Skip to contentSkip to conversation

hw/arm/virt: Add support for Target Implementation CPUs

RFC PATCH In review Shameer Kolothum 2 participants 7 messages Sep 11 – Nov 2

lore
Share & tools
lore
#0 lore raw

v2 cover hw/arm/virt: Add support for Target Implementation CPUs

Hi,

Changes from RFC v1:
https://lore.kernel.org/qemu-devel/[email protected]/

-Rebased on top of Connie/Eric's "customizable aarch64 KVM host" series v8[0] -Addressed feedback on v1.

One item from v1 is still open: What should actually set the implementation ID registers(Sebastian raised this on v1).

As it stands, this series enables KVM_CAP_ARM_WRITABLE_IMP_ID_REGS but never writes MIDR/REVIDR/AIDR. impl-cpu feeds the hypercall only, so a guest that reads MIDR_EL1 directly still sees the host value, while DISCOVER_IMPL_CPUS reports the configured list. Sebastian suggested using target_impl_cpus[0].*, which would make the guest-visible CPU identity a configuration value rather than an artefact of whichever host the VM first booted on.

Please take a look and let me know.

Thanks,
Shameer

[0] https://lore.kernel.org/qemu-devel/[email protected]/

From v1:

On ARM64 platforms, many errata workarounds are based on CPU identification registers, particularly MIDR_EL1 and REVIDR_EL1. Some of these errata require corresponding fixes in the guest kernel as well. This becomes a challenge during guest migration between hosts with different MIDR/REVIDR values, even when the VMM provides a common baseline feature set using the recently introduced writable ID register support.

To address this, the Linux kernel now provides:

-A mechanism to expose implementation CPU data to guests via KVM
hypercalls:

ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_VER_FUNC_ID ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_CPUS_FUNC_ID

-A way to override implementation ID registers (MIDR, REVIDR, AIDR),
which were previously treated as invariant.

What this RFC does:

This RFC enables the virt machine to specify Target Implementation CPUs via QEMU command-line, exposing them to the guest via KVM hypercalls.

Example use case (hosts with differing MIDRs):

./qemu-system-aarch64 -machine virt,gic-version=3 \
-enable-kvm \
-bios QEMU_EFI.fd \
-m 1G -smp cpus=4,maxcpus=4 \
-cpu host \
-M impl-cpu.0.midr=0x481fd010,impl-cpu.0.revidr=0,impl-cpu.0.aidr=0x551,\
impl-cpu.1.midr=0x481fd011,impl-cpu.1.revidr=0,impl-cpu.1.aidr=0x551 \
-kernel Image-6.16-rc2 \
-initrd rootfs-iperf.cpio \
-append "rdinit=init console=ttyAMA0 root=/dev/vda rw earlycon=pl011,0x9000000 kpti=off" \
-net none \
-nographic

Shameer Kolothum (5):
target/arm/kvm-consts.h: Add SMCCC vendor hypercall definitions target/arm/kvm: Introduce helper to check target impl CPU support target/arm/kvm: Add QAPI struct ArmTargetImplCPU target/arm/kvm: Handle KVM Target Imp CPU hypercalls hw/arm/virt: Add Target Implementation CPU support

 docs/system/arm/virt.rst |  22 +++++
 qapi/misc-arm.json       |  36 ++++++++
 include/hw/arm/virt.h    |   2 +
 target/arm/kvm-consts.h  |  48 ++++++++++
 target/arm/kvm_arm.h     |  18 ++++
 hw/arm/virt.c            |  48 ++++++++++
 target/arm/kvm-stub.c    |  10 ++
 target/arm/kvm.c         | 194 +++++++++++++++++++++++++++++++++++++++
 8 files changed, 378 insertions(+)
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH v2 1/5 target/arm/kvm-consts.h: Add SMCCC vendor hypercall definitions

The KVM target implementation CPU support relies on two KVM vendor hypercalls, DISCOVER_IMPL_VER and DISCOVER_IMPL_CPUS, together with the SMCCC return codes. In the kernel these live in include/linux/arm-smccc.h, which is not a uapi header, so they cannot be imported through linux-headers/. Mirror the few definitions we need in kvm-consts.h

---
 target/arm/kvm-consts.h | 48 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
