Support disable/enable CPU features for AArch64
v3 cover Support disable/enable CPU features for AArch64
QEMU does not support disable/enable CPU features in AArch64 for now. This patch series add support for CPU features in AArch64.
Firstly, we change the isar struct in ARMCPU to an array for convenience. Secondly, we add support to configure CPU feautres in AArch64 and make sure that the ID registers can be synchronized to KVM so that guest can read the value we configure. Thirdly, we add a mechanism to solve the dependency relationship of some CPU features. Last, we add a KVM_CAP_ARM_CPU_FEATURE to check whether KVM supports to set CPU features in AArch64.
Also export CPU features to the result of qmp query-cpu-model-expansion so that libvirt can get the supported CPU features.
Update the ID fields to ARMv8.6 and add some CPU features according to the new ID fields.
With related KVM patch set[1], we can disable/enable CPU features in AArch64.
[1] https://patchwork.kernel.org/project/kvm/cover/[email protected]/
v2 -> v3:
- rebase to newest code
v1 -> v2:
- adjust the order of patches
- only expose AArch64 features which are exposed by kernel via /proc/cpuinfo
- add check for conflict CPU features set by user
- split the change in linux-headers/linux/kvm.h
Peng Liang (10):
linux-header: Introduce KVM_CAP_ARM_CPU_FEATURE target/arm: Update ID fields
target/arm: only set ID_PFR1_EL1.GIC for AArch32 guest target/arm: convert isar regs to array
target/arm: Introduce kvm_arm_cpu_feature_supported target/arm: register CPU features for property
target/arm: Allow ID registers to synchronize to KVM target/arm: Introduce user_mask to indicate whether the feature is set
explicitly
target/arm: introduce CPU feature dependency mechanism target/arm: Add CPU features to query-cpu-model-expansion
hw/intc/armv7m_nvic.c | 32 +-- linux-headers/linux/kvm.h | 1 + target/arm/cpu.c | 575 +++++++++++++++++++++++++++++--------- target/arm/cpu.h | 255 +++++++++-------- target/arm/cpu64.c | 190 ++++++------- target/arm/cpu_tcg.c | 314 +++++++++++---------- target/arm/helper.c | 106 ++++--- target/arm/internals.h | 15 +- target/arm/kvm.c | 38 +++ target/arm/kvm64.c | 90 +++--- target/arm/kvm_arm.h | 10 + target/arm/monitor.c | 4 + 12 files changed, 1038 insertions(+), 592 deletions(-)
Signature · 1 line
2.26.2
RFC v3 1/10 linux-header: Introduce KVM_CAP_ARM_CPU_FEATURE
Introduce KVM_CAP_ARM_CPU_FEATURE.
--- linux-headers/linux/kvm.h | 1 + 1 file changed, 1 insertion(+)
linux-headers/linux/kvm.h +1 -0
@@ -1037,6 +1037,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_SMALLER_MAXPHYADDR 185#define KVM_CAP_S390_DIAG318 186#define KVM_CAP_STEAL_TIME 187 +#define KVM_CAP_ARM_CPU_FEATURE 191#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.26.2
RFC v3 2/10 target/arm: Update ID fields
In reply to Peng LiangUpdate definitions for ID fields, up to ARMv8.6.
--- target/arm/cpu.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
target/arm/cpu.h +17 -0
@@ -1776,6 +1776,8 @@ FIELD(ID_ISAR6, DP, 4, 4) FIELD(ID_ISAR6, FHM, 8, 4) FIELD(ID_ISAR6, SB, 12, 4) FIELD(ID_ISAR6, SPECRES, 16, 4) +FIELD(ID_ISAR6, BF16, 20, 4) +FIELD(ID_ISAR6, I8MM, 24, 4) FIELD(ID_MMFR0, VMSA, 0, 4)FIELD (ID_MMFR0 ,PMSA ,4 ,4 )
@@ -1839,6 +1841,9 @@ FIELD(ID_AA64ISAR1, GPI, 28, 4) FIELD(ID_AA64ISAR1, FRINTTS, 32, 4) FIELD(ID_AA64ISAR1, SB, 36, 4) FIELD(ID_AA64ISAR1, SPECRES, 40, 4) +FIELD(ID_AA64ISAR1, BF16, 44, 4) +FIELD(ID_AA64ISAR1, DGH, 48, 4) +FIELD(ID_AA64ISAR1, I8MM, 52, 4) FIELD(ID_AA64PFR0, EL0, 0, 4)FIELD (ID_AA64PFR0 ,EL1 ,4 ,4 )
@@ -1849,11 +1854,18 @@ FIELD(ID_AA64PFR0, ADVSIMD, 20, 4) FIELD(ID_AA64PFR0, GIC, 24, 4) FIELD(ID_AA64PFR0, RAS, 28, 4) FIELD(ID_AA64PFR0, SVE, 32, 4) +FIELD(ID_AA64PFR0, SEL2, 36, 4) +FIELD(ID_AA64PFR0, MPAM, 40, 4) +FIELD(ID_AA64PFR0, AMU, 44, 4) +FIELD(ID_AA64PFR0, DIT, 44, 4) +FIELD(ID_AA64PFR0, CSV2, 56, 4) +FIELD(ID_AA64PFR0, CSV3, 60, 4) FIELD(ID_AA64PFR1, BT, 0, 4) FIELD(ID_AA64PFR1, SBSS, 4, 4) FIELD(ID_AA64PFR1, MTE, 8, 4) FIELD(ID_AA64PFR1, RAS_FRAC, 12, 4) +FIELD(ID_AA64PFR1, MPAM_FRAC, 16, 4) FIELD(ID_AA64MMFR0, PARANGE, 0, 4)FIELD (ID_AA64MMFR0 ,ASIDBITS ,4 ,4 )
@@ -1867,6 +1879,8 @@ FIELD(ID_AA64MMFR0, TGRAN16_2, 32, 4) FIELD(ID_AA64MMFR0, TGRAN64_2, 36, 4) FIELD(ID_AA64MMFR0, TGRAN4_2, 40, 4) FIELD(ID_AA64MMFR0, EXS, 44, 4) +FIELD(ID_AA64MMFR0, FGT, 56, 4) +FIELD(ID_AA64MMFR0, ECV, 60, 4) FIELD(ID_AA64MMFR1, HAFDBS, 0, 4)FIELD (ID_AA64MMFR1 ,VMIDBITS ,4 ,4 )
@@ -1876,6 +1890,8 @@ FIELD(ID_AA64MMFR1, LO, 16, 4) FIELD(ID_AA64MMFR1, PAN, 20, 4) FIELD(ID_AA64MMFR1, SPECSEI, 24, 4) FIELD(ID_AA64MMFR1, XNX, 28, 4) +FIELD(ID_AA64MMFR1, TWED, 32, 4) +FIELD(ID_AA64MMFR1, ETS, 36, 4) FIELD(ID_AA64MMFR2, CNP, 0, 4)FIELD (ID_AA64MMFR2 ,UAO ,4 ,4 )
@@ -1902,6 +1918,7 @@ FIELD(ID_AA64DFR0, CTX_CMPS, 28, 4) FIELD(ID_AA64DFR0, PMSVER, 32, 4) FIELD(ID_AA64DFR0, DOUBLELOCK, 36, 4) FIELD(ID_AA64DFR0, TRACEFILT, 40, 4) +FIELD(ID_AA64DFR0, MUPMU, 48, 4) FIELD(ID_DFR0, COPDBG, 0, 4)FIELD (ID_DFR0 ,COPSDBG ,4 ,4 )
Signature · 1 line
2.26.2
RFC v3 3/10 target/arm: only set ID_PFR1_EL1.GIC for AArch32 guest
In reply to Peng LiangSome AArch64 CPU doesn't support AArch32 mode, AArch32 registers should be 0.
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -6660,7 +6660,7 @@ static uint64_t id_pfr1_read(CPUARMState *env, const ARMCPRegInfo *ri)ARMCPU *cpu =env_archcpu (env);uint64_t pfr1 = cpu->isar.id_pfr1; -if (env->gicv3state) { +if (!arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ) && env->gicv3state) { pfr1 |=1 <<28 ; }return pfr1;
Signature · 1 line
2.26.2
RFC v3 4/10 target/arm: convert isar regs to array
In reply to Peng LiangThe isar in ARMCPU is a struct, each field of which represents an ID register. It's not convenient for us to support CPU feature in AArch64. So let's change it to an array first and add an enum as the index of the array for convenience. Since we will never access high 32-bits of ID registers in AArch32, it's harmless to change the ID registers in AArch32 to 64-bits.
--- hw/intc/armv7m_nvic.c | 32 ++--- target/arm/cpu.c | 251 ++++++++++++++++---------------- target/arm/cpu.h | 237 ++++++++++++++++--------------- target/arm/cpu64.c | 190 ++++++++++++------------- target/arm/cpu_tcg.c | 314 +++++++++++++++++++++-------------------- target/arm/helper.c | 58 ++++---- target/arm/internals.h | 15 +- target/arm/kvm64.c | 76 +++++----- 8 files changed, 593 insertions(+), 580 deletions(-)
hw/intc/armv7m_nvic.c +16 -16
@@ -1241,17 +1241,17 @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_pfr0; +return cpu->isar.regs[ID_PFR0 ];case 0xd44 :/* PFR1. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_pfr1; +return cpu->isar.regs[ID_PFR1 ];case 0xd48 :/* DFR0. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_dfr0; +return cpu->isar.regs[ID_DFR0 ];case 0xd4c :/* AFR0. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset;
@@ -1261,52 +1261,52 @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_mmfr0; +return cpu->isar.regs[ID_MMFR0 ];case 0xd54 :/* MMFR1. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_mmfr1; +return cpu->isar.regs[ID_MMFR1 ];case 0xd58 :/* MMFR2. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_mmfr2; +return cpu->isar.regs[ID_MMFR2 ];case 0xd5c :/* MMFR3. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_mmfr3; +return cpu->isar.regs[ID_MMFR3 ];case 0xd60 :/* ISAR0. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_isar0; +return cpu->isar.regs[ID_ISAR0 ];case 0xd64 :/* ISAR1. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_isar1; +return cpu->isar.regs[ID_ISAR1 ];case 0xd68 :/* ISAR2. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_isar2; +return cpu->isar.regs[ID_ISAR2 ];case 0xd6c :/* ISAR3. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_isar3; +return cpu->isar.regs[ID_ISAR3 ];case 0xd70 :/* ISAR4. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_isar4; +return cpu->isar.regs[ID_ISAR4 ];case 0xd74 :/* ISAR5. */ if (!arm_feature (&cpu->env,ARM_FEATURE_M_MAIN )) { goto bad_offset; } -return cpu->isar.id_isar5; +return cpu->isar.regs[ID_ISAR5 ];case 0xd78 :/* CLIDR */ return cpu->clidr;case 0xd7c :/* CTR */
@@ -1510,11 +1510,11 @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) }return cpu->env.v7m.fpdscr[attrs.secure];case 0xf40 :/* MVFR0 */ -return cpu->isar.mvfr0; +return cpu->isar.regs[MVFR0 ];case 0xf44 :/* MVFR1 */ -return cpu->isar.mvfr1; +return cpu->isar.regs[MVFR1 ];case 0xf48 :/* MVFR2 */ -return cpu->isar.mvfr2; +return cpu->isar.regs[MVFR2 ];default : bad_offset:qemu_log_mask (LOG_GUEST_ERROR ,"NVIC: Bad read offset 0x%x\n" , offset);
target/arm/cpu.c +126 -125
436 lines not on this page · raw message
target/arm/cpu.h +121 -116
608 lines not on this page · raw message
target/arm/cpu64.c +95 -95
294 lines not on this page · raw message
target/arm/cpu_tcg.c +159 -155
417 lines not on this page · raw message
target/arm/helper.c +29 -29
198 lines not on this page · raw message
target/arm/internals.h +8 -7
@@ -237,7 +237,7 @@ static inline unsigned int arm_pamax(ARMCPU *cpu) [5] = 48, };unsigned int parange = -FIELD_EX64 (cpu->isar.id_aa64mmfr0,ID_AA64MMFR0 ,PARANGE ); +FIELD_EX64 (cpu->isar.regs[ID_AA64MMFR0 ],ID_AA64MMFR0 ,PARANGE );/* id_aa64mmfr0 is a read-only register so values outside of the * supported mappings can be considered an implementation error. */
@@ -991,9 +991,9 @@ static inline uint32_t arm_debug_exception_fsr(CPUARMState *env)static inline int arm_num_brps (ARMCPU *cpu) {if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { -return FIELD_EX64 (cpu->isar.id_aa64dfr0,ID_AA64DFR0 ,BRPS ) +1 ; +return FIELD_EX64 (cpu->isar.regs[ID_AA64DFR0 ],ID_AA64DFR0 ,BRPS ) +1 ; }else { -return FIELD_EX32 (cpu->isar.dbgdidr,DBGDIDR ,BRPS ) +1 ; +return FIELD_EX32 (cpu->isar.regs[DBGDIDR ],DBGDIDR ,BRPS ) +1 ; } }
@@ -1005,9 +1005,9 @@ static inline int arm_num_brps(ARMCPU *cpu)static inline int arm_num_wrps (ARMCPU *cpu) {if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { -return FIELD_EX64 (cpu->isar.id_aa64dfr0,ID_AA64DFR0 ,WRPS ) +1 ; +return FIELD_EX64 (cpu->isar.regs[ID_AA64DFR0 ],ID_AA64DFR0 ,WRPS ) +1 ; }else { -return FIELD_EX32 (cpu->isar.dbgdidr,DBGDIDR ,WRPS ) +1 ; +return FIELD_EX32 (cpu->isar.regs[DBGDIDR ],DBGDIDR ,WRPS ) +1 ; } }
@@ -1019,9 +1019,10 @@ static inline int arm_num_wrps(ARMCPU *cpu)static inline int arm_num_ctx_cmps (ARMCPU *cpu) {if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { -return FIELD_EX64 (cpu->isar.id_aa64dfr0,ID_AA64DFR0 ,CTX_CMPS ) +1 ; +return FIELD_EX64 (cpu->isar.regs[ID_AA64DFR0 ],ID_AA64DFR0 , +CTX_CMPS ) +1 ; }else { -return FIELD_EX32 (cpu->isar.dbgdidr,DBGDIDR ,CTX_CMPS ) +1 ; +return FIELD_EX32 (cpu->isar.regs[DBGDIDR ],DBGDIDR ,CTX_CMPS ) +1 ; } }
target/arm/kvm64.c +39 -37
149 lines not on this page · raw message
Signature · 1 line
2.26.2
RFC v3 5/10 target/arm: Introduce kvm_arm_cpu_feature_supported
In reply to Peng LiangIntroduce kvm_arm_cpu_feature_supported to check whether KVM supports to set CPU features in ARM.
--- target/arm/kvm64.c | 14 ++++++++++++++ target/arm/kvm_arm.h | 7 +++++++ 2 files changed, 21 insertions(+)
target/arm/kvm64.c +14 -0
@@ -721,6 +721,20 @@ bool kvm_arm_steal_time_supported(void)return kvm_check_extension (kvm_state,KVM_CAP_STEAL_TIME ); } +bool kvm_arm_cpu_feature_supported (void ) +{ +static bool cpu_feature_initialized; +static bool cpu_feature_supported; + +if (!cpu_feature_initialized) { + cpu_feature_supported =kvm_check_extension (kvm_state, +KVM_CAP_ARM_CPU_FEATURE ); + cpu_feature_initialized = true; + } + +return cpu_feature_supported; +} +QEMU_BUILD_BUG_ON (KVM_ARM64_SVE_VQ_MIN !=1 );void kvm_arm_sve_get_vls (CPUState *cs,unsigned long *map)
target/arm/kvm_arm.h +7 -0
@@ -308,6 +308,13 @@ bool kvm_arm_pmu_supported(void);*/ bool kvm_arm_sve_supported (void ); +/** +* kvm_arm_cpu_feature_supported: +* +* Returns true if KVM can set CPU features and false otherwise. +*/ +bool kvm_arm_cpu_feature_supported (void ); +/** * kvm_arm_get_max_vm_ipa_size: * @ms: Machine state handle
Signature · 1 line
2.26.2
RFC v3 6/10 target/arm: register CPU features for property
In reply to Peng LiangThe Arm architecture specifies a number of ID registers that are characterized as comprising a set of 4-bit ID fields. Each ID field identifies the presence, and possibly the level of support for, a particular feature in an implementation of the architecture. [1]
For most of the ID fields, there is a minimum presence value, equal to or higher than which means the corresponding CPU feature is implemented. Hence, we can use the minimum presence value to determine whether a CPU feature is enabled and enable a CPU feature.
To disable a CPU feature, setting the corresponding ID field to 0x0/0xf (for unsigned/signed field) seems as a good idea. However, it maybe lead to some problems. For example, ID_AA64PFR0_EL1.FP is a signed ID field. ID_AA64PFR0_EL1.FP == 0x0 represents the implementation of FP (floating-point) and ID_AA64PFR0_EL1.FP == 0x1 represents the implementation of FPHP (half-precision floating-point). If ID_AA64PFR0_EL1.FP is set to 0xf when FPHP is disabled (which is also disable FP), guest kernel maybe stuck. Hence, we add a ni_value (means not-implemented value) to disable a CPU feature safely.
[1] D13.1.3 Principles of the ID scheme for fields in ID registers in
DDI.0487
--- target/arm/cpu.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+)
target/arm/cpu.c +188 -0
@@ -1157,6 +1157,193 @@ unsigned int gt_cntfrq_period_ns(ARMCPU *cpu) NANOSECONDS_PER_SECOND / cpu->gt_cntfrq_hz : 1; } +/** +* CPUFeatureInfo: +* @reg: The ID register where the ID field is in. +* @name: The name of the CPU feature. +* @length: The bit length of the ID field. +* @shift: The bit shift of the ID field in the ID register. +* @min_value: The minimum value equal to or larger than which means the CPU +* feature is implemented. +* @ni_value: Not-implemented value. It will be set to the ID field when +* disabling the CPU feature. Usually, it's min_value - 1. +* @sign: Whether the ID field is signed. +* @is_32bit: Whether the CPU feature is for 32-bit. +* +* In ARM, a CPU feature is described by an ID field, which is a 4-bit field in +* an ID register. +*/ +typedef struct CPUFeatureInfo { +CPUIDReg reg; +const char *name; +int length; +int shift; +int min_value; +int ni_value; +bool sign; +bool is_32bit; +}CPUFeatureInfo ; + +#define FIELD_INFO (feat_name, id_reg, field, s, min_val, ni_val, is32bit) { \ + .reg = id_reg, \ + .length = R_ ## id_reg ## _ ## field ## _LENGTH, \ + .shift = R_ ## id_reg ## _ ## field ## _SHIFT, \ + .sign = s, \ + .min_value = min_val, \ + .ni_value = ni_val, \ + .name = feat_name, \ + .is_32bit = is32bit, \ +} + +static struct CPUFeatureInfo cpu_features[] = { +FIELD_INFO ("aes" ,ID_AA64ISAR0 ,AES , false,1 ,0 , false), +FIELD_INFO ("sha1" ,ID_AA64ISAR0 ,SHA1 , false,1 ,0 , false), +FIELD_INFO ("sha2" ,ID_AA64ISAR0 ,SHA2 , false,1 ,0 , false), +FIELD_INFO ("crc32" ,ID_AA64ISAR0 ,CRC32 , false,1 ,0 , false), +FIELD_INFO ("atomics" ,ID_AA64ISAR0 ,ATOMIC , false,1 ,0 , false), +FIELD_INFO ("asimdrdm" ,ID_AA64ISAR0 ,RDM , false,1 ,0 , false), +FIELD_INFO ("sha3" ,ID_AA64ISAR0 ,SHA3 , false,1 ,0 , false), +FIELD_INFO ("sm3" ,ID_AA64ISAR0 ,SM3 , false,1 ,0 , false), +FIELD_INFO ("sm4" ,ID_AA64ISAR0 ,SM4 , false,1 ,0 , false), +FIELD_INFO ("asimddp" ,ID_AA64ISAR0 ,DP , false,1 ,0 , false), +FIELD_INFO ("asimdfhm" ,ID_AA64ISAR0 ,FHM , false,1 ,0 , false), +FIELD_INFO ("flagm" ,ID_AA64ISAR0 ,TS , false,1 ,0 , false), +FIELD_INFO ("rng" ,ID_AA64ISAR0 ,RNDR , false,1 ,0 , false), + +FIELD_INFO ("dcpop" ,ID_AA64ISAR1 ,DPB , false,1 ,0 , false), +FIELD_INFO ("jscvt" ,ID_AA64ISAR1 ,JSCVT , false,1 ,0 , false), +FIELD_INFO ("fcma" ,ID_AA64ISAR1 ,FCMA , false,1 ,0 , false), +FIELD_INFO ("lrcpc" ,ID_AA64ISAR1 ,LRCPC , false,1 ,0 , false), +FIELD_INFO ("frint" ,ID_AA64ISAR1 ,FRINTTS , false,1 ,0 , false), +FIELD_INFO ("sb" ,ID_AA64ISAR1 ,SB , false,1 ,0 , false), +FIELD_INFO ("i8mm" ,ID_AA64ISAR1 ,I8MM , false,1 ,0 , false), +FIELD_INFO ("bf16" ,ID_AA64ISAR1 ,BF16 , false,1 ,0 , false), +FIELD_INFO ("dgh" ,ID_AA64ISAR1 ,DGH , false,1 ,0 , false), + +FIELD_INFO ("fp" ,ID_AA64PFR0 ,FP , true,0 ,0xf , false), +FIELD_INFO ("asimd" ,ID_AA64PFR0 ,ADVSIMD , true,0 ,0xf , false), +FIELD_INFO ("dit" ,ID_AA64PFR0 ,DIT , false,1 ,0 , false), + +FIELD_INFO ("bt" ,ID_AA64PFR1 ,BT , false,1 ,0 , false), +FIELD_INFO ("sbss" ,ID_AA64PFR1 ,SBSS , false,1 ,0 , false), + +FIELD_INFO ("uscat" ,ID_AA64MMFR2 ,AT , false,1 ,0 , false), + + { + .reg =ID_AA64PFR0 , .length =R_ID_AA64PFR0_FP_LENGTH , + .shift =R_ID_AA64PFR0_FP_SHIFT , .sign = true, .min_value =1 , + .ni_value =0 , .name ="fphp" , .is_32bit = false, + }, + { + .reg =ID_AA64PFR0 , .length =R_ID_AA64PFR0_ADVSIMD_LENGTH , + .shift =R_ID_AA64PFR0_ADVSIMD_SHIFT , .sign = true, .min_value =1 , + .ni_value =0 , .name ="asimdhp" , .is_32bit = false, + }, + { + .reg =ID_AA64ISAR0 , .length =R_ID_AA64ISAR0_AES_LENGTH , + .shift =R_ID_AA64ISAR0_AES_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="pmull" , .is_32bit = false, + }, + { + .reg =ID_AA64ISAR0 , .length =R_ID_AA64ISAR0_SHA2_LENGTH , + .shift =R_ID_AA64ISAR0_SHA2_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="sha512" , .is_32bit = false, + }, + { + .reg =ID_AA64ISAR0 , .length =R_ID_AA64ISAR0_TS_LENGTH , + .shift =R_ID_AA64ISAR0_TS_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="flagm2" , .is_32bit = false, + }, + { + .reg =ID_AA64ISAR1 , .length =R_ID_AA64ISAR1_DPB_LENGTH , + .shift =R_ID_AA64ISAR1_DPB_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="dcpodp" , .is_32bit = false, + }, + { + .reg =ID_AA64ISAR1 , .length =R_ID_AA64ISAR1_LRCPC_LENGTH , + .shift =R_ID_AA64ISAR1_LRCPC_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="ilrcpc" , .is_32bit = false, + }, +}; + +static void arm_cpu_get_feature_prop (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +ARMCPU *cpu =ARM_CPU (obj); +CPUFeatureInfo *feat = opaque; +int field_value = feat->sign ?sextract64 (cpu->isar.regs[feat->reg], + feat->shift, feat->length) : +extract64 (cpu->isar.regs[feat->reg], + feat->shift, feat->length); +bool value = field_value >= feat->min_value; + +visit_type_bool (v, name, &value, errp); +} + +static void arm_cpu_set_feature_prop (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +ARMCPU *cpu =ARM_CPU (obj); +ARMISARegisters *isar = &cpu->isar; +CPUFeatureInfo *feat = opaque; +Error *local_err =NULL ; +bool value; + +if (!kvm_arm_cpu_feature_supported ()) { +warn_report ("KVM doesn't support to set CPU feature in arm. " +"Setting to `%s` is ignored." , name); +return ; + } +if (dev->realized) { +qdev_prop_set_after_realize (dev, name, errp); +return ; + } + +visit_type_bool (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +if (value) { +if (object_property_get_bool (obj, feat->name, &error_abort)) { +return ; + } + isar->regs[feat->reg] =deposit64 (isar->regs[feat->reg], + feat->shift, feat->length, + feat->min_value); + }else { +if (!object_property_get_bool (obj, feat->name, &error_abort)) { +return ; + } + isar->regs[feat->reg] =deposit64 (isar->regs[feat->reg], + feat->shift, feat->length, + feat->ni_value); + } +} + +static void arm_cpu_register_feature_props (ARMCPU *cpu) +{ +int i; +ObjectProperty *op; +CPUARMState *env = &cpu->env; + +for (i =0 ; i <ARRAY_SIZE (cpu_features); i++) { +if (!(arm_feature (env,ARM_FEATURE_AARCH64 ) ^ + cpu_features[i].is_32bit)) { +continue ; + } + op =object_property_find (OBJECT (cpu), cpu_features[i].name); +if (!op) { +object_property_add (OBJECT (cpu), cpu_features[i].name,"bool" , + arm_cpu_get_feature_prop, + arm_cpu_set_feature_prop, +NULL , &cpu_features[i]); + } + } +} +void arm_cpu_post_init (Object *obj) {ARMCPU *cpu =ARM_CPU (obj);
@@ -1282,6 +1469,7 @@ void arm_cpu_post_init(Object *obj) } }#endif +arm_cpu_register_feature_props (cpu); }static void arm_cpu_finalizefn (Object *obj)
Signature · 1 line
2.26.2
RFC v3 7/10 target/arm: Allow ID registers to synchronize to KVM
In reply to Peng LiangThere are 2 steps to synchronize the values of system registers from CPU state to KVM:
1. write to the values of system registers from CPU state to (index,value) list by write_cpustate_to_list;
2. write the values in (index,value) list to KVM by write_list_to_kvmstate;
In step 1, the values of constant system registers are not allowed to write to (index,value) list. However, a constant system register is CONSTANT for guest but not for QEMU, which means, QEMU can set/modify the value of constant system registers that is different from phsical registers when startup. But if KVM is enabled, guest can not read the values of the system registers which QEMU set unless they can be written to (index,value) list. And why not try to write to KVM if kvm_sync is true?
At the moment we call write_cpustate_to_list, all ID registers are contant, including ID_PFR1_EL1 and ID_AA64PFR0_EL1 because GIC has been initialized. Hence, let's give all ID registers a chance to write to KVM. If the write is successful, then write to (index,value) list.
--- target/arm/helper.c | 46 +++++++++++++++++++++++++++++++++----------- target/arm/kvm.c | 38 ++++++++++++++++++++++++++++++++++++ target/arm/kvm_arm.h | 3 +++ 3 files changed, 76 insertions(+), 11 deletions(-)
target/arm/helper.c +35 -11
@@ -35,6 +35,7 @@#include "arm_ldst.h" #include "exec/cpu_ldst.h" #endif +#include "kvm_arm.h" #define ARM_CPU_FREQ 1000000000/* FIXME: 1 GHz, should be configurable */
@@ -355,6 +356,16 @@ static bool raw_accessors_invalid(const ARMCPRegInfo *ri)return true; } +static inline bool is_id_register (const ARMCPRegInfo *ri) +{ +/* +* (Op0, Op1, CRn, CRm, Op2) of ID registers is (3, 0, 0, crm, op2), +* where 1<=crm<8, 0<=op2<8. +*/ +return ri->opc0 ==3 && ri->opc1 ==0 && ri->crn ==0 && + ri->crm >0 && ri->crm <8 ; +} +bool write_cpustate_to_list (ARMCPU *cpu,bool kvm_sync) {/* Write the coprocessor state from cpu->env to the (index,value) list. */
@@ -371,30 +382,43 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync) ok = false;continue ; } -if (ri->type &ARM_CP_NO_RAW ) { +/* Let's give ID registers a chance to synchronize to kvm. */ +if ((ri->type &ARM_CP_NO_RAW ) && !(kvm_sync &&is_id_register (ri))) {continue ; } newval =read_raw_cp_reg (&cpu->env, ri);if (kvm_sync) { -/* -* Only sync if the previous list->cpustate sync succeeded. -* Rather than tracking the success/failure state for every -* item in the list, we just recheck "does the raw write we must -* have made in write_list_to_cpustate() read back OK" here. -*/ -uint64_t oldval = cpu->cpreg_values[i]; +/* Only sync if we can sync to KVM successfully. */ +uint64_t oldval; +uint64_t kvmval; +if (kvm_arm_get_one_reg (cpu, cpu->cpreg_indexes[i], &oldval)) { +continue ; + }if (oldval == newval) {continue ; } -write_raw_cp_reg (&cpu->env, ri, oldval); -if (read_raw_cp_reg (&cpu->env, ri) != oldval) { +if (kvm_arm_set_one_reg (cpu, cpu->cpreg_indexes[i], &newval)) { +if (is_id_register (ri)) { + ok = false; +error_report ("Cannot set ID regsiter %s: %s" , ri->name, +strerror (errno)); + } +continue ; + } +if (kvm_arm_get_one_reg (cpu, cpu->cpreg_indexes[i], &kvmval) || + kvmval != newval) { +if (is_id_register (ri)) { + ok = false; +error_report ("Setting ID register %s doesn't effect" , + ri->name); + }continue ; } -write_raw_cp_reg (&cpu->env, ri, newval); +kvm_arm_set_one_reg (cpu, cpu->cpreg_indexes[i], &oldval); } cpu->cpreg_values[i] = newval; }
target/arm/kvm.c +38 -0
@@ -506,6 +506,44 @@ out:return ret; } +int kvm_arm_get_one_reg (ARMCPU *cpu,uint64_t regidx,uint64_t *target) +{ +uint32_t v32; +int ret; + +switch (regidx &KVM_REG_SIZE_MASK ) { +case KVM_REG_SIZE_U32 : + ret =kvm_get_one_reg (CPU (cpu), regidx, &v32); +if (ret ==0 ) { + *target = v32; + } +return ret; +case KVM_REG_SIZE_U64 : +return kvm_get_one_reg (CPU (cpu), regidx, target); +default : +return -1 ; + } +} + +int kvm_arm_set_one_reg (ARMCPU *cpu,uint64_t regidx,uint64_t *source) +{ +uint32_t v32; + +switch (regidx &KVM_REG_SIZE_MASK ) { +case KVM_REG_SIZE_U32 : + v32 = *source; +if (v32 != *source) { +error_report ("the value of source is too large" ); +return -1 ; + } +return kvm_set_one_reg (CPU (cpu), regidx, &v32); +case KVM_REG_SIZE_U64 : +return kvm_set_one_reg (CPU (cpu), regidx, source); +default : +return -1 ; + } +} +bool write_kvmstate_to_list (ARMCPU *cpu) {CPUState *cs =CPU (cpu);
target/arm/kvm_arm.h +3 -0
@@ -535,4 +535,7 @@ static inline const char *its_class_name(void) } } +int kvm_arm_get_one_reg (ARMCPU *cpu,uint64_t regidx,uint64_t *target); +int kvm_arm_set_one_reg (ARMCPU *cpu,uint64_t regidx,uint64_t *source); +#endif
Signature · 1 line
2.26.2
RFC v3 8/10 target/arm: Introduce user_mask to indicate whether the feature is set explicitly
In reply to Peng LiangTo add CPU feature dependencies, we need to known whether a CPU feature is set explicitly or automatically by dependencies mechanism. Introduce user_mask to do that.
--- target/arm/cpu.c | 2 ++ target/arm/cpu.h | 1 + 2 files changed, 3 insertions(+)
target/arm/cpu.c +2 -0
@@ -1306,6 +1306,8 @@ static void arm_cpu_set_feature_prop(Object *obj, Visitor *v, const char *name,return ; } + isar->user_mask[feat->reg] |=MAKE_64BIT_MASK (feat->shift, feat->length); +if (value) {if (object_property_get_bool (obj, feat->name, &error_abort)) {return ;
target/arm/cpu.h +1 -0
@@ -932,6 +932,7 @@ struct ARMCPU {*/ struct ARMISARegisters {uint64_t regs[ID_MAX ]; +uint64_t user_mask[ID_MAX ]; } isar;uint64_t midr;uint32_t revidr;
Signature · 1 line
2.26.2
RFC v3 9/10 target/arm: introduce CPU feature dependency mechanism
In reply to Peng LiangSome CPU features are dependent on other CPU features. For example, ID_AA64PFR0_EL1.FP field and ID_AA64PFR0_EL1.AdvSIMD must have the same value, which means FP and ADVSIMD are dependent on each other, FPHP and ADVSIMDHP are dependent on each other.
This commit introduces a mechanism for CPU feature dependency in AArch64. We build a directed graph from the CPU feature dependency relationship, each edge from->to means the to CPU feature is dependent on the from CPU feature. And we will automatically enable/disable CPU feature according to the directed graph.
For example, a and b CPU features are in relationship a->b, which means b is dependent on a. If b is enabled by user, then a is enabled automatically. And if a is disabled by user, then b is disabled automatically.
--- target/arm/cpu.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+)
target/arm/cpu.c +134 -0
@@ -1266,6 +1266,107 @@ static struct CPUFeatureInfo cpu_features[] = { }, }; +typedef struct CPUFeatureDep { +CPUFeatureInfo from, to; +}CPUFeatureDep ; + +static const CPUFeatureDep feature_dependencies[] = { + { + .from =FIELD_INFO ("fp" ,ID_AA64PFR0 ,FP , true,0 ,0xf , false), + .to =FIELD_INFO ("asimd" ,ID_AA64PFR0 ,ADVSIMD , true,0 ,0xf , false), + }, + { + .from =FIELD_INFO ("asimd" ,ID_AA64PFR0 ,ADVSIMD , true,0 ,0xf , false), + .to =FIELD_INFO ("fp" ,ID_AA64PFR0 ,FP , true,0 ,0xf , false), + }, + { + .from = { + .reg =ID_AA64PFR0 , .length =R_ID_AA64PFR0_FP_LENGTH , + .shift =R_ID_AA64PFR0_FP_SHIFT , .sign = true, .min_value =1 , + .ni_value =0 , .name ="fphp" , .is_32bit = false, + }, + .to = { + .reg =ID_AA64PFR0 , .length =R_ID_AA64PFR0_ADVSIMD_LENGTH , + .shift =R_ID_AA64PFR0_ADVSIMD_SHIFT , .sign = true, .min_value =1 , + .ni_value =0 , .name ="asimdhp" , .is_32bit = false, + }, + }, + { + .from = { + .reg =ID_AA64PFR0 , .length =R_ID_AA64PFR0_ADVSIMD_LENGTH , + .shift =R_ID_AA64PFR0_ADVSIMD_SHIFT , .sign = true, .min_value =1 , + .ni_value =0 , .name ="asimdhp" , .is_32bit = false, + }, + .to = { + .reg =ID_AA64PFR0 , .length =R_ID_AA64PFR0_FP_LENGTH , + .shift =R_ID_AA64PFR0_FP_SHIFT , .sign = true, .min_value =1 , + .ni_value =0 , .name ="fphp" , .is_32bit = false, + }, + }, + { + + .from =FIELD_INFO ("aes" ,ID_AA64ISAR0 ,AES , false,1 ,0 , false), + .to = { + .reg =ID_AA64ISAR0 , .length =R_ID_AA64ISAR0_AES_LENGTH , + .shift =R_ID_AA64ISAR0_AES_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="pmull" , .is_32bit = false, + }, + }, + { + + .from =FIELD_INFO ("sha2" ,ID_AA64ISAR0 ,SHA2 , false,1 ,0 , false), + .to = { + .reg =ID_AA64ISAR0 , .length =R_ID_AA64ISAR0_SHA2_LENGTH , + .shift =R_ID_AA64ISAR0_SHA2_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="sha512" , .is_32bit = false, + }, + }, + { + .from =FIELD_INFO ("lrcpc" ,ID_AA64ISAR1 ,LRCPC , false,1 ,0 , false), + .to = { + .reg =ID_AA64ISAR1 , .length =R_ID_AA64ISAR1_LRCPC_LENGTH , + .shift =R_ID_AA64ISAR1_LRCPC_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="ilrcpc" , .is_32bit = false, + }, + }, + { + .from =FIELD_INFO ("sm3" ,ID_AA64ISAR0 ,SM3 , false,1 ,0 , false), + .to =FIELD_INFO ("sm4" ,ID_AA64ISAR0 ,SM4 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO ("sm4" ,ID_AA64ISAR0 ,SM4 , false,1 ,0 , false), + .to =FIELD_INFO ("sm3" ,ID_AA64ISAR0 ,SM3 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO ("sha1" ,ID_AA64ISAR0 ,SHA1 , false,1 ,0 , false), + .to =FIELD_INFO ("sha2" ,ID_AA64ISAR0 ,SHA2 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO ("sha2" ,ID_AA64ISAR0 ,SHA2 , false,1 ,0 , false), + .to =FIELD_INFO ("sha1" ,ID_AA64ISAR0 ,SHA1 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO ("sha1" ,ID_AA64ISAR0 ,SHA1 , false,1 ,0 , false), + .to =FIELD_INFO ("sha3" ,ID_AA64ISAR0 ,SHA3 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO ("sha3" ,ID_AA64ISAR0 ,SHA3 , false,1 ,0 , false), + .to = { + .reg =ID_AA64ISAR0 , .length =R_ID_AA64ISAR0_SHA2_LENGTH , + .shift =R_ID_AA64ISAR0_SHA2_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="sha512" , .is_32bit = false, + }, + }, + { + .from = { + .reg =ID_AA64ISAR0 , .length =R_ID_AA64ISAR0_SHA2_LENGTH , + .shift =R_ID_AA64ISAR0_SHA2_SHIFT , .sign = false, .min_value =2 , + .ni_value =1 , .name ="sha512" , .is_32bit = false, + }, + .to =FIELD_INFO ("sha3" ,ID_AA64ISAR0 ,SHA3 , false,1 ,0 , false), + }, +}; +static void arm_cpu_get_feature_prop (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -1500,6 +1601,8 @@ static void arm_cpu_finalizefn(Object *obj)void arm_cpu_finalize_features (ARMCPU *cpu,Error **errp) { +int i; +ARMISARegisters *isar = &cpu->isar;Error *local_err =NULL ;if (arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) {
@@ -1517,6 +1620,37 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)return ; } } + +if (!kvm_enabled () || !kvm_arm_cpu_feature_supported ()) { +return ; + } + +for (i =0 ; i <ARRAY_SIZE (feature_dependencies); ++i) { +const CPUFeatureDep *d = &feature_dependencies[i]; +bool from_explicit = !!(isar->user_mask[d->from.reg] & +MAKE_64BIT_MASK (d->from.shift, d->from.length)); +bool to_explicit = !!(isar->user_mask[d->to.reg] & +MAKE_64BIT_MASK (d->to.shift, d->to.length)); +bool from_enabled =object_property_get_bool (OBJECT (cpu), d->from.name, + &error_abort); +bool to_enabled =object_property_get_bool (OBJECT (cpu), d->to.name, + &error_abort); + +if (!from_enabled && to_enabled) { +if (from_explicit && to_explicit) { +error_setg (errp,"The CPU feature '%s' dependes on CPU feature " +"'%s' that is disabled explicitly" , + d->to.name, d->from.name); +return ; + }else if (from_explicit) { + isar->regs[d->to.reg] =deposit64 (isar->regs[d->to.reg], + d->to.shift, d->to.length, d->to.ni_value); + }else if (to_explicit) { + isar->regs[d->from.reg] =deposit64 (isar->regs[d->from.reg], + d->from.shift, d->from.length, d->from.min_value); + } + } + } }static void arm_cpu_realizefn (DeviceState *dev,Error **errp)
Signature · 1 line
2.26.2
RFC v3 10/10 target/arm: Add CPU features to query-cpu-model-expansion
In reply to Peng LiangAdd CPU features to the result of query-cpu-model-expansion so that other applications (such as libvirt) can know the supported CPU features.
--- target/arm/monitor.c | 4 ++++ 1 file changed, 4 insertions(+)
target/arm/monitor.c +4 -0
@@ -104,6 +104,10 @@ static const char *cpu_model_advertised_features[] = {"sve640" ,"sve768" ,"sve896" ,"sve1024" ,"sve1152" ,"sve1280" ,"sve1408" ,"sve1536" ,"sve1664" ,"sve1792" ,"sve1920" ,"sve2048" ,"kvm-no-adjvtime" ,"kvm-steal-time" , +"aes" ,"sha1" ,"sha2" ,"crc32" ,"atomics" ,"asimdrdm" ,"sha3" ,"sm3" ,"sm4" , +"asimddp" ,"asimdfhm" ,"flagm" ,"rng" ,"dcpop" ,"jscvt" ,"fcma" ,"lrcpc" , +"frint" ,"sb" ,"i8mm" ,"bf16" ,"dgh" ,"fp" ,"asimd" ,"dit" ,"bt" ,"sbss" , +"uscat" ,"fphp" ,"asimdhp" ,"pmull" ,"sha512" ,"flagm2" ,"dcpodp" ,"ilrcpc" ,NULL };
Signature · 1 line
2.26.2