Skip to contentSkip to conversation

iommufd: Misc cleanups per iommufd iopf merging

PATCH Applied Yi Liu 4 participants 8 messages Sep 8, 2024 – Sep 14, 2024

Subsystems (3)
lore
Share & tools
lore

Yi Liu

author
#0 lore raw

cover iommufd: Misc cleanups per iommufd iopf merging

Hi,

Two misc patches per the iommufd iopf merging. Please feel free comment.

Regards,
Yi Liu

Yi Liu (2):
iommufd: Avoid duplicated __iommu_group_set_core_domain() call
iommu: Set iommu_attach_handle->domain in core

 drivers/iommu/iommu.c                   | 1 +
 drivers/iommu/iommufd/fault.c           | 1 -
 drivers/iommu/iommufd/iommufd_private.h | 4 +++-
 3 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 iommufd: Avoid duplicated __iommu_group_set_core_domain() call

For the fault-capable hwpts, the iommufd_hwpt_detach_device() calls both iommufd_fault_domain_detach_dev() and iommu_detach_group(). This would have duplicated __iommu_group_set_core_domain() call since both functions call it in the end. This looks no harm as the __iommu_group_set_core_domain() returns if the new domain equals to the existing one. But it makes sense to avoid such duplicated calls in caller side.

---
 drivers/iommu/iommufd/iommufd_private.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/iommufd_private.h +3 -1
index 92efe30a8f0d..1141c0633dc9 100644
@@ -490,8 +490,10 @@ static inline int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
 static inline void iommufd_hwpt_detach_device(struct iommufd_hw_pagetable *hwpt,
 					      struct iommufd_device *idev)
 {
-	if (hwpt->fault)
+	if (hwpt->fault) {
 		iommufd_fault_domain_detach_dev(hwpt, idev);
+		return;
+	}
 
 	iommu_detach_group(hwpt->domain, idev->igroup->group);
 }
Signature · 1 line
2.34.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] iommufd: Avoid duplicated __iommu_group_set_core_domain() call

Quoted 11 lines · Yi Liu

For the fault-capable hwpts, the iommufd_hwpt_detach_device() calls both iommufd_fault_domain_detach_dev() and iommu_detach_group(). This would have duplicated __iommu_group_set_core_domain() call since both functions call it in the end. This looks no harm as the __iommu_group_set_core_domain() returns if the new domain equals to the existing one. But it makes sense to avoid such duplicated calls in caller side.

---
  drivers/iommu/iommufd/iommufd_private.h | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

Thanks,
baolu

maintainer Reviewed-by on v1 1/2
#3 lore raw

RE: [PATCH 1/2] iommufd: Avoid duplicated __iommu_group_set_core_domain() call

In reply to Yi Liu
Quoted 11 lines

From: Liu, Yi L <[email protected]>
Sent: Sunday, September 8, 2024 7:43 PM

For the fault-capable hwpts, the iommufd_hwpt_detach_device() calls both iommufd_fault_domain_detach_dev() and iommu_detach_group(). This would have
duplicated __iommu_group_set_core_domain() call since both functions call it in the end. This looks no harm as the __iommu_group_set_core_domain() returns if the new domain equals to the existing one. But it makes sense to avoid such duplicated calls in caller side.

Quoted 1 line
author
#4 lore raw

PATCH 2/2 iommu: Set iommu_attach_handle->domain in core

In reply to Yi Liu

The IOMMU core sets the iommu_attach_handle->domain for the iommu_attach_group_handle() path, while the iommu_replace_group_handle() sets it on the caller side. Make the two paths aligned on it.

---
 drivers/iommu/iommu.c         | 1 +
 drivers/iommu/iommufd/fault.c | 1 -
 2 files changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/iommu.c +1 -0
index ed6c5cb60c5a..83c8e617a2c5 100644
@@ -3578,6 +3578,7 @@ int iommu_replace_group_handle(struct iommu_group *group,
 		ret = xa_reserve(&group->pasid_array, IOMMU_NO_PASID, GFP_KERNEL);
 		if (ret)
 			goto err_unlock;
+		handle->domain = new_domain;
 	}
 
 	ret = __iommu_group_set_domain(group, new_domain);
drivers/iommu/iommufd/fault.c +0 -1
index a643d5c7c535..c4715261f2c7 100644
@@ -161,7 +161,6 @@ static int __fault_domain_replace_dev(struct iommufd_device *idev,
 		if (!handle)
 			return -ENOMEM;
 
-		handle->handle.domain = hwpt->domain;
 		handle->idev = idev;
 		ret = iommu_replace_group_handle(idev->igroup->group,
 						 hwpt->domain, &handle->handle);
Signature · 1 line
2.34.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] iommu: Set iommu_attach_handle->domain in core

Quoted 9 lines · Yi Liu

The IOMMU core sets the iommu_attach_handle->domain for the iommu_attach_group_handle() path, while the iommu_replace_group_handle() sets it on the caller side. Make the two paths aligned on it.

---
  drivers/iommu/iommu.c         | 1 +
  drivers/iommu/iommufd/fault.c | 1 -
  2 files changed, 1 insertion(+), 1 deletion(-)

Thanks,
baolu

maintainer Reviewed-by on v1 2/2
#6 lore raw

RE: [PATCH 2/2] iommu: Set iommu_attach_handle->domain in core

In reply to Yi Liu
Quoted 9 lines

From: Liu, Yi L <[email protected]>
Sent: Sunday, September 8, 2024 7:43 PM

The IOMMU core sets the iommu_attach_handle->domain for the iommu_attach_group_handle() path, while the iommu_replace_group_handle()
sets it on the caller side. Make the two paths aligned on it.

maintainer Applied
#7 lore raw
In reply to Yi Liu
Quoted 10 lines · Yi Liu

Hi,

Two misc patches per the iommufd iopf merging. Please feel free comment.

Regards,
Yi Liu

Yi Liu (2):
iommufd: Avoid duplicated __iommu_group_set_core_domain() call
iommu: Set iommu_attach_handle->domain in core

Applied to for-next, thanks

Jason