From: Rusty Russell <[email protected]>

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

Signed-off-by: Rusty Russell <[email protected]>
---
 arch/arm/kvm/emulate.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

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;
        }
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to