From: sashiko-bot@kernel.org
To: "Jiaxing Hu" <gahing@gahingwoo.com>
Cc: robh@kernel.org, conor+dt@kernel.org,
dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v12 02/14] accel/rocket: take the completion register writes under job_lock
Date: Sat, 12 Sep 2026 07:04:11 +0000 [thread overview]
Message-ID: <20260912070412.44CE11F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260912065053.1519165-3-gahing@gahingwoo.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] The shared hardirq handler accesses hardware registers without checking if the device is active via pm_runtime_get_if_active(), causing spurious interrupts and potential bus faults when suspended.
- [High] The runtime suspend callback disables hardware clocks without first calling `synchronize_irq()`, leading to potential race conditions and hardware lockups with the shared IRQ handler.
- [Medium] Leak of IOMMU group kobject reference in `rocket_job_handle_irq()`.
- [Medium] The module removal path calls `pm_runtime_disable()` which can cancel a pending asynchronous autosuspend, leaving the hardware clocks permanently enabled.
--
commit 628f481e9ee69f13147956ea2124dd232b5d1c38
Author: Jiaxing Hu <gahing@gahingwoo.com>
accel/rocket: take the completion register writes under job_lock
This patch fixes a race condition by moving the OPERATION_ENABLE and
INTERRUPT_CLEAR register writes inside the job_lock scoped_guard. This ensures
that stopping the block and deciding what to start next are performed as a
single atomic step.
> diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
> index f404355058185..575945015ca3b 100644
> --- a/drivers/accel/rocket/rocket_job.c
> +++ b/drivers/accel/rocket/rocket_job.c
> @@ -345,10 +345,15 @@ static void rocket_job_handle_irq(struct rocket_core *core)
> {
> pm_runtime_mark_last_busy(core->dev);
>
> - rocket_pc_writel(core, OPERATION_ENABLE, 0x0);
> - rocket_pc_writel(core, INTERRUPT_CLEAR, 0x1ffff);
> + scoped_guard(mutex, &core->job_lock) {
> + /*
> + * Stopping the block belongs under the lock. hw_submit() writes
> + * OPERATION_ENABLE too, and outside the lock this zero can land
> + * after that one and stop a task that has only just started.
> + */
> + rocket_pc_writel(core, OPERATION_ENABLE, 0x0);
> + rocket_pc_writel(core, INTERRUPT_CLEAR, 0x1ffff);
>
> - scoped_guard(mutex, &core->job_lock)
> if (core->in_flight_job) {
> if (core->in_flight_job->next_task_idx < core->in_flight_job->task_count) {
> rocket_job_hw_submit(core, core->in_flight_job);
[Severity: Medium]
This is a pre-existing issue, but does this code leak a kobject
reference every time a job completes?
Just below this hunk in rocket_job_handle_irq(), the completion path has:
iommu_detach_group(NULL, iommu_group_get(core->dev));
Calling iommu_group_get(core->dev) retrieves the group and increments its
reference count.
However, iommu_detach_group() does not consume this reference, and there is
no matching iommu_group_put() in this path.
Could this be fixed by using the pre-cached core->iommu_group instead?
[ ... ]
[Severity: High]
This is a pre-existing issue, but can the shared IRQ handler cause an
asynchronous bus fault or spurious handling when the device is suspended?
The interrupt is registered as IRQF_SHARED in rocket_job_init():
drivers/accel/rocket/rocket_job.c:rocket_job_init() {
...
ret = devm_request_threaded_irq(core->dev, core->irq,
rocket_job_irq_handler,
rocket_job_irq_handler_thread,
IRQF_SHARED, dev_name(core->dev), core);
...
}
If another device on the same shared line triggers an interrupt while the
rocket device is runtime-suspended, the handler blindly reads from the hardware:
drivers/accel/rocket/rocket_job.c:rocket_job_irq_handler() {
struct rocket_core *core = data;
u32 raw_status = rocket_pc_readl(core, INTERRUPT_RAW_STATUS);
...
}
This unprotected read will typically return 0xffffffff when clocks are
disabled, which satisfies the bitmask checks and causes the handler to wake
the IRQ thread. The thread then executes on powered-off hardware.
Per subsystem guidelines, should we check if the device is active using
pm_runtime_get_if_active() before accessing registers here?
[Severity: High]
This is a pre-existing issue, but does the runtime suspend callback disable
clocks while the shared IRQ handler might still be executing?
drivers/accel/rocket/rocket_drv.c:rocket_device_runtime_suspend() {
...
clk_bulk_disable_unprepare(ARRAY_SIZE(rdev->cores[core].clks),
rdev->cores[core].clks);
return 0;
}
Since the interrupt is registered as IRQF_SHARED, the handler could be running
concurrently on another CPU.
If clocks are disabled exactly while the in-flight handler attempts to access
hardware registers, it will cause a hardware lockup.
Per subsystem guidelines, drivers using IRQF_SHARED must call
synchronize_irq() in their runtime suspend callback before powering down.
Should a synchronize_irq() call be added here?
[Severity: Medium]
This is a pre-existing issue, but can unloading the module leave the hardware
powered on permanently?
At the end of rocket_core_init() and during job completions, an autosuspend
is scheduled using pm_runtime_put_autosuspend(). However, the removal path
calls pm_runtime_disable() directly:
drivers/accel/rocket/rocket_core.c:rocket_core_fini() {
pm_runtime_dont_use_autosuspend(core->dev);
pm_runtime_disable(core->dev);
iommu_group_put(core->iommu_group);
...
}
Calling pm_runtime_disable() cancels any pending asynchronous autosuspend work.
If the module is removed while an autosuspend is pending, the device is left
powered on with clocks enabled.
Should we ensure the device is fully suspended (e.g., using
pm_runtime_put_sync()) before disabling runtime PM?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260912065053.1519165-1-gahing@gahingwoo.com?part=2
next prev parent reply other threads:[~2026-09-12 7:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-12 6:50 [PATCH v12 00/14] accel/rocket: RK3576 NPU (RKNN) enablement Jiaxing Hu
2026-09-12 6:50 ` [PATCH v12 01/14] accel/rocket: request the core clocks by name Jiaxing Hu
2026-09-12 7:03 ` sashiko-bot
2026-09-12 6:50 ` [PATCH v12 02/14] accel/rocket: take the completion register writes under job_lock Jiaxing Hu
2026-09-12 7:04 ` sashiko-bot [this message]
2026-09-12 6:50 ` [PATCH v12 03/14] accel/rocket: wait for a running IRQ handler before resetting a core Jiaxing Hu
2026-09-12 7:09 ` sashiko-bot
2026-09-12 11:37 ` Igor Paunovic
2026-09-12 6:50 ` [PATCH v12 04/14] accel/rocket: let the core suspend after a reset Jiaxing Hu
2026-09-12 7:04 ` sashiko-bot
2026-09-12 6:50 ` [PATCH v12 05/14] accel/rocket: factor the completion tail out of the IRQ handler Jiaxing Hu
2026-09-12 7:05 ` sashiko-bot
2026-09-12 6:50 ` [PATCH v12 06/14] dt-bindings: npu: rockchip: add rockchip,rk3576-rknn-core Jiaxing Hu
2026-09-12 6:50 ` [PATCH v12 07/14] dt-bindings: power: rockchip: allow resets in a power domain node Jiaxing Hu
2026-09-12 6:50 ` [PATCH v12 08/14] dt-bindings: iommu: rockchip: describe the RK3576 NPU MMU Jiaxing Hu
2026-09-12 7:02 ` sashiko-bot
2026-09-12 6:50 ` [PATCH v12 09/14] pmdomain: rockchip: add optional per-domain power-on settle delay Jiaxing Hu
2026-09-12 7:09 ` sashiko-bot
2026-09-12 6:50 ` [PATCH v12 10/14] pmdomain: rockchip: cycle optional power-domain resets on power-on Jiaxing Hu
2026-09-12 7:04 ` sashiko-bot
2026-09-12 6:50 ` [PATCH v12 11/14] accel/rocket: select the per-core clock and reset counts from match data Jiaxing Hu
2026-09-12 7:06 ` sashiko-bot
2026-09-12 6:50 ` [PATCH v12 12/14] accel/rocket: add RK3576 NPU (RKNN) support Jiaxing Hu
2026-09-12 7:22 ` sashiko-bot
2026-09-12 6:50 ` [PATCH v12 13/14] arm64: dts: rockchip: add NPU (RKNN) nodes to rk3576 Jiaxing Hu
2026-09-12 6:50 ` [PATCH v12 14/14] arm64: dts: rockchip: enable the NPU on rk3576-rock-4d Jiaxing Hu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260912070412.44CE11F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gahing@gahingwoo.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox