target-ppc: support ibm, pa-features device property
RFC PATCH 1/1 target-ppc: support ibm, pa-features device property
We will use this later to disable Transactional memory in case of PR KVM
---
NOTE:PPC2_TM value may need update before merging this.
hw/ppc/spapr.c | 42 ++++++++++++++++++++++++++++++++++++++++++ target-ppc/cpu.h | 2 ++ target-ppc/kvm_ppc.h | 10 ++++++++++ target-ppc/translate_init.c | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +42 -0
@@ -287,6 +287,46 @@ static size_t create_page_sizes_prop(CPUPPCState *env, uint32_t *prop, } while (0) +#define MAX_PA_FEATURES 23 +static void spapr_pa_features_skel (CPUState *cs,void *fdt) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; +char pa_features[2 +MAX_PA_FEATURES ]; + +/* +* We are currently using this only to disable P8 TM on PR. +* So don't add the property for any other case +*/ +if (!(env->insns_flags2 &PPC2_TM ) || !kvm_is_pr (cs)) { +return ; + } +memset (pa_features,0 ,sizeof (pa_features)); + pa_features[0 ] =MAX_PA_FEATURES ; + pa_features[1 ] =0 ;/* We only support a attribute specifier type of 0 */ + +/* +* Linux kernel only looks at the below feature set +* Big Endian/Little Endian +*/ + pa_features[2 ] |=1 <<7 ;/* PPC_FEATURE_HAS_MMU */ + pa_features[2 ] |=1 <<6 ;/* PPC_FEATURE_HAS_FPU */ + pa_features[2 ] |=1 <<5 ;/* MMU_FTR_SLB */ + pa_features[2 ] |=1 <<4 ;/* CPU_FTR_CTRL */ + pa_features[2 ] |=1 <<1 ;/* CPU_FTR_NOEXECUTE */ + + pa_features[3 ] |=1 <<6 ;/* CPU_FTR_NODSISRALIGN */ + pa_features[3 ] |=1 <<5 ;/* MMU_FTR_CI_LARGE_PAGE */ + + pa_features[7 ] |=1 <<7 ;/* CPU_FTR_REAL_LE */ + +/* pa_features[24] CPU_FTR_TM is disabled */ + +_FDT ((fdt_property (fdt,"ibm,pa-features" , + pa_features,sizeof (pa_features)))); +return ; +} + static void *spapr_create_fdt_skel(hwaddr initrd_base, hwaddr initrd_size, hwaddr kernel_size,
@@ -463,6 +503,8 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base, page_sizes_prop, page_sizes_prop_size))); } +spapr_pa_features_skel (cs, fdt); +_FDT ((fdt_end_node (fdt))); }
target-ppc/cpu.h +2 -0
@@ -1876,6 +1876,8 @@ enum {PPC2_DBRX =0x0000000000000010ULL ,/* Book I 2.05 PowerPC specification */ PPC2_ISA205 =0x0000000000000020ULL , +/* Transaction Memory */ +PPC2_TM =0x0000000000000040ULL , #define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_VSX | PPC2_PRCNTL | PPC2_DBRX | \PPC2_ISA205 )
target-ppc/kvm_ppc.h +10 -0
@@ -14,6 +14,7 @@void kvmppc_init (void );#ifdef CONFIG_KVM +#include "sysemu/kvm.h" uint32_t kvmppc_get_tbfreq (void );uint64_t kvmppc_get_clockfreq (void );
@@ -35,6 +36,11 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd);int kvmppc_remove_spapr_tce (void *table,int pfd,uint32_t window_size);int kvmppc_reset_htab (int shift_hint);uint64_t kvmppc_rma_size (uint64_t current_size,unsigned int hash_shift); +static inline int kvm_is_pr (CPUState *cs) +{ +return (kvm_check_extension (cs->kvm_state,KVM_CAP_PPC_GET_PVINFO ) ==1 ); +} +#endif /* !CONFIG_USER_ONLY */ int kvmppc_fixup_cpu (PowerPCCPU *cpu);bool kvmppc_has_cap_epr (void );
@@ -159,6 +165,10 @@ static inline int kvmppc_update_sdr1(CPUPPCState *env) return 0; } +static inline int kvm_is_pr (CPUState *cs) +{ +return false; +}#endif /* !CONFIG_USER_ONLY */ static inline int kvmppc_fixup_cpu (PowerPCCPU *cpu)
target-ppc/translate_init.c +1 -1
@@ -7312,7 +7312,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)PPC_64B |PPC_ALTIVEC |PPC_SEGMENT_64B |PPC_SLBI |PPC_POPCNTB |PPC_POPCNTWD ; - pcc->insns_flags2 =PPC2_VSX |PPC2_DFP |PPC2_DBRX ; + pcc->insns_flags2 =PPC2_VSX |PPC2_DFP |PPC2_DBRX |PPC2_TM ; pcc->msr_mask =0x800000000284FF36ULL ; pcc->mmu_model =POWERPC_MMU_2_06 ;#if defined(CONFIG_SOFTMMU )
Signature · 1 line
1.8.5.3
Quoted 18 lines · Aneesh Kumar K.V
We will use this later to disable Transactional memory in case of PR KVM
Signed-off-by Aneesh Kumar K.V <[email protected]>---
NOTE:PPC2_TMvalue may need update before merging this.hw/ppc/spapr.c | 42 ++++++++++++++++++++++++++++++++++++++++++ target-ppc/cpu.h | 2 ++ target-ppc/kvm_ppc.h | 10 ++++++++++ target-ppc/translate_init.c | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-)hw/ppc/spapr.c +0
-0
hw/ppc/spapr.c static size_t create_page_sizes_prop(CPUPPCState *env, uint32_t *prop, · line 290
Quoted 4 lines
hw/ppc/spapr.c +1
-0@@ -287,6 +287,46 @@ static size_t create_page_sizes_prop(CPUPPCState *env, uint32_t *prop, } while (0) +#define MAX_PA_FEATURES 23
What does this mean?
hw/ppc/spapr.c static size_t create_page_sizes_prop(CPUPPCState *env, uint32_t *prop, · line 301
Quoted 11 lines
hw/ppc/spapr.c +11
-0+static void spapr_pa_features_skel (CPUState *cs,void *fdt) +{ +PowerPCCPU *cpu =POWERPC_CPU (cs); +CPUPPCState *env = &cpu->env; +char pa_features[2 +MAX_PA_FEATURES ]; + +/* +* We are currently using this only to disable P8 TM on PR. +* So don't add the property for any other case +*/ +if (!(env->insns_flags2 &PPC2_TM ) || !kvm_is_pr (cs)) {
Better fetch a CAP from KVM to check whether it supports TM. Then we only need a patch in the kernel later to enable it.
hw/ppc/spapr.c static size_t create_page_sizes_prop(CPUPPCState *env, uint32_t *prop, · line 302
Quoted 1 line
hw/ppc/spapr.c +1
-0+return ;
How about the other cases? Why don't we always provide this node? How hard is it to simply implement TM in PR KVM? Can we play dumb and always fail transactions?
Quoted 9 lines
hw/ppc/spapr.c +9
-0+ } +memset (pa_features,0 ,sizeof (pa_features)); + pa_features[0 ] =MAX_PA_FEATURES ; + pa_features[1 ] =0 ;/* We only support a attribute specifier type of 0 */ + +/* +* Linux kernel only looks at the below feature set +* Big Endian/Little Endian +*/
hw/ppc/spapr.c static size_t create_page_sizes_prop(CPUPPCState *env, uint32_t *prop, · line 321
Quoted 10 lines
hw/ppc/spapr.c +10
-0+ pa_features[2 ] |=1 <<7 ;/* PPC_FEATURE_HAS_MMU */ + pa_features[2 ] |=1 <<6 ;/* PPC_FEATURE_HAS_FPU */ + pa_features[2 ] |=1 <<5 ;/* MMU_FTR_SLB */ + pa_features[2 ] |=1 <<4 ;/* CPU_FTR_CTRL */ + pa_features[2 ] |=1 <<1 ;/* CPU_FTR_NOEXECUTE */ + + pa_features[3 ] |=1 <<6 ;/* CPU_FTR_NODSISRALIGN */ + pa_features[3 ] |=1 <<5 ;/* MMU_FTR_CI_LARGE_PAGE */ + + pa_features[7 ] |=1 <<7 ;/* CPU_FTR_REAL_LE */
Any particular reason you give all those nice readable names, but don't just use them as defines? I'm sure you can also derive most of them from feature flags we already know about the CPU.
Quoted 46 lines
hw/ppc/spapr.c +10
-0+ +/* pa_features[24] CPU_FTR_TM is disabled */ + +_FDT ((fdt_property (fdt,"ibm,pa-features" , + pa_features,sizeof (pa_features)))); +return ; +} + static void *spapr_create_fdt_skel(hwaddr initrd_base, hwaddr initrd_size, hwaddr kernel_size,@@ -463,6 +503,8 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base, page_sizes_prop, page_sizes_prop_size))); } +spapr_pa_features_skel (cs, fdt); +_FDT ((fdt_end_node (fdt))); }target-ppc/cpu.h +2
-0@@ -1876,6 +1876,8 @@ enum {PPC2_DBRX =0x0000000000000010ULL ,/* Book I 2.05 PowerPC specification */ PPC2_ISA205 =0x0000000000000020ULL , +/* Transaction Memory */ +PPC2_TM =0x0000000000000040ULL , #define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_VSX | PPC2_PRCNTL | PPC2_DBRX | \PPC2_ISA205 )target-ppc/kvm_ppc.h +1
-0@@ -14,6 +14,7 @@void kvmppc_init (void );#ifdef CONFIG_KVM +#include "sysemu/kvm.h" uint32_t kvmppc_get_tbfreq (void );uint64_t kvmppc_get_clockfreq (void );
target-ppc/kvm_ppc.h void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd); · line 41
Quoted 6 lines
target-ppc/kvm_ppc.h +3
-0@@ -35,6 +36,11 @@ void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd);int kvmppc_remove_spapr_tce (void *table,int pfd,uint32_t window_size);int kvmppc_reset_htab (int shift_hint);uint64_t kvmppc_rma_size (uint64_t current_size,unsigned int hash_shift); +static inline int kvm_is_pr (CPUState *cs) +{ +return (kvm_check_extension (cs->kvm_state,KVM_CAP_PPC_GET_PVINFO ) ==1 );
There's no reason HV KVM couldn't implement PVINFO.
Quoted 21 lines
target-ppc/kvm_ppc.h +6
-0+} +#endif /* !CONFIG_USER_ONLY */ int kvmppc_fixup_cpu (PowerPCCPU *cpu);bool kvmppc_has_cap_epr (void );@@ -159,6 +165,10 @@ static inline int kvmppc_update_sdr1(CPUPPCState *env) return 0; } +static inline int kvm_is_pr (CPUState *cs) +{ +return false; +}#endif /* !CONFIG_USER_ONLY */ static inline int kvmppc_fixup_cpu (PowerPCCPU *cpu)target-ppc/translate_init.c +0
-0
target-ppc/translate_init.c POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data) · line 7315
Quoted 5 lines
target-ppc/translate_init.c +1
-1@@ -7312,7 +7312,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data)PPC_64B |PPC_ALTIVEC |PPC_SEGMENT_64B |PPC_SLBI |PPC_POPCNTB |PPC_POPCNTWD ; - pcc->insns_flags2 =PPC2_VSX |PPC2_DFP |PPC2_DBRX ; + pcc->insns_flags2 =PPC2_VSX |PPC2_DFP |PPC2_DBRX |PPC2_TM ;
This means that with TCG we break with -cpu POWER8, no?
Alex
Quoted 6 lines
target-ppc/translate_init.c +0
-0pcc->msr_mask =0x800000000284FF36ULL ; pcc->mmu_model =POWERPC_MMU_2_06 ;#if defined(CONFIG_SOFTMMU )Signature · 1 line
1.8.5.3