arm: add kvm-psci-version vcpu property
v6 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 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/[email protected]/
[2] https://lore.kernel.org/kvmarm/[email protected]/
[3] https://lore.kernel.org/kvmarm/[email protected]/
[4] https://lore.kernel.org/kvmarm/[email protected]/
[5] https://lore.kernel.org/kvmarm/[email protected]/
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(-)
Signature · 1 line
2.52.0
PATCH v6 1/1 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.
--- docs/system/arm/cpu-features.rst | 11 ++++++++ target/arm/cpu.c | 8 +++++- target/arm/kvm.c | 48 ++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-)
docs/system/arm/cpu-features.rst +11 -0
@@ -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 =================
target/arm/cpu.c +7 -1
@@ -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 ()) {
target/arm/kvm.c +46 -2
72 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v6 1/1] target/arm/kvm: add kvm-psci-version vcpu property
Quoted 71 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
Note: in order to support PSCI v0.1 we need to drop vcpu initialization with
KVM_CAP_ARM_PSCI_0_2in that case.Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Signed-off-by Sebastian Ott <[email protected]>--- docs/system/arm/cpu-features.rst | 11 ++++++++ target/arm/cpu.c | 8 +++++- target/arm/kvm.c | 48 ++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-)docs/system/arm/cpu-features.rst +11
-0@@ -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 =================target/arm/cpu.c +7
-1@@ -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 ()) {target/arm/kvm.c +5
-0@@ -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",
target/arm/kvm.c static void kvm_steal_time_set(Object *obj, bool value, Error **errp) · line 502
Quoted 10 lines
target/arm/kvm.c +10
-0+ (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
Re: [PATCH v6 1/1] target/arm/kvm: add kvm-psci-version vcpu property
Quoted 77 lines · Peter Maydell
Quoted 76 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
Note: in order to support PSCI v0.1 we need to drop vcpu initialization with
KVM_CAP_ARM_PSCI_0_2in that case.Reviewed-by Eric Auger <[email protected]>Tested-by Eric Auger <[email protected]>Signed-off-by Sebastian Ott <[email protected]>--- docs/system/arm/cpu-features.rst | 11 ++++++++ target/arm/cpu.c | 8 +++++- target/arm/kvm.c | 48 ++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-)docs/system/arm/cpu-features.rst +11
-0@@ -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 =================target/arm/cpu.c +7
-1@@ -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 ()) {target/arm/kvm.c +10
-0@@ -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)
Quoted 8 lines
target/arm/kvm.c static void kvm_steal_time_set(Object *obj, bool value, Error **errp) · line 502
Quoted 5 lines
target/arm/kvm.c +5
-0+{ +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.
Quoted 1 line
(If you agree I can just make this fix locally, no need for you to respin.)
That'd be great, Thanks!
Sebastian