Skip to content

Commit b41e38e

Browse files
LuBaolujgunthorpe
authored andcommitted
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>
1 parent 9838f2b commit b41e38e

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4077,38 +4077,39 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
40774077
struct iommu_domain *parent,
40784078
const struct iommu_user_data *user_data)
40794079
{
4080+
struct device_domain_info *info = dev_iommu_priv_get(dev);
4081+
bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
4082+
bool nested_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT;
4083+
struct intel_iommu *iommu = info->iommu;
40804084
struct iommu_domain *domain;
4081-
struct intel_iommu *iommu;
4082-
bool dirty_tracking;
4085+
4086+
/* Must be NESTING domain */
4087+
if (parent) {
4088+
if (!nested_supported(iommu) || flags)
4089+
return ERR_PTR(-EOPNOTSUPP);
4090+
return intel_nested_domain_alloc(parent, user_data);
4091+
}
40834092

40844093
if (flags &
40854094
(~(IOMMU_HWPT_ALLOC_NEST_PARENT | IOMMU_HWPT_ALLOC_DIRTY_TRACKING)))
40864095
return ERR_PTR(-EOPNOTSUPP);
4087-
4088-
if (parent || user_data)
4089-
return ERR_PTR(-EOPNOTSUPP);
4090-
4091-
iommu = device_to_iommu(dev, NULL, NULL);
4092-
if (!iommu)
4093-
return ERR_PTR(-ENODEV);
4094-
4095-
if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !nested_supported(iommu))
4096+
if (nested_parent && !nested_supported(iommu))
40964097
return ERR_PTR(-EOPNOTSUPP);
4097-
4098-
dirty_tracking = (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING);
4099-
if (dirty_tracking && !ssads_supported(iommu))
4098+
if (user_data || (dirty_tracking && !ssads_supported(iommu)))
41004099
return ERR_PTR(-EOPNOTSUPP);
41014100

41024101
/*
4103-
* domain_alloc_user op needs to fully initialize a domain
4104-
* before return, so uses iommu_domain_alloc() here for
4105-
* simple.
4102+
* domain_alloc_user op needs to fully initialize a domain before
4103+
* return, so uses iommu_domain_alloc() here for simple.
41064104
*/
41074105
domain = iommu_domain_alloc(dev->bus);
41084106
if (!domain)
4109-
domain = ERR_PTR(-ENOMEM);
4107+
return ERR_PTR(-ENOMEM);
4108+
4109+
if (nested_parent)
4110+
to_dmar_domain(domain)->nested_parent = true;
41104111

4111-
if (!IS_ERR(domain) && dirty_tracking) {
4112+
if (dirty_tracking) {
41124113
if (to_dmar_domain(domain)->use_first_level) {
41134114
iommu_domain_free(domain);
41144115
return ERR_PTR(-EOPNOTSUPP);

drivers/iommu/intel/iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ struct dmar_domain {
601601
* level.
602602
*/
603603
u8 dirty_tracking:1; /* Dirty tracking is enabled */
604+
u8 nested_parent:1; /* Has other domains nested on it */
604605

605606
spinlock_t lock; /* Protect device tracking lists */
606607
struct list_head devices; /* all devices' list */

drivers/iommu/intel/nested.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent,
8989
/* Must be nested domain */
9090
if (user_data->type != IOMMU_HWPT_DATA_VTD_S1)
9191
return ERR_PTR(-EOPNOTSUPP);
92-
if (parent->ops != intel_iommu_ops.default_domain_ops)
92+
if (parent->ops != intel_iommu_ops.default_domain_ops ||
93+
!s2_domain->nested_parent)
9394
return ERR_PTR(-EINVAL);
9495

9596
ret = iommu_copy_struct_from_user(&vtd, user_data,

0 commit comments

Comments
 (0)