Re: [PATCH] KVM: x86 emulator: fix group 8 instruction decoding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/04/2010 10:27 AM, Wei Yongjun wrote:
> Group 8 instruction, BT[S|R|C] should be mask as BitOp.
> 
> Signed-off-by: Wei Yongjun<yjwei@xxxxxxxxxxxxxx>
> ---
>   arch/x86/kvm/emulate.c |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index d197b46..eba5a67 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -2261,7 +2261,7 @@ static struct opcode twobyte_table[256] = {
>   	    D(DstReg | SrcMem16 | ModRM | Mov),
>   	/* 0xB8 - 0xBF */
>   	N, N,
> -	G(0, group8), D(DstMem | SrcReg | ModRM | BitOp | Lock),
> +	G(BitOp, group8), D(DstMem | SrcReg | ModRM | BitOp | Lock),
>   	N, N, D(ByteOp | DstReg | SrcMem | ModRM | Mov),
>   	    D(DstReg | SrcMem16 | ModRM | Mov),
>   	/* 0xC0 - 0xCF */

This is correct with your 4/4 patch, but incorrect before it.  It will
incorrectly cause the emulator to adjust the address of the source
operand.  This is documented to happen with a register source but not
with an immediate source.  You can test it with this:

#include <stdio.h>
int main()
{
  int a[3] = {0, 0, 0};
  asm ("btcl $32, %0" :: "m" (a[0]) : "memory");
  asm ("btcl $1, %0" :: "m" (a[1]) : "memory");
  asm ("btcl %1, %0" :: "m" (a[0]), "r" (66) : "memory");
  printf ("%x %x %x\n", a[0], a[1], a[2]);
}

It prints "1 2 4".  I'm quite confident that instead it would print "0 3
4" with this patch, and "5 2 0" with this patch + 4/4.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux