@@ -58,6 +58,24 @@ int iommufd_hw_pagetable_enforce_cc(struct iommufd_hw_pagetable *hwpt)
return 0;
}
+static int iommufd_hw_pagetable_link_ioas(struct iommufd_hw_pagetable *hwpt)
+{
+ int rc;
+
+ /*
+ * Only a parent hwpt needs to be linked to the IOAS. And a hwpt->parent
+ * must be linked to the IOAS already, when it's being allocated.
+ */
+ if (hwpt->parent)
+ return 0;
+
+ rc = iopt_table_add_domain(&hwpt->ioas->iopt, hwpt->domain);
+ if (rc)
+ return rc;
+ list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list);
+ return 0;
+}
+
/**
* iommufd_hw_pagetable_alloc() - Get an iommu_domain for a device
* @ictx: iommufd context
@@ -160,10 +178,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
goto out_abort;
}
- rc = iopt_table_add_domain(&hwpt->ioas->iopt, hwpt->domain);
+ rc = iommufd_hw_pagetable_link_ioas(hwpt);
if (rc)
goto out_detach;
- list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list);
return hwpt;
out_detach: