]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iommu/vt-d: Report right snoop capability when using FL for IOVA
authorLu Baolu <baolu.lu@linux.intel.com>
Tue, 30 Mar 2021 02:11:45 +0000 (10:11 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 07:50:32 +0000 (09:50 +0200)
[ Upstream commit 6c00612d0cba10f7d0917cf1f73c945003ed4cd7 ]

The Intel VT-d driver checks wrong register to report snoop capablility
when using first level page table for GPA to HPA translation. This might
lead the IOMMU driver to say that it supports snooping control, but in
reality, it does not. Fix this by always setting PASID-table-entry.PGSNP
whenever a pasid entry is setting up for GPA to HPA translation so that
the IOMMU driver could report snoop capability as long as it runs in the
scalable mode.

Fixes: b802d070a52a1 ("iommu/vt-d: Use iova over first level")
Suggested-by: Rajesh Sankaran <rajesh.sankaran@intel.com>
Suggested-by: Kevin Tian <kevin.tian@intel.com>
Suggested-by: Ashok Raj <ashok.raj@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20210330021145.13824-1-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iommu/intel/iommu.c
drivers/iommu/intel/pasid.c
drivers/iommu/intel/pasid.h

index 7e3db4c0324d39d7746515a24c987b43aa6669cd..3295e5e162a463405c87f3aa851c5b9f24485b5f 100644 (file)
@@ -656,7 +656,14 @@ static int domain_update_iommu_snooping(struct intel_iommu *skip)
        rcu_read_lock();
        for_each_active_iommu(iommu, drhd) {
                if (iommu != skip) {
-                       if (!ecap_sc_support(iommu->ecap)) {
+                       /*
+                        * If the hardware is operating in the scalable mode,
+                        * the snooping control is always supported since we
+                        * always set PASID-table-entry.PGSNP bit if the domain
+                        * is managed outside (UNMANAGED).
+                        */
+                       if (!sm_supported(iommu) &&
+                           !ecap_sc_support(iommu->ecap)) {
                                ret = 0;
                                break;
                        }
@@ -2599,6 +2606,9 @@ static int domain_setup_first_level(struct intel_iommu *iommu,
 
        flags |= (level == 5) ? PASID_FLAG_FL5LP : 0;
 
+       if (domain->domain.type == IOMMU_DOMAIN_UNMANAGED)
+               flags |= PASID_FLAG_PAGE_SNOOP;
+
        return intel_pasid_setup_first_level(iommu, dev, (pgd_t *)pgd, pasid,
                                             domain->iommu_did[iommu->seq_id],
                                             flags);
index b92af83b79bdcf04732f37947994873d29ea8352..ce4ef2d245e3b72a0216fc9580840175f69ac233 100644 (file)
@@ -411,6 +411,16 @@ static inline void pasid_set_page_snoop(struct pasid_entry *pe, bool value)
        pasid_set_bits(&pe->val[1], 1 << 23, value << 23);
 }
 
+/*
+ * Setup the Page Snoop (PGSNP) field (Bit 88) of a scalable mode
+ * PASID entry.
+ */
+static inline void
+pasid_set_pgsnp(struct pasid_entry *pe)
+{
+       pasid_set_bits(&pe->val[1], 1ULL << 24, 1ULL << 24);
+}
+
 /*
  * Setup the First Level Page table Pointer field (Bit 140~191)
  * of a scalable mode PASID entry.
@@ -579,6 +589,9 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,
                }
        }
 
+       if (flags & PASID_FLAG_PAGE_SNOOP)
+               pasid_set_pgsnp(pte);
+
        pasid_set_domain_id(pte, did);
        pasid_set_address_width(pte, iommu->agaw);
        pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
@@ -657,6 +670,9 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,
        pasid_set_fault_enable(pte);
        pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
 
+       if (domain->domain.type == IOMMU_DOMAIN_UNMANAGED)
+               pasid_set_pgsnp(pte);
+
        /*
         * Since it is a second level only translation setup, we should
         * set SRE bit as well (addresses are expected to be GPAs).
index 444c0bec221a441a44d54d3533cc21da838a04b8..086ebd697319911f0020a419847ef80377b93512 100644 (file)
@@ -48,6 +48,7 @@
  */
 #define PASID_FLAG_SUPERVISOR_MODE     BIT(0)
 #define PASID_FLAG_NESTED              BIT(1)
+#define PASID_FLAG_PAGE_SNOOP          BIT(2)
 
 /*
  * The PASID_FLAG_FL5LP flag Indicates using 5-level paging for first-