iommufd: Add a flag to enforce dirty tracking on attach
authorJoao Martins <joao.m.martins@oracle.com>
Tue, 24 Oct 2023 13:50:56 +0000 (14:50 +0100)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 24 Oct 2023 14:58:42 +0000 (11:58 -0300)
Throughout IOMMU domain lifetime that wants to use dirty tracking, some
guarantees are needed such that any device attached to the iommu_domain
supports dirty tracking.

The idea is to handle a case where IOMMU in the system are assymetric
feature-wise and thus the capability may not be supported for all devices.
The enforcement is done by adding a flag into HWPT_ALLOC namely:

IOMMU_HWPT_ALLOC_DIRTY_TRACKING

.. Passed in HWPT_ALLOC ioctl() flags. The enforcement is done by creating
a iommu_domain via domain_alloc_user() and validating the requested flags
with what the device IOMMU supports (and failing accordingly) advertised).
Advertising the new IOMMU domain feature flag requires that the individual
iommu driver capability is supported when a future device attachment
happens.

Link: https://lore.kernel.org/r/20231024135109.73787-6-joao.m.martins@oracle.com
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/hw_pagetable.c
include/uapi/linux/iommufd.h

index 8b3d2875d642d9a8c1f8d6f2d51bb4d8145faa69..dd50ca9e2c0962a14b5da5c52607ddf766f7dbdb 100644 (file)
@@ -157,7 +157,9 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
        struct iommufd_ioas *ioas;
        int rc;
 
-       if ((cmd->flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT)) || cmd->__reserved)
+       if ((cmd->flags & ~(IOMMU_HWPT_ALLOC_NEST_PARENT |
+                           IOMMU_HWPT_ALLOC_DIRTY_TRACKING)) ||
+           cmd->__reserved)
                return -EOPNOTSUPP;
 
        idev = iommufd_get_device(ucmd, cmd->dev_id);
index be7a95042677b97641fa19b9fbc1712f0a3d2b0b..c76248410120ac2da1ab8fd9bb32fa3b8fcaba76 100644 (file)
@@ -351,9 +351,12 @@ struct iommu_vfio_ioas {
  * enum iommufd_hwpt_alloc_flags - Flags for HWPT allocation
  * @IOMMU_HWPT_ALLOC_NEST_PARENT: If set, allocate a HWPT that can serve as
  *                                the parent HWPT in a nesting configuration.
+ * @IOMMU_HWPT_ALLOC_DIRTY_TRACKING: Dirty tracking support for device IOMMU is
+ *                                   enforced on device attachment
  */
 enum iommufd_hwpt_alloc_flags {
        IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0,
+       IOMMU_HWPT_ALLOC_DIRTY_TRACKING = 1 << 1,
 };
 
 /**