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 08/10] rust: iommu: require a dma::Handle for IoPageTable::new()
Date: Sun, 29 Nov 2026 23:24:27 +0100 [thread overview]
Message-ID: <20261129222429.2380652-9-kernel@matt3o12.de> (raw)
In-Reply-To: <20261129222429.2380652-1-kernel@matt3o12.de>
The io-pgtable code DMA-maps its table pages for the device when the
tables are not walked coherently, which depends on the device's DMA
parameters.
Take a dma::Handle instead of the device in IoPageTable::new(), and
record in the type invariant that the device has been configured.
Convert Tyr, the only user.
Signed-off-by: Matteo Kloiber <kernel@matt3o12.de>
---
drivers/gpu/drm/tyr/mmu/address_space.rs | 2 +-
rust/kernel/iommu/pgtable.rs | 24 +++++++++++++-----------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs b/drivers/gpu/drm/tyr/mmu/address_space.rs
index de7dce8e9ee6..ed131b8a6b57 100644
--- a/drivers/gpu/drm/tyr/mmu/address_space.rs
+++ b/drivers/gpu/drm/tyr/mmu/address_space.rs
@@ -102,7 +102,7 @@ pub(crate) fn new<'a>(
coherent_walk: false,
};
- let page_table_init = IoPageTable::new(dma.device(), pt_config);
+ let page_table_init = IoPageTable::new(dma, pt_config);
try_pin_init!(Self {
as_seat: LockedBy::new(&mmu.as_manager, Seat::NoSeat),
diff --git a/rust/kernel/iommu/pgtable.rs b/rust/kernel/iommu/pgtable.rs
index 5f9b42ca92c2..78acef800011 100644
--- a/rust/kernel/iommu/pgtable.rs
+++ b/rust/kernel/iommu/pgtable.rs
@@ -12,10 +12,7 @@
use crate::{
alloc,
bindings,
- device::{
- Bound,
- Device, //
- },
+ dma,
error::to_result,
io::PhysAddr,
prelude::*, //
@@ -57,10 +54,11 @@ pub struct Config {
///
/// # Invariants
///
-/// The pointer references a valid io page table.
+/// The pointer references a valid io page table whose device's DMA parameters have been
+/// configured and remain unchanged for the lifetime of the page table.
pub struct IoPageTable<'a, F: IoPageTableFmt> {
ptr: NonNull<bindings::io_pgtable_ops>,
- _dev: PhantomData<&'a Device<Bound>>,
+ _dma: PhantomData<dma::Handle<'a>>,
_marker: PhantomData<F>,
}
@@ -77,8 +75,10 @@ pub trait IoPageTableFmt: 'static {
impl<'a, F: IoPageTableFmt> IoPageTable<'a, F> {
/// Create a new `IoPageTable`.
+ ///
+ /// Requires a configured DMA handle because non-coherent page tables may use DMA mappings.
#[inline]
- pub fn new(dev: &'a Device<Bound>, config: Config) -> Result<IoPageTable<'a, F>> {
+ pub fn new(dma: dma::Handle<'a>, config: Config) -> Result<IoPageTable<'a, F>> {
let mut raw_cfg = bindings::io_pgtable_cfg {
quirks: config.quirks,
pgsize_bitmap: config.pgsize_bitmap,
@@ -86,7 +86,7 @@ pub fn new(dev: &'a Device<Bound>, config: Config) -> Result<IoPageTable<'a, F>>
oas: config.oas,
coherent_walk: config.coherent_walk,
tlb: &raw const NOOP_FLUSH_OPS,
- iommu_dev: dev.as_raw(),
+ iommu_dev: dma.as_raw(),
..Zeroable::zeroed()
};
@@ -94,15 +94,17 @@ pub fn new(dev: &'a Device<Bound>, config: Config) -> Result<IoPageTable<'a, F>>
// * The raw_cfg pointer is valid for the duration of this call.
// * The provided `FLUSH_OPS` contains valid function pointers that accept a null pointer
// as cookie.
- // * The caller ensures that the io pgtable does not outlive the device.
+ // * The DMA handle ensures that the device is configured and remains bound for `'a`.
+ // The returned page table cannot outlive this lifetime.
let ops = unsafe {
bindings::alloc_io_pgtable_ops(F::FORMAT, &mut raw_cfg, core::ptr::null_mut())
};
- // INVARIANT: We successfully created a valid page table.
+ // INVARIANT: We successfully created a valid page table. The DMA handle guarantees
+ // that its device's parameters are configured and remain unchanged for `'a`.
Ok(IoPageTable {
ptr: NonNull::new(ops).ok_or(ENOMEM)?,
- _dev: PhantomData,
+ _dma: PhantomData,
_marker: PhantomData,
})
}
--
2.51.2
next 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 ` Matteo Kloiber [this message]
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 ` [RFC PATCH v2 10/10] rust: dma: remove the Device trait and its setters Matteo Kloiber
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-9-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®