All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: ojeda@kernel.org, dri-devel@lists.freedesktop.org,
	"Alexandre Courbot" <acourbot@nvidia.com>
Subject: Re: [PATCH v3 12/13] rust: drm: Pass registration data to ioctl handlers
Date: Sat, 20 Jun 2026 01:16:03 +0000	[thread overview]
Message-ID: <20260620011603.F05AC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260620005431.1562115-13-dakr@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing `Sync` bound on `RegistrationData` allows data races via concurrent ioctl calls.
- [High] Unconstrained type inference in `declare_drm_ioctls!` bypasses type invariants, causing Undefined Behavior.
--

commit 4f19dadb5da1b4410f3118837853bdb09c3f4718
Author: Danilo Krummrich <dakr@kernel.org>

rust: drm: Pass registration data to ioctl handlers

Pass registration data to ioctl handlers via
drm::Device<Registered>::registration_data_with().

[ ... ]
> diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
> index c6a03be018e6d..ecc1a0383635c 100644
> --- a/rust/kernel/drm/ioctl.rs
> +++ b/rust/kernel/drm/ioctl.rs
[ ... ]
> @@ -143,9 +144,16 @@ macro_rules! declare_drm_ioctls {
>                              // type to `$func`'s first parameter, which the compiler cannot infer
>                              // through method resolution and associated-type projections alone.
>                              #[allow(unreachable_code)]
> -                            let _ = || $func(dev, unreachable!(), unreachable!());
> +                            let _ = || {
> +                                $func(
> +                                    dev,
> +                                    unreachable!(),
> +                                    unreachable!(),
> +                                    unreachable!(),
> +                                )
> +                            };

[Severity: High]
Does this type inference bypass the safety invariants of Device::from_raw()?

Because dev is passed directly to the user-provided $func in this dummy 
closure, the compiler infers the DeviceContext of dev from the handler's 
signature. If an ioctl handler expects &Device<T, Registered>, the compiler 
resolves dev to be a Registered device.

This means the preceding call to Device::from_raw(raw_dev) instantiates a 
Registered device reference before registration_guard() establishes the 
drm_dev_enter SRCU critical section. This bypasses the safety contract which 
requires the parent bus device to be bound.

Would it be safer to explicitly constrain dev to Device<_, Normal>, and 
pass &*guard instead of dev to the dummy closure?

>  
> -                            let Some(_guard) = dev.registration_guard() else {
> +                            let Some(guard) = dev.registration_guard() else {
>                                  return $crate::error::code::ENODEV.to_errno();
>                              };
[ ... ]
> @@ -160,7 +168,9 @@ macro_rules! declare_drm_ioctls {
>                              // SAFETY: This is just the DRM file structure
>                              let file = unsafe { $crate::drm::File::from_raw(raw_file) };
>  
> -                            match $func(dev, data, file) {
> +                            match guard.registration_data_with(|reg_data| {
> +                                $func(&*guard, reg_data, data, file)
> +                            }) {

[Severity: High]
Can this allow data races if the RegistrationData type is not Sync?

Looking at the Driver trait definition in rust/kernel/drm/driver.rs:

trait Driver {
    type RegistrationData: ForLt;
    ...
}

RegistrationData is defined without a Sync bound. However, Device<T, C> 
is unconditionally Sync, meaning any thread can access its shared methods 
concurrently. 

Since multiple userspace threads can invoke DRM ioctls concurrently, multiple 
threads can call registration_data_with() at the same time to obtain shared 
references to the same data. If a driver uses a non-Sync type for 
RegistrationData (such as Cell<T>), could this lead to concurrent mutation 
and undefined behavior?

>                                  Err(e) => e.to_errno(),
>                                  Ok(i) => i.try_into()
>                                              .unwrap_or($crate::error::code::ERANGE.to_errno()),

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260620005431.1562115-1-dakr@kernel.org?part=12

  reply	other threads:[~2026-06-20  1:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-20  0:51 [PATCH v3 00/13] rust: drm: Higher-Ranked Lifetime private data Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 01/13] rust: drm: rename Uninit DeviceContext to Normal Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 02/13] rust: drm: Add Driver::ParentDevice associated type Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 03/13] rust: drm: change default DeviceContext to Normal Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 04/13] rust: drm: restrict AlwaysRefCounted to Normal Device context Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 05/13] rust: drm: restrict AlwaysRefCounted to Normal GEM Object context Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 06/13] rust: drm: split Deref for Device context typestates Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 07/13] rust: drm: return ParentDevice from Device AsRef Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 08/13] rust: drm: add AsRef<ParentDevice<Bound>> for Device<Registered> Danilo Krummrich
2026-06-20  0:51 ` [PATCH v3 09/13] rust: drm: Add RegistrationGuard for drm_dev_enter/exit critical sections Danilo Krummrich
2026-06-20  1:12   ` sashiko-bot
2026-06-20  0:51 ` [PATCH v3 10/13] rust: drm: Add RegistrationData to drm::Driver Danilo Krummrich
2026-06-20  1:10   ` sashiko-bot
2026-06-20  0:51 ` [PATCH v3 11/13] rust: drm: Wrap ioctl dispatch in RegistrationGuard Danilo Krummrich
2026-06-20  1:13   ` sashiko-bot
2026-06-20  0:51 ` [PATCH v3 12/13] rust: drm: Pass registration data to ioctl handlers Danilo Krummrich
2026-06-20  1:16   ` sashiko-bot [this message]
2026-06-20  0:51 ` [PATCH v3 13/13] drm: nova: Use drm::Device<Registered> to access the parent bus device Danilo Krummrich
2026-06-20  1:17   ` sashiko-bot
2026-06-20 16:52 ` [PATCH v3 00/13] rust: drm: Higher-Ranked Lifetime private data Danilo Krummrich

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=20260620011603.F05AC1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --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.