mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pmdomain: core: connect consumer with supplier via device link
@ 2026-11-12  7:45 Yixun Lan
  2026-11-14 11:33 ` Ulf Hansson
  2026-12-01 19:33 ` Stefan Dösinger
  0 siblings, 2 replies; 6+ messages in thread
From: Yixun Lan @ 2026-11-12  7:45 UTC (permalink / raw)
  To: Ulf Hansson, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Troy Mitchell
  Cc: Icenowy Zheng, linux-pm, linux-kernel, linux-riscv, spacemit, Yixun Lan

Connect downstream Power Domain consumer with the supplier through
the device link API, So when the pmdomain driver is unloaded or unbinded,
the consumer can be automatically notified and purged gracefully.

Signed-off-by: Yixun Lan <dlan@kernel.org>
---
The power domain drivers under pmdomain subystem suffer fom
the problem that unable to notify the downstream consumer with
module unload or unlink event, left with stale sysfs interface.
 Curently, the solution is a) use builtin_platform_driver() API
to disable the module unloading b) adding suppress_bind_attrs flag
to disable the unlink interface, which prevent it from being 
triggered from user space.

Take spacemit K3 platform [1] for example, without this patch,
Removing spacemit_pm_domains module will trigger a failure to
remove power domain, access pm_genpd_summary will result an
kernel oops, See detail log below

domain                          status          children        performance
    /device                         runtime status                  managed by
------------------------------------------------------------------------------
lcd1                            on                              0
    cac88000.dp                     unsupported                 0           SW
lcd0                            off-0                           0
audio                           on                              0
gpu                             on                              0
    cac00000.gpu                    active                      0           SW
vpu                             off-0                           0

gpu  lcd1  pm_genpd_summary

(gpu and lcd1 isn't clean up)

[  181.353671] spacemit_pm_domains spacemit_ccu.k3-apmu-pmdomain.3: failed to remove domain gpu: -16 - state may be inconsistent
[  181.353889] PM: genpd_remove: unable to remove lcd1
[  181.353896] spacemit_pm_domains spacemit_ccu.k3-apmu-pmdomain.3: failed to remove domain lcd1: -16 - state may be inconsistent

[  206.228045] CPU: 5 UID: 0 PID: 2560 Comm: cat Not tainted 7.3.0-rc12 #81 PREEMPTLAZY
[  206.238002] Hardware name: SpacemiT K3 Pico-ITX (DT)
[  206.243027] epc : summary_show+0xaa/0x308
[  206.247081]  ra : summary_show+0x264/0x308
[  206.251224] epc : ffffffff809f50fa ra : ffffffff809f52b4 sp : ffffffc601273a80
[  206.258542]  gp : ffffffff82333b98 tp : ffffffd601d5ec80 t0 : ffffffff80026b38
[  206.265859]  t1 : ffffffd6092d3cb0 t2 : ffffffff81601810 s0 : ffffffc601273b10
[  206.273177]  s1 : ffffffd601b92470 a0 : ffffffd601b92588 a1 : 000000000000000a
[  206.280494]  a2 : ffffffd609ae8000 a3 : 0000000000000000 a4 : ffffffd601d5ec80
[  206.287811]  a5 : 0000000000000000 a6 : ffffffffffffe000 a7 : 0000000000000000
[  206.295128]  s2 : ffffffd6092d3cb0 s3 : ffffffd601b92470 s4 : ffffffd601b94040
[  206.302447]  s5 : 0000000000000000 s6 : 0000000000000003 s7 : ffffffff8221e3a8
[  206.309764]  s8 : 0000000000000001 s9 : ffffffff8172b8c8 s10: 0000000000000004
[  206.317082]  s11: 0000000000000000 t3 : 000000000000017a t4 : 0000000000000002
[  206.324399]  t5 : 0000000000000000 t6 : ffffffd609ae7178 ssp : 0000000000000000
[  206.331804] status: 0000000200000120 badaddr: 0000000000000010 cause: 000000000000000d
[  206.339829] [<ffffffff809f50fa>] summary_show+0xaa/0x308
[  206.345206] [<ffffffff804b67f8>] seq_read_iter+0xe0/0x390
[  206.350671] [<ffffffff804b6b86>] seq_read+0xde/0x158
[  206.355697] [<ffffffff8063dee4>] full_proxy_read+0x54/0x88
[  206.361250] [<ffffffff8047a03e>] vfs_read+0xae/0x380
[  206.366275] [<ffffffff8047adc2>] ksys_read+0x6a/0xf0
[  206.371301] [<ffffffff8047ae68>] __riscv_sys_read+0x20/0x30
[  206.376944] [<ffffffff8101fa6a>] do_trap_ecall_u+0x19a/0x518
[  206.382674] [<ffffffff81033acc>] handle_exception+0x16c/0x178
[  206.388503] Code: 0a13 c00a 4c05 4b0d 3783 540a 3823 f804 3423 f804 (6b9c) 8552
[  206.396050] ---[ end trace 0000000000000000 ]---
Segmentation fault         cat /sys/kernel/debug/pm_genpd/pm_genpd_summary

====================================================================================

With this patch applied, either unload the module or trigger an
unbind operation, the downstream gpu, lcd1 will exit gracefully

or

domain                          status          children        performance
    /device                         runtime status                  managed by
------------------------------------------------------------------------------

Link: https://patch.msgid.link/20261108-04-k3-pm-support-v3-0-b9dc0857039b@kernel.org [1]
---
 drivers/pmdomain/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 964e44c2f78f..870fc8083bca 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -3543,6 +3543,8 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
 		return -EPROBE_DEFER;
 	}
 
