From: sashiko-bot@kernel.org
To: "Philipp Stanner" <phasta@kernel.org>
Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org,
ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v2 06/10] rust: DmaFence: Replace call_rcu() with cond_synchronize_rcu()
Date: Tue, 24 Nov 2026 12:43:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-231165@kernel.org> (raw)
In-Reply-To: <20261124122951.878199-8-phasta@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] rust: dma_fence: T::FenceDataType leak in DriverFence::drop()
--
commit feab68d7112ee39624929e1b6780cb4f28b65440
Author: Philipp Stanner <phasta@kernel.org>
rust: DmaFence: Replace call_rcu() with cond_synchronize_rcu()
This commit replaces deferred call_rcu() destruction of DriverFence data
with an inline cond_synchronize_rcu() wait in DriverFence::drop() so that
fence payloads are dropped in process context.
> diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs
> index c04b68fe67fe3..20dadbde4eb9d 100644
> --- a/rust/kernel/dma_buf/dma_fence.rs
> +++ b/rust/kernel/dma_buf/dma_fence.rs
[ ... ]
> @@ -988,59 +995,31 @@ fn drop(&mut self) {
> return;
> }
>
> - // SAFETY: Valid because `self` is valid.
> - let rcu_head_ptr = unsafe { &raw mut (*self.data.as_ptr()).rcu_head };
> + // SAFETY: `self` is valid. No one can access the cookie anymore because
> + // we are dropping.
> + let rcu_cookie = unsafe { *self.data.as_ref().synchronize_rcu_cookie.get() };
>
> - // 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>)) };
> - }
> -}
> + // Make sure none of the fence backend_ops can access fence-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().
> + if rcu_cookie != 0 {
> + // SAFETY: The if-else checks whether the cookie was validly
> + // initialized when this fence signaled.
> + unsafe { cond_synchronize_rcu(rcu_cookie) };
> + } else {
> + // The user never signaled this fence. We don't know the grace period.
> + synchronize_rcu();
> + }
>
> -// TODO:
> -// The entire call_rcu() mechanism in the drop above and the code below would be
> -// unnecessary if C's dma_fence_signal() could be reworked in a way that after it
> -// ran, the caller knows that no fence_ops callbacks can be running anymore.
> -// In other words, if the dma_fence backend would use its spinlock for full
> -// synchronization.
> -//
> -// Then we could move the drop_in_place() and dma_fence_put() upwards into the
> -// drop() implementation and call it a day.
> + // SAFETY: Valid because `self` is valid. RCU above ensures that all
> + // accessors are gone.
> + unsafe { drop_in_place(&raw mut self.data) };
>
> -/// Finally really drop this `DriverFence<T>`
> -///
> -/// # Safety
> -///
> -/// `head` references the `rcu_head` field of an `DriverFenceData<T>`. All
> -/// accessors to that `DriverFenceData<T>` must be gone by now. This must be
> -/// ensured by signalling the associated `DriverFence<T>` and then waiting
> -/// for a grace period until calling this function here.
> -unsafe extern "C" fn drop_driver_fence_data<T: Send + Sync + FenceContextOps>(
> - head: *mut bindings::callback_head,
> -) {
> - // SAFETY: Caller provides a pointer to the `rcu_head` field of a `DriverFenceData<C>`.
> - let fence_data = unsafe { container_of!(head, DriverFenceData<'_, T>, rcu_head) };
> -
> - // SAFETY: `fence_data` was created validly above. All the fence's data will
> - // only drop below, but the raw pointer to the raw C `dma_fence` remains
> - // valid because the reference count is only decremented at the end of the
> - // function.
> - let fence = unsafe { (*fence_data).inner.inner.get() };
> -
> - // SAFETY: `fence_data` was created validly above. The user has already
> - // dropped the only conventional accessor to the user data, the `DriverFence`,
> - // one grace period ago. All accessors are gone now.
> - unsafe { drop_in_place(&raw mut (*fence_data).data) };
> -
> - // The inner `Fence` explicitly does not get dropped because there may be
> - // many more users / consumers, each holding their own reference.
> -
> - // SAFETY: Once a `DriverFence` is initialized, the inner `fence` is valid
> - // and initialized. It is valid until the refcount drops to 0, which can
> - // earliest happen once we drop the `DriverFence`'s reference here.
> - unsafe { bindings::dma_fence_put(fence) };
> -
> - // The actual memory the data associated with a `DriverFence` lives in
> - // gets freed by the C dma_fence backend once the fence's refcount reaches 0.
> + // SAFETY: Valid because `self` is valid. This is the initial reference
> + // from when this `DriverFence` was created.
> + unsafe { bindings::dma_fence_put(self.as_raw()) };
> + }
> }
[Severity: High]
Does drop_in_place(&raw mut self.data) leak the inner T::FenceDataType
payload?
self.data on DriverFence is a NonNull<DriverFenceData<'a, T>>, which has no
Drop implementation, so drop_in_place(&raw mut self.data) is a no-op and
(*self.data.as_ptr()).data is never dropped before dma_fence_put() releases
the allocation. Note also that self.as_raw() creates a shared reference
&DriverFenceData<'a, T>, so the raw dma_fence pointer should be obtained
before dropping (*self.data.as_ptr()).data in place.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124122951.878199-2-phasta@kernel.org?part=6
next prev parent reply other threads:[~2026-11-24 12:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 12:29 [PATCH v2 00/10] rust: Add drm::JobQueue Philipp Stanner
2026-11-24 12:29 ` [PATCH v2 01/10] rust: rcu: Add get_state_synchronize_rcu() Philipp Stanner
2026-11-24 12:29 ` [PATCH v2 02/10] rust: rcu: Add cond_synchronize_rcu() Philipp Stanner
2026-11-24 12:29 ` [PATCH v2 03/10] rust: DmaFence: Implement Deref for FenceContext Philipp Stanner
2026-11-24 12:29 ` [PATCH v2 04/10] rust: DmaFence: Add ID accessor " Philipp Stanner
2026-11-24 12:29 ` [PATCH v2 05/10] rust: DmaFence: Don't drop on signal Philipp Stanner
2026-11-24 12:29 ` [PATCH v2 06/10] rust: DmaFence: Replace call_rcu() with cond_synchronize_rcu() Philipp Stanner
2026-11-24 12:43 ` sashiko-bot [this message]
2026-11-24 12:29 ` [PATCH v2 07/10] rust: DmaFence: Replace is_signaled() with status() Philipp Stanner
2026-11-24 12:44 ` sashiko-bot
2026-11-24 12:29 ` [PATCH v2 08/10] rust: DmaFence: Pass result in callbacks Philipp Stanner
2026-11-24 12:29 ` [PATCH v2 09/10] rust: drm: Add JobQueue Philipp Stanner
2026-11-24 12:55 ` sashiko-bot
2026-11-24 12:29 ` [PATCH v2 10/10] MAINTAINERS: Add drm::JobQueue to drm_sched's entry 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-231165@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