aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/emulate.c
diff options
context:
space:
mode:
authorNadav Amit <namit@cs.technion.ac.il>2014-09-30 13:49:19 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2014-11-03 06:07:24 -0500
commit518547b32ab41b12c1303d12e6e15fb1621dca4c (patch)
treea73ab7b46108c449f8a288ed1f3a2034047a47c3 /arch/x86/kvm/emulate.c
parent6bdf06625d240361e92254143a123ab432e337f8 (diff)
KVM: x86: Emulator does not calculate address correctly
In long-mode, when the address size is 4 bytes, the linear address is not truncated as the emulator mistakenly does. Instead, the offset within the segment (the ea field) should be truncated according to the address size. As Intel SDM says: "In 64-bit mode, the effective address components are added and the effective address is truncated ... before adding the full 64-bit segment base." Signed-off-by: Nadav Amit <namit@cs.technion.ac.il> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/emulate.c')
-rw-r--r--arch/x86/kvm/emulate.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 058aff86cfba..bdd4197e31fa 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -655,7 +655,8 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
655 u16 sel; 655 u16 sel;
656 unsigned cpl; 656 unsigned cpl;
657 657
658 la = seg_base(ctxt, addr.seg) + addr.ea; 658 la = seg_base(ctxt, addr.seg) +
659 (fetch || ctxt->ad_bytes == 8 ? addr.ea : (u32)addr.ea);
659 *max_size = 0; 660 *max_size = 0;
660 switch (ctxt->mode) { 661 switch (ctxt->mode) {
661 case X86EMUL_MODE_PROT64: 662 case X86EMUL_MODE_PROT64:
@@ -717,7 +718,7 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
717 } 718 }
718 break; 719 break;
719 } 720 }
720 if (fetch ? ctxt->mode != X86EMUL_MODE_PROT64 : ctxt->ad_bytes != 8) 721 if (ctxt->mode != X86EMUL_MODE_PROT64)
721 la &= (u32)-1; 722 la &= (u32)-1;
722 if (insn_aligned(ctxt, size) && ((la & (size - 1)) != 0)) 723 if (insn_aligned(ctxt, size) && ((la & (size - 1)) != 0))
723 return emulate_gp(ctxt, 0); 724 return emulate_gp(ctxt, 0);