+	device_link_add(dev, &pd->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
+
 	return 1;
 
 err:

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261112-01-pm-device-link-9fdd0fe59a49

Best regards,
--  
Yixun Lan <dlan@kernel.org>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pmdomain: core: connect consumer with supplier via device link
  2026-11-12  7:45 [PATCH] pmdomain: core: connect consumer with supplier via device link Yixun Lan
@ 2026-11-14 11:33 ` Ulf Hansson
  2026-11-16  7:24   ` Yixun Lan
  2026-12-01 19:33 ` Stefan Dösinger
  1 sibling, 1 reply; 6+ messages in thread
From: Ulf Hansson @ 2026-11-14 11:33 UTC (permalink / raw)
  To: Yixun Lan
  Cc: Ulf Hansson, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Troy Mitchell, Icenowy Zheng, linux-pm,
	linux-kernel, linux-riscv, spacemit

On Thu, Nov 12, 2026 at 8:45 AM Yixun Lan <dlan@kernel.org> wrote:
>
> Connect downstream Power Domain consumer with the supplier through
> the device link API, So when the pmdomain driver is unloaded or unbinded,
> the consumer can be automatically notified and purged gracefully.
>
> Signed-off-by: Yixun Lan <dlan@kernel.org>

Can you check if the below commit that sits on my fixes branch solves
this problem for you?

e279833a5362 pmdomain: core: Wait for device link removals before
dropping genpd->dev

Kind regards
Uffe

> ---
> The power domain drivers under pmdomain subystem suffer fom
> the problem that unable to notify the downstream consumer with
> module unload or unlink event, left with stale sysfs interface.
>  Curently, the solution is a) use builtin_platform_driver() API
> to disable the module unloading b) adding suppress_bind_attrs flag
> to disable the unlink interface, which prevent it from being
> triggered from user space.
>
> Take spacemit K3 platform [1] for example, without this patch,
> Removing spacemit_pm_domains module will trigger a failure to
> remove power domain, access pm_genpd_summary will result an
> kernel oops, See detail log below
>
> domain                          status          children        performance
>     /device                         runtime status                  managed by
> ------------------------------------------------------------------------------
> lcd1                            on                              0
>     cac88000.dp                     unsupported                 0           SW
> lcd0                            off-0                           0
> audio                           on                              0
> gpu                             on                              0
>     cac00000.gpu                    active                      0           SW
> vpu                             off-0                           0
>
> gpu  lcd1  pm_genpd_summary
>
> (gpu and lcd1 isn't clean up)
>
> [  181.353671] spacemit_pm_domains spacemit_ccu.k3-apmu-pmdomain.3: failed to remove domain gpu: -16 - state may be inconsistent
> [  181.353889] PM: genpd_remove: unable to remove lcd1
> [  181.353896] spacemit_pm_domains spacemit_ccu.k3-apmu-pmdomain.3: failed to remove domain lcd1: -16 - state may be inconsistent
>
> [  206.228045] CPU: 5 UID: 0 PID: 2560 Comm: cat Not tainted 7.3.0-rc12 #81 PREEMPTLAZY
> [  206.238002] Hardware name: SpacemiT K3 Pico-ITX (DT)
> [  206.243027] epc : summary_show+0xaa/0x308
> [  206.247081]  ra : summary_show+0x264/0x308
> [  206.251224] epc : ffffffff809f50fa ra : ffffffff809f52b4 sp : ffffffc601273a80
> [  206.258542]  gp : ffffffff82333b98 tp : ffffffd601d5ec80 t0 : ffffffff80026b38
> [  206.265859]  t1 : ffffffd6092d3cb0 t2 : ffffffff81601810 s0 : ffffffc601273b10
> [  206.273177]  s1 : ffffffd601b92470 a0 : ffffffd601b92588 a1 : 000000000000000a
> [  206.280494]  a2 : ffffffd609ae8000 a3 : 0000000000000000 a4 : ffffffd601d5ec80
> [  206.287811]  a5 : 0000000000000000 a6 : ffffffffffffe000 a7 : 0000000000000000
> [  206.295128]  s2 : ffffffd6092d3cb0 s3 : ffffffd601b92470 s4 : ffffffd601b94040
> [  206.302447]  s5 : 0000000000000000 s6 : 0000000000000003 s7 : ffffffff8221e3a8
> [  206.309764]  s8 : 0000000000000001 s9 : ffffffff8172b8c8 s10: 0000000000000004
> [  206.317082]  s11: 0000000000000000 t3 : 000000000000017a t4 : 0000000000000002
> [  206.324399]  t5 : 0000000000000000 t6 : ffffffd609ae7178 ssp : 0000000000000000
> [  206.331804] status: 0000000200000120 badaddr: 0000000000000010 cause: 000000000000000d
> [  206.339829] [<ffffffff809f50fa>] summary_show+0xaa/0x308
> [  206.345206] [<ffffffff804b67f8>] seq_read_iter+0xe0/0x390
> [  206.350671] [<ffffffff804b6b86>] seq_read+0xde/0x158
> [  206.355697] [<ffffffff8063dee4>] full_proxy_read+0x54/0x88
> [  206.361250] [<ffffffff8047a03e>] vfs_read+0xae/0x380
> [  206.366275] [<ffffffff8047adc2>] ksys_read+0x6a/0xf0
> [  206.371301] [<ffffffff8047ae68>] __riscv_sys_read+0x20/0x30
> [  206.376944] [<ffffffff8101fa6a>] do_trap_ecall_u+0x19a/0x518
> [  206.382674] [<ffffffff81033acc>] handle_exception+0x16c/0x178
> [  206.388503] Code: 0a13 c00a 4c05 4b0d 3783 540a 3823 f804 3423 f804 (6b9c) 8552
> [  206.396050] ---[ end trace 0000000000000000 ]---
> Segmentation fault         cat /sys/kernel/debug/pm_genpd/pm_genpd_summary
>
> ====================================================================================
>
> With this patch applied, either unload the module or trigger an
> unbind operation, the downstream gpu, lcd1 will exit gracefully
>
> or
>
> domain                          status          children        performance
>     /device                         runtime status                  managed by
> ------------------------------------------------------------------------------
>
> Link: https://patch.msgid.link/20261108-04-k3-pm-support-v3-0-b9dc0857039b@kernel.org [1]
> ---
>  drivers/pmdomain/core.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
> index 964e44c2f78f..870fc8083bca 100644
> --- a/drivers/pmdomain/core.c
> +++ b/drivers/pmdomain/core.c
> @@ -3543,6 +3543,8 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
>                 return -EPROBE_DEFER;
>         }
>
> +       device_link_add(dev, &pd->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
> +
>         return 1;
>
>  err:
>
> ---
> base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
> change-id: 20261112-01-pm-device-link-9fdd0fe59a49
>
> Best regards,
> --
> Yixun Lan <dlan@kernel.org>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pmdomain: core: connect consumer with supplier via device link
  2026-11-14 11:33 ` Ulf Hansson
@ 2026-11-16  7:24   ` Yixun Lan
  2026-11-16  7:46     ` Icenowy Zheng
  0 siblings, 1 reply; 6+ messages in thread
From: Yixun Lan @ 2026-11-16  7:24 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Ulf Hansson, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Troy Mitchell, Icenowy Zheng, linux-pm,
	linux-kernel, linux-riscv, spacemit

Hi Ulf,

On 12:33 Sat 14 Nov     , Ulf Hansson wrote:
> On Thu, Nov 12, 2026 at 8:45 AM Yixun Lan <dlan@kernel.org> wrote:
> >
> > Connect downstream Power Domain consumer with the supplier through
> > the device link API, So when the pmdomain driver is unloaded or unbinded,
> > the consumer can be automatically notified and purged gracefully.
> >
> > Signed-off-by: Yixun Lan <dlan@kernel.org>
> 
> Can you check if the below commit that sits on my fixes branch solves
> this problem for you?
> 
No, I've cherry-picked below commit and it does not solve my issue,
 it's a different problem.

Problem here is the pm consumer side isn't aware pm driver is removed. 

> e279833a5362 pmdomain: core: Wait for device link removals before
> dropping genpd->dev
> 
> Kind regards
> Uffe
> 

-- 
Yixun Lan (dlan)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pmdomain: core: connect consumer with supplier via device link
  2026-11-16  7:24   ` Yixun Lan
@ 2026-11-16  7:46     ` Icenowy Zheng
  2026-11-25 10:34       ` Ulf Hansson
  0 siblings, 1 reply; 6+ messages in thread
From: Icenowy Zheng @ 2026-11-16  7:46 UTC (permalink / raw)
  To: Yixun Lan, Ulf Hansson
  Cc: Ulf Hansson, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Troy Mitchell, linux-pm, linux-kernel,
	linux-riscv, spacemit

在 2026-11-16一的 07:24 +0000,Yixun Lan写道:
> Hi Ulf,
> 
> On 12:33 Sat 14 Nov     , Ulf Hansson wrote:
> > On Thu, Nov 12, 2026 at 8:45 AM Yixun Lan <dlan@kernel.org> wrote:
> > > 
> > > Connect downstream Power Domain consumer with the supplier
> > > through
> > > the device link API, So when the pmdomain driver is unloaded or
> > > unbinded,
> > > the consumer can be automatically notified and purged gracefully.
> > > 
> > > Signed-off-by: Yixun Lan <dlan@kernel.org>
> > 
> > Can you check if the below commit that sits on my fixes branch
> > solves
> > this problem for you?
> > 
> No, I've cherry-picked below commit and it does not solve my issue,
>  it's a different problem.
> 
> Problem here is the pm consumer side isn't aware pm driver is
> removed. 
> 

I do think it's just better to prevent PM drivers from being removed.

Thanks,
Icenowy

> 
> > e279833a5362 pmdomain: core: Wait for device link removals before
> > dropping genpd->dev
> > 
> > Kind regards
> > Uffe
> > 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pmdomain: core: connect consumer with supplier via device link
  2026-11-16  7:46     ` Icenowy Zheng
@ 2026-11-25 10:34       ` Ulf Hansson
  0 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2026-11-25 10:34 UTC (permalink / raw)
  To: Icenowy Zheng, Yixun Lan
  Cc: Ulf Hansson, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Troy Mitchell, linux-pm, linux-kernel,
	linux-riscv, spacemit

On Mon, Nov 16, 2026 at 8:47 AM Icenowy Zheng <uwu@icenowy.me> wrote:
>
> 在 2026-11-16一的 07:24 +0000,Yixun Lan写道:
> > Hi Ulf,
> >
> > On 12:33 Sat 14 Nov     , Ulf Hansson wrote:
> > > On Thu, Nov 12, 2026 at 8:45 AM Yixun Lan <dlan@kernel.org> wrote:
> > > >
> > > > Connect downstream Power Domain consumer with the supplier
> > > > through
> > > > the device link API, So when the pmdomain driver is unloaded or
> > > > unbinded,
> > > > the consumer can be automatically notified and purged gracefully.
> > > >
> > > > Signed-off-by: Yixun Lan <dlan@kernel.org>
> > >
> > > Can you check if the below commit that sits on my fixes branch
> > > solves
> > > this problem for you?
> > >
> > No, I've cherry-picked below commit and it does not solve my issue,
> >  it's a different problem.
> >
> > Problem here is the pm consumer side isn't aware pm driver is
> > removed.
> >
>
> I do think it's just better to prevent PM drivers from being removed.
>
> Thanks,
> Icenowy
>

I tend to agree.

Unless we have a real use case where we really need to unbind a power
domain provider driver. Is that the case?

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pmdomain: core: connect consumer with supplier via device link
  2026-11-12  7:45 [PATCH] pmdomain: core: connect consumer with supplier via device link Yixun Lan
  2026-11-14 11:33 ` Ulf Hansson
@ 2026-12-01 19:33 ` Stefan Dösinger
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Dösinger @ 2026-12-01 19:33 UTC (permalink / raw)
  To: Ulf Hansson, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Troy Mitchell, spacemit
  Cc: Icenowy Zheng, linux-pm, linux-kernel, linux-riscv, spacemit, Yixun Lan

[-- Attachment #1: Type: text/plain, Size: 2036 bytes --]

Hi,

Am Donnerstag, 12. November 2026, 10:45:43 Ostafrikanische Zeit schrieb Yixun 
Lan:
> Connect downstream Power Domain consumer with the supplier through
> the device link API, So when the pmdomain driver is unloaded or unbinded,
> the consumer can be automatically notified and purged gracefully.

I ran into the same issue with the zx297520v3 pmdomain driver I submitted [0].

The issue happens when the pm domain device is an MFD child registered with 
mfd_add_devices() and the #power-domain-cells rolled into the MFD parent's DTS 
node. In this case from the DTS's point of view the provider is the MFD 
parent, whereas the runtime provider is the MFD child.

Linking the consumer to the MFD child that actually provides the pmdomain 
makes sure that the consumer gets unbound when the MFD child gets unbound.

Why not make the pmdomain child a DTS node? writing-bindings.rst explicitly 
discourages it:

> - DON'T create nodes just for the sake of instantiating drivers. Multi-
> function devices only need child nodes when the child nodes have their own
> DT resources. A single node can be multiple providers (e.g. clocks and
> resets).

In my case Krzysztof Kozlowski reiterated that in [1].

The clk subsystem takes extra care to handle provider registration from a MFD 
child - see dev_or_parent_of_node().

I don't deeply care about being able to unbind my pmdomain driver and/or build 
it as module and unload it. I implemented it because Brian Masney asked me to 
build the clk drivers this way[2]. On my hardware the pmdomain is easy to shut 
down without crashing/powering off the board, so I might as well. And to me 
being able to unwind a device registration is a good check that the device 
registration itself is built the right way.

Cheers,
Stefan

0: https://lore.kernel.org/linux-arm-kernel/20261120-zx29usb-v1-3-b0433258e51b@gmail.com/
1: https://lore.kernel.org/linux-arm-kernel/20260717-uncovered-feathered-groundhog-eab16e@quoll/
2: https://lore.kernel.org/linux-arm-kernel/anPD-I9GDyOZSDO7@redhat.com/

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 870 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-02  8:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12  7:45 [PATCH] pmdomain: core: connect consumer with supplier via device link Yixun Lan
2026-11-14 11:33 ` Ulf Hansson
2026-11-16  7:24   ` Yixun Lan
2026-11-16  7:46     ` Icenowy Zheng
2026-11-25 10:34       ` Ulf Hansson
2026-12-01 19:33 ` Stefan Dösinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®