On Sat, May 17, 2025 at 08:21:27PM -0700, Nicolin Chen wrote:
The new HW QUEUE object will be added for HW to access the guest queue for HW-accelerated virtualization feature. Some of HW QUEUEs are designed in a way of accessing the guest queue via a host physical address without doing a translation using the nesting parent IO page table, while others can use the guest physical address. For the former case, kernel working with a VMM needs to pin the physical pages backing the guest memory to lock them when HW QUEUE is accessing, and to ensure those physical pages to be contiguous in the physical address space.
This is very like the existing iommufd_access_pin_pages() that outputs the pinned page list for the caller to test its contiguity.
Move those code from iommufd_access_pin/unpin_pages() and related function for a pair of iopt helpers that can be shared with the HW QUEUE allocator.
Rename check_area_prot() to align with the existing iopt_area helpers, and inline it to the header since iommufd_access_rw() still uses it.
Reviewed-by: Pranjal Shrivastava praan@google.com Reviewed-by: Kevin Tian kevin.tian@intel.com Reviewed-by: Jason Gunthorpe jgg@nvidia.com Signed-off-by: Nicolin Chen nicolinc@nvidia.com
drivers/iommu/iommufd/io_pagetable.h | 8 ++ drivers/iommu/iommufd/iommufd_private.h | 6 ++ drivers/iommu/iommufd/device.c | 119 ++---------------------- drivers/iommu/iommufd/io_pagetable.c | 97 +++++++++++++++++++ 4 files changed, 119 insertions(+), 111 deletions(-)
And if you do what was suggested do we need this patch at all? Just use the normal access sequence:
iommufd_access_create(ops=NULL) iommufd_access_attach(viommu->hwpt->ioas) iommufd_access_pin_pages()
And store a viommu->access pointer to undo it all.
This avoids making it all special with different internal behavior from a mdev. The only difference is we allowe ops=null for viommu but not for mdev.
I don't think it is worth doing all these changes just to eliminate the access memory allocation.. viommu allocation is not fast path.
Jason