On Tue, Nov 08, 2022 at 02:18:12PM -0500, Matthew Rosato wrote: > Update on why -ap is failing -- I see vfio_pin_pages requests from > vfio_ap_irq_enable that are failing on -EINVAL -- input is not > page-aligned, just like what vfio-ccw was hitting. > > I just tried a quick hack to force these to page-aligned requests > and with that the vfio-ap tests I'm running start passing again. So > I think a proper fix in the iommufd code for this will also fix > vfio-ap (we will test of course) Right, so my first fix isn't the right thing. The APIs are mismatched too much. The length gets all messed up in the process. So how about this? (drop the prior attempt) diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index d835a77aaf26d9..b590ca3c186396 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1906,8 +1906,13 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, if (iova > ULONG_MAX) return -EINVAL; + /* + * VFIO ignores the sub page offset, npages is from the start of + * a PAGE_SIZE chunk of IOVA. + */ ret = iommufd_access_pin_pages( - device->iommufd_access, iova, npage * PAGE_SIZE, pages, + device->iommufd_access, ALIGN_DOWN(iova, PAGE_SIZE), + npage * PAGE_SIZE, pages, (prot & IOMMU_WRITE) ? IOMMUFD_ACCESS_RW_WRITE : 0); if (ret) return ret; @@ -1937,7 +1942,8 @@ void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage) if (device->iommufd_access) { if (WARN_ON(iova > ULONG_MAX)) return; - iommufd_access_unpin_pages(device->iommufd_access, iova, + iommufd_access_unpin_pages(device->iommufd_access, + ALIGN_DOWN(iova, PAGE_SIZE), npage * PAGE_SIZE); return; } Thanks, Jason