From: Matteo Kloiber <kernel@matt3o12.de>
To: Danilo Krummrich <dakr@kernel.org>,
Alexandre Courbot <acourbot@nvidia.com>,
Alice Ryhl <aliceryhl@google.com>,
Abdiel Janulgue <abdiel.janulgue@gmail.com>,
Robin Murphy <robin.murphy@arm.com>,
Andreas Hindborg <a.hindborg@kernel.org>,
Gary Guo <gary@garyguo.net>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev,
dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev,
linux-kernel@vger.kernel.org,
"Matteo Kloiber" <kernel@matt3o12.de>
Subject: [RFC PATCH v2 10/10] rust: dma: remove the Device trait and its setters
Date: Sun, 29 Nov 2026 23:24:29 +0100 [thread overview]
Message-ID: <20261129222429.2380652-11-kernel@matt3o12.de> (raw)
In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de>
All drivers configure DMA through dma::Setup now, and nothing calls the
unsafe dma::Device setters anymore. Keeping them would allow changing
the DMA parameters behind an existing dma::Handle.
Remove the trait, its PCI and platform implementations, and the
dma_set_mask_and_coherent() helper, which only the trait used.
With the setters gone, a driver can only change the DMA parameters
through its dma::Setup, and all Rust DMA APIs require the dma::Handle
that configure() returns. Update the safety comments of the PCI and
platform probe callbacks accordingly.
Signed-off-by: Matteo Kloiber <kernel@matt3o12.de>
---
rust/helpers/dma.c | 6 ---
rust/kernel/dma.rs | 83 +----------------------------------------
rust/kernel/pci.rs | 5 +--
rust/kernel/platform.rs | 5 +--
4 files changed, 5 insertions(+), 94 deletions(-)
diff --git a/rust/helpers/dma.c b/rust/helpers/dma.c
index ff8f24dae9df..443360237606 100644
--- a/rust/helpers/dma.c
+++ b/rust/helpers/dma.c
@@ -17,12 +17,6 @@ __rust_helper void rust_helper_dma_free_attrs(struct device *dev, size_t size,
dma_free_attrs(dev, size, cpu_addr, dma_handle, attrs);
}
-__rust_helper int rust_helper_dma_set_mask_and_coherent(struct device *dev,
- u64 mask)
-{
- return dma_set_mask_and_coherent(dev, mask);
-}
-
__rust_helper int rust_helper_dma_set_mask(struct device *dev, u64 mask)
{
return dma_set_mask(dev, mask);
diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index 226d00397f56..6b06f57bbdd2 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -9,8 +9,7 @@
debugfs,
device::{
self,
- Bound,
- Core, //
+ Bound, //
},
error::to_result,
fs::file,
@@ -178,86 +177,6 @@ pub(crate) fn new_for_test(dev: &'bound device::Device<Bound>) -> Self {
}
}
-/// Trait to be implemented by DMA capable bus devices.
-///
-/// The [`dma::Device`](Device) trait should be implemented by bus specific device representations,
-/// where the underlying bus is DMA capable, such as:
-#[cfg_attr(CONFIG_PCI, doc = "* [`pci::Device`](kernel::pci::Device)")]
-/// * [`platform::Device`](::kernel::platform::Device)
-pub trait Device<'a>: AsRef<device::Device<Core<'a>>> {
- /// Set up the device's DMA streaming addressing capabilities.
- ///
- /// This method is usually called once from `probe()` as soon as the device capabilities are
- /// known.
- ///
- /// # Safety
- ///
- /// This method must not be called concurrently with any DMA allocation or mapping primitives,
- /// such as [`Coherent::zeroed`].
- unsafe fn dma_set_mask(&self, mask: DmaMask) -> Result {
- // SAFETY:
- // - By the type invariant of `device::Device`, `self.as_ref().as_raw()` is valid.
- // - The safety requirement of this function guarantees that there are no concurrent calls
- // to DMA allocation and mapping primitives using this mask.
- to_result(unsafe { bindings::dma_set_mask(self.as_ref().as_raw(), mask.value()) })
- }
-
- /// Set up the device's DMA coherent addressing capabilities.
- ///
- /// This method is usually called once from `probe()` as soon as the device capabilities are
- /// known.
- ///
- /// # Safety
- ///
- /// This method must not be called concurrently with any DMA allocation or mapping primitives,
- /// such as [`Coherent::zeroed`].
- unsafe fn dma_set_coherent_mask(&self, mask: DmaMask) -> Result {
- // SAFETY:
- // - By the type invariant of `device::Device`, `self.as_ref().as_raw()` is valid.
- // - The safety requirement of this function guarantees that there are no concurrent calls
- // to DMA allocation and mapping primitives using this mask.
- to_result(unsafe { bindings::dma_set_coherent_mask(self.as_ref().as_raw(), mask.value()) })
- }
-
- /// Set up the device's DMA addressing capabilities.
- ///
- /// This is a combination of [`Device::dma_set_mask`] and [`Device::dma_set_coherent_mask`].
- ///
- /// This method is usually called once from `probe()` as soon as the device capabilities are
- /// known.
- ///
- /// # Safety
- ///
- /// This method must not be called concurrently with any DMA allocation or mapping primitives,
- /// such as [`Coherent::zeroed`].
- unsafe fn dma_set_mask_and_coherent(&self, mask: DmaMask) -> Result {
- // SAFETY:
- // - By the type invariant of `device::Device`, `self.as_ref().as_raw()` is valid.
- // - The safety requirement of this function guarantees that there are no concurrent calls
- // to DMA allocation and mapping primitives using this mask.
- to_result(unsafe {
- bindings::dma_set_mask_and_coherent(self.as_ref().as_raw(), mask.value())
- })
- }
-
- /// Set the maximum size of a single DMA segment the device may request.
- ///
- /// This method is usually called once from `probe()` as soon as the device capabilities are
- /// known.
- ///
- /// # Safety
- ///
- /// This method must not be called concurrently with any DMA allocation or mapping primitives,
- /// such as [`Coherent::zeroed`].
- unsafe fn dma_set_max_seg_size(&self, size: u32) {
- // SAFETY:
- // - By the type invariant of `device::Device`, `self.as_ref().as_raw()` is valid.
- // - The safety requirement of this function guarantees that there are no concurrent calls
- // to DMA allocation and mapping primitives using this parameter.
- unsafe { bindings::dma_set_max_seg_size(self.as_ref().as_raw(), size) }
- }
-}
-
/// A DMA mask that holds a bitmask with the lowest `n` bits set.
///
/// Use [`DmaMask::new`] or [`DmaMask::try_new`] to construct a value. Values
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 10b00b641dea..a98fbc252cd2 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -150,7 +150,8 @@ extern "C" fn probe_callback(
from_result(|| {
// SAFETY: The bus initializes the DMA parameters before probing. This is the only
// setup token issued for this binding, and no driver code has run for the binding
- // yet.
+ // yet. The driver cannot use the Rust DMA allocation or mapping APIs until it
+ // consumes the token, and has no other way to change the DMA parameters.
let dma = unsafe { dma::Setup::new(pdev.as_ref()) };
let data = T::probe(pdev, InitTokens { dma }, info);
@@ -839,8 +840,6 @@ unsafe impl<Ctx: device::DeviceContext> device::AsBusDevice<Ctx> for Device<Ctx>
kernel::impl_device_context_deref!(unsafe { Device });
kernel::impl_device_context_into_aref!(Device);
-impl<'a> crate::dma::Device<'a> for Device<device::Core<'a>> {}
-
// SAFETY: Instances of `Device` are always reference-counted.
unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
#[inline]
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index bdb2c5c09b21..a24114c212bf 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -107,7 +107,8 @@ extern "C" fn probe_callback(pdev: *mut bindings::platform_device) -> kernel::ff
from_result(|| {
// SAFETY: The bus initializes the DMA parameters before probing. This is the only
// setup token issued for this binding, and no driver code has run for the binding
- // yet.
+ // yet. The driver cannot use the Rust DMA allocation or mapping APIs until it
+ // consumes the token, and has no other way to change the DMA parameters.
let dma = unsafe { dma::Setup::new(pdev.as_ref()) };
let data = T::probe(pdev, InitTokens { dma }, info);
@@ -547,8 +548,6 @@ pub fn optional_irq_by_name(&self, name: &CStr) -> Result<IrqRequest<'_>> {
kernel::impl_device_context_deref!(unsafe { Device });
kernel::impl_device_context_into_aref!(Device);
-impl<'a> crate::dma::Device<'a> for Device<device::Core<'a>> {}
-
// SAFETY: Instances of `Device` are always reference-counted.
unsafe impl crate::sync::aref::AlwaysRefCounted for Device {
fn inc_ref(&self) {
--
2.51.2
prev parent reply other threads:[~2026-11-29 22:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 22:24 [RFC PATCH v2 00/10] rust: dma: require device configuration before DMA Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 01/10] rust: pci, platform: pass InitTokens to probe() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 02/10] rust: dma: add Setup, Params and Handle Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 03/10] gpu: nova-core: configure DMA through dma::Setup Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 04/10] drm/tyr: " Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 05/10] samples: rust: dma: " Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 06/10] rust: dma: require a Handle for coherent allocations Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 07/10] rust: scatterlist: require a dma::Handle for SGTable::new() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 08/10] rust: iommu: require a dma::Handle for IoPageTable::new() Matteo Kloiber
2026-11-29 22:24 ` [RFC PATCH v2 09/10] rust: drm: require a dma::Handle for shmem sg_table() Matteo Kloiber
2026-11-29 22:24 ` Matteo Kloiber [this message]
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=20261129222429.2380652-11-kernel@matt3o12.de \
--to=kernel@matt3o12.de \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
/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
all inboxes | Powered by JetHome®