iommufd: Support allocating nested parent domain
authorYi Liu <yi.l.liu@intel.com>
Thu, 28 Sep 2023 07:15:26 +0000 (00:15 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 10 Oct 2023 16:31:24 +0000 (13:31 -0300)
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>
drivers/iommu/iommufd/hw_pagetable.c
include/uapi/linux/iommufd.h

index 5be7a31cbd9cfc9fe7c10c73e14253a41adc128e..8b3d2875d642d9a8c1f8d6f2d51bb4d8145faa69 100644 (file)
@@ -83,6 +83,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
 
        lockdep_assert_held(&ioas->mutex);
 
+       if (flags && !ops->domain_alloc_user)
+               return ERR_PTR(-EOPNOTSUPP);
+
        hwpt = iommufd_object_alloc(ictx, hwpt, IOMMUFD_OBJ_HW_PAGETABLE);
        if (IS_ERR(hwpt))
                return hwpt;
@@ -154,7 +157,7 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
        struct iommufd_ioas *ioas;
        int rc;
 
-       if (cmd->flags || cmd->__reserved)
+       if ((cmd->flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) || cmd->__reserved)
                return -EOPNOTSUPP;
 
        idev = iommufd_get_device(ucmd, cmd->dev_id);
index b4ba0c0cbab6b8b1562fa359d34f9835a9cde757..4a7c5c8fdbb44293bdd8482bcb53e1e81d58833b 100644 (file)
@@ -347,10 +347,20 @@ struct iommu_vfio_ioas {
 };
 #define IOMMU_VFIO_IOAS _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VFIO_IOAS)
 
+/**
+ * enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation
+ * @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a domain which can serve
+ *                                as the parent domain in the nesting
+ *                                configuration.
+ */
+enum iommufd_hwpt_alloc_flags {
+       IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0,
+};
+
 /**
  * struct iommu_hwpt_alloc - ioctl(IOMMU_HWPT_ALLOC)
  * @size: sizeof(struct iommu_hwpt_alloc)
- * @flags: Must be 0
+ * @flags: Combination of enum iommufd_hwpt_alloc_flags
  * @dev_id: The device to allocate this HWPT for
  * @pt_id: The IOAS to connect this HWPT to
  * @out_hwpt_id: The ID of the new HWPT