aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNadav Amit <namit@cs.technion.ac.il>2015-03-30 08:39:21 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2015-03-30 10:46:11 -0400
commit900efe200e317649aecbeaa55619a4fc3adb2251 (patch)
tree88322796917be9a8edc1b43adb7f0d932e8acea8
parent6fd8e1275709a5bb084847eda6730b983538a572 (diff)
KVM: x86: BSF and BSR emulation change register unnecassarily
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> Message-Id: <1427719163-5429-4-git-send-email-namit@cs.technion.ac.il> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/emulate.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 4961dc5eb303..70045779c725 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -962,6 +962,22 @@ FASTOP2(xadd);
962 962
963FASTOP2R(cmp, cmp_r); 963FASTOP2R(cmp, cmp_r);
964 964
965static int em_bsf_c(struct x86_emulate_ctxt *ctxt)
966{
967 /* If src is zero, do not writeback, but update flags */
968 if (ctxt->src.val == 0)
969 ctxt->dst.type = OP_NONE;
970 return fastop(ctxt, em_bsf);
971}
972
973static int em_bsr_c(struct x86_emulate_ctxt *ctxt)
974{
975 /* If src is zero, do not writeback, but update flags */
976 if (ctxt->src.val == 0)
977 ctxt->dst.type = OP_NONE;
978 return fastop(ctxt, em_bsr);
979}
980
965static u8 test_cc(unsigned int condition, unsigned long flags) 981static u8 test_cc(unsigned int condition, unsigned long flags)
966{ 982{
967 u8 rc; 983 u8 rc;
@@ -4188,7 +4204,8 @@ static const struct opcode twobyte_table[256] = {
4188 N, N, 4204 N, N,
4189 G(BitOp, group8), 4205 G(BitOp, group8),
4190 F(DstMem | SrcReg | ModRM | BitOp | Lock | PageTable, em_btc), 4206 F(DstMem | SrcReg | ModRM | BitOp | Lock | PageTable, em_btc),
4191 F(DstReg | SrcMem | ModRM, em_bsf), F(DstReg | SrcMem | ModRM, em_bsr), 4207 I(DstReg | SrcMem | ModRM, em_bsf_c),
4208 I(DstReg | SrcMem | ModRM, em_bsr_c),
4192 D(DstReg | SrcMem8 | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov), 4209 D(DstReg | SrcMem8 | ModRM | Mov), D(DstReg | SrcMem16 | ModRM | Mov),
4193 /* 0xC0 - 0xC7 */ 4210 /* 0xC0 - 0xC7 */
4194 F2bv(DstMem | SrcReg | ModRM | SrcWrite | Lock, em_xadd), 4211 F2bv(DstMem | SrcReg | ModRM | SrcWrite | Lock, em_xadd),