Commit 1d149ab2 authored by Jason Gunthorpe's avatar Jason Gunthorpe

iommufd: Make sw_msi_start a group global

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_resv_regions() move the sw_msi_start to the iommufd_group so it
is always available once any HWPT has been attached.

Link: https://lore.kernel.org/r/7-v8-6659224517ea+532-iommufd_alloc_jgg@nvidia.comReviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Tested-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 269c5238
...@@ -88,6 +88,7 @@ static struct iommufd_group *iommufd_get_group(struct iommufd_ctx *ictx, ...@@ -88,6 +88,7 @@ static struct iommufd_group *iommufd_get_group(struct iommufd_ctx *ictx,
kref_init(&new_igroup->ref); kref_init(&new_igroup->ref);
mutex_init(&new_igroup->lock); mutex_init(&new_igroup->lock);
INIT_LIST_HEAD(&new_igroup->device_list); INIT_LIST_HEAD(&new_igroup->device_list);
new_igroup->sw_msi_start = PHYS_ADDR_MAX;
/* group reference moves into new_igroup */ /* group reference moves into new_igroup */
new_igroup->group = group; new_igroup->group = group;
...@@ -292,10 +293,10 @@ u32 iommufd_device_to_id(struct iommufd_device *idev) ...@@ -292,10 +293,10 @@ u32 iommufd_device_to_id(struct iommufd_device *idev)
} }
EXPORT_SYMBOL_NS_GPL(iommufd_device_to_id, IOMMUFD); EXPORT_SYMBOL_NS_GPL(iommufd_device_to_id, IOMMUFD);
static int iommufd_device_setup_msi(struct iommufd_device *idev, static int iommufd_group_setup_msi(struct iommufd_group *igroup,
struct iommufd_hw_pagetable *hwpt, struct iommufd_hw_pagetable *hwpt)
phys_addr_t sw_msi_start)
{ {
phys_addr_t sw_msi_start = igroup->sw_msi_start;
int rc; int rc;
/* /*
...@@ -328,7 +329,6 @@ static int iommufd_device_setup_msi(struct iommufd_device *idev, ...@@ -328,7 +329,6 @@ static int iommufd_device_setup_msi(struct iommufd_device *idev,
int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
struct iommufd_device *idev) struct iommufd_device *idev)
{ {
phys_addr_t sw_msi_start = PHYS_ADDR_MAX;
int rc; int rc;
mutex_lock(&idev->igroup->lock); mutex_lock(&idev->igroup->lock);
...@@ -356,8 +356,8 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, ...@@ -356,8 +356,8 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
} }
} }
rc = iopt_table_enforce_dev_resv_regions( rc = iopt_table_enforce_dev_resv_regions(&hwpt->ioas->iopt, idev->dev,
&hwpt->ioas->iopt, idev->dev, &sw_msi_start); &idev->igroup->sw_msi_start);
if (rc) if (rc)
goto err_unlock; goto err_unlock;
...@@ -369,7 +369,7 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, ...@@ -369,7 +369,7 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
* attachment. * attachment.
*/ */
if (list_empty(&idev->igroup->device_list)) { if (list_empty(&idev->igroup->device_list)) {
rc = iommufd_device_setup_msi(idev, hwpt, sw_msi_start); rc = iommufd_group_setup_msi(idev->igroup, hwpt);
if (rc) if (rc)
goto err_unresv; goto err_unresv;
......
...@@ -267,6 +267,7 @@ struct iommufd_group { ...@@ -267,6 +267,7 @@ struct iommufd_group {
struct iommu_group *group; struct iommu_group *group;
struct iommufd_hw_pagetable *hwpt; struct iommufd_hw_pagetable *hwpt;
struct list_head device_list; struct list_head device_list;
phys_addr_t sw_msi_start;
}; };
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment