Re: [PATCH v10 04/18] perf/x86: Expose perf_capabilities to KVM
From: Mi, Dapeng
Date: Tue Dec 01 2026 - 01:03:29 EST
Reviewed-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
On 11/25/2026 5:38 AM, Zide Chen wrote:
> perf already applies model-specific errata (e.g. RPL018 on RPL/MTL)
> and sanitizes contradictory values (e.g. clearing pebs_baseline when
> the PEBS format is < 4). Reading the MSR directly in KVM bypasses all
> of that.
>
> Add perf_capabilities to struct x86_pmu_capability, next to the
> counter counts, bit widths and event masks it already exports, so
> that KVM can use the validated value.
>
> Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> ---
> v10: New patch.
> ---
> arch/x86/events/core.c | 1 +
> arch/x86/include/asm/perf_event.h | 1 +
> 2 files changed, 2 insertions(+)
>
> diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
> index 8b3ea0adb965..770ca960fa6e 100644
> --- a/arch/x86/events/core.c
> +++ b/arch/x86/events/core.c
> @@ -3164,6 +3164,7 @@ void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap)
> cap->events_mask_len = x86_pmu.events_mask_len;
> cap->pebs_ept = x86_pmu.pebs_ept;
> cap->mediated = !!(pmu.capabilities & PERF_PMU_CAP_MEDIATED_VPMU);
> + cap->perf_capabilities = x86_pmu.intel_cap.capabilities;
> }
> EXPORT_SYMBOL_FOR_KVM(perf_get_x86_pmu_capability);
>
> diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
> index ca630bc282fb..a68cb7c79d8b 100644
> --- a/arch/x86/include/asm/perf_event.h
> +++ b/arch/x86/include/asm/perf_event.h
> @@ -308,6 +308,7 @@ struct x86_pmu_capability {
> int events_mask_len;
> unsigned int pebs_ept :1;
> unsigned int mediated :1;
> + u64 perf_capabilities;
> };
>
> /*