From: sashiko-bot@kernel.org
To: "Lyude Paul" <lyude@redhat.com>
Cc: linux-media@vger.kernel.org, ojeda@kernel.org
Subject: Re: [PATCH v17 2/6] rust: drm: gem: shmem: Add DmaResvGuard helper
Date: Wed, 03 Jun 2026 20:09:17 +0000 [thread overview]
Message-ID: <20260603200918.6160D1F00898@smtp.kernel.org> (raw)
In-Reply-To: <20260603195210.693856-3-lyude@redhat.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] `DmaResvGuard` implicitly implements `Send`, allowing the lock to be sent to and unlocked by a different thread, violating kernel locking rules.
- [Medium] `DmaResvGuard` lacks the `#[must_use]` attribute, which can lead to accidental immediate lock drops.
- [Low] Incorrect use of `#[inline(always)]` instead of `#[inline]` on abstraction functions.
--
commit 35ca0f9ce4df1005935e123463429a164cf640a5
Author: Lyude Paul <lyude@redhat.com>
rust: drm: gem: shmem: Add DmaResvGuard helper
Just a temporary holdover to make locking/unlocking the dma_resv lock much
easier.
> diff --git a/rust/kernel/drm/gem/shmem.rs b/rust/kernel/drm/gem/shmem.rs
> index 084b798ce795b..650c34dd8b7a4 100644
> --- a/rust/kernel/drm/gem/shmem.rs
> +++ b/rust/kernel/drm/gem/shmem.rs
[ ... ]
> @@ -244,3 +247,29 @@ impl<T: DriverObject, C: DeviceContext> driver::AllocImpl for Object<T, C> {
> dumb_map_offset: None,
> };
> }
> +
> +/// Private helper-type for holding the `dma_resv` object for a GEM shmem object.
> +///
> +/// When this is dropped, the `dma_resv` lock is dropped as well.
> +///
> +// TODO: This should be replace with a WwMutex equivalent once we have such bindings in the kernel.
> +struct DmaResvGuard<'a, T: DriverObject, C: DeviceContext = Registered>(&'a Object<T, C>);
[Severity: High]
Does `DmaResvGuard` implicitly implement `Send`, allowing the lock to be
acquired in one thread, sent to another thread, and unlocked there?
Since `Object<T, C>` implements `Sync`, the shared reference `&'a Object<T, C>`
is `Send`. However, `bindings::dma_resv_unlock` internally calls
`ww_mutex_unlock()`, which requires the mutex to be unlocked by the exact
same task that locked it.
Should this struct include `NotThreadSafe` (or `PhantomData<*mut ()>`) to
ensure it cannot be sent across threads?
[Severity: Medium]
Could this struct also be annotated with `#[must_use]`?
Without it, if a caller writes `DmaResvGuard::new(obj);` instead of
`let _guard = DmaResvGuard::new(obj);`, the lock is acquired and immediately
released at the end of the statement, leaving the rest of the scope
unprotected without triggering a compiler warning.
> +
> +impl<'a, T: DriverObject, C: DeviceContext> DmaResvGuard<'a, T, C> {
> + #[inline(always)]
[Severity: Low]
This isn't a bug, but according to the Rust coding guidelines, shouldn't small
abstraction functions or binding wrappers like this be annotated with `#[inline]`
rather than `#[inline(always)]`?
`#[inline(always)]` is generally reserved for functions using `build_assert!()`
that depend on function parameters.
> + #[expect(unused)]
> + fn new(obj: &'a Object<T, C>) -> Self {
> + // SAFETY: This lock is initialized throughout the lifetime of `object`.
> + unsafe { bindings::dma_resv_lock(obj.raw_dma_resv(), ptr::null_mut()) };
> +
> + Self(obj)
> + }
> +}
> +
> +impl<'a, T: DriverObject, C: DeviceContext> Drop for DmaResvGuard<'a, T, C> {
> + #[inline(always)]
[Severity: Low]
This isn't a bug, but similar to the new() function above, should this
be `#[inline]` instead of `#[inline(always)]`?
> + fn drop(&mut self) {
> + // SAFETY: We are releasing the lock grabbed during the creation of this object.
> + unsafe { bindings::dma_resv_unlock(self.0.raw_dma_resv()) };
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260603195210.693856-1-lyude@redhat.com?part=2
next prev parent reply other threads:[~2026-06-03 20:09 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 19:42 [PATCH v17 0/6] Rust bindings for gem shmem Lyude Paul
2026-06-03 19:42 ` Lyude Paul
2026-06-03 19:42 ` [PATCH v17 1/6] rust: drm: gem: shmem: Fix Default implementation for ObjectConfig Lyude Paul
2026-06-03 19:42 ` Lyude Paul
2026-06-03 20:02 ` sashiko-bot
2026-06-04 11:49 ` Alice Ryhl
2026-06-04 11:49 ` Alice Ryhl
2026-06-03 19:42 ` [PATCH v17 2/6] rust: drm: gem: shmem: Add DmaResvGuard helper Lyude Paul
2026-06-03 19:42 ` Lyude Paul
2026-06-03 20:09 ` sashiko-bot [this message]
2026-06-03 19:42 ` [PATCH v17 3/6] rust: drm: gem: shmem: Add vmap functions Lyude Paul
2026-06-03 19:42 ` Lyude Paul
2026-06-03 20:11 ` sashiko-bot
2026-06-03 19:42 ` [PATCH v17 4/6] rust: faux: Allow retrieving a bound Device Lyude Paul
2026-06-03 19:42 ` Lyude Paul
2026-06-03 20:08 ` sashiko-bot
2026-06-04 13:25 ` Danilo Krummrich
2026-06-04 13:25 ` Danilo Krummrich
2026-06-04 18:48 ` lyude
2026-06-04 18:48 ` lyude
2026-06-03 19:42 ` [PATCH v17 5/6] rust: sync: Add SetOnce::reset() Lyude Paul
2026-06-03 19:42 ` Lyude Paul
2026-06-03 20:07 ` sashiko-bot
2026-06-04 11:58 ` Alice Ryhl
2026-06-04 18:53 ` lyude
2026-06-03 19:42 ` [PATCH v17 6/6] rust: drm: gem: Introduce shmem::Object::sg_table() Lyude Paul
2026-06-03 19:42 ` Lyude Paul
2026-06-03 20:12 ` sashiko-bot
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=20260603200918.6160D1F00898@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@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.