iommu/vt-d: Enhance capability check for nested parent domain allocation
authorYi Liu <yi.l.liu@intel.com>
Tue, 24 Oct 2023 15:00:11 +0000 (08:00 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Thu, 26 Oct 2023 14:16:11 +0000 (11:16 -0300)
This adds the scalable mode check before allocating the nested parent domain
as checking nested capability is not enough. User may turn off scalable mode
which also means no nested support even if the hardware supports it.

Fixes: c97d1b20d383 ("iommu/vt-d: Add domain_alloc_user op")
Link: https://lore.kernel.org/r/20231024150011.44642-1-yi.l.liu@intel.com
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/intel/iommu.c
drivers/iommu/intel/iommu.h

index fe67f8d77b09eadbba6fd0ad2da84152f43eebc5..cb64759b3d95be0088570d58068d20296647790c 100644 (file)
@@ -4095,7 +4095,7 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags,
        if (!iommu)
                return ERR_PTR(-ENODEV);
 
-       if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap))
+       if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !nested_supported(iommu))
                return ERR_PTR(-EOPNOTSUPP);
 
        dirty_tracking = (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING);
index 3bb5691462292fe36f5323751f924ee2af368bbb..cc73015797737c877b308cc39e3ce65341cd25aa 100644 (file)
@@ -544,6 +544,8 @@ enum {
                                 ecap_pasid((iommu)->ecap))
 #define ssads_supported(iommu) (sm_supported(iommu) &&                 \
                                ecap_slads((iommu)->ecap))
+#define nested_supported(iommu)        (sm_supported(iommu) &&                 \
+                                ecap_nest((iommu)->ecap))
 
 struct pasid_entry;
 struct pasid_state_entry;