From nobody Fri Oct 3 21:09:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5E36D207DE2; Mon, 25 Aug 2025 13:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128355; cv=none; b=gSVc7W1rVEDcfDxpWOa7YtNn3rLu4tcUmgbuwZCOJ4QplhDLr8BTa0YFt6LXCNBWpdLFDl3btT8gUbWE/L+pOGE21BGkI2pmXwnNBSAWiM1DTwlSyrEyxmF2O5iXl9nR8iFYRpVIXEXaPR1o5e1Cm2o6kin2BcdcFrthZ33pcA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128355; c=relaxed/simple; bh=6rhTOCn2Ximh5yl+dNj5WvB36g/GrWekZfjHfLEufqQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pdQqQCVMy4XAyB/WJEaAI3Dom7a7zVpWLeG0Ua7T0Kbkg3gzcWrEhdca6aE46YEcyBNYT1eJyDnDGgnmcqNu2japgGzJj8n9yvmy7fBinlw8l0btlNqNQirxycXV7ak5gBvdyNr2RtWfeF6YVtnR5+YqsE7n1iyF9IocdJsR02Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XNcw3K+z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XNcw3K+z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06B35C116C6; Mon, 25 Aug 2025 13:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756128354; bh=6rhTOCn2Ximh5yl+dNj5WvB36g/GrWekZfjHfLEufqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XNcw3K+zljCQQC6wKGh2XQPjwbsylElvtshPXrO4hdMqH4T+a6qwzzIyK4RqRVKJ7 Xx/m0fi9h867aQBMOykZJ8rMt+oTl4EuY0OxJnKAjVqPnq50diOPUEfpsnA7v7RtEx Ly6Jq/DToriTjC+fWS02cW/YmF98CA0oLJ9CAB2uzpbeN85zckRqk/RuTk7jZHcVtT QeLHiX8ZBNUq/fhmhMnzRNmWIBhz13iyC4CyMuXqiuK3SJgWRXUnsXtu1EV3wFpeFS c5mvBas1QnAb13618sUCCu2+I2IIn/tA/cPAdkyIvlHovp0G7aQj9OSnnD5C9PL74Q 0iirsgnq6CsWg== From: Danilo Krummrich To: akpm@linux-foundation.org, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, abdiel.janulgue@gmail.com, acourbot@nvidia.com, jgg@ziepe.ca, lyude@redhat.com, robin.murphy@arm.com, daniel.almeida@collabora.com Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH v3 1/5] rust: dma: implement DataDirection Date: Mon, 25 Aug 2025 15:24:40 +0200 Message-ID: <20250825132539.122412-2-dakr@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250825132539.122412-1-dakr@kernel.org> References: <20250825132539.122412-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the `DataDirection` struct, a newtype wrapper around the C `enum dma_data_direction`. This provides a type-safe Rust interface for specifying the direction of DMA transfers. Reviewed-by: Alice Ryhl Reviewed-by: Alexandre Courbot Signed-off-by: Danilo Krummrich Reviewed-by: Daniel Almeida Reviewed-by: Lyude Paul --- rust/bindings/bindings_helper.h | 1 + rust/kernel/dma.rs | 68 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helpe= r.h index 0e140e07758b..c2cc52ee9945 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs index 2bc8ab51ec28..27b25f041f32 100644 --- a/rust/kernel/dma.rs +++ b/rust/kernel/dma.rs @@ -244,6 +244,74 @@ pub mod attrs { pub const DMA_ATTR_PRIVILEGED: Attrs =3D Attrs(bindings::DMA_ATTR_PRIV= ILEGED); } =20 +/// DMA data direction. +/// +/// Corresponds to the C [`enum dma_data_direction`]. +/// +/// [`enum dma_data_direction`]: srctree/include/linux/dma-direction.h +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[repr(u32)] +pub enum DataDirection { + /// The DMA mapping is for bidirectional data transfer. + /// + /// This is used when the buffer can be both read from and written to = by the device. + /// The cache for the corresponding memory region is both flushed and = invalidated. + Bidirectional =3D Self::const_cast(bindings::dma_data_direction_DMA_BI= DIRECTIONAL), + + /// The DMA mapping is for data transfer from memory to the device (wr= ite). + /// + /// The CPU has prepared data in the buffer, and the device will read = it. + /// The cache for the corresponding memory region is flushed before de= vice access. + ToDevice =3D Self::const_cast(bindings::dma_data_direction_DMA_TO_DEVI= CE), + + /// The DMA mapping is for data transfer from the device to memory (re= ad). + /// + /// The device will write data into the buffer for the CPU to read. + /// The cache for the corresponding memory region is invalidated befor= e CPU access. + FromDevice =3D Self::const_cast(bindings::dma_data_direction_DMA_FROM_= DEVICE), + + /// The DMA mapping is not for data transfer. + /// + /// This is primarily for debugging purposes. With this direction, the= DMA mapping API + /// will not perform any cache coherency operations. + None =3D Self::const_cast(bindings::dma_data_direction_DMA_NONE), +} + +impl DataDirection { + /// Casts the bindgen-generated enum type to a `u32` at compile time. + /// + /// This function will cause a compile-time error if the underlying va= lue of the + /// C enum is out of bounds for `u32`. + const fn const_cast(val: bindings::dma_data_direction) -> u32 { + // CAST: The C standard allows compilers to choose different integ= er types for enums. + // To safely check the value, we cast it to a wide signed integer = type (`i128`) + // which can hold any standard C integer enum type without truncat= ion. + let wide_val =3D val as i128; + + // Check if the value is outside the valid range for the target ty= pe `u32`. + // CAST: `u32::MAX` is cast to `i128` to match the type of `wide_v= al` for the comparison. + if wide_val < 0 || wide_val > u32::MAX as i128 { + // Trigger a compile-time error in a const context. + build_error!("C enum value is out of bounds for the target typ= e `u32`."); + } + + // CAST: This cast is valid because the check above guarantees tha= t `wide_val` + // is within the representable range of `u32`. + wide_val as u32 + } +} + +impl From for bindings::dma_data_direction { + /// Returns the raw representation of [`enum dma_data_direction`]. + fn from(direction: DataDirection) -> Self { + // CAST: `direction as u32` gets the underlying representation of = our `#[repr(u32)]` enum. + // The subsequent cast to `Self` (the bindgen type) assumes the C = enum is compatible + // with the enum variants of `DataDirection`, which is a valid ass= umption given our + // compile-time checks. + direction as u32 as Self + } +} + /// An abstraction of the `dma_alloc_coherent` API. /// /// This is an abstraction around the `dma_alloc_coherent` API which is us= ed to allocate and map --=20 2.51.0 From nobody Fri Oct 3 21:09:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 998F6274FEF; Mon, 25 Aug 2025 13:25:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128358; cv=none; b=uT8DGaMWKffLLrXGrN9KnITlHJdyFOXmbJdKnbqoOPxr4VfEExzXFWka7FS4CK4FUkwd+5j3SfoEbWf/R1UCeylYpv2TWfEV3/9AKD8U8TpvrXuLTkTnYsLvzhNYVYqzmQj/vxrM68VWJXm6hZ8xBUjHCr5ghn2ZTZm/LrezsBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128358; c=relaxed/simple; bh=A3L0Nwe0/dbduzO9gX/IxMSFwYiKAMDTLYKwRVn49xc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VdyGI+Ja1NhlAU2v8BluNZU9fjbBaCwmSH7rJQkXePBppRanXR+EML6XXRYHMLY8GwVTTCIFUEYu5gHeoDjcBck2PD8z8jwAmGgvoydIouXMalGsqpIh23wgvccJoWr4hoIXWbzz/g8Zn0dKczfKrMCvkhoStsDlchbgTYAdLXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cVi/+NOa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cVi/+NOa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C543AC4CEED; Mon, 25 Aug 2025 13:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756128358; bh=A3L0Nwe0/dbduzO9gX/IxMSFwYiKAMDTLYKwRVn49xc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cVi/+NOaxUVCkFSRXU/63mm/BBVqoke+aWXYjTlNh34qBMGopiUcFyK3vWTizgrVr HLnrrdUuKVoJkfQl9EZpZPO4No0lZF3ToEmd6GoaBLEXvW51Xg9xWBfCTBxNvzJq04 5iGiceyrHGc3PqdxNKmy+VDBqkiVugAxLNjoHqRnFjiXTn/w7gopXzb33Xta/FytA+ D9OZdpZiM4cSDJVIBcW3+pAaQGFY6tiQ6Y+WvH8UXd4oCy61lm9hnYgDDE4fNrAulY JhrAJGbbVpMr9WXssnSiUynN+J7vVakORY+4I3qcmv4O5Q/NjdTSIl+UzeAauegu5d tgScsjdFuVdBA== From: Danilo Krummrich To: akpm@linux-foundation.org, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, abdiel.janulgue@gmail.com, acourbot@nvidia.com, jgg@ziepe.ca, lyude@redhat.com, robin.murphy@arm.com, daniel.almeida@collabora.com Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH v3 2/5] rust: dma: add type alias for bindings::dma_addr_t Date: Mon, 25 Aug 2025 15:24:41 +0200 Message-ID: <20250825132539.122412-3-dakr@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250825132539.122412-1-dakr@kernel.org> References: <20250825132539.122412-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a type alias for bindings::dma_addr_t (DmaAddress), such that we do not have to access bindings directly. Reviewed-by: Alice Ryhl Reviewed-by: Alexandre Courbot Suggested-by: Alice Ryhl Signed-off-by: Danilo Krummrich Reviewed-by: Daniel Almeida Reviewed-by: Lyude Paul --- drivers/gpu/nova-core/falcon.rs | 4 ++-- rust/kernel/dma.rs | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon= .rs index 50437c67c14a..aa36ed8c04ed 100644 --- a/drivers/gpu/nova-core/falcon.rs +++ b/drivers/gpu/nova-core/falcon.rs @@ -4,8 +4,8 @@ =20 use core::ops::Deref; use hal::FalconHal; -use kernel::bindings; use kernel::device; +use kernel::dma::DmaAddress; use kernel::prelude::*; use kernel::time::Delta; use kernel::types::ARef; @@ -443,7 +443,7 @@ fn dma_wr>( fw.dma_handle_with_offset(load_offsets.src_start as usize)= ?, ), }; - if dma_start % bindings::dma_addr_t::from(DMA_LEN) > 0 { + if dma_start % DmaAddress::from(DMA_LEN) > 0 { dev_err!( self.dev, "DMA transfer start addresses must be a multiple of {}", diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs index 27b25f041f32..b2a6282876da 100644 --- a/rust/kernel/dma.rs +++ b/rust/kernel/dma.rs @@ -13,6 +13,16 @@ types::ARef, }; =20 +/// DMA address type. +/// +/// Represents a bus address used for Direct Memory Access (DMA) operation= s. +/// +/// This is an alias of the kernel's `dma_addr_t`, which may be `u32` or `= u64` depending on +/// `CONFIG_ARCH_DMA_ADDR_T_64BIT`. +/// +/// Note that this may be `u64` even on 32-bit architectures. +pub type DmaAddress =3D bindings::dma_addr_t; + /// Trait to be implemented by DMA capable bus devices. /// /// The [`dma::Device`](Device) trait should be implemented by bus specifi= c device representations, @@ -343,7 +353,7 @@ fn from(direction: DataDirection) -> Self { // entire `CoherentAllocation` including the allocated memory itself. pub struct CoherentAllocation { dev: ARef, - dma_handle: bindings::dma_addr_t, + dma_handle: DmaAddress, count: usize, cpu_addr: *mut T, dma_attrs: Attrs, @@ -444,7 +454,7 @@ pub fn start_ptr_mut(&mut self) -> *mut T { =20 /// Returns a DMA handle which may be given to the device as the DMA a= ddress base of /// the region. - pub fn dma_handle(&self) -> bindings::dma_addr_t { + pub fn dma_handle(&self) -> DmaAddress { self.dma_handle } =20 @@ -452,13 +462,13 @@ pub fn dma_handle(&self) -> bindings::dma_addr_t { /// device as the DMA address base of the region. /// /// Returns `EINVAL` if `offset` is not within the bounds of the alloc= ation. - pub fn dma_handle_with_offset(&self, offset: usize) -> Result { + pub fn dma_handle_with_offset(&self, offset: usize) -> Result { if offset >=3D self.count { Err(EINVAL) } else { // INVARIANT: The type invariant of `Self` guarantees that `si= ze_of:: * count` fits // into a `usize`, and `offset` is inferior to `count`. - Ok(self.dma_handle + (offset * core::mem::size_of::()) as b= indings::dma_addr_t) + Ok(self.dma_handle + (offset * core::mem::size_of::()) as D= maAddress) } } =20 --=20 2.51.0 From nobody Fri Oct 3 21:09:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1659C273803; Mon, 25 Aug 2025 13:26:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128362; cv=none; b=BczddxA4esZV9vPSo0WieJuo0m+U49Zyekq2XLC1EGXehf+4U+bxePpU2PtC6aJoqWi6L8Gy6ljF3jeNXtitLFUTbXmRF6fNn271TQVdJg3AKcw/fI1qqRhk1pGyP0LJ8dCisYVF6tK0+RFVSTZSawZextdqpXpOxO2muPdb7o8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128362; c=relaxed/simple; bh=Gg5vS9fldVoRNzNIbY69DFkPnzVFbaRQhfyOKls2PCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nenwplQYm/GnUijiOLHykzgvhVjPXQXlwG98m1ipVg5WNkVkIgoa+dnW7BlD9SeeFOAKC87oM6eM26heFskNn/UdHgnN2jspgPc6Omb7Hi9jJctQKFco6VtkVy0ZslzOxdxAtzpVU6fVV8c4Hvolwu5cGRcXZOROCqZ+ZJTifGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=acSOaKNy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="acSOaKNy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D452C116D0; Mon, 25 Aug 2025 13:25:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756128361; bh=Gg5vS9fldVoRNzNIbY69DFkPnzVFbaRQhfyOKls2PCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=acSOaKNy40sKgOx3xbwjAgjINc1s7oybMSN3h4X3HRXLPmUEV4DvAXbxn3vrPZ0ST jw0+6EqEW4YsVelKblRwqJ9tvTPSdnTN08HDwqyMHJdV5XHuwCA3MzHZExUYLNPdhf NuvK8nrHm7EgpagwN3nXT64NyoMXNRscascHZadO0M7DuxjYeud0lpXVsuWFBnD2/6 p73T3SUb4wGkOtZInFJHj46uhc72bOWMehCuGEY5o7J3BF1drQ4ywaFQdmotnPk7UG XFiXgZr3hlu7T3HPDatcgANVfZb5H4YidE/H5edk7saVsLu3x7J4E4OinFb6e8HiuY XRSZQ6WyqA+zQ== From: Danilo Krummrich To: akpm@linux-foundation.org, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, abdiel.janulgue@gmail.com, acourbot@nvidia.com, jgg@ziepe.ca, lyude@redhat.com, robin.murphy@arm.com, daniel.almeida@collabora.com Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH v3 3/5] rust: scatterlist: Add abstraction for sg_table Date: Mon, 25 Aug 2025 15:24:42 +0200 Message-ID: <20250825132539.122412-4-dakr@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250825132539.122412-1-dakr@kernel.org> References: <20250825132539.122412-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a safe Rust abstraction for the kernel's scatter-gather list facilities (`struct scatterlist` and `struct sg_table`). This commit introduces `SGTable`, a wrapper that uses a generic parameter to provide compile-time guarantees about ownership and lifetime. The abstraction provides two primary states: - `SGTable>`: Represents a table whose resources are fully managed by Rust. It takes ownership of a page provider `P`, allocates the underlying `struct sg_table`, maps it for DMA, and handles all cleanup automatically upon drop. The DMA mapping's lifetime is tied to the associated device using `Devres`, ensuring it is correctly unmapped before the device is unbound. - `SGTable` (or just `SGTable`): A zero-cost representation of an externally managed `struct sg_table`. It is created from a raw pointer using `SGTable::as_ref()` and provides a lifetime-bound reference (`&'a SGTable`) for operations like iteration. The API exposes a safe iterator that yields `&SGEntry` references, allowing drivers to easily access the DMA address and length of each segment in the list. Co-developed-by: Abdiel Janulgue Signed-off-by: Abdiel Janulgue Signed-off-by: Danilo Krummrich Reviewed-by: Alexandre Courbot Reviewed-by: Alice Ryhl Reviewed-by: Daniel Almeida Reviewed-by: Lyude Paul Tested-by: Alexandre Courbot --- rust/helpers/helpers.c | 1 + rust/helpers/scatterlist.c | 24 ++ rust/kernel/lib.rs | 1 + rust/kernel/scatterlist.rs | 483 +++++++++++++++++++++++++++++++++++++ 4 files changed, 509 insertions(+) create mode 100644 rust/helpers/scatterlist.c create mode 100644 rust/kernel/scatterlist.rs diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c index 7cf7fe95e41d..e94542bf6ea7 100644 --- a/rust/helpers/helpers.c +++ b/rust/helpers/helpers.c @@ -39,6 +39,7 @@ #include "rcu.c" #include "refcount.c" #include "regulator.c" +#include "scatterlist.c" #include "security.c" #include "signal.c" #include "slab.c" diff --git a/rust/helpers/scatterlist.c b/rust/helpers/scatterlist.c new file mode 100644 index 000000000000..80c956ee09ab --- /dev/null +++ b/rust/helpers/scatterlist.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +dma_addr_t rust_helper_sg_dma_address(struct scatterlist *sg) +{ + return sg_dma_address(sg); +} + +unsigned int rust_helper_sg_dma_len(struct scatterlist *sg) +{ + return sg_dma_len(sg); +} + +struct scatterlist *rust_helper_sg_next(struct scatterlist *sg) +{ + return sg_next(sg); +} + +void rust_helper_dma_unmap_sgtable(struct device *dev, struct sg_table *sg= t, + enum dma_data_direction dir, unsigned long attrs) +{ + return dma_unmap_sgtable(dev, sgt, dir, attrs); +} diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index ed53169e795c..55acbc893736 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -113,6 +113,7 @@ pub mod rbtree; pub mod regulator; pub mod revocable; +pub mod scatterlist; pub mod security; pub mod seq_file; pub mod sizes; diff --git a/rust/kernel/scatterlist.rs b/rust/kernel/scatterlist.rs new file mode 100644 index 000000000000..e76e5c2cbdc7 --- /dev/null +++ b/rust/kernel/scatterlist.rs @@ -0,0 +1,483 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Abstractions for scatter-gather lists. +//! +//! C header: [`include/linux/scatterlist.h`](srctree/include/linux/scatte= rlist.h) +//! +//! Scatter-gather (SG) I/O is a memory access technique that allows devic= es to perform DMA +//! operations on data buffers that are not physically contiguous in memor= y. It works by creating a +//! "scatter-gather list", an array where each entry specifies the address= and length of a +//! physically contiguous memory segment. +//! +//! The device's DMA controller can then read this list and process the se= gments sequentially as +//! part of one logical I/O request. This avoids the need for a single, la= rge, physically contiguous +//! memory buffer, which can be difficult or impossible to allocate. +//! +//! This module provides safe Rust abstractions over the kernel's `struct = scatterlist` and +//! `struct sg_table` types. +//! +//! The main entry point is the [`SGTable`] type, which represents a compl= ete scatter-gather table. +//! It can be either: +//! +//! - An owned table ([`SGTable>`]), created from a Rust memory b= uffer (e.g., [`VVec`]). +//! This type manages the allocation of the `struct sg_table`, the DMA m= apping of the buffer, and +//! the automatic cleanup of all resources. +//! - A borrowed reference (&[`SGTable`]), which provides safe, read-only = access to a table that was +//! allocated by other (e.g., C) code. +//! +//! Individual entries in the table are represented by [`SGEntry`], which = can be accessed by +//! iterating over an [`SGTable`]. + +use crate::{ + alloc, + alloc::allocator::VmallocPageIter, + bindings, + device::{Bound, Device}, + devres::Devres, + dma, error, + io::resource::ResourceSize, + page, + prelude::*, + types::{ARef, Opaque}, +}; +use core::{ops::Deref, ptr::NonNull}; + +/// A single entry in a scatter-gather list. +/// +/// An `SGEntry` represents a single, physically contiguous segment of mem= ory that has been mapped +/// for DMA. +/// +/// Instances of this struct are obtained by iterating over an [`SGTable`]= . Drivers do not create +/// or own [`SGEntry`] objects directly. +#[repr(transparent)] +pub struct SGEntry(Opaque); + +// SAFETY: `SGEntry` can be send to any task. +unsafe impl Send for SGEntry {} + +// SAFETY: `SGEntry` can be accessed concurrently. +unsafe impl Sync for SGEntry {} + +impl SGEntry { + /// Convert a raw `struct scatterlist *` to a `&'a SGEntry`. + /// + /// # Safety + /// + /// Callers must ensure that the `struct scatterlist` pointed to by `p= tr` is valid for the + /// lifetime `'a`. + #[inline] + unsafe fn from_raw<'a>(ptr: *mut bindings::scatterlist) -> &'a Self { + // SAFETY: The safety requirements of this function guarantee that= `ptr` is a valid pointer + // to a `struct scatterlist` for the duration of `'a`. + unsafe { &*ptr.cast() } + } + + /// Obtain the raw `struct scatterlist *`. + #[inline] + fn as_raw(&self) -> *mut bindings::scatterlist { + self.0.get() + } + + /// Returns the DMA address of this SG entry. + /// + /// This is the address that the device should use to access the memor= y segment. + #[inline] + pub fn dma_address(&self) -> dma::DmaAddress { + // SAFETY: `self.as_raw()` is a valid pointer to a `struct scatter= list`. + unsafe { bindings::sg_dma_address(self.as_raw()) } + } + + /// Returns the length of this SG entry in bytes. + #[inline] + pub fn dma_len(&self) -> ResourceSize { + #[allow(clippy::useless_conversion)] + // SAFETY: `self.as_raw()` is a valid pointer to a `struct scatter= list`. + unsafe { bindings::sg_dma_len(self.as_raw()) }.into() + } +} + +/// The borrowed type state of an [`SGTable`], representing a borrowed or = externally managed table. +#[repr(transparent)] +pub struct Borrowed(Opaque); + +// SAFETY: `Borrowed` can be send to any task. +unsafe impl Send for Borrowed {} + +// SAFETY: `Borrowed` can be accessed concurrently. +unsafe impl Sync for Borrowed {} + +/// A scatter-gather table. +/// +/// This struct is a wrapper around the kernel's `struct sg_table`. It man= ages a list of DMA-mapped +/// memory segments that can be passed to a device for I/O operations. +/// +/// The generic parameter `T` is used as a type state to distinguish betwe= en owned and borrowed +/// tables. +/// +/// - [`SGTable`]: An owned table created and managed entirely by = Rust code. It handles +/// allocation, DMA mapping, and cleanup of all associated resources. S= ee [`SGTable::new`]. +/// - [`SGTable`} (or simply [`SGTable`]): Represents a table w= hose lifetime is managed +/// externally. It can be used safely via a borrowed reference `&'a SGT= able`, where `'a` is the +/// external lifetime. +/// +/// All [`SGTable`] variants can be iterated over the individual [`SGEntry= `]s. +#[repr(transparent)] +#[pin_data] +pub struct SGTable { + #[pin] + inner: T, +} + +impl SGTable { + /// Creates a borrowed `&'a SGTable` from a raw `struct sg_table` poin= ter. + /// + /// This allows safe access to an `sg_table` that is managed elsewhere= (for example, in C code). + /// + /// # Safety + /// + /// Callers must ensure that: + /// + /// - the `struct sg_table` pointed to by `ptr` is valid for the entir= e lifetime of `'a`, + /// - the data behind `ptr` is not modified concurrently for the durat= ion of `'a`. + #[inline] + pub unsafe fn from_raw<'a>(ptr: *mut bindings::sg_table) -> &'a Self { + // SAFETY: The safety requirements of this function guarantee that= `ptr` is a valid pointer + // to a `struct sg_table` for the duration of `'a`. + unsafe { &*ptr.cast() } + } + + #[inline] + fn as_raw(&self) -> *mut bindings::sg_table { + self.inner.0.get() + } + + /// Returns an [`SGTableIter`] bound to the lifetime of `self`. + pub fn iter(&self) -> SGTableIter<'_> { + // SAFETY: `self.as_raw()` is a valid pointer to a `struct sg_tabl= e`. + let nents =3D unsafe { (*self.as_raw()).nents }; + + let pos =3D if nents > 0 { + // SAFETY: `self.as_raw()` is a valid pointer to a `struct sg_= table`. + let ptr =3D unsafe { (*self.as_raw()).sgl }; + + // SAFETY: `ptr` is guaranteed to be a valid pointer to a `str= uct scatterlist`. + Some(unsafe { SGEntry::from_raw(ptr) }) + } else { + None + }; + + SGTableIter { pos, nents } + } +} + +/// Represents the DMA mapping state of a `struct sg_table`. +/// +/// This is used as an inner type of [`Owned`] to manage the DMA mapping l= ifecycle. +/// +/// # Invariants +/// +/// - `sgt` is a valid pointer to a `struct sg_table` for the entire lifet= ime of the +/// [`DmaMappedSgt`]. +/// - `sgt` is always DMA mapped. +struct DmaMappedSgt { + sgt: NonNull, + dev: ARef, + dir: dma::DataDirection, +} + +// SAFETY: `DmaMappedSgt` can be send to any task. +unsafe impl Send for DmaMappedSgt {} + +// SAFETY: `DmaMappedSgt` can be accessed concurrently. +unsafe impl Sync for DmaMappedSgt {} + +impl DmaMappedSgt { + /// # Safety + /// + /// - `sgt` must be a valid pointer to a `struct sg_table` for the ent= ire lifetime of the + /// returned [`DmaMappedSgt`]. + /// - The caller must guarantee that `sgt` remains DMA mapped for the = entire lifetime of + /// [`DmaMappedSgt`]. + unsafe fn new( + sgt: NonNull, + dev: &Device, + dir: dma::DataDirection, + ) -> Result { + // SAFETY: + // - `dev.as_raw()` is a valid pointer to a `struct device`, which= is guaranteed to be + // bound to a driver for the duration of this call. + // - `sgt` is a valid pointer to a `struct sg_table`. + error::to_result(unsafe { + bindings::dma_map_sgtable(dev.as_raw(), sgt.as_ptr(), dir.into= (), 0) + })?; + + // INVARIANT: By the safety requirements of this function it is gu= aranteed that `sgt` is + // valid for the entire lifetime of this object instance. + Ok(Self { + sgt, + dev: dev.into(), + dir, + }) + } +} + +impl Drop for DmaMappedSgt { + #[inline] + fn drop(&mut self) { + // SAFETY: + // - `self.dev.as_raw()` is a pointer to a valid `struct device`. + // - `self.dev` is the same device the mapping has been created fo= r in `Self::new()`. + // - `self.sgt.as_ptr()` is a valid pointer to a `struct sg_table`= by the type invariants + // of `Self`. + // - `self.dir` is the same `dma::DataDirection` the mapping has b= een created with in + // `Self::new()`. + unsafe { + bindings::dma_unmap_sgtable(self.dev.as_raw(), self.sgt.as_ptr= (), self.dir.into(), 0) + }; + } +} + +#[repr(transparent)] +#[pin_data(PinnedDrop)] +struct RawSGTable { + #[pin] + sgt: Opaque, +} + +// SAFETY: `RawSGTable` can be send to any task. +unsafe impl Send for RawSGTable {} + +// SAFETY: `RawSGTable` can be accessed concurrently. +unsafe impl Sync for RawSGTable {} + +impl RawSGTable { + fn new( + pages: &mut [*mut bindings::page], + size: usize, + max_segment: u32, + flags: alloc::Flags, + ) -> impl PinInit + '_ { + try_pin_init!(Self { + sgt <- Opaque::try_ffi_init(|slot: *mut bindings::sg_table| { + // `sg_alloc_table_from_pages_segment()` expects at least = one page, otherwise it + // produces a NPE. + if pages.is_empty() { + return Err(EINVAL); + } + + // SAFETY: + // - `slot` is a valid pointer to uninitialized memory. + // - As by the check above, `pages` is not empty. + error::to_result(unsafe { + bindings::sg_alloc_table_from_pages_segment( + slot, + pages.as_mut_ptr(), + pages.len().try_into()?, + 0, + size, + max_segment, + flags.as_raw(), + ) + }) + }), + }) + } + + #[inline] + fn as_raw(&self) -> *mut bindings::sg_table { + self.sgt.get() + } +} + +#[pinned_drop] +impl PinnedDrop for RawSGTable { + #[inline] + fn drop(self: Pin<&mut Self>) { + // SAFETY: `sgt` is a valid and initialized `struct sg_table`. + unsafe { bindings::sg_free_table(self.sgt.get()) }; + } +} + +/// The [`Owned`] type state of an [`SGTable`]. +/// +/// A [`SGTable`] signifies that the [`SGTable`] owns all associate= d resources: +/// +/// - The backing memory pages. +/// - The `struct sg_table` allocation (`sgt`). +/// - The DMA mapping, managed through a [`Devres`]-managed `DmaMappedSgt`. +/// +/// Users interact with this type through the [`SGTable`] handle and do no= t need to manage +/// [`Owned`] directly. +#[pin_data] +pub struct Owned

