target/arm/kvm: add kvm-psci-version vcpu property
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 Note: in order to support PSCI v0.1 we need to drop vcpu initialization with KVM_CAP_ARM_PSCI_0_2 in that case. Reviewed-by: Eric Auger <eric.auger@redhat.com> Tested-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Sebastian Ott <sebott@redhat.com> Message-id: 20260220115656.4831-2-sebott@redhat.com [PMM: adjust sscanf to not permit negative numbers] Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Sebastian Ott committed
Feb 26, 2026 at 11:27 UTC
a99e32dbd4a11fdf168438ded961a5fb70a37503
3 files changed
+64
-3
docs/system/arm/cpu-features.rst
+11
@@ -204,6 +204,17 @@ the list of KVM VCPU features and their descriptions.
204
the guest scheduler behavior and/or be exposed to the guest
205
userspace.
206
207
+``kvm-psci-version``
208
+ Set the Power State Coordination Interface (PSCI) firmware ABI version
209
+ that KVM provides to the guest. By default KVM will use the newest
210
+ version that it knows about (which is PSCI v1.3 in Linux v6.13).
211
+
212
+ You only need to set this if you want to be able to migrate this
213
+ VM to a host machine running an older kernel that does not
214
+ recognize the PSCI version that this host's kernel defaults to.
215
+
216
+ Current valid values are: 0.1, 0.2, 1.0, 1.1, 1.2, and 1.3.
217
+
218
TCG VCPU Features
219
=================
220
target/arm/cpu.c
+7
-1
@@ -1144,7 +1144,13 @@ static void arm_cpu_initfn(Object *obj)
1144
* picky DTB consumer will also provide a helpful error message.
1145
*/
1146
cpu->dtb_compatible = "qemu,unknown";
1147
- cpu->psci_version = QEMU_PSCI_VERSION_0_1; /* By default assume PSCI v0.1 */
1147
+ if (!kvm_enabled()) {
1148
+ /* By default KVM will use the newest PSCI version that it knows about.
1149
+ * This can be changed using the kvm-psci-version property.
1150
+ * For others assume PSCI v0.1 by default.
1151
+ */
1152
+ cpu->psci_version = QEMU_PSCI_VERSION_0_1;
1153
+ }
1154
cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
1155
1156
if (tcg_enabled() || hvf_enabled()) {
target/arm/kvm.c
+46
-2
@@ -485,6 +485,28 @@ static void kvm_steal_time_set(Object *obj, bool value, Error **errp)
485
ARM_CPU(obj)->kvm_steal_time = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
486
}
487
488
+static char *kvm_get_psci_version(Object *obj, Error **errp)
489
+{
490
+ ARMCPU *cpu = ARM_CPU(obj);
491
+
492
+ return g_strdup_printf("%d.%d",
493
+ (int) PSCI_VERSION_MAJOR(cpu->psci_version),
494
+ (int) PSCI_VERSION_MINOR(cpu->psci_version));
495
+}
496
+
497
+static void kvm_set_psci_version(Object *obj, const char *value, Error **errp)
498
+{
499
+ ARMCPU *cpu = ARM_CPU(obj);
500
+ uint16_t maj, min;
501
+
502
+ if (sscanf(value, "%hu.%hu", &maj, &min) != 2) {
503
+ error_setg(errp, "Invalid PSCI version.");
504
+ return;
505
+ }
506
+
507
+ cpu->psci_version = PSCI_VERSION(maj, min);
508
+}
509
+
510
/* KVM VCPU properties should be prefixed with "kvm-". */
511
void kvm_arm_add_vcpu_properties(ARMCPU *cpu)
512
{
@@ -506,6 +528,12 @@ void kvm_arm_add_vcpu_properties(ARMCPU *cpu)
528
kvm_steal_time_set);
529
object_property_set_description(obj, "kvm-steal-time",
530
"Set off to disable KVM steal time.");
531
+
532
+ object_property_add_str(obj, "kvm-psci-version", kvm_get_psci_version,
533
+ kvm_set_psci_version);
534
+ object_property_set_description(obj, "kvm-psci-version",
535
+ "Set PSCI version. "
536
+ "Valid values are 0.1, 0.2, 1.0, 1.1, 1.2, 1.3");
537
}
538
539
bool kvm_arm_pmu_supported(void)
@@ -1976,8 +2004,12 @@ int kvm_arch_init_vcpu(CPUState *cs)
2004
if (cs->start_powered_off) {
2005
cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
2006
}
1979
- if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
1980
- cpu->psci_version = QEMU_PSCI_VERSION_0_2;
2007
+ if (cpu->psci_version != QEMU_PSCI_VERSION_0_1 &&
2008
+ kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
2009
+ /*
2010
+ * Versions >= v0.2 are backward compatible with v0.2
2011
+ * omit the feature flag for v0.1 .
2012
+ */
2013
cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
2014
}
2015
if (!arm_feature(env, ARM_FEATURE_AARCH64)) {
@@ -2015,6 +2047,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
2047
}
2048
}
2049
2050
+ if (cpu->psci_version) {
2051
+ psciver = cpu->psci_version;
2052
+ ret = kvm_set_one_reg(cs, KVM_REG_ARM_PSCI_VERSION, &psciver);
2053
+ if (ret) {
2054
+ error_report("KVM in this kernel does not support PSCI version %d.%d",
2055
+ (int) PSCI_VERSION_MAJOR(psciver),
2056
+ (int) PSCI_VERSION_MINOR(psciver));
2057
+ error_printf("Consider setting the kvm-psci-version property on the "
2058
+ "migration source.\n");
2059
+ return ret;
2060
+ }
2061
+ }
2062
/*
2063
* KVM reports the exact PSCI version it is implementing via a
2064
* special sysreg. If it is present, use its contents to determine