io: add io_pgtable abstraction
Subsystems (3)
Alice Ryhl
maintainerPATCH v5 1/1 io: add io_pgtable abstraction
From: Asahi Lina <[email protected]>
This will be used by the Tyr driver to create and modify the page table of each address space on the GPU. Each time a mapping gets created or removed by userspace, Tyr will call into GPUVM, which will figure out which calls to map_pages and unmap_pages are required to map the data in question in the page table so that the GPU may access those pages when using that address space.
The Rust type wraps the struct using a raw pointer rather than the usual Opaque+ARef approach because Opaque+ARef requires the target type to be refcounted.
---
We did not discuss where this should go in the MAINTAINERS file yet. As
an initial suggestion I added it under IOMMU SUBSYSTEM, but please let
me know what you prefer. There is also a DEVICE I/O & IRQ [RUST]
subsystem that it could fall under.
---
Changes in v5:
- Fix warning by removing #[must_use] from map_pages.
- Reword comment on NOOP_FLUSH_OPS
- Add blank line after alloc_io_pgtable_ops
- Reword safety comment in Drop to refer ttbr method
- List in MAINTAINERS
- Pick up Reviewed-by: Daniel
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Rename prot::PRIV to prot::PRIVILEGED
- Adjust map_pages to return the length even on error.
- Explain return value in docs of map_pages and unmap_pages.
- Explain in map_pages that the caller must explicitly flush the TLB before accessing the resulting mapping.
- Add a safety requirement that access to a given range is required to
be exclusive.
- Reword comment on NOOP_FLUSH_OPS.
- Rebase on v6.19-rc1 and pick up tags.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Almost entirely rewritten from scratch.
- Link to v2: https://lore.kernel.org/all/[email protected]/
--- MAINTAINERS | 1 + rust/bindings/bindings_helper.h | 3 +- rust/kernel/io.rs | 1 + rust/kernel/io/pgtable.rs | 276 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 280 insertions(+), 1 deletion(-)
MAINTAINERS +1 -0
@@ -13241,6 +13241,7 @@ F: drivers/iommu/ F: include/linux/iommu.h F: include/linux/iova.h F: include/linux/of_iommu.h +F: rust/kernel/io/pgtable.rs IOMMUFD M: Jason Gunthorpe <[email protected]>
rust/bindings/bindings_helper.h +2 -1
@@ -56,9 +56,10 @@#include <linux/fdtable.h> #include <linux/file.h> #include <linux/firmware.h> -#include <linux/interrupt.h> #include <linux/fs.h> #include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/io-pgtable.h> #include <linux/ioport.h> #include <linux/jiffies.h> #include <linux/jump_label.h>
rust/kernel/io.rs +1 -0
@@ -10,6 +10,7 @@ };pub mod mem; +pub mod pgtable;pub mod poll;pub mod resource;
rust/kernel/io/pgtable.rs new file +276 -0
276 lines not on this page · raw message
---
base-commit: 3e7f562e20ee87a25e104ef4fce557d39d62fa85
change-id: 20251111-io-pgtable-fe0822b4ebdd
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Danilo Krummrich
maintainerQuoted 4 lines · Alice Ryhl
We did not discuss where this should go in the
MAINTAINERSfile yet. As an initial suggestion I added it under IOMMU SUBSYSTEM, but please let me know what you prefer. There is also a DEVICE I/O & IRQ [RUST] subsystem that it could fall under.
Either sounds good to me.
MAINTAINERS F: drivers/iommu/ · line 13244
Quoted 9 lines
MAINTAINERS +1
-0@@ -13241,6 +13241,7 @@ F: drivers/iommu/ F: include/linux/iommu.h F: include/linux/iova.h F: include/linux/of_iommu.h +F: rust/kernel/io/pgtable.rs
If it's going to be IOMMU, let's move the file to rust/kernel/iommu/, otherwise it gets picked up by both entries.
Quoted 13 lines · Alice Ryhl
From: Asahi Lina <[email protected]>
This will be used by the Tyr driver to create and modify the page table of each address space on the GPU. Each time a mapping gets created or removed by userspace, Tyr will call into GPUVM, which will figure out which calls to
map_pagesandunmap_pagesare required to map the data in question in the page table so that the GPU may access those pages when using that address space.The Rust type wraps the struct using a raw pointer rather than the usual Opaque+ARef approach because Opaque+ARef requires the target type to be refcounted.
Quoted 7 lines
Signed-off-by Asahi Lina <[email protected]>Acked-by Boris Brezillon <[email protected]>Reviewed-by Daniel Almeida <[email protected]>Co-developed-by Alice Ryhl <[email protected]>Signed-off-by Alice Ryhl <[email protected]>---
As part of the wip for booting Tyr firmware, I have been using this io_pgtable abstraction including v5.
Built and tested on arm64 with rustc 1.91.0 and bindgen 0.72.1.
Hi Alice,
Quoted 5 lines · Alice Ryhl
MAINTAINERS | 1 + rust/bindings/bindings_helper.h | 3 +- rust/kernel/io.rs | 1 + rust/kernel/io/pgtable.rs | 276 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 280 insertions(+), 1 deletion(-)
Thanks for your contribution! I'd like to queue that for 6.20 but agree with Danilo that there should be a dedicated iommu directory under rust/kernel/. Can you please move the file and send a v6?
That directory might some day also contain everything needed to having full IOMMU drivers written in Rust :)
-Joerg
Alice Ryhl
maintainerQuoted 10 lines · Joerg Roedel
Hi Alice,
Quoted 5 lines · Alice Ryhl
MAINTAINERS | 1 + rust/bindings/bindings_helper.h | 3 +- rust/kernel/io.rs | 1 + rust/kernel/io/pgtable.rs | 276 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 280 insertions(+), 1 deletion(-)
Quoted 6 lines
Thanks for your contribution! I'd like to queue that for 6.20 but agree with Danilo that there should be a dedicated iommu directory under
rust/kernel/. Can you please move the file and send a v6?That directory might some day also contain everything needed to having full IOMMU drivers written in Rust :)
Done!