dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "GuoHan Zhao" <zhaoguohan@kylinos.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 5/5] accel/ethosu: fix job completion fence cleanup
Date: Fri, 17 Jul 2026 06:22:17 +0000	[thread overview]
Message-ID: <20260717062218.29B071F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717061145.1478139-6-zhaoguohan@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Calling drm_sched_job_cleanup() on an uninitialized struct drm_sched_job causes a NULL pointer dereference in the ethosu_ioctl_submit_job() error path.
- [High] The shared IRQ handler accesses hardware registers without ensuring the device is active via Runtime PM, and the suspend callback fails to synchronize IRQs, risking fatal bus faults.
--

--- Patch [5]: [PATCH v2 5/5] accel/ethosu: fix job completion fence cleanup ---
commit b390c1806154d7460d3ff212d56c250283785f11
Author: GuoHan Zhao <zhaoguohan@kylinos.cn>
Subject: accel/ethosu: fix job completion fence cleanup

This commit addresses memory leaks and refcount underflows in the Ethos-U NPU
driver's job cleanup path. It ensures that the done_fence is properly released
during error cleanup and uses dma_fence_was_initialized() to handle raw
allocations gracefully.

Link: https://sashiko.dev/#/patchset/20260716065219.931088-1-zhaoguohan@kylinos.cn?part=1

> diff --git a/drivers/accel/ethosu/ethosu_job.c b/drivers/accel/ethosu/ethosu_job.c
> index 5847433e87e7e..b68a905d22f83 100644
> --- a/drivers/accel/ethosu/ethosu_job.c
> +++ b/drivers/accel/ethosu/ethosu_job.c
> @@ -152,6 +152,13 @@ static void ethosu_job_err_cleanup(struct ethosu_job *job)
>  
>  	drm_gem_object_put(job->cmd_bo);
>  
> +	if (job->done_fence) {
> +		if (dma_fence_was_initialized(job->done_fence))
> +			dma_fence_put(job->done_fence);
> +		else
> +			dma_fence_free(job->done_fence);
> +	}
> +
>  	kfree(job);
>  }
>  

[Severity: High]
This is a pre-existing issue, but was not introduced by this patch.

When the done_fence allocation fails in ethosu_ioctl_submit_job(), it jumps
to out_cleanup_job:

drivers/accel/ethosu/ethosu_job.c:ethosu_ioctl_submit_job() {
    ...
	if (!ejob->done_fence) {
		ret = -ENOMEM;
		goto out_cleanup_job;
	}
    ...
out_cleanup_job:
	if (ret)
		drm_sched_job_cleanup(&ejob->base);
}

Because drm_sched_job_init() was not called yet, ejob->base is completely
zero-initialized, meaning ejob->base.s_fence is NULL.

When drm_sched_job_cleanup() attempts to read the refcount:

drivers/gpu/drm/scheduler/sched_main.c:drm_sched_job_cleanup() {
    ...
	if (kref_read(&job->s_fence->finished.refcount)) {
    ...
}

Will this result in a NULL pointer dereference because the function assumes
job->s_fence is a valid pointer?


[Severity: High]
This isn't a bug introduced by this patch, but there appears to be an issue
with how shared interrupts interact with runtime PM.

The NPU interrupt is registered with the IRQF_SHARED flag:

drivers/accel/ethosu/ethosu_job.c:ethosu_job_init() {
    ...
	ret = devm_request_threaded_irq(dev, edev->irq,
				ethosu_job_irq_handler,
				ethosu_job_irq_handler_thread,
				IRQF_SHARED, KBUILD_MODNAME,
				edev);
    ...
}

If another device sharing the IRQ line triggers an interrupt while the NPU is
runtime-suspended, the handler executes and reads MMIO registers:

drivers/accel/ethosu/ethosu_job.c:ethosu_job_irq_handler() {
    ...
	u32 status = readl_relaxed(dev->regs + NPU_REG_STATUS);

	if (!(status & STATUS_IRQ_RAISED))
		return IRQ_NONE;
    ...
}

Could this unconditionally read registers without verifying the device's PM
state via pm_runtime_get_if_active()?

Furthermore, the runtime suspend callback disables clocks:

drivers/accel/ethosu/ethosu_drv.c:ethosu_device_suspend() {
    ...
	clk_bulk_disable_unprepare(ethosudev->num_clks, ethosudev->clks);
	return 0;
}

Since this doesn't call synchronize_irq() to wait for executing handlers,
could concurrent IRQ execution cause invalid hardware writes or a bus fault
when accessing powered-off MMIO registers?

> @@ -162,7 +169,6 @@ static void ethosu_job_cleanup(struct kref *ref)
>  
>  	pm_runtime_put_autosuspend(job->dev->base.dev);
>  
> -	dma_fence_put(job->done_fence);
>  	dma_fence_put(job->inference_done_fence);
>  
>  	ethosu_job_err_cleanup(job);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260717061145.1478139-1-zhaoguohan@kylinos.cn?part=5

      reply	other threads:[~2026-07-17  6:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17  6:11 [PATCH v2 0/5] accel/ethosu: fix probe and job cleanup errors GuoHan Zhao
2026-07-17  6:11 ` [PATCH v2 1/5] accel/ethosu: check DMA mask setup GuoHan Zhao
2026-07-17  6:23   ` sashiko-bot
2026-07-17  6:11 ` [PATCH v2 2/5] accel/ethosu: fix scheduler and IRQ lifetime GuoHan Zhao
2026-07-17  6:24   ` sashiko-bot
2026-07-17  6:11 ` [PATCH v2 3/5] accel/ethosu: clean up resources on probe failure GuoHan Zhao
2026-07-17  6:27   ` sashiko-bot
2026-07-17  6:11 ` [PATCH v2 4/5] accel/ethosu: propagate SRAM initialization errors GuoHan Zhao
2026-07-17  6:24   ` sashiko-bot
2026-07-17  6:11 ` [PATCH v2 5/5] accel/ethosu: fix job completion fence cleanup GuoHan Zhao
2026-07-17  6:22   ` sashiko-bot [this message]

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=20260717062218.29B071F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhaoguohan@kylinos.cn \
    /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