{ + // Note: The drop order is relevant; we first have to unmap the `struc= t sg_table`, then free the + // `struct sg_table` and finally free the backing pages. + #[pin] + dma: Devres, + #[pin] + sgt: RawSGTable, + _pages: P, +} + +// SAFETY: `Owned` can be send to any task if `P` can be send to any task. +unsafe impl Send for Owned

{} + +// SAFETY: `Owned` can be accessed concurrently if `P` can be accessed con= currently. +unsafe impl Sync for Owned

{} + +impl

Owned

+where + for<'a> P: page::AsPageIter =3D VmallocPageIter<'a>> + 'stati= c, +{ + fn new( + dev: &Device, + mut pages: P, + dir: dma::DataDirection, + flags: alloc::Flags, + ) -> Result + '_> { + let page_iter =3D pages.page_iter(); + let size =3D page_iter.size(); + + let mut page_vec: KVec<*mut bindings::page> =3D + KVec::with_capacity(page_iter.page_count(), flags)?; + + for page in page_iter { + page_vec.push(page.as_ptr(), flags)?; + } + + // `dma_max_mapping_size` returns `size_t`, but `sg_alloc_table_fr= om_pages_segment()` takes + // an `unsigned int`. + // + // SAFETY: `dev.as_raw()` is a valid pointer to a `struct device`. + let max_segment =3D match unsafe { bindings::dma_max_mapping_size(= dev.as_raw()) } { + 0 =3D> u32::MAX, + max_segment =3D> u32::try_from(max_segment).unwrap_or(u32::MAX= ), + }; + + Ok(try_pin_init!(&this in Self { + sgt <- RawSGTable::new(&mut page_vec, size, max_segment, flags= ), + dma <- { + // SAFETY: `this` is a valid pointer to uninitialized memo= ry. + let sgt =3D unsafe { &raw mut (*this.as_ptr()).sgt }.cast(= ); + + // SAFETY: `sgt` is guaranteed to be non-null. + let sgt =3D unsafe { NonNull::new_unchecked(sgt) }; + + // SAFETY: + // - It is guaranteed that the object returned by `DmaMapp= edSgt::new` won't out-live + // `sgt`. + // - `sgt` is never DMA unmapped manually. + Devres::new(dev, unsafe { DmaMappedSgt::new(sgt, dev, dir)= }) + }, + _pages: pages, + })) + } +} + +impl

SGTable> +where + for<'a> P: page::AsPageIter =3D VmallocPageIter<'a>> + 'stati= c, +{ + /// Allocates a new scatter-gather table from the given pages and maps= it for DMA. + /// + /// This constructor creates a new [`SGTable`] that takes owner= ship of `P`. + /// It allocates a `struct sg_table`, populates it with entries corres= ponding to the physical + /// pages of `P`, and maps the table for DMA with the specified [`Devi= ce`] and + /// [`dma::DataDirection`]. + /// + /// The DMA mapping is managed through [`Devres`], ensuring that the D= MA mapping is unmapped + /// once the associated [`Device`] is unbound, or when the [`SGTable`] is dropped. + /// + /// # Parameters + /// + /// * `dev`: The [`Device`] that will be performing the DMA. + /// * `pages`: The entity providing the backing pages. It must impleme= nt [`page::AsPageIter`]. + /// The ownership of this entity is moved into the new [`SGTable`]. + /// * `dir`: The [`dma::DataDirection`] of the DMA transfer. + /// * `flags`: Allocation flags for internal allocations (e.g., [`GFP_= KERNEL`]). + /// + /// # Examples + /// + /// ``` + /// use kernel::{ + /// device::{Bound, Device}, + /// dma, page, + /// prelude::*, + /// scatterlist::{SGTable, Owned}, + /// }; + /// + /// fn test(dev: &Device) -> Result { + /// let size =3D 4 * page::PAGE_SIZE; + /// let pages =3D VVec::::with_capacity(size, GFP_KERNEL)?; + /// + /// let sgt =3D KBox::pin_init(SGTable::new( + /// dev, + /// pages, + /// dma::DataDirection::ToDevice, + /// GFP_KERNEL, + /// ), GFP_KERNEL)?; + /// + /// Ok(()) + /// } + /// ``` + pub fn new( + dev: &Device, + pages: P, + dir: dma::DataDirection, + flags: alloc::Flags, + ) -> impl PinInit + '_ { + try_pin_init!(Self { + inner <- Owned::new(dev, pages, dir, flags)? + }) + } +} + +impl

Deref for SGTable> { + type Target =3D SGTable; + + #[inline] + fn deref(&self) -> &Self::Target { + // SAFETY: + // - `self.inner.sgt.as_raw()` is a valid pointer to a `struct sg_= table` for the entire + // lifetime of `self`. + // - The backing `struct sg_table` is not modified for the entire = lifetime of `self`. + unsafe { SGTable::from_raw(self.inner.sgt.as_raw()) } + } +} + +mod private { + pub trait Sealed {} + + impl Sealed for super::Borrowed {} + impl

Sealed for super::Owned

{} +} + +/// An [`Iterator`] over the DMA mapped [`SGEntry`] items of an [`SGTable`= ]. +/// +/// Note that the existence of an [`SGTableIter`] does not guarantee that = the [`SGEntry`] items +/// actually remain DMA mapped; they are prone to be unmapped on device un= bind. +pub struct SGTableIter<'a> { + pos: Option<&'a SGEntry>, + /// The number of DMA mapped entries in a `struct sg_table`. + nents: c_uint, +} + +impl<'a> Iterator for SGTableIter<'a> { + type Item =3D &'a SGEntry; + + fn next(&mut self) -> Option { + let entry =3D self.pos?; + self.nents =3D self.nents.saturating_sub(1); + + // SAFETY: `entry.as_raw()` is a valid pointer to a `struct scatte= rlist`. + let next =3D unsafe { bindings::sg_next(entry.as_raw()) }; + + self.pos =3D (!next.is_null() && self.nents > 0).then(|| { + // SAFETY: If `next` is not NULL, `sg_next()` guarantees to re= turn a valid pointer to + // the next `struct scatterlist`. + unsafe { SGEntry::from_raw(next) } + }); + + Some(entry) + } +} --=20 2.51.0 From nobody Fri Oct 3 21:09:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 427BE277CAF; Mon, 25 Aug 2025 13:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128366; cv=none; b=rdMpHcG5AbEtJAVmHEgfiD8QozRD/hEScm8EqRft+JDQOmH7yO7QBMJVCzuYgvfNRPg9KCf85pnC0Yb8LRlC9fdftZzsNXQK31MtIGFWfpscmkEC0s8SepfUqNjHgufBc3JJO4Cf8SgQgA/zf3AMGMYz6HjkF/Bll3KIdJMeAYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128366; c=relaxed/simple; bh=SJh5t8S3nGrnslvyfeBojfqqKV9PCASWSn3mgBhpZZY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qCC3AqtM4fssnnp2VymJZtn9kWm3R7YoGsdIgOSs1c0QijaAftMEzaY479o/62Ev8rlfOEomQpDnES9/jZ/BcE7264IVT+04M2tLNlSFoXO0e34xaGVMsxU9IDfjtTVChl+/SuuBX/Ky04AK8wZjog3HEAtYVUrweOQyF1cQPOw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fZyi7xes; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fZyi7xes" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AFB0C113D0; Mon, 25 Aug 2025 13:26:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756128365; bh=SJh5t8S3nGrnslvyfeBojfqqKV9PCASWSn3mgBhpZZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fZyi7xes+Bcn7ilguHlnSH6ReNnQ4aLB6OVj7qoUxc8XTAx/GH5sWAJozC4+U/SoT 2fQJYdhbQYnxVcIqZE0XRGZEzzuPA5z4ukT+LgEJV93eajJeLJIk6WJa0tnPMs0ARo 94d6wET5Sh3C21+SeUrTwUcc2N9PjM2HzGUQqfGhnK+gOcmwCC1QB22pQoPynbJItt NHvQvsYyHVagPHROFBbNZa27gVEam4IAjIfHZ00vn2uH5+RWfV7NvgeavRLmtOanls M7v1T0awdrSQzJZ98F3SK34QYpOcBcxt9fbROFscILn72PaQSqLtO0I4rLT/yyNwdC nB3FZphU1WsEw== From: Danilo Krummrich To: akpm@linux-foundation.org, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, abdiel.janulgue@gmail.com, acourbot@nvidia.com, jgg@ziepe.ca, lyude@redhat.com, robin.murphy@arm.com, daniel.almeida@collabora.com Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH v3 4/5] samples: rust: dma: add sample code for SGTable Date: Mon, 25 Aug 2025 15:24:43 +0200 Message-ID: <20250825132539.122412-5-dakr@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250825132539.122412-1-dakr@kernel.org> References: <20250825132539.122412-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add sample code for allocating and mapping a scatter-gather table (`SGTable`). Co-developed-by: Abdiel Janulgue Signed-off-by: Abdiel Janulgue Signed-off-by: Danilo Krummrich Reviewed-by: Alexandre Courbot Reviewed-by: Daniel Almeida Reviewed-by: Lyude Paul --- samples/rust/rust_dma.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index c5e7cce68654..04007e29fd85 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -7,15 +7,19 @@ use kernel::{ bindings, device::Core, - dma::{CoherentAllocation, Device, DmaMask}, - pci, + dma::{CoherentAllocation, DataDirection, Device, DmaMask}, + page, pci, prelude::*, + scatterlist::{Owned, SGTable}, types::ARef, }; =20 +#[pin_data(PinnedDrop)] struct DmaSampleDriver { pdev: ARef, ca: CoherentAllocation, + #[pin] + sgt: SGTable>>, } =20 const TEST_VALUES: [(u32, u32); 5] =3D [ @@ -70,21 +74,30 @@ fn probe(pdev: &pci::Device, _info: &Self::IdInfo= ) -> Result) { + let dev =3D self.pdev.as_ref(); + + dev_info!(dev, "Unload DMA test driver.\n"); =20 for (i, value) in TEST_VALUES.into_iter().enumerate() { let val0 =3D kernel::dma_read!(self.ca[i].h); @@ -99,6 +112,10 @@ fn drop(&mut self) { assert_eq!(val1, value.1); } } + + for (i, entry) in self.sgt.iter().enumerate() { + dev_info!(dev, "Entry[{}]: DMA address: {:#x}", i, entry.dma_a= ddress()); + } } } =20 --=20 2.51.0 From nobody Fri Oct 3 21:09:18 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 04AD0274FDE; Mon, 25 Aug 2025 13:26:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128370; cv=none; b=K87sszUygQmUs4c1wIRx1O17Y+M7gUT8fXziHRs4AEvA0hqnl8CP4UGhMTIFXPtCGgraK62Z5Yxm1caEf1nILQErqmt1j6ZUVZCzLPMaxFNPXC0/v/kMsDLFaZJ1ekuyH6ohB8t73sWT+t4Gqev5wdn3wgx+kHPyY1/mhuu9hoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756128370; c=relaxed/simple; bh=E4wCK0TZxjppsY8JGUrvDL9UhfW0ST7KROT2/IHhT2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JIMflJh/36F7kFlHHSWkK0YhzTI7L4ics3xRXN56SuygSj5/K9zyaZOF5Gybv19ZoDkHy9go4V4UTxEwG8Fp1XekYbS5GKYTRTkun3lG/wGbz2QaTNUm8GWEY9gtQ4ssnYRhYhLGqC3MtN/BQwS7QSasmK8agppAWwkPal/7yvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=THoeUpgC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="THoeUpgC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 255D9C116C6; Mon, 25 Aug 2025 13:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756128369; bh=E4wCK0TZxjppsY8JGUrvDL9UhfW0ST7KROT2/IHhT2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=THoeUpgC3Ho2A4YS5B5v7efx2bFN5X2GlW/nKbGKeIQdK8C/FBG4pkdLT+76z/hIB I4SX31T4vAr5GpDpsyMN9avkznyKCAKl3mQXEDVTam6YXGb1oqpqRzbOXwTJI8chQr v08XVmJqNN/6w89n1Q7xWUR8C/3B5a/TsvOKkoe8cjHEIvPIJNxuR2dsnbTcJsL129 zcL/LN9UHyctZ+POfEQMr/QWh20rrzDMoclSLNxvZexRyGHo0Hio23DSAe0e6X54Jm l6zgeLR1Y5rc+SUPn5hvNuFek5lK3zbWCP9h0VdsUdODHLlPmzOilw3jUSia16s7IZ RfNahSmH8uggw== From: Danilo Krummrich To: akpm@linux-foundation.org, ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, abdiel.janulgue@gmail.com, acourbot@nvidia.com, jgg@ziepe.ca, lyude@redhat.com, robin.murphy@arm.com, daniel.almeida@collabora.com Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Danilo Krummrich Subject: [PATCH v3 5/5] MAINTAINERS: rust: dma: add scatterlist files Date: Mon, 25 Aug 2025 15:24:44 +0200 Message-ID: <20250825132539.122412-6-dakr@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250825132539.122412-1-dakr@kernel.org> References: <20250825132539.122412-1-dakr@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename the "DMA MAPPING HELPERS DEVICE DRIVER API [RUST]" maintainers entry to "DMA MAPPING & SCATTERLIST API [RUST]" and add the corresponding scatterlist files. Signed-off-by: Danilo Krummrich Acked-by: Miguel Ojeda Reviewed-by: Lyude Paul --- MAINTAINERS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index fe168477caa4..65f676b2c304 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7238,7 +7238,7 @@ F: include/linux/dma-mapping.h F: include/linux/swiotlb.h F: kernel/dma/ =20 -DMA MAPPING HELPERS DEVICE DRIVER API [RUST] +DMA MAPPING & SCATTERLIST API [RUST] M: Abdiel Janulgue M: Danilo Krummrich R: Daniel Almeida @@ -7249,7 +7249,9 @@ S: Supported W: https://rust-for-linux.com T: git https://github.com/Rust-for-Linux/linux.git alloc-next F: rust/helpers/dma.c +F: rust/helpers/scatterlist.c F: rust/kernel/dma.rs +F: rust/kernel/scatterlist.rs F: samples/rust/rust_dma.rs =20 DMA-BUF HEAPS FRAMEWORK --=20 2.51.0