Re: [PATCH] powercap: intel_rapl: Fix kernel panic during PMU unbind

"Sumeet R.P." <[email protected]>
Newsgroups org.kernel.vger.linux-pm,org.kernel.vger.linux-kernel
Message-ID <CAJ9orWRp=zKJBHm1sS_ZiXuA8nhi-Cddi+s2JxWcfmsRdC7SwA@mail.gmail.com>
On Sun, Jul 26, 2026 at 9:33 AM Sumeet Pawnikar <[email protected]> wrote:
>
> rapl_package_add_pmu() fails internally at perf_pmu_register(),
> and rapl_pmu_update() leaves the global rapl_pmu.pmu structure
> zero-initialized via memset and returns an error. But any
> previously probed packages retain has_pmu = true.
>
> When the driver is subsequently unbound or removed,
> rapl_package_remove_pmu_locked() sees has_pmu == true and
> unconditionally calls perf_pmu_unregister(&rapl_pmu.pmu) on the
> zeroed-out structure. This attempts a list_del_rcu() on a NULL
> list head, immediately causing a kernel panic.
>
> Fix this by checking if the PMU is actually registered before
> attempting to unregister it.
>
> Signed-off-by: Sumeet Pawnikar <[email protected]>

Hi Rafael,

Gentle ping.
Any chance for this to go into next rc ?

Thanks & Regards,
Sumeet Pawnikar.

> ---
>  drivers/powercap/intel_rapl_common.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
> index 1006d183d508..22100f1ca222 100644
> --- a/drivers/powercap/intel_rapl_common.c
> +++ b/drivers/powercap/intel_rapl_common.c
> @@ -1652,7 +1652,8 @@ void rapl_package_remove_pmu_locked(struct rapl_package *rp)
>                         return;
>         }
>
> -       perf_pmu_unregister(&rapl_pmu.pmu);
> +       if (rapl_pmu.registered)
> +               perf_pmu_unregister(&rapl_pmu.pmu);
>         memset(&rapl_pmu, 0, sizeof(struct rapl_pmu));
>  }
>  EXPORT_SYMBOL_NS_GPL(rapl_package_remove_pmu_locked, "INTEL_RAPL");
> --
> 2.43.0
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.