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 3/5] KVM: x86: BSF and BSR emulation change register unnecassarily
Date: Mon, 30 Mar 2015 15:39:21 +0300	[thread overview]
Message-ID: <1427719163-5429-4-git-send-email-namit@cs.technion.ac.il> (raw)
In-Reply-To: <1427719163-5429-1-git-send-email-namit@cs.technion.ac.il>

If the source of BSF and BSR is zero, the destination register should not
change. That is how real hardware behaves.  If we set the destination even with
the same value that we had before, we may clear bits [63:32] unnecassarily.

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

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 4961dc5..7004577 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -962,6 +962,22 @@ FASTOP2(xadd);
 
 FASTOP2R(cmp, cmp_r);
 
+static int em_bsf_c(struct x86_emulate_ctxt *ctxt)
+{
+	/* If src is zero, do not writeback, but update flags */
+	if (ctxt->src.val == 0)
+		ctxt->dst.type = OP_NONE;
+	return fastop(ctxt, em_bsf);
+}
+
+static int em_bsr_c(struct x86_emulate_ctxt *ctxt)
+{
+	/* If src is zero, do not writeback, but update flags */
+	if (ctxt->src.val == 0)
+		ctxt->dst.type = OP_NONE;
+	return fastop(ctxt, em_bsr);
+}
+
 static u8 test_cc(unsigned int condition, unsigned long flags)
 {
 	u8 rc;
@@ -4188,7 +4204,8 @@ static const struct opcode twobyte_table[256] = {
 	N, N,
 	G(BitOp, group8),
 	F(DstMem | SrcReg | ModRM | BitOp | Lock | PageTable, em_btc),
-	F(DstReg | SrcMem | ModRM, em_bsf), F(DstReg | SrcMem | ModRM, em_bsr),
+	I(DstReg | SrcMem | ModRM, em_bsf_c),
+	I(DstReg | SrcMem | ModRM, em_bsr_c),
 	D(DstReg | SrcMem8 | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov),
 	/* 0xC0 - 0xC7 */
 	F2bv(DstMem | SrcReg | ModRM | SrcWrite | Lock, em_xadd),
-- 
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 ` [PATCH 2/5] KVM: x86: POPA emulation may not clear bits [63:32] Nadav Amit
2015-03-30 12:39 ` Nadav Amit [this message]
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-4-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.