Re: [PATCH v2] pmdomain: core: Wait for device link removals before dropping genpd->dev
From: Ulf Hansson
Date: Fri Nov 13 2026 - 13:29:23 EST
+ Loic
On Fri, Jul 31, 2026 at 3:10 PM Jan Sebastian Götte <linux@xxxxxxxx> wrote:
>
> genpd->dev is embedded in struct generic_pm_domain and its release
> function is empty, so providers free the containing genpd with a plain
> kfree() once of_genpd_remove_last() returns, ignoring its refcount.
>
> Since genpd->dev is registered on the genpd provider bus, fw_devlink
> creates device links to it, and those are torn down asynchronously.
> Nothing made genpd_remove() wait for those teardowns, so the provider
> could free the memory backing genpd->dev while the queued workers still
> used it.
>
> This is reachable at boot on qrb2210, where the firmware rejects PC mode
> and psci_cpuidle_domain_probe() removes all the CPU PM domains before
> returning -EPROBE_DEFER. The bug is asymptomatic on defconfig, but shows
> up when enabling KASAN or INIT_ON_FREE_DEFAULT_ON. In some builds, it
> causes the kernel to crash a few hundred ms into the boot.
>
> Call device_link_wait_removal() before dropping the final reference. All
> link removal work is queued from device_del(), via
> device_links_driver_cleanup() and device_links_purge(), which precedes
> genpd_free_data(), and flush_workqueue() waits for it to complete.
>
> Assisted-by: Claude:claude-5-opus
> Fixes: 18a3a510ecfd ("pmdomain: core: Add the genpd->dev to the genpd provider bus")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jan Sebastian Götte <linux@xxxxxxxx>
I decided to apply this patch as is, for fixes! Apologize for the delay!
Let's try to come back to this and see if there is a better long term
solution, along the lines of what Saravana suggested.
@Loic, if you have time, can you please have a go and see if $subject
patch solves the problem you are seeing as well [1]?
Kind regards
Uffe
[1]
https://lore.kernel.org/all/20261020-cpuidl-psci-fix-v1-1-d8ab9ac3b56d@xxxxxxxxxxxxxxxx/
> ---
> v2: remove this note from the commit text.
>
> Note: This patch was LLM-assisted. I reproduced the issue and tested
> this patch on hardware, and I did my best to verify it by hand. However,
> I'm far from an expert in pmdomain, so YMMV.
>
> drivers/pmdomain/core.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
> index 842c4169e290..4eeb980e5a40 100644
> --- a/drivers/pmdomain/core.c
> +++ b/drivers/pmdomain/core.c
> @@ -2348,6 +2348,9 @@ static int genpd_alloc_data(struct generic_pm_domain *genpd)
>
> static void genpd_free_data(struct generic_pm_domain *genpd)
> {
> + /* Pending device link removals still reference genpd->dev. */
> + device_link_wait_removal();
> +
> put_device(&genpd->dev);
> if (genpd->device_id != -ENXIO)
> ida_free(&genpd_ida, genpd->device_id);
> --
> 2.53.0
>