Re: [Patch v8 01/23] perf/x86/intel: Validate return value of intel_pmu_init_hybrid()

From: Peter Zijlstra

Date: Fri May 29 2026 - 07:16:07 EST


On Fri, May 29, 2026 at 03:56:23PM +0800, Dapeng Mi wrote:
> The memory allocation for the x86_pmu.hybrid_pmu[] array in
> intel_pmu_init_hybrid() can theoretically fail due to memory shortages.
> If this occurs, the initialization of the x86 hybrid PMU would fail.
>
> Currently, the code does not check the return value of the
> intel_pmu_init_hybrid() function, which could lead to attempts to access
> the uninitialized x86_pmu.hybrid_pmu[] array, potentially causing a
> system panic.
>
> So, adds a check for the return value of intel_pmu_init_hybrid() to
> prevent invalid memory access in such scenarios.
>
> Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
> ---
>
> V8: New patch.
>
> arch/x86/events/intel/core.c | 29 ++++++++++++++++++++++-------
> 1 file changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 0217e701aeeb..85c329bd52be 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -7870,6 +7870,7 @@ __init int intel_pmu_init(void)
> int version, i;
> char *name;
> struct x86_hybrid_pmu *pmu;
> + int ret;
>
> /* Architectural Perfmon was introduced starting with Core "Yonah" */
> if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
> @@ -8545,7 +8546,9 @@ __init int intel_pmu_init(void)
> *
> * Initialize the common PerfMon capabilities here.
> */
> - intel_pmu_init_hybrid(hybrid_big_small);
> + ret = intel_pmu_init_hybrid(hybrid_big_small);
> + if (ret < 0)
> + return ret;

Sashiko notes this will leak the intel_pmu_arch_lbt_init() kmemcache.

I'm not entirely sure we care much about that, but its not really nice.