Skip to content

Commit bc06f7f

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd/device: Only add reserved_iova in non-pasid path
As the pasid is passed through the attach/replace/detach helpers, it is necessary to ensure only the non-pasid path adds reserved_iova. Link: https://patch.msgid.link/r/20250321171940.7213-5-yi.l.liu@intel.com Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.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>
1 parent 03c9b10 commit bc06f7f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

drivers/iommu/iommufd/device.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
483483
struct iommufd_device *idev, ioasid_t pasid)
484484
{
485485
struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt);
486+
bool attach_resv = hwpt_paging && pasid == IOMMU_NO_PASID;
486487
int rc;
487488

488489
mutex_lock(&idev->igroup->lock);
@@ -492,7 +493,7 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
492493
goto err_unlock;
493494
}
494495

495-
if (hwpt_paging) {
496+
if (attach_resv) {
496497
rc = iommufd_device_attach_reserved_iova(idev, hwpt_paging);
497498
if (rc)
498499
goto err_unlock;
@@ -516,7 +517,7 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
516517
mutex_unlock(&idev->igroup->lock);
517518
return 0;
518519
err_unresv:
519-
if (hwpt_paging)
520+
if (attach_resv)
520521
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev);
521522
err_unlock:
522523
mutex_unlock(&idev->igroup->lock);
@@ -535,7 +536,7 @@ iommufd_hw_pagetable_detach(struct iommufd_device *idev, ioasid_t pasid)
535536
iommufd_hwpt_detach_device(hwpt, idev, pasid);
536537
idev->igroup->hwpt = NULL;
537538
}
538-
if (hwpt_paging)
539+
if (hwpt_paging && pasid == IOMMU_NO_PASID)
539540
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev);
540541
mutex_unlock(&idev->igroup->lock);
541542

@@ -602,6 +603,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
602603
struct iommufd_hw_pagetable *hwpt)
603604
{
604605
struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt);
606+
bool attach_resv = hwpt_paging && pasid == IOMMU_NO_PASID;
605607
struct iommufd_hwpt_paging *old_hwpt_paging;
606608
struct iommufd_group *igroup = idev->igroup;
607609
struct iommufd_hw_pagetable *old_hwpt;
@@ -626,7 +628,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
626628
}
627629

628630
old_hwpt = igroup->hwpt;
629-
if (hwpt_paging) {
631+
if (attach_resv) {
630632
rc = iommufd_group_do_replace_reserved_iova(igroup, hwpt_paging);
631633
if (rc)
632634
goto err_unlock;
@@ -637,7 +639,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
637639
goto err_unresv;
638640

639641
old_hwpt_paging = find_hwpt_paging(old_hwpt);
640-
if (old_hwpt_paging &&
642+
if (old_hwpt_paging && pasid == IOMMU_NO_PASID &&
641643
(!hwpt_paging || hwpt_paging->ioas != old_hwpt_paging->ioas))
642644
iommufd_group_remove_reserved_iova(igroup, old_hwpt_paging);
643645

@@ -657,7 +659,7 @@ iommufd_device_do_replace(struct iommufd_device *idev, ioasid_t pasid,
657659
/* Caller must destroy old_hwpt */
658660
return old_hwpt;
659661
err_unresv:
660-
if (hwpt_paging)
662+
if (attach_resv)
661663
iommufd_group_remove_reserved_iova(igroup, hwpt_paging);
662664
err_unlock:
663665
mutex_unlock(&idev->igroup->lock);

0 commit comments

Comments
 (0)