dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lyude Paul" <lyude@redhat.com>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org
Subject: Re: [PATCH v19 2/4] rust: drm: gem: shmem: Add vmap functions
Date: Mon, 08 Jun 2026 18:45:46 +0000	[thread overview]
Message-ID: <20260608184546.88D101F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260608183057.2001376-3-lyude@redhat.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] The `vmap_io` KUnit test assumes little-endian byte ordering, causing the test to fail on big-endian architectures.
- [Medium] The `VMap` struct lacks explicit `Send` and `Sync` implementations, preventing users from safely sharing or transferring owned mappings across threads.
- [Low] The `VMap` struct is constructed without an `// INVARIANT:` comment explaining how its pointer validity invariant is satisfied.
--

commit ceea14411fbb1d31f384d7a4decb9b7c0d4302da
Author: Lyude Paul <lyude@redhat.com>

rust: drm: gem: shmem: Add vmap functions

This commit adds virtual memory mapping capabilities for GEM shmem objects
to the Rust DRM bindings.

> diff --git a/rust/kernel/drm/gem/shmem.rs b/rust/kernel/drm/gem/shmem.rs
> index 79ebd746e9611..e0bd0695ba1f8 100644
> --- a/rust/kernel/drm/gem/shmem.rs
> +++ b/rust/kernel/drm/gem/shmem.rs

[ ... ]

> @@ -191,6 +199,77 @@ extern "C" fn free_callback(obj: *mut bindings::drm_gem_object) {
>          // SAFETY: We're recovering the Kbox<> we created in gem_create_object()
>          let _ = unsafe { KBox::from_raw(this) };
>      }
> +
> +    /// Attempt to create a vmap from the gem object, and confirm the size of said vmap.
> +    fn make_vmap<'a, R, const SIZE: usize>(&'a self) -> Result<VMap<T, R, C, SIZE>>

[ ... ]

> +        // XXX: We don't currently support iomem allocations
> +        if map.is_iomem {
> +            // SAFETY: The vmap operation above succeeded, guaranteeing that map points to a valid
> +            // memory mapping.
> +            unsafe { self.raw_vunmap(map) };
> +
> +            Err(ENOTSUPP)
> +        } else {
> +            Ok(VMap {
> +                // SAFETY: We checked that this is not an iomem allocation, making it safe to read
> +                // vaddr.
> +                addr: unsafe { map.__bindgen_anon_1.vaddr },
> +                owner: self.into(),
> +            })

[Severity: Low]
this isn't a bug, but should there be an // INVARIANT: comment here?

According to the Rust subsystem guidelines, when a struct with an Invariants
documentation section is constructed, the code must have a comment explaining
why the invariants are satisfied. The pointer validity invariant doesn't
appear to be documented during this instantiation.

> +        }
> +    }

[ ... ]

> @@ -270,3 +348,238 @@ fn drop(&mut self) {
> +/// A reference to a virtual mapping for an shmem-based GEM object in kernel address space.
> +///
> +/// # Invariants
> +///
> +/// - The size of owner is >= SIZE.
> +/// - The memory pointed to by addr remains valid at least until this object is dropped.
> +pub struct VMap<D, R, C = Registered, const SIZE: usize = 0>
> +where
> +    D: DriverObject,
> +    C: DeviceContext,
> +    R: Deref<Target = Object<D, C>>,
> +{
> +    addr: *mut c_void,
> +    owner: R,
> +}

[Severity: Medium]
Should VMap explicitly implement Send and Sync?

Since the addr field is a raw pointer, VMap and its aliases will default to
being !Send and !Sync. Would this prevent users from safely passing owned
mappings across threads or into multithreaded workqueues?

[ ... ]

> +    #[test]
> +    fn vmap_io() -> Result {
> +        let (_dev, drm) = create_drm_dev()?;
> +
> +        let obj = Object::<KunitObject, _>::new(&drm, PAGE_SIZE, ObjectConfig::default(), ())?;
> +
> +        let vmap = obj.vmap::<PAGE_SIZE>()?;
> +
> +        vmap.write8(0xDE, 0x0);
> +        assert_eq!(vmap.read8(0x0), 0xDE);
> +        vmap.write32(0xFEDCBA98, 0x20);
> +
> +        assert_eq!(vmap.read32(0x20), 0xFEDCBA98);
> +
> +        assert_eq!(vmap.read8(0x20), 0x98);
> +        assert_eq!(vmap.read8(0x21), 0xBA);
> +        assert_eq!(vmap.read8(0x22), 0xDC);
> +        assert_eq!(vmap.read8(0x23), 0xFE);

[Severity: Medium]
Does this test assume little-endian byte ordering?

The test writes a 32-bit integer (0xFEDCBA98) using native byte ordering,
but the byte-by-byte assertions check that the first byte at the lowest
address is 0x98. On big-endian architectures, wouldn't the most significant
byte (0xFE) be stored at the lowest address, causing this test to fail?

> +
> +        Ok(())
> +    }
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260608183057.2001376-1-lyude@redhat.com?part=2

  reply	other threads:[~2026-06-08 18:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08 18:29 [PATCH v19 0/4] Rust bindings for gem shmem Lyude Paul
2026-06-08 18:29 ` [PATCH v19 1/4] rust: drm: gem: shmem: Add DmaResvGuard helper Lyude Paul
2026-06-08 18:43   ` sashiko-bot
2026-06-09 18:19     ` lyude
2026-06-09 19:28       ` Miguel Ojeda
2026-06-08 18:29 ` [PATCH v19 2/4] rust: drm: gem: shmem: Add vmap functions Lyude Paul
2026-06-08 18:45   ` sashiko-bot [this message]
2026-06-08 18:29 ` [PATCH v19 3/4] rust: faux: Allow retrieving a bound Device Lyude Paul
2026-06-08 18:41   ` sashiko-bot
2026-06-08 18:29 ` [PATCH v19 4/4] rust: drm: gem: Introduce shmem::Object::sg_table() Lyude Paul
2026-06-08 18:48   ` sashiko-bot
2026-06-10 15:46     ` lyude
2026-06-08 18:50 ` [PATCH v19 0/4] Rust bindings for gem shmem Danilo Krummrich
2026-06-10  0:20 ` Deborah Brouwer

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=20260608184546.88D101F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox