* [PATCH RESEND] powercap: intel_rapl: Fix kernel panic during PMU unbind
@ 2026-08-22 9:46 Sumeet Pawnikar
2026-08-24 7:35 ` Abel Vesa
0 siblings, 1 reply; 3+ messages in thread
From: Sumeet Pawnikar @ 2026-08-22 9:46 UTC (permalink / raw)
To: rafael, linux-pm; +Cc: linux-kernel, sumeet4linux
From: Sumeet Pawnikar <sumeet4linux@gmail.com>
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 <sumeet4linux@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] powercap: intel_rapl: Fix kernel panic during PMU unbind
2026-08-22 9:46 [PATCH RESEND] powercap: intel_rapl: Fix kernel panic during PMU unbind Sumeet Pawnikar
@ 2026-08-24 7:35 ` Abel Vesa
2026-08-24 10:32 ` Rafael J. Wysocki (Intel)
0 siblings, 1 reply; 3+ messages in thread
From: Abel Vesa @ 2026-08-24 7:35 UTC (permalink / raw)
To: Sumeet Pawnikar; +Cc: rafael, linux-pm, linux-kernel
On 26-08-22 15:16:57, Sumeet Pawnikar wrote:
> From: Sumeet Pawnikar <sumeet4linux@gmail.com>
>
> 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 <sumeet4linux@gmail.com>
Looks OK to me, so:
Reviewed-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RESEND] powercap: intel_rapl: Fix kernel panic during PMU unbind
2026-08-24 7:35 ` Abel Vesa
@ 2026-08-24 10:32 ` Rafael J. Wysocki (Intel)
0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-08-24 10:32 UTC (permalink / raw)
To: Abel Vesa, Sumeet Pawnikar; +Cc: linux-pm, linux-kernel
On Mon, Aug 24, 2026 at 9:35 AM Abel Vesa <abel.vesa@oss.qualcomm.com> wrote:
>
> On 26-08-22 15:16:57, Sumeet Pawnikar wrote:
> > From: Sumeet Pawnikar <sumeet4linux@gmail.com>
> >
> > 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 <sumeet4linux@gmail.com>
>
> Looks OK to me, so:
>
> Reviewed-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
Applied as 7.3-rc material, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-24 10:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-22 9:46 [PATCH RESEND] powercap: intel_rapl: Fix kernel panic during PMU unbind Sumeet Pawnikar
2026-08-24 7:35 ` Abel Vesa
2026-08-24 10:32 ` Rafael J. Wysocki (Intel)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox