On Tue, Feb 04, 2025 at 11:33:24AM +0100, David Hildenbrand wrote: > On 03.02.25 10:58, Simona Vetter wrote: > > On Sun, Feb 02, 2025 at 10:05:42PM +0900, Asahi Lina wrote: > > > This series refactors the existing Page wrapper to support borrowing > > > `struct page` objects without ownership on the Rust side, and converting > > > page references to/from physical memory addresses. > > > > > > The series overlaps with the earlier submission in [1] and follows a > > > different approach, based on the discussion that happened there. > > > > > > The primary use case for this is implementing IOMMU-style page table > > > management in Rust. This allows drivers for IOMMUs and MMU-containing > > > SoC devices to be written in Rust (such as embedded GPUs). The intended > > > logic is similar to how ARM SMMU page tables are managed in the > > > drivers/iommu tree. > > > > > > First, introduce a concept of Owned<T> and an Ownable trait. These are > > > similar to ARef<T> and AlwaysRefCounted, but are used for types which > > > are not ref counted but rather have a single intended owner. > > > > > > Then, refactor the existing Page support to use the new mechanism. Pages > > > returned from the page allocator are not intended to be ref counted by > > > consumers (see previous discussion in [1]), so this keeps Rust's view of > > > page ownership as a simple "owned or not". Of course, this is still > > > composable as Arc<Owned<Page>> if Rust code needs to reference count its > > > own Page allocations for whatever reason. > > > > I think there's a bit a potential mess here because the conversion to > > folios isn't far enough yet that we can entirely ignore page refcounts and > > just use folio refcounts. But I guess we can deal with that oddity if we > > hit it (maybe folio conversion moves fast enough), since this only really > > starts to become relevant for hmm/svm gpu stuff. > > I'll note that in the future only selected things will be folios (e.g., > pagecache, anonymous memory). Everything else will either get a separate > memdesc (e.g., ptdesc), or work on bare pages. > > Likely, when talking about page tables, "ptdesc" might be what you want to > allocate here, and not "folios". I just posted a series to clean up the iommu code that this is cribbing the interface from: add an ioptdesc, remove all the struct page from the API and so forth: https://lore.kernel.org/all/0-v1-416f64558c7c+2a5-iommu_pages_jgg@xxxxxxxxxx/ I strongly suggest that rust not expose these old schemes that will need another cleanup like the above. Page tables just need an allocator using simple void *, kmalloc is good enough for simple cases. Drivers should not be exposing or touching struct page just to implement a page table. Jason