From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21E0E224244; Thu, 4 Sep 2025 16:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757002631; cv=pass; b=ZjhIywkkEX2xB6scjYlmZ5ugYQAgy0M6BEklycaSYQ4Qn5c0HfSB4d+F28q+wpy29Da6SAi7V9x7OWrGRmLoOFwRfAo1OI4vBkNlO0GfPpw3ukV+MYA0JjGESKO1S/ESaGG5TJFIPltWkyAlvhD8aKNAJL7mEQR1y9M7VqTG7Vk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757002631; c=relaxed/simple; bh=vkNlwPsXCh03q4QvUN7xLznR2qq7bO1XsEL19DXw7jk=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=qtjV1xC/o53Bc40OYngSZ/nogywgHZwEXUduBFn/FldFfIh95UeSjjlOPNEEBeAvqnPo4eMSGd01eZmyEDvr0rmVAV+0oORf65BG1Flqe6qUmiLwgBxeWnMGV1rsqGCDDOsxn18uUmVk+M5G7y6mwnihpC0WxydZ5pvXV8IoOA4= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b=YnoKmLxf; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b="YnoKmLxf" ARC-Seal: i=1; a=rsa-sha256; t=1757002602; cv=none; d=zohomail.com; s=zohoarc; b=VHMYafhZFE2pstJbX0WhsvQVHtyyyFgCvVKQ3nO5Ilwy5s9+qiXR6/NDUee9kV/Xvm0I0whyov8yvtNAyNJtZBFfrbljwKTBHvYRJv3xvNzenqQ8WXYCgfbqJN/DDbVWqT9QFwCQ2d62Dwx1/Q6DJ8G5s2NyruqN9vF/JHoFzVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757002602; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=FIqcoPZSc1O3/JVIvRpHNLeM+xtMfjWtg6IHGtGPB9M=; b=VktHaoNE3ghG/Rp38dGH3zb2IAwEqWaLlhG9Cc6g9zkJfXNJj95tMUg7FHJRCFY+SH7OENHpmRFDAZJgFFKIP9XttaBJz+872H2rok1RlPOhRhZnfEf8ZVhPFOyja9qStx3i7rDOEeoFYI4WCUbxnw3tVr3EmrMDwaAQiM3Zwv8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=daniel.almeida@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1757002602; s=zohomail; d=collabora.com; i=daniel.almeida@collabora.com; h=Content-Type:Mime-Version:Subject:Subject:From:From:In-Reply-To:Date:Date:Cc:Cc:Content-Transfer-Encoding:Message-Id:Message-Id:References:To:To:Reply-To; bh=FIqcoPZSc1O3/JVIvRpHNLeM+xtMfjWtg6IHGtGPB9M=; b=YnoKmLxfdFea7bkc4g6zROBrQB6TPG/6gccwAfRJBqq63fbKnvn+XO0mwnkkEg0n nY9dly0GuhXtCrUhHj6SY1h4DSldODjdCbAFLnKuIitBP8/W8owMowpz3NyiZ1mrhXn rtxgaCn8cuE0HX6vquorJXulozUSTbc9dnxekLhg= Received: by mx.zohomail.com with SMTPS id 1757002600009698.7115522639169; Thu, 4 Sep 2025 09:16:40 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PATCH v3 12/14] rust: Add dma_buf stub bindings From: Daniel Almeida In-Reply-To: <20250829224116.477990-13-lyude@redhat.com> Date: Thu, 4 Sep 2025 13:16:22 -0300 Cc: dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Sumit Semwal , =?utf-8?Q?Christian_K=C3=B6nig?= , Greg Kroah-Hartman , Wedson Almeida Filho , Viresh Kumar , Tamir Duberstein , Xiangfei Ding , linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, "open list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b" ), "moderated list:DMA BUFFER SHARING FRAMEWORK:Keyword:bdma_(?:buf|fence|resv)b" ) Content-Transfer-Encoding: quoted-printable Message-Id: <88013821-0710-4B52-B622-3BAB429A6254@collabora.com> References: <20250829224116.477990-1-lyude@redhat.com> <20250829224116.477990-13-lyude@redhat.com> To: Lyude Paul X-Mailer: Apple Mail (2.3826.700.81) X-ZohoMailClient: External > On 29 Aug 2025, at 19:35, Lyude Paul wrote: >=20 > In order to implement the gem export callback, we need a type to = represent > struct dma_buf. So - this commit introduces a set of stub bindings for > dma_buf. These bindings provide a ref-counted DmaBuf object, but don't > currently implement any functionality for using the DmaBuf. >=20 > Signed-off-by: Lyude Paul >=20 > --- > V3: > * Rename as_ref() to from_raw() >=20 > Signed-off-by: Lyude Paul > --- > rust/kernel/dma_buf.rs | 40 ++++++++++++++++++++++++++++++++++++++++ > rust/kernel/lib.rs | 1 + > 2 files changed, 41 insertions(+) > create mode 100644 rust/kernel/dma_buf.rs >=20 > diff --git a/rust/kernel/dma_buf.rs b/rust/kernel/dma_buf.rs > new file mode 100644 > index 0000000000000..a66829afcd129 > --- /dev/null > +++ b/rust/kernel/dma_buf.rs > @@ -0,0 +1,40 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +//! DMA buffer API Missing period? > +//! > +//! C header: = [`include/linux/dma-buf.h`](srctree/include/linux/dma-buf.h) > + > +use bindings; > +use kernel::types::*; > + > +/// A DMA buffer object. > +/// > +/// # Invariants > +/// > +/// The data layout of this type is equivalent to that of `struct = dma_buf`. > +#[repr(transparent)] > +pub struct DmaBuf(Opaque); > + > +// SAFETY: `struct dma_buf` is thread-safe > +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`]. > + /// > + /// # Safety > + /// > + /// The caller guarantees that `self_ptr` points to a valid = initialized `struct dma_buf` for the > + /// duration of the lifetime of `'a`, and promises to not violate = rust's data aliasing rules > + /// using the reference provided by this function. > + pub(crate) unsafe fn from_raw<'a>(self_ptr: *mut = bindings::dma_buf) -> &'a Self { > + // SAFETY: Our data layout is equivalent to `dma_buf` . > + unsafe { &*self_ptr.cast() } > + } > + > + pub(crate) fn as_raw(&self) -> *mut bindings::dma_buf { > + self.0.get() > + } > +} > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index fcffc3988a903..59242d83efe21 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -81,6 +81,7 @@ > pub mod device_id; > pub mod devres; > pub mod dma; > +pub mod dma_buf; > pub mod driver; > #[cfg(CONFIG_DRM =3D "y")] > pub mod drm; > --=20 > 2.50.0 >=20 Reviewed-by: Daniel Almeida