ppc64: Rudimentary Support for extra page sizes on server CPUs
PATCH 1/2 ppc64: Rudimentary Support for extra page sizes on server CPUs
More recent Power server chips (i.e. based on the 64 bit hash MMU) support more than just the traditional 4k and 16M page sizes. This can get quite complicated, because which page sizes are supported, which combinations are supported within an MMU segment and how these page sizes are encoded both in the SLB entry and the hash PTE can vary depending on the CPU model (they are not specified by the architecture). In addition the firmware or hypervisor may not permit use of certain page sizes, for various reasons. Whether various page sizes are supported on KVM, for example, depends on whether the PR or HV variant of KVM is in use, and on the page size of the memory backing the guest's RAM.
This patch adds information to the CPUState and cpu defs to describe the supported page sizes and encodings. Since TCG does not yet support any extended page sizes, we just set this to NULL in the static CPU definitions, expanding this to the default 4k and 16M page sizes when we initialize the cpu state. When using KVM, however, we instead determine available page sizes using the new KVM_PPC_GET_SMMU_INFO call. For old kernels without that call, we use some defaults, with some guesswork which should do the right thing for existing HV and PR implementations. The fallback might not be correct for future versions, but that's ok, because they'll have KVM_PPC_GET_SMMU_INFO.
---
This is long overdue and addresses your latest comments. The kernel headers update is gone as qemu already have the right definitions.
target-ppc/cpu.h | 31 +++++++ target-ppc/helper.c | 7 ++ target-ppc/kvm.c | 208 +++++++++++++++++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 5 + target-ppc/translate_init.c | 21 +++++ 5 files changed, 272 insertions(+), 0 deletions(-)
target-ppc/cpu.h +31 -0
@@ -119,6 +119,8 @@ enum powerpc_mmu_t {POWERPC_MMU_620 =POWERPC_MMU_64 |0x00000002 ,/* Architecture 2.06 variant */ POWERPC_MMU_2_06 =POWERPC_MMU_64 |POWERPC_MMU_1TSEG |0x00000003 , +/* Architecture 2.06 "degraded" (no 1T segments) */ + POWERPC_MMU_2_06d = POWERPC_MMU_64 | 0x00000003, #endif /* defined(TARGET_PPC64) */ };
@@ -874,6 +876,29 @@ enum {#define DBELL_PIRTAG_MASK 0x3fff/*****************************************************************************/ +/* Segment page size information, used by recent hash MMUs +* The format of this structure mirrors kvm_ppc_smmu_info +*/ + +#define PPC_PAGE_SIZES_MAX_SZ 8 + +struct ppc_one_page_size { +uint32_t page_shift;/* Page shift (or 0) */ +uint32_t pte_enc;/* Encoding in the HPTE (>>12) */ +}; + +struct ppc_one_seg_page_size { +uint32_t page_shift;/* Base page shift of segment (or 0) */ +uint32_t slb_enc;/* SLB encoding for BookS */ +struct ppc_one_page_size enc[PPC_PAGE_SIZES_MAX_SZ ]; +}; + +struct ppc_segment_page_sizes { +struct ppc_one_seg_page_size sps[PPC_PAGE_SIZES_MAX_SZ ]; +}; + + +/*****************************************************************************/ /* The whole PowerPC CPU context */ #define NB_MMU_MODES 3
@@ -889,6 +914,9 @@ struct ppc_def_t {powerpc_input_t bus_model;uint32_t flags;int bfd_mach; +#if defined(TARGET_PPC64 ) +const struct ppc_segment_page_sizes *sps; +#endif void (*init_proc)(CPUPPCState *env);int (*check_pow)(CPUPPCState *env); };
@@ -1012,6 +1040,9 @@ struct CPUPPCState {uint32_t flags;uint64_t insns_flags;uint64_t insns_flags2; +#if defined(TARGET_PPC64 ) +struct ppc_segment_page_sizes sps; +#endif #if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY )target_phys_addr_t vpa;
target-ppc/helper.c +7 -0
@@ -1617,6 +1617,7 @@ void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env)#if defined(TARGET_PPC64 )case POWERPC_MMU_64B :case POWERPC_MMU_2_06 : +case POWERPC_MMU_2_06d:mmubooks_dump_mmu (f, cpu_fprintf, env);break ;#endif
@@ -1647,6 +1648,7 @@ static inline int check_physical(CPUPPCState *env, mmu_ctx_t *ctx,case POWERPC_MMU_620 :case POWERPC_MMU_64B :case POWERPC_MMU_2_06 : +case POWERPC_MMU_2_06d:/* Real address are 60 bits long */ ctx->raddr &=0x0FFFFFFFFFFFFFFFULL ; ctx->prot |=PAGE_WRITE ;
@@ -1727,6 +1729,7 @@ int get_physical_address (CPUPPCState *env, mmu_ctx_t *ctx, target_ulong eaddr,case POWERPC_MMU_620 :case POWERPC_MMU_64B :case POWERPC_MMU_2_06 : +case POWERPC_MMU_2_06d:#endif if (ret <0 ) {/* We didn't match any BAT entry or don't have BATs */
@@ -1867,6 +1870,7 @@ int cpu_ppc_handle_mmu_fault (CPUPPCState *env, target_ulong address, int rw,case POWERPC_MMU_620 :case POWERPC_MMU_64B :case POWERPC_MMU_2_06 : +case POWERPC_MMU_2_06d:#endif env->exception_index =POWERPC_EXCP_ISI ; env->error_code =0x40000000 ;
@@ -1977,6 +1981,7 @@ int cpu_ppc_handle_mmu_fault (CPUPPCState *env, target_ulong address, int rw,case POWERPC_MMU_620 :case POWERPC_MMU_64B :case POWERPC_MMU_2_06 : +case POWERPC_MMU_2_06d:#endif env->exception_index =POWERPC_EXCP_DSI ; env->error_code =0 ;
@@ -2299,6 +2304,7 @@ void ppc_tlb_invalidate_all (CPUPPCState *env)case POWERPC_MMU_620 :case POWERPC_MMU_64B :case POWERPC_MMU_2_06 : +case POWERPC_MMU_2_06d:#endif /* defined(TARGET_PPC64) */ tlb_flush (env,1 );break ;
@@ -2367,6 +2373,7 @@ void ppc_tlb_invalidate_one (CPUPPCState *env, target_ulong addr)case POWERPC_MMU_620 :case POWERPC_MMU_64B :case POWERPC_MMU_2_06 : +case POWERPC_MMU_2_06d:/* tlbie invalidate TLBs for all segments */ /* 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,
target-ppc/kvm.c +208 -0
224 lines not on this page · raw message
target-ppc/kvm_ppc.h +5 -0
@@ -58,6 +58,11 @@ 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 (CPUPPCState *env,int irq,int level) {return -1 ;
target-ppc/translate_init.c +21 -0
@@ -9928,6 +9928,27 @@ int cpu_ppc_register_internal (CPUPPCState *env, const ppc_def_t *def) env->bfd_mach = def->bfd_mach; env->check_pow = def->check_pow; +#if defined(TARGET_PPC64 ) +if (def->sps) + env->sps = *def->sps; +else if (env->mmu_model &POWERPC_MMU_64 ) { +/* Use default sets of page sizes */ +static const struct ppc_segment_page_sizes defsps = { + .sps = { + { .page_shift =12 ,/* 4K */ + .slb_enc =0 , + .enc = { { .page_shift =12 , .pte_enc =0 } } + }, + { .page_shift =24 ,/* 16M */ + .slb_enc =0x100 , + .enc = { { .page_shift =24 , .pte_enc =0 } } + }, + }, + }; + env->sps = defsps; + } +#endif /* defined(TARGET_PPC64) */ +if (kvm_enabled ()) {if (kvmppc_fixup_cpu (env) !=0 ) {fprintf (stderr,"Unable to virtualize selected CPU with KVM\n" );
Alexander Graf
AppliedQuoted 24 lines · Benjamin Herrenschmidt
More recent Power server chips (i.e. based on the 64 bit hash MMU) support more than just the traditional 4k and 16M page sizes. This can get quite complicated, because which page sizes are supported, which combinations are supported within an MMU segment and how these page sizes are encoded both in the SLB entry and the hash PTE can vary depending on the CPU model (they are not specified by the architecture). In addition the firmware or hypervisor may not permit use of certain page sizes, for various reasons. Whether various page sizes are supported on KVM, for example, depends on whether the PR or HV variant of KVM is in use, and on the page size of the memory backing the guest's RAM.
This patch adds information to the CPUState and cpu defs to describe the supported page sizes and encodings. Since TCG does not yet support any extended page sizes, we just set this to NULL in the static CPU definitions, expanding this to the default 4k and 16M page sizes when we initialize the cpu state. When using KVM, however, we instead determine available page sizes using the new
KVM_PPC_GET_SMMU_INFOcall. For old kernels without that call, we use some defaults, with some guesswork which should do the right thing for existing HV and PR implementations. The fallback might not be correct for future versions, but that's ok, because they'll haveKVM_PPC_GET_SMMU_INFO.
Quoted 2 lines
Signed-off-by Benjamin Herrenschmidt <[email protected]>Signed-off-by David Gibson <[email protected]>
Thanks, applied both to ppc-next.
Alex