target/arm/kvm-consts.h +48 -0
index 9fba3e886d..741309c300 100644
@@ -190,4 +190,52 @@ MISMATCH_CHECK(CP_REG_ARM64_SYSREG_OP2_SHIFT, KVM_REG_ARM64_SYSREG_OP2_SHIFT);
 #define KVMID_AA64_SYS_REG64(op0, op1, crn, crm, op2)   \
     (KVMID_AA64_SYS_REG_(op0, op1, crn, crm, op2) | CP_REG_SIZE_U64)
 
+/*
+ * SMC Calling Convention function identifiers.
+ * These mirror the kernel's include/linux/arm-smccc.h
+ */
+#define ARM_SMCCC_FAST_CALL             1U
+#define ARM_SMCCC_TYPE_SHIFT            31
+
+#define ARM_SMCCC_SMC_32                0
+#define ARM_SMCCC_SMC_64                1
+#define ARM_SMCCC_CALL_CONV_SHIFT       30
+
+#define ARM_SMCCC_OWNER_MASK            0x3F
+#define ARM_SMCCC_OWNER_SHIFT           24
+
+#define ARM_SMCCC_FUNC_MASK             0xFFFF
+
+#define ARM_SMCCC_OWNER_VENDOR_HYP      6
+
+#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num)   \
+    (((type) << ARM_SMCCC_TYPE_SHIFT) |                                 \
+     ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) |              \
+     (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) |      \
+     ((func_num) & ARM_SMCCC_FUNC_MASK))
+
+/*
+ * KVM/arm64-specific vendor hypercalls which may be exposed by KVM/arm64
+ * to guest operating systems and managed by the VMM.
+ */
+#define ARM_SMCCC_KVM_FUNC_DISCOVER_IMPL_VER    64
+#define ARM_SMCCC_KVM_FUNC_DISCOVER_IMPL_CPUS   65
+
+#define ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_VER_FUNC_ID              \
+    ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                             \
+                       ARM_SMCCC_SMC_64,                                \
+                       ARM_SMCCC_OWNER_VENDOR_HYP,                      \
+                       ARM_SMCCC_KVM_FUNC_DISCOVER_IMPL_VER)
+
+#define ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_CPUS_FUNC_ID             \
+    ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                             \
+                       ARM_SMCCC_SMC_64,                                \
+                       ARM_SMCCC_OWNER_VENDOR_HYP,                      \
+                       ARM_SMCCC_KVM_FUNC_DISCOVER_IMPL_CPUS)
+
+#define SMCCC_RET_SUCCESS                       0
+#define SMCCC_RET_NOT_SUPPORTED                 -1
+#define SMCCC_RET_NOT_REQUIRED                  -2
+#define SMCCC_RET_INVALID_PARAMETER             -3
+
 #endif
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH v2 2/5 target/arm/kvm: Introduce helper to check target impl CPU support

In reply to Shameer Kolothum

The helper function will try to set the SMCCC filters for KVM vendor hypercalls related to target implementation CPU support. It also checks the kernel support for writable implementation ID registers (MIDR/REVIDR/AIDR) and enables it.

Subsequent patches for Target Impl CPU support will make use of this helper.

---
 target/arm/kvm_arm.h  |  7 +++++
 target/arm/kvm-stub.c |  5 ++++
 target/arm/kvm.c      | 69 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+)
target/arm/kvm_arm.h +7 -0
index aafb3cd232..8cd770c7c3 100644
@@ -212,6 +212,13 @@ bool kvm_arm_mte_supported(void);
  * Returns true if KVM can enable EL2 and false otherwise.
  */
 bool kvm_arm_el2_supported(void);
+
+/**
+ * kvm_arm_target_impl_cpus_supported:
+ *
+ * Returns: true if KVM can enable target impl CPUs, and false otherwise.
+ */
+bool kvm_arm_target_impl_cpus_supported(void);
 #else
 
 static inline bool kvm_arm_aarch32_supported(void)
target/arm/kvm-stub.c +5 -0
index eae2e1ec2c..a0aed2fd84 100644
@@ -42,6 +42,11 @@ bool kvm_arm_el2_supported(void)
     return false;
 }
 
+bool kvm_arm_target_impl_cpus_supported(void)
+{
+    return false;
+}
+
 /*
  * These functions should never actually be called without KVM support.
  */
target/arm/kvm.c +69 -0

75 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH v2 3/5 target/arm/kvm: Add QAPI struct ArmTargetImplCPU

In reply to Shameer Kolothum

Introduce a QAPI-defined struct (and its array) for target implementation CPUs. This enables specifying target implementation CPU parameters via -machine, for example:

-M virt, \
impl-cpu.0.midr=1,impl-cpu.0.revidr=1,impl-cpu.0.aidr=1, \
impl-cpu.1.midr=2,impl-cpu.1.revidr=2,impl-cpu.1.aidr=0

Subsequent patch will make use of this by using object_property_add(), allowing users to configure each target CPU's midr, revidr, and aidr fields directly from the command line.

While at it, also provide a helper function to set the target CPUs.

---
 qapi/misc-arm.json    | 36 ++++++++++++++++++++++++++++++++++++
 target/arm/kvm_arm.h  | 11 +++++++++++
 target/arm/kvm-stub.c |  5 +++++
 target/arm/kvm.c      | 20 ++++++++++++++++++++
 4 files changed, 72 insertions(+)
qapi/misc-arm.json +36 -0
index 4dc66d00e5..8dbfb98fe5 100644
@@ -89,3 +89,39 @@
 ##
 { 'enum': 'OasMode',
   'data': [ 'auto', '32', '36', '40', '42', '44', '48', '52', '56' ] }
+
+##
+# @ArmTargetImplCPU:
+#
+# Info for a single target implementation CPU.
+#
+# @midr: MIDR value
+#
+# @revidr: REVIDR value
+#
+# @aidr: AIDR value
+#
+# Since: 11.2
+##
+{ 'struct': 'ArmTargetImplCPU',
+  'data': {
+    'midr': 'uint64',
+    'revidr': 'uint64',
+    'aidr': 'uint64'
+  }
+}
+
+##
+# @ArmTargetImplCPUs:
+#
+# List of target implementation CPUs.
+#
+# @target-cpus: List of ArmTargetImplCPU entries.
+#
+# Since: 11.2
+##
+{ 'struct': 'ArmTargetImplCPUs',
+  'data': {
+    'target-cpus': ['ArmTargetImplCPU']
+  }
+}
target/arm/kvm_arm.h +11 -0
index 8cd770c7c3..4dc59779bb 100644
@@ -281,4 +281,15 @@ char *kvm_print_register_name(uint64_t regidx);
 bool kvm_idreg_write_scratch_vcpu(int cpufd, Visitor *v, const char *name,
                                   void *opaque, Error **errp);
 
+/**
+ * kvm_arm_set_target_impl_cpus:
+ * @cpus: list of target implementation CPU descriptions
+ *
+ * Record the target implementation CPUs to be reported to the guest via
+ * the KVM vendor hypercalls. May only be called once.
+ *
+ * Returns: true on success, false if the target CPUs were already set.
+ */
+bool kvm_arm_set_target_impl_cpus(ArmTargetImplCPUList *cpus);
+
 #endif
target/arm/kvm-stub.c +5 -0
index a0aed2fd84..9f835787f1 100644
@@ -47,6 +47,11 @@ bool kvm_arm_target_impl_cpus_supported(void)
     return false;
 }
 
+bool kvm_arm_set_target_impl_cpus(ArmTargetImplCPUList *cpus)
+{
+    return false;
+}
+
 /*
  * These functions should never actually be called without KVM support.
  */
