diff mbox

[05/11] KVM: PPC: add GPR RA update skeleton for MMIO emulation

Message ID 1524657284-16706-6-git-send-email-wei.guo.simon@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

simon April 25, 2018, 11:54 a.m. UTC
From: Simon Guo <wei.guo.simon@gmail.com>

To optimize kvm emulation code with analyse_instr, adds new
mmio_update_ra flag to aid with GPR RA update.

This patch arms RA update at load/store emulation path for both
qemu mmio emulation or coalesced mmio emulation.

Signed-off-by: Simon Guo <wei.guo.simon@gmail.com>
---
 arch/powerpc/include/asm/kvm_host.h  |  2 ++
 arch/powerpc/kvm/emulate_loadstore.c |  1 +
 arch/powerpc/kvm/powerpc.c           | 17 +++++++++++++++++
 3 files changed, 20 insertions(+)

Comments

Paul Mackerras May 3, 2018, 5:58 a.m. UTC | #1
On Wed, Apr 25, 2018 at 07:54:38PM +0800, wei.guo.simon@gmail.com wrote:
> From: Simon Guo <wei.guo.simon@gmail.com>
> 
> To optimize kvm emulation code with analyse_instr, adds new
> mmio_update_ra flag to aid with GPR RA update.
> 
> This patch arms RA update at load/store emulation path for both
> qemu mmio emulation or coalesced mmio emulation.

It's not clear to me why you need to do this.  The existing code
writes RA at the point where the instruction is decoded.  In later
patches, you change that so the RA update occurs after the MMIO
operation is performed.  Is there a particular reason why you made
that change?

Paul.
simon May 3, 2018, 8:37 a.m. UTC | #2
On Thu, May 03, 2018 at 03:58:14PM +1000, Paul Mackerras wrote:
> On Wed, Apr 25, 2018 at 07:54:38PM +0800, wei.guo.simon@gmail.com wrote:
> > From: Simon Guo <wei.guo.simon@gmail.com>
> > 
> > To optimize kvm emulation code with analyse_instr, adds new
> > mmio_update_ra flag to aid with GPR RA update.
> > 
> > This patch arms RA update at load/store emulation path for both
> > qemu mmio emulation or coalesced mmio emulation.
> 
> It's not clear to me why you need to do this.  The existing code
> writes RA at the point where the instruction is decoded.  In later
> patches, you change that so the RA update occurs after the MMIO
> operation is performed.  Is there a particular reason why you made
> that change?
> 
> Paul.

I wanted to avoid the case that GPR RA was updated even when EMULATE_FAIL. But
if it is not mandatory, I can update RA in kvmppc_emulate_loadstore()
instead..

Thanks,
- Simon
diff mbox

Patch

diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 2d87768..1c7da00 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -673,6 +673,8 @@  struct kvm_vcpu_arch {
 	u8 mmio_sign_extend;
 	/* conversion between single and double precision */
 	u8 mmio_sp64_extend;
+	u8 mmio_ra; /* GPR as ra to be updated with EA */
+	u8 mmio_update_ra;
 	/*
 	 * Number of simulations for vsx.
 	 * If we use 2*8bytes to simulate 1*16bytes,
diff --git a/arch/powerpc/kvm/emulate_loadstore.c b/arch/powerpc/kvm/emulate_loadstore.c
index b8a3aef..90b9692 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -111,6 +111,7 @@  int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
 	vcpu->arch.mmio_sp64_extend = 0;
 	vcpu->arch.mmio_sign_extend = 0;
 	vcpu->arch.mmio_vmx_copy_nums = 0;
+	vcpu->arch.mmio_update_ra = 0;
 	vcpu->arch.mmio_host_swabbed = 0;
 
 	switch (get_op(inst)) {
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index bef27b1..f7fd68f 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -1111,6 +1111,12 @@  static int __kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
 
 	if (!ret) {
 		kvmppc_complete_mmio_load(vcpu, run);
+		if (vcpu->arch.mmio_update_ra) {
+			kvmppc_set_gpr(vcpu, vcpu->arch.mmio_ra,
+					vcpu->arch.vaddr_accessed);
+			vcpu->arch.mmio_update_ra = 0;
+		}
+
 		vcpu->mmio_needed = 0;
 		return EMULATE_DONE;
 	}
@@ -1215,6 +1221,12 @@  int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
 
 	if (!ret) {
 		vcpu->mmio_needed = 0;
+		if (vcpu->arch.mmio_update_ra) {
+			kvmppc_set_gpr(vcpu, vcpu->arch.mmio_ra,
+					vcpu->arch.vaddr_accessed);
+			vcpu->arch.mmio_update_ra = 0;
+		}
+
 		return EMULATE_DONE;
 	}
 
@@ -1581,6 +1593,11 @@  int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 			}
 		}
 #endif
+		if (vcpu->arch.mmio_update_ra) {
+			kvmppc_set_gpr(vcpu, vcpu->arch.mmio_ra,
+					vcpu->arch.vaddr_accessed);
+			vcpu->arch.mmio_update_ra = 0;
+		}
 	} else if (vcpu->arch.osi_needed) {
 		u64 *gprs = run->osi.gprs;
 		int i;