From: Alice Ryhl <aliceryhl@google.com>
To: Daniel Almeida <daniel.almeida@collabora.com>,
Deborah Brouwer <deborah.brouwer@collabora.com>,
Sami Tolvanen <samitolvanen@google.com>
Cc: "Danilo Krummrich" <dakr@kernel.org>,
"Matthew Brost" <matthew.brost@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
"Will Deacon" <will@kernel.org>,
"Robin Murphy" <robin.murphy@arm.com>,
"Boris Brezillon" <boris.brezillon@collabora.com>,
dri-devel@lists.freedesktop.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
"Alice Ryhl" <aliceryhl@google.com>
Subject: [PATCH 2/4] rust: iommu: pgtable: add iova_to_phys
Date: Tue, 17 Nov 2026 19:32:19 +0000 [thread overview]
Message-ID: <20261117-tyr-remap-2mb-v1-2-2a8efd4c8180@google.com> (raw)
In-Reply-To: <20261117-tyr-remap-2mb-v1-0-2a8efd4c8180@google.com>
From: Sami Tolvanen <samitolvanen@google.com>
Tyr's VM_BIND remap path rebuilds the page-table mappings that a partial
unmap sweeps away, recovering their backing from the still-present
entries. Add IoPageTable::iova_to_phys(), which returns the physical
address that an iova maps to.
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
[aliceryhl: split into separate gpuvm and iommu commits]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
rust/kernel/iommu/pgtable.rs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/rust/kernel/iommu/pgtable.rs b/rust/kernel/iommu/pgtable.rs
index 5f9b42ca92c2..306c03862a72 100644
--- a/rust/kernel/iommu/pgtable.rs
+++ b/rust/kernel/iommu/pgtable.rs
@@ -199,6 +199,29 @@ pub unsafe fn unmap_pages(&self, iova: usize, pgsize: usize, pgcount: usize) ->
// SAFETY: The safety requirements of this method are sufficient to call `unmap_pages`.
unsafe { (unmap_pages)(self.raw_ops(), iova, pgsize, pgcount, core::ptr::null_mut()) }
}
+
+ /// Translate an `iova` to the physical address it maps to.
+ ///
+ /// Returns [`None`] if `iova` is not mapped. As in the underlying C op, a mapping to physical
+ /// address 0 is indistinguishable from unmapped and also reports [`None`]. The returned address
+ /// includes the offset of `iova` within the mapping block, so it is exact for any `iova`, not
+ /// just block-aligned ones. This walk is lock-free and does not allocate.
+ ///
+ /// # Safety
+ ///
+ /// No other io-pgtable operation may modify the entry covering `iova` while this walk
+ /// executes.
+ #[inline]
+ pub unsafe fn iova_to_phys(&self, iova: usize) -> Option<PhysAddr> {
+ // SAFETY: The `iova_to_phys` function in `io_pgtable_ops` is never null.
+ let iova_to_phys = unsafe { (*self.raw_ops()).iova_to_phys.unwrap_unchecked() };
+
+ // SAFETY: The safety requirements of this method are sufficient to call `iova_to_phys`.
+ let paddr = unsafe { (iova_to_phys)(self.raw_ops(), iova) };
+
+ // A zero return means `iova` is not mapped.
+ (paddr != 0).then_some(paddr)
+ }
}
// For the initial users of these rust bindings, the GPU FW is managing the IOTLB and performs all
--
2.56.1.703.gf848ed807c-goog
next prev parent reply other threads:[~2026-11-17 19:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 19:32 [PATCH 0/4] drm/tyr: fix partial 2MB block unmaps on GPUVM remap Alice Ryhl
2026-11-17 19:32 ` [PATCH 1/4] rust: drm/gpuvm: add GpuVa::data_ref accessor Alice Ryhl
2026-11-17 19:40 ` Danilo Krummrich
2026-11-17 19:32 ` Alice Ryhl [this message]
2026-11-17 19:32 ` [PATCH 3/4] drm/tyr: vm: expand sub-block unmaps to 2MB boundaries on remap Alice Ryhl
2026-11-17 19:32 ` [PATCH 4/4] drm/tyr: vm: check the remaining length in pt_unmap() Alice Ryhl
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=20261117-tyr-remap-2mb-v1-2-2a8efd4c8180@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=boris.brezillon@collabora.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=deborah.brouwer@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=matthew.brost@intel.com \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=tamird@kernel.org \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tmgross@umich.edu \
--cc=will@kernel.org \
--cc=work@onurozkan.dev \
/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®