Re: [PATCHv3 4/4] powerpc/kvm-hv-pmu: Free hostwide stats buffers if perf_pmu_register() fails

From: Mukesh Kumar Chaurasiya

Date: Wed Nov 25 2026 - 00:58:42 EST


On Mon, Nov 23, 2026 at 07:21:53PM +0530, Ritesh Harjani (IBM) wrote:
> kvmppc_register_pmu() calls kvmppc_init_hostwide(), which allocates
> gsm_l0_stats and gsb_l0_stats. It then registers the pmu. If
> perf_pmu_register() fails we return without freeing them.
>
> Call kvmppc_cleanup_hostwide() on that error path.
>
> Fixes: f0c9c49c5067 ("powerpc/kvm-hv-pmu: Implement GSB message-ops for hostwide counters")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>
> ---
> arch/powerpc/perf/kvm-hv-pmu.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/perf/kvm-hv-pmu.c b/arch/powerpc/perf/kvm-hv-pmu.c
> index a58634f656e9..ec05b4855736 100644
> --- a/arch/powerpc/perf/kvm-hv-pmu.c
> +++ b/arch/powerpc/perf/kvm-hv-pmu.c
> @@ -402,8 +402,10 @@ static int __init kvmppc_register_pmu(void)
>
> /* Register the pmu */
> rc = perf_pmu_register(&kvmppc_pmu, kvmppc_pmu.name, -1);
> - if (rc)
> + if (rc) {
> + kvmppc_cleanup_hostwide();
Just a question.
Inside this function, should we also take lock just to set the pointers
NULL rather than putting the whole logic(free also) inside the lock like
we did in previous patch?

Apart from this, all looks good.

Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@xxxxxxxxx>
> goto out;
> + }
>
> pr_info("Registered kvm-hv pmu");
> }
> --
> 2.39.5
>