All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nadav Amit <namit@cs.technion.ac.il>
To: mtosatti@redhat.com
Cc: kvm@vger.kernel.org, pbonzini@redhat.com,
	Nadav Amit <namit@cs.technion.ac.il>
Subject: [PATCH 2/5] KVM: x86: POPA emulation may not clear bits [63:32]
Date: Mon, 30 Mar 2015 15:39:20 +0300	[thread overview]
Message-ID: <1427719163-5429-3-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1427719163-5429-1-git-send-email-namit@cs.technion.ac.il>

POPA should assign the values to the registers as usual registers are assigned.
In other words, 32-bits register assignments should clear bits [63:32] of the
register.

Split the code of register assignments that will be used by future changes as
well.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
---
 arch/x86/kvm/emulate.c | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 62f7a39..4961dc5 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -478,6 +478,25 @@ static void assign_masked(ulong *dest, ulong src, ulong mask)
 	*dest = (*dest & ~mask) | (src & mask);
 }
 
+static void assign_register(unsigned long *reg, u64 val, int bytes)
+{
+	/* The 4-byte case *is* correct: in 64-bit mode we zero-extend. */
+	switch (bytes) {
+	case 1:
+		*(u8 *)reg = (u8)val;
+		break;
+	case 2:
+		*(u16 *)reg = (u16)val;
+		break;
+	case 4:
+		*reg = (u32)val;
+		break;	/* 64b: zero-extend */
+	case 8:
+		*reg = val;
+		break;
+	}
+}
+
 static inline unsigned long ad_mask(struct x86_emulate_ctxt *ctxt)
 {
 	return (1UL << (ctxt->ad_bytes << 3)) - 1;
@@ -1691,21 +1710,7 @@ static int load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
 
 static void write_register_operand(struct operand *op)
 {
-	/* The 4-byte case *is* correct: in 64-bit mode we zero-extend. */
-	switch (op->bytes) {
-	case 1:
-		*(u8 *)op->addr.reg = (u8)op->val;
-		break;
-	case 2:
-		*(u16 *)op->addr.reg = (u16)op->val;
-		break;
-	case 4:
-		*op->addr.reg = (u32)op->val;
-		break;	/* 64b: zero-extend */
-	case 8:
-		*op->addr.reg = op->val;
-		break;
-	}
+	return assign_register(op->addr.reg, op->val, op->bytes);
 }
 
 static int writeback(struct x86_emulate_ctxt *ctxt, struct operand *op)
@@ -1926,6 +1931,7 @@ static int em_popa(struct x86_emulate_ctxt *ctxt)
 {
 	int rc = X86EMUL_CONTINUE;
 	int reg = VCPU_REGS_RDI;
+	u32 val;
 
 	while (reg >= VCPU_REGS_RAX) {
 		if (reg == VCPU_REGS_RSP) {
@@ -1933,9 +1939,10 @@ static int em_popa(struct x86_emulate_ctxt *ctxt)
 			--reg;
 		}
 
-		rc = emulate_pop(ctxt, reg_rmw(ctxt, reg), ctxt->op_bytes);
+		rc = emulate_pop(ctxt, &val, ctxt->op_bytes);
 		if (rc != X86EMUL_CONTINUE)
 			break;
+		assign_register(reg_rmw(ctxt, reg), val, ctxt->op_bytes);
 		--reg;
 	}
 	return rc;
-- 
1.9.1


  parent reply	other threads:[~2015-03-30 12:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-30 12:39 [PATCH 0/5] KVM: x86: 64/32 bit fixes and INIT/BSP fixes Nadav Amit
2015-03-30 12:39 ` [PATCH 1/5] KVM: x86: CMOV emulation on legacy mode is wrong Nadav Amit
2015-03-30 12:39 ` Nadav Amit [this message]
2015-03-30 12:39 ` [PATCH 3/5] KVM: x86: BSF and BSR emulation change register unnecassarily Nadav Amit
2015-03-30 12:39 ` [PATCH 4/5] KVM: x86: INIT and reset sequences are different Nadav Amit
2015-03-30 12:39 ` [PATCH 5/5] KVM: x86: BSP in MSR_IA32_APICBASE is writable Nadav Amit
2015-03-30 14:12   ` Paolo Bonzini
2015-03-30 14:40     ` Nadav Amit
2015-03-30 14:45       ` Paolo Bonzini
2015-03-30 19:31         ` Nadav Amit
2015-03-30 19:37           ` Paolo Bonzini
2015-03-30 14:46 ` [PATCH 0/5] KVM: x86: 64/32 bit fixes and INIT/BSP fixes 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=1427719163-5429-3-git-send-email-namit@cs.technion.ac.il \
    --to=namit@cs.technion.ac.il \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.