Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Yi Liu and committed by
Jason Gunthorpe
bc06f7f6 03c9b102

+8 -6
+8 -6
drivers/iommu/iommufd/device.c
··· 483 483 struct iommufd_device *idev, ioasid_t pasid) 484 484 { 485 485 struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt); 486 + bool attach_resv = hwpt_paging && pasid == IOMMU_NO_PASID; 486 487 int rc; 487 488 488 489 mutex_lock(&idev->igroup->lock); ··· 493 492 goto err_unlock; 494 493 } 495 494 496 - if (hwpt_paging) { 495 + if (attach_resv) { 497 496 rc = iommufd_device_attach_reserved_iova(idev, hwpt_paging); 498 497 if (rc) 499 498 goto err_unlock; ··· 517 516 mutex_unlock(&idev->igroup->lock); 518 517 return 0; 519 518 err_unresv: 520 - if (hwpt_paging) 519 + if (attach_resv) 521 520 iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev); 522 521 err_unlock: 523 522 mutex_unlock(&idev->igroup->lock); ··· 536 535 iommufd_hwpt_detach_device(hwpt, idev, pasid); 537 536 idev->igroup->hwpt = NULL; 538 537 } 539 - if (hwpt_paging) 538 + if (hwpt_paging && pasid == IOMMU_NO_PASID) 540 539 iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, idev->dev); 541 540 mutex_unlock(&idev->igroup->lock); 542 541 ··· 603 602 struct iommufd_hw_pagetable *hwpt) 604 603 { 605 604 struct iommufd_hwpt_paging *hwpt_paging = find_hwpt_paging(hwpt); 605 + bool attach_resv = hwpt_paging && pasid == IOMMU_NO_PASID; 606 606 struct iommufd_hwpt_paging *old_hwpt_paging; 607 607 struct iommufd_group *igroup = idev->igroup; 608 608 struct iommufd_hw_pagetable *old_hwpt; ··· 628 626 } 629 627 630 628 old_hwpt = igroup->hwpt; 631 - if (hwpt_paging) { 629 + if (attach_resv) { 632 630 rc = iommufd_group_do_replace_reserved_iova(igroup, hwpt_paging); 633 631 if (rc) 634 632 goto err_unlock; ··· 639 637 goto err_unresv; 640 638 641 639 old_hwpt_paging = find_hwpt_paging(old_hwpt); 642 - if (old_hwpt_paging && 640 + if (old_hwpt_paging && pasid == IOMMU_NO_PASID && 643 641 (!hwpt_paging || hwpt_paging->ioas != old_hwpt_paging->ioas)) 644 642 iommufd_group_remove_reserved_iova(igroup, old_hwpt_paging); 645 643 ··· 659 657 /* Caller must destroy old_hwpt */ 660 658 return old_hwpt; 661 659 err_unresv: 662 - if (hwpt_paging) 660 + if (attach_resv) 663 661 iommufd_group_remove_reserved_iova(igroup, hwpt_paging); 664 662 err_unlock: 665 663 mutex_unlock(&idev->igroup->lock);