[PATCH] pmdomain: core: connect consumer with supplier via device link

Yixun Lan dlan at kernel.org
Wed Nov 11 23:45:43 PST 2026


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 at 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 at kernel.org>




More information about the linux-riscv mailing list