diff mbox

[09/10] kvm: avoid reference vcpu->arch.hxfar by making thumb offset_addr relative

Message ID 1351077923-17977-10-git-send-email-rusty@rustcorp.com.au (mailing list archive)
State New, archived
Headers show

Commit Message

Rusty Russell Oct. 24, 2012, 11:25 a.m. UTC
From: Rusty Russell <rusty.russell@linaro.org>

For generic code we won't know the hdfar, so make the offset_addr relative
in thumb mode.

Signed-off-by: Rusty Russell <rusty.russell@linaro.org>
---
 arch/arm/kvm/emulate.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/arch/arm/kvm/emulate.c b/arch/arm/kvm/emulate.c
index 5ac4cf7..c0014e1 100644
--- a/arch/arm/kvm/emulate.c
+++ b/arch/arm/kvm/emulate.c
@@ -567,18 +567,17 @@  struct thumb_decode {
 static bool decode_thumb_wb(struct kvm_vcpu *vcpu, struct arm_insn *ti)
 {
 	u8 imm8 = ti->instr & 0xff;
-	u32 offset_addr = vcpu->arch.hxfar;
 
 	ti->P = (ti->instr >> 10) & 1;
 	ti->U = (ti->instr >> 9) & 1;
 	ti->Rn = (ti->instr >> 16) & 0xf;
 	ti->Rd = (ti->instr >> 12) & 0xf;
 
-	/* Handle Writeback */
+	/* Handle Writeback: offset_addr relative to fault address. */
 	if (!ti->P && ti->U)
-		ti->offset_addr = offset_addr + imm8;
+		ti->offset_addr = imm8;
 	else if (!ti->P && !ti->U)
-		ti->offset_addr = offset_addr - imm8;
+		ti->offset_addr = -imm8;
 	return true;
 }
 
@@ -740,8 +739,10 @@  static bool execute(struct kvm_vcpu *vcpu, struct kvm_exit_mmio *mmio,
 		if (kvm_vcpu_reg_is_pc(vcpu, ai->Rn))
 			return false;
 
-		if (!ai->P)
-			*vcpu_reg(vcpu, ai->Rn) = ai->offset_addr;
+		if (!ai->P) {
+			*vcpu_reg(vcpu, ai->Rn)
+				= vcpu->arch.hxfar + ai->offset_addr;
+		}
 		vcpu->arch.mmio.sign_extend = ai->sign_extend;
 		return true;
 	}