Skip to content

Commit 4ff5421

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd: Support allocating nested parent domain
Extend IOMMU_HWPT_ALLOC to allocate domains to be used as parent (stage-2) in nested translation. Add IOMMU_HWPT_ALLOC_NEST_PARENT to the uAPI. Link: https://lore.kernel.org/r/20230928071528.26258-5-yi.l.liu@intel.com Signed-off-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 89d6387 commit 4ff5421

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

drivers/iommu/iommufd/hw_pagetable.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
8383

8484
lockdep_assert_held(&ioas->mutex);
8585

86+
if (flags && !ops->domain_alloc_user)
87+
return ERR_PTR(-EOPNOTSUPP);
88+
8689
hwpt = iommufd_object_alloc(ictx, hwpt, IOMMUFD_OBJ_HW_PAGETABLE);
8790
if (IS_ERR(hwpt))
8891
return hwpt;
@@ -154,7 +157,7 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
154157
struct iommufd_ioas *ioas;
155158
int rc;
156159

157-
if (cmd->flags || cmd->__reserved)
160+
if ((cmd->flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) || cmd->__reserved)
158161
return -EOPNOTSUPP;
159162

160163
idev = iommufd_get_device(ucmd, cmd->dev_id);

include/uapi/linux/iommufd.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,20 @@ struct iommu_vfio_ioas {
347347
};
348348
#define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS)
349349

350+
/**
351+
* enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation
352+
* @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a domain which can serve
353+
* as the parent domain in the nesting
354+
* configuration.
355+
*/
356+
enum iommufd_hwpt_alloc_flags {
357+
IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0,
358+
};
359+
350360
/**
351361
* struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC)
352362
* @size: sizeof(struct iommu_hwpt_alloc)
353-
* @flags: Must be 0
363+
* @flags: Combination of enum iommufd_hwpt_alloc_flags
354364
* @dev_id: The device to allocate this HWPT for
355365
* @pt_id: The IOAS to connect this HWPT to
356366
* @out_hwpt_id: The ID of the new HWPT

0 commit comments

Comments
 (0)