Skip to contentSkip to conversation

kvm/arm: Introduce a customizable aarch64 KVM host model

RFC PATCH Superseded Eric Auger 4 participants 55 messages Jul 26 – Aug 27 Page 2 of 2

Subsystems (2)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#41 lore raw

Re: [RFC PATCH v7 18/18] arm-qmp-cmds: introspection for ID register props

In reply to Eric Auger
Quoted 26 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

From: Cornelia Huck <[email protected]>

Implement the capability to query available ID register values by adding SYSREG_* options and values to the cpu model expansion for the host model, if available.

Excerpt:
(QEMU) query-cpu-model-expansion type=full model={"name":"host"} {"return": {"model": {"name": "host", "props": {"SYSREG_ID_AA64PFR0_EL1_EL3": 1, "SYSREG_ID_AA64ISAR2_EL1_CLRBHB": 0, "SYSREG_CTR_EL0_L1Ip": 3, "SYSREG_MIDR_EL1_PartNum": 3407, "SYSREG_CTR_EL0_DminLine": 4, "SYSREG_ID_AA64MMFR0_EL1_PARange": 5, "SYSREG_ID_AA64MMFR1_EL1_ECBHB": 0 ../..

This allows the upper stack to detect available writable ID regs and the "host passthrough model" values.

Quoted 6 lines

It also allows to test some ID reg field values:
(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x13}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x13) exceeds length of field (4)!"}}

(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x2}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x2) does not match any arch valid enum value!”}}

My reasoning here is: User never asked to run the CPU model/configuration. The QMP command is supposed to return the final prop values which QEMU will set/request from KVM.

Like on x86, the query-cpu-model-expansion type=full model={“host”: “props”: {“amx-tile": true}} does not return with error even if host does not have AMX.

But, maybe we can append CpuModelInfo or CpuModelExpansionInfo with optional ‘usable’ boolean. This even fills an existing gap, as, query-cpu-definitions cannot take property values.

Warm Regards,
Khushit

Quoted 178 lines

The following checks are performed:
- the value does not exceed the field size
- if the field is associated to enum values, the set value must be one of those enum values
- the value is applied against a scratch vcpu making sure the setting is not rejected for this host

---

v5 -> v6:
- add the write capability
---
target/arm/arm-qmp-cmds.c | 98 +++++++++++++++++++++++++++++++++++++++

1 file changed, 98 insertions(+)
target/arm/arm-qmp-cmds.c +98 -0
index 83ec95c290..41fefadcea 100644
@@ -21,6 +21,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "qemu/target-info.h"
 #include "hw/core/boards.h"
 #include "kvm_arm.h"
@@ -30,7 +31,10 @@
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc-arm.h"
 #include "qobject/qdict.h"
+#include "qobject/qnum.h"
 #include "qom/qom-qobject.h"
+#include <linux/kvm.h>
+#include "system/kvm.h"
 #include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
@@ -84,11 +88,14 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                     Error **errp)
 {
    CpuModelExpansionInfo *expansion_info;
+    ObjectPropertyIterator iter;
    const QDict *qdict_in;
+    ObjectProperty *idregprop;
    QDict *qdict_out;
    ObjectClass *oc;
    Object *obj;
    const char *name;
+    int fdarray[3];
    int i;
 
    if (type != CPU_MODEL_EXPANSION_TYPE_FULL) {
@@ -133,6 +140,38 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
 
    obj = object_new(object_class_get_name(oc));
 
+    if (kvm_enabled()) {
+        bool pmuv3_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3);
+        bool sve_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE);
+        struct kvm_vcpu_init init = { .target = -1, };
+        bool el2_supported = kvm_arm_el2_supported();
+        bool pauth_supported;
+        int ret;
+
+        pauth_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
+                          kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_GENERIC);
+
+        if (sve_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
+        }
+        if (el2_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+        }
+        if (pauth_supported) {
+            init.features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
+                             1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
+        }
+        if (pmuv3_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_PMU_V3;
+        }
+
+        ret = kvm_arm_create_scratch_host_vcpu(fdarray, &init);
+        if (!ret) {
+            error_setg(errp, "failing creating a scratch vcpu");
+            return NULL;
+        }
+    }
+
    if (model->props) {
        Visitor *visitor;
        Error *err = NULL;
@@ -145,6 +184,49 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
        }
 
        qdict_in = qobject_to(QDict, model->props);
