iommufd/device: Replace idev->igroup with local variable
With more use of the fields of igroup, use a local vairable instead of using the idev->igroup heavily. No functional change expected. Link: https://patch.msgid.link/r/20250321171940.7213-6-yi.l.liu@intel.com Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>pull/1193/head
parent
bc06f7f66d
commit
2eaa7f845e
|
|
@ -333,18 +333,19 @@ static int
|
||||||
iommufd_device_attach_reserved_iova(struct iommufd_device *idev,
|
iommufd_device_attach_reserved_iova(struct iommufd_device *idev,
|
||||||
struct iommufd_hwpt_paging *hwpt_paging)
|
struct iommufd_hwpt_paging *hwpt_paging)
|
||||||
{
|
{
|
||||||
|
struct iommufd_group *igroup = idev->igroup;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
lockdep_assert_held(&idev->igroup->lock);
|
lockdep_assert_held(&igroup->lock);
|
||||||
|
|
||||||
rc = iopt_table_enforce_dev_resv_regions(&hwpt_paging->ioas->iopt,
|
rc = iopt_table_enforce_dev_resv_regions(&hwpt_paging->ioas->iopt,
|
||||||
idev->dev,
|
idev->dev,
|
||||||
&idev->igroup->sw_msi_start);
|
&igroup->sw_msi_start);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (list_empty(&idev->igroup->device_list)) {
|
if (list_empty(&igroup->device_list)) {
|
||||||
rc = iommufd_group_setup_msi(idev->igroup, hwpt_paging);
|
rc = iommufd_group_setup_msi(igroup, hwpt_paging);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt,
|
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt,
|
||||||
idev->dev);
|
idev->dev);
|
||||||
|
|
@ -484,11 +485,12 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
|
||||||
{
|
{
|
||||||
struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt);
|
struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt);
|
||||||
bool attach_resv = hwpt_paging && pasid == IOMMU_NO_PASID;
|
bool attach_resv = hwpt_paging && pasid == IOMMU_NO_PASID;
|
||||||
|
struct iommufd_group *igroup = idev->igroup;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
mutex_lock(&idev->igroup->lock);
|
mutex_lock(&igroup->lock);
|
||||||
|
|
||||||
if (idev->igroup->hwpt != NULL && idev->igroup->hwpt != hwpt) {
|
if (igroup->hwpt && igroup->hwpt != hwpt) {
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
goto err_unlock;
|
goto err_unlock;
|
||||||
}
|
}
|
||||||
|
|
@ -506,39 +508,40 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
|
||||||
* reserved regions are only updated during individual device
|
* reserved regions are only updated during individual device
|
||||||
* attachment.
|
* attachment.
|
||||||
*/
|
*/
|
||||||
if (list_empty(&idev->igroup->device_list)) {
|
if (list_empty(&igroup->device_list)) {
|
||||||
rc = iommufd_hwpt_attach_device(hwpt, idev, pasid);
|
rc = iommufd_hwpt_attach_device(hwpt, idev, pasid);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto err_unresv;
|
goto err_unresv;
|
||||||
idev->igroup->hwpt = hwpt;
|
igroup->hwpt = hwpt;
|
||||||
}
|
}
|
||||||
refcount_inc(&hwpt->obj.users);
|
refcount_inc(&hwpt->obj.users);
|
||||||
list_add_tail(&idev->group_item, &idev->igroup->device_list);
|
list_add_tail(&idev->group_item, &igroup->device_list);
|
||||||
mutex_unlock(&idev->igroup->lock);
|
mutex_unlock(&igroup->lock);
|
||||||
return 0;
|
return 0;
|
||||||
err_unresv:
|
err_unresv:
|
||||||
if (attach_resv)
|
if (attach_resv)
|
||||||
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev);
|
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev);
|
||||||
err_unlock:
|
err_unlock:
|
||||||
mutex_unlock(&idev->igroup->lock);
|
mutex_unlock(&igroup->lock);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct iommufd_hw_pagetable *
|
struct iommufd_hw_pagetable *
|
||||||
iommufd_hw_pagetable_detach(struct iommufd_device *idev, ioasid_t pasid)
|
iommufd_hw_pagetable_detach(struct iommufd_device *idev, ioasid_t pasid)
|
||||||
{
|
{
|
||||||
struct iommufd_hw_pagetable *hwpt = idev->igroup->hwpt;
|
struct iommufd_group *igroup = idev->igroup;
|
||||||
|
struct iommufd_hw_pagetable *hwpt = igroup->hwpt;
|
||||||
struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt);
|
struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt);
|
||||||
|
|
||||||
mutex_lock(&idev->igroup->lock);
|
mutex_lock(&igroup->lock);
|
||||||
list_del(&idev->group_item);
|
list_del(&idev->group_item);
|
||||||
if (list_empty(&idev->igroup->device_list)) {
|
if (list_empty(&igroup->device_list)) {
|
||||||
iommufd_hwpt_detach_device(hwpt, idev, pasid);
|
iommufd_hwpt_detach_device(hwpt, idev, pasid);
|
||||||
idev->igroup->hwpt = NULL;
|
igroup->hwpt = NULL;
|
||||||
}
|
}
|
||||||
if (hwpt_paging && pasid == IOMMU_NO_PASID)
|
if (hwpt_paging && pasid == IOMMU_NO_PASID)
|
||||||
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev);
|
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev);
|
||||||
mutex_unlock(&idev->igroup->lock);
|
mutex_unlock(&igroup->lock);
|
||||||
|
|
||||||
/* Caller must destroy hwpt */
|
/* Caller must destroy hwpt */
|
||||||
return hwpt;
|
return hwpt;
|
||||||
|
|
@ -610,7 +613,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
|
||||||
unsigned int num_devices;
|
unsigned int num_devices;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
mutex_lock(&idev->igroup->lock);
|
mutex_lock(&igroup->lock);
|
||||||
|
|
||||||
if (igroup->hwpt == NULL) {
|
if (igroup->hwpt == NULL) {
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
|
|
@ -623,7 +626,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hwpt == igroup->hwpt) {
|
if (hwpt == igroup->hwpt) {
|
||||||
mutex_unlock(&idev->igroup->lock);
|
mutex_unlock(&igroup->lock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -654,7 +657,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
|
||||||
if (num_devices > 1)
|
if (num_devices > 1)
|
||||||
WARN_ON(refcount_sub_and_test(num_devices - 1,
|
WARN_ON(refcount_sub_and_test(num_devices - 1,
|
||||||
&old_hwpt->obj.users));
|
&old_hwpt->obj.users));
|
||||||
mutex_unlock(&idev->igroup->lock);
|
mutex_unlock(&igroup->lock);
|
||||||
|
|
||||||
/* Caller must destroy old_hwpt */
|
/* Caller must destroy old_hwpt */
|
||||||
return old_hwpt;
|
return old_hwpt;
|
||||||
|
|
@ -662,7 +665,7 @@ err_unresv:
|
||||||
if (attach_resv)
|
if (attach_resv)
|
||||||
iommufd_group_remove_reserved_iova(igroup, hwpt_paging);
|
iommufd_group_remove_reserved_iova(igroup, hwpt_paging);
|
||||||
err_unlock:
|
err_unlock:
|
||||||
mutex_unlock(&idev->igroup->lock);
|
mutex_unlock(&igroup->lock);
|
||||||
return ERR_PTR(rc);
|
return ERR_PTR(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue