[PATCH v3 06/16] iommufd/hw_pagetable: Allow viommu->ops->cache_invalidate for hwpt_nested

Nicolin Chen nicolinc at nvidia.com
Wed Oct 9 09:38:18 PDT 2024


Now cache entries for hwpt_nested can be invalidated via the vIOMMU's
cache_invalidate op alternatively. Allow iommufd_hwpt_nested_alloc to
support such a case.

Signed-off-by: Nicolin Chen <nicolinc at nvidia.com>
---
 drivers/iommu/iommufd/hw_pagetable.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c
index b88a638d07da..ccaaf801955c 100644
--- a/drivers/iommu/iommufd/hw_pagetable.c
+++ b/drivers/iommu/iommufd/hw_pagetable.c
@@ -202,6 +202,17 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
 	return ERR_PTR(rc);
 }
 
+static inline bool
+iommufd_hwpt_nested_has_invalidate_op(struct iommufd_hwpt_nested *hwpt_nested)
+{
+	struct iommufd_viommu *viommu = hwpt_nested->viommu;
+
+	if (viommu)
+		return viommu->ops && viommu->ops->cache_invalidate;
+	else
+		return hwpt_nested->common.domain->ops->cache_invalidate_user;
+}
+
 /**
  * iommufd_hwpt_nested_alloc() - Get a NESTED iommu_domain for a device
  * @ictx: iommufd context
@@ -257,7 +268,7 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx,
 	hwpt->domain->owner = ops;
 
 	if (WARN_ON_ONCE(hwpt->domain->type != IOMMU_DOMAIN_NESTED ||
-			 !hwpt->domain->ops->cache_invalidate_user)) {
+			 !iommufd_hwpt_nested_has_invalidate_op(hwpt_nested))) {
 		rc = -EINVAL;
 		goto out_abort;
 	}
-- 
2.43.0




More information about the linux-arm-kernel mailing list