accel/rocket: request the core clocks by name
Subsystems (3)
PATCH v2 1/1 accel/rocket: request the core clocks by name
rocket_core_init() hands core->clks to devm_clk_bulk_get() without ever setting the .id members. The rocket_core array is allocated with devm_kcalloc() in rocket_device_init(), and rocket_probe() only fills in .rdev, .dev and .index, so all four clk_bulk_data entries are requested with a NULL con_id (unlike core->resets, whose ids are set a few lines above).
clk_get(dev, NULL) ends up in of_clk_get_hw(np, 0, NULL), and of_parse_clkspec() only consults "clock-names" when a name was passed, so the index stays 0 for all four entries. Every entry therefore ends up holding a handle to the *first* clock of the DT "clocks" property, i.e. ACLK_NPUn. Nothing fails: probe succeeds and the driver believes it owns four different clocks.
The consequence is that rocket_device_runtime_resume() prepares and enables the AXI clock four times, while hclk, pclk and - most importantly - the NPU compute clock ("npu", SCMI_CLK_NPU on RK3588) are never prepared or enabled by this driver at all. The NPU still works only because the Rockchip power-domain driver sets GENPD_FLAG_PM_CLK and its attach_dev() callback walks the device node with of_clk_get() and adds every clock to the pm_clk list, so genpd happens to keep the remaining clocks running. The bug is therefore latent today, but it means the driver holds no reference to the clock that actually feeds the NPU, which stands in the way of any future frequency scaling (OPP/devfreq) work.
Found on an Orange Pi 5 Plus (RK3588) by reading the live clock tree:/sys/kernel/debug/clk/clk_summary shows four "fdab0000.npu" consumer handles on aclk_npu0 (and likewise on aclk_npu1/aclk_npu2 for the other two cores), while hclk_npu0, pclk_npu_root and scmi_clk_npu have no "fdab0000.npu" consumer at all - their only consumers are the "npu@fdab0000" handles created by the power-domain driver via of_clk_get().
Set the ids explicitly, in the order mandated by the binding (Documentation/devicetree/bindings/npu/rockchip,rk3588-rknn-core.yaml):
aclk, hclk, npu, pclk. After the change the driver holds one handle per distinct clock and clk_bulk_prepare_enable() covers all four.
Note that this is a user-visible tightening for out-of-tree DTs: the old NULL-id requests resolved by index and succeeded no matter what "clock-names" contained, while the named requests fail probe with -ENOENT when one of the four names is missing. That is the right outcome for in-tree users - the binding requires exactly these four clock-names and rk3588-base.dtsi carries them on all three cores - but a DT that relied on the permissive lookup goes from silently running on the wrong clock handles to not probing at all, so record the change here where git log will find it.
---
v2:
- document that resolving by name is a behaviour change for DTs that
do not carry all four clock-names (Jiaxing Hu)
- collect Jiaxing's Reviewed-by
v1: https://lore.kernel.org/linux-rockchip/[email protected]/
The same four id assignments are board-tested on RK3576 (ROCK 4D) as part of Jiaxing's RK3576 enablement series (v2 6/8), so the change has been exercised on two SoCs between us.
Verified on RK3588 (Orange Pi 5 Plus): after the change clk_summary shows one consumer handle per clock instead of four handles on aclk, the NPU still powers up and down cleanly through runtime PM, and a MobileNetV1 inference run via the Teflon TFLite delegate produces bit-identical output tensors to the unpatched driver.
drivers/accel/rocket/rocket_core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/accel/rocket/rocket_core.c +4 -0
@@ -28,6 +28,10 @@ int rocket_core_init(struct rocket_core *core)if (err)return dev_err_probe (dev, err,"failed to get resets for core %d\n" , core->index); + core->clks[0 ].id ="aclk" ; + core->clks[1 ].id ="hclk" ; + core->clks[2 ].id ="npu" ; + core->clks[3 ].id ="pclk" ; err =devm_clk_bulk_get (dev,ARRAY_SIZE (core->clks), core->clks);if (err)return dev_err_probe (dev, err,"failed to get clocks for core %d\n" , core->index);
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [Critical] If rocket_device_init fails during the first core's probe, the global rdev pointer is left as an ERR_PTR rather than being reset to NULL, causing a kernel panic on subsequent probes.
- [High] The driver leaks the shared rdev and rdev->cores structures upon probe deferral or failure.
- [High] The driver incorrectly uses rdev->num_cores both as a count of active cores and as the boundary index, causing state corruption and resource leaks upon out-of-order unbind. --
--- Patch [1]: [PATCH v2] accel/rocket: request the core clocks by name --- commit 4687ac2abf99b6ec4120f9d98c0f4148fc2a6b97
Author: Igor Paunovic <[email protected]>
accel/rocket: request the core clocks by name
This commit fixes clock initialization by setting the proper names for the "aclk", "hclk", "npu", and "pclk" clocks before requesting them. Previously, all four clocks defaulted to index 0, which meant only the AXI clock was controlled by the driver.
Quoted 5 lines
drivers/accel/rocket/rocket_core.c +0
-0
drivers/accel/rocket/rocket_core.c int rocket_core_init(struct rocket_core *core) · line 37
Quoted 10 lines
drivers/accel/rocket/rocket_core.c +4
-0@@ -28,6 +28,10 @@ int rocket_core_init(struct rocket_core *core)if (err)return dev_err_probe (dev, err,"failed to get resets for core %d\n" , core->index); + core->clks[0 ].id ="aclk" ; + core->clks[1 ].id ="hclk" ; + core->clks[2 ].id ="npu" ; + core->clks[3 ].id ="pclk" ; err =devm_clk_bulk_get (dev,ARRAY_SIZE (core->clks), core->clks);if (err)return dev_err_probe (dev, err,"failed to get clocks for core %d\n" , core->index);
[Severity: High]
This isn't a bug introduced by this patch, but this devm_clk_bulk_get() call can defer probe. If rocket_core_init() fails here, I noticed a potential memory leak in the cleanup path.
In drivers/accel/rocket/rocket_device.c:rocket_device_init(), the rdev structure is allocated via devres attached to the static drm_dev device:
drivers/accel/rocket/rocket_device.c:rocket_device_init() {
...
rdev = devm_drm_dev_alloc(dev, rocket_drm_driver, struct rocket_device, ddev);
...
}
However, if probe fails, drivers/accel/rocket/rocket_drv.c:rocket_probe() abandons it without freeing the devres:
drivers/accel/rocket/rocket_drv.c:rocket_probe() {
...
if (rdev->num_cores == 0) {
rocket_device_fini(rdev);
rdev = NULL;
}...
}
Since drm_dev is never unbound while the module is loaded, does this leak the rdev and rdev->cores structures on every probe deferral?
[Severity: Critical]
This is a pre-existing issue, but looking at the error handling in drivers/accel/rocket/rocket_drv.c:rocket_probe():
drivers/accel/rocket/rocket_drv.c:rocket_probe() {
...
if (rdev == NULL) {
/* First core probing, initialize DRM device. */
rdev = rocket_device_init(drm_dev, &rocket_drm_driver);
if (IS_ERR(rdev)) {
dev_err(&pdev->dev, "failed to initialize rocket device\n");
return PTR_ERR(rdev);
}
}
unsigned int core = rdev->num_cores;...
}
If rocket_device_init() returns an error, rdev is left holding an ERR_PTR instead of being reset to NULL. Will a subsequent probe attempt try to dereference the poisoned rdev pointer when evaluating rdev->num_cores?
[Severity: High]
This is a pre-existing issue, but does the driver mishandle out-of-order unbinds?
In drivers/accel/rocket/rocket_drv.c:find_core_for_dev(), num_cores is used as a strict upper bound:
drivers/accel/rocket/rocket_drv.c:find_core_for_dev() {
...
for (unsigned int core = 0; core < rdev->num_cores; core++) {
if (dev == rdev->cores[core].dev)
return core;
}...
}
If an earlier core is unbound, num_cores is decremented. If a higher-indexed core is then unbound, find_core_for_dev() won't search far enough to find it.
Furthermore, if another core is then bound, rocket_probe() inserts it using num_cores as the index:
drivers/accel/rocket/rocket_drv.c:rocket_probe() {
...
rdev->cores[core].rdev = rdev; rdev->cores[core].dev = &pdev->dev;
...
}
Could this overwrite an active higher-indexed core that was never properly cleaned up?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 1 line · Igor Paunovic
Found on an Orange Pi 5 Plus (RK3588) by reading the live clock tree:
I see the same thing on a Radxa ROCK 5B+ (RK3588), and the patch fixes it here as well.
Before, clk_summary has the four rocket handles piled up on the AXI clock, with no driver consumer at all on the other three:
aclk_npu0 4x fdab0000.npu 1x npu@fdab0000 hclk_npu0 - 1x npu@fdab0000 pclk_npu_root - 3x npu@fdXX0000 scmi_clk_npu - 3x npu@fdXX0000
After the patch every clock has exactly one fdXX0000.npu consumer, and scmi_clk_npu picks up driver handles for all three cores.
No regressions here:
- 90 runtime PM suspend/resume cycles over the three cores: no power-domain ack failures, no SErrors, nothing logged at all. scmi_clk_npu stays at its boot rate and returns to enable_cnt 0 when the cores go idle.
- Five MobileNetV2 subgraphs through the Teflon TFLite delegate still match the CPU reference (max diff 1). I could not measure any change in inference time either way, though run-to-run spread on this box is around 10%, so that only rules out a large regression.
Tested on v7.2-rc3.
Thanks,
Sidong
Hi Igor,
Quoted 26 lines · Igor Paunovic
rocket_core_init()handscore->clkstodevm_clk_bulk_get()without ever setting the .id members. Therocket_corearray is allocated withdevm_kcalloc()inrocket_device_init(), androcket_probe()only fills in .rdev, .dev and .index, so all fourclk_bulk_dataentries are requested with a NULLcon_id(unlikecore->resets, whose ids are set a few lines above).
clk_get(dev, NULL)ends up inof_clk_get_hw(np, 0, NULL), andof_parse_clkspec()only consults "clock-names" when a name was passed, so the index stays 0 for all four entries. Every entry therefore ends up holding a handle to the *first* clock of the DT "clocks" property, i.e.ACLK_NPUn. Nothing fails: probe succeeds and the driver believes it owns four different clocks.The consequence is that
rocket_device_runtime_resume()prepares and enables the AXI clock four times, while hclk, pclk and - most importantly - the NPU compute clock ("npu",SCMI_CLK_NPUon RK3588) are never prepared or enabled by this driver at all. The NPU still works only because the Rockchip power-domain driver setsGENPD_FLAG_PM_CLKand itsattach_dev()callback walks the device node withof_clk_get()and adds every clock to thepm_clklist, so genpd happens to keep the remaining clocks running. The bug is therefore latent today, but it means the driver holds no reference to the clock that actually feeds the NPU, which stands in the way of any future frequency scaling (OPP/devfreq) work.
Quoted 7 lines
Found on an Orange Pi 5 Plus (RK3588) by reading the live clock tree:
/sys/kernel/debug/clk/clk_summaryshows four "fdab0000.npu" consumer handles onaclk_npu0(and likewise on aclk_npu1/aclk_npu2 for the other two cores), whilehclk_npu0,pclk_npu_rootandscmi_clk_npuhave no "fdab0000.npu" consumer at all - their only consumers are the "npu@fdab0000" handles created by the power-domain driver viaof_clk_get().
I have confirmed both the 'old' situation and the 'new' one on both my NanoPC-T6 LTS and NanoPC-T6 Plus (both RK3588), so feel free to add
Cheers,
Diederik
Quoted 59 lines
Set the ids explicitly, in the order mandated by the binding (
Documentation/devicetree/bindings/npu/rockchip,rk3588-rknn-core.yaml):
aclk, hclk, npu, pclk. After the change the driver holds one handle per distinct clock andclk_bulk_prepare_enable()covers all four.Note that this is a user-visible tightening for out-of-tree DTs: the old NULL-id requests resolved by index and succeeded no matter what "clock-names" contained, while the named requests fail probe with
-ENOENTwhen one of the four names is missing. That is the right outcome for in-tree users - the binding requires exactly these four clock-names andrk3588-base.dtsicarries them on all three cores - but a DT that relied on the permissive lookup goes from silently running on the wrong clock handles to not probing at all, so record the change here where git log will find it.Fixes ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")Signed-off-by Igor Paunovic <[email protected]>Reviewed-by Jiaxing Hu <[email protected]>---
v2:
- document that resolving by name is a behaviour change for DTs that
do not carry all four clock-names (Jiaxing Hu)
- collect Jiaxing's Reviewed-by
v1: https://lore.kernel.org/linux-rockchip/[email protected]/The same four id assignments are board-tested on RK3576 (ROCK 4D) as part of Jiaxing's RK3576 enablement series (v2 6/8), so the change has been exercised on two SoCs between us.
Verified on RK3588 (Orange Pi 5 Plus): after the change
clk_summaryshows one consumer handle per clock instead of four handles on aclk, the NPU still powers up and down cleanly through runtime PM, and a MobileNetV1 inference run via the Teflon TFLite delegate produces bit-identical output tensors to the unpatched driver.drivers/accel/rocket/rocket_core.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/accel/rocket/rocket_core.c +4
-0@@ -28,6 +28,10 @@ int rocket_core_init(struct rocket_core *core)if (err)return dev_err_probe (dev, err,"failed to get resets for core %d\n" , core->index); + core->clks[0 ].id ="aclk" ; + core->clks[1 ].id ="hclk" ; + core->clks[2 ].id ="npu" ; + core->clks[3 ].id ="pclk" ; err =devm_clk_bulk_get (dev,ARRAY_SIZE (core->clks), core->clks);if (err)return dev_err_probe (dev, err,"failed to get clocks for core %d\n" , core->index);_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Hi,
Quoted 49 lines · Igor Paunovic
rocket_core_init()handscore->clkstodevm_clk_bulk_get()without ever setting the .id members. Therocket_corearray is allocated withdevm_kcalloc()inrocket_device_init(), androcket_probe()only fills in .rdev, .dev and .index, so all fourclk_bulk_dataentries are requested with a NULLcon_id(unlikecore->resets, whose ids are set a few lines above).
clk_get(dev, NULL)ends up inof_clk_get_hw(np, 0, NULL), andof_parse_clkspec()only consults "clock-names" when a name was passed, so the index stays 0 for all four entries. Every entry therefore ends up holding a handle to the *first* clock of the DT "clocks" property, i.e.ACLK_NPUn. Nothing fails: probe succeeds and the driver believes it owns four different clocks.The consequence is that
rocket_device_runtime_resume()prepares and enables the AXI clock four times, while hclk, pclk and - most importantly - the NPU compute clock ("npu",SCMI_CLK_NPUon RK3588) are never prepared or enabled by this driver at all. The NPU still works only because the Rockchip power-domain driver setsGENPD_FLAG_PM_CLKand itsattach_dev()callback walks the device node withof_clk_get()and adds every clock to thepm_clklist, so genpd happens to keep the remaining clocks running. The bug is therefore latent today, but it means the driver holds no reference to the clock that actually feeds the NPU, which stands in the way of any future frequency scaling (OPP/devfreq) work.Found on an Orange Pi 5 Plus (RK3588) by reading the live clock tree:
/sys/kernel/debug/clk/clk_summaryshows four "fdab0000.npu" consumer handles onaclk_npu0(and likewise on aclk_npu1/aclk_npu2 for the other two cores), whilehclk_npu0,pclk_npu_rootandscmi_clk_npuhave no "fdab0000.npu" consumer at all - their only consumers are the "npu@fdab0000" handles created by the power-domain driver viaof_clk_get().Set the ids explicitly, in the order mandated by the binding (
Documentation/devicetree/bindings/npu/rockchip,rk3588-rknn-core.yaml):
aclk, hclk, npu, pclk. After the change the driver holds one handle per distinct clock andclk_bulk_prepare_enable()covers all four.Note that this is a user-visible tightening for out-of-tree DTs: the old NULL-id requests resolved by index and succeeded no matter what "clock-names" contained, while the named requests fail probe with
-ENOENTwhen one of the four names is missing. That is the right outcome for in-tree users - the binding requires exactly these four clock-names andrk3588-base.dtsicarries them on all three cores - but a DT that relied on the permissive lookup goes from silently running on the wrong clock handles to not probing at all, so record the change here where git log will find it.
Quoted 4 lines
Fixes ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")Signed-off-by Igor Paunovic <[email protected]>Reviewed-by Jiaxing Hu <[email protected]>---
-- Sebastian
Quoted 34 lines
v2:
- document that resolving by name is a behaviour change for DTs that
do not carry all four clock-names (Jiaxing Hu)
- collect Jiaxing's Reviewed-by
v1: https://lore.kernel.org/linux-rockchip/[email protected]/The same four id assignments are board-tested on RK3576 (ROCK 4D) as part of Jiaxing's RK3576 enablement series (v2 6/8), so the change has been exercised on two SoCs between us.
Verified on RK3588 (Orange Pi 5 Plus): after the change
clk_summaryshows one consumer handle per clock instead of four handles on aclk, the NPU still powers up and down cleanly through runtime PM, and a MobileNetV1 inference run via the Teflon TFLite delegate produces bit-identical output tensors to the unpatched driver.drivers/accel/rocket/rocket_core.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/accel/rocket/rocket_core.c +4
-0@@ -28,6 +28,10 @@ int rocket_core_init(struct rocket_core *core)if (err)return dev_err_probe (dev, err,"failed to get resets for core %d\n" , core->index); + core->clks[0 ].id ="aclk" ; + core->clks[1 ].id ="hclk" ; + core->clks[2 ].id ="npu" ; + core->clks[3 ].id ="pclk" ; err =devm_clk_bulk_get (dev,ARRAY_SIZE (core->clks), core->clks);if (err)return dev_err_probe (dev, err,"failed to get clocks for core %d\n" , core->index);
Igor Paunovic
Reviewed-by Jiaxing Hu Reviewed-by Sebastian Reichel Tested-by Sidong Yang Tested-by Diederik de Haas on v2 1/1Hi Tomeu,
A gentle ping on this one. It has been on the list since 29 July and has picked up review and test coverage in the meantime:
so it now carries two reviews and two independent test reports, covering the two NanoPC-T6 variants besides my own board.
The reason I am pinging rather than simply waiting: Jiaxing's RK3576 enablement series is based on this patch as of v6,
https://lore.kernel.org/linux-rockchip/[email protected]/
and he has a v7 in preparation. Up to v5 that series carried a duplicate of the same hunk, which would have conflicted whichever of the two landed first. Basing on this patch is the right fix, but it does mean his series is now waiting behind it.
Nothing has changed in the patch itself since v2 and there is no open comment on it, so it should apply as is. Happy to resend it with the tags collected if that is easier for you.
Thanks,
Igor
A correction to my own message above, before it stands uncorrected in the archive.
I wrote that the two test reports cover "the two NanoPC-T6 variants besides my own board". That is wrong, and it misattributes Sidong's work. Sidong tested on a Radxa ROCK 5B+, not on a NanoPC-T6:
https://lore.kernel.org/all/[email protected]/
Diederik's report is the one covering the two NanoPC-T6 variants. So the coverage is three boards besides mine, on three different designs:
Apologies to Sidong for getting his hardware wrong - his report was the more thorough of the two, with clk_summary before and after, 90 runtime PM cycles across the three cores, and bit-exact inference results, and it deserved to be quoted accurately.
Nothing else in that message changes.
Igor
Hi Igor,
Heads up before you see this patch arrive as 01/14 of my series.
Tomeu asked for it on the v10 cover:
"Sashiko is not reviewing this series because it doesn't not understand
yet prerequisite-patch-id. Can you please resubmit the series with Igor's (presumably) patches bundled in it?"
So v11 carries it as 01/14. Unchanged, under your name, your Signed-off-by first and mine underneath as the person passing it on, with the four tags it has collected.
Regards,
Jiaxing
Heiko Stübner
maintainerAm Montag, 31. August 2026, 10:03:56 Mitteleuropäische Normalzeit schrieb Jiaxing Hu:
Quoted 6 lines
Hi Igor,
Heads up before you see this patch arrive as 01/14 of my series.
Tomeu asked for it on the v10 cover:
Quoted 7 lines
"Sashiko is not reviewing this series because it doesn't not understand
yet prerequisite-patch-id. Can you please resubmit the series with Igor's (presumably) patches bundled in it?"So v11 carries it as 01/14. Unchanged, under your name, your Signed-off-by first and mine underneath as the person passing it on, with the four tags it has collected.
just citing here too, what I said elsewhere
https://lore.kernel.org/all/13701281.ZYm5mLc6kN@diego/
additionally, while reading the followup patches, please introduce some constants for the indices. ROCKET_CLK_ACLK, ... or some other name. Because when you access them later by index, that makes things harder to read and follow (especially in the future)
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip