Message ID | 20230921075431.125239-11-yi.l.liu@intel.com |
---|---|
State | New |
Headers | show |
Series | None | expand |
> From: Liu, Yi L <yi.l.liu@intel.com> > Sent: Thursday, September 21, 2023 3:55 PM > > > + if (hwpt_type != IOMMU_HWPT_TYPE_DEFAULT && > + hwpt_type != IOMMU_HWPT_TYPE_VTD_S1) > + return ERR_PTR(-EINVAL); > + > + if ((hwpt_type == IOMMU_HWPT_TYPE_DEFAULT) == !!parent) > + return ERR_PTR(-EINVAL); this is probably too strict. What about intel-iommu driver supports a IOMMU_HWPT_TYPE_VTD_S2 later for some tweak w/o nesting? let's make the parent match specific to VTD_S1 type. > + > + if (parent && request_nest_parent) > + return ERR_PTR(-EINVAL); this check should be moved to iommufd?
On 2023/9/27 14:56, Tian, Kevin wrote: >> From: Liu, Yi L <yi.l.liu@intel.com> >> Sent: Thursday, September 21, 2023 3:55 PM >> >> >> + if (hwpt_type != IOMMU_HWPT_TYPE_DEFAULT && >> + hwpt_type != IOMMU_HWPT_TYPE_VTD_S1) >> + return ERR_PTR(-EINVAL); >> + >> + if ((hwpt_type == IOMMU_HWPT_TYPE_DEFAULT) == !!parent) >> + return ERR_PTR(-EINVAL); > > this is probably too strict. What about intel-iommu driver supports a > IOMMU_HWPT_TYPE_VTD_S2 later for some tweak w/o nesting? in that case, this check needs to be updated > let's make the parent match specific to VTD_S1 type. ok. how about below? if ((data_type == IOMMU_HWPT_ALLOC_DATA_VTD_S1) && !parent) >> + >> + if (parent && request_nest_parent) >> + return ERR_PTR(-EINVAL); > > this check should be moved to iommufd? > oops, maybe no need, iommufd_hwpt_alloc() has below check. if (cmd->flags & IOMMU_HWPT_ALLOC_NEST_PARENT && cmd->data_type != IOMMU_HWPT_ALLOC_DATA_NONE) return -EINVAL;
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index c93c91ed4ee2..9b10e4b1d400 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4077,19 +4077,35 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, struct iommu_domain *parent, const struct iommu_user_data *user_data) { + bool request_nest_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT; struct iommu_domain *domain; struct intel_iommu *iommu; + if (hwpt_type != IOMMU_HWPT_TYPE_DEFAULT && + hwpt_type != IOMMU_HWPT_TYPE_VTD_S1) + return ERR_PTR(-EINVAL); + + if ((hwpt_type == IOMMU_HWPT_TYPE_DEFAULT) == !!parent) + return ERR_PTR(-EINVAL); + + if (parent && request_nest_parent) + return ERR_PTR(-EINVAL); + iommu = device_to_iommu(dev, NULL, NULL); if (!iommu) return ERR_PTR(-ENODEV); - if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap)) + if ((parent || request_nest_parent) && !ecap_nest(iommu->ecap)) return ERR_PTR(-EOPNOTSUPP); - domain = iommu_domain_alloc(dev->bus); - if (!domain) - domain = ERR_PTR(-ENOMEM); + if (parent) { + domain = intel_nested_domain_alloc(parent, user_data); + } else { + domain = iommu_domain_alloc(dev->bus); + if (!domain) + domain = ERR_PTR(-ENOMEM); + } + return domain; }