On Thu, 24 Sept 2026 at 18:30, Colton Lewis <[email protected]> wrote:
>
> Add CPU properties to configure KVM ARM64 PMU counter partitioning:
> - 'pmu-partition' (bool): enables KVM_ARM_VCPU_PMU_V3_ENABLE_PARTITION
> - 'pmu-num-counters' (uint32): sets KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS
>
> When 'pmu-partition=on' and 'pmu-num-counters=N' are passed via -cpu,
> QEMU enables hardware PMU partitioning and reserves N general-purpose
> event counters for the guest prior to calling KVM_ARM_VCPU_PMU_V3_INIT.
>
> Note that this patch is an example to demonstrate the KVM ARM64 PMU
> Partitioning uAPI [1]. That is why it aborts immediately if setting the
> device attributes does not succeed.
>
> [1]
> https://lore.kernel.org/kvmarm/[email protected]/
>
> Signed-off-by: Colton Lewis <[email protected]>
FYI for next time around, QEMU patches that depend on not-yet-accepted
kernel ABI changes should be tagged RFC, please.
> ---
> target/arm/cpu.c | 20 ++++++++++++++++++++
> target/arm/cpu.h | 4 ++++
> target/arm/kvm.c | 32 ++++++++++++++++++++++++++++++++
New CPU properties should be documented in docs/system/arm/cpu-features.rst .
> 3 files changed, 56 insertions(+)
>
> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
> index f58a1db843..7538c6a24c 100644
> --- a/target/arm/cpu.c
> +++ b/target/arm/cpu.c
> @@ -1359,6 +1359,20 @@ static bool arm_get_pmu(Object *obj, Error **errp)
> return cpu->has_pmu;
> }
>
> +static bool arm_get_pmu_partition(Object *obj, Error **errp)
> +{
> + ARMCPU *cpu = ARM_CPU(obj);
> +
> + return cpu->kvm_pmu_partition;
> +}
> +
> +static void arm_set_pmu_partition(Object *obj, bool value, Error **errp)
> +{
> + ARMCPU *cpu = ARM_CPU(obj);
> +
> + cpu->kvm_pmu_partition = value;
> +}
If your getter/setter are only updating the struct field,
you can use a DEFINE_PROP_BOOL to avoid having to have them
(compare arm_cpu_has_el2_property etc.)
> +
> static void arm_set_pmu(Object *obj, bool value, Error **errp)
> {
> ARMCPU *cpu = ARM_CPU(obj);
> @@ -1604,6 +1618,12 @@ static void arm_cpu_post_init(Object *obj)
> if (arm_feature(&cpu->env, ARM_FEATURE_PMU)) {
> cpu->has_pmu = true;
> object_property_add_bool(obj, "pmu", arm_get_pmu, arm_set_pmu);
> + object_property_add_bool(obj, "pmu-partition",
> + arm_get_pmu_partition,
> + arm_set_pmu_partition);
> + object_property_add_uint32_ptr(obj, "pmu-num-counters",
> + &cpu->kvm_pmu_nr_counters,
> + OBJ_PROP_FLAG_READWRITE);
What should we do with these properties if we're not using KVM
(i.e. for TCG, hvf, etc) ?
thanks
-- PMM