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 5/6] rust: DmaFence: Replace call_rcu() with synchronize_rcu()
Date: Fri, 09 Oct 2026 19:25:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-166000@kernel.org> (raw)
In-Reply-To: <20261009191124.1022902-7-phasta@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] rust: dma_fence: Memory leak of T::FenceDataType in DriverFence::drop()
- [High] rust: dma_fence: Sleep-in-atomic hazard due to synchronize_rcu() in Drop
--
commit fd18c02da88f26cc4c8c5dc518b90c8f1e16560b
Author: Philipp Stanner <phasta@kernel.org>
rust: DmaFence: Replace call_rcu() with synchronize_rcu()
The C dma_fence contract demands that a fence's data disappears no
earlier than 1 RCU grace period after the DriverFence was signaled.
So far, we achieved this with dropping the DriverFence's data in a
deferred manner with a manual, raw binding call to call_rcu().
> diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs
> index 4e9b4a6a9471b..cefcde80bf092 100644
> --- a/rust/kernel/dma_buf/dma_fence.rs
> +++ b/rust/kernel/dma_buf/dma_fence.rs
[ ... ]
> @@ -1022,59 +1020,18 @@ fn drop(&mut self) {
> return;
> }
>
> + // Make sure none of the fence backend_ops can access data anymore.
> + //
> + // TODO:
> + // This would not be necessary if the C dma_fence backend were using a
> + // spinlock to properly synchronize its signaled state. Fix it in C and
> + // then remove synchronize_rcu().
> + synchronize_rcu();
[Severity: High]
Does this introduce a sleep-in-atomic hazard when a DriverFence is dropped?
Since synchronize_rcu() blocks the current thread until an RCU grace period
completes, and Drop is executed implicitly when a value goes out of scope in
Rust, this could sleep if a DriverFence is dropped in an atomic context
(such as an interrupt handler or a spinlock critical section).
Because dma_fence is frequently manipulated in hardware IRQs, could this
cause a 'scheduling while atomic' kernel panic or deadlock?
>
> // SAFETY: Valid because `self` is valid.
> - let rcu_head_ptr = unsafe { &raw mut (*self.data.as_ptr()).rcu_head };
> + unsafe { drop_in_place(&raw mut self.data) };
[Severity: High]
Does this leak the T::FenceDataType payload?
Since self.data appears to be a NonNull wrapper, the expression
&raw mut self.data yields a pointer to the wrapper itself, not the actual
payload it points to.
Calling drop_in_place() on this pointer invokes the destructor for NonNull,
which is a no-op since it only implements Copy. Should this be dropping the
underlying payload, such as via &raw mut (*self.data.as_ptr()).data, as it
did in the previous drop_driver_fence_data callback?
>
> - // SAFETY: `call_rcu()` is always safe to be called. `rcu_head_ptr` was
> - // created validly above. The module must perform a `synchronize_rcu()`
> - // or `rcu_barrier()` call to guard against module unload.
> - unsafe { bindings::call_rcu(rcu_head_ptr, Some(drop_driver_fence_data::<T>)) };
> + // SAFETY: The `synchronize_rcu()` above ensures all accessors are gone.
> + unsafe { bindings::dma_fence_put(self.as_raw()) };
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261009191124.1022902-2-phasta@kernel.org?part=5
next prev parent reply other threads:[~2026-10-09 19:25 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
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 [this message]
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-166000@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox