From: Nadav Amit <namit@cs.technion.ac.il>
To: mtosatti@redhat.com, pbonzini@redhat.com, hpa@zytor.com
Cc: gleb@kernel.org, tglx@linutronix.de, mingo@redhat.com,
x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Nadav Amit <namit@cs.technion.ac.il>
Subject: [PATCH 1/5] KVM: x86: Emulator does not calculate address correctly
Date: Wed, 7 May 2014 15:32:48 +0300 [thread overview]
Message-ID: <1399465972-4026-2-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1399465972-4026-1-git-send-email-namit@cs.technion.ac.il>
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>
---
arch/x86/kvm/emulate.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index e8a5840..743e8e3 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -631,7 +631,8 @@ static int __linearize(struct x86_emulate_ctxt *ctxt,
u16 sel;
unsigned cpl;
- la = seg_base(ctxt, addr.seg) + addr.ea;
+ la = seg_base(ctxt, addr.seg) +
+ (ctxt->ad_bytes == 8 ? addr.ea : (u32)addr.ea);
switch (ctxt->mode) {
case X86EMUL_MODE_PROT64:
if (((signed long)la << 16) >> 16 != la)
@@ -678,7 +679,7 @@ static int __linearize(struct x86_emulate_ctxt *ctxt,
}
break;
}
- if (fetch ? ctxt->mode != X86EMUL_MODE_PROT64 : ctxt->ad_bytes != 8)
+ if (ctxt->mode != X86EMUL_MODE_PROT64)
la &= (u32)-1;
if (insn_aligned(ctxt, size) && ((la & (size - 1)) != 0))
return emulate_gp(ctxt, 0);
--
1.9.1
next prev parent reply other threads:[~2014-05-07 12:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-07 12:32 [PATCH 0/5] KVM: x86: Fix exit handler and emulation bugs Nadav Amit
2014-05-07 12:32 ` Nadav Amit [this message]
2014-05-07 13:57 ` [PATCH 1/5] KVM: x86: Emulator does not calculate address correctly Paolo Bonzini
2014-05-07 15:21 ` Nadav Amit
2014-05-07 12:32 ` [PATCH 2/5] KVM: vmx: handle_dr does not handle RSP correctly Nadav Amit
2014-05-07 12:32 ` [PATCH 3/5] KVM: x86: Mark bit 7 in long-mode PDPTE according to 1GB pages support Nadav Amit
2014-05-07 12:32 ` [PATCH 4/5] KVM: x86: Wrong register masking in 64-bit mode Nadav Amit
2014-05-07 14:50 ` Bandan Das
2014-05-07 15:24 ` Paolo Bonzini
2014-05-07 16:11 ` Nadav Amit
2014-05-07 15:52 ` Paolo Bonzini
2014-05-08 12:27 ` Nadav Amit
2014-05-07 12:32 ` [PATCH 5/5] KVM: x86: Fix wrong masking on relative jump/call Nadav Amit
2014-05-07 14:43 ` Bandan Das
2014-05-07 15:57 ` Nadav Amit
2014-05-07 15:59 ` Paolo Bonzini
2014-05-07 16:00 ` [PATCH 0/5] KVM: x86: Fix exit handler and emulation bugs Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1399465972-4026-2-git-send-email-namit@cs.technion.ac.il \
--to=namit@cs.technion.ac.il \
--cc=gleb@kernel.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®