KVM: PPC: reimplement mmio emulation with analyse_instr()
Subsystems (3)
v2 cover KVM: PPC: reimplement mmio emulation with analyse_instr()
From: Simon Guo <[email protected]>
We already have analyse_instr() which analyzes instructions for the instruction type, size, addtional flags, etc. What kvmppc_emulate_loadstore() did is somehow duplicated and it will be good to utilize analyse_instr() to reimplement the code. The advantage is that the code logic will be shared and more clean to be maintained.
This patch series reimplement kvmppc_emulate_loadstore() for various load/store instructions.
The testcase locates at:
https://github.com/justdoitqd/publicFiles/blob/master/test_mmio.c
- Tested at both PR/HV KVM.
- Also tested with little endian host & big endian guest.
Tested instruction list:
lbz lbzu lbzx ld ldbrx
ldu ldx lfd lfdu lfdx
lfiwax lfiwzx lfs lfsu lfsx
lha lhau lhax lhbrx lhz
lhzu lhzx lvx lwax lwbrx
lwz lwzu lwzx lxsdx lxsiwax
lxsiwzx lxsspx lxvd2x lxvdsx lxvw4x
stb stbu stbx std stdbrx
stdu stdx stfd stfdu stfdx
stfiwx stfs stfsx sth sthbrx
sthu sthx stvx stw stwbrx
stwu stwx stxsdx stxsiwx stxsspx
stxvd2x stxvw4x
lvebx stvebx
lvehx stvehx
lvewx stvewx
V2 changes:
1) correct patch split issue in v1.
2) revise some commit message/code comment per review comment
3) remove incorrect special handling for stxsiwx
4) remove mmio_update_ra related and move the RA update into kvmppc_emulate_loadstore().
5) rework giveup_ext() which is only meaningful when not NULL.
6) rewrite VMX emulation code and cover rest VMX instructions:
lvebx stvebx
lvehx stvehx
lvewx stvewx
Simon Guo (10):
KVM: PPC: add pt_regs into kvm_vcpu_arch and move vcpu->arch.gpr[]
into it
KVM: PPC: mov nip/ctr/lr/xer registers to pt_regs in kvm_vcpu_arch
KVM: PPC: Fix a mmio_host_swabbed uninitialized usage issue when VMX
store
KVM: PPC: add KVMPPC_VSX_COPY_WORD_LOAD_DUMP type support for mmio
emulation
KVM: PPC: reimplement non-SIMD LOAD/STORE instruction mmio emulation
with analyse_intr() input
KVM: PPC: add giveup_ext() hook for PPC KVM ops
KVM: PPC: reimplement LOAD_FP/STORE_FP instruction mmio emulation with
analyse_intr() input
KVM: PPC: reimplements LOAD_VSX/STORE_VSX instruction mmio emulation
with analyse_intr() input
KVM: PPC: expand mmio_vsx_copy_type to mmio_copy_type to cover VMX
load/store elem types
KVM: PPC: reimplements LOAD_VMX/STORE_VMX instruction mmio emulation
with analyse_intr() input
arch/powerpc/include/asm/kvm_book3s.h | 20 +- arch/powerpc/include/asm/kvm_book3s_64.h | 20 +- arch/powerpc/include/asm/kvm_booke.h | 20 +- arch/powerpc/include/asm/kvm_host.h | 17 +- arch/powerpc/include/asm/kvm_ppc.h | 17 +- arch/powerpc/kernel/asm-offsets.c | 18 +- arch/powerpc/kvm/book3s.c | 4 +- arch/powerpc/kvm/book3s_32_mmu.c | 2 +- arch/powerpc/kvm/book3s_64_vio_hv.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 6 +- arch/powerpc/kvm/book3s_hv_builtin.c | 6 +- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 15 +- arch/powerpc/kvm/book3s_hv_rm_xics.c | 2 +- arch/powerpc/kvm/book3s_hv_tm.c | 10 +- arch/powerpc/kvm/book3s_hv_tm_builtin.c | 10 +- arch/powerpc/kvm/book3s_pr.c | 73 +-- arch/powerpc/kvm/book3s_xive_template.c | 4 +- arch/powerpc/kvm/booke.c | 41 +- arch/powerpc/kvm/booke_emulate.c | 6 +- arch/powerpc/kvm/e500_emulate.c | 6 +- arch/powerpc/kvm/e500_mmu.c | 2 +- arch/powerpc/kvm/e500_mmu_host.c | 8 +- arch/powerpc/kvm/emulate_loadstore.c | 746 +++++++++---------------------- arch/powerpc/kvm/powerpc.c | 299 ++++++++++--- 24 files changed, 628 insertions(+), 726 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/10 KVM: PPC: add pt_regs into kvm_vcpu_arch and move vcpu->arch.gpr[] into it
From: Simon Guo <[email protected]>
Current regs are scattered at kvm_vcpu_arch structure and it will be more neat to organize them into pt_regs structure.
Also it will enable reimplementation of MMIO emulation code with analyse_instr() later.
--- arch/powerpc/include/asm/kvm_book3s.h | 4 +-- arch/powerpc/include/asm/kvm_book3s_64.h | 8 ++--- arch/powerpc/include/asm/kvm_booke.h | 4 +-- arch/powerpc/include/asm/kvm_host.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kvm/book3s_64_vio_hv.c | 2 +- arch/powerpc/kvm/book3s_hv_builtin.c | 6 ++-- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 15 +++++---- arch/powerpc/kvm/book3s_hv_rm_xics.c | 2 +- arch/powerpc/kvm/book3s_pr.c | 56 ++++++++++++++++---------------- arch/powerpc/kvm/book3s_xive_template.c | 4 +-- arch/powerpc/kvm/e500_emulate.c | 4 +-- 12 files changed, 55 insertions(+), 54 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +2 -2
@@ -273,12 +273,12 @@ static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) { - vcpu->arch.gpr[num] = val; + vcpu->arch.regs.gpr[num] = val; }static inline ulong kvmppc_get_gpr (struct kvm_vcpu *vcpu,int num) { -return vcpu->arch.gpr[num]; +return vcpu->arch.regs.gpr[num]; }static inline void kvmppc_set_cr (struct kvm_vcpu *vcpu,u32 val)
arch/powerpc/include/asm/kvm_book3s_64.h +4 -4
@@ -490,8 +490,8 @@ static inline void copy_from_checkpoint(struct kvm_vcpu *vcpu) vcpu->arch.ppr = vcpu->arch.ppr_tm; vcpu->arch.dscr = vcpu->arch.dscr_tm; vcpu->arch.tar = vcpu->arch.tar_tm; -memcpy (vcpu->arch.gpr, vcpu->arch.gpr_tm, -sizeof (vcpu->arch.gpr)); +memcpy (vcpu->arch.regs.gpr, vcpu->arch.gpr_tm, +sizeof (vcpu->arch.regs.gpr)); vcpu->arch.fp = vcpu->arch.fp_tm; vcpu->arch.vr = vcpu->arch.vr_tm; vcpu->arch.vrsave = vcpu->arch.vrsave_tm;
@@ -507,8 +507,8 @@ static inline void copy_to_checkpoint(struct kvm_vcpu *vcpu) vcpu->arch.ppr_tm = vcpu->arch.ppr; vcpu->arch.dscr_tm = vcpu->arch.dscr; vcpu->arch.tar_tm = vcpu->arch.tar; -memcpy (vcpu->arch.gpr_tm, vcpu->arch.gpr, -sizeof (vcpu->arch.gpr)); +memcpy (vcpu->arch.gpr_tm, vcpu->arch.regs.gpr, +sizeof (vcpu->arch.regs.gpr)); vcpu->arch.fp_tm = vcpu->arch.fp; vcpu->arch.vr_tm = vcpu->arch.vr; vcpu->arch.vrsave_tm = vcpu->arch.vrsave;
arch/powerpc/include/asm/kvm_booke.h +2 -2
@@ -36,12 +36,12 @@static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) { - vcpu->arch.gpr[num] = val; + vcpu->arch.regs.gpr[num] = val; }static inline ulong kvmppc_get_gpr (struct kvm_vcpu *vcpu,int num) { -return vcpu->arch.gpr[num]; +return vcpu->arch.regs.gpr[num]; }static inline void kvmppc_set_cr (struct kvm_vcpu *vcpu,u32 val)
arch/powerpc/include/asm/kvm_host.h +1 -1
@@ -486,7 +486,7 @@ struct kvm_vcpu_arch {struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;#endif -ulong gpr[32 ]; +struct pt_regs regs;struct thread_fp_state fp;
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -425,7 +425,7 @@ int main(void)OFFSET (VCPU_HOST_STACK , kvm_vcpu, arch.host_stack);OFFSET (VCPU_HOST_PID , kvm_vcpu, arch.host_pid);OFFSET (VCPU_GUEST_PID , kvm_vcpu, arch.pid); -OFFSET (VCPU_GPRS , kvm_vcpu, arch.gpr); +OFFSET (VCPU_GPRS , kvm_vcpu, arch.regs.gpr);OFFSET (VCPU_VRSAVE , kvm_vcpu, arch.vrsave);OFFSET (VCPU_FPRS , kvm_vcpu, arch.fp.fpr);#ifdef CONFIG_ALTIVEC
arch/powerpc/kvm/book3s_64_vio_hv.c +1 -1
@@ -571,7 +571,7 @@ long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn, page = stt->pages[idx /TCES_PER_PAGE ]; tbl = (u64 *)page_address (page); - vcpu->arch.gpr[4 ] = tbl[idx %TCES_PER_PAGE ]; + vcpu->arch.regs.gpr[4 ] = tbl[idx %TCES_PER_PAGE ];return H_SUCCESS ; }
arch/powerpc/kvm/book3s_hv_builtin.c +3 -3
@@ -211,9 +211,9 @@ long kvmppc_h_random(struct kvm_vcpu *vcpu)/* Only need to do the expensive mfmsr() on radix */ if (kvm_is_radix (vcpu->kvm) && (mfmsr () &MSR_IR )) - r =powernv_get_random_long (&vcpu->arch.gpr[4 ]); + r =powernv_get_random_long (&vcpu->arch.regs.gpr[4 ]);else - r =powernv_get_random_real_mode (&vcpu->arch.gpr[4 ]); + r =powernv_get_random_real_mode (&vcpu->arch.regs.gpr[4 ]);if (r)return H_SUCCESS ;
@@ -562,7 +562,7 @@ unsigned long kvmppc_rm_h_xirr_x(struct kvm_vcpu *vcpu) {if (!kvmppc_xics_enabled (vcpu))return H_TOO_HARD ; - vcpu->arch.gpr[5 ] =get_tb (); + vcpu->arch.regs.gpr[5 ] =get_tb ();if (xive_enabled ()) {if (is_rm ())return xive_rm_h_xirr (vcpu);
arch/powerpc/kvm/book3s_hv_rm_mmu.c +8 -7
@@ -418,7 +418,8 @@ long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, long pte_index, unsigned long pteh, unsigned long ptel) { return kvmppc_do_h_enter(vcpu->kvm, flags, pte_index, pteh, ptel, - vcpu->arch.pgdir, true, &vcpu->arch.gpr[4]); + vcpu->arch.pgdir, true, + &vcpu->arch.regs.gpr[4]); }#ifdef __BIG_ENDIAN__
@@ -565,13 +566,13 @@ long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags, unsigned long pte_index, unsigned long avpn) {return kvmppc_do_h_remove (vcpu->kvm, flags, pte_index, avpn, - &vcpu->arch.gpr[4 ]); + &vcpu->arch.regs.gpr[4 ]); }long kvmppc_h_bulk_remove (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm; -unsigned long *args = &vcpu->arch.gpr[4 ]; +unsigned long *args = &vcpu->arch.regs.gpr[4 ];__be64 *hp, *hptes[4 ];unsigned long tlbrb[4 ];long int i, j, k, n, found, indexes[4 ];
@@ -791,8 +792,8 @@ long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags, r = rev[i].guest_rpte | (r & (HPTE_R_R |HPTE_R_C )); r &= ~HPTE_GR_RESERVED ; } - vcpu->arch.gpr[4 + i *2 ] = v; - vcpu->arch.gpr[5 + i *2 ] = r; + vcpu->arch.regs.gpr[4 + i *2 ] = v; + vcpu->arch.regs.gpr[5 + i *2 ] = r; }return H_SUCCESS ; }
@@ -838,7 +839,7 @@ long kvmppc_h_clear_ref(struct kvm_vcpu *vcpu, unsigned long flags, } } } - vcpu->arch.gpr[4 ] = gr; + vcpu->arch.regs.gpr[4 ] = gr; ret =H_SUCCESS ; out:unlock_hpte (hpte, v & ~HPTE_V_HVLOCK );
@@ -885,7 +886,7 @@ long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags,kvmppc_set_dirty_from_hpte (kvm, v, gr); } } - vcpu->arch.gpr[4 ] = gr; + vcpu->arch.regs.gpr[4 ] = gr; ret =H_SUCCESS ; out:unlock_hpte (hpte, v & ~HPTE_V_HVLOCK );
arch/powerpc/kvm/book3s_hv_rm_xics.c +1 -1
@@ -517,7 +517,7 @@ unsigned long xics_rm_h_xirr(struct kvm_vcpu *vcpu) }while (!icp_rm_try_update (icp, old_state, new_state));/* Return the result in GPR4 */ - vcpu->arch.gpr[4 ] = xirr; + vcpu->arch.regs.gpr[4 ] = xirr;return check_too_hard (xics, icp); }
arch/powerpc/kvm/book3s_pr.c +28 -28
68 lines not on this page · raw message
arch/powerpc/kvm/book3s_xive_template.c +2 -2
@@ -327,7 +327,7 @@ X_STATIC unsigned long GLUE(X_PFX,h_xirr)(struct kvm_vcpu *vcpu)*/ /* Return interrupt and old CPPR in GPR4 */ - vcpu->arch.gpr[4 ] = hirq | (old_cppr <<24 ); + vcpu->arch.regs.gpr[4 ] = hirq | (old_cppr <<24 );return H_SUCCESS ; }
@@ -362,7 +362,7 @@ X_STATIC unsigned long GLUE(X_PFX,h_ipoll)(struct kvm_vcpu *vcpu, unsigned long hirq =GLUE (X_PFX ,scan_interrupts)(xc, pending, scan_poll);/* Return interrupt and old CPPR in GPR4 */ - vcpu->arch.gpr[4 ] = hirq | (xc->cppr <<24 ); + vcpu->arch.regs.gpr[4 ] = hirq | (xc->cppr <<24 );return H_SUCCESS ; }
arch/powerpc/kvm/e500_emulate.c +2 -2
@@ -53,7 +53,7 @@ static int dbell2prio(ulong param)static int kvmppc_e500_emul_msgclr (struct kvm_vcpu *vcpu,int rb) { -ulong param = vcpu->arch.gpr[rb]; +ulong param = vcpu->arch.regs.gpr[rb];int prio =dbell2prio (param);if (prio <0 )
@@ -65,7 +65,7 @@ static int kvmppc_e500_emul_msgclr(struct kvm_vcpu *vcpu, int rb)static int kvmppc_e500_emul_msgsnd (struct kvm_vcpu *vcpu,int rb) { -ulong param = vcpu->arch.gpr[rb]; +ulong param = vcpu->arch.regs.gpr[rb];int prio =dbell2prio (rb);int pir = param &PPC_DBELL_PIR_MASK ;int i;
Signature · 1 line
1.8.3.1
PATCH v2 2/10 KVM: PPC: mov nip/ctr/lr/xer registers to pt_regs in kvm_vcpu_arch
In reply to [email protected]From: Simon Guo <[email protected]>
This patch moves nip/ctr/lr/xer registers from scattered places in kvm_vcpu_arch to pt_regs structure.
cr register is "unsigned long" in pt_regs and u32 in vcpu->arch. It will need more consideration and may move in later patches.
--- arch/powerpc/include/asm/kvm_book3s.h | 16 ++++++------- arch/powerpc/include/asm/kvm_book3s_64.h | 12 +++++----- arch/powerpc/include/asm/kvm_booke.h | 16 ++++++------- arch/powerpc/include/asm/kvm_host.h | 4 ---- arch/powerpc/kernel/asm-offsets.c | 16 ++++++------- arch/powerpc/kvm/book3s_32_mmu.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 6 ++--- arch/powerpc/kvm/book3s_hv_tm.c | 10 ++++---- arch/powerpc/kvm/book3s_hv_tm_builtin.c | 10 ++++---- arch/powerpc/kvm/book3s_pr.c | 16 ++++++------- arch/powerpc/kvm/booke.c | 41 +++++++++++++++++--------------- arch/powerpc/kvm/booke_emulate.c | 6 ++--- arch/powerpc/kvm/e500_emulate.c | 2 +- arch/powerpc/kvm/e500_mmu.c | 2 +- 14 files changed, 79 insertions(+), 80 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +8 -8
@@ -293,42 +293,42 @@ static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)static inline void kvmppc_set_xer (struct kvm_vcpu *vcpu,ulong val) { - vcpu->arch.xer = val; + vcpu->arch.regs.xer = val; }static inline ulong kvmppc_get_xer (struct kvm_vcpu *vcpu) { -return vcpu->arch.xer; +return vcpu->arch.regs.xer; }static inline void kvmppc_set_ctr (struct kvm_vcpu *vcpu,ulong val) { - vcpu->arch.ctr = val; + vcpu->arch.regs.ctr = val; }static inline ulong kvmppc_get_ctr (struct kvm_vcpu *vcpu) { -return vcpu->arch.ctr; +return vcpu->arch.regs.ctr; }static inline void kvmppc_set_lr (struct kvm_vcpu *vcpu,ulong val) { - vcpu->arch.lr = val; + vcpu->arch.regs.link = val; }static inline ulong kvmppc_get_lr (struct kvm_vcpu *vcpu) { -return vcpu->arch.lr; +return vcpu->arch.regs.link; }static inline void kvmppc_set_pc (struct kvm_vcpu *vcpu,ulong val) { - vcpu->arch.pc = val; + vcpu->arch.regs.nip = val; }static inline ulong kvmppc_get_pc (struct kvm_vcpu *vcpu) { -return vcpu->arch.pc; +return vcpu->arch.regs.nip; }static inline u64 kvmppc_get_msr (struct kvm_vcpu *vcpu);
arch/powerpc/include/asm/kvm_book3s_64.h +6 -6
@@ -483,9 +483,9 @@ static inline u64 sanitize_msr(u64 msr)static inline void copy_from_checkpoint (struct kvm_vcpu *vcpu) { vcpu->arch.cr = vcpu->arch.cr_tm; - vcpu->arch.xer = vcpu->arch.xer_tm; - vcpu->arch.lr = vcpu->arch.lr_tm; - vcpu->arch.ctr = vcpu->arch.ctr_tm; + vcpu->arch.regs.xer = vcpu->arch.xer_tm; + vcpu->arch.regs.link = vcpu->arch.lr_tm; + vcpu->arch.regs.ctr = vcpu->arch.ctr_tm; vcpu->arch.amr = vcpu->arch.amr_tm; vcpu->arch.ppr = vcpu->arch.ppr_tm; vcpu->arch.dscr = vcpu->arch.dscr_tm;
@@ -500,9 +500,9 @@ static inline void copy_from_checkpoint(struct kvm_vcpu *vcpu)static inline void copy_to_checkpoint (struct kvm_vcpu *vcpu) { vcpu->arch.cr_tm = vcpu->arch.cr; - vcpu->arch.xer_tm = vcpu->arch.xer; - vcpu->arch.lr_tm = vcpu->arch.lr; - vcpu->arch.ctr_tm = vcpu->arch.ctr; + vcpu->arch.xer_tm = vcpu->arch.regs.xer; + vcpu->arch.lr_tm = vcpu->arch.regs.link; + vcpu->arch.ctr_tm = vcpu->arch.regs.ctr; vcpu->arch.amr_tm = vcpu->arch.amr; vcpu->arch.ppr_tm = vcpu->arch.ppr; vcpu->arch.dscr_tm = vcpu->arch.dscr;
arch/powerpc/include/asm/kvm_booke.h +8 -8
@@ -56,12 +56,12 @@ static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)static inline void kvmppc_set_xer (struct kvm_vcpu *vcpu,ulong val) { - vcpu->arch.xer = val; + vcpu->arch.regs.xer = val; }static inline ulong kvmppc_get_xer (struct kvm_vcpu *vcpu) { -return vcpu->arch.xer; +return vcpu->arch.regs.xer; }static inline bool kvmppc_need_byteswap (struct kvm_vcpu *vcpu)
@@ -72,32 +72,32 @@ static inline bool kvmppc_need_byteswap(struct kvm_vcpu *vcpu)static inline void kvmppc_set_ctr (struct kvm_vcpu *vcpu,ulong val) { - vcpu->arch.ctr = val; + vcpu->arch.regs.ctr = val; }static inline ulong kvmppc_get_ctr (struct kvm_vcpu *vcpu) { -return vcpu->arch.ctr; +return vcpu->arch.regs.ctr; }static inline void kvmppc_set_lr (struct kvm_vcpu *vcpu,ulong val) { - vcpu->arch.lr = val; + vcpu->arch.regs.link = val; }static inline ulong kvmppc_get_lr (struct kvm_vcpu *vcpu) { -return vcpu->arch.lr; +return vcpu->arch.regs.link; }static inline void kvmppc_set_pc (struct kvm_vcpu *vcpu,ulong val) { - vcpu->arch.pc = val; + vcpu->arch.regs.nip = val; }static inline ulong kvmppc_get_pc (struct kvm_vcpu *vcpu) { -return vcpu->arch.pc; +return vcpu->arch.regs.nip; }static inline ulong kvmppc_get_fault_dar (struct kvm_vcpu *vcpu)
arch/powerpc/include/asm/kvm_host.h +0 -4
@@ -521,14 +521,10 @@ struct kvm_vcpu_arch {u32 qpr[32 ];#endif -ulong pc; -ulong ctr; -ulong lr;#ifdef CONFIG_PPC_BOOK3S ulong tar;#endif -ulong xer;u32 cr;#ifdef CONFIG_PPC_BOOK3S
arch/powerpc/kernel/asm-offsets.c +8 -8
@@ -431,14 +431,14 @@ int main(void)#ifdef CONFIG_ALTIVEC OFFSET (VCPU_VRS , kvm_vcpu, arch.vr.vr);#endif -OFFSET (VCPU_XER , kvm_vcpu, arch.xer); -OFFSET (VCPU_CTR , kvm_vcpu, arch.ctr); -OFFSET (VCPU_LR , kvm_vcpu, arch.lr); +OFFSET (VCPU_XER , kvm_vcpu, arch.regs.xer); +OFFSET (VCPU_CTR , kvm_vcpu, arch.regs.ctr); +OFFSET (VCPU_LR , kvm_vcpu, arch.regs.link);#ifdef CONFIG_PPC_BOOK3S OFFSET (VCPU_TAR , kvm_vcpu, arch.tar);#endif OFFSET (VCPU_CR , kvm_vcpu, arch.cr); -OFFSET (VCPU_PC , kvm_vcpu, arch.pc); +OFFSET (VCPU_PC , kvm_vcpu, arch.regs.nip);#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE OFFSET (VCPU_MSR , kvm_vcpu, arch.shregs.msr);OFFSET (VCPU_SRR0 , kvm_vcpu, arch.shregs.srr0);
@@ -694,10 +694,10 @@ int main(void)#else /* CONFIG_PPC_BOOK3S */ OFFSET (VCPU_CR , kvm_vcpu, arch.cr); -OFFSET (VCPU_XER , kvm_vcpu, arch.xer); -OFFSET (VCPU_LR , kvm_vcpu, arch.lr); -OFFSET (VCPU_CTR , kvm_vcpu, arch.ctr); -OFFSET (VCPU_PC , kvm_vcpu, arch.pc); +OFFSET (VCPU_XER , kvm_vcpu, arch.regs.xer); +OFFSET (VCPU_LR , kvm_vcpu, arch.regs.link); +OFFSET (VCPU_CTR , kvm_vcpu, arch.regs.ctr); +OFFSET (VCPU_PC , kvm_vcpu, arch.regs.nip);OFFSET (VCPU_SPRG9 , kvm_vcpu, arch.sprg9);OFFSET (VCPU_LAST_INST , kvm_vcpu, arch.last_inst);OFFSET (VCPU_FAULT_DEAR , kvm_vcpu, arch.fault_dear);
arch/powerpc/kvm/book3s_32_mmu.c +1 -1
@@ -52,7 +52,7 @@static inline bool check_debug_ip (struct kvm_vcpu *vcpu) {#ifdef DEBUG_MMU_PTE_IP -return vcpu->arch.pc ==DEBUG_MMU_PTE_IP ; +return vcpu->arch.regs.nip ==DEBUG_MMU_PTE_IP ;#else return true;#endif
arch/powerpc/kvm/book3s_hv.c +3 -3
@@ -371,13 +371,13 @@ static void kvmppc_dump_regs(struct kvm_vcpu *vcpu)pr_err ("vcpu %p (%d):\n" , vcpu, vcpu->vcpu_id);pr_err ("pc = %.16lx msr = %.16llx trap = %x\n" , - vcpu->arch.pc, vcpu->arch.shregs.msr, vcpu->arch.trap); + vcpu->arch.regs.nip, vcpu->arch.shregs.msr, vcpu->arch.trap);for (r =0 ; r <16 ; ++r)pr_err ("r%2d = %.16lx r%d = %.16lx\n" , r,kvmppc_get_gpr (vcpu, r), r+16 ,kvmppc_get_gpr (vcpu, r+16 ));pr_err ("ctr = %.16lx lr = %.16lx\n" , - vcpu->arch.ctr, vcpu->arch.lr); + vcpu->arch.regs.ctr, vcpu->arch.regs.link);pr_err ("srr0 = %.16llx srr1 = %.16llx\n" , vcpu->arch.shregs.srr0, vcpu->arch.shregs.srr1); pr_err("sprg0 = %.16llx sprg1 = %.16llx\n",
@@ -385,7 +385,7 @@ static void kvmppc_dump_regs(struct kvm_vcpu *vcpu)pr_err ("sprg2 = %.16llx sprg3 = %.16llx\n" , vcpu->arch.shregs.sprg2, vcpu->arch.shregs.sprg3);pr_err ("cr = %.8x xer = %.16lx dsisr = %.8x\n" , - vcpu->arch.cr, vcpu->arch.xer, vcpu->arch.shregs.dsisr); + vcpu->arch.cr, vcpu->arch.regs.xer, vcpu->arch.shregs.dsisr);pr_err ("dar = %.16llx\n" , vcpu->arch.shregs.dar);pr_err ("fault dar = %.16lx dsisr = %.8x\n" , vcpu->arch.fault_dar, vcpu->arch.fault_dsisr);
arch/powerpc/kvm/book3s_hv_tm.c +5 -5
@@ -19,7 +19,7 @@ static void emulate_tx_failure(struct kvm_vcpu *vcpu, u64 failure_cause)u64 texasr, tfiar;u64 msr = vcpu->arch.shregs.msr; - tfiar = vcpu->arch.pc & ~0x3ull ; + tfiar = vcpu->arch.regs.nip & ~0x3ull ; texasr = (failure_cause <<56 ) |TEXASR_ABORT |TEXASR_FS |TEXASR_EXACT ;if (MSR_TM_SUSPENDED (vcpu->arch.shregs.msr)) texasr |=TEXASR_SUSP ;
@@ -57,8 +57,8 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) (newmsr & MSR_TM))); newmsr =sanitize_msr (newmsr); vcpu->arch.shregs.msr = newmsr; - vcpu->arch.cfar = vcpu->arch.pc -4 ; - vcpu->arch.pc = vcpu->arch.shregs.srr0; + vcpu->arch.cfar = vcpu->arch.regs.nip -4 ; + vcpu->arch.regs.nip = vcpu->arch.shregs.srr0;return RESUME_GUEST ;case PPC_INST_RFEBB :
@@ -90,8 +90,8 @@ int kvmhv_p9_tm_emulation(struct kvm_vcpu *vcpu) vcpu->arch.bescr = bescr; msr = (msr & ~MSR_TS_MASK ) |MSR_TS_T ; vcpu->arch.shregs.msr = msr; - vcpu->arch.cfar = vcpu->arch.pc -4 ; - vcpu->arch.pc = vcpu->arch.ebbrr; + vcpu->arch.cfar = vcpu->arch.regs.nip -4 ; + vcpu->arch.regs.nip = vcpu->arch.ebbrr;return RESUME_GUEST ;case PPC_INST_MTMSRD :
arch/powerpc/kvm/book3s_hv_tm_builtin.c +5 -5
@@ -35,8 +35,8 @@ int kvmhv_p9_tm_emulation_early(struct kvm_vcpu *vcpu)return 0 ; newmsr =sanitize_msr (newmsr); vcpu->arch.shregs.msr = newmsr; - vcpu->arch.cfar = vcpu->arch.pc -4 ; - vcpu->arch.pc = vcpu->arch.shregs.srr0; + vcpu->arch.cfar = vcpu->arch.regs.nip -4 ; + vcpu->arch.regs.nip = vcpu->arch.shregs.srr0;return 1 ;case PPC_INST_RFEBB :
@@ -58,8 +58,8 @@ int kvmhv_p9_tm_emulation_early(struct kvm_vcpu *vcpu)mtspr (SPRN_BESCR , bescr); msr = (msr & ~MSR_TS_MASK ) |MSR_TS_T ; vcpu->arch.shregs.msr = msr; - vcpu->arch.cfar = vcpu->arch.pc -4 ; - vcpu->arch.pc =mfspr (SPRN_EBBRR ); + vcpu->arch.cfar = vcpu->arch.regs.nip -4 ; + vcpu->arch.regs.nip =mfspr (SPRN_EBBRR );return 1 ;case PPC_INST_MTMSRD :
@@ -103,7 +103,7 @@ int kvmhv_p9_tm_emulation_early(struct kvm_vcpu *vcpu)void kvmhv_emulate_tm_rollback (struct kvm_vcpu *vcpu) { vcpu->arch.shregs.msr &= ~MSR_TS_MASK ;/* go to N state */ - vcpu->arch.pc = vcpu->arch.tfhar; + vcpu->arch.regs.nip = vcpu->arch.tfhar;copy_from_checkpoint (vcpu); vcpu->arch.cr = (vcpu->arch.cr &0x0fffffff ) |0xa0000000 ; }
arch/powerpc/kvm/book3s_pr.c +8 -8
@@ -162,10 +162,10 @@ void kvmppc_copy_to_svcpu(struct kvm_vcpu *vcpu) svcpu->gpr[12 ] = vcpu->arch.regs.gpr[12 ]; svcpu->gpr[13 ] = vcpu->arch.regs.gpr[13 ]; svcpu->cr = vcpu->arch.cr; - svcpu->xer = vcpu->arch.xer; - svcpu->ctr = vcpu->arch.ctr; - svcpu->lr = vcpu->arch.lr; - svcpu->pc = vcpu->arch.pc; + svcpu->xer = vcpu->arch.regs.xer; + svcpu->ctr = vcpu->arch.regs.ctr; + svcpu->lr = vcpu->arch.regs.link; + svcpu->pc = vcpu->arch.regs.nip;#ifdef CONFIG_PPC_BOOK3S_64 svcpu->shadow_fscr = vcpu->arch.shadow_fscr;#endif
@@ -209,10 +209,10 @@ void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu) vcpu->arch.regs.gpr[12 ] = svcpu->gpr[12 ]; vcpu->arch.regs.gpr[13 ] = svcpu->gpr[13 ]; vcpu->arch.cr = svcpu->cr; - vcpu->arch.xer = svcpu->xer; - vcpu->arch.ctr = svcpu->ctr; - vcpu->arch.lr = svcpu->lr; - vcpu->arch.pc = svcpu->pc; + vcpu->arch.regs.xer = svcpu->xer; + vcpu->arch.regs.ctr = svcpu->ctr; + vcpu->arch.regs.link = svcpu->lr; + vcpu->arch.regs.nip = svcpu->pc; vcpu->arch.shadow_srr1 = svcpu->shadow_srr1; vcpu->arch.fault_dar = svcpu->fault_dar; vcpu->arch.fault_dsisr = svcpu->fault_dsisr;
arch/powerpc/kvm/booke.c +22 -19
116 lines not on this page · raw message
arch/powerpc/kvm/booke_emulate.c +3 -3
@@ -34,19 +34,19 @@static void kvmppc_emul_rfi (struct kvm_vcpu *vcpu) { - vcpu->arch.pc = vcpu->arch.shared->srr0; + vcpu->arch.regs.nip = vcpu->arch.shared->srr0;kvmppc_set_msr (vcpu, vcpu->arch.shared->srr1); }static void kvmppc_emul_rfdi (struct kvm_vcpu *vcpu) { - vcpu->arch.pc = vcpu->arch.dsrr0; + vcpu->arch.regs.nip = vcpu->arch.dsrr0;kvmppc_set_msr (vcpu, vcpu->arch.dsrr1); }static void kvmppc_emul_rfci (struct kvm_vcpu *vcpu) { - vcpu->arch.pc = vcpu->arch.csrr0; + vcpu->arch.regs.nip = vcpu->arch.csrr0;kvmppc_set_msr (vcpu, vcpu->arch.csrr1); }
arch/powerpc/kvm/e500_emulate.c +1 -1
@@ -94,7 +94,7 @@ static int kvmppc_e500_emul_ehpriv(struct kvm_run *run, struct kvm_vcpu *vcpu,switch (get_oc (inst)) {case EHPRIV_OC_DEBUG : run->exit_reason =KVM_EXIT_DEBUG ; - run->debug.arch.address = vcpu->arch.pc; + run->debug.arch.address = vcpu->arch.regs.nip; run->debug.arch.status =0 ;kvmppc_account_exit (vcpu,DEBUG_EXITS ); emulated =EMULATE_EXIT_USER ;
arch/powerpc/kvm/e500_mmu.c +1 -1
@@ -513,7 +513,7 @@ void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu) {unsigned int as = !!(vcpu->arch.shared->msr &MSR_IS ); -kvmppc_e500_deliver_tlb_miss (vcpu, vcpu->arch.pc, as); +kvmppc_e500_deliver_tlb_miss (vcpu, vcpu->arch.regs.nip, as); }void kvmppc_mmu_dtlb_miss (struct kvm_vcpu *vcpu)
Signature · 1 line
1.8.3.1
PATCH v2 3/10 KVM: PPC: Fix a mmio_host_swabbed uninitialized usage issue when VMX store
In reply to [email protected]From: Simon Guo <[email protected]>
When KVM emulates VMX store, it will invoke kvmppc_get_vmx_data() to retrieve VMX reg val. kvmppc_get_vmx_data() will check mmio_host_swabbed to decide which double word of vr[] to be used. But the mmio_host_swabbed can be uninitiazed during VMX store procedure:
kvmppc_emulate_loadstore
\- kvmppc_handle_store128_by2x64 \- kvmppc_get_vmx_data
So vcpu->arch.mmio_host_swabbed is not meant to be used at all for emulation of store instructions, and this patch makes that true for VMX stores. This patch also initializes mmio_host_swabbed to avoid invisble trouble.
--- arch/powerpc/kvm/emulate_loadstore.c | 1 + arch/powerpc/kvm/powerpc.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/kvm/emulate_loadstore.c +1 -0
@@ -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_host_swabbed =0 ;switch (get_op (inst)) {case 31 :
arch/powerpc/kvm/powerpc.c +1 -1
@@ -1374,7 +1374,7 @@ static inline int kvmppc_get_vmx_data(struct kvm_vcpu *vcpu, int rs, u64 *val)if (di >1 )return -1 ; -if (vcpu->arch.mmio_host_swabbed) +if (kvmppc_need_byteswap (vcpu)) di =1 - di; w0 = vrs.u[di *2 ];
Signature · 1 line
1.8.3.1
PATCH v2 4/10 KVM: PPC: add KVMPPC_VSX_COPY_WORD_LOAD_DUMP type support for mmio emulation
In reply to [email protected]From: Simon Guo <[email protected]>
Some VSX instruction like lxvwsx will splat word into VSR. This patch adds VSX copy type KVMPPC_VSX_COPY_WORD_LOAD_DUMP to support this.
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kvm/powerpc.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -454,6 +454,7 @@ struct mmio_hpte_cache {#define KVMPPC_VSX_COPY_WORD 1#define KVMPPC_VSX_COPY_DWORD 2#define KVMPPC_VSX_COPY_DWORD_LOAD_DUMP 3 +#define KVMPPC_VSX_COPY_WORD_LOAD_DUMP 4struct openpic ;
arch/powerpc/kvm/powerpc.c +23 -0
@@ -907,6 +907,26 @@ static inline void kvmppc_set_vsr_dword_dump(struct kvm_vcpu *vcpu, } } +static inline void kvmppc_set_vsr_word_dump (struct kvm_vcpu *vcpu, +u32 gpr) +{ +union kvmppc_one_reg val; +int index = vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ; + +if (vcpu->arch.mmio_vsx_tx_sx_enabled) { + val.vsx32val[0 ] = gpr; + val.vsx32val[1 ] = gpr; + val.vsx32val[2 ] = gpr; + val.vsx32val[3 ] = gpr; +VCPU_VSX_VR (vcpu, index) = val.vval; + }else { + val.vsx32val[0 ] = gpr; + val.vsx32val[1 ] = gpr; +VCPU_VSX_FPR (vcpu, index,0 ) = val.vsxval[0 ]; +VCPU_VSX_FPR (vcpu, index,1 ) = val.vsxval[0 ]; + } +} +static inline void kvmppc_set_vsr_word (struct kvm_vcpu *vcpu,u32 gpr32) {
@@ -1061,6 +1081,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu, else if (vcpu->arch.mmio_vsx_copy_type == KVMPPC_VSX_COPY_DWORD_LOAD_DUMP) kvmppc_set_vsr_dword_dump(vcpu, gpr); + else if (vcpu->arch.mmio_vsx_copy_type == + KVMPPC_VSX_COPY_WORD_LOAD_DUMP) + kvmppc_set_vsr_word_dump(vcpu, gpr);break ;#endif #ifdef CONFIG_ALTIVEC
Signature · 1 line
1.8.3.1
PATCH v2 5/10 KVM: PPC: reimplement non-SIMD LOAD/STORE instruction mmio emulation with analyse_intr() input
In reply to [email protected]From: Simon Guo <[email protected]>
This patch reimplements non-SIMD LOAD/STORE instruction MMIO emulation with analyse_intr() input. It utilizes the BYTEREV/UPDATE/SIGNEXT properties exported by analyse_instr() and invokes kvmppc_handle_load(s)/kvmppc_handle_store() accordingly.
It also move CACHEOP type handling into the skeleton.
instruction_type within kvm_ppc.h is renamed to avoid conflict with sstep.h.
--- arch/powerpc/include/asm/kvm_ppc.h | 6 +- arch/powerpc/kvm/book3s.c | 4 +- arch/powerpc/kvm/e500_mmu_host.c | 8 +- arch/powerpc/kvm/emulate_loadstore.c | 271 ++++++----------------------------- 4 files changed, 51 insertions(+), 238 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +3 -3
@@ -52,7 +52,7 @@ enum emulation_result { EMULATE_EXIT_USER, /* emulation requires exit to user-space */ }; -enum instruction_type { +enum instruction_fetch_type {INST_GENERIC ,INST_SC ,/* system call */ };
@@ -93,7 +93,7 @@ extern int kvmppc_handle_vsx_store(struct kvm_run *run, struct kvm_vcpu *vcpu, int is_default_endian);extern int kvmppc_load_last_inst (struct kvm_vcpu *vcpu, -enum instruction_type type,u32 *inst); +enum instruction_fetch_type type,u32 *inst);extern int kvmppc_ld (struct kvm_vcpu *vcpu,ulong *eaddr,int size,void *ptr,bool data);
@@ -330,7 +330,7 @@ struct kvmppc_ops {extern struct kvmppc_ops *kvmppc_pr_ops;static inline int kvmppc_get_last_inst (struct kvm_vcpu *vcpu, -enum instruction_type type,u32 *inst) +enum instruction_fetch_type type,u32 *inst) {int ret =EMULATE_DONE ;u32 fetched_inst;
arch/powerpc/kvm/book3s.c +2 -2
@@ -450,8 +450,8 @@ int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, enum xlate_instdata xlid,return r; } -int kvmppc_load_last_inst (struct kvm_vcpu *vcpu,enum instruction_type type, -u32 *inst) +int kvmppc_load_last_inst (struct kvm_vcpu *vcpu, +enum instruction_fetch_type type,u32 *inst) {ulong pc =kvmppc_get_pc (vcpu);int r;
arch/powerpc/kvm/e500_mmu_host.c +4 -4
@@ -625,8 +625,8 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, }#ifdef CONFIG_KVM_BOOKE_HV -int kvmppc_load_last_inst (struct kvm_vcpu *vcpu,enum instruction_type type, -u32 *instr) +int kvmppc_load_last_inst (struct kvm_vcpu *vcpu, +enum instruction_fetch_type type,u32 *instr) {gva_t geaddr;hpa_t addr;
@@ -715,8 +715,8 @@ int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, enum instruction_type type, return EMULATE_DONE; }#else -int kvmppc_load_last_inst (struct kvm_vcpu *vcpu,enum instruction_type type, -u32 *instr) +int kvmppc_load_last_inst (struct kvm_vcpu *vcpu, +enum instruction_fetch_type type,u32 *instr) {return EMULATE_AGAIN ; }
arch/powerpc/kvm/emulate_loadstore.c +42 -229
326 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 6/10 KVM: PPC: add giveup_ext() hook for PPC KVM ops
In reply to [email protected]From: Simon Guo <[email protected]>
Currently HV will save math regs(FP/VEC/VSX) when trap into host. But PR KVM will only save math regs when qemu task switch out of CPU, or when returning from qemu code.
To emulate FP/VEC/VSX mmio load, PR KVM need to make sure that math regs were flushed firstly and then be able to update saved VCPU FPR/VEC/VSX area reasonably.
This patch adds giveup_ext() field to KVM ops and PR KVM has non-NULL giveup_ext() ops. kvmppc_complete_mmio_load() can invoke that hook (when not NULL) to flush math regs accordingly, before updating saved register vals.
Math regs flush is also necessary for STORE, which will be covered in later patch within this patch series.
--- arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kvm/book3s_pr.c | 1 + arch/powerpc/kvm/powerpc.c | 9 +++++++++ 3 files changed, 11 insertions(+)
arch/powerpc/include/asm/kvm_ppc.h +1 -0
@@ -324,6 +324,7 @@ struct kvmppc_ops {int (*get_rmmu_info)(struct kvm *kvm,struct kvm_ppc_rmmu_info *info);int (*set_smt_mode)(struct kvm *kvm,unsigned long mode,unsigned long flags); +void (*giveup_ext)(struct kvm_vcpu *vcpu,ulong msr); };extern struct kvmppc_ops *kvmppc_hv_ops;
arch/powerpc/kvm/book3s_pr.c +1 -0
@@ -1782,6 +1782,7 @@ static long kvm_arch_vm_ioctl_pr(struct file *filp,#ifdef CONFIG_PPC_BOOK3S_64 .hcall_implemented = kvmppc_hcall_impl_pr, #endif + .giveup_ext = kvmppc_giveup_ext, };
arch/powerpc/kvm/powerpc.c +9 -0
@@ -1061,6 +1061,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,kvmppc_set_gpr (vcpu, vcpu->arch.io_gpr, gpr);break ;case KVM_MMIO_REG_FPR : +if (vcpu->kvm->arch.kvm_ops->giveup_ext) + vcpu->kvm->arch.kvm_ops->giveup_ext (vcpu,MSR_FP ); +VCPU_FPR (vcpu, vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ) = gpr;break ;#ifdef CONFIG_PPC_BOOK3S
@@ -1074,6 +1077,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,#endif #ifdef CONFIG_VSX case KVM_MMIO_REG_VSX : +if (vcpu->kvm->arch.kvm_ops->giveup_ext) + vcpu->kvm->arch.kvm_ops->giveup_ext (vcpu,MSR_VSX ); +if (vcpu->arch.mmio_vsx_copy_type ==KVMPPC_VSX_COPY_DWORD )kvmppc_set_vsr_dword (vcpu, gpr);else if (vcpu->arch.mmio_vsx_copy_type ==KVMPPC_VSX_COPY_WORD )
@@ -1088,6 +1094,9 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,#endif #ifdef CONFIG_ALTIVEC case KVM_MMIO_REG_VMX : +if (vcpu->kvm->arch.kvm_ops->giveup_ext) + vcpu->kvm->arch.kvm_ops->giveup_ext (vcpu,MSR_VEC ); +kvmppc_set_vmx_dword (vcpu, gpr);break ;#endif
Signature · 1 line
1.8.3.1
PATCH v2 7/10 KVM: PPC: reimplement LOAD_FP/STORE_FP instruction mmio emulation with analyse_intr() input
In reply to [email protected]From: Simon Guo <[email protected]>
This patch reimplements LOAD_FP/STORE_FP instruction MMIO emulation with analyse_intr() input. It utilizes the FPCONV/UPDATE properties exported by analyse_instr() and invokes kvmppc_handle_load(s)/kvmppc_handle_store() accordingly.
For FP store MMIO emulation, the FP regs need to be flushed firstly so that the right FP reg vals can be read from vcpu->arch.fpr, which will be stored into MMIO data.
--- arch/powerpc/kvm/emulate_loadstore.c | 197 +++++++---------------------------- 1 file changed, 40 insertions(+), 157 deletions(-)
arch/powerpc/kvm/emulate_loadstore.c +40 -157
@@ -138,6 +138,22 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)break ; } +#ifdef CONFIG_PPC_FPU +case LOAD_FP : +if (kvmppc_check_fp_disabled (vcpu)) +return EMULATE_DONE ; + +if (op.type &FPCONV ) + vcpu->arch.mmio_sp64_extend =1 ; + + emulated =kvmppc_handle_load (run, vcpu, +KVM_MMIO_REG_FPR |op.reg, size,1 ); + +if ((op.type &UPDATE ) && (emulated !=EMULATE_FAIL )) +kvmppc_set_gpr (vcpu, op.update_reg, op.ea); + +break ; +#endif case STORE :/* if need byte reverse, op.val has been reversed by * analyse_instr().
@@ -149,6 +165,30 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)kvmppc_set_gpr (vcpu, op.update_reg, op.ea);break ; +#ifdef CONFIG_PPC_FPU +case STORE_FP : +if (kvmppc_check_fp_disabled (vcpu)) +return EMULATE_DONE ; + +/* The FP registers need to be flushed so that +* kvmppc_handle_store() can read actual FP vals +* from vcpu->arch. +*/ +if (vcpu->kvm->arch.kvm_ops->giveup_ext) + vcpu->kvm->arch.kvm_ops->giveup_ext (vcpu, +MSR_FP ); + +if (op.type &FPCONV ) + vcpu->arch.mmio_sp64_extend =1 ; + + emulated =kvmppc_handle_store (run, vcpu, +VCPU_FPR (vcpu, op.reg), size,1 ); + +if ((op.type &UPDATE ) && (emulated !=EMULATE_FAIL )) +kvmppc_set_gpr (vcpu, op.update_reg, op.ea); + +break ; +#endif case CACHEOP :/* Do nothing. The guest is performing dcbi because * hardware DMA is not snooped by the dcache, but
@@ -170,93 +210,6 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)switch (get_op (inst)) {case 31 :switch (get_xop (inst)) { -#ifdef CONFIG_PPC_FPU -case OP_31_XOP_LFSX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,4 ,1 ); -break ; - -case OP_31_XOP_LFSUX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,4 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; - -case OP_31_XOP_LFDX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,8 ,1 ); -break ; - -case OP_31_XOP_LFDUX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,8 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; - -case OP_31_XOP_LFIWAX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_loads (run, vcpu, -KVM_MMIO_REG_FPR |rt,4 ,1 ); -break ; - -case OP_31_XOP_LFIWZX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,4 ,1 ); -break ; - -case OP_31_XOP_STFSX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs),4 ,1 ); -break ; - -case OP_31_XOP_STFSUX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs),4 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; - -case OP_31_XOP_STFDX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs),8 ,1 ); -break ; - -case OP_31_XOP_STFDUX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs),8 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; - -case OP_31_XOP_STFIWX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs),4 ,1 ); -break ; -#endif -#ifdef CONFIG_VSX case OP_31_XOP_LXSDX :if (kvmppc_check_vsx_disabled (vcpu))
@@ -421,76 +374,6 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) }break ; -#ifdef CONFIG_PPC_FPU -case OP_STFS : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs), -4 ,1 ); -break ; - -case OP_STFSU : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs), -4 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; - -case OP_STFD : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs), -8 ,1 ); -break ; - -case OP_STFDU : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_store (run, vcpu, -VCPU_FPR (vcpu, rs), -8 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; - -case OP_LFS : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,4 ,1 ); -break ; - -case OP_LFSU : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,4 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; - -case OP_LFD : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,8 ,1 ); -break ; - -case OP_LFDU : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_load (run, vcpu, -KVM_MMIO_REG_FPR |rt,8 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; -#endif -default : emulated =EMULATE_FAIL ;break ;
Signature · 1 line
1.8.3.1
PATCH v2 8/10 KVM: PPC: reimplements LOAD_VSX/STORE_VSX instruction mmio emulation with analyse_intr() input
In reply to [email protected]From: Simon Guo <[email protected]>
This patch reimplements LOAD_VSX/STORE_VSX instruction MMIO emulation with analyse_intr() input. It utilizes VSX_FPCONV/VSX_SPLAT/SIGNEXT exported by analyse_instr() and handle accordingly.
When emulating VSX store, the VSX reg will need to be flushed so that the right reg val can be retrieved before writing to IO MEM.
--- arch/powerpc/kvm/emulate_loadstore.c | 227 ++++++++++++++--------------------- 1 file changed, 91 insertions(+), 136 deletions(-)
arch/powerpc/kvm/emulate_loadstore.c +91 -136
@@ -154,6 +154,54 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)break ;#endif +#ifdef CONFIG_VSX +case LOAD_VSX : { +int io_size_each; + +if (op.vsx_flags &VSX_CHECK_VEC ) { +if (kvmppc_check_altivec_disabled (vcpu)) +return EMULATE_DONE ; + }else { +if (kvmppc_check_vsx_disabled (vcpu)) +return EMULATE_DONE ; + } + +if (op.vsx_flags &VSX_FPCONV ) + vcpu->arch.mmio_sp64_extend =1 ; + +if (op.element_size ==8 ) { +if (op.vsx_flags &VSX_SPLAT ) + vcpu->arch.mmio_vsx_copy_type = +KVMPPC_VSX_COPY_DWORD_LOAD_DUMP ; +else + vcpu->arch.mmio_vsx_copy_type = +KVMPPC_VSX_COPY_DWORD ; + }else if (op.element_size ==4 ) { +if (op.vsx_flags &VSX_SPLAT ) + vcpu->arch.mmio_vsx_copy_type = +KVMPPC_VSX_COPY_WORD_LOAD_DUMP ; +else + vcpu->arch.mmio_vsx_copy_type = +KVMPPC_VSX_COPY_WORD ; + }else +break ; + +if (size < op.element_size) { +/* precision convert case: lxsspx, etc */ + vcpu->arch.mmio_vsx_copy_nums =1 ; + io_size_each = size; + }else {/* lxvw4x, lxvd2x, etc */ + vcpu->arch.mmio_vsx_copy_nums = + size/op.element_size; + io_size_each = op.element_size; + } + + emulated =kvmppc_handle_vsx_load (run, vcpu, +KVM_MMIO_REG_VSX |op.reg, io_size_each, +1 , op.type &SIGNEXT ); +break ; + } +#endif case STORE :/* if need byte reverse, op.val has been reversed by * analyse_instr().
@@ -189,6 +237,49 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)break ;#endif +#ifdef CONFIG_VSX +case STORE_VSX : { +int io_size_each; + +if (op.vsx_flags &VSX_CHECK_VEC ) { +if (kvmppc_check_altivec_disabled (vcpu)) +return EMULATE_DONE ; + }else { +if (kvmppc_check_vsx_disabled (vcpu)) +return EMULATE_DONE ; + } + +if (vcpu->kvm->arch.kvm_ops->giveup_ext) + vcpu->kvm->arch.kvm_ops->giveup_ext (vcpu, +MSR_VSX ); + +if (op.vsx_flags &VSX_FPCONV ) + vcpu->arch.mmio_sp64_extend =1 ; + +if (op.element_size ==8 ) + vcpu->arch.mmio_vsx_copy_type = +KVMPPC_VSX_COPY_DWORD ; +else if (op.element_size ==4 ) + vcpu->arch.mmio_vsx_copy_type = +KVMPPC_VSX_COPY_WORD ; +else +break ; + +if (size < op.element_size) { +/* precise conversion case, like stxsspx */ + vcpu->arch.mmio_vsx_copy_nums =1 ; + io_size_each = size; + }else {/* stxvw4x, stxvd2x, etc */ + vcpu->arch.mmio_vsx_copy_nums = + size/op.element_size; + io_size_each = op.element_size; + } + + emulated =kvmppc_handle_vsx_store (run, vcpu, + op.reg, io_size_each,1 ); +break ; + } +#endif case CACHEOP :/* Do nothing. The guest is performing dcbi because * hardware DMA is not snooped by the dcache, but
@@ -210,142 +301,6 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)switch (get_op (inst)) {case 31 :switch (get_xop (inst)) { -#ifdef CONFIG_VSX -case OP_31_XOP_LXSDX : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =1 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_DWORD ; - emulated =kvmppc_handle_vsx_load (run, vcpu, -KVM_MMIO_REG_VSX |rt,8 ,1 ,0 ); -break ; - -case OP_31_XOP_LXSSPX : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =1 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_DWORD ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_vsx_load (run, vcpu, -KVM_MMIO_REG_VSX |rt,4 ,1 ,0 ); -break ; - -case OP_31_XOP_LXSIWAX : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =1 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_DWORD ; - emulated =kvmppc_handle_vsx_load (run, vcpu, -KVM_MMIO_REG_VSX |rt,4 ,1 ,1 ); -break ; - -case OP_31_XOP_LXSIWZX : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =1 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_DWORD ; - emulated =kvmppc_handle_vsx_load (run, vcpu, -KVM_MMIO_REG_VSX |rt,4 ,1 ,0 ); -break ; - -case OP_31_XOP_LXVD2X : -/* -* In this case, the official load/store process is like this: -* Step1, exit from vm by page fault isr, then kvm save vsr. -* Please see guest_exit_cont->store_fp_state->SAVE_32VSRS -* as reference. -* -* Step2, copy data between memory and VCPU -* Notice: for LXVD2X/STXVD2X/LXVW4X/STXVW4X, we use -* 2copies*8bytes or 4copies*4bytes -* to simulate one copy of 16bytes. -* Also there is an endian issue here, we should notice the -* layout of memory. -* Please see MARCO of LXVD2X_ROT/STXVD2X_ROT as more reference. -* If host is little-endian, kvm will call XXSWAPD for -* LXVD2X_ROT/STXVD2X_ROT. -* So, if host is little-endian, -* the postion of memeory should be swapped. -* -* Step3, return to guest, kvm reset register. -* Please see kvmppc_hv_entry->load_fp_state->REST_32VSRS -* as reference. -*/ -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =2 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_DWORD ; - emulated =kvmppc_handle_vsx_load (run, vcpu, -KVM_MMIO_REG_VSX |rt,8 ,1 ,0 ); -break ; - -case OP_31_XOP_LXVW4X : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =4 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_WORD ; - emulated =kvmppc_handle_vsx_load (run, vcpu, -KVM_MMIO_REG_VSX |rt,4 ,1 ,0 ); -break ; - -case OP_31_XOP_LXVDSX : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =1 ; - vcpu->arch.mmio_vsx_copy_type = -KVMPPC_VSX_COPY_DWORD_LOAD_DUMP ; - emulated =kvmppc_handle_vsx_load (run, vcpu, -KVM_MMIO_REG_VSX |rt,8 ,1 ,0 ); -break ; - -case OP_31_XOP_STXSDX : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =1 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_DWORD ; - emulated =kvmppc_handle_vsx_store (run, vcpu, - rs,8 ,1 ); -break ; - -case OP_31_XOP_STXSSPX : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =1 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_DWORD ; - vcpu->arch.mmio_sp64_extend =1 ; - emulated =kvmppc_handle_vsx_store (run, vcpu, - rs,4 ,1 ); -break ; - -case OP_31_XOP_STXSIWX : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_offset =1 ; - vcpu->arch.mmio_vsx_copy_nums =1 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_WORD ; - emulated =kvmppc_handle_vsx_store (run, vcpu, - rs,4 ,1 ); -break ; - -case OP_31_XOP_STXVD2X : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =2 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_DWORD ; - emulated =kvmppc_handle_vsx_store (run, vcpu, - rs,8 ,1 ); -break ; - -case OP_31_XOP_STXVW4X : -if (kvmppc_check_vsx_disabled (vcpu)) -return EMULATE_DONE ; - vcpu->arch.mmio_vsx_copy_nums =4 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_WORD ; - emulated =kvmppc_handle_vsx_store (run, vcpu, - rs,4 ,1 ); -break ; -#endif /* CONFIG_VSX */ -#ifdef CONFIG_ALTIVEC case OP_31_XOP_LVX :if (kvmppc_check_altivec_disabled (vcpu))
Signature · 1 line
1.8.3.1
PATCH v2 9/10 KVM: PPC: expand mmio_vsx_copy_type to mmio_copy_type to cover VMX load/store elem types
In reply to [email protected]From: Simon Guo <[email protected]>
VSX MMIO emulation uses mmio_vsx_copy_type to represent VSX emulated element size/type, such as KVMPPC_VSX_COPY_DWORD_LOAD, etc. This patch expands mmio_vsx_copy_type to cover VMX copy type, such as KVMPPC_VMX_COPY_BYTE(stvebx/lvebx), etc. As a result, mmio_vsx_copy_type is also renamed to mmio_copy_type.
It is a preparation for reimplement VMX MMIO emulation.
--- arch/powerpc/include/asm/kvm_host.h | 9 +++++++-- arch/powerpc/kvm/emulate_loadstore.c | 14 +++++++------- arch/powerpc/kvm/powerpc.c | 10 +++++----- 3 files changed, 19 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/kvm_host.h +7 -2
@@ -456,6 +456,11 @@ struct mmio_hpte_cache {#define KVMPPC_VSX_COPY_DWORD_LOAD_DUMP 3#define KVMPPC_VSX_COPY_WORD_LOAD_DUMP 4 +#define KVMPPC_VMX_COPY_BYTE 8 +#define KVMPPC_VMX_COPY_HWORD 9 +#define KVMPPC_VMX_COPY_WORD 10 +#define KVMPPC_VMX_COPY_DWORD 11 +struct openpic ;/* W0 and W1 of a XIVE thread management context */
@@ -678,16 +683,16 @@ struct kvm_vcpu_arch {* Number of simulations for vsx. * If we use 2*8bytes to simulate 1*16bytes, * then the number should be 2 and -* mmio_vsx_copy_type=KVMPPC_VSX_COPY_DWORD. +* mmio_copy_type=KVMPPC_VSX_COPY_DWORD. * If we use 4*4bytes to simulate 1*16bytes, * the number should be 4 and * mmio_vsx_copy_type=KVMPPC_VSX_COPY_WORD. */ u8 mmio_vsx_copy_nums;u8 mmio_vsx_offset; -u8 mmio_vsx_copy_type;u8 mmio_vsx_tx_sx_enabled;u8 mmio_vmx_copy_nums; +u8 mmio_copy_type;u8 osi_needed;u8 osi_enabled;u8 papr_enabled;
arch/powerpc/kvm/emulate_loadstore.c +7 -7
@@ -109,7 +109,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) vcpu->arch.mmio_vsx_tx_sx_enabled =get_tx_or_sx (inst); vcpu->arch.mmio_vsx_copy_nums =0 ; vcpu->arch.mmio_vsx_offset =0 ; - vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_NONE ; + vcpu->arch.mmio_copy_type =KVMPPC_VSX_COPY_NONE ; vcpu->arch.mmio_sp64_extend =0 ; vcpu->arch.mmio_sign_extend =0 ; vcpu->arch.mmio_vmx_copy_nums =0 ;
@@ -171,17 +171,17 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)if (op.element_size ==8 ) {if (op.vsx_flags &VSX_SPLAT ) - vcpu->arch.mmio_vsx_copy_type = + vcpu->arch.mmio_copy_type =KVMPPC_VSX_COPY_DWORD_LOAD_DUMP ;else - vcpu->arch.mmio_vsx_copy_type = + vcpu->arch.mmio_copy_type =KVMPPC_VSX_COPY_DWORD ; }else if (op.element_size ==4 ) {if (op.vsx_flags &VSX_SPLAT ) - vcpu->arch.mmio_vsx_copy_type = + vcpu->arch.mmio_copy_type =KVMPPC_VSX_COPY_WORD_LOAD_DUMP ;else - vcpu->arch.mmio_vsx_copy_type = + vcpu->arch.mmio_copy_type =KVMPPC_VSX_COPY_WORD ; }else break ;
@@ -257,10 +257,10 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) vcpu->arch.mmio_sp64_extend =1 ;if (op.element_size ==8 ) - vcpu->arch.mmio_vsx_copy_type = + vcpu->arch.mmio_copy_type =KVMPPC_VSX_COPY_DWORD ;else if (op.element_size ==4 ) - vcpu->arch.mmio_vsx_copy_type = + vcpu->arch.mmio_copy_type =KVMPPC_VSX_COPY_WORD ;else break ;
arch/powerpc/kvm/powerpc.c +5 -5
@@ -1080,14 +1080,14 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,if (vcpu->kvm->arch.kvm_ops->giveup_ext) vcpu->kvm->arch.kvm_ops->giveup_ext (vcpu,MSR_VSX ); -if (vcpu->arch.mmio_vsx_copy_type ==KVMPPC_VSX_COPY_DWORD ) +if (vcpu->arch.mmio_copy_type ==KVMPPC_VSX_COPY_DWORD )kvmppc_set_vsr_dword (vcpu, gpr); -else if (vcpu->arch.mmio_vsx_copy_type ==KVMPPC_VSX_COPY_WORD ) +else if (vcpu->arch.mmio_copy_type ==KVMPPC_VSX_COPY_WORD )kvmppc_set_vsr_word (vcpu, gpr); -else if (vcpu->arch.mmio_vsx_copy_type == +else if (vcpu->arch.mmio_copy_type ==KVMPPC_VSX_COPY_DWORD_LOAD_DUMP )kvmppc_set_vsr_dword_dump (vcpu, gpr); -else if (vcpu->arch.mmio_vsx_copy_type == +else if (vcpu->arch.mmio_copy_type ==KVMPPC_VSX_COPY_WORD_LOAD_DUMP )kvmppc_set_vsr_word_dump (vcpu, gpr);break ;
@@ -1260,7 +1260,7 @@ static inline int kvmppc_get_vsr_data(struct kvm_vcpu *vcpu, int rs, u64 *val)u32 dword_offset, word_offset;union kvmppc_one_reg reg;int vsx_offset =0 ; -int copy_type = vcpu->arch.mmio_vsx_copy_type; +int copy_type = vcpu->arch.mmio_copy_type;int result =0 ;switch (copy_type) {
Signature · 1 line
1.8.3.1
PATCH v2 10/10 KVM: PPC: reimplements LOAD_VMX/STORE_VMX instruction mmio emulation with analyse_intr() input
In reply to [email protected]From: Simon Guo <[email protected]>
This patch reimplements LOAD_VMX/STORE_VMX MMIO emulation with analyse_intr() input. When emulating the store, the VMX reg will need to be flushed so that the right reg val can be retrieved before writing to IO MEM.
This patch also adds support for lvebx/lvehx/lvewx/stvebx/stvehx/stvewx MMIO emulation. To meet the requirement of handling different element sizes, kvmppc_handle_load128_by2x64()/kvmppc_handle_store128_by2x64() were replaced with kvmppc_handle_vmx_load()/kvmppc_handle_vmx_store().
The framework used is the similar with VSX instruction mmio emulation.
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/kvm_ppc.h | 10 +- arch/powerpc/kvm/emulate_loadstore.c | 124 +++++++++++------ arch/powerpc/kvm/powerpc.c | 259 ++++++++++++++++++++++++++++------- 4 files changed, 302 insertions(+), 92 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -692,6 +692,7 @@ struct kvm_vcpu_arch {u8 mmio_vsx_offset;u8 mmio_vsx_tx_sx_enabled;u8 mmio_vmx_copy_nums; +u8 mmio_vmx_offset;u8 mmio_copy_type;u8 osi_needed;u8 osi_enabled;
arch/powerpc/include/asm/kvm_ppc.h +6 -4
@@ -81,10 +81,10 @@ extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,extern int kvmppc_handle_vsx_load (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int rt,unsigned int bytes,int is_default_endian,int mmio_sign_extend); -extern int kvmppc_handle_load128_by2x64 (struct kvm_run *run, -struct kvm_vcpu *vcpu,unsigned int rt,int is_default_endian); -extern int kvmppc_handle_store128_by2x64 (struct kvm_run *run, -struct kvm_vcpu *vcpu,unsigned int rs,int is_default_endian); +extern int kvmppc_handle_vmx_load (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int rt,unsigned int bytes,int is_default_endian); +extern int kvmppc_handle_vmx_store (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int rs,unsigned int bytes,int is_default_endian);extern int kvmppc_handle_store (struct kvm_run *run,struct kvm_vcpu *vcpu,u64 val,unsigned int bytes,int is_default_endian);
@@ -265,6 +265,8 @@ extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, u32 *server,vector128 vval;u64 vsxval[2 ];u32 vsx32val[4 ]; +u16 vsx16val[8 ]; +u8 vsx8val[16 ];struct {u64 addr;u64 length;
arch/powerpc/kvm/emulate_loadstore.c +83 -41
148 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +212 -47
337 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH v2 05/10] KVM: PPC: reimplement non-SIMD LOAD/STORE instruction mmio emulation with analyse_intr() input
In reply to [email protected]Quoted 7 lines · On Mon, May 07, 2018 at 02:20:11PM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
This patch reimplements non-SIMD LOAD/STORE instruction MMIO emulation with
analyse_intr()input. It utilizes the BYTEREV/UPDATE/SIGNEXT properties exported byanalyse_instr()and invokes kvmppc_handle_load(s)/kvmppc_handle_store() accordingly.
Quoted 7 lines
It also move CACHEOP type handling into the skeleton.
instruction_typewithinkvm_ppc.his renamed to avoid conflict withsstep.h.Suggested-by Paul Mackerras <[email protected]>Signed-off-by Simon Guo <[email protected]>
Looks pretty good, but one comment below...
arch/powerpc/kvm/emulate_loadstore.c int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) · line 168
Quoted 6 lines
arch/powerpc/kvm/emulate_loadstore.c +2
-4-case OP_31_XOP_LWAUX : - emulated =kvmppc_handle_loads (run, vcpu, rt,4 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; +if (emulated ==EMULATE_DONE ) + goto out;
Shouldn't this also goto out if emulated == EMULATE_DO_MMIO?
Paul.
Re: [PATCH v2 07/10] KVM: PPC: reimplement LOAD_FP/STORE_FP instruction mmio emulation with analyse_intr() input
In reply to [email protected]Quoted 7 lines · On Mon, May 07, 2018 at 02:20:13PM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
This patch reimplements LOAD_FP/STORE_FP instruction MMIO emulation with
analyse_intr()input. It utilizes the FPCONV/UPDATE properties exported byanalyse_instr()and invokes kvmppc_handle_load(s)/kvmppc_handle_store() accordingly.
Quoted 6 lines
For FP store MMIO emulation, the FP regs need to be flushed firstly so that the right FP reg vals can be read from
vcpu->arch.fpr, which will be stored into MMIO data.Suggested-by Paul Mackerras <[email protected]>Signed-off-by Simon Guo <[email protected]>
One comment below, otherwise looks good...
Quoted 11 lines
arch/powerpc/kvm/emulate_loadstore.c | 197 +++++++---------------------------- 1 file changed, 40 insertions(+), 157 deletions(-)arch/powerpc/kvm/emulate_loadstore.c +0
-0@@ -138,6 +138,22 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)break ; }
arch/powerpc/kvm/emulate_loadstore.c int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) · line 150
Quoted 10 lines
arch/powerpc/kvm/emulate_loadstore.c +10
-0+#ifdef CONFIG_PPC_FPU +case LOAD_FP : +if (kvmppc_check_fp_disabled (vcpu)) +return EMULATE_DONE ; + +if (op.type &FPCONV ) + vcpu->arch.mmio_sp64_extend =1 ; + + emulated =kvmppc_handle_load (run, vcpu, +KVM_MMIO_REG_FPR |op.reg, size,1 );
You need to check the SIGNEXT flag and call kvmppc_handle_loads if it is set, because of the lfiwax case:
arch/powerpc/kvm/emulate_loadstore.c int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) · line 211
Quoted 6 lines
arch/powerpc/kvm/emulate_loadstore.c +0
-6-case OP_31_XOP_LFIWAX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_loads (run, vcpu, -KVM_MMIO_REG_FPR |rt,4 ,1 ); -break ;
Paul.
Quoted 8 lines · On Mon, May 07, 2018 at 02:20:06PM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
We already have
analyse_instr()which analyzes instructions for the instruction type, size, addtional flags, etc. Whatkvmppc_emulate_loadstore()did is somehow duplicated and it will be good to utilizeanalyse_instr()to reimplement the code. The advantage is that the code logic will be shared and more clean to be maintained.
Quoted 8 lines
This patch series reimplement
kvmppc_emulate_loadstore()for various load/store instructions.The testcase locates at:
https://github.com/justdoitqd/publicFiles/blob/master/test_mmio.c- Tested at both PR/HV KVM.
- Also tested with little endian host & big endian guest.
This series looks good. I have just a couple of comments on two of the patches.
Thanks,
Paul.
Re: [PATCH v2 07/10] KVM: PPC: reimplement LOAD_FP/STORE_FP instruction mmio emulation with analyse_intr() input
In reply to Paul MackerrasQuoted 42 lines · Paul Mackerras
Quoted 7 lines · On Mon, May 07, 2018 at 02:20:13PM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
This patch reimplements LOAD_FP/STORE_FP instruction MMIO emulation with
analyse_intr()input. It utilizes the FPCONV/UPDATE properties exported byanalyse_instr()and invokes kvmppc_handle_load(s)/kvmppc_handle_store() accordingly.Quoted 6 lines
For FP store MMIO emulation, the FP regs need to be flushed firstly so that the right FP reg vals can be read from
vcpu->arch.fpr, which will be stored into MMIO data.Suggested-by Paul Mackerras <[email protected]>Signed-off-by Simon Guo <[email protected]>One comment below, otherwise looks good...
Quoted 11 lines
arch/powerpc/kvm/emulate_loadstore.c | 197 +++++++---------------------------- 1 file changed, 40 insertions(+), 157 deletions(-)arch/powerpc/kvm/emulate_loadstore.c +0
-0@@ -138,6 +138,22 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)break ; }arch/powerpc/kvm/emulate_loadstore.c int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) · line 150
Quoted 10 lines
arch/powerpc/kvm/emulate_loadstore.c +10
-0+#ifdef CONFIG_PPC_FPU +case LOAD_FP : +if (kvmppc_check_fp_disabled (vcpu)) +return EMULATE_DONE ; + +if (op.type &FPCONV ) + vcpu->arch.mmio_sp64_extend =1 ; + + emulated =kvmppc_handle_load (run, vcpu, +KVM_MMIO_REG_FPR |op.reg, size,1 );You need to check the SIGNEXT flag and call
kvmppc_handle_loadsif it is set, because of the lfiwax case:
Quoted 6 lines
arch/powerpc/kvm/emulate_loadstore.c int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) · line 211
Quoted 6 lines
arch/powerpc/kvm/emulate_loadstore.c +0
-6-case OP_31_XOP_LFIWAX : -if (kvmppc_check_fp_disabled (vcpu)) -return EMULATE_DONE ; - emulated =kvmppc_handle_loads (run, vcpu, -KVM_MMIO_REG_FPR |rt,4 ,1 ); -break ;
Yes. I need to handle that. Thanks for point it out.
BR,
- Simon
Re: [PATCH v2 05/10] KVM: PPC: reimplement non-SIMD LOAD/STORE instruction mmio emulation with analyse_intr() input
In reply to Paul MackerrasHi Paul,
Quoted 18 lines · Paul Mackerras
Quoted 7 lines · On Mon, May 07, 2018 at 02:20:11PM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
This patch reimplements non-SIMD LOAD/STORE instruction MMIO emulation with
analyse_intr()input. It utilizes the BYTEREV/UPDATE/SIGNEXT properties exported byanalyse_instr()and invokes kvmppc_handle_load(s)/kvmppc_handle_store() accordingly.Quoted 7 lines
It also move CACHEOP type handling into the skeleton.
instruction_typewithinkvm_ppc.his renamed to avoid conflict withsstep.h.Suggested-by Paul Mackerras <[email protected]>Signed-off-by Simon Guo <[email protected]>Looks pretty good, but one comment below...
Quoted 8 lines
arch/powerpc/kvm/emulate_loadstore.c int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) · line 168
Quoted 6 lines
arch/powerpc/kvm/emulate_loadstore.c +2
-4-case OP_31_XOP_LWAUX : - emulated =kvmppc_handle_loads (run, vcpu, rt,4 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed); -break ; +if (emulated ==EMULATE_DONE ) + goto out;Shouldn't this also goto out if emulated ==
EMULATE_DO_MMIO?
Yes. Let me update this.
Thanks,
- Simon
Quoted 7 lines · On Mon, May 07, 2018 at 02:20:06PM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
We already have
analyse_instr()which analyzes instructions for the instruction type, size, addtional flags, etc. Whatkvmppc_emulate_loadstore()did is somehow duplicated and it will be good to utilizeanalyse_instr()to reimplement the code. The advantage is that the code logic will be shared and more clean to be maintained.
I have put patches 1-3 into my kvm-ppc-next branch.
Thanks,
Paul.