target/arm/kvm.c +20 -0
index ee4b2e72e8..68c22a6cde 100644
@@ -69,6 +69,9 @@ typedef struct ARMHostCPUFeatures {
 
 static ARMHostCPUFeatures arm_host_cpu_features;
 
+static uint64_t target_impl_cpus_num;
+static ArmTargetImplCPUList *target_impl_cpus;
+
 /**
  * kvm_arm_vcpu_init:
  * @cpu: ARMCPU
@@ -3061,3 +3064,20 @@ void arm_gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3)
 
     kvm_arm_destroy_scratch_host_vcpu(fdarray);
 }
+
+bool kvm_arm_set_target_impl_cpus(ArmTargetImplCPUList *cpus)
+{
+    ArmTargetImplCPUList *iter;
+
+    if (target_impl_cpus_num) {
+        return false;
+    }
+
+    for (iter = cpus; iter; iter = iter->next) {
+        target_impl_cpus_num++;
+    }
+
+    target_impl_cpus = cpus;
+
+    return true;
+}
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH v2 4/5 target/arm/kvm: Handle KVM Target Imp CPU hypercalls

In reply to Shameer Kolothum

When target implementation CPUs are set, handle the related hyper calls correctly by returning the information requested.

---
 target/arm/kvm.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
target/arm/kvm.c +105 -0
index 68c22a6cde..48eb3e51a5 100644
@@ -1903,6 +1903,77 @@ static bool kvm_arm_handle_debug(ARMCPU *cpu,
     return false;
 }
 
+/* Only supports HYP_KVM_DISCOVER_IMPL_XXX hypercalls */
+static void arm_handle_smccc_kvm_vendor_hypercall(ARMCPU *cpu)
+{
+    CPUARMState *env = &cpu->env;
+    ArmTargetImplCPUList *iter;
+    uint64_t param[4] = { };
+    uint64_t idx;
+
+    if (!is_a64(env)) {
+        env->regs[0] = SMCCC_RET_NOT_SUPPORTED;
+        return;
+    }
+
+    memcpy(param, env->xregs, sizeof(param));
+
+    switch (param[0]) {
+    case ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_VER_FUNC_ID:
+        if (!target_impl_cpus_num) {
+            env->xregs[0] = SMCCC_RET_NOT_SUPPORTED;
+            return;
+        }
+        env->xregs[0] = SMCCC_RET_SUCCESS;
+        env->xregs[1] = PSCI_VERSION(1, 0);
+        env->xregs[2] = target_impl_cpus_num;
+        break;
+    case ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_CPUS_FUNC_ID:
+        idx = param[1];
+
+        if (!target_impl_cpus_num || idx >= target_impl_cpus_num) {
+            env->xregs[0] = SMCCC_RET_INVALID_PARAMETER;
+            return;
+        }
+
+        iter = target_impl_cpus;
+        for (uint64_t i = 0; i < idx; i++) {
+            iter = iter->next;
+        }
+
+        env->xregs[0] = SMCCC_RET_SUCCESS;
+        env->xregs[1] = iter->value->midr;
+        env->xregs[2] = iter->value->revidr;
+        env->xregs[3] = iter->value->aidr;
+        break;
+    default:
+        env->xregs[0] = SMCCC_RET_NOT_SUPPORTED;
+    }
+}
+
+static int kvm_arm_handle_hypercall(CPUState *cs, struct kvm_run *run)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    kvm_cpu_synchronize_state(cs);
+
+    if (run->hypercall.flags == KVM_HYPERCALL_EXIT_SMC) {
+        cs->exception_index = EXCP_SMC;
+        env->exception.syndrome = syn_aa64_smc(0);
+    } else {
+        cs->exception_index = EXCP_HVC;
+        env->exception.syndrome = syn_aa64_hvc(0);
+    }
+    env->exception.target_el = 1;
+
+    bql_lock();
+    arm_handle_smccc_kvm_vendor_hypercall(cpu);
+    bql_unlock();
+
+    return EXCP_INTERRUPT;
+}
+
 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 {
     ARMCPU *cpu = ARM_CPU(cs);
@@ -1919,6 +1990,9 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
         ret = kvm_arm_handle_dabt_nisv(cpu, run->arm_nisv.esr_iss,
                                        run->arm_nisv.fault_ipa);
         break;
+    case KVM_EXIT_HYPERCALL:
+        ret = kvm_arm_handle_hypercall(cs, run);
+        break;
     default:
         qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n",
                       __func__, run->exit_reason);
@@ -2379,6 +2453,29 @@ static int kvm_arm_sve_set_vls(ARMCPU *cpu)
     return kvm_set_one_reg(CPU(cpu), KVM_REG_ARM64_SVE_VLS, &vls[0]);
 }
 
+/*
+ * Supported Target Implementation CPU hypercalls:
+ *   KVM_REG_ARM_VENDOR_HYP_BIT_DISCOVER_IMPL_VER   = 0,
+ *   KVM_REG_ARM_VENDOR_HYP_BIT_DISCOVER_IMPL_CPUS  = 1
+ *
+ * Setting these bits advertises the availability of the corresponding
+ * Target Implementation CPU hypercalls to the guest.
+ */
+#define BMAP_2_DISCOVER_IMPL_BITS 0x3ULL
+static int kvm_arm_target_impl_cpus_set_hyp_bmap2(ARMCPU *cpu)
+{
+    uint64_t bmap2;
+    int ret;
+
+    ret = kvm_get_one_reg(CPU(cpu), KVM_REG_ARM_VENDOR_HYP_BMAP_2, &bmap2);
+    if (ret) {
+        return ret;
+    }
+
+    bmap2 |= BMAP_2_DISCOVER_IMPL_BITS;
+    return kvm_set_one_reg(CPU(cpu), KVM_REG_ARM_VENDOR_HYP_BMAP_2, &bmap2);
+}
+
 #define ARM_CPU_ID_MPIDR       3, 0, 0, 0, 5
 
 int kvm_arch_pre_create_vcpu(CPUState *cpu, Error **errp)
@@ -2482,6 +2579,14 @@ int kvm_arch_init_vcpu(CPUState *cs)
     }
     cpu->mp_affinity = mpidr & ARM64_AFFINITY_MASK;
 
+    /* Set KVM_REG_ARM_VENDOR_HYP_BMAP_2 if target impl CPUs are required */
+    if (target_impl_cpus_num) {
+        ret = kvm_arm_target_impl_cpus_set_hyp_bmap2(cpu);
+        if (ret) {
+            return ret;
+        }
+    }
+
     ret = kvm_arm_init_cpreg_list(cpu);
     if (ret) {
         return ret;
Signature · 1 line
2.43.0
#5 lore raw

RFC PATCH v2 5/5 hw/arm/virt: Add Target Implementation CPU support

In reply to Shameer Kolothum

Add the impl-cpu property to virt machine. This will enable user to specify the target implementation CPUs as the example below:

...
-M impl-cpu.0.midr=1,impl-cpu.0.revidr=1,impl-cpu.0.aidr=1,\
impl-cpu.1.midr=2,impl-cpu.1.revidr=2,impl-cpu.1.aidr=2 \

Make use of helper functions to check the KVM support for target Impl CPUs and if supported set the user specified target CPUs.

---
 docs/system/arm/virt.rst | 22 ++++++++++++++++++
 include/hw/arm/virt.h    |  2 ++
 hw/arm/virt.c            | 48 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
docs/system/arm/virt.rst +22 -0
index 5f6dd17978..a27a5dc8b1 100644
@@ -259,6 +259,28 @@ x-oem-table-id
   Set string (up to 8 bytes) to override the default value of field OEM Table ID
   in ACPI table header.
 
+impl-cpu
+  Set the list of target implementation CPUs that the guest may run on, so
+  that the guest kernel can enable the errata workarounds required by all of
+  them. This is intended for migrating a guest between hosts whose CPUs
+  differ in their ``MIDR_EL1``, ``REVIDR_EL1`` and ``AIDR_EL1`` values.
+
+  Each entry is described by its ``midr``, ``revidr`` and ``aidr`` values,
+  and all three must be given::
+
+    -machine virt,impl-cpu.0.midr=0x481fd010,impl-cpu.0.revidr=0,\
+    impl-cpu.0.aidr=0x551,impl-cpu.1.midr=0x481fd011,\
+    impl-cpu.1.revidr=0,impl-cpu.1.aidr=0x551
+
+  The list is reported to the guest through KVM vendor hypercalls, so this is
+  only available when using KVM on a host kernel that supports them.
+
+  The list must include the CPU of the host QEMU is running on. A guest that
+  is given a target list stops consulting its own ``MIDR_EL1`` when deciding
+  which errata to enable, so omitting the running host means the guest will
+  not enable the workarounds that host requires. QEMU does not currently
+  verify this.
+
 SMMU configuration
 """"""""""""""""""
 
include/hw/arm/virt.h +2 -0
index 22e66d1a11..1095a5d326 100644
@@ -42,6 +42,7 @@
 #include "hw/intc/arm_gicv3_common.h"
 #include "qom/object.h"
 #include "hw/core/cpu.h"
+#include "qapi/qapi-types-misc-arm.h"
 
 #define NUM_GICV2M_SPIS       64
 #define NUM_VIRTIO_TRANSPORTS 32
@@ -211,6 +212,7 @@ struct VirtMachineState {
     MemoryRegion *secure_sysmem;
     bool pci_preserve_config;
     GPtrArray *smmuv3_devices;
+    ArmTargetImplCPUList *target_cpus_list;
 };
 
 #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM)
hw/arm/virt.c +48 -0

72 lines not on this page · raw message

Signature · 1 line
2.43.0
Tested-by on the v2 series
#6 lore raw
In reply to Shameer Kolothum

Hi Shameer,

We tested this series on HIP09 and HIP12, with the mainline kernel side support (host and guest both v7.3-rc7).

Both ends of the migration run QEMU from Eric's v8 branch plus this series, with the same target implementation CPU list:

```
./qemu-system-aarch64 -machine virt,gic-version=3 \
-enable-kvm -bios QEMU_EFI.fd -m 4G -smp cpus=4,maxcpus=4 \
-cpu host,pauth=off,pmu=off,sve=off,\
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_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 \
-M impl-cpu.0.midr=0x480fd030,impl-cpu.0.revidr=0,impl-cpu.0.aidr=0x1550,\
impl-cpu.1.midr=0x480fd060,impl-cpu.1.revidr=0,impl-cpu.1.aidr=0x51500 \
-kernel Image -initrd minifs.cpio.gz \
-append "rdinit=init console=ttyAMA0 earlycon=pl011,0x9000000 kpti=off" -net none -nographic
[-incoming tcp:150.0.207.41:6666]
```

By migrating back and forth between HIP09 and HIP12, it can be observed that guest has enabled ARM64_WORKAROUND_HISILICON_ERRATUM_162100125, which is an erratum required only in the HIP09 implementation. This proves that the migration of the erratum was successful.

Thanks,
Jinqian

Quoted 83 lines · Shameer Kolothum

Hi,

Changes from RFC v1:
https://lore.kernel.org/qemu-devel/[email protected]/

-Rebased on top of Connie/Eric's "customizable aarch64 KVM host" series v8[0] -Addressed feedback on v1.

One item from v1 is still open: What should actually set the implementation ID registers(Sebastian raised this on v1).

As it stands, this series enables KVM_CAP_ARM_WRITABLE_IMP_ID_REGS but never writes MIDR/REVIDR/AIDR. impl-cpu feeds the hypercall only, so a guest that reads MIDR_EL1 directly still sees the host value, while DISCOVER_IMPL_CPUS reports the configured list. Sebastian suggested using target_impl_cpus[0].*, which would make the guest-visible CPU identity a configuration value rather than an artefact of whichever host the VM first booted on.

Please take a look and let me know.

Thanks,
Shameer

[0] https://lore.kernel.org/qemu-devel/[email protected]/

From v1:

On ARM64 platforms, many errata workarounds are based on CPU identification registers, particularly MIDR_EL1 and REVIDR_EL1. Some of these errata require corresponding fixes in the guest kernel as well. This becomes a challenge during guest migration between hosts with different MIDR/REVIDR values, even when the VMM provides a common baseline feature set using the recently introduced writable ID register support.

To address this, the Linux kernel now provides:

-A mechanism to expose implementation CPU data to guests via KVM
hypercalls:

ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_VER_FUNC_ID ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_CPUS_FUNC_ID

-A way to override implementation ID registers (MIDR, REVIDR, AIDR),
which were previously treated as invariant.

What this RFC does:

This RFC enables the virt machine to specify Target Implementation CPUs via QEMU command-line, exposing them to the guest via KVM hypercalls.

Example use case (hosts with differing MIDRs):

./qemu-system-aarch64 -machine virt,gic-version=3 \
   -enable-kvm \
   -bios QEMU_EFI.fd \
   -m 1G -smp cpus=4,maxcpus=4 \
   -cpu host \
   -M impl-cpu.0.midr=0x481fd010,impl-cpu.0.revidr=0,impl-cpu.0.aidr=0x551,\
    impl-cpu.1.midr=0x481fd011,impl-cpu.1.revidr=0,impl-cpu.1.aidr=0x551 \
   -kernel Image-6.16-rc2 \
   -initrd rootfs-iperf.cpio \
   -append "rdinit=init console=ttyAMA0 root=/dev/vda rw earlycon=pl011,0x9000000 kpti=off" \
   -net none \
   -nographic

Shameer Kolothum (5):
target/arm/kvm-consts.h: Add SMCCC vendor hypercall definitions target/arm/kvm: Introduce helper to check target impl CPU support target/arm/kvm: Add QAPI struct ArmTargetImplCPU target/arm/kvm: Handle KVM Target Imp CPU hypercalls hw/arm/virt: Add Target Implementation CPU support

  docs/system/arm/virt.rst |  22 +++++
  qapi/misc-arm.json       |  36 ++++++++
  include/hw/arm/virt.h    |   2 +
  target/arm/kvm-consts.h  |  48 ++++++++++
  target/arm/kvm_arm.h     |  18 ++++
  hw/arm/virt.c            |  48 ++++++++++
  target/arm/kvm-stub.c    |  10 ++
  target/arm/kvm.c         | 194 +++++++++++++++++++++++++++++++++++++++
  8 files changed, 378 insertions(+)