]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
iommu/vt-d: Refine intel_iommu_domain_alloc_user()
authorLu Baolu <baolu.lu@linux.intel.com>
Mon, 4 Nov 2024 01:40:27 +0000 (09:40 +0800)
committerJoerg Roedel <jroedel@suse.de>
Tue, 5 Nov 2024 12:32:19 +0000 (13:32 +0100)
The domain_alloc_user ops should always allocate a guest-compatible page
table unless specific allocation flags are specified.

Currently, IOMMU_HWPT_ALLOC_NEST_PARENT and IOMMU_HWPT_ALLOC_DIRTY_TRACKING
require special handling, as both require hardware support for scalable
mode and second-stage translation. In such cases, the driver should select
a second-stage page table for the paging domain.

Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20241021085125.192333-8-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/intel/iommu.c

index bad9593f24641c9dc0bda18a66f6d35a59bcf3a5..2b5027dd0c961229c82184c8452feacd118af199 100644 (file)
@@ -3297,6 +3297,7 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
        struct intel_iommu *iommu = info->iommu;
        struct dmar_domain *dmar_domain;
        struct iommu_domain *domain;
+       bool first_stage;
 
        /* Must be NESTING domain */
        if (parent) {
@@ -3313,8 +3314,20 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
        if (user_data || (dirty_tracking && !ssads_supported(iommu)))
                return ERR_PTR(-EOPNOTSUPP);
 
-       /* Do not use first stage for user domain translation. */
-       dmar_domain = paging_domain_alloc(dev, false);
+       /*
+        * Always allocate the guest compatible page table unless
+        * IOMMU_HWPT_ALLOC_NEST_PARENT or IOMMU_HWPT_ALLOC_DIRTY_TRACKING
+        * is specified.
+        */
+       if (nested_parent || dirty_tracking) {
+               if (!sm_supported(iommu) || !ecap_slts(iommu->ecap))
+                       return ERR_PTR(-EOPNOTSUPP);
+               first_stage = false;
+       } else {
+               first_stage = first_level_by_default(iommu);
+       }
+
+       dmar_domain = paging_domain_alloc(dev, first_stage);
        if (IS_ERR(dmar_domain))
                return ERR_CAST(dmar_domain);
        domain = &dmar_domain->domain;