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: [RFC PATCH v7 4/8] rust: DmaFence: Replace call_rcu() with synchronize_rcu()
Date: Tue, 03 Nov 2026 15:44:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-195644@kernel.org> (raw)
In-Reply-To: <20261103153138.1087330-6-phasta@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] rust: dma_fence: payload leak in DriverFence::drop() dropping NonNull wrapper
--
commit 5c06afa6bb1de1d597e5eea16a29dd0b6c6d9220
Author: Philipp Stanner <phasta@kernel.org>
rust: DmaFence: Replace call_rcu() with synchronize_rcu()
This commit replaces the deferred RCU callback in DriverFence::drop() with
synchronize_rcu() so that driver fence data is not dropped from atomic
context, and updates FenceContext::drop() to use synchronize_rcu() instead
of rcu_barrier().
> diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs
> index 735c4f090a2c4..fbbc6ab202eca 100644
> --- a/rust/kernel/dma_buf/dma_fence.rs
> +++ b/rust/kernel/dma_buf/dma_fence.rs
[ ... ]
> @@ -980,59 +968,18 @@ fn drop(&mut self) {
> return;
> }
>
> + // 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().
> + synchronize_rcu();
> +
> // 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) };
>
> - // 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()) };
> }
> }
[Severity: High]
As reported by Sashiko on RFC v6 [1], does DriverFence::drop() leak the
T::FenceDataType payload when a DriverFence is dropped?
In DriverFence, self.data has type NonNull<DriverFenceData<'a, T>>, while
the user payload of type T::FenceDataType lives in the inner data field of
DriverFenceData:
rust/kernel/dma_buf/dma_fence.rs:
struct DriverFenceData<'a, T: Send + Sync + FenceContextOps> {
#[pin]
inner: Fence,
fctx: &'a FenceContext<T>,
#[pin]
data: T::FenceDataType,
}
...
pub struct DriverFence<'a, T: Send + Sync + FenceContextOps> {
data: NonNull<DriverFenceData<'a, T>>,
}
Because self is &mut DriverFence<'a, T>, passing &raw mut self.data to
drop_in_place() passes *mut NonNull<DriverFenceData<'a, T>> rather than
*mut T::FenceDataType. Since NonNull is a Copy pointer wrapper with no Drop
implementation, drop_in_place(&raw mut self.data) is a no-op, and the
subsequent dma_fence_put() releases the underlying allocation without ever
running the destructor for T::FenceDataType.
Should this obtain the raw dma_fence pointer before dropping the inner
payload, and then pass &raw mut (*self.data.as_ptr()).data to
drop_in_place() so that self.as_raw() does not create a shared reference to
DriverFenceData after its data field has been dropped in place?
[1] https://lore.kernel.org/r/20261016085724.1031766-6-phasta@kernel.org
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103153138.1087330-2-phasta@kernel.org?part=4
next prev parent reply other threads:[~2026-11-03 15:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 15:31 [RFC PATCH v7 0/8] rust: Add drm::JobQueue Philipp Stanner
2026-11-03 15:31 ` [RFC PATCH v7 1/8] rust: DmaFence: Implement Deref for FenceContext Philipp Stanner
2026-11-03 15:31 ` [RFC PATCH v7 2/8] rust: DmaFence: Add ID accessor for fctx Philipp Stanner
2026-11-03 15:31 ` [RFC PATCH v7 3/8] rust: DmaFence: Don't drop on signal Philipp Stanner
2026-11-03 15:31 ` [RFC PATCH v7 4/8] rust: DmaFence: Replace call_rcu() with synchronize_rcu() Philipp Stanner
2026-11-03 15:44 ` sashiko-bot [this message]
2026-11-03 15:31 ` [RFC PATCH v7 5/8] rust: DmaFence: Replace is_signaled() with status() Philipp Stanner
2026-11-03 15:45 ` sashiko-bot
2026-11-03 15:31 ` [RFC PATCH v7 6/8] rust: DmaFence: Tell results in signaling callbacks Philipp Stanner
2026-11-03 15:52 ` sashiko-bot
2026-11-03 15:31 ` [RFC PATCH v7 7/8] rust: drm: Add JobQueue Philipp Stanner
2026-11-03 16:08 ` sashiko-bot
2026-11-03 15:31 ` [RFC PATCH v7 8/8] samples: rust: Add JobQueue Tester Philipp Stanner
2026-11-03 16:07 ` sashiko-bot
2026-11-03 22:27 ` Younes Akhouayri
2026-11-04 8:41 ` 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-195644@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.