[PATCH v2 0/2] iommu: Allow passing custom allocators to pgtable drivers
Jason Gunthorpe
jgg at nvidia.com
Fri Nov 10 08:12:29 PST 2023
On Fri, Nov 10, 2023 at 04:48:09PM +0100, Boris Brezillon wrote:
> > Shouldn't improving the allocator in the io page table be done
> > generically?
>
> While most of it could be made generic, the pre-reservation is a bit
> special for VM_BIND: we need to pre-reserve page tables without knowing
> the state of the page table tree (over-reservation), because page table
> updates are executed asynchronously (the state of the VM when we
> prepare the request might differ from its state when we execute it). We
> also need to make sure no other pre-reservation requests steal pages
> from the pool of pages we reserved for requests that were not executed
> yet.
>
> I'm not saying this is impossible to implement, but it sounds too
> specific for a generic io-pgtable cache.
It is quite easy, and indeed much better to do it internally.
struct page allocations like the io page table uses get a few pointers
of data to be used by the caller in the struct page *.
You can put a refcounter in that data per-page to count how many
callers have reserved the page. Add a new "allocate VA" API to
allocate and install page table levels that cover a VA range in the
radix tree and increment all the refcounts on all the impacted struct
pages.
Now you can be guarenteed that future map in that VA range will be
fully non-allocating, and future unmap will be fully non-freeing.
Some "unallocate VA" will decrement the refcounts and free the page
table levels within that VA range.
Precompute the number of required pages at the start of allocate and
you can trivally do batch allocations. Ditto for unallocate, it can
trivially do batch freeing.
Way better and more generically useful than allocator ops!
I'd be interested in something like this for iommufd too, we greatly
suffer from poor iommu driver performace during map, and in general we
lack a robust way to actually fully unmap all page table levels.
A new domain API to prepare all the ioptes more efficiently would be a
great general improvement!
Jason
More information about the linux-arm-kernel
mailing list