public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/1] arm: add kvm-psci-version vcpu property
@ 2026-02-20 11:56 Sebastian Ott
  2026-02-20 11:56 ` [PATCH v6 1/1] target/arm/kvm: " Sebastian Ott
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Ott @ 2026-02-20 11:56 UTC (permalink / raw)
  To: peter.maydell, qemu-devel
  Cc: eric.auger, kvm, kvmarm, pbonzini, qemu-arm, Sebastian Ott

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 V5 [5]:
* incorporated feedback from Peter
* dropped patch that is already upstream
Changes since V4 [4]:
* incorporated feedback from Peter
* added R-B, T-B
Changes since V3 [3]:
* changed variable name as requested by Eric
* added R-B
Changes since V2 [2]:
* fix kvm_get_psci_version() when the prop is not specified - thanks Eric!
* removed the assertion in kvm_get_psci_version() so that this also works
  with a future kernel/psci version
* added R-B
Changes since V1 [1]:
* incorporated feedback from Peter and Eric

[1] https://lore.kernel.org/kvmarm/20250911144923.24259-1-sebott@redhat.com/
[2] https://lore.kernel.org/kvmarm/20251030165905.73295-1-sebott@redhat.com/
[3] https://lore.kernel.org/kvmarm/20251112181357.38999-1-sebott@redhat.com/
[4] https://lore.kernel.org/kvmarm/20251202160853.22560-1-sebott@redhat.com/
[5] https://lore.kernel.org/kvmarm/20260211153032.19327-1-sebott@redhat.com/

Sebastian Ott (1):
  target/arm/kvm: add kvm-psci-version vcpu property

 docs/system/arm/cpu-features.rst | 11 ++++++++
 target/arm/cpu.c                 |  8 +++++-
 target/arm/kvm.c                 | 48 ++++++++++++++++++++++++++++++--
 3 files changed, 64 insertions(+), 3 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v6 1/1] target/arm/kvm: add kvm-psci-version vcpu property
  2026-02-20 11:56 [PATCH v6 0/1] arm: add kvm-psci-version vcpu property Sebastian Ott
@ 2026-02-20 11:56 ` Sebastian Ott
  2026-02-24 14:34   ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Ott @ 2026-02-20 11:56 UTC (permalink / raw)
  To: peter.maydell, qemu-devel
  Cc: eric.auger, kvm, kvmarm, pbonzini, qemu-arm, 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

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>
---
 docs/system/arm/cpu-features.rst | 11 ++++++++
 target/arm/cpu.c                 |  8 +++++-
 target/arm/kvm.c                 | 48 ++++++++++++++++++++++++++++++--
 3 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-features.rst
index 3db1f19401..ce19ae6a04 100644
--- a/docs/system/arm/cpu-features.rst
+++ b/docs/system/arm/cpu-features.rst
@@ -204,6 +204,17 @@ the list of KVM VCPU features and their descriptions.
   the guest scheduler behavior and/or be exposed to the guest
   userspace.
 
+``kvm-psci-version``
+  Set the Power State Coordination Interface (PSCI) firmware ABI version
+  that KVM provides to the guest. By default KVM will use the newest
+  version that it knows about (which is PSCI v1.3 in Linux v6.13).
+
+  You only need to set this if you want to be able to migrate this
+  VM to a host machine running an older kernel that does not
+  recognize the PSCI version that this host's kernel defaults to.
+
+  Current valid values are: 0.1, 0.2, 1.0, 1.1, 1.2, and 1.3.
+
 TCG VCPU Features
 =================
 
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 10f8280eef..60f391651d 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1144,7 +1144,13 @@ static void arm_cpu_initfn(Object *obj)
      * picky DTB consumer will also provide a helpful error message.
      */
     cpu->dtb_compatible = "qemu,unknown";
-    cpu->psci_version = QEMU_PSCI_VERSION_0_1; /* By default assume PSCI v0.1 */
+    if (!kvm_enabled()) {
+        /* By default KVM will use the newest PSCI version that it knows about.
+         * This can be changed using the kvm-psci-version property.
+         * For others assume PSCI v0.1 by default.
+         */
+        cpu->psci_version = QEMU_PSCI_VERSION_0_1;
+    }
     cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
 
     if (tcg_enabled() || hvf_enabled()) {
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index ded582e0da..5453460965 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -485,6 +485,28 @@ 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;
 }
 
+static char *kvm_get_psci_version(Object *obj, Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+
+    return g_strdup_printf("%d.%d",
+                           (int) PSCI_VERSION_MAJOR(cpu->psci_version),
+                           (int) PSCI_VERSION_MINOR(cpu->psci_version));
+}
+
+static void kvm_set_psci_version(Object *obj, const char *value, Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    uint16_t maj, min;
+
+    if (sscanf(value, "%hd.%hd", &maj, &min) != 2) {
+        error_setg(errp, "Invalid PSCI version.");
+        return;
+    }
+
+    cpu->psci_version = PSCI_VERSION(maj, min);
+}
+
 /* KVM VCPU properties should be prefixed with "kvm-". */
 void kvm_arm_add_vcpu_properties(ARMCPU *cpu)
 {
@@ -506,6 +528,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)
@@ -1976,8 +2004,12 @@ 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)) {
-        cpu->psci_version = QEMU_PSCI_VERSION_0_2;
+    if (cpu->psci_version != QEMU_PSCI_VERSION_0_1 &&
+        kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
+        /*
+         * Versions >= v0.2 are backward compatible with v0.2
+         * omit the feature flag for v0.1 .
+         */
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
     }
     if (!arm_feature(env, ARM_FEATURE_AARCH64)) {
@@ -2015,6 +2047,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
         }
     }
 
+    if (cpu->psci_version) {
+        psciver = cpu->psci_version;
+        ret = kvm_set_one_reg(cs, KVM_REG_ARM_PSCI_VERSION, &psciver);
+        if (ret) {
+            error_report("KVM in this kernel does not support PSCI version %d.%d",
+                         (int) PSCI_VERSION_MAJOR(psciver),
+                         (int) PSCI_VERSION_MINOR(psciver));
+            error_printf("Consider setting the kvm-psci-version property on the "
+                         "migration source.\n");
+            return ret;
+        }
+    }
     /*
      * KVM reports the exact PSCI version it is implementing via a
      * special sysreg. If it is present, use its contents to determine
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v6 1/1] target/arm/kvm: add kvm-psci-version vcpu property
  2026-02-20 11:56 ` [PATCH v6 1/1] target/arm/kvm: " Sebastian Ott
@ 2026-02-24 14:34   ` Peter Maydell
  2026-02-25  7:16     ` Sebastian Ott
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2026-02-24 14:34 UTC (permalink / raw)
  To: Sebastian Ott; +Cc: qemu-devel, eric.auger, kvm, kvmarm, pbonzini, qemu-arm

On Fri, 20 Feb 2026 at 11:57, Sebastian Ott <sebott@redhat.com> wrote:
>
> 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>
> ---
>  docs/system/arm/cpu-features.rst | 11 ++++++++
>  target/arm/cpu.c                 |  8 +++++-
>  target/arm/kvm.c                 | 48 ++++++++++++++++++++++++++++++--
>  3 files changed, 64 insertions(+), 3 deletions(-)
>
> diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-features.rst
> index 3db1f19401..ce19ae6a04 100644
> --- a/docs/system/arm/cpu-features.rst
> +++ b/docs/system/arm/cpu-features.rst
> @@ -204,6 +204,17 @@ the list of KVM VCPU features and their descriptions.
>    the guest scheduler behavior and/or be exposed to the guest
>    userspace.
>
> +``kvm-psci-version``
> +  Set the Power State Coordination Interface (PSCI) firmware ABI version
> +  that KVM provides to the guest. By default KVM will use the newest
> +  version that it knows about (which is PSCI v1.3 in Linux v6.13).
> +
> +  You only need to set this if you want to be able to migrate this
> +  VM to a host machine running an older kernel that does not
> +  recognize the PSCI version that this host's kernel defaults to.
> +
> +  Current valid values are: 0.1, 0.2, 1.0, 1.1, 1.2, and 1.3.
> +
>  TCG VCPU Features
>  =================
>
> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
> index 10f8280eef..60f391651d 100644
> --- a/target/arm/cpu.c
> +++ b/target/arm/cpu.c
> @@ -1144,7 +1144,13 @@ static void arm_cpu_initfn(Object *obj)
>       * picky DTB consumer will also provide a helpful error message.
>       */
>      cpu->dtb_compatible = "qemu,unknown";
> -    cpu->psci_version = QEMU_PSCI_VERSION_0_1; /* By default assume PSCI v0.1 */
> +    if (!kvm_enabled()) {
> +        /* By default KVM will use the newest PSCI version that it knows about.
> +         * This can be changed using the kvm-psci-version property.
> +         * For others assume PSCI v0.1 by default.
> +         */
> +        cpu->psci_version = QEMU_PSCI_VERSION_0_1;
> +    }
>      cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
>
>      if (tcg_enabled() || hvf_enabled()) {
> diff --git a/target/arm/kvm.c b/target/arm/kvm.c
> index ded582e0da..5453460965 100644
> --- a/target/arm/kvm.c
> +++ b/target/arm/kvm.c
> @@ -485,6 +485,28 @@ 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;
>  }
>
> +static char *kvm_get_psci_version(Object *obj, Error **errp)
> +{
> +    ARMCPU *cpu = ARM_CPU(obj);
> +
> +    return g_strdup_printf("%d.%d",
> +                           (int) PSCI_VERSION_MAJOR(cpu->psci_version),
> +                           (int) PSCI_VERSION_MINOR(cpu->psci_version));
> +}
> +
> +static void kvm_set_psci_version(Object *obj, const char *value, Error **errp)
> +{
> +    ARMCPU *cpu = ARM_CPU(obj);
> +    uint16_t maj, min;
> +
> +    if (sscanf(value, "%hd.%hd", &maj, &min) != 2) {

%hd is a signed value, so this will accept "-3.-5" I think ?
Probably we want %hu.

(If you agree I can just make this fix locally, no need for you to respin.)

-- PMM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v6 1/1] target/arm/kvm: add kvm-psci-version vcpu property
  2026-02-24 14:34   ` Peter Maydell
@ 2026-02-25  7:16     ` Sebastian Ott
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Ott @ 2026-02-25  7:16 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, eric.auger, kvm, kvmarm, pbonzini, qemu-arm



On Tue, 24 Feb 2026, Peter Maydell wrote:

> On Fri, 20 Feb 2026 at 11:57, Sebastian Ott <sebott@redhat.com> wrote:
>>
>> 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>
>> ---
>>  docs/system/arm/cpu-features.rst | 11 ++++++++
>>  target/arm/cpu.c                 |  8 +++++-
>>  target/arm/kvm.c                 | 48 ++++++++++++++++++++++++++++++--
>>  3 files changed, 64 insertions(+), 3 deletions(-)
>>
>> diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-features.rst
>> index 3db1f19401..ce19ae6a04 100644
>> --- a/docs/system/arm/cpu-features.rst
>> +++ b/docs/system/arm/cpu-features.rst
>> @@ -204,6 +204,17 @@ the list of KVM VCPU features and their descriptions.
>>    the guest scheduler behavior and/or be exposed to the guest
>>    userspace.
>>
>> +``kvm-psci-version``
>> +  Set the Power State Coordination Interface (PSCI) firmware ABI version
>> +  that KVM provides to the guest. By default KVM will use the newest
>> +  version that it knows about (which is PSCI v1.3 in Linux v6.13).
>> +
>> +  You only need to set this if you want to be able to migrate this
>> +  VM to a host machine running an older kernel that does not
>> +  recognize the PSCI version that this host's kernel defaults to.
>> +
>> +  Current valid values are: 0.1, 0.2, 1.0, 1.1, 1.2, and 1.3.
>> +
>>  TCG VCPU Features
>>  =================
>>
>> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
>> index 10f8280eef..60f391651d 100644
>> --- a/target/arm/cpu.c
>> +++ b/target/arm/cpu.c
>> @@ -1144,7 +1144,13 @@ static void arm_cpu_initfn(Object *obj)
>>       * picky DTB consumer will also provide a helpful error message.
>>       */
>>      cpu->dtb_compatible = "qemu,unknown";
>> -    cpu->psci_version = QEMU_PSCI_VERSION_0_1; /* By default assume PSCI v0.1 */
>> +    if (!kvm_enabled()) {
>> +        /* By default KVM will use the newest PSCI version that it knows about.
>> +         * This can be changed using the kvm-psci-version property.
>> +         * For others assume PSCI v0.1 by default.
>> +         */
>> +        cpu->psci_version = QEMU_PSCI_VERSION_0_1;
>> +    }
>>      cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
>>
>>      if (tcg_enabled() || hvf_enabled()) {
>> diff --git a/target/arm/kvm.c b/target/arm/kvm.c
>> index ded582e0da..5453460965 100644
>> --- a/target/arm/kvm.c
>> +++ b/target/arm/kvm.c
>> @@ -485,6 +485,28 @@ 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;
>>  }
>>
>> +static char *kvm_get_psci_version(Object *obj, Error **errp)
>> +{
>> +    ARMCPU *cpu = ARM_CPU(obj);
>> +
>> +    return g_strdup_printf("%d.%d",
>> +                           (int) PSCI_VERSION_MAJOR(cpu->psci_version),
>> +                           (int) PSCI_VERSION_MINOR(cpu->psci_version));
>> +}
>> +
>> +static void kvm_set_psci_version(Object *obj, const char *value, Error **errp)
>> +{
>> +    ARMCPU *cpu = ARM_CPU(obj);
>> +    uint16_t maj, min;
>> +
>> +    if (sscanf(value, "%hd.%hd", &maj, &min) != 2) {
>
> %hd is a signed value, so this will accept "-3.-5" I think ?
> Probably we want %hu.

Ugh, right.

> (If you agree I can just make this fix locally, no need for you to respin.)

That'd be great, Thanks!

Sebastian


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-25  7:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-20 11:56 [PATCH v6 0/1] arm: add kvm-psci-version vcpu property Sebastian Ott
2026-02-20 11:56 ` [PATCH v6 1/1] target/arm/kvm: " Sebastian Ott
2026-02-24 14:34   ` Peter Maydell
2026-02-25  7:16     ` Sebastian Ott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox