summaryrefslogtreecommitdiff
path: root/drivers/iommu/intel/iommu.c
diff options
context:
space:
mode:
authorLu Baolu <baolu.lu@linux.intel.com>2023-10-26 07:42:15 +0300
committerJason Gunthorpe <jgg@nvidia.com>2023-10-26 17:16:34 +0300
commitb41e38e225398191aaa0f1115d6234f57ffd0741 (patch)
treeb412993e8e2d760cd95da68852290182c7f49a8d /drivers/iommu/intel/iommu.c
parent9838f2bb6b6be1e648b9377fc97ee7b18d9f2fbf (diff)
downloadlinux-b41e38e225398191aaa0f1115d6234f57ffd0741.tar.xz
iommu/vt-d: Add nested domain allocation
This adds the support for IOMMU_HWPT_DATA_VTD_S1 type. And 'nested_parent' is added to mark the nested parent domain to sanitize the input parent domain. Link: https://lore.kernel.org/r/20231026044216.64964-8-yi.l.liu@intel.com Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Diffstat (limited to 'drivers/iommu/intel/iommu.c')
-rw-r--r--drivers/iommu/intel/iommu.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 292baa64188b..4ce372d5d4f3 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4077,38 +4077,39 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
struct iommu_domain *parent,
const struct iommu_user_data *user_data)
{
+ struct device_domain_info *info = dev_iommu_priv_get(dev);
+ bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
+ bool nested_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT;
+ struct intel_iommu *iommu = info->iommu;
struct iommu_domain *domain;
- struct intel_iommu *iommu;
- bool dirty_tracking;
+
+ /* Must be NESTING domain */
+ if (parent) {
+ if (!nested_supported(iommu) || flags)
+ return ERR_PTR(-EOPNOTSUPP);
+ return intel_nested_domain_alloc(parent, user_data);
+ }
if (flags &
(~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING)))
return ERR_PTR(-EOPNOTSUPP);
-
- if (parent || user_data)
- return ERR_PTR(-EOPNOTSUPP);
-
- iommu = device_to_iommu(dev, NULL, NULL);
- if (!iommu)
- return ERR_PTR(-ENODEV);
-
- if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !nested_supported(iommu))
+ if (nested_parent && !nested_supported(iommu))
return ERR_PTR(-EOPNOTSUPP);
-
- dirty_tracking = (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING);
- if (dirty_tracking && !ssads_supported(iommu))
+ if (user_data || (dirty_tracking && !ssads_supported(iommu)))
return ERR_PTR(-EOPNOTSUPP);
/*
- * domain_alloc_user op needs to fully initialize a domain
- * before return, so uses iommu_domain_alloc() here for
- * simple.
+ * domain_alloc_user op needs to fully initialize a domain before
+ * return, so uses iommu_domain_alloc() here for simple.
*/
domain = iommu_domain_alloc(dev->bus);
if (!domain)
- domain = ERR_PTR(-ENOMEM);
+ return ERR_PTR(-ENOMEM);
+
+ if (nested_parent)
+ to_dmar_domain(domain)->nested_parent = true;
- if (!IS_ERR(domain) && dirty_tracking) {
+ if (dirty_tracking) {
if (to_dmar_domain(domain)->use_first_level) {
iommu_domain_free(domain);
return ERR_PTR(-EOPNOTSUPP);