Skip to contentSkip to conversation

arm: add kvm-psci-version vcpu property

PATCH Superseded Sebastian Ott 2 participants 6 messages Oct 30, 2025 – Nov 12, 2025

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover arm: add kvm-psci-version vcpu property

This series adds a vcpu knob to request a specific PSCI version from KVM via the KVM_REG_ARM_PSCI_VERSION FW register.

The use case for this is to support migration between host kernels that differ in their default (a.k.a. most recent) PSCI version.

Note: in order to support PSCI v0.1 we need to drop vcpu initialization with KVM_CAP_ARM_PSCI_0_2 in that case. Alternatively we could limit support to versions >=0.2 .

Changes since V1 [1]:
* incorporated feedback from Peter and Eric

[1] https://lore.kernel.org/kvmarm/[email protected]/

Sebastian Ott (2):
target/arm/kvm: add constants for new PSCI versions target/arm/kvm: add kvm-psci-version vcpu property

 docs/system/arm/cpu-features.rst |  5 +++
 target/arm/cpu.h                 |  6 ++++
 target/arm/kvm-consts.h          |  2 ++
 target/arm/kvm.c                 | 60 +++++++++++++++++++++++++++++++-
 4 files changed, 72 insertions(+), 1 deletion(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH v2 1/2 target/arm/kvm: add constants for new PSCI versions

Add constants for PSCI version 1_2 and 1_3.

---
 target/arm/kvm-consts.h | 2 ++
 1 file changed, 2 insertions(+)
target/arm/kvm-consts.h +2 -0
index 54ae5da7ce..9fba3e886d 100644
@@ -97,6 +97,8 @@ MISMATCH_CHECK(QEMU_PSCI_1_0_FN_PSCI_FEATURES, PSCI_1_0_FN_PSCI_FEATURES);
 #define QEMU_PSCI_VERSION_0_2                     0x00002
 #define QEMU_PSCI_VERSION_1_0                     0x10000
 #define QEMU_PSCI_VERSION_1_1                     0x10001
+#define QEMU_PSCI_VERSION_1_2                     0x10002
+#define QEMU_PSCI_VERSION_1_3                     0x10003
 
 MISMATCH_CHECK(QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED, PSCI_0_2_TOS_MP);
 /* We don't bother to check every possible version value */
Signature · 1 line
2.42.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] target/arm/kvm: add constants for new PSCI versions

Hi Sebstian,

Quoted 3 lines · Sebastian Ott

Add constants for PSCI version 1_2 and 1_3.

Eric

Quoted 17 lines
---
 target/arm/kvm-consts.h | 2 ++
 1 file changed, 2 insertions(+)
target/arm/kvm-consts.h +2 -0
index 54ae5da7ce..9fba3e886d 100644
@@ -97,6 +97,8 @@ MISMATCH_CHECK(QEMU_PSCI_1_0_FN_PSCI_FEATURES, PSCI_1_0_FN_PSCI_FEATURES);
 #define QEMU_PSCI_VERSION_0_2                     0x00002
 #define QEMU_PSCI_VERSION_1_0                     0x10000
 #define QEMU_PSCI_VERSION_1_1                     0x10001
+#define QEMU_PSCI_VERSION_1_2                     0x10002
+#define QEMU_PSCI_VERSION_1_3                     0x10003
 
 MISMATCH_CHECK(QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED, PSCI_0_2_TOS_MP);
 /* We don't bother to check every possible version value */
#3 lore raw

PATCH v2 2/2 target/arm/kvm: add kvm-psci-version vcpu property

In reply to Sebastian Ott

Provide a kvm specific vcpu property to override the default (as of kernel v6.13 that would be PSCI v1.3) PSCI version emulated by kvm. Current valid values are: 0.1, 0.2, 1.0, 1.1, 1.2, and 1.3

---
 docs/system/arm/cpu-features.rst |  5 +++
 target/arm/cpu.h                 |  6 ++++
 target/arm/kvm.c                 | 60 +++++++++++++++++++++++++++++++-
 3 files changed, 70 insertions(+), 1 deletion(-)
docs/system/arm/cpu-features.rst +5 -0
index 37d5dfd15b..1d32ce0fee 100644
@@ -204,6 +204,11 @@ the list of KVM VCPU features and their descriptions.
   the guest scheduler behavior and/or be exposed to the guest
   userspace.
 
+``kvm-psci-version``
+  Override the default (as of kernel v6.13 that would be PSCI v1.3)
+  PSCI version emulated by the kernel. Current valid values are:
+  0.1, 0.2, 1.0, 1.1, 1.2, and 1.3
+
 TCG VCPU Features
 =================
 
target/arm/cpu.h +6 -0
index 39f2b2e54d..c2032070b7 100644
@@ -981,6 +981,12 @@ struct ArchCPU {
      */
     uint32_t psci_version;
 
+    /*
+     * Intermediate value used during property parsing.
+     * Once finalized, the value should be read from psci_version.
+     */
+    uint32_t prop_psci_version;
+
     /* Current power state, access guarded by BQL */
     ARMPSCIState power_state;
 
target/arm/kvm.c +59 -1

84 lines not on this page · raw message

Signature · 1 line
2.42.0
#4 lore raw

Re: [PATCH v2 2/2] target/arm/kvm: add kvm-psci-version vcpu property

Quoted 64 lines · Sebastian Ott

Provide a kvm specific vcpu property to override the default (as of kernel v6.13 that would be PSCI v1.3) PSCI version emulated by kvm. Current valid values are: 0.1, 0.2, 1.0, 1.1, 1.2, and 1.3

---
 docs/system/arm/cpu-features.rst |  5 +++
 target/arm/cpu.h                 |  6 ++++
 target/arm/kvm.c                 | 60 +++++++++++++++++++++++++++++++-
 3 files changed, 70 insertions(+), 1 deletion(-)
docs/system/arm/cpu-features.rst +5 -0
index 37d5dfd15b..1d32ce0fee 100644
@@ -204,6 +204,11 @@ the list of KVM VCPU features and their descriptions.
   the guest scheduler behavior and/or be exposed to the guest
   userspace.
 
+``kvm-psci-version``
+  Override the default (as of kernel v6.13 that would be PSCI v1.3)
+  PSCI version emulated by the kernel. Current valid values are:
+  0.1, 0.2, 1.0, 1.1, 1.2, and 1.3
+
 TCG VCPU Features
 =================
 
target/arm/cpu.h +6 -0
index 39f2b2e54d..c2032070b7 100644
@@ -981,6 +981,12 @@ struct ArchCPU {
      */
     uint32_t psci_version;
 
+    /*
+     * Intermediate value used during property parsing.
+     * Once finalized, the value should be read from psci_version.
+     */
+    uint32_t prop_psci_version;
+
     /* Current power state, access guarded by BQL */
     ARMPSCIState power_state;
 
target/arm/kvm.c +12 -0
index 0d57081e69..c53b307b76 100644
@@ -484,6 +484,49 @@ static void kvm_steal_time_set(Object *obj, bool value, Error **errp)
     ARM_CPU(obj)->kvm_steal_time = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
 }
 
+struct psci_version {
+    uint32_t number;
+    const char *str;
+};
+
+static const struct psci_version psci_versions[] = {
+    { QEMU_PSCI_VERSION_0_1, "0.1" },
+    { QEMU_PSCI_VERSION_0_2, "0.2" },
+    { QEMU_PSCI_VERSION_1_0, "1.0" },
+    { QEMU_PSCI_VERSION_1_1, "1.1" },
+    { QEMU_PSCI_VERSION_1_2, "1.2" },
+    { QEMU_PSCI_VERSION_1_3, "1.3" },

target/arm/kvm.c static void kvm_steal_time_set(Object *obj, bool value, Error **errp) · line 508

Quoted 10 lines
target/arm/kvm.c +10 -0
+    { -1, NULL },
+};
+
+static char *kvm_get_psci_version(Object *obj, Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    const struct psci_version *ver;
+
+    for (ver = psci_versions; ver->number != -1; ver++) {
+        if (ver->number == cpu->prop_psci_version)

I still have the same question/comment as on v1. In case the end user does not override the psci version I think you want to return the default value, retrieved from KVM through KVM_REG_ARM_PSCI_VERSION and which populates cpu->psci_version. So to me you should use cpu->psci_version instead

Quoted 38 lines
target/arm/kvm.c +27 -0
+            return g_strdup(ver->str);
+    }
+
+    g_assert_not_reached();
+}
+
+static void kvm_set_psci_version(Object *obj, const char *value, Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    const struct psci_version *ver;
+
+    for (ver = psci_versions; ver->number != -1; ver++) {
+        if (!strcmp(value, ver->str)) {
+            cpu->prop_psci_version = ver->number;
+            return;
+        }
+    }
+
+    error_setg(errp, "Invalid PSCI-version value");
+}
+
 /* KVM VCPU properties should be prefixed with "kvm-". */
 void kvm_arm_add_vcpu_properties(ARMCPU *cpu)
 {
@@ -505,6 +548,12 @@ void kvm_arm_add_vcpu_properties(ARMCPU *cpu)
                              kvm_steal_time_set);
     object_property_set_description(obj, "kvm-steal-time",
                                     "Set off to disable KVM steal time.");
+
+    object_property_add_str(obj, "kvm-psci-version", kvm_get_psci_version,
+                            kvm_set_psci_version);
+    object_property_set_description(obj, "kvm-psci-version",
+                                    "Set PSCI version. "
+                                    "Valid values are 0.1, 0.2, 1.0, 1.1, 1.2, 1.3");
 }
 
 bool kvm_arm_pmu_supported(void)

