PPC: KVM: Enable PR KVM on ppc64le
Subsystems (3)
cover PPC: KVM: Enable PR KVM on ppc64le
During the enablement of ppc64le KVM has been kept unfixed. This patch set is the initial attempt to make all of KVM work on ppc64le hosts. It starts the effort by bringing PR KVM over.
With this patch set I am successfully able to run book3s_32 (BE) and book3s_64 (BE, LE) guests on a host ppc64le system.
Please bear in mind that this patch set does *not* implement POWER8 support, so if you're running on a POWER8 host you definitely want to pass in -cpu POWER7 and cross your fingers that the guest doesn't trigger a facility unavailable interrupt which we don't trap on yet.
Alex
Alexander Graf (13):
KVM: PPC: Book3S PR: Implement LPCR ONE_REG
KVM: PPC: Book3S: PR: Fix C/R bit setting
KVM: PPC: Book3S_32: PR: Access HTAB in big endian
KVM: PPC: Book3S_64 PR: Access HTAB in big endian
KVM: PPC: Book3S_64 PR: Access shadow slb in big endian
KVM: PPC: Book3S PR: Give guest control over MSR_LE
KVM: PPC: Book3S PR: Default to big endian guest
KVM: PPC: Book3S PR: PAPR: Access HTAB in big endian
KVM: PPC: Book3S PR: PAPR: Access RTAS in big endian
KVM: PPC: PR: Fill pvinfo hcall instructions in big endian
KVM: PPC: Make shared struct aka magic page guest endian
KVM: PPC: Book3S PR: Do dcbz32 patching with big endian instructions
KVM: PPC: Book3S: Move little endian conflict to HV KVM
arch/powerpc/include/asm/kvm_book3s.h | 4 +- arch/powerpc/include/asm/kvm_host.h | 3 + arch/powerpc/include/asm/kvm_ppc.h | 80 ++++++++++++++++++++++- arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kvm/Kconfig | 2 +- arch/powerpc/kvm/book3s.c | 72 ++++++++++---------- arch/powerpc/kvm/book3s_32_mmu.c | 41 +++++++----- arch/powerpc/kvm/book3s_32_mmu_host.c | 4 +- arch/powerpc/kvm/book3s_64_mmu.c | 42 +++++++----- arch/powerpc/kvm/book3s_64_mmu_host.c | 4 +- arch/powerpc/kvm/book3s_64_slb.S | 33 +++++----- arch/powerpc/kvm/book3s_emulate.c | 28 ++++---- arch/powerpc/kvm/book3s_hv.c | 11 ++++ arch/powerpc/kvm/book3s_interrupts.S | 23 ++++++- arch/powerpc/kvm/book3s_paired_singles.c | 16 +++-- arch/powerpc/kvm/book3s_pr.c | 109 +++++++++++++++++++------------ arch/powerpc/kvm/book3s_pr_papr.c | 16 +++-- arch/powerpc/kvm/book3s_rtas.c | 29 ++++++++ arch/powerpc/kvm/emulate.c | 24 +++---- arch/powerpc/kvm/powerpc.c | 50 +++++++++++--- arch/powerpc/kvm/trace_pr.h | 2 +- 21 files changed, 410 insertions(+), 185 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/13 KVM: PPC: Book3S PR: Implement LPCR ONE_REG
To control whether we should inject interrupts in little or big endian mode, user space sets the LPCR.ILE bit accordingly via ONE_REG.
Let's implement it, so we are able to trigger interrupts in LE mode.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/kvm/book3s_64_mmu.c | 8 +++++++- arch/powerpc/kvm/book3s_pr.c | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -0
@@ -106,6 +106,7 @@ struct kvmppc_vcpu_book3s {#endif int hpte_cache_count;spinlock_t mmu_lock; +ulong lpcr; };#define CONTEXT_HOST 0
arch/powerpc/kvm/book3s_64_mmu.c +7 -1
@@ -38,7 +38,13 @@static void kvmppc_mmu_book3s_64_reset_msr (struct kvm_vcpu *vcpu) { -kvmppc_set_msr (vcpu,MSR_SF ); +struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu); +ulong new_msr =MSR_SF ; + +if (vcpu_book3s->lpcr &LPCR_ILE ) + new_msr |=MSR_LE ; + +kvmppc_set_msr (vcpu, new_msr); } static struct kvmppc_slb *kvmppc_mmu_book3s_64_find_slbe(
arch/powerpc/kvm/book3s_pr.c +6 -0
@@ -1110,6 +1110,9 @@ static int kvmppc_get_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_HIOR : *val =get_reg_val (id,to_book3s (vcpu)->hior);break ; +case KVM_REG_PPC_LPCR : + *val =get_reg_val (id,to_book3s (vcpu)->lpcr); +break ;default : r = -EINVAL ;break ;
@@ -1128,6 +1131,9 @@ static int kvmppc_set_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,to_book3s (vcpu)->hior =set_reg_val (id, *val);to_book3s (vcpu)->hior_explicit = true;break ; +case KVM_REG_PPC_LPCR : +to_book3s (vcpu)->lpcr =set_reg_val (id, *val) &LPCR_ILE ; +break ;default : r = -EINVAL ;break ;
Signature · 1 line
1.8.1.4
PATCH 2/13 KVM: PPC: Book3S: PR: Fix C/R bit setting
In reply to Alexander GrafCommit 9308ab8e2d made C/R HTAB updates go byte-wise into the target HTAB. However, it didn't update the guest's copy of the HTAB, but instead the host local copy of it.
Write to the guest's HTAB instead.
--- arch/powerpc/kvm/book3s_32_mmu.c | 2 +- arch/powerpc/kvm/book3s_64_mmu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_32_mmu.c +1 -1
@@ -270,7 +270,7 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr,page */ if (found) {u32 pte_r = pteg[i+1 ]; -char __user *addr = (char __user *) &pteg[i+1 ]; +char __user *addr = (char __user *) (ptegp + (i+1 ) *sizeof (u32));/* * Use single-byte writes to update the HPTE, to
arch/powerpc/kvm/book3s_64_mmu.c +2 -2
@@ -348,14 +348,14 @@ do_second:* non-PAPR platforms such as mac99, and this is * what real hardware does. */ -char __user *addr = (char __user *) &pteg[i+1 ]; +char __user *addr = (char __user *) (ptegp + (i +1 ) *sizeof (u64)); r |=HPTE_R_R ;put_user (r >>8 , addr +6 ); }if (iswrite && gpte->may_write && !(r &HPTE_R_C )) {/* Set the dirty flag */ /* Use a single byte write */ -char __user *addr = (char __user *) &pteg[i+1 ]; +char __user *addr = (char __user *) (ptegp + (i +1 ) *sizeof (u64)); r |=HPTE_R_C ;put_user (r, addr +7 ); }
Signature · 1 line
1.8.1.4
Re: [PATCH 02/13] KVM: PPC: Book3S: PR: Fix C/R bit setting
Quoted 8 lines · Alexander Graf
Commit
9308ab8e2dmade C/R HTAB updates go byte-wise into the target HTAB. However, it didn't update the guest's copy of the HTAB, but instead the host local copy of it.Write to the guest's HTAB instead.
Signed-off-by Alexander Graf <[email protected]>CC Paul Mackerras <[email protected]>
PATCH 3/13 KVM: PPC: Book3S_32: PR: Access HTAB in big endian
In reply to Alexander GrafThe HTAB is always big endian. We access the guest's HTAB using copy_from/to_user, but don't yet take care of the fact that we might be running on an LE host.
Wrap all accesses to the guest HTAB with big endian accessors.
--- arch/powerpc/kvm/book3s_32_mmu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
arch/powerpc/kvm/book3s_32_mmu.c +10 -6
@@ -208,6 +208,7 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr,u32 sre;hva_t ptegp;u32 pteg[16 ]; +u32 pte0, pte1;u32 ptem =0 ;int i;int found =0 ;
@@ -233,11 +234,13 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr, }for (i=0 ; i<16 ; i+=2 ) { -if (ptem == pteg[i]) { + pte0 =be32_to_cpu (pteg[i]); + pte1 =be32_to_cpu (pteg[i +1 ]); +if (ptem == pte0) {u8 pp; - pte->raddr = (pteg[i+1 ] & ~(0xFFFULL )) | (eaddr &0xFFF ); - pp = pteg[i+1 ] &3 ; + pte->raddr = (pte1 & ~(0xFFFULL )) | (eaddr &0xFFF ); + pp = pte1 &3 ;if ((sr_kp (sre) && (vcpu->arch.shared->msr &MSR_PR )) || (sr_ks (sre) && !(vcpu->arch.shared->msr &MSR_PR )))
@@ -260,7 +263,7 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr, }dprintk_pte ("MMU: Found PTE -> %x %x - %x\n" , - pteg[i], pteg[i+1 ], pp); + pte0, pte1, pp); found =1 ;break ; }
@@ -269,7 +272,7 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr,/* Update PTE C and A bits, so the guest's swapper knows we used the page */ if (found) { -u32 pte_r = pteg[i+1 ]; +u32 pte_r = pte1;char __user *addr = (char __user *) (ptegp + (i+1 ) *sizeof (u32));/*
@@ -296,7 +299,8 @@ no_page_found: to_book3s(vcpu)->sdr1, ptegp);for (i=0 ; i<16 ; i+=2 ) {dprintk_pte (" %02d: 0x%x - 0x%x (0x%x)\n" , - i, pteg[i], pteg[i+1 ], ptem); + i,be32_to_cpu (pteg[i]), +be32_to_cpu (pteg[i+1 ]), ptem); } }
Signature · 1 line
1.8.1.4
PATCH 4/13 KVM: PPC: Book3S_64 PR: Access HTAB in big endian
In reply to Alexander GrafThe HTAB is always big endian. We access the guest's HTAB using copy_from/to_user, but don't yet take care of the fact that we might be running on an LE host.
Wrap all accesses to the guest HTAB with big endian accessors.
--- arch/powerpc/kvm/book3s_64_mmu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_64_mmu.c +7 -4
@@ -281,12 +281,15 @@ do_second: key =4 ;for (i=0 ; i<16 ; i+=2 ) { +u64 pte0 =be64_to_cpu (pteg[i]); +u64 pte1 =be64_to_cpu (pteg[i +1 ]); +/* Check all relevant fields of 1st dword */ -if ((pteg[i] & v_mask) == v_val) { +if ((pte0 & v_mask) == v_val) {/* If large page bit is set, check pgsize encoding */ if (slbe->large && (vcpu->arch.hflags &BOOK3S_HFLAG_MULTI_PGSIZE )) { - pgsize =decode_pagesize (slbe, pteg[i+1 ]); + pgsize =decode_pagesize (slbe, pte1);if (pgsize <0 )continue ; }
@@ -303,8 +306,8 @@ do_second: goto do_second; } - v = pteg[i]; - r = pteg[i+1 ]; + v =be64_to_cpu (pteg[i]); + r =be64_to_cpu (pteg[i+1 ]); pp = (r &HPTE_R_PP ) | key;if (r &HPTE_R_PP0 ) pp |=8 ;
Signature · 1 line
1.8.1.4
PATCH 5/13 KVM: PPC: Book3S_64 PR: Access shadow slb in big endian
In reply to Alexander GrafThe "shadow SLB" in the PACA is shared with the hypervisor, so it has to be big endian. We access the shadow SLB during world switch, so let's make sure we access it in big endian even when we're on a little endian host.
--- arch/powerpc/kvm/book3s_64_slb.S | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
arch/powerpc/kvm/book3s_64_slb.S +16 -17
@@ -17,29 +17,28 @@ * Authors: Alexander Graf <[email protected]> */ -#ifdef __LITTLE_ENDIAN__ -#error Need to fix SLB shadow accesses in little endian mode -#endif - #define SHADOW_SLB_ESID(num) (SLBSHADOW_SAVEAREA + (num * 0x10)) #define SHADOW_SLB_VSID(num) (SLBSHADOW_SAVEAREA + (num * 0x10) + 0x8) #define UNBOLT_SLB_ENTRY(num) \ - ld r9, SHADOW_SLB_ESID(num)(r12); \ - /* Invalid? Skip. */; \ - rldicl. r0, r9, 37, 63; \ - beq slb_entry_skip_ ## num; \ - xoris r9, r9, SLB_ESID_V@h; \ - std r9, SHADOW_SLB_ESID(num)(r12); \ + li r11, SHADOW_SLB_ESID(num); \ + LDX_BE r9, r12, r11; \ + /* Invalid? Skip. */; \ + rldicl. r0, r9, 37, 63; \ + beq slb_entry_skip_ ## num; \ + xoris r9, r9, SLB_ESID_V@h; \ + STDX_BE r9, r12, r11; \ slb_entry_skip_ ## num: #define REBOLT_SLB_ENTRY(num) \ - ld r10, SHADOW_SLB_ESID(num)(r11); \ - cmpdi r10, 0; \ - beq slb_exit_skip_ ## num; \ - oris r10, r10, SLB_ESID_V@h; \ - ld r9, SHADOW_SLB_VSID(num)(r11); \ - slbmte r9, r10; \ - std r10, SHADOW_SLB_ESID(num)(r11); \ + li r8, SHADOW_SLB_ESID(num); \ + li r7, SHADOW_SLB_VSID(num); \ + LDX_BE r10, r11, r8; \ + cmpdi r10, 0; \ + beq slb_exit_skip_ ## num; \ + oris r10, r10, SLB_ESID_V@h; \ + LDX_BE r9, r11, r7; \ + slbmte r9, r10; \ + STDX_BE r10, r11, r8; \ slb_exit_skip_ ## num: /******************************************************************************
Signature · 1 line
1.8.1.4
PATCH 6/13 KVM: PPC: Book3S PR: Give guest control over MSR_LE
In reply to Alexander GrafWhen we calculate the actual MSR that the guest is running with when in guest context, we take a few MSR bits from the MSR the guest thinks it's using.
Add MSR_LE to these bits, so the guest gets full control over its own endianness setting.
--- arch/powerpc/kvm/book3s_pr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_pr.c +1 -1
@@ -249,7 +249,7 @@ static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu)ulong smsr = vcpu->arch.shared->msr;/* Guest MSR values */ - smsr &=MSR_FE0 |MSR_FE1 |MSR_SF |MSR_SE |MSR_BE ; + smsr &=MSR_FE0 |MSR_FE1 |MSR_SF |MSR_SE |MSR_BE |MSR_LE ;/* Process MSR values */ smsr |=MSR_ME |MSR_RI |MSR_IR |MSR_DR |MSR_PR |MSR_EE ;/* External providers the guest reserved */
Signature · 1 line
1.8.1.4
PATCH 7/13 KVM: PPC: Book3S PR: Default to big endian guest
In reply to Alexander GrafThe default MSR when user space does not define anything should be identical on little and big endian hosts, so remove MSR_LE from it.
--- arch/powerpc/kvm/book3s_pr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/book3s_pr.c +1 -1
@@ -1193,7 +1193,7 @@ static struct kvm_vcpu *kvmppc_core_vcpu_create_pr(struct kvm *kvm,kvmppc_set_pvr_pr (vcpu, vcpu->arch.pvr); vcpu->arch.slb_nr =64 ; - vcpu->arch.shadow_msr =MSR_USER64 ; + vcpu->arch.shadow_msr =MSR_USER64 & ~MSR_LE ; err =kvmppc_mmu_init (vcpu);if (err <0 )
Signature · 1 line
1.8.1.4
PATCH 8/13 KVM: PPC: Book3S PR: PAPR: Access HTAB in big endian
In reply to Alexander GrafThe HTAB on PPC is always in big endian. When we access it via hypercalls on behalf of the guest and we're running on a little endian host, we need to make sure we swap the bits accordingly.
--- arch/powerpc/kvm/book3s_pr_papr.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_pr_papr.c +11 -3
@@ -57,7 +57,7 @@ static int kvmppc_h_pr_enter(struct kvm_vcpu *vcpu)for (i =0 ; ; ++i) {if (i =8 ) goto done; -if ((*hpte &HPTE_V_VALID ) =0 ) +if ((be64_to_cpu (*hpte) &HPTE_V_VALID ) =0 )break ; hpte +=2 ; }
@@ -67,8 +67,8 @@ static int kvmppc_h_pr_enter(struct kvm_vcpu *vcpu) goto done; } - hpte[0 ] =kvmppc_get_gpr (vcpu,6 ); - hpte[1 ] =kvmppc_get_gpr (vcpu,7 ); + hpte[0 ] =cpu_to_be64 (kvmppc_get_gpr (vcpu,6 )); + hpte[1 ] =cpu_to_be64 (kvmppc_get_gpr (vcpu,7 )); pteg_addr += i *HPTE_SIZE ;copy_to_user ((void __user *)pteg_addr, hpte,HPTE_SIZE );kvmppc_set_gpr (vcpu,4 , pte_index | i);
@@ -93,6 +93,8 @@ static int kvmppc_h_pr_remove(struct kvm_vcpu *vcpu) pteg =get_pteg_addr (vcpu, pte_index);mutex_lock (&vcpu->kvm->arch.hpt_mutex);copy_from_user (pte, (void __user *)pteg,sizeof (pte)); + pte[0 ] =be64_to_cpu (pte[0 ]); + pte[1 ] =be64_to_cpu (pte[1 ]); ret =H_NOT_FOUND ; if ((pte[0] & HPTE_V_VALID) = 0 ||
@@ -169,6 +171,8 @@ static int kvmppc_h_pr_bulk_remove(struct kvm_vcpu *vcpu) pteg =get_pteg_addr (vcpu, tsh &H_BULK_REMOVE_PTEX );copy_from_user (pte, (void __user *)pteg,sizeof (pte)); + pte[0 ] =be64_to_cpu (pte[0 ]); + pte[1 ] =be64_to_cpu (pte[1 ]);/* tsl = AVPN */ flags = (tsh &H_BULK_REMOVE_FLAGS ) >>26 ;
@@ -207,6 +211,8 @@ static int kvmppc_h_pr_protect(struct kvm_vcpu *vcpu) pteg =get_pteg_addr (vcpu, pte_index);mutex_lock (&vcpu->kvm->arch.hpt_mutex);copy_from_user (pte, (void __user *)pteg,sizeof (pte)); + pte[0 ] =be64_to_cpu (pte[0 ]); + pte[1 ] =be64_to_cpu (pte[1 ]); ret =H_NOT_FOUND ; if ((pte[0] & HPTE_V_VALID) = 0 ||
@@ -225,6 +231,8 @@ static int kvmppc_h_pr_protect(struct kvm_vcpu *vcpu) rb =compute_tlbie_rb (v, r, pte_index); vcpu->arch.mmu.tlbie (vcpu, rb, rb &1 ? true : false); + pte[0 ] =cpu_to_be64 (pte[0 ]); + pte[1 ] =cpu_to_be64 (pte[1 ]);copy_to_user ((void __user *)pteg, pte,sizeof (pte)); ret =H_SUCCESS ;
Signature · 1 line
1.8.1.4
PATCH 9/13 KVM: PPC: Book3S PR: PAPR: Access RTAS in big endian
In reply to Alexander GrafWhen the guest does an RTAS hypercall it keeps all RTAS variables inside a big endian data structure.
To make sure we don't have to bother about endianness inside the actual RTAS handlers, let's just convert the whole structure to host endian before we call our RTAS handlers and back to big endian when we return to the guest.
--- arch/powerpc/kvm/book3s_rtas.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
arch/powerpc/kvm/book3s_rtas.c +29 -0
@@ -205,6 +205,32 @@ int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp)return rc; } +static void kvmppc_rtas_swap_endian_in (struct rtas_args *args) +{ +#ifdef __LITTLE_ENDIAN__ +int i; + + args->token =be32_to_cpu (args->token); + args->nargs =be32_to_cpu (args->nargs); + args->nret =be32_to_cpu (args->nret); +for (i =0 ; i < args->nargs; i++) + args->args[i] =be32_to_cpu (args->args[i]); +#endif +} + +static void kvmppc_rtas_swap_endian_out (struct rtas_args *args) +{ +#ifdef __LITTLE_ENDIAN__ +int i; + +for (i =0 ; i < args->nret; i++) + args->args[i] =cpu_to_be32 (args->args[i]); + args->token =cpu_to_be32 (args->token); + args->nargs =cpu_to_be32 (args->nargs); + args->nret =cpu_to_be32 (args->nret); +#endif +} +int kvmppc_rtas_hcall (struct kvm_vcpu *vcpu) {struct rtas_token_definition *d;
@@ -223,6 +249,8 @@ int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu)if (rc) goto fail; +kvmppc_rtas_swap_endian_in (&args); +/* * args->rets is a pointer into args->args. Now that we've * copied args we need to fix it up to point into our copy,
@@ -247,6 +275,7 @@ int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu)if (rc ==0 ) { args.rets = orig_rets; +kvmppc_rtas_swap_endian_out (&args); rc =kvm_write_guest (vcpu->kvm, args_phys, &args,sizeof (args));if (rc) goto fail;
Signature · 1 line
1.8.1.4
PATCH 10/13 KVM: PPC: PR: Fill pvinfo hcall instructions in big endian
In reply to Alexander GrafWe expose a blob of hypercall instructions to user space that it gives to the guest via device tree again. That blob should contain a stream of instructions necessary to do a hypercall in big endian, as it just gets passed into the guest and old guests use them straight away.
--- arch/powerpc/kvm/powerpc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/powerpc/kvm/powerpc.c +8 -8
@@ -1015,10 +1015,10 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)u32 inst_nop =0x60000000 ;#ifdef CONFIG_KVM_BOOKE_HV u32 inst_sc1 =0x44000022 ; - pvinfo->hcall[0 ] = inst_sc1; - pvinfo->hcall[1 ] = inst_nop; - pvinfo->hcall[2 ] = inst_nop; - pvinfo->hcall[3 ] = inst_nop; + pvinfo->hcall[0 ] =cpu_to_be32 (inst_sc1); + pvinfo->hcall[1 ] =cpu_to_be32 (inst_nop); + pvinfo->hcall[2 ] =cpu_to_be32 (inst_nop); + pvinfo->hcall[3 ] =cpu_to_be32 (inst_nop);#else u32 inst_lis =0x3c000000 ;u32 inst_ori =0x60000000 ;
@@ -1034,10 +1034,10 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)* sc * nop */ - pvinfo->hcall[0 ] = inst_lis | ((KVM_SC_MAGIC_R0 >>16 ) & inst_imm_mask); - pvinfo->hcall[1 ] = inst_ori | (KVM_SC_MAGIC_R0 & inst_imm_mask); - pvinfo->hcall[2 ] = inst_sc; - pvinfo->hcall[3 ] = inst_nop; + pvinfo->hcall[0 ] =cpu_to_be32 (inst_lis | ((KVM_SC_MAGIC_R0 >>16 ) & inst_imm_mask)); + pvinfo->hcall[1 ] =cpu_to_be32 (inst_ori | (KVM_SC_MAGIC_R0 & inst_imm_mask)); + pvinfo->hcall[2 ] =cpu_to_be32 (inst_sc); + pvinfo->hcall[3 ] =cpu_to_be32 (inst_nop);#endif pvinfo->flags =KVM_PPC_PVINFO_FLAGS_EV_IDLE ;
Signature · 1 line
1.8.1.4
PATCH 11/13 KVM: PPC: Make shared struct aka magic page guest endian
In reply to Alexander GrafThe shared (magic) page is a data structure that contains often used supervisor privileged SPRs accessible via memory to the user to reduce the number of exits we have to take to read/write them.
When we actually share this structure with the guest we have to maintain it in guest endianness, because some of the patch tricks only work with native endian load/store operations.
Since we only share the structure with either host or guest in little endian on book3s_64 pr mode, we don't have to worry about booke or book3s hv.
For booke, the shared struct stays big endian. For book3s_64 hv we maintain the struct in host native endian, since it never gets shared with the guest.
For book3s_64 pr we introduce a variable that tells us which endianness the shared struct is in and route every access to it through helper inline functions that evaluate this variable.
--- arch/powerpc/include/asm/kvm_book3s.h | 3 +- arch/powerpc/include/asm/kvm_host.h | 3 + arch/powerpc/include/asm/kvm_ppc.h | 80 ++++++++++++++++++++++++++- arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kvm/book3s.c | 72 ++++++++++++------------ arch/powerpc/kvm/book3s_32_mmu.c | 21 +++---- arch/powerpc/kvm/book3s_32_mmu_host.c | 4 +- arch/powerpc/kvm/book3s_64_mmu.c | 19 ++++--- arch/powerpc/kvm/book3s_64_mmu_host.c | 4 +- arch/powerpc/kvm/book3s_emulate.c | 28 +++++----- arch/powerpc/kvm/book3s_hv.c | 11 ++++ arch/powerpc/kvm/book3s_interrupts.S | 23 +++++++- arch/powerpc/kvm/book3s_paired_singles.c | 16 +++--- arch/powerpc/kvm/book3s_pr.c | 95 +++++++++++++++++++------------- arch/powerpc/kvm/book3s_pr_papr.c | 2 +- arch/powerpc/kvm/emulate.c | 24 ++++---- arch/powerpc/kvm/powerpc.c | 34 +++++++++++- arch/powerpc/kvm/trace_pr.h | 2 +- 18 files changed, 306 insertions(+), 137 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +2 -1
@@ -269,9 +269,10 @@ static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)return vcpu->arch.pc; } +static u64 kvmppc_get_msr (struct kvm_vcpu *vcpu);static inline bool kvmppc_need_byteswap (struct kvm_vcpu *vcpu) { -return (vcpu->arch.shared->msr &MSR_LE ) != (MSR_KERNEL &MSR_LE ); +return (kvmppc_get_msr (vcpu) &MSR_LE ) != (MSR_KERNEL &MSR_LE ); }static inline u32 kvmppc_get_last_inst_internal (struct kvm_vcpu *vcpu,ulong pc)
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -622,6 +622,9 @@ struct kvm_vcpu_arch {wait_queue_head_t cpu_run;struct kvm_vcpu_arch_shared *shared; +#if defined(CONFIG_PPC_BOOK3S_64 ) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE ) +bool shared_big_endian; +#endif unsigned long magic_page_pa;/* phys addr to map the magic page to */ unsigned long magic_page_ea;/* effect. addr to map the magic page to */
arch/powerpc/include/asm/kvm_ppc.h +79 -1
92 lines not on this page · raw message
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -54,6 +54,7 @@#endif #if defined(CONFIG_KVM ) && defined(CONFIG_PPC_BOOK3S )#include <asm/kvm_book3s.h> +#include <asm/kvm_ppc.h> #endif #ifdef CONFIG_PPC32
@@ -467,6 +468,7 @@ int main(void) DEFINE(VCPU_SHARED, offsetof(struct kvm_vcpu, arch.shared));DEFINE (VCPU_SHARED_MSR , offsetof(struct kvm_vcpu_arch_shared , msr)); DEFINE(VCPU_SHADOW_MSR, offsetof(struct kvm_vcpu, arch.shadow_msr)); + DEFINE(VCPU_SHAREDBE, offsetof(struct kvm_vcpu, arch.shared_big_endian));DEFINE (VCPU_SHARED_MAS0 , offsetof(struct kvm_vcpu_arch_shared , mas0));DEFINE (VCPU_SHARED_MAS1 , offsetof(struct kvm_vcpu_arch_shared , mas1));
arch/powerpc/kvm/book3s.c +36 -36
151 lines not on this page · raw message
arch/powerpc/kvm/book3s_32_mmu.c +11 -10
@@ -91,7 +91,7 @@ static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid,static u32 find_sr (struct kvm_vcpu *vcpu,gva_t eaddr) { -return vcpu->arch.shared->sr[(eaddr >>28 ) &0xf ]; +return kvmppc_get_sr (vcpu, (eaddr >>28 ) &0xf ); } static u64 kvmppc_mmu_book3s_32_ea_to_vp(struct kvm_vcpu *vcpu, gva_t eaddr,
@@ -160,7 +160,7 @@ static int kvmppc_mmu_book3s_32_xlate_bat(struct kvm_vcpu *vcpu, gva_t eaddr,else bat = &vcpu_book3s->ibat[i]; -if (vcpu->arch.shared->msr &MSR_PR ) { +if (kvmppc_get_msr (vcpu) &MSR_PR ) {if (!bat->vp)continue ; }else {
@@ -242,8 +242,8 @@ static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr, pte->raddr = (pte1 & ~(0xFFFULL )) | (eaddr &0xFFF ); pp = pte1 &3 ; -if ((sr_kp (sre) && (vcpu->arch.shared->msr &MSR_PR )) || - (sr_ks (sre) && !(vcpu->arch.shared->msr &MSR_PR ))) +if ((sr_kp (sre) && (kvmppc_get_msr (vcpu) &MSR_PR )) || + (sr_ks (sre) && !(kvmppc_get_msr (vcpu) &MSR_PR ))) pp |=4 ; pte->may_write = false;
@@ -320,7 +320,7 @@ static int kvmppc_mmu_book3s_32_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,/* Magic page override */ if (unlikely (mp_ea) &&unlikely ((eaddr & ~0xfffULL ) = (mp_ea & ~0xfffULL )) && - !(vcpu->arch.shared->msr &MSR_PR )) { + !(kvmppc_get_msr (vcpu) &MSR_PR )) { pte->vpage =kvmppc_mmu_book3s_32_ea_to_vp (vcpu, eaddr, data); pte->raddr = vcpu->arch.magic_page_pa | (pte->raddr &0xfff ); pte->raddr &=KVM_PAM ;
@@ -345,13 +345,13 @@ static int kvmppc_mmu_book3s_32_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,static u32 kvmppc_mmu_book3s_32_mfsrin (struct kvm_vcpu *vcpu,u32 srnum) { -return vcpu->arch.shared->sr[srnum]; +return kvmppc_get_sr (vcpu, srnum); }static void kvmppc_mmu_book3s_32_mtsrin (struct kvm_vcpu *vcpu,u32 srnum,ulong value) { - vcpu->arch.shared->sr[srnum] = value; +kvmppc_set_sr (vcpu, srnum, value);kvmppc_mmu_map_segment (vcpu, srnum <<SID_SHIFT ); }
@@ -371,8 +371,9 @@ static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid,ulong ea = esid <<SID_SHIFT ;u32 sr;u64 gvsid = esid; +u64 msr =kvmppc_get_msr (vcpu); -if (vcpu->arch.shared->msr & (MSR_DR |MSR_IR )) { +if (msr & (MSR_DR |MSR_IR )) { sr =find_sr (vcpu, ea);if (sr_valid (sr)) gvsid =sr_vsid (sr);
@@ -381,7 +382,7 @@ static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid,/* In case we only have one of MSR_IR or MSR_DR set, let's put that in the real-mode context (and hope RM doesn't access high memory) */ -switch (vcpu->arch.shared->msr & (MSR_DR |MSR_IR )) { +switch (msr & (MSR_DR |MSR_IR )) {case 0 : *vsid =VSID_REAL | esid;break ;
@@ -401,7 +402,7 @@ static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid,BUG (); } -if (vcpu->arch.shared->msr &MSR_PR ) +if (msr &MSR_PR ) *vsid |=VSID_PR ;return 0 ;
arch/powerpc/kvm/book3s_32_mmu_host.c +2 -2
@@ -92,7 +92,7 @@ static struct kvmppc_sid_map *find_sid_vsid(struct kvm_vcpu *vcpu, u64 gvsid)struct kvmppc_sid_map *map;u16 sid_map_mask; -if (vcpu->arch.shared->msr &MSR_PR ) +if (kvmppc_get_msr (vcpu) &MSR_PR ) gvsid |=VSID_PR ; sid_map_mask =kvmppc_sid_hash (vcpu, gvsid);
@@ -279,7 +279,7 @@ static struct kvmppc_sid_map *create_sid_map(struct kvm_vcpu *vcpu, u64 gvsid)u16 sid_map_mask;static int backwards_map =0 ; -if (vcpu->arch.shared->msr &MSR_PR ) +if (kvmppc_get_msr (vcpu) &MSR_PR ) gvsid |=VSID_PR ;/* We might get collisions that trap in preceding order, so let's
arch/powerpc/kvm/book3s_64_mmu.c +10 -9
@@ -232,7 +232,7 @@ static int kvmppc_mmu_book3s_64_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,/* Magic page override */ if (unlikely (mp_ea) &&unlikely ((eaddr & ~0xfffULL ) = (mp_ea & ~0xfffULL )) && - !(vcpu->arch.shared->msr &MSR_PR )) { + !(kvmppc_get_msr (vcpu) &MSR_PR )) { gpte->eaddr = eaddr; gpte->vpage =kvmppc_mmu_book3s_64_ea_to_vp (vcpu, eaddr, data); gpte->raddr = vcpu->arch.magic_page_pa | (gpte->raddr &0xfff );
@@ -275,9 +275,9 @@ do_second: goto no_page_found; } -if ((vcpu->arch.shared->msr &MSR_PR ) && slbe->Kp) +if ((kvmppc_get_msr (vcpu) &MSR_PR ) && slbe->Kp) key =4 ; -else if (!(vcpu->arch.shared->msr &MSR_PR ) && slbe->Ks) +else if (!(kvmppc_get_msr (vcpu) &MSR_PR ) && slbe->Ks) key =4 ;for (i=0 ; i<16 ; i+=2 ) {
@@ -488,7 +488,7 @@ static void kvmppc_mmu_book3s_64_slbia(struct kvm_vcpu *vcpu) vcpu->arch.slb[i].origv =0 ; } -if (vcpu->arch.shared->msr &MSR_IR ) { +if (kvmppc_get_msr (vcpu) &MSR_IR ) {kvmppc_mmu_flush_segments (vcpu);kvmppc_mmu_map_segment (vcpu,kvmppc_get_pc (vcpu)); }
@@ -572,7 +572,7 @@ static int segment_contains_magic_page(struct kvm_vcpu *vcpu, ulong esid) {ulong mp_ea = vcpu->arch.magic_page_ea; -return mp_ea && !(vcpu->arch.shared->msr &MSR_PR ) && +return mp_ea && !(kvmppc_get_msr (vcpu) &MSR_PR ) && (mp_ea >>SID_SHIFT ) = esid; }#endif
@@ -585,8 +585,9 @@ static int kvmppc_mmu_book3s_64_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid,u64 gvsid = esid;ulong mp_ea = vcpu->arch.magic_page_ea;int pagesize =MMU_PAGE_64K ; +u64 msr =kvmppc_get_msr (vcpu); -if (vcpu->arch.shared->msr & (MSR_DR |MSR_IR )) { +if (msr & (MSR_DR |MSR_IR )) { slb =kvmppc_mmu_book3s_64_find_slbe (vcpu, ea);if (slb) { gvsid = slb->vsid;
@@ -599,7 +600,7 @@ static int kvmppc_mmu_book3s_64_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid, } } -switch (vcpu->arch.shared->msr & (MSR_DR |MSR_IR )) { +switch (msr & (MSR_DR |MSR_IR )) {case 0 : gvsid =VSID_REAL | esid;break ;
@@ -632,7 +633,7 @@ static int kvmppc_mmu_book3s_64_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid, gvsid |=VSID_64K ;#endif -if (vcpu->arch.shared->msr &MSR_PR ) +if (kvmppc_get_msr (vcpu) &MSR_PR ) gvsid |=VSID_PR ; *vsid = gvsid;
@@ -642,7 +643,7 @@ no_slb:/* Catch magic page case */ if (unlikely (mp_ea) &&unlikely (esid = (mp_ea >>SID_SHIFT )) && - !(vcpu->arch.shared->msr &MSR_PR )) { + !(kvmppc_get_msr (vcpu) &MSR_PR )) { *vsid =VSID_REAL | esid;return 0 ; }
arch/powerpc/kvm/book3s_64_mmu_host.c +2 -2
@@ -58,7 +58,7 @@ static struct kvmppc_sid_map *find_sid_vsid(struct kvm_vcpu *vcpu, u64 gvsid)struct kvmppc_sid_map *map;u16 sid_map_mask; -if (vcpu->arch.shared->msr &MSR_PR ) +if (kvmppc_get_msr (vcpu) &MSR_PR ) gvsid |=VSID_PR ; sid_map_mask =kvmppc_sid_hash (vcpu, gvsid);
@@ -230,7 +230,7 @@ static struct kvmppc_sid_map *create_sid_map(struct kvm_vcpu *vcpu, u64 gvsid)u16 sid_map_mask;static int backwards_map =0 ; -if (vcpu->arch.shared->msr &MSR_PR ) +if (kvmppc_get_msr (vcpu) &MSR_PR ) gvsid |=VSID_PR ;/* We might get collisions that trap in preceding order, so let's
arch/powerpc/kvm/book3s_emulate.c +14 -14
@@ -80,7 +80,7 @@ static bool spr_allowed(struct kvm_vcpu *vcpu, enum priv_level level)return false;/* Limit user space to its own small SPR set */ -if ((vcpu->arch.shared->msr &MSR_PR ) && level >PRIV_PROBLEM ) +if ((kvmppc_get_msr (vcpu) &MSR_PR ) && level >PRIV_PROBLEM )return false;return true;
@@ -100,8 +100,8 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,switch (get_xop (inst)) {case OP_19_XOP_RFID :case OP_19_XOP_RFI : -kvmppc_set_pc (vcpu, vcpu->arch.shared->srr0); -kvmppc_set_msr (vcpu, vcpu->arch.shared->srr1); +kvmppc_set_pc (vcpu,kvmppc_get_srr0 (vcpu)); +kvmppc_set_msr (vcpu,kvmppc_get_srr1 (vcpu)); *advance =0 ;break ;
@@ -113,16 +113,16 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,case 31 :switch (get_xop (inst)) {case OP_31_XOP_MFMSR : -kvmppc_set_gpr (vcpu, rt, vcpu->arch.shared->msr); +kvmppc_set_gpr (vcpu, rt,kvmppc_get_msr (vcpu));break ;case OP_31_XOP_MTMSRD : {ulong rs_val =kvmppc_get_gpr (vcpu, rs);if (inst &0x10000 ) { -ulong new_msr = vcpu->arch.shared->msr; +ulong new_msr =kvmppc_get_msr (vcpu); new_msr &= ~(MSR_RI |MSR_EE ); new_msr |= rs_val & (MSR_RI |MSR_EE ); - vcpu->arch.shared->msr = new_msr; +kvmppc_set_msr_fast (vcpu, new_msr); }else kvmppc_set_msr (vcpu, rs_val);break ;
@@ -179,7 +179,7 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,ulong cmd =kvmppc_get_gpr (vcpu,3 );int i; -if ((vcpu->arch.shared->msr &MSR_PR ) || +if ((kvmppc_get_msr (vcpu) &MSR_PR ) || !vcpu->arch.papr_enabled) { emulated =EMULATE_FAIL ;break ;
@@ -261,14 +261,14 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, ra_val =kvmppc_get_gpr (vcpu, ra); addr = (ra_val + rb_val) & ~31ULL ; -if (!(vcpu->arch.shared->msr &MSR_SF )) +if (!(kvmppc_get_msr (vcpu) &MSR_SF )) addr &=0xffffffff ; vaddr = addr; r =kvmppc_st (vcpu, &addr,32 , zeros, true);if ((r = -ENOENT ) || (r = -EPERM )) { *advance =0 ; - vcpu->arch.shared->dar = vaddr; +kvmppc_set_dar (vcpu, vaddr); vcpu->arch.fault_dar = vaddr; dsisr =DSISR_ISSTORE ;
@@ -277,7 +277,7 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,else if (r = -EPERM ) dsisr |=DSISR_PROTFAULT ; - vcpu->arch.shared->dsisr = dsisr; +kvmppc_set_dsisr (vcpu, dsisr); vcpu->arch.fault_dsisr = dsisr; kvmppc_book3s_queue_irqprio(vcpu,
@@ -356,10 +356,10 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)to_book3s (vcpu)->sdr1 = spr_val;break ;case SPRN_DSISR : - vcpu->arch.shared->dsisr = spr_val; +kvmppc_set_dsisr (vcpu, spr_val);break ;case SPRN_DAR : - vcpu->arch.shared->dar = spr_val; +kvmppc_set_dar (vcpu, spr_val);break ;case SPRN_HIOR :to_book3s (vcpu)->hior = spr_val;
@@ -493,10 +493,10 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val *spr_val =to_book3s (vcpu)->sdr1;break ;case SPRN_DSISR : - *spr_val = vcpu->arch.shared->dsisr; + *spr_val =kvmppc_get_dsisr (vcpu);break ;case SPRN_DAR : - *spr_val = vcpu->arch.shared->dar; + *spr_val =kvmppc_get_dar (vcpu);break ;case SPRN_HIOR : *spr_val =to_book3s (vcpu)->hior;
arch/powerpc/kvm/book3s_hv.c +11 -0
@@ -1280,6 +1280,17 @@ static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm, goto free_vcpu; vcpu->arch.shared = &vcpu->arch.shregs; +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE +/* +* The shared struct is never shared on HV, +* so we can always use host endianness +*/ +#ifdef __BIG_ENDIAN__ + vcpu->arch.shared_big_endian = true; +#else + vcpu->arch.shared_big_endian = false; +#endif +#endif vcpu->arch.mmcr[0 ] =MMCR0_FC ; vcpu->arch.ctrl =CTRL_RUNLATCH ;/* default to host PVR, since we can't spoof it */
arch/powerpc/kvm/book3s_interrupts.S +21 -2
@@ -104,8 +104,27 @@ kvm_start_lightweight: stb r3, HSTATE_RESTORE_HID5(r13) /* Load up guest SPRG3 value, since it's user readable */ - ld r3, VCPU_SHARED(r4) - ld r3, VCPU_SHARED_SPRG3(r3) + lwz r3, VCPU_SHAREDBE(r4) + cmpwi r3, 0 + ld r5, VCPU_SHARED(r4) + beq sprg3_little_endian +sprg3_big_endian: +#ifdef __BIG_ENDIAN__ + ld r3, VCPU_SHARED_SPRG3(r5) +#else + addi r5, r5, VCPU_SHARED_SPRG3 + ldbrx r3, 0, r5 +#endif + b after_sprg3_load +sprg3_little_endian: +#ifdef __LITTLE_ENDIAN__ + ld r3, VCPU_SHARED_SPRG3(r5) +#else + addi r5, r5, VCPU_SHARED_SPRG3 + ldbrx r3, 0, r5 +#endif + +after_sprg3_load: mtspr SPRN_SPRG3, r3 #endif /* CONFIG_PPC_BOOK3S_64 */
arch/powerpc/kvm/book3s_paired_singles.c +9 -7
@@ -165,16 +165,18 @@ static inline void kvmppc_sync_qpr(struct kvm_vcpu *vcpu, int rt)static void kvmppc_inject_pf (struct kvm_vcpu *vcpu,ulong eaddr,bool is_store) { -u64 dsisr; -struct kvm_vcpu_arch_shared *shared = vcpu->arch.shared; +u32 dsisr; +u64 msr =kvmppc_get_msr (vcpu); - shared->msr =kvmppc_set_field (shared->msr,33 ,36 ,0 ); - shared->msr =kvmppc_set_field (shared->msr,42 ,47 ,0 ); - shared->dar = eaddr; + msr =kvmppc_set_field (msr,33 ,36 ,0 ); + msr =kvmppc_set_field (msr,42 ,47 ,0 ); +kvmppc_set_msr (vcpu, msr); +kvmppc_set_dar (vcpu, eaddr);/* Page Fault */ dsisr =kvmppc_set_field (0 ,33 ,33 ,1 );if (is_store) - shared->dsisr =kvmppc_set_field (dsisr,38 ,38 ,1 ); + dsisr =kvmppc_set_field (dsisr,38 ,38 ,1 ); +kvmppc_set_dsisr (vcpu, dsisr);kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_DATA_STORAGE ); }
@@ -660,7 +662,7 @@ int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu)if (!kvmppc_inst_is_paired_single (vcpu, inst))return EMULATE_FAIL ; -if (!(vcpu->arch.shared->msr &MSR_FP )) { +if (!(kvmppc_get_msr (vcpu) &MSR_FP )) {kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_FP_UNAVAIL );return EMULATE_AGAIN ; }
arch/powerpc/kvm/book3s_pr.c +56 -36
241 lines not on this page · raw message
arch/powerpc/kvm/book3s_pr_papr.c +1 -1
@@ -278,7 +278,7 @@ int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)case H_PUT_TCE :return kvmppc_h_pr_put_tce (vcpu);case H_CEDE : - vcpu->arch.shared->msr |=MSR_EE ; +kvmppc_set_msr_fast (vcpu,kvmppc_get_msr (vcpu) |MSR_EE );kvm_vcpu_block (vcpu);clear_bit (KVM_REQ_UNHALT , &vcpu->requests); vcpu->stat.halt_wakeup++;
arch/powerpc/kvm/emulate.c +12 -12
@@ -97,10 +97,10 @@ static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)switch (sprn) {case SPRN_SRR0 : - vcpu->arch.shared->srr0 = spr_val; +kvmppc_set_srr0 (vcpu, spr_val);break ;case SPRN_SRR1 : - vcpu->arch.shared->srr1 = spr_val; +kvmppc_set_srr1 (vcpu, spr_val);break ;/* XXX We need to context-switch the timebase for
@@ -114,16 +114,16 @@ static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)break ;case SPRN_SPRG0 : - vcpu->arch.shared->sprg0 = spr_val; +kvmppc_set_sprg0 (vcpu, spr_val);break ;case SPRN_SPRG1 : - vcpu->arch.shared->sprg1 = spr_val; +kvmppc_set_sprg1 (vcpu, spr_val);break ;case SPRN_SPRG2 : - vcpu->arch.shared->sprg2 = spr_val; +kvmppc_set_sprg2 (vcpu, spr_val);break ;case SPRN_SPRG3 : - vcpu->arch.shared->sprg3 = spr_val; +kvmppc_set_sprg3 (vcpu, spr_val);break ;/* PIR can legally be written, but we ignore it */
@@ -150,10 +150,10 @@ static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)switch (sprn) {case SPRN_SRR0 : - spr_val = vcpu->arch.shared->srr0; + spr_val =kvmppc_get_srr0 (vcpu);break ;case SPRN_SRR1 : - spr_val = vcpu->arch.shared->srr1; + spr_val =kvmppc_get_srr1 (vcpu);break ;case SPRN_PVR : spr_val = vcpu->arch.pvr;
@@ -173,16 +173,16 @@ static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)break ;case SPRN_SPRG0 : - spr_val = vcpu->arch.shared->sprg0; + spr_val =kvmppc_get_sprg0 (vcpu);break ;case SPRN_SPRG1 : - spr_val = vcpu->arch.shared->sprg1; + spr_val =kvmppc_get_sprg1 (vcpu);break ;case SPRN_SPRG2 : - spr_val = vcpu->arch.shared->sprg2; + spr_val =kvmppc_get_sprg2 (vcpu);break ;case SPRN_SPRG3 : - spr_val = vcpu->arch.shared->sprg3; + spr_val =kvmppc_get_sprg3 (vcpu);break ;/* Note: SPRG4-7 are user-readable, so we don't get * a trap. */
arch/powerpc/kvm/powerpc.c +33 -1
@@ -125,6 +125,27 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu) }EXPORT_SYMBOL_GPL (kvmppc_prepare_to_enter); +#if defined(CONFIG_PPC_BOOK3S_64 ) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE ) +static void kvmppc_swab_shared (struct kvm_vcpu *vcpu) +{ +struct kvm_vcpu_arch_shared *shared = vcpu->arch.shared; +int i; + + shared->sprg0 =swab64 (shared->sprg0); + shared->sprg1 =swab64 (shared->sprg1); + shared->sprg2 =swab64 (shared->sprg2); + shared->sprg3 =swab64 (shared->sprg3); + shared->srr0 =swab64 (shared->srr0); + shared->srr1 =swab64 (shared->srr1); + shared->dar =swab64 (shared->dar); + shared->msr =swab64 (shared->msr); + shared->dsisr =swab32 (shared->dsisr); + shared->int_pending =swab32 (shared->int_pending); +for (i =0 ; i <ARRAY_SIZE (shared->sr); i++) + shared->sr[i] =swab32 (shared->sr[i]); +} +#endif +int kvmppc_kvm_pv (struct kvm_vcpu *vcpu) {int nr =kvmppc_get_gpr (vcpu,11 );
@@ -135,7 +156,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)unsigned long __maybe_unused param4 =kvmppc_get_gpr (vcpu,6 );unsigned long r2 =0 ; -if (!(vcpu->arch.shared->msr &MSR_SF )) { +if (!(kvmppc_get_msr (vcpu) &MSR_SF )) {/* 32 bit mode */ param1 &=0xffffffff ; param2 &=0xffffffff ;
@@ -146,6 +167,17 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)switch (nr) {case KVM_HCALL_TOKEN (KVM_HC_PPC_MAP_MAGIC_PAGE ): { +#if defined(CONFIG_PPC_BOOK3S_64 ) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE ) +/* Book3S can be little endian, find it out here */ +struct kvmppc_vcpu_book3s *vcpu_book3s =to_book3s (vcpu); +int shared_big_endian = true; +if (vcpu_book3s->lpcr &LPCR_ILE ) + shared_big_endian = false; +if (shared_big_endian != vcpu->arch.shared_big_endian) +kvmppc_swab_shared (vcpu); + vcpu->arch.shared_big_endian = shared_big_endian; +#endif + vcpu->arch.magic_page_pa = param1; vcpu->arch.magic_page_ea = param2;
arch/powerpc/kvm/trace_pr.h +1 -1
@@ -255,7 +255,7 @@ TRACE_EVENT(kvm_exit, __entry->exit_nr = exit_nr; __entry->pc =kvmppc_get_pc (vcpu); __entry->dar =kvmppc_get_fault_dar (vcpu); - __entry->msr = vcpu->arch.shared->msr; + __entry->msr =kvmppc_get_msr (vcpu); __entry->srr1 = vcpu->arch.shadow_srr1; __entry->last_inst = vcpu->arch.last_inst; ),
Signature · 1 line
1.8.1.4
PATCH 12/13 KVM: PPC: Book3S PR: Do dcbz32 patching with big endian instructions
In reply to Alexander GrafWhen the host CPU we're running on doesn't support dcbz32 itself, but the guest wants to have dcbz only clear 32 bytes of data, we loop through every executable mapped page to search for dcbz instructions and patch them with a special privileged instruction that we emulate as dcbz32.
The only guests that want to see dcbz act as 32byte are book3s_32 guests, so we don't have to worry about little endian instruction ordering. So let's just always search for big endian dcbz instructions, also when we're on a little endian host.
--- arch/powerpc/kvm/book3s_32_mmu.c | 2 +- arch/powerpc/kvm/book3s_pr.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_32_mmu.c +1 -1
@@ -131,7 +131,7 @@ static hva_t kvmppc_mmu_book3s_32_get_pteg(struct kvm_vcpu *vcpu, pteg = (vcpu_book3s->sdr1 &0xffff0000 ) | hash;dprintk ("MMU: pc=0x%lx eaddr=0x%lx sdr1=0x%llx pteg=0x%x vsid=0x%x\n" , -kvmppc_get_pc (&vcpu_book3s->vcpu), eaddr, vcpu_book3s->sdr1, pteg, +kvmppc_get_pc (vcpu), eaddr, vcpu_book3s->sdr1, pteg,sr_vsid (sre)); r =gfn_to_hva (vcpu->kvm, pteg >>PAGE_SHIFT );
arch/powerpc/kvm/book3s_pr.c +2 -2
@@ -428,8 +428,8 @@ static void kvmppc_patch_dcbz(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte)/* patch dcbz into reserved instruction, so we trap */ for (i=hpage_offset; i < hpage_offset + (HW_PAGE_SIZE /4 ); i++) -if ((page[i] &0xff0007ff ) =INS_DCBZ ) - page[i] &=0xfffffff7 ; +if ((be32_to_cpu (page[i]) &0xff0007ff ) =INS_DCBZ ) + page[i] &=cpu_to_be32 (0xfffffff7 );kunmap_atomic (page);put_page (hpage);
Signature · 1 line
1.8.1.4
PATCH 13/13 KVM: PPC: Book3S: Move little endian conflict to HV KVM
In reply to Alexander GrafWith the previous patches applied, we can now successfully use PR KVM on little endian hosts which means we can now allow users to select it.
However, HV KVM still needs some work, so let's keep the kconfig conflict on that one.
--- arch/powerpc/kvm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/Kconfig +1 -1
@@ -6,7 +6,6 @@ source "virt/kvm/Kconfig" menuconfig VIRTUALIZATION bool "Virtualization" - depends on !CPU_LITTLE_ENDIAN ---help--- Say Y here to get to see options for using your Linux host to run other operating systems inside virtual machines (guests).
@@ -76,6 +75,7 @@ config KVM_BOOK3S_64 config KVM_BOOK3S_64_HV tristate "KVM support for POWER7 and PPC970 using hypervisor mode in host" depends on KVM_BOOK3S_64 + depends on !CPU_LITTLE_ENDIAN select KVM_BOOK3S_HV_POSSIBLE select MMU_NOTIFIER select CMA
Signature · 1 line
1.8.1.4