* [PATCH] rust: drm: ioctl: fix call to unsafe function
@ 2026-11-18 13:32 Vishal Moola (Fractile)
2026-11-18 15:29 ` Alice Ryhl
2026-11-18 16:17 ` Danilo Krummrich
0 siblings, 2 replies; 5+ messages in thread
From: Vishal Moola (Fractile) @ 2026-11-18 13:32 UTC (permalink / raw)
To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan, Asahi Lina,
Lyude Paul
Cc: dri-devel, rust-for-linux, linux-kernel, Vishal Moola (Fractile)
dev is created via an unsafe pointer dereference. Following the
convention, it should be wrapped in an unsafe block, but it is not.
The compiler only properly lints declare_drm_ioctls! when its defined
in the same crate as it expands in. Since upstream drivers are all
separate crates, this is silently ignored.
This has been present since commit 9a69570682b1 ("rust: drm: ioctl:
Add DRM ioctl abstraction").
Fixes: 9a69570682b1 ("rust: drm: ioctl: Add DRM ioctl abstraction")
Signed-off-by: Vishal Moola (Fractile) <vishal.moola@gmail.com>
--------------------
Based on drm-rust-next.
I encountered this while trying to build a rust driver out of tree. I
copied the macro to an out-of-tree crate so that our uapi can see the
same generated values without needing the generated bindings.
Ai has told me that this is because the macro expands from the same
crate its defined in, which sounds sensible.
I see:
error[E0133]: call to unsafe function `kernel::drm::Device::<T, C>::from_raw` is unsafe and requires unsafe block
--> driver/drm_ioctl.rs:77:33
|
77 | ... ::kernel::drm::device::Device::from_raw(raw_dev);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
Plus a number of warnings. But warnings are warnings so those are
whatever... Its all silently ignored upstream anyways, so doesn't
need a cc-stable either.
---
rust/kernel/drm/ioctl.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
index 64af9eacc306..5a2e2f4f0e91 100644
--- a/rust/kernel/drm/ioctl.rs
+++ b/rust/kernel/drm/ioctl.rs
@@ -152,7 +152,7 @@ macro_rules! declare_drm_ioctls {
// dev/file match the current driver these ioctls are being declared
// for, and it's not clear how to enforce this within the type system.
let dev: &$crate::drm::device::Device<_, $crate::drm::Ioctl> =
- $crate::drm::device::Device::from_raw(raw_dev);
+ unsafe { $crate::drm::device::Device::from_raw(raw_dev) };
// Type-inference anchor: the closure is never called but ties `dev`'s
// type to `$func`'s first parameter, which the compiler cannot infer
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] rust: drm: ioctl: fix call to unsafe function
2026-11-18 13:32 [PATCH] rust: drm: ioctl: fix call to unsafe function Vishal Moola (Fractile)
@ 2026-11-18 15:29 ` Alice Ryhl
2026-11-18 15:55 ` Vishal Moola (Fractile)
2026-11-18 16:17 ` Danilo Krummrich
1 sibling, 1 reply; 5+ messages in thread
From: Alice Ryhl @ 2026-11-18 15:29 UTC (permalink / raw)
To: Vishal Moola (Fractile)
Cc: Alice Ryhl, Danilo Krummrich, David Airlie, Simona Vetter,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan, Asahi Lina,
Lyude Paul, dri-devel, rust-for-linux, linux-kernel
On Wed, Nov 18, 2026 at 01:32:32PM +0000, Vishal Moola (Fractile) wrote:
> Fixes: 9a69570682b1 ("rust: drm: ioctl: Add DRM ioctl abstraction")
> Signed-off-by: Vishal Moola (Fractile) <vishal.moola@gmail.com>
>
> --------------------
> Based on drm-rust-next.
Note that patch commentary needs to go after a three-dash `---` line
rather than `--------------------`, otherwise `git am` / `b4` includes
everything above `---` in the commit message. No need to resend just for
that as we can strip it when applying.
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Alice
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: drm: ioctl: fix call to unsafe function
2026-11-18 15:29 ` Alice Ryhl
@ 2026-11-18 15:55 ` Vishal Moola (Fractile)
0 siblings, 0 replies; 5+ messages in thread
From: Vishal Moola (Fractile) @ 2026-11-18 15:55 UTC (permalink / raw)
To: Alice Ryhl
Cc: Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Trevor Gross, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, Asahi Lina, Lyude Paul,
dri-devel, rust-for-linux, linux-kernel
On Wed, Nov 18, 2026 at 03:29:01PM +0000, Alice Ryhl wrote:
> On Wed, Nov 18, 2026 at 01:32:32PM +0000, Vishal Moola (Fractile) wrote:
> > Fixes: 9a69570682b1 ("rust: drm: ioctl: Add DRM ioctl abstraction")
> > Signed-off-by: Vishal Moola (Fractile) <vishal.moola@gmail.com>
> >
> > --------------------
> > Based on drm-rust-next.
>
> Note that patch commentary needs to go after a three-dash `---` line
> rather than `--------------------`, otherwise `git am` / `b4` includes
> everything above `---` in the commit message. No need to resend just for
> that as we can strip it when applying.
Ah, I never realized the tools were that particular about exactly three
dashes. Thanks for pointing that out, I'll keep that in mind for the
future :).
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
>
> Alice
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: drm: ioctl: fix call to unsafe function
2026-11-18 13:32 [PATCH] rust: drm: ioctl: fix call to unsafe function Vishal Moola (Fractile)
2026-11-18 15:29 ` Alice Ryhl
@ 2026-11-18 16:17 ` Danilo Krummrich
2026-11-18 16:57 ` Vishal Moola (Fractile)
1 sibling, 1 reply; 5+ messages in thread
From: Danilo Krummrich @ 2026-11-18 16:17 UTC (permalink / raw)
To: Vishal Moola (Fractile)
Cc: Alice Ryhl, David Airlie, Simona Vetter, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Asahi Lina, Lyude Paul, dri-devel,
rust-for-linux, linux-kernel
On Wed Nov 18, 2026 at 2:32 PM CET, Vishal Moola (Fractile) wrote:
> diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
> index 64af9eacc306..5a2e2f4f0e91 100644
> --- a/rust/kernel/drm/ioctl.rs
> +++ b/rust/kernel/drm/ioctl.rs
> @@ -152,7 +152,7 @@ macro_rules! declare_drm_ioctls {
> // dev/file match the current driver these ioctls are being declared
> // for, and it's not clear how to enforce this within the type system.
> let dev: &$crate::drm::device::Device<_, $crate::drm::Ioctl> =
> - $crate::drm::device::Device::from_raw(raw_dev);
> + unsafe { $crate::drm::device::Device::from_raw(raw_dev) };
I remember there has been at least one compiler version in the supported range
that complained when the safety comment isn't directly above the unsafe block.
Has this been fixed in the meantime?
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] rust: drm: ioctl: fix call to unsafe function
2026-11-18 16:17 ` Danilo Krummrich
@ 2026-11-18 16:57 ` Vishal Moola (Fractile)
0 siblings, 0 replies; 5+ messages in thread
From: Vishal Moola (Fractile) @ 2026-11-18 16:57 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Alice Ryhl, David Airlie, Simona Vetter, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Asahi Lina, Lyude Paul, dri-devel,
rust-for-linux, linux-kernel
On Wed, Nov 18, 2026 at 05:17:41PM +0100, Danilo Krummrich wrote:
> On Wed Nov 18, 2026 at 2:32 PM CET, Vishal Moola (Fractile) wrote:
> > diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
> > index 64af9eacc306..5a2e2f4f0e91 100644
> > --- a/rust/kernel/drm/ioctl.rs
> > +++ b/rust/kernel/drm/ioctl.rs
> > @@ -152,7 +152,7 @@ macro_rules! declare_drm_ioctls {
> > // dev/file match the current driver these ioctls are being declared
> > // for, and it's not clear how to enforce this within the type system.
> > let dev: &$crate::drm::device::Device<_, $crate::drm::Ioctl> =
> > - $crate::drm::device::Device::from_raw(raw_dev);
> > + unsafe { $crate::drm::device::Device::from_raw(raw_dev) };
>
> I remember there has been at least one compiler version in the supported range
> that complained when the safety comment isn't directly above the unsafe block.
> Has this been fixed in the meantime?
I'm not sure? I'm compiling with rustc 1.98.1 (48a229cea 2026-09-01) (Fedora 1.98.1-1.fc44)
which gives me no errors like this.
Hopefully the build-bots catch it if there's a specific compiler version
that still dislikes it.
The following command shows a few other occurences in the kernel like this,
so if its still an issue I imagine it'd likely be caught somewhere:
grep -rn -B1 '^\s*unsafe {' rust/kernel | grep '=$'
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-18 16:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 13:32 [PATCH] rust: drm: ioctl: fix call to unsafe function Vishal Moola (Fractile)
2026-11-18 15:29 ` Alice Ryhl
2026-11-18 15:55 ` Vishal Moola (Fractile)
2026-11-18 16:17 ` Danilo Krummrich
2026-11-18 16:57 ` Vishal Moola (Fractile)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox