On Tue, 2022-11-08 at 16:04 -0400, Jason Gunthorpe wrote: > 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) That seems to get the sniff tests for both -ccw and -ap working. I'll keep playing with it for -ccw; Tony and Jason can do more validation on the -ap side. > > 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