From: Rusty Russell Subject: [PATCH 09/10] kvm: avoid reference vcpu->arch.hxfar by making thumb offset_addr relative Date: Wed, 24 Oct 2012 21:55:22 +1030 Message-ID: <1351077923-17977-10-git-send-email-rusty@rustcorp.com.au> References: <20121022174555.GD26619@mudshark.cambridge.arm.com> <1351077923-17977-1-git-send-email-rusty@rustcorp.com.au> Cc: Christoffer Dall , "kvm@vger.kernel.org" , dave.martin@linaro.org, Rusty Russell To: Will Deacon Return-path: Received: from ozlabs.org ([203.10.76.45]:50350 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758242Ab2JXL36 (ORCPT ); Wed, 24 Oct 2012 07:29:58 -0400 In-Reply-To: <1351077923-17977-1-git-send-email-rusty@rustcorp.com.au> Sender: kvm-owner@vger.kernel.org List-ID: From: Rusty Russell For generic code we won't know the hdfar, so make the offset_addr relative in thumb mode. Signed-off-by: Rusty Russell --- 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