+
+        for (const QDictEntry *entry = qdict_first(qdict_in);
+                 entry != NULL; entry = qdict_next(qdict_in, entry)) {
+            const char *key = qdict_entry_key(entry);
+            QObject *val_obj = qdict_entry_value(entry);
+            ObjectProperty *prop;
+            Visitor *v;
+            bool success;
+            uint64_t val;
+
+            prop = object_property_find(obj, key);
+            if (!prop) {
+                error_setg(errp, "%s does not exist!", key);
+                return NULL;
+            }
+
+            if (!g_str_has_prefix(key, "SYSREG_")) {
+                continue;
+            }
+
+            /* consume the prop to avoid unexpected parameter */
+            if (!visit_type_uint64(visitor, key, &val, errp)) {
+                return NULL;
+            }
+
+            v = qobject_input_visitor_new(val_obj);
+
+            if (!object_property_set(obj, key, v, &err)) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+
+            success = kvm_idreg_write_scratch_vcpu(fdarray[2], v, key,
+                                                   prop->opaque, &err);
+            if (!success) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+            visit_free(v);
+        }
+
        i = 0;
        while ((name = cpu_model_advertised_features[i++]) != NULL) {
            if (qdict_get(qdict_in, name)) {
@@ -160,6 +242,10 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
        if (!err) {
            arm_cpu_finalize_features(ARM_CPU(obj), &err);
        }
+
+        if (kvm_enabled()) {
+            kvm_arm_destroy_scratch_host_vcpu(fdarray);
+        }
        visit_end_struct(visitor, NULL);
        visit_free(visitor);
        if (err) {
@@ -190,6 +276,18 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
        }
    }
 
+    object_property_iter_init(&iter, obj);
+
+    while ((idregprop = object_property_iter_next(&iter))) {
+        QObject *value;
+
+        if (!g_str_has_prefix(idregprop->name, "SYSREG_")) {
+            continue;
+        }
+        value = object_property_get_qobject(obj, idregprop->name, &error_abort);
+        qdict_put_obj(qdict_out, idregprop->name, value);
+    }
+
    if (!qdict_size(qdict_out)) {
        qobject_unref(qdict_out);
    } else {
Signature · 1 line
2.53.0
author
#42 lore raw

Re: [RFC PATCH v7 18/18] arm-qmp-cmds: introspection for ID register props

Hi Khushit,

Quoted 31 lines · Khushit Shah
Quoted 25 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

From: Cornelia Huck <[email protected]>

Implement the capability to query available ID register values by adding SYSREG_* options and values to the cpu model expansion for the host model, if available.

Excerpt:
(QEMU) query-cpu-model-expansion type=full model={"name":"host"} {"return": {"model": {"name": "host", "props": {"SYSREG_ID_AA64PFR0_EL1_EL3": 1, "SYSREG_ID_AA64ISAR2_EL1_CLRBHB": 0, "SYSREG_CTR_EL0_L1Ip": 3, "SYSREG_MIDR_EL1_PartNum": 3407, "SYSREG_CTR_EL0_DminLine": 4, "SYSREG_ID_AA64MMFR0_EL1_PARange": 5, "SYSREG_ID_AA64MMFR1_EL1_ECBHB": 0 ../..

This allows the upper stack to detect available writable ID regs and the "host passthrough model" values.

Quoted 6 lines

It also allows to test some ID reg field values:
(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x13}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x13) exceeds length of field (4)!"}}

(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x2}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x2) does not match any arch valid enum value!”}}

Quoted 8 lines

My reasoning here is: User never asked to run the CPU model/configuration. The QMP command is supposed to return the final prop values which QEMU will set/request from KVM.

Like on x86, the query-cpu-model-expansion type=full model={“host”: “props”: {“amx-tile": true}} does not return with error even if host does not have AMX.

But, maybe we can append CpuModelInfo or CpuModelExpansionInfo with optional ‘usable’ boolean. This even fills an existing gap, as, query-cpu-definitions cannot take property values.

Refering to docs/system/arm/cpu-features.rst it looks a normal case the command fails in case settings cannot apply:

See

(3) Let's try to disable ``aarch64``, which enables the AArch32 CPU feature::

      (QEMU) query-cpu-model-expansion type=full model={"name":"max","props":{"aarch64":false}}
      {"error": {
       "class": "GenericError", "desc":
       "'aarch64' feature cannot be disabled unless KVM is enabled and 32-bit EL1 is supported"
      }}

So my understanding is query-cpu-model-expansion is well suited to settings dry-run

Thanks

Eric

Quoted 180 lines

Warm Regards,
Khushit

Quoted 178 lines

The following checks are performed:
- the value does not exceed the field size
- if the field is associated to enum values, the set value must be one of those enum values
- the value is applied against a scratch vcpu making sure the setting is not rejected for this host

---

v5 -> v6:
- add the write capability
---
target/arm/arm-qmp-cmds.c | 98 +++++++++++++++++++++++++++++++++++++++

1 file changed, 98 insertions(+)
target/arm/arm-qmp-cmds.c +98 -0
index 83ec95c290..41fefadcea 100644
@@ -21,6 +21,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "qemu/target-info.h"
 #include "hw/core/boards.h"
 #include "kvm_arm.h"
@@ -30,7 +31,10 @@
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc-arm.h"
 #include "qobject/qdict.h"
+#include "qobject/qnum.h"
 #include "qom/qom-qobject.h"
+#include <linux/kvm.h>
+#include "system/kvm.h"
 #include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
@@ -84,11 +88,14 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                     Error **errp)
 {
    CpuModelExpansionInfo *expansion_info;
+    ObjectPropertyIterator iter;
    const QDict *qdict_in;
+    ObjectProperty *idregprop;
    QDict *qdict_out;
    ObjectClass *oc;
    Object *obj;
    const char *name;
+    int fdarray[3];
    int i;
 
    if (type != CPU_MODEL_EXPANSION_TYPE_FULL) {
@@ -133,6 +140,38 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
 
    obj = object_new(object_class_get_name(oc));
 
+    if (kvm_enabled()) {
+        bool pmuv3_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3);
+        bool sve_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE);
+        struct kvm_vcpu_init init = { .target = -1, };
+        bool el2_supported = kvm_arm_el2_supported();
+        bool pauth_supported;
+        int ret;
+
+        pauth_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
+                          kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_GENERIC);
+
+        if (sve_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
+        }
+        if (el2_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+        }
+        if (pauth_supported) {
+            init.features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
+                             1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
+        }
+        if (pmuv3_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_PMU_V3;
+        }
+
+        ret = kvm_arm_create_scratch_host_vcpu(fdarray, &init);
+        if (!ret) {
+            error_setg(errp, "failing creating a scratch vcpu");
+            return NULL;
+        }
+    }
+
    if (model->props) {
        Visitor *visitor;
        Error *err = NULL;
@@ -145,6 +184,49 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
        }
 
        qdict_in = qobject_to(QDict, model->props);
+
+        for (const QDictEntry *entry = qdict_first(qdict_in);
+                 entry != NULL; entry = qdict_next(qdict_in, entry)) {
+            const char *key = qdict_entry_key(entry);
+            QObject *val_obj = qdict_entry_value(entry);
+            ObjectProperty *prop;
+            Visitor *v;
+            bool success;
+            uint64_t val;
+
+            prop = object_property_find(obj, key);
+            if (!prop) {
+                error_setg(errp, "%s does not exist!", key);
+                return NULL;
+            }
+
+            if (!g_str_has_prefix(key, "SYSREG_")) {
+                continue;
+            }
+
+            /* consume the prop to avoid unexpected parameter */
+            if (!visit_type_uint64(visitor, key, &val, errp)) {
+                return NULL;
+            }
+
+            v = qobject_input_visitor_new(val_obj);
+
+            if (!object_property_set(obj, key, v, &err)) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+
+            success = kvm_idreg_write_scratch_vcpu(fdarray[2], v, key,
+                                                   prop->opaque, &err);
+            if (!success) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+            visit_free(v);
+        }
+
        i = 0;
        while ((name = cpu_model_advertised_features[i++]) != NULL) {
            if (qdict_get(qdict_in, name)) {
@@ -160,6 +242,10 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
        if (!err) {
            arm_cpu_finalize_features(ARM_CPU(obj), &err);
        }
+
+        if (kvm_enabled()) {
+            kvm_arm_destroy_scratch_host_vcpu(fdarray);
+        }
        visit_end_struct(visitor, NULL);
        visit_free(visitor);
        if (err) {
@@ -190,6 +276,18 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
        }
    }
 
+    object_property_iter_init(&iter, obj);
+
+    while ((idregprop = object_property_iter_next(&iter))) {
+        QObject *value;
+
+        if (!g_str_has_prefix(idregprop->name, "SYSREG_")) {
+            continue;
+        }
+        value = object_property_get_qobject(obj, idregprop->name, &error_abort);
+        qdict_put_obj(qdict_out, idregprop->name, value);
+    }
+
    if (!qdict_size(qdict_out)) {
        qobject_unref(qdict_out);
    } else {
Signature · 1 line
2.53.0
#43 lore raw

Re: [RFC PATCH v7 18/18] arm-qmp-cmds: introspection for ID register props

Quoted 62 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Hi Khushit,

Quoted 31 lines · Khushit Shah
Quoted 25 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

From: Cornelia Huck <[email protected]>

Implement the capability to query available ID register values by adding SYSREG_* options and values to the cpu model expansion for the host model, if available.

Excerpt:
(QEMU) query-cpu-model-expansion type=full model={"name":"host"} {"return": {"model": {"name": "host", "props": {"SYSREG_ID_AA64PFR0_EL1_EL3": 1, "SYSREG_ID_AA64ISAR2_EL1_CLRBHB": 0, "SYSREG_CTR_EL0_L1Ip": 3, "SYSREG_MIDR_EL1_PartNum": 3407, "SYSREG_CTR_EL0_DminLine": 4, "SYSREG_ID_AA64MMFR0_EL1_PARange": 5, "SYSREG_ID_AA64MMFR1_EL1_ECBHB": 0 ../..

This allows the upper stack to detect available writable ID regs and the "host passthrough model" values.

Quoted 6 lines

It also allows to test some ID reg field values:
(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x13}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x13) exceeds length of field (4)!"}}

(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x2}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x2) does not match any arch valid enum value!”}}

Quoted 8 lines

My reasoning here is: User never asked to run the CPU model/configuration. The QMP command is supposed to return the final prop values which QEMU will set/request from KVM.

Like on x86, the query-cpu-model-expansion type=full model={“host”: “props”: {“amx-tile": true}} does not return with error even if host does not have AMX.

But, maybe we can append CpuModelInfo or CpuModelExpansionInfo with optional ‘usable’ boolean. This even fills an existing gap, as, query-cpu-definitions cannot take property values.

Refering to docs/system/arm/cpu-features.rst it looks a normal case the command fails in case settings cannot apply:

See

(3) Let's try to disable ``aarch64``, which enables the AArch32 CPU feature::

(QEMU) query-cpu-model-expansion type=full
model={"name":"max","props":{"aarch64":false}}

Quoted 8 lines
      {"error": {
       "class": "GenericError", "desc":
       "'aarch64' feature cannot be disabled unless KVM is enabled and
32-bit EL1 is supported"
      }}

So my understanding is query-cpu-model-expansion is well suited to settings dry-run

I don't really like the current handling from the named models perspective.

query-cpu-model-expansion should not be performing host-compatibility checks. We should decouple applying the requested props from asking whether this host can actually run them. x86 and s390x are designed the same way.

While this patch only dry-runs SYSREG_* props if they are passed, once named models exist:
query-cpu-model-expansion type=full model={"name":"ampere-1a"}

should not fail because it is not host-compatible. It should still return the model's SYSREG prop values on a host that cannot realise it.

Warm Regards,
Khushit

Quoted 183 lines

Thanks

Eric

Quoted 179 lines

Warm Regards,
Khushit

Quoted 177 lines

The following checks are performed:
- the value does not exceed the field size
- if the field is associated to enum values, the set value must be one of those enum values
- the value is applied against a scratch vcpu making sure the setting is not rejected for this host

---

v5 -> v6:
- add the write capability
---
target/arm/arm-qmp-cmds.c | 98 +++++++++++++++++++++++++++++++++++++++

1 file changed, 98 insertions(+)
target/arm/arm-qmp-cmds.c +98 -0
index 83ec95c290..41fefadcea 100644
@@ -21,6 +21,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "qemu/target-info.h"
 #include "hw/core/boards.h"
 #include "kvm_arm.h"
@@ -30,7 +31,10 @@
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc-arm.h"
 #include "qobject/qdict.h"
+#include "qobject/qnum.h"
 #include "qom/qom-qobject.h"
+#include <linux/kvm.h>
+#include "system/kvm.h"
 #include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
@@ -84,11 +88,14 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                    Error **errp)
 {
   CpuModelExpansionInfo *expansion_info;
+    ObjectPropertyIterator iter;
   const QDict *qdict_in;
+    ObjectProperty *idregprop;
   QDict *qdict_out;
   ObjectClass *oc;
   Object *obj;
   const char *name;
+    int fdarray[3];
   int i;
 
   if (type != CPU_MODEL_EXPANSION_TYPE_FULL) {
@@ -133,6 +140,38 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
 
   obj = object_new(object_class_get_name(oc));
 
+    if (kvm_enabled()) {
+        bool pmuv3_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3);
+        bool sve_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE);
+        struct kvm_vcpu_init init = { .target = -1, };
+        bool el2_supported = kvm_arm_el2_supported();
+        bool pauth_supported;
+        int ret;
+
+        pauth_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
+                          kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_GENERIC);
+
+        if (sve_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
+        }
+        if (el2_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+        }
+        if (pauth_supported) {
+            init.features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
+                             1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
+        }
+        if (pmuv3_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_PMU_V3;
+        }
+
+        ret = kvm_arm_create_scratch_host_vcpu(fdarray, &init);
+        if (!ret) {
+            error_setg(errp, "failing creating a scratch vcpu");
+            return NULL;
+        }
+    }
+
   if (model->props) {
       Visitor *visitor;
       Error *err = NULL;
@@ -145,6 +184,49 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       }
 
       qdict_in = qobject_to(QDict, model->props);
+
+        for (const QDictEntry *entry = qdict_first(qdict_in);
+                 entry != NULL; entry = qdict_next(qdict_in, entry)) {
+            const char *key = qdict_entry_key(entry);
+            QObject *val_obj = qdict_entry_value(entry);
+            ObjectProperty *prop;
+            Visitor *v;
+            bool success;
+            uint64_t val;
+
+            prop = object_property_find(obj, key);
+            if (!prop) {
+                error_setg(errp, "%s does not exist!", key);
+                return NULL;
+            }
+
+            if (!g_str_has_prefix(key, "SYSREG_")) {
+                continue;
+            }
+
+            /* consume the prop to avoid unexpected parameter */
+            if (!visit_type_uint64(visitor, key, &val, errp)) {
+                return NULL;
+            }
+
+            v = qobject_input_visitor_new(val_obj);
+
+            if (!object_property_set(obj, key, v, &err)) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+
+            success = kvm_idreg_write_scratch_vcpu(fdarray[2], v, key,
+                                                   prop->opaque, &err);
+            if (!success) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+            visit_free(v);
+        }
+
       i = 0;
       while ((name = cpu_model_advertised_features[i++]) != NULL) {
           if (qdict_get(qdict_in, name)) {
@@ -160,6 +242,10 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       if (!err) {
           arm_cpu_finalize_features(ARM_CPU(obj), &err);
       }
+
+        if (kvm_enabled()) {
+            kvm_arm_destroy_scratch_host_vcpu(fdarray);
+        }
       visit_end_struct(visitor, NULL);
       visit_free(visitor);
       if (err) {
@@ -190,6 +276,18 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       }
   }
 
+    object_property_iter_init(&iter, obj);
+
+    while ((idregprop = object_property_iter_next(&iter))) {
+        QObject *value;
+
+        if (!g_str_has_prefix(idregprop->name, "SYSREG_")) {
+            continue;
+        }
+        value = object_property_get_qobject(obj, idregprop->name, &error_abort);
+        qdict_put_obj(qdict_out, idregprop->name, value);
+    }
+
   if (!qdict_size(qdict_out)) {
       qobject_unref(qdict_out);
   } else {
Signature · 1 line
2.53.0
author
#44 lore raw

Re: [RFC PATCH v7 18/18] arm-qmp-cmds: introspection for ID register props

Quoted 75 lines · Khushit Shah
Quoted 59 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Hi Khushit,

Quoted 30 lines · Khushit Shah
Quoted 24 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

From: Cornelia Huck <[email protected]>

Implement the capability to query available ID register values by adding SYSREG_* options and values to the cpu model expansion for the host model, if available.

Excerpt:
(QEMU) query-cpu-model-expansion type=full model={"name":"host"} {"return": {"model": {"name": "host", "props": {"SYSREG_ID_AA64PFR0_EL1_EL3": 1, "SYSREG_ID_AA64ISAR2_EL1_CLRBHB": 0, "SYSREG_CTR_EL0_L1Ip": 3, "SYSREG_MIDR_EL1_PartNum": 3407, "SYSREG_CTR_EL0_DminLine": 4, "SYSREG_ID_AA64MMFR0_EL1_PARange": 5, "SYSREG_ID_AA64MMFR1_EL1_ECBHB": 0 ../..

This allows the upper stack to detect available writable ID regs and the "host passthrough model" values.

Quoted 6 lines

It also allows to test some ID reg field values:
(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x13}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x13) exceeds length of field (4)!"}}

(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x2}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x2) does not match any arch valid enum value!”}}

Quoted 8 lines

My reasoning here is: User never asked to run the CPU model/configuration. The QMP command is supposed to return the final prop values which QEMU will set/request from KVM.

Like on x86, the query-cpu-model-expansion type=full model={“host”: “props”: {“amx-tile": true}} does not return with error even if host does not have AMX.

But, maybe we can append CpuModelInfo or CpuModelExpansionInfo with optional ‘usable’ boolean. This even fills an existing gap, as, query-cpu-definitions cannot take property values.

Refering to docs/system/arm/cpu-features.rst it looks a normal case the command fails in case settings cannot apply:

See

(3) Let's try to disable ``aarch64``, which enables the AArch32 CPU feature::

(QEMU) query-cpu-model-expansion type=full
model={"name":"max","props":{"aarch64":false}}

Quoted 8 lines
      {"error": {
       "class": "GenericError", "desc":
       "'aarch64' feature cannot be disabled unless KVM is enabled and
32-bit EL1 is supported"
      }}

So my understanding is query-cpu-model-expansion is well suited to settings dry-run

I don't really like the current handling from the named models perspective.

query-cpu-model-expansion should not be performing host-compatibility checks. We should decouple applying the requested props from asking whether this host can actually run them. x86 and s390x are designed the same way.

Quoted 7 lines

While this patch only dry-runs SYSREG_* props if they are passed, once named models exist:
query-cpu-model-expansion type=full model={"name":"ampere-1a"}

should not fail because it is not host-compatible. It should still return the model's SYSREG prop values on a host that cannot realise it.

Looking at qapi/machine.json,

# Errors:
#     - if expanding CPU models is not supported
#     - if the model cannot be expanded
#     - if the model contains an unknown CPU definition name, unknown #       properties or properties with a wrong type
#     - if an expansion type is not supported

Maybe we could use the "static" parameter which is not currently implement on ARM.

# * machine options (including accelerator): in some architectures, #   CPU models may look different depending on machine and accelerator #   options.  (Except for CPU models reported as "static" in #   query-cpu-definitions.)

in case you use static we don't expand against the accelerator, while with full we would do?

Thanks

Eric

Quoted 188 lines

Warm Regards,
Khushit

Quoted 183 lines

Thanks

Eric

Quoted 179 lines

Warm Regards,
Khushit

Quoted 177 lines

The following checks are performed:
- the value does not exceed the field size
- if the field is associated to enum values, the set value must be one of those enum values
- the value is applied against a scratch vcpu making sure the setting is not rejected for this host

---

v5 -> v6:
- add the write capability
---
target/arm/arm-qmp-cmds.c | 98 +++++++++++++++++++++++++++++++++++++++

1 file changed, 98 insertions(+)
target/arm/arm-qmp-cmds.c +98 -0
index 83ec95c290..41fefadcea 100644
@@ -21,6 +21,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "qemu/target-info.h"
 #include "hw/core/boards.h"
 #include "kvm_arm.h"
@@ -30,7 +31,10 @@
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc-arm.h"
 #include "qobject/qdict.h"
+#include "qobject/qnum.h"
 #include "qom/qom-qobject.h"
+#include <linux/kvm.h>
+#include "system/kvm.h"
 #include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
@@ -84,11 +88,14 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                    Error **errp)
 {
   CpuModelExpansionInfo *expansion_info;
+    ObjectPropertyIterator iter;
   const QDict *qdict_in;
+    ObjectProperty *idregprop;
   QDict *qdict_out;
   ObjectClass *oc;
   Object *obj;
   const char *name;
+    int fdarray[3];
   int i;
 
   if (type != CPU_MODEL_EXPANSION_TYPE_FULL) {
@@ -133,6 +140,38 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
 
   obj = object_new(object_class_get_name(oc));
 
+    if (kvm_enabled()) {
+        bool pmuv3_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3);
+        bool sve_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE);
+        struct kvm_vcpu_init init = { .target = -1, };
+        bool el2_supported = kvm_arm_el2_supported();
+        bool pauth_supported;
+        int ret;
+
+        pauth_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
+                          kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_GENERIC);
+
+        if (sve_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
+        }
+        if (el2_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+        }
+        if (pauth_supported) {
+            init.features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
+                             1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
+        }
+        if (pmuv3_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_PMU_V3;
+        }
+
+        ret = kvm_arm_create_scratch_host_vcpu(fdarray, &init);
+        if (!ret) {
+            error_setg(errp, "failing creating a scratch vcpu");
+            return NULL;
+        }
+    }
+
   if (model->props) {
       Visitor *visitor;
       Error *err = NULL;
@@ -145,6 +184,49 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       }
 
       qdict_in = qobject_to(QDict, model->props);
+
+        for (const QDictEntry *entry = qdict_first(qdict_in);
+                 entry != NULL; entry = qdict_next(qdict_in, entry)) {
+            const char *key = qdict_entry_key(entry);
+            QObject *val_obj = qdict_entry_value(entry);
+            ObjectProperty *prop;
+            Visitor *v;
+            bool success;
+            uint64_t val;
+
+            prop = object_property_find(obj, key);
+            if (!prop) {
+                error_setg(errp, "%s does not exist!", key);
+                return NULL;
+            }
+
+            if (!g_str_has_prefix(key, "SYSREG_")) {
+                continue;
+            }
+
+            /* consume the prop to avoid unexpected parameter */
+            if (!visit_type_uint64(visitor, key, &val, errp)) {
+                return NULL;
+            }
+
+            v = qobject_input_visitor_new(val_obj);
+
+            if (!object_property_set(obj, key, v, &err)) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+
+            success = kvm_idreg_write_scratch_vcpu(fdarray[2], v, key,
+                                                   prop->opaque, &err);
+            if (!success) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+            visit_free(v);
+        }
+
       i = 0;
       while ((name = cpu_model_advertised_features[i++]) != NULL) {
           if (qdict_get(qdict_in, name)) {
@@ -160,6 +242,10 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       if (!err) {
           arm_cpu_finalize_features(ARM_CPU(obj), &err);
       }
+
+        if (kvm_enabled()) {
+            kvm_arm_destroy_scratch_host_vcpu(fdarray);
+        }
       visit_end_struct(visitor, NULL);
       visit_free(visitor);
       if (err) {
@@ -190,6 +276,18 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       }
   }
 
+    object_property_iter_init(&iter, obj);
+
+    while ((idregprop = object_property_iter_next(&iter))) {
+        QObject *value;
+
+        if (!g_str_has_prefix(idregprop->name, "SYSREG_")) {
+            continue;
+        }
+        value = object_property_get_qobject(obj, idregprop->name, &error_abort);
+        qdict_put_obj(qdict_out, idregprop->name, value);
+    }
+
   if (!qdict_size(qdict_out)) {
       qobject_unref(qdict_out);
   } else {
Signature · 1 line
2.53.0
#45 lore raw

Re: [RFC PATCH v7 18/18] arm-qmp-cmds: introspection for ID register props

Quoted 78 lines · Eric Auger
Quoted 75 lines · Khushit Shah
Quoted 59 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Hi Khushit,

Quoted 30 lines · Khushit Shah
Quoted 24 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

From: Cornelia Huck <[email protected]>

Implement the capability to query available ID register values by adding SYSREG_* options and values to the cpu model expansion for the host model, if available.

Excerpt:
(QEMU) query-cpu-model-expansion type=full model={"name":"host"} {"return": {"model": {"name": "host", "props": {"SYSREG_ID_AA64PFR0_EL1_EL3": 1, "SYSREG_ID_AA64ISAR2_EL1_CLRBHB": 0, "SYSREG_CTR_EL0_L1Ip": 3, "SYSREG_MIDR_EL1_PartNum": 3407, "SYSREG_CTR_EL0_DminLine": 4, "SYSREG_ID_AA64MMFR0_EL1_PARange": 5, "SYSREG_ID_AA64MMFR1_EL1_ECBHB": 0 ../..

This allows the upper stack to detect available writable ID regs and the "host passthrough model" values.

Quoted 6 lines

It also allows to test some ID reg field values:
(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x13}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x13) exceeds length of field (4)!"}}

(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x2}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x2) does not match any arch valid enum value!”}}

Quoted 8 lines

My reasoning here is: User never asked to run the CPU model/configuration. The QMP command is supposed to return the final prop values which QEMU will set/request from KVM.

Like on x86, the query-cpu-model-expansion type=full model={“host”: “props”: {“amx-tile": true}} does not return with error even if host does not have AMX.

But, maybe we can append CpuModelInfo or CpuModelExpansionInfo with optional ‘usable’ boolean. This even fills an existing gap, as, query-cpu-definitions cannot take property values.

Refering to docs/system/arm/cpu-features.rst it looks a normal case the command fails in case settings cannot apply:

See

(3) Let's try to disable ``aarch64``, which enables the AArch32 CPU feature::

(QEMU) query-cpu-model-expansion type=full
model={"name":"max","props":{"aarch64":false}}

Quoted 8 lines
      {"error": {
       "class": "GenericError", "desc":
       "'aarch64' feature cannot be disabled unless KVM is enabled and
32-bit EL1 is supported"
      }}

So my understanding is query-cpu-model-expansion is well suited to settings dry-run

I don't really like the current handling from the named models perspective.

query-cpu-model-expansion should not be performing host-compatibility checks. We should decouple applying the requested props from asking whether this host can actually run them. x86 and s390x are designed the same way.

Quoted 7 lines
Quoted 7 lines

While this patch only dry-runs SYSREG_* props if they are passed, once named models exist:
query-cpu-model-expansion type=full model={"name":"ampere-1a"}

should not fail because it is not host-compatible. It should still return the model's SYSREG prop values on a host that cannot realise it.

Isn't it the role of query-cpu-definitions:

# @unavailable-features: List of properties that prevent the CPU model
# from running in the current host. (since 2.8)

in qapi/machine.json

Thanks

Eric

Quoted 216 lines

Looking at qapi/machine.json,

# Errors:
#     - if expanding CPU models is not supported
#     - if the model cannot be expanded
#     - if the model contains an unknown CPU definition name, unknown #       properties or properties with a wrong type
#     - if an expansion type is not supported

Maybe we could use the "static" parameter which is not currently implement on ARM.

# * machine options (including accelerator): in some architectures, #   CPU models may look different depending on machine and accelerator #   options.  (Except for CPU models reported as "static" in #   query-cpu-definitions.)

in case you use static we don't expand against the accelerator, while with full we would do?

Thanks

Eric

Quoted 188 lines

Warm Regards,
Khushit

Quoted 183 lines

Thanks

Eric

Quoted 179 lines

Warm Regards,
Khushit

Quoted 177 lines

The following checks are performed:
- the value does not exceed the field size
- if the field is associated to enum values, the set value must be one of those enum values
- the value is applied against a scratch vcpu making sure the setting is not rejected for this host

---

v5 -> v6:
- add the write capability
---
target/arm/arm-qmp-cmds.c | 98 +++++++++++++++++++++++++++++++++++++++

1 file changed, 98 insertions(+)
target/arm/arm-qmp-cmds.c +98 -0
index 83ec95c290..41fefadcea 100644
@@ -21,6 +21,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "qemu/target-info.h"
 #include "hw/core/boards.h"
 #include "kvm_arm.h"
@@ -30,7 +31,10 @@
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc-arm.h"
 #include "qobject/qdict.h"
+#include "qobject/qnum.h"
 #include "qom/qom-qobject.h"
+#include <linux/kvm.h>
+#include "system/kvm.h"
 #include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
@@ -84,11 +88,14 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                    Error **errp)
 {
   CpuModelExpansionInfo *expansion_info;
+    ObjectPropertyIterator iter;
   const QDict *qdict_in;
+    ObjectProperty *idregprop;
   QDict *qdict_out;
   ObjectClass *oc;
   Object *obj;
   const char *name;
+    int fdarray[3];
   int i;
 
   if (type != CPU_MODEL_EXPANSION_TYPE_FULL) {
@@ -133,6 +140,38 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
 
   obj = object_new(object_class_get_name(oc));
 
+    if (kvm_enabled()) {
+        bool pmuv3_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3);
+        bool sve_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE);
+        struct kvm_vcpu_init init = { .target = -1, };
+        bool el2_supported = kvm_arm_el2_supported();
+        bool pauth_supported;
+        int ret;
+
+        pauth_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
+                          kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_GENERIC);
+
+        if (sve_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
+        }
+        if (el2_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+        }
+        if (pauth_supported) {
+            init.features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
+                             1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
+        }
+        if (pmuv3_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_PMU_V3;
+        }
+
+        ret = kvm_arm_create_scratch_host_vcpu(fdarray, &init);
+        if (!ret) {
+            error_setg(errp, "failing creating a scratch vcpu");
+            return NULL;
+        }
+    }
+
   if (model->props) {
       Visitor *visitor;
       Error *err = NULL;
@@ -145,6 +184,49 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       }
 
       qdict_in = qobject_to(QDict, model->props);
+
+        for (const QDictEntry *entry = qdict_first(qdict_in);
+                 entry != NULL; entry = qdict_next(qdict_in, entry)) {
+            const char *key = qdict_entry_key(entry);
+            QObject *val_obj = qdict_entry_value(entry);
+            ObjectProperty *prop;
+            Visitor *v;
+            bool success;
+            uint64_t val;
+
+            prop = object_property_find(obj, key);
+            if (!prop) {
+                error_setg(errp, "%s does not exist!", key);
+                return NULL;
+            }
+
+            if (!g_str_has_prefix(key, "SYSREG_")) {
+                continue;
+            }
+
+            /* consume the prop to avoid unexpected parameter */
+            if (!visit_type_uint64(visitor, key, &val, errp)) {
+                return NULL;
+            }
+
+            v = qobject_input_visitor_new(val_obj);
+
+            if (!object_property_set(obj, key, v, &err)) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+
+            success = kvm_idreg_write_scratch_vcpu(fdarray[2], v, key,
+                                                   prop->opaque, &err);
+            if (!success) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+            visit_free(v);
+        }
+
       i = 0;
       while ((name = cpu_model_advertised_features[i++]) != NULL) {
           if (qdict_get(qdict_in, name)) {
@@ -160,6 +242,10 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       if (!err) {
           arm_cpu_finalize_features(ARM_CPU(obj), &err);
       }
+
+        if (kvm_enabled()) {
+            kvm_arm_destroy_scratch_host_vcpu(fdarray);
+        }
       visit_end_struct(visitor, NULL);
       visit_free(visitor);
       if (err) {
@@ -190,6 +276,18 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
       }
   }
 
+    object_property_iter_init(&iter, obj);
+
+    while ((idregprop = object_property_iter_next(&iter))) {
+        QObject *value;
+
+        if (!g_str_has_prefix(idregprop->name, "SYSREG_")) {
+            continue;
+        }
+        value = object_property_get_qobject(obj, idregprop->name, &error_abort);
+        qdict_put_obj(qdict_out, idregprop->name, value);
+    }
+
   if (!qdict_size(qdict_out)) {
       qobject_unref(qdict_out);
   } else {
Signature · 1 line
2.53.0
#46 lore raw

Re: [RFC PATCH v7 18/18] arm-qmp-cmds: introspection for ID register props

Quoted 90 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Quoted 78 lines · Eric Auger
Quoted 75 lines · Khushit Shah
Quoted 59 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Hi Khushit,

Quoted 30 lines · Khushit Shah
Quoted 24 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

From: Cornelia Huck <[email protected]>

Implement the capability to query available ID register values by adding SYSREG_* options and values to the cpu model expansion for the host model, if available.

Excerpt:
(QEMU) query-cpu-model-expansion type=full model={"name":"host"} {"return": {"model": {"name": "host", "props": {"SYSREG_ID_AA64PFR0_EL1_EL3": 1, "SYSREG_ID_AA64ISAR2_EL1_CLRBHB": 0, "SYSREG_CTR_EL0_L1Ip": 3, "SYSREG_MIDR_EL1_PartNum": 3407, "SYSREG_CTR_EL0_DminLine": 4, "SYSREG_ID_AA64MMFR0_EL1_PARange": 5, "SYSREG_ID_AA64MMFR1_EL1_ECBHB": 0 ../..

This allows the upper stack to detect available writable ID regs and the "host passthrough model" values.

Quoted 6 lines

It also allows to test some ID reg field values:
(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x13}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x13) exceeds length of field (4)!"}}

(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x2}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x2) does not match any arch valid enum value!”}}

Quoted 8 lines

My reasoning here is: User never asked to run the CPU model/configuration. The QMP command is supposed to return the final prop values which QEMU will set/request from KVM.

Like on x86, the query-cpu-model-expansion type=full model={“host”: “props”: {“amx-tile": true}} does not return with error even if host does not have AMX.

But, maybe we can append CpuModelInfo or CpuModelExpansionInfo with optional ‘usable’ boolean. This even fills an existing gap, as, query-cpu-definitions cannot take property values.

Refering to docs/system/arm/cpu-features.rst it looks a normal case the command fails in case settings cannot apply:

See

(3) Let's try to disable ``aarch64``, which enables the AArch32 CPU feature::

(QEMU) query-cpu-model-expansion type=full
model={"name":"max","props":{"aarch64":false}}

Quoted 8 lines
     {"error": {
      "class": "GenericError", "desc":
      "'aarch64' feature cannot be disabled unless KVM is enabled and
32-bit EL1 is supported"
     }}

So my understanding is query-cpu-model-expansion is well suited to settings dry-run

I don't really like the current handling from the named models perspective.

query-cpu-model-expansion should not be performing host-compatibility checks. We should decouple applying the requested props from asking whether this host can actually run them. x86 and s390x are designed the same way.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

While this patch only dry-runs SYSREG_* props if they are passed, once named models exist:
query-cpu-model-expansion type=full model={"name":"ampere-1a"}

should not fail because it is not host-compatible. It should still return the model's SYSREG prop values on a host that cannot realise it.

Isn't it the role of query-cpu-definitions:

Nope, query-cpu-definitions’s unavailable-features only list the problematic properties. While query-cpu-model-expansion should give the full ID reg view (all SYSREG props)

Warm Regards,
Khushit

Quoted 223 lines

# @unavailable-features: List of properties that prevent the CPU model
# from running in the current host. (since 2.8)

in qapi/machine.json

Thanks

Eric

Quoted 214 lines

Looking at qapi/machine.json,

# Errors:

#     - if expanding CPU models is not supported
#     - if the model cannot be expanded
#     - if the model contains an unknown CPU definition name, unknown

# properties or properties with a wrong type
# - if an expansion type is not supported

Maybe we could use the "static" parameter which is not currently implement on ARM.

# * machine options (including accelerator): in some architectures,

#   CPU models may look different depending on machine and accelerator
#   options.  (Except for CPU models reported as "static" in
#   `query-cpu-definitions`.)

in case you use static we don't expand against the accelerator, while with full we would do?

Thanks

Eric

Quoted 187 lines

Warm Regards,
Khushit

Quoted 183 lines

Thanks

Eric

Quoted 179 lines

Warm Regards,
Khushit

Quoted 177 lines

The following checks are performed:
- the value does not exceed the field size
- if the field is associated to enum values, the set value must be one of those enum values
- the value is applied against a scratch vcpu making sure the setting is not rejected for this host

---

v5 -> v6:
- add the write capability
---
target/arm/arm-qmp-cmds.c | 98 +++++++++++++++++++++++++++++++++++++++

1 file changed, 98 insertions(+)
target/arm/arm-qmp-cmds.c +98 -0
index 83ec95c290..41fefadcea 100644
@@ -21,6 +21,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "qemu/target-info.h"
 #include "hw/core/boards.h"
 #include "kvm_arm.h"
@@ -30,7 +31,10 @@
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc-arm.h"
 #include "qobject/qdict.h"
+#include "qobject/qnum.h"
 #include "qom/qom-qobject.h"
+#include <linux/kvm.h>
+#include "system/kvm.h"
 #include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
@@ -84,11 +88,14 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                   Error **errp)
 {
  CpuModelExpansionInfo *expansion_info;
+    ObjectPropertyIterator iter;
  const QDict *qdict_in;
+    ObjectProperty *idregprop;
  QDict *qdict_out;
  ObjectClass *oc;
  Object *obj;
  const char *name;
+    int fdarray[3];
  int i;
 
  if (type != CPU_MODEL_EXPANSION_TYPE_FULL) {
@@ -133,6 +140,38 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
 
  obj = object_new(object_class_get_name(oc));
 
+    if (kvm_enabled()) {
+        bool pmuv3_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3);
+        bool sve_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE);
+        struct kvm_vcpu_init init = { .target = -1, };
+        bool el2_supported = kvm_arm_el2_supported();
+        bool pauth_supported;
+        int ret;
+
+        pauth_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
+                          kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_GENERIC);
+
+        if (sve_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
+        }
+        if (el2_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+        }
+        if (pauth_supported) {
+            init.features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
+                             1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
+        }
+        if (pmuv3_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_PMU_V3;
+        }
+
+        ret = kvm_arm_create_scratch_host_vcpu(fdarray, &init);
+        if (!ret) {
+            error_setg(errp, "failing creating a scratch vcpu");
+            return NULL;
+        }
+    }
+
  if (model->props) {
      Visitor *visitor;
      Error *err = NULL;
@@ -145,6 +184,49 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
      }
 
      qdict_in = qobject_to(QDict, model->props);
+
+        for (const QDictEntry *entry = qdict_first(qdict_in);
+                 entry != NULL; entry = qdict_next(qdict_in, entry)) {
+            const char *key = qdict_entry_key(entry);
+            QObject *val_obj = qdict_entry_value(entry);
+            ObjectProperty *prop;
+            Visitor *v;
+            bool success;
+            uint64_t val;
+
+            prop = object_property_find(obj, key);
+            if (!prop) {
+                error_setg(errp, "%s does not exist!", key);
+                return NULL;
+            }
+
+            if (!g_str_has_prefix(key, "SYSREG_")) {
+                continue;
+            }
+
+            /* consume the prop to avoid unexpected parameter */
+            if (!visit_type_uint64(visitor, key, &val, errp)) {
+                return NULL;
+            }
+
+            v = qobject_input_visitor_new(val_obj);
+
+            if (!object_property_set(obj, key, v, &err)) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+
+            success = kvm_idreg_write_scratch_vcpu(fdarray[2], v, key,
+                                                   prop->opaque, &err);
+            if (!success) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+            visit_free(v);
+        }
+
      i = 0;
      while ((name = cpu_model_advertised_features[i++]) != NULL) {
          if (qdict_get(qdict_in, name)) {
@@ -160,6 +242,10 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
      if (!err) {
          arm_cpu_finalize_features(ARM_CPU(obj), &err);
      }
+
+        if (kvm_enabled()) {
+            kvm_arm_destroy_scratch_host_vcpu(fdarray);
+        }
      visit_end_struct(visitor, NULL);
      visit_free(visitor);
      if (err) {
@@ -190,6 +276,18 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
      }
  }
 
+    object_property_iter_init(&iter, obj);
+
+    while ((idregprop = object_property_iter_next(&iter))) {
+        QObject *value;
+
+        if (!g_str_has_prefix(idregprop->name, "SYSREG_")) {
+            continue;
+        }
+        value = object_property_get_qobject(obj, idregprop->name, &error_abort);
+        qdict_put_obj(qdict_out, idregprop->name, value);
+    }
+
  if (!qdict_size(qdict_out)) {
      qobject_unref(qdict_out);
  } else {
Signature · 1 line
2.53.0
#47 lore raw

Re: [RFC PATCH v7 18/18] arm-qmp-cmds: introspection for ID register props

Quoted 94 lines · Khushit Shah
Quoted 94 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Quoted 82 lines · Eric Auger
Quoted 79 lines · Khushit Shah
Quoted 59 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Hi Khushit,

Quoted 30 lines · Khushit Shah
Quoted 24 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

From: Cornelia Huck <[email protected]>

Implement the capability to query available ID register values by adding SYSREG_* options and values to the cpu model expansion for the host model, if available.

Excerpt:
(QEMU) query-cpu-model-expansion type=full model={"name":"host"} {"return": {"model": {"name": "host", "props": {"SYSREG_ID_AA64PFR0_EL1_EL3": 1, "SYSREG_ID_AA64ISAR2_EL1_CLRBHB": 0, "SYSREG_CTR_EL0_L1Ip": 3, "SYSREG_MIDR_EL1_PartNum": 3407, "SYSREG_CTR_EL0_DminLine": 4, "SYSREG_ID_AA64MMFR0_EL1_PARange": 5, "SYSREG_ID_AA64MMFR1_EL1_ECBHB": 0 ../..

This allows the upper stack to detect available writable ID regs and the "host passthrough model" values.

Quoted 6 lines

It also allows to test some ID reg field values:
(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x13}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x13) exceeds length of field (4)!"}}

(QEMU) query-cpu-model-expansion type=full model={"name":"host","props":{"SYSREG_ID_AA64ISAR0_EL1_DP":0x2}} {"error": {"class": "GenericError", "desc": "idreg SYSREG_ID_AA64ISAR0_EL1_DP set value (0x2) does not match any arch valid enum value!”}}

Quoted 8 lines

My reasoning here is: User never asked to run the CPU model/configuration. The QMP command is supposed to return the final prop values which QEMU will set/request from KVM.

Like on x86, the query-cpu-model-expansion type=full model={“host”: “props”: {“amx-tile": true}} does not return with error even if host does not have AMX.

But, maybe we can append CpuModelInfo or CpuModelExpansionInfo with optional ‘usable’ boolean. This even fills an existing gap, as, query-cpu-definitions cannot take property values.

Refering to docs/system/arm/cpu-features.rst it looks a normal case the command fails in case settings cannot apply:

See

(3) Let's try to disable ``aarch64``, which enables the AArch32 CPU feature::

(QEMU) query-cpu-model-expansion type=full
model={"name":"max","props":{"aarch64":false}}

Quoted 8 lines
     {"error": {
      "class": "GenericError", "desc":
      "'aarch64' feature cannot be disabled unless KVM is enabled and
32-bit EL1 is supported"
     }}

So my understanding is query-cpu-model-expansion is well suited to settings dry-run

I don't really like the current handling from the named models perspective.

query-cpu-model-expansion should not be performing host-compatibility checks. We should decouple applying the requested props from asking whether this host can actually run them. x86 and s390x are designed the same way.

While this patch only dry-runs SYSREG_* props if they are passed, once named models exist:
query-cpu-model-expansion type=full model={"name":"ampere-1a"}

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

should not fail because it is not host-compatible. It should still return the model's SYSREG prop values on a host that cannot realise it.

Isn't it the role of query-cpu-definitions:

Nope, query-cpu-definitions’s unavailable-features only list the problematic properties. While query-cpu-model-expansion should give the full ID reg view (all SYSREG props)

OK, for named vcpu models you can implement query-cpu-model-expansion without scratch vcpu model validation and use this latter in query-cpu-definitions’s unavailable-features. For custom host, query-cpu-model-expansion can have a different implementation.

Thanks

Eric

Quoted 228 lines

Warm Regards,
Khushit

Quoted 223 lines

# @unavailable-features: List of properties that prevent the CPU model
# from running in the current host. (since 2.8)

in qapi/machine.json

Thanks

Eric

Quoted 214 lines

Looking at qapi/machine.json,

# Errors:

#     - if expanding CPU models is not supported
#     - if the model cannot be expanded
#     - if the model contains an unknown CPU definition name, unknown

# properties or properties with a wrong type
# - if an expansion type is not supported

Maybe we could use the "static" parameter which is not currently implement on ARM.

# * machine options (including accelerator): in some architectures,

#   CPU models may look different depending on machine and accelerator
#   options.  (Except for CPU models reported as "static" in
#   `query-cpu-definitions`.)

in case you use static we don't expand against the accelerator, while with full we would do?

Thanks

Eric

Quoted 187 lines

Warm Regards,
Khushit

Quoted 183 lines

Thanks

Eric

Quoted 179 lines

Warm Regards,
Khushit

Quoted 177 lines

The following checks are performed:
- the value does not exceed the field size
- if the field is associated to enum values, the set value must be one of those enum values
- the value is applied against a scratch vcpu making sure the setting is not rejected for this host

---

v5 -> v6:
- add the write capability
---
target/arm/arm-qmp-cmds.c | 98 +++++++++++++++++++++++++++++++++++++++

1 file changed, 98 insertions(+)
target/arm/arm-qmp-cmds.c +98 -0
index 83ec95c290..41fefadcea 100644
@@ -21,6 +21,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/error-report.h"
 #include "qemu/target-info.h"
 #include "hw/core/boards.h"
 #include "kvm_arm.h"
@@ -30,7 +31,10 @@
 #include "qapi/qapi-commands-machine.h"
 #include "qapi/qapi-commands-misc-arm.h"
 #include "qobject/qdict.h"
+#include "qobject/qnum.h"
 #include "qom/qom-qobject.h"
+#include <linux/kvm.h>
+#include "system/kvm.h"
 #include "cpu.h"
 
 static GICCapability *gic_cap_new(int version)
@@ -84,11 +88,14 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
                                                   Error **errp)
 {
  CpuModelExpansionInfo *expansion_info;
+    ObjectPropertyIterator iter;
  const QDict *qdict_in;
+    ObjectProperty *idregprop;
  QDict *qdict_out;
  ObjectClass *oc;
  Object *obj;
  const char *name;
+    int fdarray[3];
  int i;
 
  if (type != CPU_MODEL_EXPANSION_TYPE_FULL) {
@@ -133,6 +140,38 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
 
  obj = object_new(object_class_get_name(oc));
 
+    if (kvm_enabled()) {
+        bool pmuv3_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3);
+        bool sve_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_SVE);
+        struct kvm_vcpu_init init = { .target = -1, };
+        bool el2_supported = kvm_arm_el2_supported();
+        bool pauth_supported;
+        int ret;
+
+        pauth_supported = kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
+                          kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_GENERIC);
+
+        if (sve_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_SVE;
+        }
+        if (el2_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
+        }
+        if (pauth_supported) {
+            init.features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
+                             1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
+        }
+        if (pmuv3_supported) {
+            init.features[0] |= 1 << KVM_ARM_VCPU_PMU_V3;
+        }
+
+        ret = kvm_arm_create_scratch_host_vcpu(fdarray, &init);
+        if (!ret) {
+            error_setg(errp, "failing creating a scratch vcpu");
+            return NULL;
+        }
+    }
+
  if (model->props) {
      Visitor *visitor;
      Error *err = NULL;
@@ -145,6 +184,49 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
      }
 
      qdict_in = qobject_to(QDict, model->props);
+
+        for (const QDictEntry *entry = qdict_first(qdict_in);
+                 entry != NULL; entry = qdict_next(qdict_in, entry)) {
+            const char *key = qdict_entry_key(entry);
+            QObject *val_obj = qdict_entry_value(entry);
+            ObjectProperty *prop;
+            Visitor *v;
+            bool success;
+            uint64_t val;
+
+            prop = object_property_find(obj, key);
+            if (!prop) {
+                error_setg(errp, "%s does not exist!", key);
+                return NULL;
+            }
+
+            if (!g_str_has_prefix(key, "SYSREG_")) {
+                continue;
+            }
+
+            /* consume the prop to avoid unexpected parameter */
+            if (!visit_type_uint64(visitor, key, &val, errp)) {
+                return NULL;
+            }
+
+            v = qobject_input_visitor_new(val_obj);
+
+            if (!object_property_set(obj, key, v, &err)) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+
+            success = kvm_idreg_write_scratch_vcpu(fdarray[2], v, key,
+                                                   prop->opaque, &err);
+            if (!success) {
+                error_propagate(errp, err);
+                visit_free(v);
+                return NULL;
+            }
+            visit_free(v);
+        }
+
      i = 0;
      while ((name = cpu_model_advertised_features[i++]) != NULL) {
          if (qdict_get(qdict_in, name)) {
@@ -160,6 +242,10 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
      if (!err) {
          arm_cpu_finalize_features(ARM_CPU(obj), &err);
      }
+
+        if (kvm_enabled()) {
+            kvm_arm_destroy_scratch_host_vcpu(fdarray);
+        }
      visit_end_struct(visitor, NULL);
      visit_free(visitor);
      if (err) {
@@ -190,6 +276,18 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
      }
  }
 
+    object_property_iter_init(&iter, obj);
+
+    while ((idregprop = object_property_iter_next(&iter))) {
+        QObject *value;
+
+        if (!g_str_has_prefix(idregprop->name, "SYSREG_")) {
+            continue;
+        }
+        value = object_property_get_qobject(obj, idregprop->name, &error_abort);
+        qdict_put_obj(qdict_out, idregprop->name, value);
+    }
+
  if (!qdict_size(qdict_out)) {
      qobject_unref(qdict_out);
  } else {
Signature · 1 line
2.53.0
#48 lore raw
In reply to Eric Auger
Quoted 153 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

This series enhances the current host KVM model with capability to set writable ID reg fields.

Since v6.7 kernel, KVM/arm allows the userspace to overwrite the values of a subset of ID regs. The list of writable fields continues to grow. The feature ID range is defined as the AArch64 System register space with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}.

The end goal is to get more flexibility when migrating guests between different host hardware.

QEMU retrieves the writable ID fields from KVM UAPI [1] and match them against a generated description of ID regs and their named fields that stem from AARCHMRS Registers.json file. Current description is based on latest 2026-03 edition. The content of the generated files was compared against kernel linux/arch/arm64/tools/sysreg file. It is not straightforward to have unit tests for python scripts as there are many cases for field extraction.

For each writable named field a uint64 property is created following the "SYSREG_<REG>_<FIELD>" naming convention. REG and FIELD names are those described in ARM ARM Reference manual.

The list of SYSREG_ID properties can be retrieved through the qmp monitor using query-cpu-model-expansion [2].

For the record, Jinqian was able to migrate between Hisilicon KunPeng HIP09 and HIP12 chips with this series using this kind of command:

-cpu host,pauth=off,pmu=off,sve=off,\
SYSREG_ID_AA64PFR1_EL1_NMI=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LS64=0x0,\
SYSREG_ID_AA64ISAR1_EL1_XS=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LRCPC=0x2,\
SYSREG_ID_AA64ISAR2_EL1_RPRFM=0x0,\
SYSREG_ID_AA64ISAR2_EL1_CLRBHB=0x0,\
SYSREG_ID_AA64ISAR2_EL1_PAC_frac=0x0,\
SYSREG_ID_AA64ISAR2_EL1_BC=0x0,\
SYSREG_ID_AA64ISAR2_EL1_RPRES=0x0,\
SYSREG_ID_AA64ISAR2_EL1_WFxT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_FGT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_BigEnd=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ECBHB=0x0,\
SYSREG_ID_AA64MMFR1_EL1_CMOW=0x0,\
SYSREG_ID_AA64MMFR1_EL1_TIDCP1=0x0,\
SYSREG_ID_AA64MMFR1_EL1_nTLBPA=0x0,\
SYSREG_ID_AA64MMFR1_EL1_AFP=0x0,\
SYSREG_ID_AA64MMFR1_EL1_HCX=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ETS=0x0,\
SYSREG_ID_AA64MMFR1_EL1_PAN=0x2,\
SYSREG_ID_AA64MMFR1_EL1_HAFDBS=0x2,\
SYSREG_ID_AA64MMFR2_EL1_CnP=0x0,\
SYSREG_ID_AA64MMFR3_EL1_TCRX=0x0,\
SYSREG_ID_AA64DFR0_EL1_PMUVer=0x6,\
SYSREG_ID_AA64DFR0_EL1_DebugVer=0x9,\
SYSREG_ID_AA64DFR0_EL1_DoubleLock=0xf,\
SYSREG_ID_AA64ZFR0_EL1_F64MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_F32MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SM4=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SHA3=0x0,\
SYSREG_ID_AA64ZFR0_EL1_BitPerm=0x0,\
SYSREG_ID_AA64ZFR0_EL1_AES=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SVEver=0x0,\
SYSREG_CTR_EL0_L1Ip=0x2 \

Connie & Eric

This series can be found at:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_eauger_qemu_tree_arm-2Dcpu-2Dmodel-2Dv7&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=xh5u7-r6auXiWQScafdj-0wW70mXB4FhClh58GryHmExkx8uZN-h9j4B2c90Lowd&s=Ro4v_mjoNaLsznyxm781lzXBcRtXTudjibmgIhoJsNM&e=

History:
--------
v6 -> v7:
- query-cpu-model-expansion now applies the sysreg props onto a scratch vcpu (POC) allowing a finer validation of settings (not perfect though as init may be revisited depending on settings)
- Properly handle ValueRange (Khushit)
- Remove cpu parameter in get_host_cpu_idregs call chain (Khushit)

v5 -> v6:
v6 is mostly for Khushit to see how he may work on top of this series. It fulfills some of his requirements:
- Upon Khushit request I added description for enum values and reserved fields
- set_sysreg_prop checks the input value against enum values if any
- writable_bitmap is now dispatched into the sysreg descripton and not stored in vcpu state anymore (besides it is VM wide)
- implemented write for qmp inspection. However this is not yet checked against KVM. That's the next step I think, ie. instantiate a scratch vcpu to test if the field value can be applied?
- if some inconsistencies between writable mask and idreg field, reserved fields only produce traces
- this version does not yet fix some reported issues about host supporting nested virt. I will further sync with Khushit. so this is definitively not candidate to be applied, hence the RFC tag.

Cornelia Huck (3):
target/arm/kvm: Retrieve writable ID reg map arm/cpu-features: document ID reg properties
arm-qmp-cmds: introspection for ID register props

Eric Auger (14):
scripts: introduce scripts/update-aarch64-cpu-sysregs-header.py target/arm/cpu-sysregs.h.inc: Sort by name alphabetical order target/arm/cpu-sysregs.h.inc: Update with automatic generation arm/cpu: Add infra to handle generated ID register definitions
scripts: Introduce scripts/aarch64_sysreg_helpers module
scripts: Introduce scripts/update-aarch64-cpu-sysreg-properties.py target/arm/cpu-idregs.h.inc: generate with script target/arm/cpu-idregs.h.inc: Generate enum values arm/kvm: Initialize all writable ID registers from host target/arm/kvm: Introduce kvm_arm_expose_idreg_properties target/arm/cpu: Expose writable ID reg field properties on the kvm
host vcpu model
target/arm/cpu-idregs.h.inc: Generate reserved fields target/arm/kvm: Ignore and trace unexpected writable reserved fields target/arm/kvm: add utility to write idregs in scratch vcpu

Shaju Abraham (1):
target/arm/cpu_idregs: generate tables for Arm64 ID registers and
fields

docs/system/arm/cpu-features.rst              |  106 +-
target/arm/cpu-idregs.h                       |   41 +
target/arm/kvm_arm.h                          |   13 +
target/arm/cpu-idregs.h.inc                   | 2164 +++++++++++++++++
target/arm/cpu-sysregs.h.inc                  |   57 +-
target/arm/arm-qmp-cmds.c                     |   98 +
target/arm/cpu-idregs.c                       |   96 +
target/arm/cpu64.c                            |    5 +
target/arm/kvm-stub.c                         |    6 +
target/arm/kvm.c                              |  360 ++-
scripts/aarch64_sysreg_helpers.py             |  109 +
.../update-aarch64-cpu-sysreg-properties.py   |  290 +++
scripts/update-aarch64-cpu-sysregs-header.py  |   51 +
target/arm/meson.build                        |    1 +
target/arm/trace-events                       |    8 +
15 files changed, 3373 insertions(+), 32 deletions(-)
Quoted 10 lines

create mode 100644 target/arm/cpu-idregs.h
create mode 100644 target/arm/cpu-idregs.h.inc
create mode 100644 target/arm/cpu-idregs.c
create mode 100644 scripts/aarch64_sysreg_helpers.py create mode 100644 scripts/update-aarch64-cpu-sysreg-properties.py create mode 100755 scripts/update-aarch64-cpu-sysregs-header.py

Signature · 1 line
2.53.0

Hi,

On my box the build is failing with:
[97/2192] Linking target qemu-system-arm
FAILED: qemu-system-arm
cc @qemu-system-arm.rsp
/usr/bin/ld: libsystem_arm.a.p/target_arm_arm-qmp-cmds.c.o: in function `qmp_query_cpu_model_expansion':
/home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:144:(.text+0x4d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:145:(.text+0x4e4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:151:(.text+0x514): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:168:(.text+0x554): undefined reference to kvm_arm_create_scratch_host_vcpu' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:152:(.text+0x7d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:247:(.text+0x8f4): undefined reference to kvm_arm_destroy_scratch_host_vcpu'
collect2: error: ld returned 1 exit status

#49 lore raw
Quoted 170 lines · Khushit Shah
Quoted 154 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

This series enhances the current host KVM model with capability to set writable ID reg fields.

Since v6.7 kernel, KVM/arm allows the userspace to overwrite the values of a subset of ID regs. The list of writable fields continues to grow. The feature ID range is defined as the AArch64 System register space with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}.

The end goal is to get more flexibility when migrating guests between different host hardware.

QEMU retrieves the writable ID fields from KVM UAPI [1] and match them against a generated description of ID regs and their named fields that stem from AARCHMRS Registers.json file. Current description is based on latest 2026-03 edition. The content of the generated files was compared against kernel linux/arch/arm64/tools/sysreg file. It is not straightforward to have unit tests for python scripts as there are many cases for field extraction.

For each writable named field a uint64 property is created following the "SYSREG_<REG>_<FIELD>" naming convention. REG and FIELD names are those described in ARM ARM Reference manual.

The list of SYSREG_ID properties can be retrieved through the qmp monitor using query-cpu-model-expansion [2].

For the record, Jinqian was able to migrate between Hisilicon KunPeng HIP09 and HIP12 chips with this series using this kind of command:

-cpu host,pauth=off,pmu=off,sve=off,\
SYSREG_ID_AA64PFR1_EL1_NMI=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LS64=0x0,\
SYSREG_ID_AA64ISAR1_EL1_XS=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LRCPC=0x2,\
SYSREG_ID_AA64ISAR2_EL1_RPRFM=0x0,\
SYSREG_ID_AA64ISAR2_EL1_CLRBHB=0x0,\
SYSREG_ID_AA64ISAR2_EL1_PAC_frac=0x0,\
SYSREG_ID_AA64ISAR2_EL1_BC=0x0,\
SYSREG_ID_AA64ISAR2_EL1_RPRES=0x0,\
SYSREG_ID_AA64ISAR2_EL1_WFxT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_FGT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_BigEnd=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ECBHB=0x0,\
SYSREG_ID_AA64MMFR1_EL1_CMOW=0x0,\
SYSREG_ID_AA64MMFR1_EL1_TIDCP1=0x0,\
SYSREG_ID_AA64MMFR1_EL1_nTLBPA=0x0,\
SYSREG_ID_AA64MMFR1_EL1_AFP=0x0,\
SYSREG_ID_AA64MMFR1_EL1_HCX=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ETS=0x0,\
SYSREG_ID_AA64MMFR1_EL1_PAN=0x2,\
SYSREG_ID_AA64MMFR1_EL1_HAFDBS=0x2,\
SYSREG_ID_AA64MMFR2_EL1_CnP=0x0,\
SYSREG_ID_AA64MMFR3_EL1_TCRX=0x0,\
SYSREG_ID_AA64DFR0_EL1_PMUVer=0x6,\
SYSREG_ID_AA64DFR0_EL1_DebugVer=0x9,\
SYSREG_ID_AA64DFR0_EL1_DoubleLock=0xf,\
SYSREG_ID_AA64ZFR0_EL1_F64MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_F32MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SM4=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SHA3=0x0,\
SYSREG_ID_AA64ZFR0_EL1_BitPerm=0x0,\
SYSREG_ID_AA64ZFR0_EL1_AES=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SVEver=0x0,\
SYSREG_CTR_EL0_L1Ip=0x2 \

Connie & Eric

This series can be found at:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_eauger_qemu_tree_arm-2Dcpu-2Dmodel-2Dv7&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=xh5u7-r6auXiWQScafdj-0wW70mXB4FhClh58GryHmExkx8uZN-h9j4B2c90Lowd&s=Ro4v_mjoNaLsznyxm781lzXBcRtXTudjibmgIhoJsNM&e=

History:
--------
v6 -> v7:
- query-cpu-model-expansion now applies the sysreg props onto a scratch vcpu (POC) allowing a finer validation of settings (not perfect though as init may be revisited depending on settings)
- Properly handle ValueRange (Khushit)
- Remove cpu parameter in get_host_cpu_idregs call chain (Khushit)

v5 -> v6:
v6 is mostly for Khushit to see how he may work on top of this series. It fulfills some of his requirements:
- Upon Khushit request I added description for enum values and reserved fields
- set_sysreg_prop checks the input value against enum values if any
- writable_bitmap is now dispatched into the sysreg descripton and not stored in vcpu state anymore (besides it is VM wide)
- implemented write for qmp inspection. However this is not yet checked against KVM. That's the next step I think, ie. instantiate a scratch vcpu to test if the field value can be applied?
- if some inconsistencies between writable mask and idreg field, reserved fields only produce traces
- this version does not yet fix some reported issues about host supporting nested virt. I will further sync with Khushit. so this is definitively not candidate to be applied, hence the RFC tag.

Cornelia Huck (3):
target/arm/kvm: Retrieve writable ID reg map
arm/cpu-features: document ID reg properties
arm-qmp-cmds: introspection for ID register props

Eric Auger (14):
scripts: introduce scripts/update-aarch64-cpu-sysregs-header.py target/arm/cpu-sysregs.h.inc: Sort by name alphabetical order target/arm/cpu-sysregs.h.inc: Update with automatic generation arm/cpu: Add infra to handle generated ID register definitions
scripts: Introduce scripts/aarch64_sysreg_helpers module
scripts: Introduce scripts/update-aarch64-cpu-sysreg-properties.py target/arm/cpu-idregs.h.inc: generate with script target/arm/cpu-idregs.h.inc: Generate enum values arm/kvm: Initialize all writable ID registers from host target/arm/kvm: Introduce kvm_arm_expose_idreg_properties target/arm/cpu: Expose writable ID reg field properties on the kvm
host vcpu model
target/arm/cpu-idregs.h.inc: Generate reserved fields target/arm/kvm: Ignore and trace unexpected writable reserved fields target/arm/kvm: add utility to write idregs in scratch vcpu

Shaju Abraham (1):
target/arm/cpu_idregs: generate tables for Arm64 ID registers and
fields

docs/system/arm/cpu-features.rst              |  106 +-
target/arm/cpu-idregs.h                       |   41 +
target/arm/kvm_arm.h                          |   13 +
target/arm/cpu-idregs.h.inc                   | 2164 +++++++++++++++++
target/arm/cpu-sysregs.h.inc                  |   57 +-
target/arm/arm-qmp-cmds.c                     |   98 +
target/arm/cpu-idregs.c                       |   96 +
target/arm/cpu64.c                            |    5 +
target/arm/kvm-stub.c                         |    6 +
target/arm/kvm.c                              |  360 ++-
scripts/aarch64_sysreg_helpers.py             |  109 +
.../update-aarch64-cpu-sysreg-properties.py   |  290 +++
scripts/update-aarch64-cpu-sysregs-header.py  |   51 +
target/arm/meson.build                        |    1 +
target/arm/trace-events                       |    8 +
15 files changed, 3373 insertions(+), 32 deletions(-)
Quoted 10 lines

create mode 100644 target/arm/cpu-idregs.h
create mode 100644 target/arm/cpu-idregs.h.inc
create mode 100644 target/arm/cpu-idregs.c
create mode 100644 scripts/aarch64_sysreg_helpers.py create mode 100644 scripts/update-aarch64-cpu-sysreg-properties.py create mode 100755 scripts/update-aarch64-cpu-sysregs-header.py

Signature · 1 line
2.53.0

Hi,

Quoted 12 lines

On my box the build is failing with:
[97/2192] Linking target qemu-system-arm
FAILED: qemu-system-arm
cc @qemu-system-arm.rsp
/usr/bin/ld: libsystem_arm.a.p/target_arm_arm-qmp-cmds.c.o: in function `qmp_query_cpu_model_expansion':
/home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:144:(.text+0x4d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:145:(.text+0x4e4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:151:(.text+0x514): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:168:(.text+0x554): undefined reference to kvm_arm_create_scratch_host_vcpu' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:152:(.text+0x7d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:247:(.text+0x8f4): undefined reference to kvm_arm_destroy_scratch_host_vcpu'
collect2: error: ld returned 1 exit status

If I add appropriate stubs, Following test fails:

  30/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test         ERROR            1.58s   killed by signal 6 SIGABRT
 126/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test                       ERROR           46.65s   killed by signal 6 SIGABRT
 426/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/arm-cpu-features               ERROR            0.51s   killed by signal 6 SIGABRT
 467/1079 qemu:qtest+qtest-arm / qtest-arm/arm-cpu-features                       ERROR            0.46s   killed by signal 6 SIGABRT
 966/1079 qemu:block / io-qcow2-161                                               ERROR            1.95s   exit status 1
author
#50 lore raw

Hi Khushit,

Quoted 181 lines · Khushit Shah
Quoted 168 lines · Khushit Shah
Quoted 154 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

This series enhances the current host KVM model with capability to set writable ID reg fields.

Since v6.7 kernel, KVM/arm allows the userspace to overwrite the values of a subset of ID regs. The list of writable fields continues to grow. The feature ID range is defined as the AArch64 System register space with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}.

The end goal is to get more flexibility when migrating guests between different host hardware.

QEMU retrieves the writable ID fields from KVM UAPI [1] and match them against a generated description of ID regs and their named fields that stem from AARCHMRS Registers.json file. Current description is based on latest 2026-03 edition. The content of the generated files was compared against kernel linux/arch/arm64/tools/sysreg file. It is not straightforward to have unit tests for python scripts as there are many cases for field extraction.

For each writable named field a uint64 property is created following the "SYSREG_<REG>_<FIELD>" naming convention. REG and FIELD names are those described in ARM ARM Reference manual.

The list of SYSREG_ID properties can be retrieved through the qmp monitor using query-cpu-model-expansion [2].

For the record, Jinqian was able to migrate between Hisilicon KunPeng HIP09 and HIP12 chips with this series using this kind of command:

-cpu host,pauth=off,pmu=off,sve=off,\
SYSREG_ID_AA64PFR1_EL1_NMI=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LS64=0x0,\
SYSREG_ID_AA64ISAR1_EL1_XS=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LRCPC=0x2,\
SYSREG_ID_AA64ISAR2_EL1_RPRFM=0x0,\
SYSREG_ID_AA64ISAR2_EL1_CLRBHB=0x0,\
SYSREG_ID_AA64ISAR2_EL1_PAC_frac=0x0,\
SYSREG_ID_AA64ISAR2_EL1_BC=0x0,\
SYSREG_ID_AA64ISAR2_EL1_RPRES=0x0,\
SYSREG_ID_AA64ISAR2_EL1_WFxT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_FGT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_BigEnd=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ECBHB=0x0,\
SYSREG_ID_AA64MMFR1_EL1_CMOW=0x0,\
SYSREG_ID_AA64MMFR1_EL1_TIDCP1=0x0,\
SYSREG_ID_AA64MMFR1_EL1_nTLBPA=0x0,\
SYSREG_ID_AA64MMFR1_EL1_AFP=0x0,\
SYSREG_ID_AA64MMFR1_EL1_HCX=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ETS=0x0,\
SYSREG_ID_AA64MMFR1_EL1_PAN=0x2,\
SYSREG_ID_AA64MMFR1_EL1_HAFDBS=0x2,\
SYSREG_ID_AA64MMFR2_EL1_CnP=0x0,\
SYSREG_ID_AA64MMFR3_EL1_TCRX=0x0,\
SYSREG_ID_AA64DFR0_EL1_PMUVer=0x6,\
SYSREG_ID_AA64DFR0_EL1_DebugVer=0x9,\
SYSREG_ID_AA64DFR0_EL1_DoubleLock=0xf,\
SYSREG_ID_AA64ZFR0_EL1_F64MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_F32MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SM4=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SHA3=0x0,\
SYSREG_ID_AA64ZFR0_EL1_BitPerm=0x0,\
SYSREG_ID_AA64ZFR0_EL1_AES=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SVEver=0x0,\
SYSREG_CTR_EL0_L1Ip=0x2 \

Connie & Eric

This series can be found at:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_eauger_qemu_tree_arm-2Dcpu-2Dmodel-2Dv7&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=xh5u7-r6auXiWQScafdj-0wW70mXB4FhClh58GryHmExkx8uZN-h9j4B2c90Lowd&s=Ro4v_mjoNaLsznyxm781lzXBcRtXTudjibmgIhoJsNM&e=

History:
--------
v6 -> v7:
- query-cpu-model-expansion now applies the sysreg props onto a scratch vcpu (POC) allowing a finer validation of settings (not perfect though as init may be revisited depending on settings)
- Properly handle ValueRange (Khushit)
- Remove cpu parameter in get_host_cpu_idregs call chain (Khushit)

v5 -> v6:
v6 is mostly for Khushit to see how he may work on top of this series. It fulfills some of his requirements:
- Upon Khushit request I added description for enum values and reserved fields
- set_sysreg_prop checks the input value against enum values if any
- writable_bitmap is now dispatched into the sysreg descripton and not stored in vcpu state anymore (besides it is VM wide)
- implemented write for qmp inspection. However this is not yet checked against KVM. That's the next step I think, ie. instantiate a scratch vcpu to test if the field value can be applied?
- if some inconsistencies between writable mask and idreg field, reserved fields only produce traces
- this version does not yet fix some reported issues about host supporting nested virt. I will further sync with Khushit. so this is definitively not candidate to be applied, hence the RFC tag.

Cornelia Huck (3):
target/arm/kvm: Retrieve writable ID reg map
arm/cpu-features: document ID reg properties
arm-qmp-cmds: introspection for ID register props

Eric Auger (14):
scripts: introduce scripts/update-aarch64-cpu-sysregs-header.py target/arm/cpu-sysregs.h.inc: Sort by name alphabetical order target/arm/cpu-sysregs.h.inc: Update with automatic generation arm/cpu: Add infra to handle generated ID register definitions
scripts: Introduce scripts/aarch64_sysreg_helpers module
scripts: Introduce scripts/update-aarch64-cpu-sysreg-properties.py target/arm/cpu-idregs.h.inc: generate with script target/arm/cpu-idregs.h.inc: Generate enum values arm/kvm: Initialize all writable ID registers from host target/arm/kvm: Introduce kvm_arm_expose_idreg_properties target/arm/cpu: Expose writable ID reg field properties on the kvm
host vcpu model
target/arm/cpu-idregs.h.inc: Generate reserved fields target/arm/kvm: Ignore and trace unexpected writable reserved fields target/arm/kvm: add utility to write idregs in scratch vcpu

Shaju Abraham (1):
target/arm/cpu_idregs: generate tables for Arm64 ID registers and
fields

docs/system/arm/cpu-features.rst              |  106 +-
target/arm/cpu-idregs.h                       |   41 +
target/arm/kvm_arm.h                          |   13 +
target/arm/cpu-idregs.h.inc                   | 2164 +++++++++++++++++
target/arm/cpu-sysregs.h.inc                  |   57 +-
target/arm/arm-qmp-cmds.c                     |   98 +
target/arm/cpu-idregs.c                       |   96 +
target/arm/cpu64.c                            |    5 +
target/arm/kvm-stub.c                         |    6 +
target/arm/kvm.c                              |  360 ++-
scripts/aarch64_sysreg_helpers.py             |  109 +
.../update-aarch64-cpu-sysreg-properties.py   |  290 +++
scripts/update-aarch64-cpu-sysregs-header.py  |   51 +
target/arm/meson.build                        |    1 +
target/arm/trace-events                       |    8 +
15 files changed, 3373 insertions(+), 32 deletions(-)
Quoted 10 lines

create mode 100644 target/arm/cpu-idregs.h
create mode 100644 target/arm/cpu-idregs.h.inc
create mode 100644 target/arm/cpu-idregs.c
create mode 100644 scripts/aarch64_sysreg_helpers.py create mode 100644 scripts/update-aarch64-cpu-sysreg-properties.py create mode 100755 scripts/update-aarch64-cpu-sysregs-header.py

Signature · 1 line
2.53.0

Hi,

Quoted 12 lines

On my box the build is failing with:
[97/2192] Linking target qemu-system-arm
FAILED: qemu-system-arm
cc @qemu-system-arm.rsp
/usr/bin/ld: libsystem_arm.a.p/target_arm_arm-qmp-cmds.c.o: in function `qmp_query_cpu_model_expansion':
/home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:144:(.text+0x4d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:145:(.text+0x4e4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:151:(.text+0x514): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:168:(.text+0x554): undefined reference to kvm_arm_create_scratch_host_vcpu' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:152:(.text+0x7d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:247:(.text+0x8f4): undefined reference to kvm_arm_destroy_scratch_host_vcpu'
collect2: error: ld returned 1 exit status

Quoted 7 lines

If I add appropriate stubs, Following test fails:

  30/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test         ERROR            1.58s   killed by signal 6 SIGABRT
 126/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test                       ERROR           46.65s   killed by signal 6 SIGABRT
 426/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/arm-cpu-features               ERROR            0.51s   killed by signal 6 SIGABRT
 467/1079 qemu:qtest+qtest-arm / qtest-arm/arm-cpu-features                       ERROR            0.46s   killed by signal 6 SIGABRT
 966/1079 qemu:block / io-qcow2-161                                               ERROR            1.95s   exit status 1

Thanks. I am currently working on it. Planning to respin this week

Eric

#51 lore raw
Quoted 200 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Hi Khushit,

Quoted 181 lines · Khushit Shah
Quoted 168 lines · Khushit Shah
Quoted 154 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

This series enhances the current host KVM model with capability to set writable ID reg fields.

Since v6.7 kernel, KVM/arm allows the userspace to overwrite the values of a subset of ID regs. The list of writable fields continues to grow. The feature ID range is defined as the AArch64 System register space with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}.

The end goal is to get more flexibility when migrating guests between different host hardware.

QEMU retrieves the writable ID fields from KVM UAPI [1] and match them against a generated description of ID regs and their named fields that stem from AARCHMRS Registers.json file. Current description is based on latest 2026-03 edition. The content of the generated files was compared against kernel linux/arch/arm64/tools/sysreg file. It is not straightforward to have unit tests for python scripts as there are many cases for field extraction.

For each writable named field a uint64 property is created following the "SYSREG_<REG>_<FIELD>" naming convention. REG and FIELD names are those described in ARM ARM Reference manual.

The list of SYSREG_ID properties can be retrieved through the qmp monitor using query-cpu-model-expansion [2].

For the record, Jinqian was able to migrate between Hisilicon KunPeng HIP09 and HIP12 chips with this series using this kind of command:

-cpu host,pauth=off,pmu=off,sve=off,\
SYSREG_ID_AA64PFR1_EL1_NMI=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LS64=0x0,\
SYSREG_ID_AA64ISAR1_EL1_XS=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LRCPC=0x2,\
SYSREG_ID_AA64ISAR2_EL1_RPRFM=0x0,\
SYSREG_ID_AA64ISAR2_EL1_CLRBHB=0x0,\
SYSREG_ID_AA64ISAR2_EL1_PAC_frac=0x0,\
SYSREG_ID_AA64ISAR2_EL1_BC=0x0,\
SYSREG_ID_AA64ISAR2_EL1_RPRES=0x0,\
SYSREG_ID_AA64ISAR2_EL1_WFxT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_FGT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_BigEnd=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ECBHB=0x0,\
SYSREG_ID_AA64MMFR1_EL1_CMOW=0x0,\
SYSREG_ID_AA64MMFR1_EL1_TIDCP1=0x0,\
SYSREG_ID_AA64MMFR1_EL1_nTLBPA=0x0,\
SYSREG_ID_AA64MMFR1_EL1_AFP=0x0,\
SYSREG_ID_AA64MMFR1_EL1_HCX=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ETS=0x0,\
SYSREG_ID_AA64MMFR1_EL1_PAN=0x2,\
SYSREG_ID_AA64MMFR1_EL1_HAFDBS=0x2,\
SYSREG_ID_AA64MMFR2_EL1_CnP=0x0,\
SYSREG_ID_AA64MMFR3_EL1_TCRX=0x0,\
SYSREG_ID_AA64DFR0_EL1_PMUVer=0x6,\
SYSREG_ID_AA64DFR0_EL1_DebugVer=0x9,\
SYSREG_ID_AA64DFR0_EL1_DoubleLock=0xf,\
SYSREG_ID_AA64ZFR0_EL1_F64MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_F32MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SM4=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SHA3=0x0,\
SYSREG_ID_AA64ZFR0_EL1_BitPerm=0x0,\
SYSREG_ID_AA64ZFR0_EL1_AES=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SVEver=0x0,\
SYSREG_CTR_EL0_L1Ip=0x2 \

Connie & Eric

This series can be found at:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_eauger_qemu_tree_arm-2Dcpu-2Dmodel-2Dv7&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=xh5u7-r6auXiWQScafdj-0wW70mXB4FhClh58GryHmExkx8uZN-h9j4B2c90Lowd&s=Ro4v_mjoNaLsznyxm781lzXBcRtXTudjibmgIhoJsNM&e=

History:
--------
v6 -> v7:
- query-cpu-model-expansion now applies the sysreg props onto a scratch vcpu (POC) allowing a finer validation of settings (not perfect though as init may be revisited depending on settings)
- Properly handle ValueRange (Khushit)
- Remove cpu parameter in get_host_cpu_idregs call chain (Khushit)

v5 -> v6:
v6 is mostly for Khushit to see how he may work on top of this series. It fulfills some of his requirements:
- Upon Khushit request I added description for enum values and reserved fields
- set_sysreg_prop checks the input value against enum values if any
- writable_bitmap is now dispatched into the sysreg descripton and not stored in vcpu state anymore (besides it is VM wide)
- implemented write for qmp inspection. However this is not yet checked against KVM. That's the next step I think, ie. instantiate a scratch vcpu to test if the field value can be applied?
- if some inconsistencies between writable mask and idreg field, reserved fields only produce traces
- this version does not yet fix some reported issues about host supporting nested virt. I will further sync with Khushit. so this is definitively not candidate to be applied, hence the RFC tag.

Cornelia Huck (3):
target/arm/kvm: Retrieve writable ID reg map
arm/cpu-features: document ID reg properties
arm-qmp-cmds: introspection for ID register props

Eric Auger (14):
scripts: introduce scripts/update-aarch64-cpu-sysregs-header.py target/arm/cpu-sysregs.h.inc: Sort by name alphabetical order target/arm/cpu-sysregs.h.inc: Update with automatic generation arm/cpu: Add infra to handle generated ID register definitions
scripts: Introduce scripts/aarch64_sysreg_helpers module
scripts: Introduce scripts/update-aarch64-cpu-sysreg-properties.py target/arm/cpu-idregs.h.inc: generate with script target/arm/cpu-idregs.h.inc: Generate enum values arm/kvm: Initialize all writable ID registers from host target/arm/kvm: Introduce kvm_arm_expose_idreg_properties target/arm/cpu: Expose writable ID reg field properties on the kvm
host vcpu model
target/arm/cpu-idregs.h.inc: Generate reserved fields target/arm/kvm: Ignore and trace unexpected writable reserved fields target/arm/kvm: add utility to write idregs in scratch vcpu

Shaju Abraham (1):
target/arm/cpu_idregs: generate tables for Arm64 ID registers and
fields

docs/system/arm/cpu-features.rst              |  106 +-
target/arm/cpu-idregs.h                       |   41 +
target/arm/kvm_arm.h                          |   13 +
target/arm/cpu-idregs.h.inc                   | 2164 +++++++++++++++++
target/arm/cpu-sysregs.h.inc                  |   57 +-
target/arm/arm-qmp-cmds.c                     |   98 +
target/arm/cpu-idregs.c                       |   96 +
target/arm/cpu64.c                            |    5 +
target/arm/kvm-stub.c                         |    6 +
target/arm/kvm.c                              |  360 ++-
scripts/aarch64_sysreg_helpers.py             |  109 +
.../update-aarch64-cpu-sysreg-properties.py   |  290 +++
scripts/update-aarch64-cpu-sysregs-header.py  |   51 +
target/arm/meson.build                        |    1 +
target/arm/trace-events                       |    8 +
15 files changed, 3373 insertions(+), 32 deletions(-)
Quoted 10 lines

create mode 100644 target/arm/cpu-idregs.h
create mode 100644 target/arm/cpu-idregs.h.inc
create mode 100644 target/arm/cpu-idregs.c
create mode 100644 scripts/aarch64_sysreg_helpers.py create mode 100644 scripts/update-aarch64-cpu-sysreg-properties.py create mode 100755 scripts/update-aarch64-cpu-sysregs-header.py

Signature · 1 line
2.53.0

Hi,

Quoted 12 lines

On my box the build is failing with:
[97/2192] Linking target qemu-system-arm
FAILED: qemu-system-arm
cc @qemu-system-arm.rsp
/usr/bin/ld: libsystem_arm.a.p/target_arm_arm-qmp-cmds.c.o: in function `qmp_query_cpu_model_expansion':
/home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:144:(.text+0x4d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:145:(.text+0x4e4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:151:(.text+0x514): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:168:(.text+0x554): undefined reference to kvm_arm_create_scratch_host_vcpu' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:152:(.text+0x7d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:247:(.text+0x8f4): undefined reference to kvm_arm_destroy_scratch_host_vcpu'
collect2: error: ld returned 1 exit status

Quoted 7 lines

If I add appropriate stubs, Following test fails:

 30/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test         ERROR            1.58s   killed by signal 6 SIGABRT
126/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test                       ERROR           46.65s   killed by signal 6 SIGABRT
426/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/arm-cpu-features               ERROR            0.51s   killed by signal 6 SIGABRT
467/1079 qemu:qtest+qtest-arm / qtest-arm/arm-cpu-features                       ERROR            0.46s   killed by signal 6 SIGABRT
966/1079 qemu:block / io-qcow2-161                                               ERROR            1.95s   exit status 1
Quoted 4 lines

Thanks. I am currently working on it. Planning to respin this week

Eric

Thanks, will base my v4 based on that.

Warm Regards,
Khushit

author
#52 lore raw
In reply to Khushit Shah
Quoted 181 lines · Khushit Shah
Quoted 168 lines · Khushit Shah
Quoted 154 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

This series enhances the current host KVM model with capability to set writable ID reg fields.

Since v6.7 kernel, KVM/arm allows the userspace to overwrite the values of a subset of ID regs. The list of writable fields continues to grow. The feature ID range is defined as the AArch64 System register space with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}.

The end goal is to get more flexibility when migrating guests between different host hardware.

QEMU retrieves the writable ID fields from KVM UAPI [1] and match them against a generated description of ID regs and their named fields that stem from AARCHMRS Registers.json file. Current description is based on latest 2026-03 edition. The content of the generated files was compared against kernel linux/arch/arm64/tools/sysreg file. It is not straightforward to have unit tests for python scripts as there are many cases for field extraction.

For each writable named field a uint64 property is created following the "SYSREG_<REG>_<FIELD>" naming convention. REG and FIELD names are those described in ARM ARM Reference manual.

The list of SYSREG_ID properties can be retrieved through the qmp monitor using query-cpu-model-expansion [2].

For the record, Jinqian was able to migrate between Hisilicon KunPeng HIP09 and HIP12 chips with this series using this kind of command:

-cpu host,pauth=off,pmu=off,sve=off,\
SYSREG_ID_AA64PFR1_EL1_NMI=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LS64=0x0,\
SYSREG_ID_AA64ISAR1_EL1_XS=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LRCPC=0x2,\
SYSREG_ID_AA64ISAR2_EL1_RPRFM=0x0,\
SYSREG_ID_AA64ISAR2_EL1_CLRBHB=0x0,\
SYSREG_ID_AA64ISAR2_EL1_PAC_frac=0x0,\
SYSREG_ID_AA64ISAR2_EL1_BC=0x0,\
SYSREG_ID_AA64ISAR2_EL1_RPRES=0x0,\
SYSREG_ID_AA64ISAR2_EL1_WFxT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_FGT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_BigEnd=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ECBHB=0x0,\
SYSREG_ID_AA64MMFR1_EL1_CMOW=0x0,\
SYSREG_ID_AA64MMFR1_EL1_TIDCP1=0x0,\
SYSREG_ID_AA64MMFR1_EL1_nTLBPA=0x0,\
SYSREG_ID_AA64MMFR1_EL1_AFP=0x0,\
SYSREG_ID_AA64MMFR1_EL1_HCX=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ETS=0x0,\
SYSREG_ID_AA64MMFR1_EL1_PAN=0x2,\
SYSREG_ID_AA64MMFR1_EL1_HAFDBS=0x2,\
SYSREG_ID_AA64MMFR2_EL1_CnP=0x0,\
SYSREG_ID_AA64MMFR3_EL1_TCRX=0x0,\
SYSREG_ID_AA64DFR0_EL1_PMUVer=0x6,\
SYSREG_ID_AA64DFR0_EL1_DebugVer=0x9,\
SYSREG_ID_AA64DFR0_EL1_DoubleLock=0xf,\
SYSREG_ID_AA64ZFR0_EL1_F64MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_F32MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SM4=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SHA3=0x0,\
SYSREG_ID_AA64ZFR0_EL1_BitPerm=0x0,\
SYSREG_ID_AA64ZFR0_EL1_AES=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SVEver=0x0,\
SYSREG_CTR_EL0_L1Ip=0x2 \

Connie & Eric

This series can be found at:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_eauger_qemu_tree_arm-2Dcpu-2Dmodel-2Dv7&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=xh5u7-r6auXiWQScafdj-0wW70mXB4FhClh58GryHmExkx8uZN-h9j4B2c90Lowd&s=Ro4v_mjoNaLsznyxm781lzXBcRtXTudjibmgIhoJsNM&e=

History:
--------
v6 -> v7:
- query-cpu-model-expansion now applies the sysreg props onto a scratch vcpu (POC) allowing a finer validation of settings (not perfect though as init may be revisited depending on settings)
- Properly handle ValueRange (Khushit)
- Remove cpu parameter in get_host_cpu_idregs call chain (Khushit)

v5 -> v6:
v6 is mostly for Khushit to see how he may work on top of this series. It fulfills some of his requirements:
- Upon Khushit request I added description for enum values and reserved fields
- set_sysreg_prop checks the input value against enum values if any
- writable_bitmap is now dispatched into the sysreg descripton and not stored in vcpu state anymore (besides it is VM wide)
- implemented write for qmp inspection. However this is not yet checked against KVM. That's the next step I think, ie. instantiate a scratch vcpu to test if the field value can be applied?
- if some inconsistencies between writable mask and idreg field, reserved fields only produce traces
- this version does not yet fix some reported issues about host supporting nested virt. I will further sync with Khushit. so this is definitively not candidate to be applied, hence the RFC tag.

Cornelia Huck (3):
target/arm/kvm: Retrieve writable ID reg map
arm/cpu-features: document ID reg properties
arm-qmp-cmds: introspection for ID register props

Eric Auger (14):
scripts: introduce scripts/update-aarch64-cpu-sysregs-header.py target/arm/cpu-sysregs.h.inc: Sort by name alphabetical order target/arm/cpu-sysregs.h.inc: Update with automatic generation arm/cpu: Add infra to handle generated ID register definitions
scripts: Introduce scripts/aarch64_sysreg_helpers module
scripts: Introduce scripts/update-aarch64-cpu-sysreg-properties.py target/arm/cpu-idregs.h.inc: generate with script target/arm/cpu-idregs.h.inc: Generate enum values arm/kvm: Initialize all writable ID registers from host target/arm/kvm: Introduce kvm_arm_expose_idreg_properties target/arm/cpu: Expose writable ID reg field properties on the kvm
host vcpu model
target/arm/cpu-idregs.h.inc: Generate reserved fields target/arm/kvm: Ignore and trace unexpected writable reserved fields target/arm/kvm: add utility to write idregs in scratch vcpu

Shaju Abraham (1):
target/arm/cpu_idregs: generate tables for Arm64 ID registers and
fields

docs/system/arm/cpu-features.rst              |  106 +-
target/arm/cpu-idregs.h                       |   41 +
target/arm/kvm_arm.h                          |   13 +
target/arm/cpu-idregs.h.inc                   | 2164 +++++++++++++++++
target/arm/cpu-sysregs.h.inc                  |   57 +-
target/arm/arm-qmp-cmds.c                     |   98 +
target/arm/cpu-idregs.c                       |   96 +
target/arm/cpu64.c                            |    5 +
target/arm/kvm-stub.c                         |    6 +
target/arm/kvm.c                              |  360 ++-
scripts/aarch64_sysreg_helpers.py             |  109 +
.../update-aarch64-cpu-sysreg-properties.py   |  290 +++
scripts/update-aarch64-cpu-sysregs-header.py  |   51 +
target/arm/meson.build                        |    1 +
target/arm/trace-events                       |    8 +
15 files changed, 3373 insertions(+), 32 deletions(-)
Quoted 10 lines

create mode 100644 target/arm/cpu-idregs.h
create mode 100644 target/arm/cpu-idregs.h.inc
create mode 100644 target/arm/cpu-idregs.c
create mode 100644 scripts/aarch64_sysreg_helpers.py create mode 100644 scripts/update-aarch64-cpu-sysreg-properties.py create mode 100755 scripts/update-aarch64-cpu-sysregs-header.py

Signature · 1 line
2.53.0

Hi,

Quoted 12 lines

On my box the build is failing with:
[97/2192] Linking target qemu-system-arm
FAILED: qemu-system-arm
cc @qemu-system-arm.rsp
/usr/bin/ld: libsystem_arm.a.p/target_arm_arm-qmp-cmds.c.o: in function `qmp_query_cpu_model_expansion':
/home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:144:(.text+0x4d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:145:(.text+0x4e4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:151:(.text+0x514): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:168:(.text+0x554): undefined reference to kvm_arm_create_scratch_host_vcpu' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:152:(.text+0x7d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:247:(.text+0x8f4): undefined reference to kvm_arm_destroy_scratch_host_vcpu'
collect2: error: ld returned 1 exit status

Quoted 5 lines

If I add appropriate stubs, Following test fails:

  30/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test         ERROR            1.58s   killed by signal 6 SIGABRT
 126/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test                       ERROR           46.65s   killed by signal 6 SIGABRT
 426/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/arm-cpu-features               ERROR            0.51s   killed by signal 6 SIGABRT
 467/1079 qemu:qtest+qtest-arm / qtest-arm/arm-cpu-features                       ERROR            0.46s   killed by signal 6 SIGABRT

all the above are fixed now.

Quoted 1 line

966/1079 qemu:block / io-qcow2-161 ERROR 1.95s exit status 1

this one looks unrelated to this series. I did not encounter it.

Thanks

Eric

Quoted 1 line
#53 lore raw
Quoted 193 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Quoted 181 lines · Khushit Shah
Quoted 180 lines · Khushit Shah
Quoted 154 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

This series enhances the current host KVM model with capability to set writable ID reg fields.

Since v6.7 kernel, KVM/arm allows the userspace to overwrite the values of a subset of ID regs. The list of writable fields continues to grow. The feature ID range is defined as the AArch64 System register space with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}.

The end goal is to get more flexibility when migrating guests between different host hardware.

QEMU retrieves the writable ID fields from KVM UAPI [1] and match them against a generated description of ID regs and their named fields that stem from AARCHMRS Registers.json file. Current description is based on latest 2026-03 edition. The content of the generated files was compared against kernel linux/arch/arm64/tools/sysreg file. It is not straightforward to have unit tests for python scripts as there are many cases for field extraction.

For each writable named field a uint64 property is created following the "SYSREG_<REG>_<FIELD>" naming convention. REG and FIELD names are those described in ARM ARM Reference manual.

The list of SYSREG_ID properties can be retrieved through the qmp monitor using query-cpu-model-expansion [2].

For the record, Jinqian was able to migrate between Hisilicon KunPeng HIP09 and HIP12 chips with this series using this kind of command:

-cpu host,pauth=off,pmu=off,sve=off,\
SYSREG_ID_AA64PFR1_EL1_NMI=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LS64=0x0,\
SYSREG_ID_AA64ISAR1_EL1_XS=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LRCPC=0x2,\
SYSREG_ID_AA64ISAR2_EL1_RPRFM=0x0,\
SYSREG_ID_AA64ISAR2_EL1_CLRBHB=0x0,\
SYSREG_ID_AA64ISAR2_EL1_PAC_frac=0x0,\
SYSREG_ID_AA64ISAR2_EL1_BC=0x0,\
SYSREG_ID_AA64ISAR2_EL1_RPRES=0x0,\
SYSREG_ID_AA64ISAR2_EL1_WFxT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_FGT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_BigEnd=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ECBHB=0x0,\
SYSREG_ID_AA64MMFR1_EL1_CMOW=0x0,\
SYSREG_ID_AA64MMFR1_EL1_TIDCP1=0x0,\
SYSREG_ID_AA64MMFR1_EL1_nTLBPA=0x0,\
SYSREG_ID_AA64MMFR1_EL1_AFP=0x0,\
SYSREG_ID_AA64MMFR1_EL1_HCX=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ETS=0x0,\
SYSREG_ID_AA64MMFR1_EL1_PAN=0x2,\
SYSREG_ID_AA64MMFR1_EL1_HAFDBS=0x2,\
SYSREG_ID_AA64MMFR2_EL1_CnP=0x0,\
SYSREG_ID_AA64MMFR3_EL1_TCRX=0x0,\
SYSREG_ID_AA64DFR0_EL1_PMUVer=0x6,\
SYSREG_ID_AA64DFR0_EL1_DebugVer=0x9,\
SYSREG_ID_AA64DFR0_EL1_DoubleLock=0xf,\
SYSREG_ID_AA64ZFR0_EL1_F64MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_F32MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SM4=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SHA3=0x0,\
SYSREG_ID_AA64ZFR0_EL1_BitPerm=0x0,\
SYSREG_ID_AA64ZFR0_EL1_AES=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SVEver=0x0,\
SYSREG_CTR_EL0_L1Ip=0x2 \

Connie & Eric

This series can be found at:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_eauger_qemu_tree_arm-2Dcpu-2Dmodel-2Dv7&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=xh5u7-r6auXiWQScafdj-0wW70mXB4FhClh58GryHmExkx8uZN-h9j4B2c90Lowd&s=Ro4v_mjoNaLsznyxm781lzXBcRtXTudjibmgIhoJsNM&e=

History:
--------
v6 -> v7:
- query-cpu-model-expansion now applies the sysreg props onto a scratch vcpu (POC) allowing a finer validation of settings (not perfect though as init may be revisited depending on settings)
- Properly handle ValueRange (Khushit)
- Remove cpu parameter in get_host_cpu_idregs call chain (Khushit)

v5 -> v6:
v6 is mostly for Khushit to see how he may work on top of this series. It fulfills some of his requirements:
- Upon Khushit request I added description for enum values and reserved fields
- set_sysreg_prop checks the input value against enum values if any
- writable_bitmap is now dispatched into the sysreg descripton and not stored in vcpu state anymore (besides it is VM wide)
- implemented write for qmp inspection. However this is not yet checked against KVM. That's the next step I think, ie. instantiate a scratch vcpu to test if the field value can be applied?
- if some inconsistencies between writable mask and idreg field, reserved fields only produce traces
- this version does not yet fix some reported issues about host supporting nested virt. I will further sync with Khushit. so this is definitively not candidate to be applied, hence the RFC tag.

Cornelia Huck (3):
target/arm/kvm: Retrieve writable ID reg map
arm/cpu-features: document ID reg properties
arm-qmp-cmds: introspection for ID register props

Eric Auger (14):
scripts: introduce scripts/update-aarch64-cpu-sysregs-header.py target/arm/cpu-sysregs.h.inc: Sort by name alphabetical order target/arm/cpu-sysregs.h.inc: Update with automatic generation arm/cpu: Add infra to handle generated ID register definitions
scripts: Introduce scripts/aarch64_sysreg_helpers module
scripts: Introduce scripts/update-aarch64-cpu-sysreg-properties.py target/arm/cpu-idregs.h.inc: generate with script target/arm/cpu-idregs.h.inc: Generate enum values arm/kvm: Initialize all writable ID registers from host target/arm/kvm: Introduce kvm_arm_expose_idreg_properties target/arm/cpu: Expose writable ID reg field properties on the kvm
host vcpu model
target/arm/cpu-idregs.h.inc: Generate reserved fields target/arm/kvm: Ignore and trace unexpected writable reserved fields target/arm/kvm: add utility to write idregs in scratch vcpu

Shaju Abraham (1):
target/arm/cpu_idregs: generate tables for Arm64 ID registers and
fields

docs/system/arm/cpu-features.rst              |  106 +-
target/arm/cpu-idregs.h                       |   41 +
target/arm/kvm_arm.h                          |   13 +
target/arm/cpu-idregs.h.inc                   | 2164 +++++++++++++++++
target/arm/cpu-sysregs.h.inc                  |   57 +-
target/arm/arm-qmp-cmds.c                     |   98 +
target/arm/cpu-idregs.c                       |   96 +
target/arm/cpu64.c                            |    5 +
target/arm/kvm-stub.c                         |    6 +
target/arm/kvm.c                              |  360 ++-
scripts/aarch64_sysreg_helpers.py             |  109 +
.../update-aarch64-cpu-sysreg-properties.py   |  290 +++
scripts/update-aarch64-cpu-sysregs-header.py  |   51 +
target/arm/meson.build                        |    1 +
target/arm/trace-events                       |    8 +
15 files changed, 3373 insertions(+), 32 deletions(-)
Quoted 10 lines

create mode 100644 target/arm/cpu-idregs.h
create mode 100644 target/arm/cpu-idregs.h.inc
create mode 100644 target/arm/cpu-idregs.c
create mode 100644 scripts/aarch64_sysreg_helpers.py create mode 100644 scripts/update-aarch64-cpu-sysreg-properties.py create mode 100755 scripts/update-aarch64-cpu-sysregs-header.py

Signature · 1 line
2.53.0

Hi,

On my box the build is failing with:
[97/2192] Linking target qemu-system-arm
FAILED: qemu-system-arm
cc @qemu-system-arm.rsp
/usr/bin/ld: libsystem_arm.a.p/target_arm_arm-qmp-cmds.c.o: in function `qmp_query_cpu_model_expansion':
/home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:144:(.text+0x4d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:145:(.text+0x4e4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:151:(.text+0x514): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:168:(.text+0x554): undefined reference to kvm_arm_create_scratch_host_vcpu' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:152:(.text+0x7d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:247:(.text+0x8f4): undefined reference to kvm_arm_destroy_scratch_host_vcpu'
collect2: error: ld returned 1 exit status

Quoted 6 lines
Quoted 5 lines

If I add appropriate stubs, Following test fails:

 30/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test         ERROR            1.58s   killed by signal 6 SIGABRT
126/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test                       ERROR           46.65s   killed by signal 6 SIGABRT
426/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/arm-cpu-features               ERROR            0.51s   killed by signal 6 SIGABRT
467/1079 qemu:qtest+qtest-arm / qtest-arm/arm-cpu-features                       ERROR            0.46s   killed by signal 6 SIGABRT

all the above are fixed now.

Is it available on the same GitHub repo?

Also may I know what are your thoughts on cpu-model-expansion schematics?

Quoted 2 lines
Quoted 1 line

966/1079 qemu:block / io-qcow2-161 ERROR 1.95s exit status 1

this one looks unrelated to this series. I did not encounter it.

Acked.

Quoted 3 lines

Thanks

Eric

author
#54 lore raw
Quoted 190 lines · Khushit Shah
Quoted 190 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

Quoted 179 lines · Khushit Shah
Quoted 179 lines · Khushit Shah
Quoted 154 lines · Eric Auger

!-------------------------------------------------------------------|
CAUTION: External Email

|-------------------------------------------------------------------!

This series enhances the current host KVM model with capability to set writable ID reg fields.

Since v6.7 kernel, KVM/arm allows the userspace to overwrite the values of a subset of ID regs. The list of writable fields continues to grow. The feature ID range is defined as the AArch64 System register space with op0==3, op1=={0, 1, 3}, CRn==0, CRm=={0-7}, op2=={0-7}.

The end goal is to get more flexibility when migrating guests between different host hardware.

QEMU retrieves the writable ID fields from KVM UAPI [1] and match them against a generated description of ID regs and their named fields that stem from AARCHMRS Registers.json file. Current description is based on latest 2026-03 edition. The content of the generated files was compared against kernel linux/arch/arm64/tools/sysreg file. It is not straightforward to have unit tests for python scripts as there are many cases for field extraction.

For each writable named field a uint64 property is created following the "SYSREG_<REG>_<FIELD>" naming convention. REG and FIELD names are those described in ARM ARM Reference manual.

The list of SYSREG_ID properties can be retrieved through the qmp monitor using query-cpu-model-expansion [2].

For the record, Jinqian was able to migrate between Hisilicon KunPeng HIP09 and HIP12 chips with this series using this kind of command:

-cpu host,pauth=off,pmu=off,sve=off,\
SYSREG_ID_AA64PFR1_EL1_NMI=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LS64=0x0,\
SYSREG_ID_AA64ISAR1_EL1_XS=0x0,\
SYSREG_ID_AA64ISAR1_EL1_LRCPC=0x2,\
SYSREG_ID_AA64ISAR2_EL1_RPRFM=0x0,\
SYSREG_ID_AA64ISAR2_EL1_CLRBHB=0x0,\
SYSREG_ID_AA64ISAR2_EL1_PAC_frac=0x0,\
SYSREG_ID_AA64ISAR2_EL1_BC=0x0,\
SYSREG_ID_AA64ISAR2_EL1_RPRES=0x0,\
SYSREG_ID_AA64ISAR2_EL1_WFxT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_FGT=0x0,\
SYSREG_ID_AA64MMFR0_EL1_BigEnd=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ECBHB=0x0,\
SYSREG_ID_AA64MMFR1_EL1_CMOW=0x0,\
SYSREG_ID_AA64MMFR1_EL1_TIDCP1=0x0,\
SYSREG_ID_AA64MMFR1_EL1_nTLBPA=0x0,\
SYSREG_ID_AA64MMFR1_EL1_AFP=0x0,\
SYSREG_ID_AA64MMFR1_EL1_HCX=0x0,\
SYSREG_ID_AA64MMFR1_EL1_ETS=0x0,\
SYSREG_ID_AA64MMFR1_EL1_PAN=0x2,\
SYSREG_ID_AA64MMFR1_EL1_HAFDBS=0x2,\
SYSREG_ID_AA64MMFR2_EL1_CnP=0x0,\
SYSREG_ID_AA64MMFR3_EL1_TCRX=0x0,\
SYSREG_ID_AA64DFR0_EL1_PMUVer=0x6,\
SYSREG_ID_AA64DFR0_EL1_DebugVer=0x9,\
SYSREG_ID_AA64DFR0_EL1_DoubleLock=0xf,\
SYSREG_ID_AA64ZFR0_EL1_F64MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_F32MM=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SM4=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SHA3=0x0,\
SYSREG_ID_AA64ZFR0_EL1_BitPerm=0x0,\
SYSREG_ID_AA64ZFR0_EL1_AES=0x0,\
SYSREG_ID_AA64ZFR0_EL1_SVEver=0x0,\
SYSREG_CTR_EL0_L1Ip=0x2 \

Connie & Eric

This series can be found at:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_eauger_qemu_tree_arm-2Dcpu-2Dmodel-2Dv7&d=DwIDAg&c=s883GpUCOChKOHiocYtGcg&r=PGWMyignA0NiDmTlyP7vOTHozBws_VN86yrVmSMkBp0&m=xh5u7-r6auXiWQScafdj-0wW70mXB4FhClh58GryHmExkx8uZN-h9j4B2c90Lowd&s=Ro4v_mjoNaLsznyxm781lzXBcRtXTudjibmgIhoJsNM&e=

History:
--------
v6 -> v7:
- query-cpu-model-expansion now applies the sysreg props onto a scratch vcpu (POC) allowing a finer validation of settings (not perfect though as init may be revisited depending on settings)
- Properly handle ValueRange (Khushit)
- Remove cpu parameter in get_host_cpu_idregs call chain (Khushit)

v5 -> v6:
v6 is mostly for Khushit to see how he may work on top of this series. It fulfills some of his requirements:
- Upon Khushit request I added description for enum values and reserved fields
- set_sysreg_prop checks the input value against enum values if any
- writable_bitmap is now dispatched into the sysreg descripton and not stored in vcpu state anymore (besides it is VM wide)
- implemented write for qmp inspection. However this is not yet checked against KVM. That's the next step I think, ie. instantiate a scratch vcpu to test if the field value can be applied?
- if some inconsistencies between writable mask and idreg field, reserved fields only produce traces
- this version does not yet fix some reported issues about host supporting nested virt. I will further sync with Khushit. so this is definitively not candidate to be applied, hence the RFC tag.

Cornelia Huck (3):
target/arm/kvm: Retrieve writable ID reg map
arm/cpu-features: document ID reg properties
arm-qmp-cmds: introspection for ID register props

Eric Auger (14):
scripts: introduce scripts/update-aarch64-cpu-sysregs-header.py target/arm/cpu-sysregs.h.inc: Sort by name alphabetical order target/arm/cpu-sysregs.h.inc: Update with automatic generation arm/cpu: Add infra to handle generated ID register definitions
scripts: Introduce scripts/aarch64_sysreg_helpers module
scripts: Introduce scripts/update-aarch64-cpu-sysreg-properties.py target/arm/cpu-idregs.h.inc: generate with script target/arm/cpu-idregs.h.inc: Generate enum values arm/kvm: Initialize all writable ID registers from host target/arm/kvm: Introduce kvm_arm_expose_idreg_properties target/arm/cpu: Expose writable ID reg field properties on the kvm
host vcpu model
target/arm/cpu-idregs.h.inc: Generate reserved fields target/arm/kvm: Ignore and trace unexpected writable reserved fields target/arm/kvm: add utility to write idregs in scratch vcpu

Shaju Abraham (1):
target/arm/cpu_idregs: generate tables for Arm64 ID registers and
fields

docs/system/arm/cpu-features.rst              |  106 +-
target/arm/cpu-idregs.h                       |   41 +
target/arm/kvm_arm.h                          |   13 +
target/arm/cpu-idregs.h.inc                   | 2164 +++++++++++++++++
target/arm/cpu-sysregs.h.inc                  |   57 +-
target/arm/arm-qmp-cmds.c                     |   98 +
target/arm/cpu-idregs.c                       |   96 +
target/arm/cpu64.c                            |    5 +
target/arm/kvm-stub.c                         |    6 +
target/arm/kvm.c                              |  360 ++-
scripts/aarch64_sysreg_helpers.py             |  109 +
.../update-aarch64-cpu-sysreg-properties.py   |  290 +++
scripts/update-aarch64-cpu-sysregs-header.py  |   51 +
target/arm/meson.build                        |    1 +
target/arm/trace-events                       |    8 +
15 files changed, 3373 insertions(+), 32 deletions(-)
Quoted 10 lines

create mode 100644 target/arm/cpu-idregs.h
create mode 100644 target/arm/cpu-idregs.h.inc
create mode 100644 target/arm/cpu-idregs.c
create mode 100644 scripts/aarch64_sysreg_helpers.py create mode 100644 scripts/update-aarch64-cpu-sysreg-properties.py create mode 100755 scripts/update-aarch64-cpu-sysregs-header.py

Signature · 1 line
2.53.0

Hi,

On my box the build is failing with:
[97/2192] Linking target qemu-system-arm
FAILED: qemu-system-arm
cc @qemu-system-arm.rsp
/usr/bin/ld: libsystem_arm.a.p/target_arm_arm-qmp-cmds.c.o: in function `qmp_query_cpu_model_expansion':
/home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:144:(.text+0x4d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:145:(.text+0x4e4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:151:(.text+0x514): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:168:(.text+0x554): undefined reference to kvm_arm_create_scratch_host_vcpu' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:152:(.text+0x7d4): undefined reference to kvm_check_extension' /usr/bin/ld: /home/ahv/qemu/build/../target/arm/arm-qmp-cmds.c:247:(.text+0x8f4): undefined reference to kvm_arm_destroy_scratch_host_vcpu'
collect2: error: ld returned 1 exit status

Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

If I add appropriate stubs, Following test fails:

 30/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test         ERROR            1.58s   killed by signal 6 SIGABRT
126/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test                       ERROR           46.65s   killed by signal 6 SIGABRT
426/1079 qemu:qtest+qtest-aarch64 / qtest-aarch64/arm-cpu-features               ERROR            0.51s   killed by signal 6 SIGABRT
467/1079 qemu:qtest+qtest-arm / qtest-arm/arm-cpu-features                       ERROR            0.46s   killed by signal 6 SIGABRT

all the above are fixed now.

Is it available on the same GitHub repo?

Not yet. Soon ;-)

Quoted 2 lines

Also may I know what are your thoughts on cpu-model-expansion schematics?

do you refer to your last comment in
https://lore.kernel.org/all/[email protected]/#t
if so, I will reply on this msg instead

Thanks

Eric

Quoted 9 lines
Quoted 3 lines
Quoted 2 lines

966/1079 qemu:block / io-qcow2-161 ERROR 1.95s exit status 1

this one looks unrelated to this series. I did not encounter it.

Acked.

Quoted 3 lines

Thanks

Eric