Clean up page size handling for ppc 64-bit hash MMUs with TCG
cover Clean up page size handling for ppc 64-bit hash MMUs with TCG
Encoding of page sizes on 64-bit hash MMUs for Power is rather arcane, involving control bits in both the SLB and HPTE. At present we support a few of the options, but far fewer than real hardware.
We're able to get away with that in practice, because guests use a device tree property to determine which page sizes are available and we are setting that to match. However, the fact that the actual code doesn't necessarily what we put into the table of available page sizes is another ugliness.
This series makes a number of cleanups to the page size handling. The upshot is that afterwards the softmmu code operates off the same page size encoding table that is advertised to the guests, ensuring that they will be in sync.
Finally, we extend the table of allowed sizes for POWER7 and POWER8 to include the options allowed in hardware (including MPSS). We can fix other hash MMU based CPUs in future if anyone cares enough.
Please review, and I'll fold into ppc-for-2.6 for my next pull.
Changes since RFC:
* Moved lookup of SLB encodings table from SLB lookup time to SLB store time
David Gibson (10):
target-ppc: Remove unused kvmppc_read_segment_page_sizes() stub
target-ppc: Convert mmu-hash{32,64}.[ch] from CPUPPCState to
PowerPCCPU
target-ppc: Rework ppc_store_slb
target-ppc: Rework SLB page size lookup
target-ppc: Use actual page size encodings from HPTE
target-ppc: Remove unused mmu models from ppc_tlb_invalidate_one
target-ppc: Split 44x tlbiva from ppc_tlb_invalidate_one()
target-ppc: Add new TLB invalidate by HPTE call for hash64 MMUs
target-ppc: Helper to determine page size information from hpte alone
target-ppc: Allow more page sizes for POWER7 & POWER8 in TCG
hw/ppc/spapr_hcall.c | 102 ++++------------ target-ppc/cpu.h | 1 + target-ppc/helper.h | 1 + target-ppc/kvm.c | 2 +- target-ppc/kvm_ppc.h | 5 - target-ppc/machine.c | 20 ++++ target-ppc/mmu-hash32.c | 68 ++++++----- target-ppc/mmu-hash32.h | 30 ++--- target-ppc/mmu-hash64.c | 286 ++++++++++++++++++++++++++++++++------------ target-ppc/mmu-hash64.h | 30 +++-- target-ppc/mmu_helper.c | 59 ++++----- target-ppc/translate.c | 2 +- target-ppc/translate_init.c | 32 +++++ 13 files changed, 389 insertions(+), 249 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/10 target-ppc: Remove unused kvmppc_read_segment_page_sizes() stub
This stub function is in the !KVM ifdef in target-ppc/kvm_ppc.h. However no such function exists on the KVM side, or is ever used.
I think this originally referenced a function which read host page size information from /proc, for we we now use the KVM GET_SMMU_INFO extension instead.
In any case, it has no function now, so remove it.
--- target-ppc/kvm_ppc.h | 5 ----- 1 file changed, 5 deletions(-)
target-ppc/kvm_ppc.h +0 -5
@@ -98,11 +98,6 @@ static inline int kvmppc_get_hypercall(CPUPPCState *env, uint8_t *buf, int buf_lreturn -1 ; } -static inline int kvmppc_read_segment_page_sizes (uint32_t *prop,int maxcells) -{ -return -1 ; -} -static inline int kvmppc_set_interrupt (PowerPCCPU *cpu,int irq,int level) {return -1 ;
Signature · 1 line
2.5.0
PATCH 2/10 target-ppc: Convert mmu-hash{32, 64}.[ch] from CPUPPCState to PowerPCCPU
In reply to David GibsonLike a lot of places these files include a mixture of functions taking both the older CPUPPCState *env and newer PowerPCCPU *cpu. Move a step closer to cleaning this up by standardizing on PowerPCCPU, except for the helper_* functions which are called with the CPUPPCState * from tcg.
Callers and some related functions are updated as well, the boundaries of what's changed here are a bit arbitrary.
--- hw/ppc/spapr_hcall.c | 31 ++++++++++--------- target-ppc/kvm.c | 2 +- target-ppc/mmu-hash32.c | 68 +++++++++++++++++++++++------------------ target-ppc/mmu-hash32.h | 30 ++++++++++--------- target-ppc/mmu-hash64.c | 80 +++++++++++++++++++++++++++++-------------------- target-ppc/mmu-hash64.h | 21 ++++++------- target-ppc/mmu_helper.c | 13 ++++---- 7 files changed, 136 insertions(+), 109 deletions(-)
hw/ppc/spapr_hcall.c +15 -16
@@ -160,7 +160,7 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *spapr, pte_index &= ~7ULL ; token =ppc_hash64_start_access (cpu, pte_index);for (; index <8 ; index++) { -if ((ppc_hash64_load_hpte0 (env, token, index) &HPTE64_V_VALID ) ==0 ) { +if (!(ppc_hash64_load_hpte0 (cpu, token, index) &HPTE64_V_VALID )) {break ; } }
@@ -170,14 +170,14 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *spapr, } }else { token =ppc_hash64_start_access (cpu, pte_index); -if (ppc_hash64_load_hpte0 (env, token,0 ) &HPTE64_V_VALID ) { +if (ppc_hash64_load_hpte0 (cpu, token,0 ) &HPTE64_V_VALID ) {ppc_hash64_stop_access (token);return H_PTEG_FULL ; }ppc_hash64_stop_access (token); } -ppc_hash64_store_hpte (env, pte_index + index, +ppc_hash64_store_hpte (cpu, pte_index + index, pteh |HPTE64_V_HPTE_DIRTY , ptel); args[0 ] = pte_index + index;
@@ -191,11 +191,12 @@ typedef enum {REMOVE_HW =3 , } RemoveResult; -static RemoveResult remove_hpte (CPUPPCState *env,target_ulong ptex, +static RemoveResult remove_hpte (PowerPCCPU *cpu,target_ulong ptex,target_ulong avpn,target_ulong flags,target_ulong *vp,target_ulong *rp) { +CPUPPCState *env = &cpu->env;uint64_t token;target_ulong v, r, rb;
@@ -203,9 +204,9 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex,return REMOVE_PARM ; } - token =ppc_hash64_start_access (ppc_env_get_cpu (env), ptex); - v =ppc_hash64_load_hpte0 (env, token,0 ); - r =ppc_hash64_load_hpte1 (env, token,0 ); + token =ppc_hash64_start_access (cpu, ptex); + v =ppc_hash64_load_hpte0 (cpu, token,0 ); + r =ppc_hash64_load_hpte1 (cpu, token,0 );ppc_hash64_stop_access (token); if ((v & HPTE64_V_VALID) == 0 ||
@@ -215,7 +216,7 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex, } *vp = v; *rp = r; -ppc_hash64_store_hpte (env, ptex,HPTE64_V_HPTE_DIRTY ,0 ); +ppc_hash64_store_hpte (cpu, ptex,HPTE64_V_HPTE_DIRTY ,0 ); rb =compute_tlbie_rb (v, r, ptex);ppc_tlb_invalidate_one (env, rb);return REMOVE_SUCCESS ;
@@ -224,13 +225,12 @@ static RemoveResult remove_hpte(CPUPPCState *env, target_ulong ptex,static target_ulong h_remove (PowerPCCPU *cpu,sPAPRMachineState *spapr,target_ulong opcode,target_ulong *args) { -CPUPPCState *env = &cpu->env;target_ulong flags = args[0 ];target_ulong pte_index = args[1 ];target_ulong avpn = args[2 ];RemoveResult ret; - ret =remove_hpte (env, pte_index, avpn, flags, + ret =remove_hpte (cpu, pte_index, avpn, flags, &args[0 ], &args[1 ]);switch (ret) {
@@ -271,7 +271,6 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,static target_ulong h_bulk_remove (PowerPCCPU *cpu,sPAPRMachineState *spapr,target_ulong opcode,target_ulong *args) { -CPUPPCState *env = &cpu->env;int i;for (i =0 ; i <H_BULK_REMOVE_MAX_BATCH ; i++) {
@@ -293,7 +292,7 @@ static target_ulong h_bulk_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,return H_PARAMETER ; } - ret =remove_hpte (env, *tsh &H_BULK_REMOVE_PTEX , tsl, + ret =remove_hpte (cpu, *tsh &H_BULK_REMOVE_PTEX , tsl, (*tsh &H_BULK_REMOVE_FLAGS ) >>26 , &v, &r);
@@ -330,8 +329,8 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPRMachineState *spapr, } token =ppc_hash64_start_access (cpu, pte_index); - v =ppc_hash64_load_hpte0 (env, token,0 ); - r =ppc_hash64_load_hpte1 (env, token,0 ); + v =ppc_hash64_load_hpte0 (cpu, token,0 ); + r =ppc_hash64_load_hpte1 (cpu, token,0 );ppc_hash64_stop_access (token); if ((v & HPTE64_V_VALID) == 0 ||
@@ -345,11 +344,11 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPRMachineState *spapr, r |= (flags <<48 ) &HPTE64_R_KEY_HI ; r |= flags & (HPTE64_R_PP |HPTE64_R_N |HPTE64_R_KEY_LO ); rb =compute_tlbie_rb (v, r, pte_index); -ppc_hash64_store_hpte (env, pte_index, +ppc_hash64_store_hpte (cpu, pte_index, (v & ~HPTE64_V_VALID ) |HPTE64_V_HPTE_DIRTY ,0 );ppc_tlb_invalidate_one (env, rb);/* Don't need a memory barrier, due to qemu's global lock */ -ppc_hash64_store_hpte (env, pte_index, v |HPTE64_V_HPTE_DIRTY , r); +ppc_hash64_store_hpte (cpu, pte_index, v |HPTE64_V_HPTE_DIRTY , r);return H_SUCCESS ; }
target-ppc/kvm.c +1 -1
@@ -1205,7 +1205,7 @@ int kvm_arch_get_registers(CPUState *cs)* Only restore valid entries */ if (rb &SLB_ESID_V ) { -ppc_store_slb (env, rb, rs); +ppc_store_slb (cpu, rb, rs); } }#endif
target-ppc/mmu-hash32.c +39 -29
221 lines not on this page · raw message
target-ppc/mmu-hash32.h +16 -14
@@ -3,8 +3,8 @@#ifndef CONFIG_USER_ONLY -hwaddr get_pteg_offset32 (CPUPPCState *env,hwaddr hash); -hwaddr ppc_hash32_get_phys_page_debug (CPUPPCState *env,target_ulong addr); +hwaddr get_pteg_offset32 (PowerPCCPU *cpu,hwaddr hash); +hwaddr ppc_hash32_get_phys_page_debug (PowerPCCPU *cpu,target_ulong addr);int ppc_hash32_handle_mmu_fault (PowerPCCPU *cpu,target_ulong address,int rw,int mmu_idx);
@@ -65,40 +65,42 @@ int ppc_hash32_handle_mmu_fault(PowerPCCPU *cpu, target_ulong address, int rw,#define HPTE32_R_WIMG 0x00000078#define HPTE32_R_PP 0x00000003 -static inline target_ulong ppc_hash32_load_hpte0 (CPUPPCState *env, +static inline target_ulong ppc_hash32_load_hpte0 (PowerPCCPU *cpu,hwaddr pte_offset) { -CPUState *cs =CPU (ppc_env_get_cpu (env)); +CPUPPCState *env = &cpu->env;assert (!env->external_htab);/* Not supported on 32-bit for now */ -return ldl_phys (cs->as, env->htab_base + pte_offset); +return ldl_phys (CPU (cpu)->as, env->htab_base + pte_offset); } -static inline target_ulong ppc_hash32_load_hpte1 (CPUPPCState *env, +static inline target_ulong ppc_hash32_load_hpte1 (PowerPCCPU *cpu,hwaddr pte_offset) { -CPUState *cs =CPU (ppc_env_get_cpu (env)); +CPUPPCState *env = &cpu->env;assert (!env->external_htab);/* Not supported on 32-bit for now */ -return ldl_phys (cs->as, env->htab_base + pte_offset +HASH_PTE_SIZE_32 /2 ); +return ldl_phys (CPU (cpu)->as, + env->htab_base + pte_offset +HASH_PTE_SIZE_32 /2 ); } -static inline void ppc_hash32_store_hpte0 (CPUPPCState *env, +static inline void ppc_hash32_store_hpte0 (PowerPCCPU *cpu,hwaddr pte_offset,target_ulong pte0) { -CPUState *cs =CPU (ppc_env_get_cpu (env)); +CPUPPCState *env = &cpu->env;assert (!env->external_htab);/* Not supported on 32-bit for now */ -stl_phys (cs->as, env->htab_base + pte_offset, pte0); +stl_phys (CPU (cpu)->as, env->htab_base + pte_offset, pte0); } -static inline void ppc_hash32_store_hpte1 (CPUPPCState *env, +static inline void ppc_hash32_store_hpte1 (PowerPCCPU *cpu,hwaddr pte_offset,target_ulong pte1) { -CPUState *cs =CPU (ppc_env_get_cpu (env)); +CPUPPCState *env = &cpu->env;assert (!env->external_htab);/* Not supported on 32-bit for now */ -stl_phys (cs->as, env->htab_base + pte_offset +HASH_PTE_SIZE_32 /2 , pte1); +stl_phys (CPU (cpu)->as, + env->htab_base + pte_offset +HASH_PTE_SIZE_32 /2 , pte1); } typedef struct {
target-ppc/mmu-hash64.c +47 -33
262 lines not on this page · raw message
target-ppc/mmu-hash64.h +11 -10
@@ -4,12 +4,13 @@#ifndef CONFIG_USER_ONLY #ifdef TARGET_PPC64 -void dump_slb (FILE *f,fprintf_function cpu_fprintf,CPUPPCState *env); -int ppc_store_slb (CPUPPCState *env,target_ulong rb,target_ulong rs); -hwaddr ppc_hash64_get_phys_page_debug (CPUPPCState *env,target_ulong addr); +void ppc_hash64_check_page_sizes (PowerPCCPU *cpu,Error **errp); +void dump_slb (FILE *f,fprintf_function cpu_fprintf,PowerPCCPU *cpu); +int ppc_store_slb (PowerPCCPU *cpu,target_ulong rb,target_ulong rs); +hwaddr ppc_hash64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong addr);int ppc_hash64_handle_mmu_fault (PowerPCCPU *cpu,target_ulong address,int rw,int mmu_idx); -void ppc_hash64_store_hpte (CPUPPCState *env,target_ulong index, +void ppc_hash64_store_hpte (PowerPCCPU *cpu,target_ulong index,target_ulong pte0,target_ulong pte1);#endif
@@ -85,31 +86,31 @@ extern bool kvmppc_kern_htab;uint64_t ppc_hash64_start_access (PowerPCCPU *cpu,target_ulong pte_index);void ppc_hash64_stop_access (uint64_t token); -static inline target_ulong ppc_hash64_load_hpte0 (CPUPPCState *env, +static inline target_ulong ppc_hash64_load_hpte0 (PowerPCCPU *cpu,uint64_t token,int index) { -CPUState *cs =CPU (ppc_env_get_cpu (env)); +CPUPPCState *env = &cpu->env;uint64_t addr; addr = token + (index *HASH_PTE_SIZE_64 );if (env->external_htab) {return ldq_p ((const void *)(uintptr_t )addr); }else { -return ldq_phys (cs->as, addr); +return ldq_phys (CPU (cpu)->as, addr); } } -static inline target_ulong ppc_hash64_load_hpte1 (CPUPPCState *env, +static inline target_ulong ppc_hash64_load_hpte1 (PowerPCCPU *cpu,uint64_t token,int index) { -CPUState *cs =CPU (ppc_env_get_cpu (env)); +CPUPPCState *env = &cpu->env;uint64_t addr; addr = token + (index *HASH_PTE_SIZE_64 ) +HASH_PTE_SIZE_64 /2 ;if (env->external_htab) {return ldq_p ((const void *)(uintptr_t )addr); }else { -return ldq_phys (cs->as, addr); +return ldq_phys (CPU (cpu)->as, addr); } }
target-ppc/mmu_helper.c +7 -6
@@ -1297,7 +1297,7 @@ void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env)case POWERPC_MMU_2_06a:case POWERPC_MMU_2_07 :case POWERPC_MMU_2_07a: -dump_slb (f, cpu_fprintf, env); +dump_slb (f, cpu_fprintf,ppc_env_get_cpu (env));break ;#endif default :
@@ -1439,12 +1439,12 @@ hwaddr ppc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)case POWERPC_MMU_2_06a:case POWERPC_MMU_2_07 :case POWERPC_MMU_2_07a: -return ppc_hash64_get_phys_page_debug (env, addr); +return ppc_hash64_get_phys_page_debug (cpu, addr);#endif case POWERPC_MMU_32B :case POWERPC_MMU_601 : -return ppc_hash32_get_phys_page_debug (env, addr); +return ppc_hash32_get_phys_page_debug (cpu, addr);default : ;
@@ -1510,6 +1510,7 @@ static int cpu_ppc_handle_mmu_fault(CPUPPCState *env, target_ulong address, int rw, int mmu_idx) {CPUState *cs =CPU (ppc_env_get_cpu (env)); +PowerPCCPU *cpu =POWERPC_CPU (cs);mmu_ctx_t ctx;int access_type;int ret =0 ;
@@ -1611,9 +1612,9 @@ static int cpu_ppc_handle_mmu_fault(CPUPPCState *env, target_ulong address, tlb_miss: env->error_code |= ctx.key <<19 ; env->spr[SPR_HASH1 ] = env->htab_base + -get_pteg_offset32 (env, ctx.hash[0 ]); +get_pteg_offset32 (cpu, ctx.hash[0 ]); env->spr[SPR_HASH2 ] = env->htab_base + -get_pteg_offset32 (env, ctx.hash[1 ]); +get_pteg_offset32 (cpu, ctx.hash[1 ]);break ;case POWERPC_MMU_SOFT_74xx:if (rw ==1 ) {
@@ -2101,7 +2102,7 @@ void helper_store_sr(CPUPPCState *env, target_ulong srnum, target_ulong value)/* flags = flags */ rs |= ((value >>27 ) &0xf ) <<8 ; -ppc_store_slb (env, rb, rs); +ppc_store_slb (cpu, rb, rs); } else#endif if (env->sr[srnum] != value) {
Signature · 1 line
2.5.0
PATCH 3/10 target-ppc: Rework ppc_store_slb
In reply to David Gibsonppc_store_slb updates the SLB for PPC cpus with 64-bit hash MMUs. Currently it takes two parameters, which contain values encoded as the register arguments to the slbmte instruction, one register contains the ESID portion of the SLBE and also the slot number, the other contains the VSID portion of the SLBE.
We're shortly going to want to do some SLB updates from other code where it is more convenient to supply the slot number and ESID separately, so rework this function and its callers to work this way.
As a bonus, this slightly simplifies the emulation of segment registers for when running a 32-bit OS on a 64-bit CPU.
--- target-ppc/kvm.c | 2 +- target-ppc/mmu-hash64.c | 24 +++++++++++++----------- target-ppc/mmu-hash64.h | 3 ++- target-ppc/mmu_helper.c | 14 +++++--------- 4 files changed, 21 insertions(+), 22 deletions(-)
target-ppc/kvm.c +1 -1
@@ -1205,7 +1205,7 @@ int kvm_arch_get_registers(CPUState *cs)* Only restore valid entries */ if (rb &SLB_ESID_V ) { -ppc_store_slb (cpu, rb, rs); +ppc_store_slb (cpu, rb &0xfff , rb & ~0xfff , rs); } }#endif
target-ppc/mmu-hash64.c +13 -11
@@ -135,28 +135,30 @@ void helper_slbie(CPUPPCState *env, target_ulong addr) } } -int ppc_store_slb (PowerPCCPU *cpu,target_ulong rb,target_ulong rs) +int ppc_store_slb (PowerPCCPU *cpu,target_ulong slot, +target_ulong esid,target_ulong vsid) {CPUPPCState *env = &cpu->env; -int slot = rb &0xfff ;ppc_slb_t *slb = &env->slb[slot]; -if (rb & (0x1000 - env->slb_nr)) { -return -1 ;/* Reserved bits set or slot too high */ +if (slot >= env->slb_nr) { +return -1 ;/* Bad slot number */ + } +if (esid & ~(SLB_ESID_ESID |SLB_ESID_V )) { +return -1 ;/* Reserved bits set */ } -if (rs & (SLB_VSID_B & ~SLB_VSID_B_1T )) { +if (vsid & (SLB_VSID_B & ~SLB_VSID_B_1T )) {return -1 ;/* Bad segment size */ } -if ((rs &SLB_VSID_B ) && !(env->mmu_model &POWERPC_MMU_1TSEG )) { +if ((vsid &SLB_VSID_B ) && !(env->mmu_model &POWERPC_MMU_1TSEG )) {return -1 ;/* 1T segment on MMU that doesn't support it */ } -/* Mask out the slot number as we store the entry */ - slb->esid = rb & (SLB_ESID_ESID |SLB_ESID_V ); - slb->vsid = rs; + slb->esid = esid; + slb->vsid = vsid;LOG_SLB ("%s: %d " TARGET_FMT_lx" - " TARGET_FMT_lx" => %016" PRIx64 -" %016" PRIx64"\n" , __func__, slot, rb, rs, +" %016" PRIx64"\n" , __func__, slot, esid, vsid, slb->esid, slb->vsid);return 0 ;
@@ -196,7 +198,7 @@ void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) {PowerPCCPU *cpu =ppc_env_get_cpu (env); -if (ppc_store_slb (cpu, rb, rs) <0 ) { +if (ppc_store_slb (cpu, rb &0xfff , rb & ~0xfff , rs) <0 ) {helper_raise_exception_err (env,POWERPC_EXCP_PROGRAM ,POWERPC_EXCP_INVAL ); }
target-ppc/mmu-hash64.h +2 -1
@@ -6,7 +6,8 @@#ifdef TARGET_PPC64 void ppc_hash64_check_page_sizes (PowerPCCPU *cpu,Error **errp);void dump_slb (FILE *f,fprintf_function cpu_fprintf,PowerPCCPU *cpu); -int ppc_store_slb (PowerPCCPU *cpu,target_ulong rb,target_ulong rs); +int ppc_store_slb (PowerPCCPU *cpu,target_ulong slot, +target_ulong esid,target_ulong vsid);hwaddr ppc_hash64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong addr);int ppc_hash64_handle_mmu_fault (PowerPCCPU *cpu,target_ulong address,int rw,int mmu_idx);
target-ppc/mmu_helper.c +5 -9
@@ -2088,21 +2088,17 @@ void helper_store_sr(CPUPPCState *env, target_ulong srnum, target_ulong value) (int)srnum, value, env->sr[srnum]);#if defined(TARGET_PPC64 )if (env->mmu_model &POWERPC_MMU_64 ) { -uint64_t rb =0 , rs =0 ; +uint64_t esid, vsid;/* ESID = srnum */ - rb |= ((uint32_t )srnum &0xf ) <<28 ; -/* Set the valid bit */ - rb |=SLB_ESID_V ; -/* Index = ESID */ - rb |= (uint32_t )srnum; + esid = ((uint64_t )(srnum &0xf ) <<28 ) |SLB_ESID_V ;/* VSID = VSID */ - rs |= (value &0xfffffff ) <<12 ; + vsid = (value &0xfffffff ) <<12 ;/* flags = flags */ - rs |= ((value >>27 ) &0xf ) <<8 ; + vsid |= ((value >>27 ) &0xf ) <<8 ; -ppc_store_slb (cpu, rb, rs); +ppc_store_slb (cpu, srnum, esid, vsid); } else#endif if (env->sr[srnum] != value) {
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 03/10] target-ppc: Rework ppc_store_slb
Quoted 80 lines · David Gibson
ppc_store_slbupdates the SLB for PPC cpus with 64-bit hash MMUs. Currently it takes two parameters, which contain values encoded as the register arguments to the slbmte instruction, one register contains the ESID portion of the SLBE and also the slot number, the other contains the VSID portion of the SLBE.We're shortly going to want to do some SLB updates from other code where it is more convenient to supply the slot number and ESID separately, so rework this function and its callers to work this way.
As a bonus, this slightly simplifies the emulation of segment registers for when running a 32-bit OS on a 64-bit CPU.
Signed-off-by David Gibson <[email protected]>--- target-ppc/kvm.c | 2 +- target-ppc/mmu-hash64.c | 24 +++++++++++++----------- target-ppc/mmu-hash64.h | 3 ++- target-ppc/mmu_helper.c | 14 +++++--------- 4 files changed, 21 insertions(+), 22 deletions(-)target-ppc/kvm.c +1
-1@@ -1205,7 +1205,7 @@ int kvm_arch_get_registers(CPUState *cs)* Only restore valid entries */ if (rb &SLB_ESID_V ) { -ppc_store_slb (cpu, rb, rs); +ppc_store_slb (cpu, rb &0xfff , rb & ~0xfff , rs); } }#endif target-ppc/mmu-hash64.c +12
-10@@ -135,28 +135,30 @@ void helper_slbie(CPUPPCState *env, target_ulong addr) } } -int ppc_store_slb (PowerPCCPU *cpu,target_ulong rb,target_ulong rs) +int ppc_store_slb (PowerPCCPU *cpu,target_ulong slot, +target_ulong esid,target_ulong vsid) {CPUPPCState *env = &cpu->env; -int slot = rb &0xfff ;ppc_slb_t *slb = &env->slb[slot]; -if (rb & (0x1000 - env->slb_nr)) { -return -1 ;/* Reserved bits set or slot too high */ +if (slot >= env->slb_nr) { +return -1 ;/* Bad slot number */ + } +if (esid & ~(SLB_ESID_ESID |SLB_ESID_V )) { +return -1 ;/* Reserved bits set */ } -if (rs & (SLB_VSID_B & ~SLB_VSID_B_1T )) { +if (vsid & (SLB_VSID_B & ~SLB_VSID_B_1T )) {return -1 ;/* Bad segment size */ } -if ((rs &SLB_VSID_B ) && !(env->mmu_model &POWERPC_MMU_1TSEG )) { +if ((vsid &SLB_VSID_B ) && !(env->mmu_model &POWERPC_MMU_1TSEG )) {return -1 ;/* 1T segment on MMU that doesn't support it */ } -/* Mask out the slot number as we store the entry */ - slb->esid = rb & (SLB_ESID_ESID |SLB_ESID_V ); - slb->vsid = rs; + slb->esid = esid; + slb->vsid = vsid;LOG_SLB ("%s: %d " TARGET_FMT_lx" - " TARGET_FMT_lx" => %016" PRIx64 -" %016" PRIx64"\n" , __func__, slot, rb, rs, +" %016" PRIx64"\n" , __func__, slot, esid, vsid, slb->esid, slb->vsid);return 0 ;
target-ppc/mmu-hash64.c void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) · line 201
Quoted 5 lines
target-ppc/mmu-hash64.c +1
-1@@ -196,7 +198,7 @@ void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) {PowerPCCPU *cpu =ppc_env_get_cpu (env); -if (ppc_store_slb (cpu, rb, rs) <0 ) { +if (ppc_store_slb (cpu, rb &0xfff , rb & ~0xfff , rs) <0 ) {
This might truncate the esid to 32bits on 32bits hosts, no? Should be 0xfffULL instead.
Alex
Quoted 48 lines
target-ppc/mmu-hash64.c +0
-0helper_raise_exception_err (env,POWERPC_EXCP_PROGRAM ,POWERPC_EXCP_INVAL ); }target-ppc/mmu-hash64.h +2
-1@@ -6,7 +6,8 @@#ifdef TARGET_PPC64 void ppc_hash64_check_page_sizes (PowerPCCPU *cpu,Error **errp);void dump_slb (FILE *f,fprintf_function cpu_fprintf,PowerPCCPU *cpu); -int ppc_store_slb (PowerPCCPU *cpu,target_ulong rb,target_ulong rs); +int ppc_store_slb (PowerPCCPU *cpu,target_ulong slot, +target_ulong esid,target_ulong vsid);hwaddr ppc_hash64_get_phys_page_debug (PowerPCCPU *cpu,target_ulong addr);int ppc_hash64_handle_mmu_fault (PowerPCCPU *cpu,target_ulong address,int rw,int mmu_idx);target-ppc/mmu_helper.c +5
-9@@ -2088,21 +2088,17 @@ void helper_store_sr(CPUPPCState *env, target_ulong srnum, target_ulong value) (int)srnum, value, env->sr[srnum]);#if defined(TARGET_PPC64 )if (env->mmu_model &POWERPC_MMU_64 ) { -uint64_t rb =0 , rs =0 ; +uint64_t esid, vsid;/* ESID = srnum */ - rb |= ((uint32_t )srnum &0xf ) <<28 ; -/* Set the valid bit */ - rb |=SLB_ESID_V ; -/* Index = ESID */ - rb |= (uint32_t )srnum; + esid = ((uint64_t )(srnum &0xf ) <<28 ) |SLB_ESID_V ;/* VSID = VSID */ - rs |= (value &0xfffffff ) <<12 ; + vsid = (value &0xfffffff ) <<12 ;/* flags = flags */ - rs |= ((value >>27 ) &0xf ) <<8 ; + vsid |= ((value >>27 ) &0xf ) <<8 ; -ppc_store_slb (cpu, rb, rs); +ppc_store_slb (cpu, srnum, esid, vsid); } else#endif if (env->sr[srnum] != value) {
Re: [Qemu-devel] [PATCH 03/10] target-ppc: Rework ppc_store_slb
Quoted 77 lines · Alexander Graf
Quoted 74 lines · David Gibson
ppc_store_slbupdates the SLB for PPC cpus with 64-bit hash MMUs. Currently it takes two parameters, which contain values encoded as the register arguments to the slbmte instruction, one register contains the ESID portion of the SLBE and also the slot number, the other contains the VSID portion of the SLBE.We're shortly going to want to do some SLB updates from other code where it is more convenient to supply the slot number and ESID separately, so rework this function and its callers to work this way.
As a bonus, this slightly simplifies the emulation of segment registers for when running a 32-bit OS on a 64-bit CPU.
Signed-off-by David Gibson <[email protected]>--- target-ppc/kvm.c | 2 +- target-ppc/mmu-hash64.c | 24 +++++++++++++----------- target-ppc/mmu-hash64.h | 3 ++- target-ppc/mmu_helper.c | 14 +++++--------- 4 files changed, 21 insertions(+), 22 deletions(-)target-ppc/kvm.c +1
-1@@ -1205,7 +1205,7 @@ int kvm_arch_get_registers(CPUState *cs)* Only restore valid entries */ if (rb &SLB_ESID_V ) { -ppc_store_slb (cpu, rb, rs); +ppc_store_slb (cpu, rb &0xfff , rb & ~0xfff , rs); } }#endif target-ppc/mmu-hash64.c +12
-10@@ -135,28 +135,30 @@ void helper_slbie(CPUPPCState *env, target_ulong addr) } } -int ppc_store_slb (PowerPCCPU *cpu,target_ulong rb,target_ulong rs) +int ppc_store_slb (PowerPCCPU *cpu,target_ulong slot, +target_ulong esid,target_ulong vsid) {CPUPPCState *env = &cpu->env; -int slot = rb &0xfff ;ppc_slb_t *slb = &env->slb[slot]; -if (rb & (0x1000 - env->slb_nr)) { -return -1 ;/* Reserved bits set or slot too high */ +if (slot >= env->slb_nr) { +return -1 ;/* Bad slot number */ + } +if (esid & ~(SLB_ESID_ESID |SLB_ESID_V )) { +return -1 ;/* Reserved bits set */ } -if (rs & (SLB_VSID_B & ~SLB_VSID_B_1T )) { +if (vsid & (SLB_VSID_B & ~SLB_VSID_B_1T )) {return -1 ;/* Bad segment size */ } -if ((rs &SLB_VSID_B ) && !(env->mmu_model &POWERPC_MMU_1TSEG )) { +if ((vsid &SLB_VSID_B ) && !(env->mmu_model &POWERPC_MMU_1TSEG )) {return -1 ;/* 1T segment on MMU that doesn't support it */ } -/* Mask out the slot number as we store the entry */ - slb->esid = rb & (SLB_ESID_ESID |SLB_ESID_V ); - slb->vsid = rs; + slb->esid = esid; + slb->vsid = vsid;LOG_SLB ("%s: %d " TARGET_FMT_lx" - " TARGET_FMT_lx" => %016" PRIx64 -" %016" PRIx64"\n" , __func__, slot, rb, rs, +" %016" PRIx64"\n" , __func__, slot, esid, vsid, slb->esid, slb->vsid);return 0 ;
Quoted 8 lines
target-ppc/mmu-hash64.c void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) · line 200
Quoted 5 lines
target-ppc/mmu-hash64.c +1
-1@@ -196,7 +198,7 @@ void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) {PowerPCCPU *cpu =ppc_env_get_cpu (env); -if (ppc_store_slb (cpu, rb, rs) <0 ) { +if (ppc_store_slb (cpu, rb &0xfff , rb & ~0xfff , rs) <0 ) {This might truncate the esid to 32bits on 32bits hosts, no? Should be
0xfffULLinstead.
Good point, nice catch.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH 03/10] target-ppc: Rework ppc_store_slb
Quoted 24 lines · David Gibson
Quoted 23 lines · Alexander Graf
Quoted 20 lines · David Gibson
ppc_store_slbupdates the SLB for PPC cpus with 64-bit hash MMUs. Currently it takes two parameters, which contain values encoded as the register arguments to the slbmte instruction, one register contains the ESID portion of the SLBE and also the slot number, the other contains the VSID portion of the SLBE.We're shortly going to want to do some SLB updates from other code where it is more convenient to supply the slot number and ESID separately, so rework this function and its callers to work this way.
As a bonus, this slightly simplifies the emulation of segment registers for when running a 32-bit OS on a 64-bit CPU.
Signed-off-by David Gibson <[email protected]>--- target-ppc/kvm.c | 2 +- target-ppc/mmu-hash64.c | 24 +++++++++++++----------- target-ppc/mmu-hash64.h | 3 ++- target-ppc/mmu_helper.c | 14 +++++--------- 4 files changed, 21 insertions(+), 22 deletions(-)
...
Quoted 10 lines
Quoted 8 lines
target-ppc/mmu-hash64.c void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) · line 200
Quoted 5 lines
target-ppc/mmu-hash64.c +1
-1@@ -196,7 +198,7 @@ void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) {PowerPCCPU *cpu =ppc_env_get_cpu (env); -if (ppc_store_slb (cpu, rb, rs) <0 ) { +if (ppc_store_slb (cpu, rb &0xfff , rb & ~0xfff , rs) <0 ) {This might truncate the esid to 32bits on 32bits hosts, no? Should be
0xfffULLinstead.Good point, nice catch.
Are you sure that it is really needed? If I run the following test program on my 64-bit system:
int main()
{
unsigned long long ll = -1ULL;
printf("%llx %llx\n", ll, ll & ~0xfff);
return 0;
}Then I get this output:
ffffffffffffffff fffffffffffff000
So it sounds like the value is sign-extended when it is cast to 64-bit.
However, if you respin this patch series anyway, then maybe better add the ULL for clarity.
Thomas
Re: [Qemu-devel] [PATCH 03/10] target-ppc: Rework ppc_store_slb
Quoted 47 lines · Thomas Huth
Quoted 24 lines · David Gibson
Quoted 23 lines · Alexander Graf
Quoted 20 lines · David Gibson
ppc_store_slbupdates the SLB for PPC cpus with 64-bit hash MMUs. Currently it takes two parameters, which contain values encoded as the register arguments to the slbmte instruction, one register contains the ESID portion of the SLBE and also the slot number, the other contains the VSID portion of the SLBE.We're shortly going to want to do some SLB updates from other code where it is more convenient to supply the slot number and ESID separately, so rework this function and its callers to work this way.
As a bonus, this slightly simplifies the emulation of segment registers for when running a 32-bit OS on a 64-bit CPU.
Signed-off-by David Gibson <[email protected]>--- target-ppc/kvm.c | 2 +- target-ppc/mmu-hash64.c | 24 +++++++++++++----------- target-ppc/mmu-hash64.h | 3 ++- target-ppc/mmu_helper.c | 14 +++++--------- 4 files changed, 21 insertions(+), 22 deletions(-)...
Quoted 10 lines
Quoted 8 lines
target-ppc/mmu-hash64.c void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) · line 200
Quoted 5 lines
target-ppc/mmu-hash64.c +1
-1@@ -196,7 +198,7 @@ void helper_store_slb(CPUPPCState *env, target_ulong rb, target_ulong rs) {PowerPCCPU *cpu =ppc_env_get_cpu (env); -if (ppc_store_slb (cpu, rb, rs) <0 ) { +if (ppc_store_slb (cpu, rb &0xfff , rb & ~0xfff , rs) <0 ) {This might truncate the esid to 32bits on 32bits hosts, no? Should be
0xfffULLinstead.Good point, nice catch.
Are you sure that it is really needed? If I run the following test program on my 64-bit system:
int
main(){ unsigned long long ll = -1ULL; printf("%llx %llx\n", ll, ll & ~0xfff); return 0; }
Quoted 6 lines
Then I get this output:
ffffffffffffffff
fffffffffffff000So it sounds like the value is sign-extended when it is cast to 64-bit.
Ah, yes. It would be promoted to s64 and sign extended before being promoted to u64. Still that's a pretty subtle detail to be relying on.
Quoted 2 lines
However, if you respin this patch series anyway, then maybe better add the ULL for clarity.
Already done.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 4/10 target-ppc: Rework SLB page size lookup
In reply to David GibsonCurrently, the ppc_hash64_page_shift() function looks up a page size based on information in an SLB entry. It open codes the bit translation for existing CPUs, however different CPU models can have different SLB encodings. We already store those in the 'sps' table in CPUPPCState, but we don't currently enforce that that actually matches the logic in ppc_hash64_page_shift.
This patch reworks lookup of page size from SLB in several ways:
* ppc_store_slb() will now fail (triggering an illegal instruction exception) if given a bad SLB page size encoding
* On success ppc_store_slb() stores a pointer to the relevant entry in the page size table in the SLB entry. This is looked up directly from the published table of page size encodings, so can't get out ot sync.
* ppc_hash64_htab_lookup() and others now use this precached page size information rather than decoding the SLB values
* Adjust ppc_hash64_pte_raddr() to take a page shift directly instead of an SLB entry. We'll be wanting the flexibility shortly.
* Adjust ppc_hash64_pte_raddr() to take a page shift directly instead of an SLB entry. Both callers now have easy access to this, and we'll need the flexibility shortly.
--- target-ppc/cpu.h | 1 + target-ppc/machine.c | 20 ++++++++++++++ target-ppc/mmu-hash64.c | 71 ++++++++++++++++++++++++++----------------------- 3 files changed, 59 insertions(+), 33 deletions(-)
target-ppc/cpu.h +1 -0
@@ -419,6 +419,7 @@ typedef struct ppc_slb_t ppc_slb_t;struct ppc_slb_t {uint64_t esid;uint64_t vsid; +const struct ppc_one_seg_page_size *sps; };#define MAX_SLB_ENTRIES 64
target-ppc/machine.c +20 -0
@@ -2,6 +2,7 @@#include "hw/boards.h" #include "sysemu/kvm.h" #include "helper_regs.h" +#include "mmu-hash64.h" static int cpu_load_old (QEMUFile *f,void *opaque,int version_id) {
@@ -352,11 +353,30 @@ static bool slb_needed(void *opaque)return (cpu->env.mmu_model &POWERPC_MMU_64 ); } +static int slb_post_load (void *opaque,int version_id) +{ +PowerPCCPU *cpu = opaque; +CPUPPCState *env = &cpu->env; +int i; + +/* We've pulled in the raw esid and vsid values from the migration +* stream, but we need to recompute the page size pointers */ +for (i =0 ; i < env->slb_nr; i++) { +if (ppc_store_slb (cpu, i, env->slb[i].esid, env->slb[i].vsid) <0 ) { +/* Migration source had bad values in its SLB */ +return -1 ; + } + } + +return 0 ; +} +static const VMStateDescription vmstate_slb = { .name ="cpu/slb" , .version_id =1 , .minimum_version_id =1 , .needed = slb_needed, + .post_load = slb_post_load, .fields = (VMStateField []) {VMSTATE_INT32_EQUAL (env.slb_nr, PowerPCCPU),VMSTATE_SLB_ARRAY (env.slb, PowerPCCPU,MAX_SLB_ENTRIES ),
target-ppc/mmu-hash64.c +38 -33
134 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 04/10] target-ppc: Rework SLB page size lookup
Quoted 199 lines · David Gibson
Currently, the
ppc_hash64_page_shift()function looks up a page size based on information in an SLB entry. It open codes the bit translation for existing CPUs, however different CPU models can have different SLB encodings. We already store those in the 'sps' table in CPUPPCState, but we don't currently enforce that that actually matches the logic inppc_hash64_page_shift.This patch reworks lookup of page size from SLB in several ways:
*ppc_store_slb()will now fail (triggering an illegal instruction exception) if given a bad SLB page size encoding
* On successppc_store_slb()stores a pointer to the relevant entry in the page size table in the SLB entry. This is looked up directly from the published table of page size encodings, so can't get out ot sync.
*ppc_hash64_htab_lookup()and others now use this precached page size information rather than decoding the SLB values
* Adjustppc_hash64_pte_raddr()to take a page shift directly instead of an SLB entry. We'll be wanting the flexibility shortly.
* Adjustppc_hash64_pte_raddr()to take a page shift directly instead of an SLB entry. Both callers now have easy access to this, and we'll need the flexibility shortly.Signed-off-by David Gibson <[email protected]>--- target-ppc/cpu.h | 1 + target-ppc/machine.c | 20 ++++++++++++++ target-ppc/mmu-hash64.c | 71 ++++++++++++++++++++++++++----------------------- 3 files changed, 59 insertions(+), 33 deletions(-)target-ppc/cpu.h +1
-0@@ -419,6 +419,7 @@ typedef struct ppc_slb_t ppc_slb_t;struct ppc_slb_t {uint64_t esid;uint64_t vsid; +const struct ppc_one_seg_page_size *sps; };#define MAX_SLB_ENTRIES 64target-ppc/machine.c +20
-0@@ -2,6 +2,7 @@#include "hw/boards.h" #include "sysemu/kvm.h" #include "helper_regs.h" +#include "mmu-hash64.h" static int cpu_load_old (QEMUFile *f,void *opaque,int version_id) {@@ -352,11 +353,30 @@ static bool slb_needed(void *opaque)return (cpu->env.mmu_model &POWERPC_MMU_64 ); } +static int slb_post_load (void *opaque,int version_id) +{ +PowerPCCPU *cpu = opaque; +CPUPPCState *env = &cpu->env; +int i; + +/* We've pulled in the raw esid and vsid values from the migration +* stream, but we need to recompute the page size pointers */ +for (i =0 ; i < env->slb_nr; i++) { +if (ppc_store_slb (cpu, i, env->slb[i].esid, env->slb[i].vsid) <0 ) { +/* Migration source had bad values in its SLB */ +return -1 ; + } + } + +return 0 ; +} +static const VMStateDescription vmstate_slb = { .name ="cpu/slb" , .version_id =1 , .minimum_version_id =1 , .needed = slb_needed, + .post_load = slb_post_load, .fields = (VMStateField []) {VMSTATE_INT32_EQUAL (env.slb_nr, PowerPCCPU),VMSTATE_SLB_ARRAY (env.slb, PowerPCCPU,MAX_SLB_ENTRIES ),target-ppc/mmu-hash64.c +33
-26@@ -19,6 +19,7 @@*/ #include "cpu.h" #include "exec/helper-proto.h" +#include "qemu/error-report.h" #include "sysemu/kvm.h" #include "kvm_ppc.h" #include "mmu-hash64.h" @@ -140,6 +141,8 @@ int ppc_store_slb(PowerPCCPU *cpu, target_ulong slot, {CPUPPCState *env = &cpu->env;ppc_slb_t *slb = &env->slb[slot]; +const struct ppc_one_seg_page_size *sps =NULL ; +int i;if (slot >= env->slb_nr) {return -1 ;/* Bad slot number */ @@ -154,8 +157,29 @@ int ppc_store_slb(PowerPCCPU *cpu, target_ulong slot,return -1 ;/* 1T segment on MMU that doesn't support it */ } +for (i =0 ; i <PPC_PAGE_SIZES_MAX_SZ ; i++) { +const struct ppc_one_seg_page_size *sps1 = &env->sps.sps[i]; + +if (!sps1->page_shift) { +break ; + } + +if ((vsid &SLB_VSID_LLP_MASK ) == sps1->slb_enc) { + sps = sps1; +break ; + } + } + +if (!sps) { +error_report ("Bad page size encoding in SLB store: slot " TARGET_FMT_lu +" esid 0x" TARGET_FMT_lx" vsid 0x" TARGET_FMT_lx, + slot, esid, vsid); +return -1 ; + } + slb->esid = esid; slb->vsid = vsid; + slb->sps = sps; LOG_SLB("%s: %d " TARGET_FMT_lx " - " TARGET_FMT_lx " => %016" PRIx64 " %016" PRIx64 "\n", __func__, slot, esid, vsid,@@ -394,24 +418,6 @@ static hwaddr ppc_hash64_pteg_search(PowerPCCPU *cpu, hwaddr hash,return -1 ; } -static uint64_t ppc_hash64_page_shift (ppc_slb_t *slb) -{ -uint64_t epnshift; - -/* Page size according to the SLB, which we use to generate the -* EPN for hash table lookup.. When we implement more recent MMU -* extensions this might be different from the actual page size -* encoded in the PTE */ -if ((slb->vsid &SLB_VSID_LLP_MASK ) ==SLB_VSID_4K ) { - epnshift =TARGET_PAGE_BITS ; - }else if ((slb->vsid &SLB_VSID_LLP_MASK ) ==SLB_VSID_64K ) { - epnshift =TARGET_PAGE_BITS_64K ; - }else { - epnshift =TARGET_PAGE_BITS_16M ; - } -return epnshift; -} -static hwaddr ppc_hash64_htab_lookup (PowerPCCPU *cpu,ppc_slb_t *slb,target_ulong eaddr,ppc_hash_pte64_t *pte)@@ -419,21 +425,24 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu,CPUPPCState *env = &cpu->env;hwaddr pte_offset;hwaddr hash; -uint64_t vsid, epnshift, epnmask, epn, ptem; +uint64_t vsid, epnmask, epn, ptem; + +/* The SLB store path should prevent any bad page size encodings +* getting in there, so: */ +assert (slb->sps); - epnshift =ppc_hash64_page_shift (slb); - epnmask = ~((1ULL << epnshift) -1 ); + epnmask = ~((1ULL << slb->sps->page_shift) -1 );if (slb->vsid &SLB_VSID_B ) {/* 1TB segment */ vsid = (slb->vsid &SLB_VSID_VSID ) >>SLB_VSID_SHIFT_1T ; epn = (eaddr & ~SEGMENT_MASK_1T ) & epnmask; - hash = vsid ^ (vsid <<25 ) ^ (epn >> epnshift); + hash = vsid ^ (vsid <<25 ) ^ (epn >> slb->sps->page_shift); }else {/* 256M segment */ vsid = (slb->vsid &SLB_VSID_VSID ) >>SLB_VSID_SHIFT ; epn = (eaddr & ~SEGMENT_MASK_256M ) & epnmask; - hash = vsid ^ (epn >> epnshift); + hash = vsid ^ (epn >> slb->sps->page_shift); } ptem = (slb->vsid &SLB_VSID_PTEM ) | ((epn >>16 ) &HPTE64_V_AVPN );@@ -465,17 +474,12 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu,return pte_offset; } -static hwaddr ppc_hash64_pte_raddr (ppc_slb_t *slb,ppc_hash_pte64_t pte, +static hwaddr ppc_hash64_pte_raddr (unsigned page_shift,ppc_hash_pte64_t pte,target_ulong eaddr) { -hwaddr mask; -int target_page_bits;
target-ppc/mmu-hash64.c static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu, · line 484
Quoted 10 lines
target-ppc/mmu-hash64.c +2
-5+hwaddr mask = (1ULL << page_shift) -1 ;hwaddr rpn = pte.pte1 &HPTE64_R_RPN ; -/* -* We support 4K, 64K and 16M now -*/ - target_page_bits =ppc_hash64_page_shift (slb); - mask = (1ULL << target_page_bits) -1 ; +return (rpn & ~mask) | (eaddr & mask); }
Isn't this basically deposit64 by now?
Alex
Quoted 20 lines
target-ppc/mmu-hash64.c +3
-2@@ -600,7 +604,7 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr,/* 7. Determine the real address from the PTE */ - raddr =ppc_hash64_pte_raddr (slb, pte, eaddr); + raddr =ppc_hash64_pte_raddr (slb->sps->page_shift, pte, eaddr);tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , prot, mmu_idx,TARGET_PAGE_SIZE );@@ -630,7 +634,8 @@ hwaddr ppc_hash64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong addr)return -1 ; } -return ppc_hash64_pte_raddr (slb, pte, addr) &TARGET_PAGE_MASK ; +return ppc_hash64_pte_raddr (slb->sps->page_shift, pte, addr) + &TARGET_PAGE_MASK ; } void ppc_hash64_store_hpte(PowerPCCPU *cpu,
Re: [Qemu-devel] [PATCH 04/10] target-ppc: Rework SLB page size lookup
Quoted 195 lines · Alexander Graf
Quoted 192 lines · David Gibson
Currently, the
ppc_hash64_page_shift()function looks up a page size based on information in an SLB entry. It open codes the bit translation for existing CPUs, however different CPU models can have different SLB encodings. We already store those in the 'sps' table in CPUPPCState, but we don't currently enforce that that actually matches the logic inppc_hash64_page_shift.This patch reworks lookup of page size from SLB in several ways:
*ppc_store_slb()will now fail (triggering an illegal instruction exception) if given a bad SLB page size encoding
* On successppc_store_slb()stores a pointer to the relevant entry in the page size table in the SLB entry. This is looked up directly from the published table of page size encodings, so can't get out ot sync.
*ppc_hash64_htab_lookup()and others now use this precached page size information rather than decoding the SLB values
* Adjustppc_hash64_pte_raddr()to take a page shift directly instead of an SLB entry. We'll be wanting the flexibility shortly.
* Adjustppc_hash64_pte_raddr()to take a page shift directly instead of an SLB entry. Both callers now have easy access to this, and we'll need the flexibility shortly.Signed-off-by David Gibson <[email protected]>--- target-ppc/cpu.h | 1 + target-ppc/machine.c | 20 ++++++++++++++ target-ppc/mmu-hash64.c | 71 ++++++++++++++++++++++++++----------------------- 3 files changed, 59 insertions(+), 33 deletions(-)target-ppc/cpu.h +1
-0@@ -419,6 +419,7 @@ typedef struct ppc_slb_t ppc_slb_t;struct ppc_slb_t {uint64_t esid;uint64_t vsid; +const struct ppc_one_seg_page_size *sps; };#define MAX_SLB_ENTRIES 64target-ppc/machine.c +20
-0@@ -2,6 +2,7 @@#include "hw/boards.h" #include "sysemu/kvm.h" #include "helper_regs.h" +#include "mmu-hash64.h" static int cpu_load_old (QEMUFile *f,void *opaque,int version_id) {@@ -352,11 +353,30 @@ static bool slb_needed(void *opaque)return (cpu->env.mmu_model &POWERPC_MMU_64 ); } +static int slb_post_load (void *opaque,int version_id) +{ +PowerPCCPU *cpu = opaque; +CPUPPCState *env = &cpu->env; +int i; + +/* We've pulled in the raw esid and vsid values from the migration +* stream, but we need to recompute the page size pointers */ +for (i =0 ; i < env->slb_nr; i++) { +if (ppc_store_slb (cpu, i, env->slb[i].esid, env->slb[i].vsid) <0 ) { +/* Migration source had bad values in its SLB */ +return -1 ; + } + } + +return 0 ; +} +static const VMStateDescription vmstate_slb = { .name ="cpu/slb" , .version_id =1 , .minimum_version_id =1 , .needed = slb_needed, + .post_load = slb_post_load, .fields = (VMStateField []) {VMSTATE_INT32_EQUAL (env.slb_nr, PowerPCCPU),VMSTATE_SLB_ARRAY (env.slb, PowerPCCPU,MAX_SLB_ENTRIES ),target-ppc/mmu-hash64.c +34
-28@@ -19,6 +19,7 @@*/ #include "cpu.h" #include "exec/helper-proto.h" +#include "qemu/error-report.h" #include "sysemu/kvm.h" #include "kvm_ppc.h" #include "mmu-hash64.h" @@ -140,6 +141,8 @@ int ppc_store_slb(PowerPCCPU *cpu, target_ulong slot, {CPUPPCState *env = &cpu->env;ppc_slb_t *slb = &env->slb[slot]; +const struct ppc_one_seg_page_size *sps =NULL ; +int i;if (slot >= env->slb_nr) {return -1 ;/* Bad slot number */ @@ -154,8 +157,29 @@ int ppc_store_slb(PowerPCCPU *cpu, target_ulong slot,return -1 ;/* 1T segment on MMU that doesn't support it */ } +for (i =0 ; i <PPC_PAGE_SIZES_MAX_SZ ; i++) { +const struct ppc_one_seg_page_size *sps1 = &env->sps.sps[i]; + +if (!sps1->page_shift) { +break ; + } + +if ((vsid &SLB_VSID_LLP_MASK ) == sps1->slb_enc) { + sps = sps1; +break ; + } + } + +if (!sps) { +error_report ("Bad page size encoding in SLB store: slot " TARGET_FMT_lu +" esid 0x" TARGET_FMT_lx" vsid 0x" TARGET_FMT_lx, + slot, esid, vsid); +return -1 ; + } + slb->esid = esid; slb->vsid = vsid; + slb->sps = sps; LOG_SLB("%s: %d " TARGET_FMT_lx " - " TARGET_FMT_lx " => %016" PRIx64 " %016" PRIx64 "\n", __func__, slot, esid, vsid,@@ -394,24 +418,6 @@ static hwaddr ppc_hash64_pteg_search(PowerPCCPU *cpu, hwaddr hash,return -1 ; } -static uint64_t ppc_hash64_page_shift (ppc_slb_t *slb) -{ -uint64_t epnshift; - -/* Page size according to the SLB, which we use to generate the -* EPN for hash table lookup.. When we implement more recent MMU -* extensions this might be different from the actual page size -* encoded in the PTE */ -if ((slb->vsid &SLB_VSID_LLP_MASK ) ==SLB_VSID_4K ) { - epnshift =TARGET_PAGE_BITS ; - }else if ((slb->vsid &SLB_VSID_LLP_MASK ) ==SLB_VSID_64K ) { - epnshift =TARGET_PAGE_BITS_64K ; - }else { - epnshift =TARGET_PAGE_BITS_16M ; - } -return epnshift; -} -static hwaddr ppc_hash64_htab_lookup (PowerPCCPU *cpu,ppc_slb_t *slb,target_ulong eaddr,ppc_hash_pte64_t *pte)@@ -419,21 +425,24 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu,CPUPPCState *env = &cpu->env;hwaddr pte_offset;hwaddr hash; -uint64_t vsid, epnshift, epnmask, epn, ptem; +uint64_t vsid, epnmask, epn, ptem; + +/* The SLB store path should prevent any bad page size encodings +* getting in there, so: */ +assert (slb->sps); - epnshift =ppc_hash64_page_shift (slb); - epnmask = ~((1ULL << epnshift) -1 ); + epnmask = ~((1ULL << slb->sps->page_shift) -1 );if (slb->vsid &SLB_VSID_B ) {/* 1TB segment */ vsid = (slb->vsid &SLB_VSID_VSID ) >>SLB_VSID_SHIFT_1T ; epn = (eaddr & ~SEGMENT_MASK_1T ) & epnmask; - hash = vsid ^ (vsid <<25 ) ^ (epn >> epnshift); + hash = vsid ^ (vsid <<25 ) ^ (epn >> slb->sps->page_shift); }else {/* 256M segment */ vsid = (slb->vsid &SLB_VSID_VSID ) >>SLB_VSID_SHIFT ; epn = (eaddr & ~SEGMENT_MASK_256M ) & epnmask; - hash = vsid ^ (epn >> epnshift); + hash = vsid ^ (epn >> slb->sps->page_shift); } ptem = (slb->vsid &SLB_VSID_PTEM ) | ((epn >>16 ) &HPTE64_V_AVPN );@@ -465,17 +474,12 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu,return pte_offset; } -static hwaddr ppc_hash64_pte_raddr (ppc_slb_t *slb,ppc_hash_pte64_t pte, +static hwaddr ppc_hash64_pte_raddr (unsigned page_shift,ppc_hash_pte64_t pte,target_ulong eaddr) { -hwaddr mask; -int target_page_bits; +hwaddr mask = (1ULL << page_shift) -1 ;hwaddr rpn = pte.pte1 &HPTE64_R_RPN ; -/* -* We support 4K, 64K and 16M now
Quoted 8 lines
target-ppc/mmu-hash64.c static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu, · line 484
Quoted 6 lines
target-ppc/mmu-hash64.c +1
-3-*/ - target_page_bits =ppc_hash64_page_shift (slb); - mask = (1ULL << target_page_bits) -1 ; +return (rpn & ~mask) | (eaddr & mask); }Isn't this basically deposit64 by now?
True. I'll remove ppc_hash64_pte_raddr() entirely and use deposit64 instead.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 5/10 target-ppc: Use actual page size encodings from HPTE
In reply to David GibsonAt present the 64-bit hash MMU code uses information from the SLB to determine the page size of a translation. We do need that information to correctly look up the hash table. However the MMU also allows a possibly larger page size to be encoded into the HPTE itself, which is used to populate the TLB. At present qemu doesn't check that, and so doesn't support the MPSS "Multiple Page Size per Segment" feature.
This makes a start on allowing this, by adding an hpte_page_shift() function which looks up the page size of an HPTE. We use this to validate page sizes encodings on faults, and populate the qemu TLB with larger page sizes when appropriate.
--- target-ppc/mmu-hash64.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-)
target-ppc/mmu-hash64.c +70 -4
@@ -21,6 +21,7 @@#include "exec/helper-proto.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "qemu/error-report.h" #include "kvm_ppc.h" #include "mmu-hash64.h"
@@ -474,6 +475,43 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu,return pte_offset; } +static unsigned hpte_page_shift (const struct ppc_one_seg_page_size *sps, +uint64_t pte0,uint64_t pte1) +{ +int i; + +if (!(pte0 &HPTE64_V_LARGE )) { +if (sps->page_shift !=12 ) { +/* 4kiB page in a non 4kiB segment */ +return 0 ; + } +/* Normal 4kiB page */ +return 12 ; + } + +for (i =0 ; i <PPC_PAGE_SIZES_MAX_SZ ; i++) { +const struct ppc_one_page_size *ps = &sps->enc[i]; +uint64_t mask; + +if (!ps->page_shift) { +break ; + } + +if (ps->page_shift ==12 ) { +/* L bit is set so this can't be a 4kiB page */ +continue ; + } + + mask = ((1ULL << ps->page_shift) -1 ) &HPTE64_R_RPN ; + +if ((pte1 & mask) == ps->pte_enc) { +return ps->page_shift; + } + } + +return 0 ;/* Bad page size encoding */ +} +static hwaddr ppc_hash64_pte_raddr (unsigned page_shift,ppc_hash_pte64_t pte,target_ulong eaddr) {
@@ -489,6 +527,7 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr,CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env;ppc_slb_t *slb; +unsigned apshift;hwaddr pte_offset;ppc_hash_pte64_t pte;int pp_prot, amr_prot, prot;
@@ -552,6 +591,28 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr,qemu_log_mask (CPU_LOG_MMU ,"found PTE at offset %08" HWADDR_PRIx"\n" , pte_offset); +/* Validate page size encoding */ + apshift =hpte_page_shift (slb->sps, pte.pte0, pte.pte1); +if (!apshift) { +error_report ("Bad page size encoding in HPTE 0x%" PRIx64" - 0x%" PRIx64 +" @ 0x%" HWADDR_PRIx, pte.pte0, pte.pte1, pte_offset); +/* Treat it like a hash miss for the guest */ +if (rwx ==2 ) { + cs->exception_index =POWERPC_EXCP_ISI ; + env->error_code =0x40000000 ; + }else { + cs->exception_index =POWERPC_EXCP_DSI ; + env->error_code =0 ; + env->spr[SPR_DAR ] = eaddr; +if (rwx ==1 ) { + env->spr[SPR_DSISR ] =0x42000000 ; + }else { + env->spr[SPR_DSISR ] =0x40000000 ; + } + } +return 1 ; + } +/* 5. Check access permissions */ pp_prot =ppc_hash64_pte_prot (cpu, slb, pte);
@@ -604,10 +665,10 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr,/* 7. Determine the real address from the PTE */ - raddr =ppc_hash64_pte_raddr (slb->sps->page_shift, pte, eaddr); + raddr =ppc_hash64_pte_raddr (apshift, pte, eaddr);tlb_set_page (cs, eaddr &TARGET_PAGE_MASK , raddr &TARGET_PAGE_MASK , - prot, mmu_idx,TARGET_PAGE_SIZE ); + prot, mmu_idx,1ULL << apshift);return 0 ; }
@@ -618,6 +679,7 @@ hwaddr ppc_hash64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong addr)ppc_slb_t *slb;hwaddr pte_offset;ppc_hash_pte64_t pte; +unsigned apshift;if (msr_dr ==0 ) {/* In real mode the top 4 effective address bits are ignored */
@@ -634,8 +696,12 @@ hwaddr ppc_hash64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong addr)return -1 ; } -return ppc_hash64_pte_raddr (slb->sps->page_shift, pte, addr) - &TARGET_PAGE_MASK ; + apshift =hpte_page_shift (slb->sps, pte.pte0, pte.pte1); +if (!apshift) { +return -1 ; + } + +return ppc_hash64_pte_raddr (apshift, pte, addr) &TARGET_PAGE_MASK ; } void ppc_hash64_store_hpte(PowerPCCPU *cpu,
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 05/10] target-ppc: Use actual page size encodings from HPTE
Quoted 53 lines · David Gibson
At present the 64-bit hash MMU code uses information from the SLB to determine the page size of a translation. We do need that information to correctly look up the hash table. However the MMU also allows a possibly larger page size to be encoded into the HPTE itself, which is used to populate the TLB. At present qemu doesn't check that, and so doesn't support the MPSS "Multiple Page Size per Segment" feature.
This makes a start on allowing this, by adding an
hpte_page_shift()function which looks up the page size of an HPTE. We use this to validate page sizes encodings on faults, and populate the qemu TLB with larger page sizes when appropriate.Signed-off-by David Gibson <[email protected]>--- target-ppc/mmu-hash64.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-)target-ppc/mmu-hash64.c +21
-0@@ -21,6 +21,7 @@#include "exec/helper-proto.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "qemu/error-report.h" #include "kvm_ppc.h" #include "mmu-hash64.h" @@ -474,6 +475,43 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu,return pte_offset; } +static unsigned hpte_page_shift (const struct ppc_one_seg_page_size *sps, +uint64_t pte0,uint64_t pte1) +{ +int i; + +if (!(pte0 &HPTE64_V_LARGE )) { +if (sps->page_shift !=12 ) { +/* 4kiB page in a non 4kiB segment */ +return 0 ; + } +/* Normal 4kiB page */ +return 12 ; + } + +for (i =0 ; i <PPC_PAGE_SIZES_MAX_SZ ; i++) { +const struct ppc_one_page_size *ps = &sps->enc[i]; +uint64_t mask; + +if (!ps->page_shift) { +break ;
target-ppc/mmu-hash64.c static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu, · line 507
Quoted 10 lines
target-ppc/mmu-hash64.c +10
-0+ } + +if (ps->page_shift ==12 ) { +/* L bit is set so this can't be a 4kiB page */ +continue ; + } + + mask = ((1ULL << ps->page_shift) -1 ) &HPTE64_R_RPN ; + +if ((pte1 & mask) == ps->pte_enc) {
Gah. This needs to be (ps->pte_enc << HPTE64_R_RPN_SHIFT) or everything breaks.
I remember fixing this earlier, but somehow I managed to lose the fix in both this posting and the previous one.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH 05/10] target-ppc: Use actual page size encodings from HPTE
In reply to David GibsonQuoted 92 lines · David Gibson
At present the 64-bit hash MMU code uses information from the SLB to determine the page size of a translation. We do need that information to correctly look up the hash table. However the MMU also allows a possibly larger page size to be encoded into the HPTE itself, which is used to populate the TLB. At present qemu doesn't check that, and so doesn't support the MPSS "Multiple Page Size per Segment" feature.
This makes a start on allowing this, by adding an
hpte_page_shift()function which looks up the page size of an HPTE. We use this to validate page sizes encodings on faults, and populate the qemu TLB with larger page sizes when appropriate.Signed-off-by David Gibson <[email protected]>--- target-ppc/mmu-hash64.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-)target-ppc/mmu-hash64.c +46
-0@@ -21,6 +21,7 @@#include "exec/helper-proto.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "qemu/error-report.h" #include "kvm_ppc.h" #include "mmu-hash64.h" @@ -474,6 +475,43 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu,return pte_offset; } +static unsigned hpte_page_shift (const struct ppc_one_seg_page_size *sps, +uint64_t pte0,uint64_t pte1) +{ +int i; + +if (!(pte0 &HPTE64_V_LARGE )) { +if (sps->page_shift !=12 ) { +/* 4kiB page in a non 4kiB segment */ +return 0 ; + } +/* Normal 4kiB page */ +return 12 ; + } + +for (i =0 ; i <PPC_PAGE_SIZES_MAX_SZ ; i++) { +const struct ppc_one_page_size *ps = &sps->enc[i]; +uint64_t mask; + +if (!ps->page_shift) { +break ; + } + +if (ps->page_shift ==12 ) { +/* L bit is set so this can't be a 4kiB page */ +continue ; + } + + mask = ((1ULL << ps->page_shift) -1 ) &HPTE64_R_RPN ; + +if ((pte1 & mask) == ps->pte_enc) { +return ps->page_shift; + } + } + +return 0 ;/* Bad page size encoding */ +} +static hwaddr ppc_hash64_pte_raddr (unsigned page_shift,ppc_hash_pte64_t pte,target_ulong eaddr) {@@ -489,6 +527,7 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr,CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env;ppc_slb_t *slb; +unsigned apshift;hwaddr pte_offset;ppc_hash_pte64_t pte;int pp_prot, amr_prot, prot;@@ -552,6 +591,28 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr,qemu_log_mask (CPU_LOG_MMU ,"found PTE at offset %08" HWADDR_PRIx"\n" , pte_offset); +/* Validate page size encoding */ + apshift =hpte_page_shift (slb->sps, pte.pte0, pte.pte1); +if (!apshift) { +error_report ("Bad page size encoding in HPTE 0x%" PRIx64" - 0x%" PRIx64 +" @ 0x%" HWADDR_PRIx, pte.pte0, pte.pte1, pte_offset); +/* Treat it like a hash miss for the guest */ +if (rwx ==2 ) {
target-ppc/mmu-hash64.c int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr, · line 610
Quoted 10 lines
target-ppc/mmu-hash64.c +10
-0+ cs->exception_index =POWERPC_EXCP_ISI ; + env->error_code =0x40000000 ; + }else { + cs->exception_index =POWERPC_EXCP_DSI ; + env->error_code =0 ; + env->spr[SPR_DAR ] = eaddr; +if (rwx ==1 ) { + env->spr[SPR_DSISR ] =0x42000000 ; + }else { + env->spr[SPR_DSISR ] =0x40000000 ;
I know that we don't do this for any other DSISR setting yet, but do you think we could mark the start here and use names for the bits instead? The kernel has a few nice defines.
Alex
Re: [Qemu-devel] [PATCH 05/10] target-ppc: Use actual page size encodings from HPTE
Quoted 98 lines · Alexander Graf
Quoted 95 lines · David Gibson
At present the 64-bit hash MMU code uses information from the SLB to determine the page size of a translation. We do need that information to correctly look up the hash table. However the MMU also allows a possibly larger page size to be encoded into the HPTE itself, which is used to populate the TLB. At present qemu doesn't check that, and so doesn't support the MPSS "Multiple Page Size per Segment" feature.
This makes a start on allowing this, by adding an
hpte_page_shift()function which looks up the page size of an HPTE. We use this to validate page sizes encodings on faults, and populate the qemu TLB with larger page sizes when appropriate.Signed-off-by David Gibson <[email protected]>--- target-ppc/mmu-hash64.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-)target-ppc/mmu-hash64.c +52
-0@@ -21,6 +21,7 @@#include "exec/helper-proto.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "qemu/error-report.h" #include "kvm_ppc.h" #include "mmu-hash64.h" @@ -474,6 +475,43 @@ static hwaddr ppc_hash64_htab_lookup(PowerPCCPU *cpu,return pte_offset; } +static unsigned hpte_page_shift (const struct ppc_one_seg_page_size *sps, +uint64_t pte0,uint64_t pte1) +{ +int i; + +if (!(pte0 &HPTE64_V_LARGE )) { +if (sps->page_shift !=12 ) { +/* 4kiB page in a non 4kiB segment */ +return 0 ; + } +/* Normal 4kiB page */ +return 12 ; + } + +for (i =0 ; i <PPC_PAGE_SIZES_MAX_SZ ; i++) { +const struct ppc_one_page_size *ps = &sps->enc[i]; +uint64_t mask; + +if (!ps->page_shift) { +break ; + } + +if (ps->page_shift ==12 ) { +/* L bit is set so this can't be a 4kiB page */ +continue ; + } + + mask = ((1ULL << ps->page_shift) -1 ) &HPTE64_R_RPN ; + +if ((pte1 & mask) == ps->pte_enc) { +return ps->page_shift; + } + } + +return 0 ;/* Bad page size encoding */ +} +static hwaddr ppc_hash64_pte_raddr (unsigned page_shift,ppc_hash_pte64_t pte,target_ulong eaddr) {@@ -489,6 +527,7 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr,CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env;ppc_slb_t *slb; +unsigned apshift;hwaddr pte_offset;ppc_hash_pte64_t pte;int pp_prot, amr_prot, prot;@@ -552,6 +591,28 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr,qemu_log_mask (CPU_LOG_MMU ,"found PTE at offset %08" HWADDR_PRIx"\n" , pte_offset); +/* Validate page size encoding */ + apshift =hpte_page_shift (slb->sps, pte.pte0, pte.pte1); +if (!apshift) { +error_report ("Bad page size encoding in HPTE 0x%" PRIx64" - 0x%" PRIx64 +" @ 0x%" HWADDR_PRIx, pte.pte0, pte.pte1, pte_offset); +/* Treat it like a hash miss for the guest */ +if (rwx ==2 ) { + cs->exception_index =POWERPC_EXCP_ISI ; + env->error_code =0x40000000 ; + }else { + cs->exception_index =POWERPC_EXCP_DSI ; + env->error_code =0 ; + env->spr[SPR_DAR ] = eaddr;
Quoted 8 lines
target-ppc/mmu-hash64.c int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong eaddr, · line 610
Quoted 4 lines
target-ppc/mmu-hash64.c +4
-0+if (rwx ==1 ) { + env->spr[SPR_DSISR ] =0x42000000 ; + }else { + env->spr[SPR_DSISR ] =0x40000000 ;I know that we don't do this for any other DSISR setting yet, but do you think we could mark the start here and use names for the bits instead? The kernel has a few nice defines.
So, that would be a bit odd, since it's just a copy of the exception code from below.
But in fact, BenH pointed out that throwing a machine check is probably more correct behaviour than a DSI or ISI, so this will go away anyway.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH 6/10 target-ppc: Remove unused mmu models from ppc_tlb_invalidate_one
In reply to David Gibsonppc_tlb_invalidate_one() has a big switch handling many different MMU types. However, most of those branches can never be reached:
It is called from 3 places: from remove_hpte() and h_protect() in spapr_hcall.c (which always has a 64-bit hash MMU type), and from helper_tlbie() in mmu_helper.c.
Calls to helper_tlbie() are generated from gen_tlbiel, gen_tlbiel and gen_tlbiva. The first two are only used with the PPC_MEM_TLBIE flag, set only with 32-bit or 64-bit hash MMU models, and gen_tlbiva() is used only on 440 and 460 models with the BookE mmu model.
These means the exhaustive list of MMU types which may call ppc_tlb_invalidate_one() is: POWERPC_MMU_SOFT_6xx, POWERPC_MMU_601, POWERPC_MMU_32B, POWERPC_MMU_SOFT_74xx, POWERPC_MMU_64B, POWERPC_MMU_2_03, POWERPC_MMU_2_06, POWERPC_MMU_2_07 and POWERPC_MMU_BOOKE.
Clean up by removing logic for all other MMU types from ppc_tlb_invalidate_one().
--- target-ppc/mmu_helper.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-)
target-ppc/mmu_helper.c +2 -18
@@ -1971,25 +1971,10 @@ void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)ppc6xx_tlb_invalidate_virt (env, addr,1 ); }break ; -case POWERPC_MMU_SOFT_4xx: -case POWERPC_MMU_SOFT_4xx_Z: -ppc4xx_tlb_invalidate_virt (env, addr, env->spr[SPR_40x_PID]); -break ; -case POWERPC_MMU_REAL : -cpu_abort (CPU (cpu),"No TLB for PowerPC 4xx in real mode\n" ); -break ; -case POWERPC_MMU_MPC8xx: -/* XXX: TODO */ -cpu_abort (CPU (cpu),"MPC8xx MMU model is not implemented\n" ); -break ;case POWERPC_MMU_BOOKE :/* XXX: TODO */ cpu_abort (CPU (cpu),"BookE MMU model is not implemented\n" );break ; -case POWERPC_MMU_BOOKE206 : -/* XXX: TODO */ -cpu_abort (CPU (cpu),"BookE 2.06 MMU model is not implemented\n" ); -break ;case POWERPC_MMU_32B :case POWERPC_MMU_601 :/* tlbie invalidate TLBs for all segments */
@@ -2031,9 +2016,8 @@ void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)break ;#endif /* defined(TARGET_PPC64) */ default : -/* XXX: TODO */ -cpu_abort (CPU (cpu),"Unknown MMU model\n" ); -break ; +/* Should never reach here with other MMU models */ +assert (0 ); }#else ppc_tlb_invalidate_all (env);
Signature · 1 line
2.5.0
PATCH 7/10 target-ppc: Split 44x tlbiva from ppc_tlb_invalidate_one()
In reply to David GibsonCurrently both the tlbiva instruction (used on 44x chips) and the tlbie instruction (used on hash MMU chips) are both handled via ppc_tlb_invalidate_one(). This is silly, because they're invoked from different places, and do different things.
Clean this up by separating out the tlbiva instruction into its own handling. In fact the implementation is only a stub anyway.
--- target-ppc/helper.h | 1 + target-ppc/mmu_helper.c | 14 ++++++++++---- target-ppc/translate.c | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-)
target-ppc/helper.h +1 -0
@@ -544,6 +544,7 @@ DEF_HELPER_2(74xx_tlbd, void, env, tl) DEF_HELPER_2(74xx_tlbi, void, env, tl) DEF_HELPER_FLAGS_1(tlbia, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_2(tlbie, TCG_CALL_NO_RWG, void, env, tl) +DEF_HELPER_FLAGS_2(tlbiva, TCG_CALL_NO_RWG, void, env, tl)#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_3(store_slb, TCG_CALL_NO_RWG, void, env, tl, tl)DEF_HELPER_2 (load_slb_esid, tl, env, tl)
target-ppc/mmu_helper.c +10 -4
@@ -1971,10 +1971,6 @@ void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)ppc6xx_tlb_invalidate_virt (env, addr,1 ); }break ; -case POWERPC_MMU_BOOKE : -/* XXX: TODO */ -cpu_abort (CPU (cpu),"BookE MMU model is not implemented\n" ); -break ;case POWERPC_MMU_32B :case POWERPC_MMU_601 :/* tlbie invalidate TLBs for all segments */
@@ -2116,6 +2112,16 @@ void helper_tlbie(CPUPPCState *env, target_ulong addr)ppc_tlb_invalidate_one (env, addr); } +void helper_tlbiva (CPUPPCState *env,target_ulong addr) +{ +PowerPCCPU *cpu =ppc_env_get_cpu (env); + +/* tlbiva instruciton only exists on BookE */ +assert (env->mmu_model ==POWERPC_MMU_BOOKE ); +/* XXX: TODO */ +cpu_abort (CPU (cpu),"BookE MMU model is not implemented\n" ); +} +/* Software driven TLBs management */ /* PowerPC 602/603 software TLB load instructions helpers */ static void do_6xx_tlb (CPUPPCState *env,target_ulong new_EPN,int is_code)
target-ppc/translate.c +1 -1
@@ -5904,7 +5904,7 @@ static void gen_tlbiva(DisasContext *ctx) } t0 =tcg_temp_new ();gen_addr_reg_index (ctx, t0); -gen_helper_tlbie (cpu_env, cpu_gpr[rB (ctx->opcode)]); +gen_helper_tlbiva (cpu_env, cpu_gpr[rB (ctx->opcode)]);tcg_temp_free (t0);#endif }
Signature · 1 line
2.5.0
PATCH 8/10 target-ppc: Add new TLB invalidate by HPTE call for hash64 MMUs
In reply to David GibsonWhen HPTEs are removed or modified by hypercalls on spapr, we need to invalidate the relevant pages in the qemu TLB.
Currently we do that by doing some complicated calculations to work out the right encoding for the tlbie instruction, then passing that to ppc_tlb_invalidate_one()... which totally ignores the argument and flushes the whole tlb.
Avoid that by adding a new flush-by-hpte helper in mmu-hash64.c.
--- hw/ppc/spapr_hcall.c | 46 ++++------------------------------------------ target-ppc/mmu-hash64.c | 12 ++++++++++++ target-ppc/mmu-hash64.h | 3 +++ 3 files changed, 19 insertions(+), 42 deletions(-)
hw/ppc/spapr_hcall.c +4 -42
@@ -37,42 +37,6 @@ static void set_spr(CPUState *cs, int spr, target_ulong value,run_on_cpu (cs, do_spr_sync, &s); } -static target_ulong compute_tlbie_rb (target_ulong v,target_ulong r, -target_ulong pte_index) -{ -target_ulong rb, va_low; - - rb = (v & ~0x7fULL ) <<16 ;/* AVA field */ - va_low = pte_index >>3 ; -if (v &HPTE64_V_SECONDARY ) { - va_low = ~va_low; - } -/* xor vsid from AVA */ -if (!(v &HPTE64_V_1TB_SEG )) { - va_low ^= v >>12 ; - }else { - va_low ^= v >>24 ; - } - va_low &=0x7ff ; -if (v &HPTE64_V_LARGE ) { - rb |=1 ;/* L field */ -#if 0 /* Disable that P7 specific bit for now */ -if (r &0xff000 ) { -/* non-16MB large page, must be 64k */ -/* (masks depend on page size) */ - rb |=0x1000 ;/* page encoding in LP field */ - rb |= (va_low &0x7f ) <<16 ;/* 7b of VA in AVA/LP field */ - rb |= (va_low &0xfe );/* AVAL field */ - } -#endif - }else { -/* 4kB page */ - rb |= (va_low &0x7ff ) <<12 ;/* remaining 11b of AVA */ - } - rb |= (v >>54 ) &0x300 ;/* B field */ -return rb; -} -static inline bool valid_pte_index (CPUPPCState *env,target_ulong pte_index) {/*
@@ -198,7 +162,7 @@ static RemoveResult remove_hpte(PowerPCCPU *cpu, target_ulong ptex, {CPUPPCState *env = &cpu->env;uint64_t token; -target_ulong v, r, rb; +target_ulong v, r;if (!valid_pte_index (env, ptex)) {return REMOVE_PARM ;
@@ -217,8 +181,7 @@ static RemoveResult remove_hpte(PowerPCCPU *cpu, target_ulong ptex, *vp = v; *rp = r;ppc_hash64_store_hpte (cpu, ptex,HPTE64_V_HPTE_DIRTY ,0 ); - rb =compute_tlbie_rb (v, r, ptex); -ppc_tlb_invalidate_one (env, rb); +ppc_hash64_tlb_flush_hpte (cpu, ptex, v, r);return REMOVE_SUCCESS ; }
@@ -322,7 +285,7 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPRMachineState *spapr,target_ulong pte_index = args[1 ];target_ulong avpn = args[2 ];uint64_t token; -target_ulong v, r, rb; +target_ulong v, r;if (!valid_pte_index (env, pte_index)) {return H_PARAMETER ;
@@ -343,10 +306,9 @@ static target_ulong h_protect(PowerPCCPU *cpu, sPAPRMachineState *spapr, r |= (flags <<55 ) &HPTE64_R_PP0 ; r |= (flags <<48 ) &HPTE64_R_KEY_HI ; r |= flags & (HPTE64_R_PP |HPTE64_R_N |HPTE64_R_KEY_LO ); - rb =compute_tlbie_rb (v, r, pte_index);ppc_hash64_store_hpte (cpu, pte_index, (v & ~HPTE64_V_VALID ) |HPTE64_V_HPTE_DIRTY ,0 ); -ppc_tlb_invalidate_one (env, rb); +ppc_hash64_tlb_flush_hpte (cpu, pte_index, v, r);/* Don't need a memory barrier, due to qemu's global lock */ ppc_hash64_store_hpte (cpu, pte_index, v |HPTE64_V_HPTE_DIRTY , r);return H_SUCCESS ;
target-ppc/mmu-hash64.c +12 -0
@@ -725,3 +725,15 @@ void ppc_hash64_store_hpte(PowerPCCPU *cpu, env->htab_base + pte_index + HASH_PTE_SIZE_64 / 2, pte1); } } + +void ppc_hash64_tlb_flush_hpte (PowerPCCPU *cpu, +target_ulong pte_index, +target_ulong pte0,target_ulong pte1) +{ +/* +* XXX: given the fact that there are too many segments to +* invalidate, and we still don't have a tlb_flush_mask(env, n, +* mask) in QEMU, we just invalidate all TLBs +*/ +tlb_flush (CPU (cpu),1 ); +}
target-ppc/mmu-hash64.h +3 -0
@@ -13,6 +13,9 @@ int ppc_hash64_handle_mmu_fault(PowerPCCPU *cpu, target_ulong address, int rw, int mmu_idx);void ppc_hash64_store_hpte (PowerPCCPU *cpu,target_ulong index,target_ulong pte0,target_ulong pte1); +void ppc_hash64_tlb_flush_hpte (PowerPCCPU *cpu, +target_ulong pte_index, +target_ulong pte0,target_ulong pte1);#endif /*
Signature · 1 line
2.5.0
PATCH 9/10 target-ppc: Helper to determine page size information from hpte alone
In reply to David Gibsonh_enter() in the spapr code needs to know the page size of the HPTE it's about to insert. Unlike other paths that do this, it doesn't have access to the SLB, so at the moment it determines this with some open-coded tests which assume POWER7 or POWER8 page size encodings.
To make this more flexible add ppc_hash64_hpte_page_shift_noslb() to determine both the "base" page size per segment, and the individual effective page size from an HPTE alone.
This means that the spapr code should now be able to handle any page size listed in the env->sps table.
--- hw/ppc/spapr_hcall.c | 25 ++++++------------------- target-ppc/mmu-hash64.c | 35 +++++++++++++++++++++++++++++++++++ target-ppc/mmu-hash64.h | 3 +++ 3 files changed, 44 insertions(+), 19 deletions(-)
hw/ppc/spapr_hcall.c +6 -19
@@ -72,31 +72,18 @@ static target_ulong h_enter(PowerPCCPU *cpu, sPAPRMachineState *spapr,target_ulong pte_index = args[1 ];target_ulong pteh = args[2 ];target_ulong ptel = args[3 ]; -target_ulong page_shift =12 ; +unsigned apshift, spshift;target_ulong raddr;target_ulong index;uint64_t token; -/* only handle 4k and 16M pages for now */ -if (pteh &HPTE64_V_LARGE ) { -#if 0 /* We don't support 64k pages yet */ -if ((ptel &0xf000 ) ==0x1000 ) { -/* 64k page */ - } else -#endif -if ((ptel &0xff000 ) ==0 ) { -/* 16M page */ - page_shift =24 ; -/* lowest AVA bit must be 0 for 16M pages */ -if (pteh &0x80 ) { -return H_PARAMETER ; - } - }else { -return H_PARAMETER ; - } + apshift =ppc_hash64_hpte_page_shift_noslb (cpu, pteh, ptel, &spshift); +if (!apshift) { +/* Bad page size encoding */ +return H_PARAMETER ; } - raddr = (ptel &HPTE64_R_RPN ) & ~((1ULL << page_shift) -1 ); + raddr = (ptel &HPTE64_R_RPN ) & ~((1ULL << apshift) -1 );if (is_ram_address (spapr, raddr)) {/* Regular RAM - should have WIMG=0010 */
target-ppc/mmu-hash64.c +35 -0
@@ -512,6 +512,41 @@ static unsigned hpte_page_shift(const struct ppc_one_seg_page_size *sps,return 0 ;/* Bad page size encoding */ } +unsigned ppc_hash64_hpte_page_shift_noslb (PowerPCCPU *cpu, +uint64_t pte0,uint64_t pte1, +unsigned *seg_page_shift) +{ +CPUPPCState *env = &cpu->env; +int i; + +if (!(pte0 &HPTE64_V_LARGE )) { + *seg_page_shift =12 ; +return 12 ; + } + +/* +* The encodings in env->sps need to be carefully chosen so that +* this gives an unambiguous result. +*/ +for (i =0 ; i <PPC_PAGE_SIZES_MAX_SZ ; i++) { +const struct ppc_one_seg_page_size *sps = &env->sps.sps[i]; +unsigned shift; + +if (!sps->page_shift) { +break ; + } + + shift =hpte_page_shift (sps, pte0, pte1); +if (shift) { + *seg_page_shift = sps->page_shift; +return shift; + } + } + + *seg_page_shift =0 ; +return 0 ; +} +static hwaddr ppc_hash64_pte_raddr (unsigned page_shift,ppc_hash_pte64_t pte,target_ulong eaddr) {
target-ppc/mmu-hash64.h +3 -0
@@ -16,6 +16,9 @@ void ppc_hash64_store_hpte(PowerPCCPU *cpu, target_ulong index,void ppc_hash64_tlb_flush_hpte (PowerPCCPU *cpu,target_ulong pte_index,target_ulong pte0,target_ulong pte1); +unsigned ppc_hash64_hpte_page_shift_noslb (PowerPCCPU *cpu, +uint64_t pte0,uint64_t pte1, +unsigned *seg_page_shift);#endif /*
Signature · 1 line
2.5.0
PATCH 10/10 target-ppc: Allow more page sizes for POWER7 & POWER8 in TCG
In reply to David GibsonNow that the TCG and spapr code has been extended to allow (semi-) arbitrary page encodings in the CPU's 'sps' table, we can add the many page sizes supported by real POWER7 and POWER8 hardware that we previously didn't support in TCG.
--- target-ppc/mmu-hash64.h | 2 ++ target-ppc/translate_init.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
target-ppc/mmu-hash64.h +2 -0
@@ -48,6 +48,8 @@ unsigned ppc_hash64_hpte_page_shift_noslb(PowerPCCPU *cpu,#define SLB_VSID_LLP_MASK (SLB_VSID_L | SLB_VSID_LP)#define SLB_VSID_4K 0x0000000000000000ULL#define SLB_VSID_64K 0x0000000000000110ULL +#define SLB_VSID_16M 0x0000000000000100ULL +#define SLB_VSID_16G 0x0000000000000120ULL/* * Hash page table definitions
target-ppc/translate_init.c +32 -0
@@ -8104,6 +8104,36 @@ static Property powerpc_servercpu_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +#ifdef CONFIG_SOFTMMU +static const struct ppc_segment_page_sizes POWER7_POWER8_sps = { + .sps = { + { + .page_shift =12 ,/* 4K */ + .slb_enc =0 , + .enc = { { .page_shift =12 , .pte_enc =0 }, + { .page_shift =16 , .pte_enc =0x7 }, + { .page_shift =24 , .pte_enc =0x38 }, }, + }, + { + .page_shift =16 ,/* 64K */ + .slb_enc =SLB_VSID_64K , + .enc = { { .page_shift =16 , .pte_enc =0x1 }, + { .page_shift =24 , .pte_enc =0x8 }, }, + }, + { + .page_shift =24 ,/* 16M */ + .slb_enc =SLB_VSID_16M , + .enc = { { .page_shift =24 , .pte_enc =0 }, }, + }, + { + .page_shift =34 ,/* 16G */ + .slb_enc =SLB_VSID_16G , + .enc = { { .page_shift =34 , .pte_enc =0x3 }, }, + }, + } +}; +#endif /* CONFIG_SOFTMMU */ +static void init_proc_POWER7 (CPUPPCState *env) {init_proc_book3s_64 (env,BOOK3S_CPU_POWER7 );
@@ -8167,6 +8197,7 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data) pcc->mmu_model =POWERPC_MMU_2_06 ;#if defined(CONFIG_SOFTMMU ) pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault; + pcc->sps = &POWER7_POWER8_sps;#endif pcc->excp_model =POWERPC_EXCP_POWER7 ; pcc->bus_model =PPC_FLAGS_INPUT_POWER7 ;
@@ -8247,6 +8278,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data) pcc->mmu_model =POWERPC_MMU_2_07 ;#if defined(CONFIG_SOFTMMU ) pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault; + pcc->sps = &POWER7_POWER8_sps;#endif pcc->excp_model =POWERPC_EXCP_POWER7 ; pcc->bus_model =PPC_FLAGS_INPUT_POWER7 ;
Signature · 1 line
2.5.0
Quoted 15 lines · David Gibson
Encoding of page sizes on 64-bit hash MMUs for Power is rather arcane, involving control bits in both the SLB and HPTE. At present we support a few of the options, but far fewer than real hardware.
We're able to get away with that in practice, because guests use a device tree property to determine which page sizes are available and we are setting that to match. However, the fact that the actual code doesn't necessarily what we put into the table of available page sizes is another ugliness.
This series makes a number of cleanups to the page size handling. The upshot is that afterwards the softmmu code operates off the same page size encoding table that is advertised to the guests, ensuring that they will be in sync.
Quoted 5 lines
Finally, we extend the table of allowed sizes for POWER7 and POWER8 to include the options allowed in hardware (including MPSS). We can fix other hash MMU based CPUs in future if anyone cares enough.
Please review, and I'll fold into ppc-for-2.6 for my next pull.
Bother, somehow missed a serious bug in here that's causing oops-on-boot. Sorry, still tracking it down.
Quoted 33 lines
Changes since RFC:
* Moved lookup of SLB encodings table from SLB lookup time to SLB store timeDavid Gibson (10):
target-ppc: Remove unusedkvmppc_read_segment_page_sizes()stub
target-ppc: Convert mmu-hash{32,64}.[ch] from CPUPPCState to
PowerPCCPU
target-ppc: Reworkppc_store_slb
target-ppc: Rework SLB page size lookup
target-ppc: Use actual page size encodings from HPTE
target-ppc: Remove unused mmu models fromppc_tlb_invalidate_one
target-ppc: Split 44x tlbiva fromppc_tlb_invalidate_one()
target-ppc: Add new TLB invalidate by HPTE call for hash64 MMUs
target-ppc: Helper to determine page size information from hpte alone
target-ppc: Allow more page sizes for POWER7 & POWER8 in TCGhw/ppc/spapr_hcall.c | 102 ++++------------ target-ppc/cpu.h | 1 + target-ppc/helper.h | 1 + target-ppc/kvm.c | 2 +- target-ppc/kvm_ppc.h | 5 - target-ppc/machine.c | 20 ++++ target-ppc/mmu-hash32.c | 68 ++++++----- target-ppc/mmu-hash32.h | 30 ++--- target-ppc/mmu-hash64.c | 286 ++++++++++++++++++++++++++++++++------------ target-ppc/mmu-hash64.h | 30 +++-- target-ppc/mmu_helper.c | 59 ++++----- target-ppc/translate.c | 2 +- target-ppc/translate_init.c | 32 +++++ 13 files changed, 389 insertions(+), 249 deletions(-)
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Alexander Graf
Reviewed-byQuoted 16 lines · David Gibson
Quoted 15 lines · David Gibson
Encoding of page sizes on 64-bit hash MMUs for Power is rather arcane, involving control bits in both the SLB and HPTE. At present we support a few of the options, but far fewer than real hardware.
We're able to get away with that in practice, because guests use a device tree property to determine which page sizes are available and we are setting that to match. However, the fact that the actual code doesn't necessarily what we put into the table of available page sizes is another ugliness.
This series makes a number of cleanups to the page size handling. The upshot is that afterwards the softmmu code operates off the same page size encoding table that is advertised to the guests, ensuring that they will be in sync.
Quoted 7 lines
Quoted 5 lines
Finally, we extend the table of allowed sizes for POWER7 and POWER8 to include the options allowed in hardware (including MPSS). We can fix other hash MMU based CPUs in future if anyone cares enough.
Please review, and I'll fold into ppc-for-2.6 for my next pull.
Bother, somehow missed a serious bug in here that's causing oops-on-boot. Sorry, still tracking it down.
I still have no idea where your bug is (bisect probably should get you there pretty quick), but the overall concept sounds very reasonable to me. Please benchmark performance before and after in the next cover letter also :)
Alex
Quoted 23 lines · Alexander Graf
Quoted 20 lines · David Gibson
Quoted 19 lines · David Gibson
Encoding of page sizes on 64-bit hash MMUs for Power is rather arcane, involving control bits in both the SLB and HPTE. At present we support a few of the options, but far fewer than real hardware.
We're able to get away with that in practice, because guests use a device tree property to determine which page sizes are available and we are setting that to match. However, the fact that the actual code doesn't necessarily what we put into the table of available page sizes is another ugliness.
This series makes a number of cleanups to the page size handling. The upshot is that afterwards the softmmu code operates off the same page size encoding table that is advertised to the guests, ensuring that they will be in sync.
Finally, we extend the table of allowed sizes for POWER7 and POWER8 to include the options allowed in hardware (including MPSS). We can fix other hash MMU based CPUs in future if anyone cares enough.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Please review, and I'll fold into ppc-for-2.6 for my next pull.
Bother, somehow missed a serious bug in here that's causing oops-on-boot. Sorry, still tracking it down.
I still have no idea where your bug is (bisect probably should get you there pretty quick),
Alas, no, because the bug only triggers once all the page sizes are added for POWER8 in the last patch.
Luckily I found it anyway (see earlier reply).
Quoted 3 lines
but the overall concept sounds very reasonable to me. Please benchmark performance before and after in the next cover letter also :)
Hrm.. as always the question is what benchmark?
Quoted 5 lines
Reviewed-by Alexander Graf <[email protected]>Alex
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 38 lines
Am 26.01.2016 um 06:41 schrieb David Gibson <[email protected]>:
Quoted 24 lines · Alexander Graf
Quoted 23 lines · David Gibson
Quoted 20 lines · David Gibson
Encoding of page sizes on 64-bit hash MMUs for Power is rather arcane, involving control bits in both the SLB and HPTE. At present we support a few of the options, but far fewer than real hardware.
We're able to get away with that in practice, because guests use a device tree property to determine which page sizes are available and we are setting that to match. However, the fact that the actual code doesn't necessarily what we put into the table of available page sizes is another ugliness.
This series makes a number of cleanups to the page size handling. The upshot is that afterwards the softmmu code operates off the same page size encoding table that is advertised to the guests, ensuring that they will be in sync.
Finally, we extend the table of allowed sizes for POWER7 and POWER8 to include the options allowed in hardware (including MPSS). We can fix other hash MMU based CPUs in future if anyone cares enough.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Please review, and I'll fold into ppc-for-2.6 for my next pull.
Bother, somehow missed a serious bug in here that's causing oops-on-boot. Sorry, still tracking it down.
I still have no idea where your bug is (bisect probably should get you there pretty quick),
Alas, no, because the bug only triggers once all the page sizes are added for POWER8 in the last patch.
Quoted 7 lines
Luckily I found it anyway (see earlier reply).
Quoted 3 lines
but the overall concept sounds very reasonable to me. Please benchmark performance before and after in the next cover letter also :)
Hrm.. as always the question is what benchmark?
For this "time" on a simple kernel boot+automatic shutdown sequence should be enough.
Alex
Quoted 11 lines
Quoted 5 lines
Reviewed-by Alexander Graf <[email protected]>Alex
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson