lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <282C2384-D046-43E3-88DE-70A130961D93@collabora.com>
Date: Fri, 5 Sep 2025 12:18:47 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Lyude Paul <lyude@...hat.com>
Cc: dri-devel@...ts.freedesktop.org, rust-for-linux@...r.kernel.org,
	linux-kernel@...r.kernel.org, Miguel Ojeda <ojeda@...nel.org>,
	Alex Gaynor <alex.gaynor@...il.com>,
	Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,
	Benno Lossin <lossin@...nel.org>,
	Andreas Hindborg <a.hindborg@...nel.org>,
	Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
	Danilo Krummrich <dakr@...nel.org>,
	Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
	Maxime Ripard <mripard@...nel.org>,
	Thomas Zimmermann <tzimmermann@...e.de>,
	David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
	Sumit Semwal <sumit.semwal@...aro.org>,
	Christian König <christian.koenig@....com>,
	Asahi Lina <lina+kernel@...hilina.net>, linux-media@...r.kernel.org,
	linaro-mm-sig@...ts.linaro.org,
	"open list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b <linux-media"@vger.kernel.org (ope>),
	"moderated list:DMA BUFFER SHARING  FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b <linaro-mm-sig"@lists.linaro.org (mod>)
Subject: Re: [PATCH v3 14/14] rust: drm: gem: Add BaseObject::prime_export()



> On 29 Aug 2025, at 19:35, Lyude Paul <lyude@...hat.com> wrote:
> 
> We just added an export() callback that GEM objects can implement, but
> without any way of actually exporting a DmaBuf<T>. So let's add one by
> introducing bindings for drm_gem_prime_export().
> 
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
> rust/kernel/dma_buf.rs     |  1 -
> rust/kernel/drm/gem/mod.rs | 24 +++++++++++++++++++++++-
> 2 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/rust/kernel/dma_buf.rs b/rust/kernel/dma_buf.rs
> index a66829afcd129..a2086918efd17 100644
> --- a/rust/kernel/dma_buf.rs
> +++ b/rust/kernel/dma_buf.rs
> @@ -20,7 +20,6 @@ unsafe impl Send for DmaBuf {}
> // SAFETY: `struct dma_buf` is thread-safe
> unsafe impl Sync for DmaBuf {}
> 
> -#[expect(unused)]
> impl DmaBuf {
>     /// Convert from a `*mut bindings::dma_buf` to a [`DmaBuf`].
>     ///
> diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs
> index 1ac25fc6d527b..75ffd5541e84c 100644
> --- a/rust/kernel/drm/gem/mod.rs
> +++ b/rust/kernel/drm/gem/mod.rs
> @@ -11,7 +11,7 @@
>     bindings, dma_buf,
>     drm::driver::{AllocImpl, AllocOps},
>     drm::{self, private::Sealed},
> -    error::{to_result, Result},
> +    error::{from_err_ptr, to_result, Result},
>     prelude::*,
>     types::{ARef, AlwaysRefCounted, Opaque},
> };
> @@ -225,6 +225,28 @@ fn lookup_handle<D, F, O>(file: &drm::File<F>, handle: u32) -> Result<ARef<Self>
>         Ok(unsafe { ARef::from_raw(obj.into()) })
>     }
> 
> +    /// Export a [`DmaBuf`] for this GEM object using the DRM prime helper library.
> +    ///
> +    /// `flags` should be a set of flags from [`fs::file::flags`](kernel::fs::file::flags).
> +    fn prime_export(&self, flags: u32) -> Result<DmaBuf<Self>> {
> +        // SAFETY: `as_raw()` always returns a valid pointer to an initialized `drm_gem_object`.
> +        let dma_ptr = unsafe { bindings::drm_gem_prime_export(self.as_raw(), flags as i32) };
> +
> +        // `drm_gem_prime_export()` returns either an error pointer, or a valid pointer to an
> +        // initialized `dma_buf` on success.
> +        let dma_ptr = from_err_ptr(dma_ptr)?;
> +
> +        // SAFETY:
> +        // - We checked that dma_ptr is not an error, so it must point to an initialized dma_buf
> +        // - We used drm_gem_prime_export(), so `dma_ptr` will remain valid until a call to
> +        //   `drm_gem_prime_release()` which we don't call here.
> +        let dma_buf = unsafe { dma_buf::DmaBuf::from_raw(dma_ptr) };
> +
> +        // INVARIANT: We used drm_gem_prime_export() to create this dma_buf, fulfilling the
> +        // invariant that this dma_buf came from a GEM object of type `Self`.
> +        Ok(DmaBuf(dma_buf.into(), PhantomData))
> +    }
> +
>     /// Creates an mmap offset to map the object from userspace.
>     fn create_mmap_offset(&self) -> Result<u64> {
>         // SAFETY: The arguments are valid per the type invariant.
> -- 
> 2.50.0
> 

Reviewed-by: Daniel Almeida <daniel.almeida@...labora.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