* [PATCH v3 0/2] arm: add kvm-psci-version vcpu property @ 2025-11-12 18:13 Sebastian Ott 2025-11-12 18:13 ` [PATCH v3 1/2] target/arm/kvm: add constants for new PSCI versions Sebastian Ott 2025-11-12 18:13 ` [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property Sebastian Ott 0 siblings, 2 replies; 9+ messages in thread From: Sebastian Ott @ 2025-11-12 18:13 UTC (permalink / raw) To: Peter Maydell, Paolo Bonzini, Eric Auger Cc: qemu-arm, qemu-devel, kvm, kvmarm, 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 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/ 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 | 64 +++++++++++++++++++++++++++++++- 4 files changed, 76 insertions(+), 1 deletion(-) -- 2.42.0 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 1/2] target/arm/kvm: add constants for new PSCI versions 2025-11-12 18:13 [PATCH v3 0/2] arm: add kvm-psci-version vcpu property Sebastian Ott @ 2025-11-12 18:13 ` Sebastian Ott 2025-11-12 18:13 ` [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property Sebastian Ott 1 sibling, 0 replies; 9+ messages in thread From: Sebastian Ott @ 2025-11-12 18:13 UTC (permalink / raw) To: Peter Maydell, Paolo Bonzini, Eric Auger Cc: qemu-arm, qemu-devel, kvm, kvmarm, Sebastian Ott Add constants for PSCI version 1_2 and 1_3. Signed-off-by: Sebastian Ott <sebott@redhat.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> --- target/arm/kvm-consts.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/arm/kvm-consts.h b/target/arm/kvm-consts.h index 54ae5da7ce..9fba3e886d 100644 --- a/target/arm/kvm-consts.h +++ b/target/arm/kvm-consts.h @@ -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 */ -- 2.42.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property 2025-11-12 18:13 [PATCH v3 0/2] arm: add kvm-psci-version vcpu property Sebastian Ott 2025-11-12 18:13 ` [PATCH v3 1/2] target/arm/kvm: add constants for new PSCI versions Sebastian Ott @ 2025-11-12 18:13 ` Sebastian Ott 2025-11-12 21:07 ` Philippe Mathieu-Daudé 2025-11-20 10:11 ` Eric Auger 1 sibling, 2 replies; 9+ messages in thread From: Sebastian Ott @ 2025-11-12 18:13 UTC (permalink / raw) To: Peter Maydell, Paolo Bonzini, Eric Auger Cc: qemu-arm, qemu-devel, kvm, kvmarm, 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. Signed-off-by: Sebastian Ott <sebott@redhat.com> --- docs/system/arm/cpu-features.rst | 5 +++ target/arm/cpu.h | 6 +++ target/arm/kvm.c | 64 +++++++++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-features.rst index 37d5dfd15b..1d32ce0fee 100644 --- a/docs/system/arm/cpu-features.rst +++ b/docs/system/arm/cpu-features.rst @@ -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 ================= diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 39f2b2e54d..c2032070b7 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -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; diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 0d57081e69..e91b1abfb8 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -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" }, + { -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->psci_version) + return g_strdup(ver->str); + } + + return g_strdup_printf("Unknown PSCI-version: %x", cpu->psci_version); +} + +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) @@ -1959,7 +2008,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)) { + if (cpu->prop_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->psci_version = QEMU_PSCI_VERSION_0_2; cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2; } @@ -1998,6 +2052,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 -- 2.42.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property 2025-11-12 18:13 ` [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property Sebastian Ott @ 2025-11-12 21:07 ` Philippe Mathieu-Daudé 2025-11-13 12:05 ` Sebastian Ott 2025-11-20 10:11 ` Eric Auger 1 sibling, 1 reply; 9+ messages in thread From: Philippe Mathieu-Daudé @ 2025-11-12 21:07 UTC (permalink / raw) To: Sebastian Ott, Peter Maydell, Paolo Bonzini, Eric Auger Cc: qemu-arm, qemu-devel, kvm, kvmarm Hi Sebastian, On 12/11/25 19:13, Sebastian Ott 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. > > Signed-off-by: Sebastian Ott <sebott@redhat.com> > --- > docs/system/arm/cpu-features.rst | 5 +++ > target/arm/cpu.h | 6 +++ > target/arm/kvm.c | 64 +++++++++++++++++++++++++++++++- > 3 files changed, 74 insertions(+), 1 deletion(-) > diff --git a/target/arm/kvm.c b/target/arm/kvm.c > index 0d57081e69..e91b1abfb8 100644 > --- a/target/arm/kvm.c > +++ b/target/arm/kvm.c > @@ -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" }, > + { -1, NULL }, > +}; > @@ -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"); Could we enumerate from psci_versions[] here? > } Thanks, Phil. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property 2025-11-12 21:07 ` Philippe Mathieu-Daudé @ 2025-11-13 12:05 ` Sebastian Ott 2025-11-20 10:10 ` Eric Auger 0 siblings, 1 reply; 9+ messages in thread From: Sebastian Ott @ 2025-11-13 12:05 UTC (permalink / raw) To: Philippe Mathieu-Daudé Cc: Peter Maydell, Paolo Bonzini, Eric Auger, qemu-arm, qemu-devel, kvm, kvmarm [-- Attachment #1: Type: text/plain, Size: 2863 bytes --] Hi Philippe, On Wed, 12 Nov 2025, Philippe Mathieu-Daudé wrote: > On 12/11/25 19:13, Sebastian Ott 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. >> >> Signed-off-by: Sebastian Ott <sebott@redhat.com> >> --- >> docs/system/arm/cpu-features.rst | 5 +++ >> target/arm/cpu.h | 6 +++ >> target/arm/kvm.c | 64 +++++++++++++++++++++++++++++++- >> 3 files changed, 74 insertions(+), 1 deletion(-) > > >> diff --git a/target/arm/kvm.c b/target/arm/kvm.c >> index 0d57081e69..e91b1abfb8 100644 >> --- a/target/arm/kvm.c >> +++ b/target/arm/kvm.c >> @@ -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" }, >> + { -1, NULL }, >> +}; > > >> @@ -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"); > > Could we enumerate from psci_versions[] here? > Hm, we'd need to concatenate these. Either manually: "Valid values are " psci_versions[0].str ", " psci_versions[1].str ", " ... which is not pretty and still needs to be touched for a new version. Or by a helper function that puts these in a new array and uses smth like g_strjoinv(", ", array); But that's quite a bit of extra code that needs to be maintained without much gain. Or we shy away from the issue and rephrase that to: "Valid values include 1.0, 1.1, 1.2, 1.3" Since the intended use case is via machine types and I don't expect a lot of users setting the psci version manually - I vote for option 3. Opinions? Sebastian ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property 2025-11-13 12:05 ` Sebastian Ott @ 2025-11-20 10:10 ` Eric Auger 2025-11-20 10:43 ` Philippe Mathieu-Daudé 2025-11-20 13:11 ` Sebastian Ott 0 siblings, 2 replies; 9+ messages in thread From: Eric Auger @ 2025-11-20 10:10 UTC (permalink / raw) To: Sebastian Ott, Philippe Mathieu-Daudé Cc: Peter Maydell, Paolo Bonzini, qemu-arm, qemu-devel, kvm, kvmarm On 11/13/25 1:05 PM, Sebastian Ott wrote: > Hi Philippe, > > On Wed, 12 Nov 2025, Philippe Mathieu-Daudé wrote: >> On 12/11/25 19:13, Sebastian Ott 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. >>> >>> Signed-off-by: Sebastian Ott <sebott@redhat.com> >>> --- >>> docs/system/arm/cpu-features.rst | 5 +++ >>> target/arm/cpu.h | 6 +++ >>> target/arm/kvm.c | 64 >>> +++++++++++++++++++++++++++++++- >>> 3 files changed, 74 insertions(+), 1 deletion(-) >> >> >>> diff --git a/target/arm/kvm.c b/target/arm/kvm.c >>> index 0d57081e69..e91b1abfb8 100644 >>> --- a/target/arm/kvm.c >>> +++ b/target/arm/kvm.c >>> @@ -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" }, >>> + { -1, NULL }, >>> +}; >> >> >>> @@ -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"); >> >> Could we enumerate from psci_versions[] here? >> > > Hm, we'd need to concatenate these. Either manually: > "Valid values are " psci_versions[0].str ", " psci_versions[1].str ", > " ... which is not pretty and still needs to be touched for a new > version. > > Or by a helper function that puts these in a new array and uses smth like > g_strjoinv(", ", array); > But that's quite a bit of extra code that needs to be maintained without > much gain. > > Or we shy away from the issue and rephrase that to: > "Valid values include 1.0, 1.1, 1.2, 1.3" Personally I would vote for keeping it as is (by the way why did you moit 0.1 and 0.2 above?) Eric > > Since the intended use case is via machine types and I don't expect a > lot of users setting the psci version manually - I vote for option 3. > > Opinions? > > Sebastian ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property 2025-11-20 10:10 ` Eric Auger @ 2025-11-20 10:43 ` Philippe Mathieu-Daudé 2025-11-20 13:11 ` Sebastian Ott 1 sibling, 0 replies; 9+ messages in thread From: Philippe Mathieu-Daudé @ 2025-11-20 10:43 UTC (permalink / raw) To: eric.auger, Sebastian Ott Cc: Peter Maydell, Paolo Bonzini, qemu-arm, qemu-devel, kvm, kvmarm On 20/11/25 11:10, Eric Auger wrote: > > > On 11/13/25 1:05 PM, Sebastian Ott wrote: >> Hi Philippe, >> >> On Wed, 12 Nov 2025, Philippe Mathieu-Daudé wrote: >>> On 12/11/25 19:13, Sebastian Ott 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. >>>> >>>> Signed-off-by: Sebastian Ott <sebott@redhat.com> >>>> --- >>>> docs/system/arm/cpu-features.rst | 5 +++ >>>> target/arm/cpu.h | 6 +++ >>>> target/arm/kvm.c | 64 >>>> +++++++++++++++++++++++++++++++- >>>> 3 files changed, 74 insertions(+), 1 deletion(-) >>> >>> >>>> diff --git a/target/arm/kvm.c b/target/arm/kvm.c >>>> index 0d57081e69..e91b1abfb8 100644 >>>> --- a/target/arm/kvm.c >>>> +++ b/target/arm/kvm.c >>>> @@ -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" }, >>>> + { -1, NULL }, >>>> +}; >>> >>> >>>> @@ -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"); >>> >>> Could we enumerate from psci_versions[] here? >>> >> >> Hm, we'd need to concatenate these. Either manually: >> "Valid values are " psci_versions[0].str ", " psci_versions[1].str ", >> " ... which is not pretty and still needs to be touched for a new >> version. >> >> Or by a helper function that puts these in a new array and uses smth like >> g_strjoinv(", ", array); >> But that's quite a bit of extra code that needs to be maintained without >> much gain. >> >> Or we shy away from the issue and rephrase that to: >> "Valid values include 1.0, 1.1, 1.2, 1.3" > Personally I would vote for keeping it as is OK. > (by the way why did you > moit 0.1 and 0.2 above?) > > Eric >> >> Since the intended use case is via machine types and I don't expect a >> lot of users setting the psci version manually - I vote for option 3. >> >> Opinions? >> >> Sebastian > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property 2025-11-20 10:10 ` Eric Auger 2025-11-20 10:43 ` Philippe Mathieu-Daudé @ 2025-11-20 13:11 ` Sebastian Ott 1 sibling, 0 replies; 9+ messages in thread From: Sebastian Ott @ 2025-11-20 13:11 UTC (permalink / raw) To: Eric Auger Cc: Philippe Mathieu-Daudé, Peter Maydell, Paolo Bonzini, qemu-arm, qemu-devel, kvm, kvmarm [-- Attachment #1: Type: text/plain, Size: 3509 bytes --] On Thu, 20 Nov 2025, Eric Auger wrote: > On 11/13/25 1:05 PM, Sebastian Ott wrote: >> Hi Philippe, >> >> On Wed, 12 Nov 2025, Philippe Mathieu-Daudé wrote: >>> On 12/11/25 19:13, Sebastian Ott 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. >>>> >>>> Signed-off-by: Sebastian Ott <sebott@redhat.com> >>>> --- >>>> docs/system/arm/cpu-features.rst | 5 +++ >>>> target/arm/cpu.h | 6 +++ >>>> target/arm/kvm.c | 64 >>>> +++++++++++++++++++++++++++++++- >>>> 3 files changed, 74 insertions(+), 1 deletion(-) >>> >>> >>>> diff --git a/target/arm/kvm.c b/target/arm/kvm.c >>>> index 0d57081e69..e91b1abfb8 100644 >>>> --- a/target/arm/kvm.c >>>> +++ b/target/arm/kvm.c >>>> @@ -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" }, >>>> + { -1, NULL }, >>>> +}; >>> >>> >>>> @@ -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"); >>> >>> Could we enumerate from psci_versions[] here? >>> >> >> Hm, we'd need to concatenate these. Either manually: >> "Valid values are " psci_versions[0].str ", " psci_versions[1].str ", >> " ... which is not pretty and still needs to be touched for a new >> version. >> >> Or by a helper function that puts these in a new array and uses smth like >> g_strjoinv(", ", array); >> But that's quite a bit of extra code that needs to be maintained without >> much gain. >> >> Or we shy away from the issue and rephrase that to: >> "Valid values include 1.0, 1.1, 1.2, 1.3" > Personally I would vote for keeping it as is OK, thanks! > (by the way why did you > moit 0.1 and 0.2 above?) Just to clarify that this is an incomplete list of possible values that we don't have to change when a new psci version is introduced. Sebastian ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property 2025-11-12 18:13 ` [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property Sebastian Ott 2025-11-12 21:07 ` Philippe Mathieu-Daudé @ 2025-11-20 10:11 ` Eric Auger 1 sibling, 0 replies; 9+ messages in thread From: Eric Auger @ 2025-11-20 10:11 UTC (permalink / raw) To: Sebastian Ott, Peter Maydell, Paolo Bonzini Cc: qemu-arm, qemu-devel, kvm, kvmarm Hi Sebastian, On 11/12/25 7:13 PM, Sebastian Ott 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. > > Signed-off-by: Sebastian Ott <sebott@redhat.com> > --- > docs/system/arm/cpu-features.rst | 5 +++ > target/arm/cpu.h | 6 +++ > target/arm/kvm.c | 64 +++++++++++++++++++++++++++++++- > 3 files changed, 74 insertions(+), 1 deletion(-) > > diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-features.rst > index 37d5dfd15b..1d32ce0fee 100644 > --- a/docs/system/arm/cpu-features.rst > +++ b/docs/system/arm/cpu-features.rst > @@ -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 > ================= > > diff --git a/target/arm/cpu.h b/target/arm/cpu.h > index 39f2b2e54d..c2032070b7 100644 > --- a/target/arm/cpu.h > +++ b/target/arm/cpu.h > @@ -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; nit: as it is a kvm only thingy, could could rename it with kvm_ prefix and move this along with the other kvm_* elements > + > /* Current power state, access guarded by BQL */ > ARMPSCIState power_state; > > diff --git a/target/arm/kvm.c b/target/arm/kvm.c > index 0d57081e69..e91b1abfb8 100644 > --- a/target/arm/kvm.c > +++ b/target/arm/kvm.c > @@ -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" }, > + { -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->psci_version) > + return g_strdup(ver->str); > + } > + > + return g_strdup_printf("Unknown PSCI-version: %x", cpu->psci_version); > +} > + > +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) > @@ -1959,7 +2008,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)) { > + if (cpu->prop_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->psci_version = QEMU_PSCI_VERSION_0_2; > cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2; > } > @@ -1998,6 +2052,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 Besides it looks good to me. Reviewed-by: Eric Auger <eric.auger@redhat.com> Eric ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-11-20 13:12 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-12 18:13 [PATCH v3 0/2] arm: add kvm-psci-version vcpu property Sebastian Ott 2025-11-12 18:13 ` [PATCH v3 1/2] target/arm/kvm: add constants for new PSCI versions Sebastian Ott 2025-11-12 18:13 ` [PATCH v3 2/2] target/arm/kvm: add kvm-psci-version vcpu property Sebastian Ott 2025-11-12 21:07 ` Philippe Mathieu-Daudé 2025-11-13 12:05 ` Sebastian Ott 2025-11-20 10:10 ` Eric Auger 2025-11-20 10:43 ` Philippe Mathieu-Daudé 2025-11-20 13:11 ` Sebastian Ott 2025-11-20 10:11 ` Eric Auger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).