target/arm/kvm.c int kvm_arch_init_vcpu(CPUState *cs) · line 2011

Quoted 5 lines
target/arm/kvm.c +1 -1
@@ -1959,7 +2008,8 @@ int kvm_arch_init_vcpu(CPUState *cs)
     if (cs->start_powered_off) {
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
-    if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+    if (cpu->prop_psci_version != QEMU_PSCI_VERSION_0_1 &&

I don't understand what this change stands for. Please document it through both a comment and a commit msg explanation

Thanks

Eric

Quoted 19 lines
target/arm/kvm.c +9 -0
+        kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
         cpu->psci_version = QEMU_PSCI_VERSION_0_2;
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
     }
@@ -1998,6 +2048,14 @@ int kvm_arch_init_vcpu(CPUState *cs)
         }
     }
 
+    if (cpu->prop_psci_version) {
+        psciver = cpu->prop_psci_version;
+        ret = kvm_set_one_reg(cs, KVM_REG_ARM_PSCI_VERSION, &psciver);
+        if (ret) {
+            error_report("PSCI version %"PRIx64" is not supported by KVM", psciver);
+            return ret;
+        }
+    }
     /*
      * KVM reports the exact PSCI version it is implementing via a
      * special sysreg. If it is present, use its contents to determine
#5 lore raw

Re: [PATCH v2 2/2] target/arm/kvm: add kvm-psci-version vcpu property

Quoted 7 lines · Eric Auger
Quoted 6 lines · Sebastian Ott

Provide a kvm specific vcpu property to override the default (as of kernel v6.13 that would be PSCI v1.3) PSCI version emulated by kvm. Current valid values are: 0.1, 0.2, 1.0, 1.1, 1.2, and 1.3

---

[...]

Quoted 4 lines
Quoted 4 lines
target/arm/kvm.c +4 -0
+static char *kvm_get_psci_version(Object *obj, Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    const struct psci_version *ver;
Quoted 8 lines

target/arm/kvm.c static void kvm_steal_time_set(Object *obj, bool value, Error **errp) · line 508

Quoted 3 lines
target/arm/kvm.c +3 -0
+
+    for (ver = psci_versions; ver->number != -1; ver++) {
+        if (ver->number == cpu->prop_psci_version)

I still have the same question/comment as on v1. In case the end user does not override the psci version I think you want to return the default value, retrieved from KVM through KVM_REG_ARM_PSCI_VERSION and which populates cpu->psci_version. So to me you should use cpu->psci_version instead

Sry, I didn't get your question the first time and double checked that the VM uses the default/most recent version when the property is not set.

I just found out how to actually call this function (via qom-get) and you're right: the VM uses the correct version but we report something different here - and in this version even trigger the assertion. Ouch.

[...]

Quoted 8 lines

target/arm/kvm.c int kvm_arch_init_vcpu(CPUState *cs) · line 2011

Quoted 6 lines
target/arm/kvm.c +1 -1
@@ -1959,7 +2008,8 @@ int kvm_arch_init_vcpu(CPUState *cs)
     if (cs->start_powered_off) {
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
-    if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+    if (cpu->prop_psci_version != QEMU_PSCI_VERSION_0_1 &&

I don't understand what this change stands for. Please document it through both a comment and a commit msg explanation

The explanation is in the cover letter - I'll move it to this patch.

Thanks,
Sebastian