All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Philipp Stanner" <phasta@kernel.org>
Cc: media-ci@linuxtv.org, ojeda@kernel.org,
	dri-devel@lists.freedesktop.org, gary@garyguo.net
Subject: Re: [RFC PATCH v5 3/6] rust: DmaFence: Don't drop on signal
Date: Fri, 09 Oct 2026 19:26:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-166001@kernel.org> (raw)
In-Reply-To: <20261009191124.1022902-5-phasta@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] dma_fence: counter underflow in DriverFence::signal on multiple calls
- [High] dma_fence: sleep-in-atomic bug when dropping DriverFence under spinlock
--

commit 79012d18b924ead15254b36baf7e1933525374af
Author: Philipp Stanner <phasta@kernel.org>

rust: DmaFence: Don't drop on signal

This commit decouples the dropping of a DriverFence from its signaling,
changing the signal() method to take &self rather than consuming the fence.
This allows the fence to be signaled multiple times and defers its
destruction to when the object goes out of scope. The intent is to avoid
dropping fences in an atomic context where deferred deletion is problematic.

> diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs
> index 0028124e6aa64..b67121c7abd41 100644
> --- a/rust/kernel/dma_buf/dma_fence.rs
> +++ b/rust/kernel/dma_buf/dma_fence.rs
> @@ -806,7 +806,7 @@ pub fn as_fence(&self) -> &Fence {
>      }
>  
>      /// Signal the fence. This will invoke all registered callbacks.
> -    pub fn signal(self, res: Result) {
> +    pub fn signal(&self, res: Result) {

[Severity: High]
Could the unconditional decrement at the end of this function corrupt the
nr_of_unsignaled_fences counter since signal() can now be called multiple
times?

rust/kernel/dma_buf/dma_fence.rs:DriverFence::signal() {
...
        let fctx = unsafe { self.data.as_ref().fctx };
        let _ = fctx.nr_of_unsignaled_fences.fetch_sub(1, Relaxed);
}

If signal() is called twice on the same fence, it looks like it will
underflow the hazard counter, causing a delayed panic when the FenceContext
is dropped.

[Severity: High]
Will this decoupling of signal() from drop() lead to a sleep-in-atomic bug
later in the series?

Since dropping is now deferred to when the DriverFence goes out of scope,
it appears to conflict with other patches in this series.

In patch 5, call_rcu() is replaced with synchronize_rcu() in
DriverFence::drop():

rust/kernel/dma_buf/dma_fence.rs:DriverFence::drop() {
...
        synchronize_rcu();
...
}

In patch 6, DriverFence is dropped while a SpinLockIrq is held:

rust/kernel/drm/job_queue.rs:JobQueue::complete_jobs_up_to_seqno() {
        let mut jq_locked = jq.lock();
        let mut jq = jq_locked.as_mut().project();

        let mut cursor = jq.running_jobs.cursor_front();

        while let Some(job) = cursor.peek_next() {
            let mut job = job.remove();
            ...
        } // `job` goes out of scope here, triggering DriverFence::drop
}

Dropping the DriverFence will call synchronize_rcu(), which sleeps, leading
to a sleep-in-atomic panic when invoked from the JobQueue lock guard.

>          let fence = self.as_fence().lock();
>  
>          // SAFETY: `fence` is valid because `self` is valid. The lock must be

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261009191124.1022902-2-phasta@kernel.org?part=3

  reply	other threads:[~2026-10-09 19:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 19:11 [RFC PATCH v5 0/6] rust: Add drm::JobQueue Philipp Stanner
2026-10-09 19:11 ` [RFC PATCH v5 1/6] rust: DmaFence: remove static lifetime Philipp Stanner
2026-10-09 19:24   ` sashiko-bot
2026-10-09 19:11 ` [RFC PATCH v5 2/6] rust: DmaFence: Implement Deref for FenceContext Philipp Stanner
2026-10-09 19:19   ` sashiko-bot
2026-10-09 19:11 ` [RFC PATCH v5 3/6] rust: DmaFence: Don't drop on signal Philipp Stanner
2026-10-09 19:26   ` sashiko-bot [this message]
2026-10-09 19:11 ` [RFC PATCH v5 4/6] rust: DmaFence: [RFC] Add Signaler Philipp Stanner
2026-10-09 19:23   ` sashiko-bot
2026-10-09 19:11 ` [RFC PATCH v5 5/6] rust: DmaFence: Replace call_rcu() with synchronize_rcu() Philipp Stanner
2026-10-09 19:25   ` sashiko-bot
2026-10-09 19:11 ` [RFC PATCH v5 6/6] rust: drm: Add JobQueue Philipp Stanner
2026-10-09 19:24   ` sashiko-bot
2026-10-11  0:22 ` [RFC PATCH v5 0/6] rust: Add drm::JobQueue Daniel Almeida
2026-10-12  8:17   ` Philipp Stanner

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=sashiko-outbox-166001@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=media-ci@linuxtv.org \
    --cc=ojeda@kernel.org \
    --cc=phasta@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.