kvm-steal-time and sve properties are added for KVM even if the corresponding features are not available. Always add pmu property for "host" and "max". Note that we still don't add the property for other CPUs that lack PMU. This is because we do not know what a PMU version should be enabled when the user sets the property to true while it is defined as an error for the "host" or "max" CPU when the hardware accelerator is enabled and the host doesn't have a PMU. This fixes qtest-aarch64/arm-cpu-features on the hosts that supports KVM but doesn't support PMU emulation. Signed-off-by: Akihiko Odaki --- Changes in v7: - Reject pmu=on for "host" when PMU is unavailable. - Handle "max" too, since it maps to "host" with hwaccel. - Link to v6: https://lore.kernel.org/qemu-devel/20250531-pmu-v6-1-2bb6c828ade3@rsg.ci.i.u-tokyo.ac.jp Changes in v6: - Limited the scope of the change to the "host" CPU. - Link to v5: https://lore.kernel.org/r/20250104-pmu-v5-1-be9c8777c786@daynix.com Changes in v5: - Rebased. - Link to v4: https://lore.kernel.org/r/20240720-pmu-v4-0-2a2b28f6b08f@daynix.com Changes in v4: - Split patch "target/arm/kvm: Fix PMU feature bit early" into "target/arm/kvm: Set PMU for host only when available" and "target/arm/kvm: Do not silently remove PMU". - Changed to define PMU also for Armv7. - Changed not to define PMU for M. - Extracted patch "hvf: arm: Raise an exception for sysreg by default" from "hvf: arm: Properly disable PMU". - Rebased. - Link to v3: https://lore.kernel.org/r/20240716-pmu-v3-0-8c7c1858a227@daynix.com Changes in v3: - Dropped patch "target/arm: Do not allow setting 'pmu' for hvf". - Dropped patch "target/arm: Allow setting 'pmu' only for host and max". - Dropped patch "target/arm/kvm: Report PMU unavailability". - Added patch "target/arm/kvm: Fix PMU feature bit early". - Added patch "hvf: arm: Do not advance PC when raising an exception". - Added patch "hvf: arm: Properly disable PMU". - Changed to check for Armv8 before adding PMU property. - Link to v2: https://lore.kernel.org/r/20240716-pmu-v2-0-f3e3e4b2d3d5@daynix.com Changes in v2: - Restricted writes to 'pmu' to host and max. - Prohibited writes to 'pmu' for hvf. - Link to v1: https://lore.kernel.org/r/20240629-pmu-v1-0-7269123b88a4@daynix.com --- target/arm/cpu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 86aae36ae552..4a4bed525359 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1345,11 +1345,11 @@ static void arm_set_pmu(Object *obj, bool value, Error **errp) { ARMCPU *cpu = ARM_CPU(obj); - if (value) { - set_feature(&cpu->env, ARM_FEATURE_PMU); - } else { - unset_feature(&cpu->env, ARM_FEATURE_PMU); + if (value && !arm_feature(&cpu->env, ARM_FEATURE_PMU)) { + error_setg(errp, "'pmu' feature is not supported"); + return; } + cpu->has_pmu = value; } @@ -1529,6 +1529,7 @@ static void arm_cpu_propagate_feature_implications(ARMCPU *cpu) static void arm_cpu_post_init(Object *obj) { ARMCPU *cpu = ARM_CPU(obj); + ARMCPUClass *acc = ARM_CPU_GET_CLASS(obj); /* * Some features imply others. Figure this out now, because we @@ -1585,6 +1586,10 @@ static void arm_cpu_post_init(Object *obj) if (arm_feature(&cpu->env, ARM_FEATURE_PMU)) { cpu->has_pmu = true; + } + + if (cpu->has_pmu || !strcmp(acc->info->name, "host") || + !strcmp(acc->info->name, "max")) { object_property_add_bool(obj, "pmu", arm_get_pmu, arm_set_pmu); } --- base-commit: b83371668192a705b878e909c5ae9c1233cbd5fb change-id: 20240629-pmu-ad5f67e2c5d0 Best regards, -- Akihiko Odaki