The sw_msi_start is only set by the ARM drivers and it is always constant. Due to the way vfio/iommufd allow domains to be re-used between devices we have a built in assumption that there is only one value for sw_msi_start and it is global to the system.
To make replace simpler where we may not reparse the iommu_get_group_resv_regions() move the sw_msi_start to the iommufd_group so it is always available once any HWPT has been attached.
Signed-off-by: Jason Gunthorpe jgg@nvidia.com --- drivers/iommu/iommufd/device.c | 13 +++++++------ drivers/iommu/iommufd/iommufd_private.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 75e8d79678736f..ea34dc5b0fd1e4 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -74,6 +74,7 @@ static struct iommufd_group *iommufd_get_group(struct iommufd_ctx *ictx,
kref_init(&new_igroup->ref); mutex_init(&new_igroup->lock); + new_igroup->sw_msi_start = PHYS_ADDR_MAX; /* group reference moves into new_igroup */ new_igroup->group = group;
@@ -238,9 +239,9 @@ void iommufd_device_unbind(struct iommufd_device *idev) EXPORT_SYMBOL_NS_GPL(iommufd_device_unbind, IOMMUFD);
static int iommufd_device_setup_msi(struct iommufd_device *idev, - struct iommufd_hw_pagetable *hwpt, - phys_addr_t sw_msi_start) + struct iommufd_hw_pagetable *hwpt) { + phys_addr_t sw_msi_start = idev->igroup->sw_msi_start; int rc;
/* @@ -273,7 +274,6 @@ static int iommufd_device_setup_msi(struct iommufd_device *idev, int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev) { - phys_addr_t sw_msi_start = PHYS_ADDR_MAX; int rc;
lockdep_assert_held(&idev->igroup->lock); @@ -310,12 +310,13 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, return 0; }
- rc = iopt_table_enforce_group_resv_regions( - &hwpt->ioas->iopt, idev->igroup->group, &sw_msi_start); + rc = iopt_table_enforce_group_resv_regions(&hwpt->ioas->iopt, + idev->igroup->group, + &idev->igroup->sw_msi_start); if (rc) return rc;
- rc = iommufd_device_setup_msi(idev, hwpt, sw_msi_start); + rc = iommufd_device_setup_msi(idev, hwpt); if (rc) goto err_unresv;
diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index dbecdff013d082..0497d6190fd1b3 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -267,6 +267,7 @@ struct iommufd_group { struct iommu_group *group; struct iommufd_hw_pagetable *hwpt; unsigned int devices; + phys_addr_t sw_msi_start; };
/*