From: Sami Tolvanen <[email protected]> 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 <[email protected]> [aliceryhl: split into separate gpuvm and iommu commits] Signed-off-by: Alice Ryhl <[email protected]> --- 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
