diff mbox

[SRU,trusty,lts-utopic] KVM: x86: bit-ops emulation ignores offset on 64-bit

Message ID 1461264983-19657-1-git-send-email-chris.j.arges@canonical.com
State New
Headers show

Commit Message

Chris J Arges April 21, 2016, 6:56 p.m. UTC
From: Nadav Amit <namit@cs.technion.ac.il>

BugLink: http://bugs.launchpad.net/bugs/1423672

The current emulation of bit operations ignores the offset from the destination
on 64-bit target memory operands. This patch fixes this behavior.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 7dec5603b6b8dc4c3e1c65d318bd2a5a8c62a424)
Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
---
 arch/x86/kvm/emulate.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Tim Gardner April 21, 2016, 7:02 p.m. UTC | #1

Kamal Mostafa April 21, 2016, 7:18 p.m. UTC | #2

Kamal Mostafa April 21, 2016, 7:47 p.m. UTC | #3

diff mbox

Patch

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 2fc81ca..4d08114 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1249,12 +1249,14 @@  static void fetch_bit_operand(struct x86_emulate_ctxt *ctxt)
 	long sv = 0, mask;
 
 	if (ctxt->dst.type == OP_MEM && ctxt->src.type == OP_REG) {
-		mask = ~(ctxt->dst.bytes * 8 - 1);
+		mask = ~((long)ctxt->dst.bytes * 8 - 1);
 
 		if (ctxt->src.bytes == 2)
 			sv = (s16)ctxt->src.val & (s16)mask;
 		else if (ctxt->src.bytes == 4)
 			sv = (s32)ctxt->src.val & (s32)mask;
+		else
+			sv = (s64)ctxt->src.val & (s64)mask;
 
 		ctxt->dst.addr.mem.ea += (sv >> 3);
 	}