Support disable/enable CPU features for AArch64
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/cover/11711693/
Peng Liang (9):
target/arm: convert isar regs to array target/arm: parse cpu feature related options target/arm: register CPU features for property target/arm: Allow ID registers to synchronize to KVM target/arm: introduce CPU feature dependency mechanism target/arm: introduce KVM_CAP_ARM_CPU_FEATURE target/arm: Add CPU features to query-cpu-model-expansion target/arm: Update ID fields
target/arm: Add more CPU features
hw/intc/armv7m_nvic.c | 48 +-- linux-headers/linux/kvm.h | 1 + target/arm/cpu.c | 753 ++++++++++++++++++++++++++++++++------ target/arm/cpu.h | 245 +++++++------ target/arm/cpu64.c | 271 +++++++++----- target/arm/cpu_tcg.c | 250 ++++++------- target/arm/helper.c | 85 +++-- target/arm/internals.h | 15 +- target/arm/kvm.c | 38 ++ target/arm/kvm64.c | 86 +++-- target/arm/kvm_arm.h | 10 + target/arm/monitor.c | 2 + 12 files changed, 1267 insertions(+), 537 deletions(-)
Signature · 1 line
2.18.4
RFC 1/9 target/arm: convert isar regs to array
The 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 | 48 ++++---- target/arm/cpu.c | 232 +++++++++++++++++++------------------- target/arm/cpu.h | 226 +++++++++++++++++++------------------ target/arm/cpu64.c | 170 ++++++++++++++-------------- target/arm/cpu_tcg.c | 250 +++++++++++++++++++++-------------------- target/arm/helper.c | 54 ++++----- target/arm/internals.h | 15 +-- target/arm/kvm64.c | 72 ++++++------ 8 files changed, 541 insertions(+), 526 deletions(-)
hw/intc/armv7m_nvic.c +24 -24
@@ -1242,29 +1242,29 @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)case 0xd44 :/* PFR1. */ return cpu->id_pfr1;case 0xd48 :/* DFR0. */ -return cpu->isar.id_dfr0; +return cpu->isar.regs[ID_DFR0 ];case 0xd4c :/* AFR0. */ return cpu->id_afr0; -case 0xd50 :/* MMFR0. */ -return cpu->isar.id_mmfr0; -case 0xd54 :/* MMFR1. */ -return cpu->isar.id_mmfr1; -case 0xd58 :/* MMFR2. */ -return cpu->isar.id_mmfr2; -case 0xd5c :/* MMFR3. */ -return cpu->isar.id_mmfr3; -case 0xd60 :/* ISAR0. */ -return cpu->isar.id_isar0; -case 0xd64 :/* ISAR1. */ -return cpu->isar.id_isar1; -case 0xd68 :/* ISAR2. */ -return cpu->isar.id_isar2; -case 0xd6c :/* ISAR3. */ -return cpu->isar.id_isar3; -case 0xd70 :/* ISAR4. */ -return cpu->isar.id_isar4; -case 0xd74 :/* ISAR5. */ -return cpu->isar.id_isar5; +case 0xd50 :/* MMFR0. */ +return cpu->isar.regs[ID_MMFR0 ]; +case 0xd54 :/* MMFR1. */ +return cpu->isar.regs[ID_MMFR1 ]; +case 0xd58 :/* MMFR2. */ +return cpu->isar.regs[ID_MMFR2 ]; +case 0xd5c :/* MMFR3. */ +return cpu->isar.regs[ID_MMFR3 ]; +case 0xd60 :/* ISAR0. */ +return cpu->isar.regs[ID_ISAR0 ]; +case 0xd64 :/* ISAR1. */ +return cpu->isar.regs[ID_ISAR1 ]; +case 0xd68 :/* ISAR2. */ +return cpu->isar.regs[ID_ISAR2 ]; +case 0xd6c :/* ISAR3. */ +return cpu->isar.regs[ID_ISAR3 ]; +case 0xd70 :/* ISAR4. */ +return cpu->isar.regs[ID_ISAR4 ]; +case 0xd74 :/* ISAR5. */ +return cpu->isar.regs[ID_ISAR5 ];case 0xd78 :/* CLIDR */ return cpu->clidr;case 0xd7c :/* CTR */
@@ -1469,11 +1469,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 +117 -115
420 lines not on this page · raw message
target/arm/cpu.h +116 -110
583 lines not on this page · raw message
target/arm/cpu64.c +85 -85
275 lines not on this page · raw message
target/arm/cpu_tcg.c +127 -123
360 lines not on this page · raw message
target/arm/helper.c +27 -27
182 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 +37 -35
143 lines not on this page · raw message
Signature · 1 line
2.18.4
Re: [RFC 1/9] target/arm: convert isar regs to array
Quoted 9 lines · Peng Liang
The 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.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Peng Liang <[email protected]>
Quoted 10 lines
--- hw/intc/armv7m_nvic.c | 48 ++++---- target/arm/cpu.c | 232 +++++++++++++++++++------------------- target/arm/cpu.h | 226 +++++++++++++++++++------------------ target/arm/cpu64.c | 170 ++++++++++++++-------------- target/arm/cpu_tcg.c | 250 +++++++++++++++++++++-------------------- target/arm/helper.c | 54 ++++----- target/arm/internals.h | 15 +-- target/arm/kvm64.c | 72 ++++++------ 8 files changed, 541 insertions(+), 526 deletions(-)
Please consider using scripts/git.orderfile.
[...]
Quoted 27 lines
target/arm/cpu.h +19
-0@@ -67,6 +67,37 @@#define ARMV7M_EXCP_PENDSV 14#define ARMV7M_EXCP_SYSTICK 15 +typedef enum CPUIDReg { + MIDR_EL1, + ID_ISAR0, + ID_ISAR1, + ID_ISAR2, + ID_ISAR3, + ID_ISAR4, + ID_ISAR5, + ID_ISAR6, + ID_MMFR0, + ID_MMFR1, + ID_MMFR2, + ID_MMFR3, + ID_MMFR4, + ID_AA64ISAR0, + ID_AA64ISAR1, + ID_AA64PFR0, + ID_AA64PFR1, + ID_AA64MMFR0,
target/arm/cpu.h line 98
Quoted 10 lines
target/arm/cpu.h +10
-0+ID_AA64MMFR1 , +ID_AA64MMFR2 , +ID_AA64DFR0 , +ID_AA64DFR1 , +ID_DFR0 , +MVFR0 , +MVFR1 , +MVFR2 , +DBGDIDR , + ID_MAX,
(nitpicking, drop the last comma).
Quoted 27 lines
target/arm/cpu.h +2
-18+} CPUIDReg; +/* For M profile, some registers are banked secure vs non-secure; * these are represented as a 2-element array where the first element * is the non-secure copy and the second is the secure copy. @@ -890,32 +921,7 @@ struct ARMCPU {* field by reading the value from the KVM vCPU. */ struct ARMISARegisters { -uint32_t id_isar0; -uint32_t id_isar1; -uint32_t id_isar2; -uint32_t id_isar3; -uint32_t id_isar4; -uint32_t id_isar5; -uint32_t id_isar6; -uint32_t id_mmfr0; -uint32_t id_mmfr1; -uint32_t id_mmfr2; -uint32_t id_mmfr3; -uint32_t id_mmfr4; -uint32_t mvfr0; -uint32_t mvfr1; -uint32_t mvfr2; -uint32_t id_dfr0; -uint32_t dbgdidr; -uint64_t id_aa64isar0;
target/arm/cpu.h struct ARMCPU { · line 925
Quoted 10 lines
target/arm/cpu.h +1
-8-uint64_t id_aa64isar1; -uint64_t id_aa64pfr0; -uint64_t id_aa64pfr1; -uint64_t id_aa64mmfr0; -uint64_t id_aa64mmfr1; -uint64_t id_aa64mmfr2; -uint64_t id_aa64dfr0; -uint64_t id_aa64dfr1; +uint64_t regs[ID_MAX ]; } isar;
Why not simply this?
uint64_t isar[ID_MAX];
Quoted 2 lines
target/arm/cpu.h +0
-0uint64_t midr;uint32_t revidr;
[...]
Re: [RFC 1/9] target/arm: convert isar regs to array
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 19 lines
struct ARMISARegisters {target/arm/cpu.h +0
-18-uint32_t id_isar0; -uint32_t id_isar1; -uint32_t id_isar2; -uint32_t id_isar3; -uint32_t id_isar4; -uint32_t id_isar5; -uint32_t id_isar6; -uint32_t id_mmfr0; -uint32_t id_mmfr1; -uint32_t id_mmfr2; -uint32_t id_mmfr3; -uint32_t id_mmfr4; -uint32_t mvfr0; -uint32_t mvfr1; -uint32_t mvfr2; -uint32_t id_dfr0; -uint32_t dbgdidr; -uint64_t id_aa64isar0;target/arm/cpu.h struct ARMCPU { · line 925
Quoted 10 lines
target/arm/cpu.h +1
-8-uint64_t id_aa64isar1; -uint64_t id_aa64pfr0; -uint64_t id_aa64pfr1; -uint64_t id_aa64mmfr0; -uint64_t id_aa64mmfr1; -uint64_t id_aa64mmfr2; -uint64_t id_aa64dfr0; -uint64_t id_aa64dfr1; +uint64_t regs[ID_MAX ]; } isar;
Quoted 3 lines
Why not simply this?
uint64_t isar[ID_MAX];
Because the ARMISARegisters type is used elsewhere.
r~
RFC 2/9 target/arm: parse cpu feature related options
In reply to Peng LiangThe implementation of CPUClass::parse_features only supports CPU features in "feature=value" format. However, libvirt maybe send us a CPU feature string in "+feature/-feature" format. Hence, we need to override CPUClass::parse_features to support CPU feature string in both "feature=value" and "+feature/-feature" format.
The logic of AArch64CPUClass::parse_features is similar to that of X86CPUClass::parse_features. The diference is that feature name is transformed to upper before it's added as a property because the name of CPU features is upper for convenience.
--- target/arm/cpu64.c | 101 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+)
target/arm/cpu64.c +101 -0
@@ -28,6 +28,7 @@#include "sysemu/kvm.h" #include "kvm_arm.h" #include "qapi/visitor.h" +#include "hw/qdev-properties.h" #ifndef CONFIG_USER_ONLY static uint64_t a57_a53_l2ctlr_read (CPUARMState *env,const ARMCPRegInfo *ri)
@@ -778,6 +779,105 @@ static gchar *aarch64_gdb_arch_name(CPUState *cs)return g_strdup ("aarch64" ); } +static void +cpu_add_feat_as_prop (const char *typename,const char *name,const char *val) +{ +GlobalProperty *prop =g_new0 (typeof (*prop),1 ); + prop->driver = typename; + prop->property =g_strdup (name); + prop->value =g_strdup (val); +qdev_prop_register_global (prop); +} + +static gint compare_string (gconstpointer a,gconstpointer b) +{ +return g_strcmp0 (a, b); +} + +static GList *plus_features, *minus_features; + +static char *strtoupr (char *str) +{ +char *orign = str; + +for (; *str !='\0' ; str++) { + *str =toupper (*str); + } + +return orign; +} + +static void aarch64_cpu_parse_features (const char *typename,char *features, +Error **errp) +{ +GList *l; +char *featurestr;/* Single 'key=value" string being parsed */ +static bool cpu_globals_initialized; + +if (cpu_globals_initialized) { +return ; + } + cpu_globals_initialized = true; + +if (!features) { +return ; + } +for (featurestr =strtok (features,"," ); + featurestr; + featurestr =strtok (NULL ,"," )) { +const char *name; +char *tmp; +const char *val =NULL ; +char *eq =NULL ; + +/* Compatibility syntax: */ +if (featurestr[0 ] =='+' ) { + plus_features =g_list_append (plus_features, +g_strdup (featurestr +1 )); +continue ; + }else if (featurestr[0 ] =='-' ) { + minus_features =g_list_append (minus_features, +g_strdup (featurestr +1 )); +continue ; + } + + eq =strchr (featurestr,'=' ); + name = featurestr; +if (eq) { + *eq++ =0 ; + val = eq; + }else { +error_setg (errp,"Unsupported property format: %s" , name); +return ; + } + +if (g_list_find_custom (plus_features, name, compare_string)) { +warn_report ("Ambiguous CPU model string. " +"Don't mix both \"+%s\" and \"%s=%s\"" , + name, name, val); + } +if (g_list_find_custom (minus_features, name, compare_string)) { +warn_report ("Ambiguous CPU model string. " +"Don't mix both \"-%s\" and \"%s=%s\"" , + name, name, val); + } + tmp =g_strdup (name); + tmp =strtoupr (tmp); +cpu_add_feat_as_prop (typename, tmp, val); +g_free (tmp); + } + +for (l = plus_features; l; l = l->next) { +const char *name =strtoupr (l->data);/* convert to upper string */ +cpu_add_feat_as_prop (typename, name,"on" ); + } + +for (l = minus_features; l; l = l->next) { +const char *name =strtoupr (l->data); +cpu_add_feat_as_prop (typename, name,"off" ); + } +} +static void aarch64_cpu_class_init (ObjectClass *oc,void *data) {CPUClass *cc =CPU_CLASS (oc);
@@ -788,6 +888,7 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) cc->gdb_num_core_regs =34 ; cc->gdb_core_xml_file ="aarch64-core.xml" ; cc->gdb_arch_name = aarch64_gdb_arch_name; + cc->parse_features = aarch64_cpu_parse_features; }static void aarch64_cpu_instance_init (Object *obj)
Signature · 1 line
2.18.4
Re: [RFC 2/9] target/arm: parse cpu feature related options
Quoted 3 lines · Peng Liang
The implementation of
CPUClass::parse_featuresonly supports CPU features in "feature=value" format. However, libvirt maybe send us a CPU feature string in "+feature/-feature" format.
Why would libvirt do that? If we have a boolean feature, then I'd think libvirt should be capable of sending feature=on/off just as easily as a +/-feature. Indeed libvirt seems to do the right thing with all the CPU features we already have: pmu, sve*, ...
Thanks,
drew
Re: [RFC 2/9] target/arm: parse cpu feature related options
Quoted 10 lines · Andrew Jones
Quoted 3 lines · Peng Liang
The implementation of
CPUClass::parse_featuresonly supports CPU features in "feature=value" format. However, libvirt maybe send us a CPU feature string in "+feature/-feature" format.Why would libvirt do that? If we have a boolean feature, then I'd think libvirt should be capable of sending feature=on/off just as easily as a +/-feature. Indeed libvirt seems to do the right thing with all the CPU features we already have: pmu, sve*, ...
Quoted 5 lines
Thanks,
drew.
Libvirt before d47db7b16dd5422c7e487c8c8ee5b181a2f9cd66 ("qemu: command:
Support new cpu feature argument syntax") will send +/-feature. Does QEMU need to support it? If not, I'll remote it.
Thanks,
Peng
Re: [RFC 2/9] target/arm: parse cpu feature related options
Quoted 14 lines · Peng Liang
Quoted 13 lines · Andrew Jones
Quoted 3 lines · Peng Liang
The implementation of
CPUClass::parse_featuresonly supports CPU features in "feature=value" format. However, libvirt maybe send us a CPU feature string in "+feature/-feature" format.Why would libvirt do that? If we have a boolean feature, then I'd think libvirt should be capable of sending feature=on/off just as easily as a +/-feature. Indeed libvirt seems to do the right thing with all the CPU features we already have: pmu, sve*, ...
Thanks,
drew
Quoted 6 lines
Quoted 2 lines
.
Libvirt before
d47db7b16dd5422c7e487c8c8ee5b181a2f9cd66("qemu: command:
Support new cpu feature argument syntax") will send +/-feature. Does QEMU need to support it? If not, I'll remote it.
No, we don't need to support pre-2016 libvirt, at least not for ARM CPU features, because libvirt didn't start querying QEMU for ARM CPU features until just last year.
Thanks,
drew
RFC 3/9 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 | 343 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 343 insertions(+)
target/arm/cpu.c +343 -0
@@ -1146,6 +1146,348 @@ 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 (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 = #field, \ + .is_32bit = is32bit, \ +} + +static struct CPUFeatureInfo cpu_features[] = { +FIELD_INFO (ID_ISAR0 ,SWAP , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,BITCOUNT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,BITFIELD , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,CMPBRANCH , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,COPROC , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,DEBUG , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,DIVIDE , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR1 ,ENDIAN , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,EXCEPT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,EXCEPT_AR , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,EXTEND , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,IFTHEN , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,IMMEDIATE , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,INTERWORK , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,JAZELLE , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR2 ,LOADSTORE , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MEMHINT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MULTIACCESSINT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MULT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MULTS , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MULTU , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,PSR_AR , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,REVERSAL , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR3 ,SATURATE , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,SIMD , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,SVC , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,SYNCHPRIM , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,TABBRANCH , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,T32COPY , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,TRUENOP , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,T32EE , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR4 ,UNPRIV , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,WITHSHIFTS , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,WRITEBACK , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,SMC , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,BARRIER , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,SYNCHPRIM_FRAC , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,PSR_M , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,SWP_FRAC , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR5 ,SEVL , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,AES , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,SHA1 , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,SHA2 , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,CRC32 , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,RDM , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,VCMA , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR6 ,JSCVT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR6 ,DP , false,1 ,0 , true), +FIELD_INFO (ID_ISAR6 ,FHM , false,1 ,0 , true), +FIELD_INFO (ID_ISAR6 ,SB , false,1 ,0 , true), +FIELD_INFO (ID_ISAR6 ,SPECRES , false,1 ,0 , true), + +FIELD_INFO (ID_MMFR3 ,CMAINTVA , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,CMAINTSW , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,BPMAINT , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,MAINTBCST , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,PAN , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,COHWALK , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,CMEMSZ , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,SUPERSEC , false,1 ,0 , true), + +FIELD_INFO (ID_MMFR4 ,SPECSEI , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,AC2 , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,XNX , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,CNP , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,HPDS , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,LSM , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,CCIDX , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,EVT , false,1 ,0 , true), + +FIELD_INFO (MVFR0 ,SIMDREG , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPSP , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPDP , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPTRAP , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPDIVIDE , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPSQRT , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPSHVEC , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPROUND , false,1 ,0 , true), + +FIELD_INFO (MVFR1 ,FPFTZ , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,FPDNAN , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDLS , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDINT , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDSP , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDHP , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,FPHP , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDFMAC , false,1 ,0 , true), + +FIELD_INFO (MVFR2 ,SIMDMISC , false,1 ,0 , true), +FIELD_INFO (MVFR2 ,FPMISC , false,1 ,0 , true), + +FIELD_INFO (ID_DFR0 ,COPDBG , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,COPSDBG , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,MMAPDBG , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,COPTRC , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,MMAPTRC , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,MPROFDBG , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,PERFMON , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,TRACEFILT , false,1 ,0 , true), + +FIELD_INFO (ID_AA64ISAR0 ,AES , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SHA1 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SHA2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,CRC32 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,ATOMIC , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,RDM , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SHA3 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SM3 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SM4 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,DP , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,FHM , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,TS , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,TLB , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,RNDR , false,1 ,0 , false), + +FIELD_INFO (ID_AA64ISAR1 ,DPB , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,APA , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,API , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,JSCVT , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,FCMA , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,LRCPC , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,GPA , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,GPI , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,FRINTTS , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,SB , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,SPECRES , false,1 ,0 , false), + +FIELD_INFO (ID_AA64PFR0 ,EL0 , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,EL1 , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,EL2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,EL3 , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,FP , true,0 ,0xf , false), +FIELD_INFO (ID_AA64PFR0 ,ADVSIMD , true,0 ,0xf , false), +FIELD_INFO (ID_AA64PFR0 ,GIC , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,RAS , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,SVE , false,1 ,0 , false), + +FIELD_INFO (ID_AA64PFR1 ,BT , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR1 ,SBSS , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR1 ,MTE , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR1 ,RAS_FRAC , false,1 ,0 , false), + +FIELD_INFO (ID_AA64MMFR0 ,PARANGE , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,ASIDBITS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,BIGEND , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,SNSMEM , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,BIGENDEL0 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN16 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN64 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN4 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN16_2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN64_2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN4_2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,EXS , false,1 ,0 , false), + +FIELD_INFO (ID_AA64MMFR1 ,HAFDBS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,VMIDBITS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,VH , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,HPDS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,LO , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,PAN , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,SPECSEI , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,XNX , false,1 ,0 , false), + +FIELD_INFO (ID_AA64MMFR2 ,CNP , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,UAO , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,LSM , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,IESB , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,VARANGE , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,CCIDX , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,NV , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,ST , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,AT , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,IDS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,FWB , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,TTL , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,BBM , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,EVT , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,E0PD , false,1 ,0 , false), + +FIELD_INFO (ID_AA64DFR0 ,DEBUGVER , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,TRACEVER , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,PMUVER , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,BRPS , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,WRPS , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,CTX_CMPS , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,PMSVER , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,DOUBLELOCK , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,TRACEFILT , 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 ="ADVSIMDHP" , .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_bit_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_bit_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 (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) { + isar->regs[feat->reg] =deposit64 (isar->regs[feat->reg], + feat->shift, feat->length, + feat->min_value); + }else { + 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; +int num =sizeof (cpu_features) /sizeof (cpu_features[i]); +ObjectProperty *op; +CPUARMState *env = &cpu->env; + +for (i =0 ; i < num; i++) { +if ((arm_feature (env,ARM_FEATURE_AARCH64 ) && cpu_features[i].is_32bit) + || (!arm_feature (env,ARM_FEATURE_AARCH64 ) && + cpu_features[i].is_32bit)) { +continue ; + } + op =object_property_find (OBJECT (cpu), cpu_features[i].name,NULL ); +if (!op) { +error_report ("register name %s" , cpu_features[i].name); +object_property_add (OBJECT (cpu), cpu_features[i].name,"bool" , + arm_cpu_get_bit_prop, + arm_cpu_set_bit_prop, +NULL , &cpu_features[i]); + } + } +} +void arm_cpu_post_init (Object *obj) {ARMCPU *cpu =ARM_CPU (obj);
@@ -1271,6 +1613,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.18.4
Re: [RFC 3/9] target/arm: register CPU features for property
Quoted 365 lines · Peng Liang
The 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 ==
0x0represents the implementation of FP (floating-point) and ID_AA64PFR0_EL1.FP ==0x1represents the implementation of FPHP (half-precision floating-point). If ID_AA64PFR0_EL1.FP is set to0xfwhen FPHP is disabled (which is also disable FP), guest kernel maybe stuck. Hence, we add ani_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.0487Signed-off-by zhanghailiang <[email protected]>Signed-off-by Peng Liang <[email protected]>--- target/arm/cpu.c | 343 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 343 insertions(+)target/arm/cpu.c +328
-0@@ -1146,6 +1146,348 @@ 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 (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 = #field, \ + .is_32bit = is32bit, \ +} + +static struct CPUFeatureInfo cpu_features[] = { +FIELD_INFO (ID_ISAR0 ,SWAP , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,BITCOUNT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,BITFIELD , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,CMPBRANCH , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,COPROC , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,DEBUG , false,1 ,0 , true), +FIELD_INFO (ID_ISAR0 ,DIVIDE , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR1 ,ENDIAN , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,EXCEPT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,EXCEPT_AR , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,EXTEND , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,IFTHEN , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,IMMEDIATE , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,INTERWORK , false,1 ,0 , true), +FIELD_INFO (ID_ISAR1 ,JAZELLE , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR2 ,LOADSTORE , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MEMHINT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MULTIACCESSINT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MULT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MULTS , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,MULTU , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,PSR_AR , false,1 ,0 , true), +FIELD_INFO (ID_ISAR2 ,REVERSAL , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR3 ,SATURATE , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,SIMD , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,SVC , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,SYNCHPRIM , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,TABBRANCH , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,T32COPY , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,TRUENOP , false,1 ,0 , true), +FIELD_INFO (ID_ISAR3 ,T32EE , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR4 ,UNPRIV , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,WITHSHIFTS , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,WRITEBACK , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,SMC , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,BARRIER , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,SYNCHPRIM_FRAC , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,PSR_M , false,1 ,0 , true), +FIELD_INFO (ID_ISAR4 ,SWP_FRAC , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR5 ,SEVL , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,AES , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,SHA1 , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,SHA2 , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,CRC32 , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,RDM , false,1 ,0 , true), +FIELD_INFO (ID_ISAR5 ,VCMA , false,1 ,0 , true), + +FIELD_INFO (ID_ISAR6 ,JSCVT , false,1 ,0 , true), +FIELD_INFO (ID_ISAR6 ,DP , false,1 ,0 , true), +FIELD_INFO (ID_ISAR6 ,FHM , false,1 ,0 , true), +FIELD_INFO (ID_ISAR6 ,SB , false,1 ,0 , true), +FIELD_INFO (ID_ISAR6 ,SPECRES , false,1 ,0 , true), + +FIELD_INFO (ID_MMFR3 ,CMAINTVA , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,CMAINTSW , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,BPMAINT , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,MAINTBCST , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,PAN , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,COHWALK , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,CMEMSZ , false,1 ,0 , true), +FIELD_INFO (ID_MMFR3 ,SUPERSEC , false,1 ,0 , true), + +FIELD_INFO (ID_MMFR4 ,SPECSEI , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,AC2 , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,XNX , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,CNP , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,HPDS , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,LSM , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,CCIDX , false,1 ,0 , true), +FIELD_INFO (ID_MMFR4 ,EVT , false,1 ,0 , true), + +FIELD_INFO (MVFR0 ,SIMDREG , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPSP , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPDP , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPTRAP , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPDIVIDE , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPSQRT , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPSHVEC , false,1 ,0 , true), +FIELD_INFO (MVFR0 ,FPROUND , false,1 ,0 , true), + +FIELD_INFO (MVFR1 ,FPFTZ , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,FPDNAN , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDLS , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDINT , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDSP , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDHP , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,FPHP , false,1 ,0 , true), +FIELD_INFO (MVFR1 ,SIMDFMAC , false,1 ,0 , true), + +FIELD_INFO (MVFR2 ,SIMDMISC , false,1 ,0 , true), +FIELD_INFO (MVFR2 ,FPMISC , false,1 ,0 , true), + +FIELD_INFO (ID_DFR0 ,COPDBG , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,COPSDBG , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,MMAPDBG , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,COPTRC , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,MMAPTRC , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,MPROFDBG , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,PERFMON , false,1 ,0 , true), +FIELD_INFO (ID_DFR0 ,TRACEFILT , false,1 ,0 , true), + +FIELD_INFO (ID_AA64ISAR0 ,AES , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SHA1 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SHA2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,CRC32 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,ATOMIC , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,RDM , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SHA3 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SM3 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,SM4 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,DP , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,FHM , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,TS , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,TLB , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR0 ,RNDR , false,1 ,0 , false), + +FIELD_INFO (ID_AA64ISAR1 ,DPB , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,APA , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,API , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,JSCVT , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,FCMA , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,LRCPC , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,GPA , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,GPI , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,FRINTTS , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,SB , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,SPECRES , false,1 ,0 , false), + +FIELD_INFO (ID_AA64PFR0 ,EL0 , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,EL1 , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,EL2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,EL3 , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,FP , true,0 ,0xf , false), +FIELD_INFO (ID_AA64PFR0 ,ADVSIMD , true,0 ,0xf , false), +FIELD_INFO (ID_AA64PFR0 ,GIC , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,RAS , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR0 ,SVE , false,1 ,0 , false), + +FIELD_INFO (ID_AA64PFR1 ,BT , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR1 ,SBSS , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR1 ,MTE , false,1 ,0 , false), +FIELD_INFO (ID_AA64PFR1 ,RAS_FRAC , false,1 ,0 , false), + +FIELD_INFO (ID_AA64MMFR0 ,PARANGE , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,ASIDBITS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,BIGEND , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,SNSMEM , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,BIGENDEL0 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN16 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN64 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN4 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN16_2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN64_2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,TGRAN4_2 , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR0 ,EXS , false,1 ,0 , false), + +FIELD_INFO (ID_AA64MMFR1 ,HAFDBS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,VMIDBITS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,VH , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,HPDS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,LO , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,PAN , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,SPECSEI , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR1 ,XNX , false,1 ,0 , false), + +FIELD_INFO (ID_AA64MMFR2 ,CNP , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,UAO , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,LSM , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,IESB , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,VARANGE , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,CCIDX , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,NV , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,ST , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,AT , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,IDS , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,FWB , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,TTL , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,BBM , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,EVT , false,1 ,0 , false), +FIELD_INFO (ID_AA64MMFR2 ,E0PD , false,1 ,0 , false), + +FIELD_INFO (ID_AA64DFR0 ,DEBUGVER , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,TRACEVER , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,PMUVER , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,BRPS , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,WRPS , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,CTX_CMPS , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,PMSVER , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,DOUBLELOCK , false,1 ,0 , false), +FIELD_INFO (ID_AA64DFR0 ,TRACEFILT , 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 ="ADVSIMDHP" , .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_bit_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_bit_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 (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) { + isar->regs[feat->reg] =deposit64 (isar->regs[feat->reg], + feat->shift, feat->length, + feat->min_value); + }else { + 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; +int num =sizeof (cpu_features) /sizeof (cpu_features[i]); +ObjectProperty *op; +CPUARMState *env = &cpu->env; + +for (i =0 ; i < num; i++) { + if ((arm_feature(env, ARM_FEATURE_AARCH64) && cpu_features[i].is_32bit) + || (!arm_feature(env, ARM_FEATURE_AARCH64) &&
target/arm/cpu.c unsigned int gt_cntfrq_period_ns(ARMCPU *cpu) · line 1486
Quoted 10 lines
target/arm/cpu.c +10
-0+ cpu_features[i].is_32bit)) { +continue ; + } + op =object_property_find (OBJECT (cpu), cpu_features[i].name,NULL ); +if (!op) { +error_report ("register name %s" , cpu_features[i].name); +object_property_add (OBJECT (cpu), cpu_features[i].name,"bool" , + arm_cpu_get_bit_prop, + arm_cpu_set_bit_prop, +NULL , &cpu_features[i]);
So we're adding properties for every CPU feature? How many of these make sense for the user to change? What happens when a user selects an invalid combination?
Thanks,
drew
Quoted 18 lines
target/arm/cpu.c +5
-0+ } + } +} +void arm_cpu_post_init (Object *obj) {ARMCPU *cpu =ARM_CPU (obj);@@ -1271,6 +1613,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.18.4
RFC 4/9 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 | 31 ++++++++++++++++++++----------- target/arm/kvm.c | 38 ++++++++++++++++++++++++++++++++++++++ target/arm/kvm_arm.h | 3 +++ 3 files changed, 61 insertions(+), 11 deletions(-)
target/arm/helper.c +20 -11
@@ -34,6 +34,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 */
@@ -369,30 +370,38 @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync) ok = false;continue ; } -if (ri->type &ARM_CP_NO_RAW ) { +/* +* (Op0, Op1, CRn, CRm, Op2) of ID registers is (3, 0, 0, crm, op2), +* where 1<=crm<8, 0<=op2<8. Let's give ID registers a chance to +* synchronize to kvm. +*/ +if ((ri->type &ARM_CP_NO_RAW ) && !(kvm_sync && + ri->opc0 ==3 && ri->opc1 ==0 && ri->crn ==0 && ri->crm >0 )) {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)) { +continue ; + } +if (kvm_arm_get_one_reg (cpu, cpu->cpreg_indexes[i], &kvmval) || + kvmval != newval) {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
@@ -490,6 +490,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
@@ -478,4 +478,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.18.4
RFC 5/9 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, b, and c CPU features are in relationship a->b->c, which means c is dependent on b and b is dependent on a. If c is enabled by user, then a and b is enabled automatically. And if a is disabled by user, then b and c is disabled automatically.
--- target/arm/cpu.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+)
target/arm/cpu.c +129 -0
@@ -1418,6 +1418,103 @@ static struct CPUFeatureInfo cpu_features[] = { }, }; +typedef struct CPUFeatureDep { +CPUFeatureInfo from, to; +}CPUFeatureDep ; + +static const CPUFeatureDep feature_dependencies[] = { + { + .from =FIELD_INFO (ID_AA64PFR0 ,FP , true,0 ,0xf , false), + .to =FIELD_INFO (ID_AA64PFR0 ,ADVSIMD , true,0 ,0xf , false), + }, + { + .from =FIELD_INFO (ID_AA64PFR0 ,ADVSIMD , true,0 ,0xf , false), + .to =FIELD_INFO (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 ="ADVSIMDHP" , .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 ="ADVSIMDHP" , .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 (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 (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 (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 (ID_AA64ISAR0 ,SM3 , false,1 ,0 , false), + .to =FIELD_INFO (ID_AA64ISAR0 ,SM4 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO (ID_AA64ISAR0 ,SM4 , false,1 ,0 , false), + .to =FIELD_INFO (ID_AA64ISAR0 ,SM3 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO (ID_AA64ISAR0 ,SHA1 , false,1 ,0 , false), + .to =FIELD_INFO (ID_AA64ISAR0 ,SHA2 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO (ID_AA64ISAR0 ,SHA1 , false,1 ,0 , false), + .to =FIELD_INFO (ID_AA64ISAR0 ,SHA3 , false,1 ,0 , false), + }, + { + .from =FIELD_INFO (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 (ID_AA64ISAR0 ,SHA3 , false,1 ,0 , false), + }, +}; +static void arm_cpu_get_bit_prop (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -1454,13 +1551,45 @@ static void arm_cpu_set_bit_prop(Object *obj, Visitor *v, const char *name, }if (value) { +if (object_property_get_bool (obj, feat->name,NULL )) { +return ; + } isar->regs[feat->reg] =deposit64 (isar->regs[feat->reg], feat->shift, feat->length, feat->min_value); +/* Auto enable the features which current feature is dependent on. */ +for (int i =0 ; i <ARRAY_SIZE (feature_dependencies); ++i) { +const CPUFeatureDep *d = &feature_dependencies[i]; +if (strcmp (d->to.name, feat->name) !=0 ) { +continue ; + } + +object_property_set_bool (obj, d->from.name, true, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } }else { +if (!object_property_get_bool (obj, feat->name,NULL )) { +return ; + } isar->regs[feat->reg] =deposit64 (isar->regs[feat->reg], feat->shift, feat->length, feat->ni_value); +/* Auto disable the features which are dependent on current feature. */ +for (int i =0 ; i <ARRAY_SIZE (feature_dependencies); ++i) { +const CPUFeatureDep *d = &feature_dependencies[i]; +if (strcmp (d->from.name, feat->name) !=0 ) { +continue ; + } + +object_property_set_bool (obj, d->to.name, false, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } } }
Signature · 1 line
2.18.4
Re: [RFC 5/9] target/arm: introduce CPU feature dependency mechanism
Quoted 11 lines · Peng Liang
Some 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->tomeans thetoCPU feature is dependent on thefromCPU feature. And we will automatically enable/disable CPU feature according to the directed graph.
Quoted 4 lines
For example, a, b, and c CPU features are in relationship
a->b->c, which means c is dependent on b and b is dependent on a. If c is enabled by user, then a and b is enabled automatically. And if a is disabled by user, then b and c is disabled automatically.
And what if a is mutually exclusive with b? I.e. a and b can both be disabled, but only a or b may be enabled.
Thanks,
drew
Re: [RFC 5/9] target/arm: introduce CPU feature dependency mechanism
Quoted 17 lines · Andrew Jones
Quoted 11 lines · Peng Liang
Some 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->tomeans thetoCPU feature is dependent on thefromCPU feature. And we will automatically enable/disable CPU feature according to the directed graph.Quoted 4 lines
For example, a, b, and c CPU features are in relationship
a->b->c, which means c is dependent on b and b is dependent on a. If c is enabled by user, then a and b is enabled automatically. And if a is disabled by user, then b and c is disabled automatically.
Quoted 8 lines
And what if a is mutually exclusive with b? I.e. a and b can both be disabled, but only a or b may be enabled.
Thanks,
drew.
Currently, a and b will be both enabled or disabled. For example, a and b are in relationship a->b, which means b is dependent on a. If -cpu host,a=off,b=on, then both a and b are enabled. If -cpu host,b=on,a=off, then both a and b are disabled. Maybe we should report an error to user in this scenario?
Thanks,
Peng
Re: [RFC 5/9] target/arm: introduce CPU feature dependency mechanism
Quoted 24 lines · Peng Liang
Quoted 23 lines · Andrew Jones
Quoted 11 lines · Peng Liang
Some 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->tomeans thetoCPU feature is dependent on thefromCPU feature. And we will automatically enable/disable CPU feature according to the directed graph.Quoted 4 lines
For example, a, b, and c CPU features are in relationship
a->b->c, which means c is dependent on b and b is dependent on a. If c is enabled by user, then a and b is enabled automatically. And if a is disabled by user, then b and c is disabled automatically.And what if a is mutually exclusive with b? I.e. a and b can both be disabled, but only a or b may be enabled.
Thanks,
drew
Quoted 8 lines
Quoted 2 lines
.
Currently, a and b will be both enabled or disabled. For example, a and b are in relationship
a->b, which means b is dependent on a. If -cpu host,a=off,b=on, then both a and b are enabled. If -cpu host,b=on,a=off, then both a and b are disabled. Maybe we should report an error to user in this scenario?
Right. There are more relationships between features than "depends on", such as "only if not" or "only if value is". The last one points out that just setting the minimum feature value may not be sufficient to control all the features. Also, there could be relationships involving more than two features, such as 'a iff b and c', or 'a iff b and !c'.
We really have to take each feature of each ID register one at a time to make sure we handle them appropriately. Exposing them all like this without any checks just pushes all the pain onto the user to figure everything out, and if there's not even errors generated, then how will the user know when they got something wrong until their guest breaks in some mysterious way?
Thanks,
drew
RFC 6/9 target/arm: introduce KVM_CAP_ARM_CPU_FEATURE
In reply to Peng LiangIntroduce KVM_CAP_ARM_CPU_FEATURE to check whether KVM supports to set CPU features in ARM.
--- linux-headers/linux/kvm.h | 1 + target/arm/cpu.c | 5 +++++ target/arm/kvm64.c | 14 ++++++++++++++ target/arm/kvm_arm.h | 7 +++++++ 4 files changed, 27 insertions(+)
linux-headers/linux/kvm.h +1 -0
@@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_PPC_SECURE_GUEST 181#define KVM_CAP_HALT_POLL 182#define KVM_CAP_ASYNC_PF_INT 183 +#define KVM_CAP_ARM_CPU_FEATURE 187#ifdef KVM_CAP_IRQ_ROUTING
target/arm/cpu.c +5 -0
@@ -1539,6 +1539,11 @@ static void arm_cpu_set_bit_prop(Object *obj, Visitor *v, const char *name,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 ;
target/arm/kvm64.c +14 -0
@@ -664,6 +664,20 @@ bool kvm_arm_sve_supported(void)return kvm_check_extension (kvm_state,KVM_CAP_ARM_SVE ); } +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
@@ -290,6 +290,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.18.4
Re: [RFC 6/9] target/arm: introduce KVM_CAP_ARM_CPU_FEATURE
Quoted 17 lines · On Thu, 13 Aug 2020 18:26:54 +0800 Peng Liang <[email protected]> wrote:
Introduce
KVM_CAP_ARM_CPU_FEATUREto check whether KVM supports to set CPU features in ARM.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Peng Liang <[email protected]>--- linux-headers/linux/kvm.h | 1 + target/arm/cpu.c | 5 +++++ target/arm/kvm64.c | 14 ++++++++++++++ target/arm/kvm_arm.h | 7 +++++++ 4 files changed, 27 insertions(+)linux-headers/linux/kvm.h +0
-0
linux-headers/linux/kvm.h struct kvm_ppc_resize_hpt { · line 1036
Quoted 6 lines
linux-headers/linux/kvm.h +1
-0@@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_PPC_SECURE_GUEST 181#define KVM_CAP_HALT_POLL 182#define KVM_CAP_ASYNC_PF_INT 183 +#define KVM_CAP_ARM_CPU_FEATURE 187#ifdef KVM_CAP_IRQ_ROUTING
Please split out this header update into a separate patch so that it can be replaced by a proper headers update once the kernel code has been included.
Re: [RFC 6/9] target/arm: introduce KVM_CAP_ARM_CPU_FEATURE
Quoted 25 lines · Cornelia Huck
Quoted 22 lines · On Thu, 13 Aug 2020 18:26:54 +0800 Peng Liang <[email protected]> wrote:
Introduce
KVM_CAP_ARM_CPU_FEATUREto check whether KVM supports to set CPU features in ARM.Signed-off-by zhanghailiang <[email protected]>Signed-off-by Peng Liang <[email protected]>--- linux-headers/linux/kvm.h | 1 + target/arm/cpu.c | 5 +++++ target/arm/kvm64.c | 14 ++++++++++++++ target/arm/kvm_arm.h | 7 +++++++ 4 files changed, 27 insertions(+)linux-headers/linux/kvm.h +1
-0@@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_PPC_SECURE_GUEST 181#define KVM_CAP_HALT_POLL 182#define KVM_CAP_ASYNC_PF_INT 183 +#define KVM_CAP_ARM_CPU_FEATURE 187
Quoted 8 lines
linux-headers/linux/kvm.h struct kvm_ppc_resize_hpt { · line 1036
Quoted 1 line
linux-headers/linux/kvm.h +0
-0#ifdef KVM_CAP_IRQ_ROUTING Please split out this header update into a separate patch so that it can be replaced by a proper headers update once the kernel code has been included.
.
Sorry, I'll split out it.
RFC 7/9 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/cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++ target/arm/cpu.h | 2 ++ target/arm/monitor.c | 2 ++ 3 files changed, 45 insertions(+)
target/arm/cpu.c +41 -0
@@ -25,6 +25,8 @@#include "qemu/module.h" #include "qapi/error.h" #include "qapi/visitor.h" +#include "qapi/qmp/qdict.h" +#include "qom/qom-qobject.h" #include "cpu.h" #include "internals.h" #include "exec/exec-all.h"
@@ -1515,6 +1517,45 @@ static const CPUFeatureDep feature_dependencies[] = { }, }; +static char *strtolower (char *src) +{ +char *start = src; + +for (; *src; ++src) { + *src =tolower (*src); + } + +return start; +} + +void arm_cpu_features_to_dict (ARMCPU *cpu,QDict *features) +{ +Object *obj =OBJECT (cpu); +const char *name; +ObjectProperty *prop; +bool is_32bit = !arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ); +int i; + +for (i =0 ; i <ARRAY_SIZE (cpu_features); ++i) { +if (is_32bit != cpu_features[i].is_32bit) { +continue ; + } + + name = cpu_features[i].name; + prop =object_property_find (obj, name,NULL ); +if (prop) { +QObject *value; + g_autofree char *tmp; + +assert (prop->get); + value =object_property_get_qobject (obj, name, &error_abort); + tmp =strtolower (g_strdup (name)); + +qdict_put_obj (features, tmp, value); + } + } +} +static void arm_cpu_get_bit_prop (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
target/arm/cpu.h +2 -0
@@ -3933,4 +3933,6 @@ static inline bool isar_feature_any_tts2uxn(const ARMISARegisters *id)#define cpu_isar_feature (name, cpu) \ ({ ARMCPU *cpu_ = (cpu); isar_feature_##name(&cpu_->isar); }) +void arm_cpu_features_to_dict (ARMCPU *cpu,QDict *features); +#endif
target/arm/monitor.c +2 -0
@@ -225,6 +225,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, } } +arm_cpu_features_to_dict (ARM_CPU (obj), qdict_out); +if (!qdict_size (qdict_out)) {qobject_unref (qdict_out); }else {
Signature · 1 line
2.18.4
Re: [RFC 7/9] target/arm: Add CPU features to query-cpu-model-expansion
Quoted 29 lines · Peng Liang
Add CPU features to the result of query-cpu-model-expansion so that other applications (such as libvirt) can know the supported CPU features.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Peng Liang <[email protected]>--- target/arm/cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++ target/arm/cpu.h | 2 ++ target/arm/monitor.c | 2 ++ 3 files changed, 45 insertions(+)target/arm/cpu.c +2
-0@@ -25,6 +25,8 @@#include "qemu/module.h" #include "qapi/error.h" #include "qapi/visitor.h" +#include "qapi/qmp/qdict.h" +#include "qom/qom-qobject.h" #include "cpu.h" #include "internals.h" #include "exec/exec-all.h" @@ -1515,6 +1517,45 @@ static const CPUFeatureDep feature_dependencies[] = { }, };
target/arm/cpu.c static const CPUFeatureDep feature_dependencies[] = { · line 1529
Quoted 10 lines
target/arm/cpu.c +10
-0+static char *strtolower (char *src) +{ +char *start = src; + +for (; *src; ++src) { + *src =tolower (*src); + } + +return start; +}
Shouldn't need this. The CPU property names should already be lowercase.
Quoted 48 lines
target/arm/cpu.c +29
-0+ +void arm_cpu_features_to_dict (ARMCPU *cpu,QDict *features) +{ +Object *obj =OBJECT (cpu); +const char *name; +ObjectProperty *prop; +bool is_32bit = !arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ); +int i; + +for (i =0 ; i <ARRAY_SIZE (cpu_features); ++i) { +if (is_32bit != cpu_features[i].is_32bit) { +continue ; + } + + name = cpu_features[i].name; + prop =object_property_find (obj, name,NULL ); +if (prop) { +QObject *value; + g_autofree char *tmp; + +assert (prop->get); + value =object_property_get_qobject (obj, name, &error_abort); + tmp =strtolower (g_strdup (name)); + +qdict_put_obj (features, tmp, value); + } + } +} +static void arm_cpu_get_bit_prop (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {target/arm/cpu.h +2
-0@@ -3933,4 +3933,6 @@ static inline bool isar_feature_any_tts2uxn(const ARMISARegisters *id)#define cpu_isar_feature (name, cpu) \ ({ ARMCPU *cpu_ = (cpu); isar_feature_##name(&cpu_->isar); }) +void arm_cpu_features_to_dict (ARMCPU *cpu,QDict *features); +#endif target/arm/monitor.c +0
-0
target/arm/monitor.c CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, · line 228
Quoted 4 lines
target/arm/monitor.c +1
-0@@ -225,6 +225,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, } } +arm_cpu_features_to_dict (ARM_CPU (obj), qdict_out);
Since nobody is looking for these features in qdict_in, then none of these features can be changed by QMP user. How does the QMP user probe whether or not the feature will work when enabled?
Thanks,
drew
Quoted 7 lines
target/arm/monitor.c +1
-0+if (!qdict_size (qdict_out)) {qobject_unref (qdict_out); }else {Signature · 1 line
2.18.4
Re: [RFC 7/9] target/arm: Add CPU features to query-cpu-model-expansion
Quoted 30 lines · Andrew Jones
Quoted 29 lines · Peng Liang
Add CPU features to the result of query-cpu-model-expansion so that other applications (such as libvirt) can know the supported CPU features.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Peng Liang <[email protected]>--- target/arm/cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++ target/arm/cpu.h | 2 ++ target/arm/monitor.c | 2 ++ 3 files changed, 45 insertions(+)target/arm/cpu.c +2
-0@@ -25,6 +25,8 @@#include "qemu/module.h" #include "qapi/error.h" #include "qapi/visitor.h" +#include "qapi/qmp/qdict.h" +#include "qom/qom-qobject.h" #include "cpu.h" #include "internals.h" #include "exec/exec-all.h" @@ -1515,6 +1517,45 @@ static const CPUFeatureDep feature_dependencies[] = { }, };
Quoted 13 lines
target/arm/cpu.c static const CPUFeatureDep feature_dependencies[] = { · line 1529
Quoted 10 lines
target/arm/cpu.c +10
-0+static char *strtolower (char *src) +{ +char *start = src; + +for (; *src; ++src) { + *src =tolower (*src); + } + +return start; +}Shouldn't need this. The CPU property names should already be lowercase.
For convenience, we use the field part defined in FIELD macro as the name of a CPU feature. So, the names of CPU features are upper...
Quoted 51 lines
Quoted 51 lines
target/arm/cpu.c +29
-0+ +void arm_cpu_features_to_dict (ARMCPU *cpu,QDict *features) +{ +Object *obj =OBJECT (cpu); +const char *name; +ObjectProperty *prop; +bool is_32bit = !arm_feature (&cpu->env,ARM_FEATURE_AARCH64 ); +int i; + +for (i =0 ; i <ARRAY_SIZE (cpu_features); ++i) { +if (is_32bit != cpu_features[i].is_32bit) { +continue ; + } + + name = cpu_features[i].name; + prop =object_property_find (obj, name,NULL ); +if (prop) { +QObject *value; + g_autofree char *tmp; + +assert (prop->get); + value =object_property_get_qobject (obj, name, &error_abort); + tmp =strtolower (g_strdup (name)); + +qdict_put_obj (features, tmp, value); + } + } +} +static void arm_cpu_get_bit_prop (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {target/arm/cpu.h +2
-0@@ -3933,4 +3933,6 @@ static inline bool isar_feature_any_tts2uxn(const ARMISARegisters *id)#define cpu_isar_feature (name, cpu) \ ({ ARMCPU *cpu_ = (cpu); isar_feature_##name(&cpu_->isar); }) +void arm_cpu_features_to_dict (ARMCPU *cpu,QDict *features); +#endif target/arm/monitor.c +0
-0@@ -225,6 +225,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, } }
Quoted 9 lines
target/arm/monitor.c CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, · line 228
Quoted 1 line
target/arm/monitor.c +1
-0+arm_cpu_features_to_dict (ARM_CPU (obj), qdict_out);Since nobody is looking for these features in
qdict_in, then none of these features can be changed by QMP user. How does the QMP user probe whether or not the feature will work when enabled?Thanks,
drew
My fault, I'll correct it.
Thanks,
Peng
Quoted 10 lines
Quoted 7 lines
target/arm/monitor.c +1
-0+if (!qdict_size (qdict_out)) {qobject_unref (qdict_out); }else {Signature · 1 line
2.18.4.
Re: [RFC 7/9] target/arm: Add CPU features to query-cpu-model-expansion
Quoted 45 lines · Peng Liang
Quoted 30 lines · Andrew Jones
Quoted 29 lines · Peng Liang
Add CPU features to the result of query-cpu-model-expansion so that other applications (such as libvirt) can know the supported CPU features.
Signed-off-by zhanghailiang <[email protected]>Signed-off-by Peng Liang <[email protected]>--- target/arm/cpu.c | 41 +++++++++++++++++++++++++++++++++++++++++ target/arm/cpu.h | 2 ++ target/arm/monitor.c | 2 ++ 3 files changed, 45 insertions(+)target/arm/cpu.c +2
-0@@ -25,6 +25,8 @@#include "qemu/module.h" #include "qapi/error.h" #include "qapi/visitor.h" +#include "qapi/qmp/qdict.h" +#include "qom/qom-qobject.h" #include "cpu.h" #include "internals.h" #include "exec/exec-all.h" @@ -1515,6 +1517,45 @@ static const CPUFeatureDep feature_dependencies[] = { }, };Quoted 13 lines
target/arm/cpu.c static const CPUFeatureDep feature_dependencies[] = { · line 1529
Quoted 10 lines
target/arm/cpu.c +10
-0+static char *strtolower (char *src) +{ +char *start = src; + +for (; *src; ++src) { + *src =tolower (*src); + } + +return start; +}Shouldn't need this. The CPU property names should already be lowercase.
Quoted 2 lines
For convenience, we use the field part defined in FIELD macro as the name of a CPU feature. So, the names of CPU features are upper...
But then the command line requires capital letters for property names, which isn't very convenient to the user. The field names could be converted to lowercase when generating the property names.
Thanks,
drew
RFC 8/9 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
@@ -1773,6 +1773,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_MMFR3, CMAINTVA, 0, 4)FIELD (ID_MMFR3 ,CMAINTSW ,4 ,4 )
@@ -1818,6 +1820,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 )
@@ -1828,11 +1833,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 )
@@ -1846,6 +1858,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 )
@@ -1855,6 +1869,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 )
@@ -1881,6 +1897,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.18.4
RFC 9/9 target/arm: Add more CPU features
In reply to Peng LiangAdd i8mm, bf16, and dgh CPU features for AArch64.
--- target/arm/cpu.c | 3 +++ 1 file changed, 3 insertions(+)
target/arm/cpu.c +3 -0
@@ -1319,6 +1319,9 @@ static struct CPUFeatureInfo cpu_features[] = {FIELD_INFO (ID_AA64ISAR1 ,FRINTTS , false,1 ,0 , false),FIELD_INFO (ID_AA64ISAR1 ,SB , false,1 ,0 , false),FIELD_INFO (ID_AA64ISAR1 ,SPECRES , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,I8MM , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,BF16 , false,1 ,0 , false), +FIELD_INFO (ID_AA64ISAR1 ,DGH , false,1 ,0 , false),FIELD_INFO (ID_AA64PFR0 ,EL0 , false,1 ,0 , false), FIELD_INFO(ID_AA64PFR0, EL1, false, 1, 0, false),
Signature · 1 line
2.18.4
Quoted 1 line · Peng Liang
QEMU does not support disable/enable CPU features in AArch64 for now.
Yes, it does. We have a handful of CPU features implemented as CPU properties and we have QMP support for probing those features and testing whether they may be enabled or disabled.
Quoted 1 line
This patch series add support for CPU features in AArch64.
Actually, it just adds all possible features as properties without considering if those features make sense to expose to users and without considering all invalid configurations. That's not a great approach.
We should try to tackle migration between non-identical hosts, but not by dumping all the burden of determining a functional configuration on the user. Instead, I think we need to audit what we're currently exposing to guests from KVM. If there are CPU features that make sense for the user to control, then we can do so using patterns for other CPU features that are already under user control. If there are other ID register bits that we should be masking/adjusting, then we can make those changes too. IOW, let's take this one ID register at a time. Eventually, we'll come to the real crux, which is MIDR. We need to provide a guest an MIDR that allows it to migrate between hosts with different MIDRs. That'll likely open the errata can of worms.
Thanks,
drew
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [RFC 0/9] Support disable/enable CPU features for AArch64
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Switched to a new branch 'test'
155e490 target/arm: Add more CPU features
5564d59 target/arm: Update ID fields
2f12ecd target/arm: Add CPU features to query-cpu-model-expansion 0911682 target/arm: introduce KVM_CAP_ARM_CPU_FEATURE 9dddca9 target/arm: introduce CPU feature dependency mechanism 89874bb target/arm: Allow ID registers to synchronize to KVM 8286a4a target/arm: register CPU features for property 7101c88 target/arm: parse cpu feature related options 56111cc target/arm: convert isar regs to array
=== OUTPUT BEGIN ===
1/9 Checking commit 56111cc30af0 (target/arm: convert isar regs to array) 2/9 Checking commit 7101c885db04 (target/arm: parse cpu feature related options)
ERROR: consider using qemu_strtoupr in preference to strtoupr
#55: FILE: target/arm/cpu64.c:799:
+static char *strtoupr(char *str)
ERROR: consider using qemu_strtoupr in preference to strtoupr #121: FILE: target/arm/cpu64.c:865:
+ tmp = strtoupr(tmp);
ERROR: consider using qemu_strtoupr in preference to strtoupr #127: FILE: target/arm/cpu64.c:871:
+ const char *name = strtoupr(l->data); /* convert to upper string */
ERROR: consider using qemu_strtoupr in preference to strtoupr #132: FILE: target/arm/cpu64.c:876:
+ const char *name = strtoupr(l->data);
total: 4 errors, 0 warnings, 119 lines checked
Patch 2/9 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
3/9 Checking commit 8286a4a789ed (target/arm: register CPU features for property) 4/9 Checking commit 89874bbdfd8e (target/arm: Allow ID registers to synchronize to KVM) 5/9 Checking commit 9dddca93c5b1 (target/arm: introduce CPU feature dependency mechanism) 6/9 Checking commit 091168210d47 (target/arm: introduce KVM_CAP_ARM_CPU_FEATURE) 7/9 Checking commit 2f12ecd63d30 (target/arm: Add CPU features to query-cpu-model-expansion)
ERROR: consider using qemu_strtolower in preference to strtolower
#32: FILE: target/arm/cpu.c:1520:
+static char *strtolower(char *src)
ERROR: consider using qemu_strtolower in preference to strtolower #64: FILE: target/arm/cpu.c:1552:
+ tmp = strtolower(g_strdup(name));
total: 2 errors, 0 warnings, 67 lines checked
Patch 7/9 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
8/9 Checking commit 5564d59a9ee0 (target/arm: Update ID fields) 9/9 Checking commit 155e490920e3 (target/arm: Add more CPU features) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===
CC aarch64-softmmu/target/arm/translate-a64.o
CC aarch64-softmmu/target/arm/helper-a64.o/tmp/qemu-test/src/target/arm/cpu.c: In function 'arm_cpu_set_bit_prop':/tmp/qemu-test/src/target/arm/cpu.c:1586:10: error: implicit declaration of function 'kvm_arm_cpu_feature_supported'; did you mean 'kvm_arm_pmu_supported'? [-Werror=implicit-function-declaration]
1586 | if (!kvm_arm_cpu_feature_supported()) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| kvm_arm_pmu_supported/tmp/qemu-test/src/target/arm/cpu.c:1586:10: error: nested extern declaration of 'kvm_arm_cpu_feature_supported' [-Werror=nested-externs]
cc1: all warnings being treated as errors
make[1]: *** [/tmp/qemu-test/src/rules.mak:69: target/arm/cpu.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:527: aarch64-softmmu/all] Error 2
Traceback (most recent call last):
File "./tests/docker/docker.py", line 709, in <module>
sys.exit(main())
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=82498ab48b9d4e83a6e3d551852f7ce7', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-05puycro/src/docker-src.2020-08-13-12.30.55.30563:/var/tmp/qemu:z,ro', 'qemu/fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=82498ab48b9d4e83a6e3d551852f7ce7
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-05puycro/src'
make: *** [docker-run-test-mingw@fedora] Error 2
real 3m42.997s
user 0m9.285s
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===
CC aarch64-softmmu/target/arm/gdbstub64.o
CC aarch64-softmmu/target/arm/machine.o/tmp/qemu-test/src/target/arm/cpu.c: In function 'arm_cpu_set_bit_prop':/tmp/qemu-test/src/target/arm/cpu.c:1586:5: error: implicit declaration of function 'kvm_arm_cpu_feature_supported' [-Werror=implicit-function-declaration]
if (!kvm_arm_cpu_feature_supported()) {
^
/tmp/qemu-test/src/target/arm/cpu.c:1586:5: error: nested extern declaration of 'kvm_arm_cpu_feature_supported' [-Werror=nested-externs]
cc1: all warnings being treated as errors
CC aarch64-softmmu/target/arm/arch_dump.o
CC aarch64-softmmu/target/arm/monitor.o
CC aarch64-softmmu/target/arm/arm-powerctl.omake[1]: *** [target/arm/cpu.o] Error 1
make[1]: *** Waiting for unfinished jobs....
CC aarch64-softmmu/target/arm/kvm-stub.o
make: *** [aarch64-softmmu/all] Error 2
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 709, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=66c80c872bf54d5084de54fbccc4353c', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-xzm_l9kf/src/docker-src.2020-08-13-12.35.23.5519:/var/tmp/qemu:z,ro', 'qemu/centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=66c80c872bf54d5084de54fbccc4353c
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-xzm_l9kf/src'
make: *** [docker-run-test-quick@centos7] Error 2
real 3m15.003s
user 0m8.959s
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]