public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6
@ 2022-11-16  5:15 Lu Baolu
  2022-11-16  5:15 ` [PATCH 1/2] iommu/vt-d: Preset Access bit for IOVA in FL non-leaf paging entries Lu Baolu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Lu Baolu @ 2022-11-16  5:15 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Tina Zhang, iommu, linux-kernel

Hi Joerg,

Below fixes are queued for v6.1. They aim to fix:

- Preset Access bit in FL non-leaf paging entries.
- Avoid setting hardware Reserved(0) bit.

This series is also available at github.
https://github.com/LuBaolu/intel-iommu/commits/vtd-fix-for-v6.1-rc6

Please consider it for the iommu/fix branch.

Best regards,
Lu Baolu

Tina Zhang (2):
  iommu/vt-d: Preset Access bit for IOVA in FL non-leaf paging entries
  iommu/vt-d: Set SRE bit only when hardware has SRS cap

 drivers/iommu/intel/iommu.c | 8 +++-----
 drivers/iommu/intel/pasid.c | 5 +++--
 2 files changed, 6 insertions(+), 7 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] iommu/vt-d: Preset Access bit for IOVA in FL non-leaf paging entries
  2022-11-16  5:15 [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6 Lu Baolu
@ 2022-11-16  5:15 ` Lu Baolu
  2022-11-16  5:15 ` [PATCH 2/2] iommu/vt-d: Set SRE bit only when hardware has SRS cap Lu Baolu
  2022-11-19  9:47 ` [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6 Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Lu Baolu @ 2022-11-16  5:15 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Tina Zhang, iommu, linux-kernel

From: Tina Zhang <tina.zhang@intel.com>

The A/D bits are preseted for IOVA over first level(FL) usage for both
kernel DMA (i.e, domain typs is IOMMU_DOMAIN_DMA) and user space DMA
usage (i.e., domain type is IOMMU_DOMAIN_UNMANAGED).

Presetting A bit in FL requires to preset the bit in every related paging
entries, including the non-leaf ones. Otherwise, hardware may treat this
as an error. For example, in a case of ECAP_REG.SMPWC==0, DMA faults might
occur with below DMAR fault messages (wrapped for line length) dumped.

 DMAR: DRHD: handling fault status reg 2
 DMAR: [DMA Read NO_PASID] Request device [aa:00.0] fault addr 0x10c3a6000
    [fault reason 0x90]
    SM: A/D bit update needed in first-level entry when set up in no snoop

Fixes: 289b3b005cb9 ("iommu/vt-d: Preset A/D bits for user space DMA usage")
Cc: stable@vger.kernel.org
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
Link: https://lore.kernel.org/r/20221113010324.1094483-1-tina.zhang@intel.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/iommu.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 48cdcd0a5cf3..996a8b5ee5ee 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -959,11 +959,9 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,
 
 			domain_flush_cache(domain, tmp_page, VTD_PAGE_SIZE);
 			pteval = ((uint64_t)virt_to_dma_pfn(tmp_page) << VTD_PAGE_SHIFT) | DMA_PTE_READ | DMA_PTE_WRITE;
-			if (domain_use_first_level(domain)) {
-				pteval |= DMA_FL_PTE_XD | DMA_FL_PTE_US;
-				if (iommu_is_dma_domain(&domain->domain))
-					pteval |= DMA_FL_PTE_ACCESS;
-			}
+			if (domain_use_first_level(domain))
+				pteval |= DMA_FL_PTE_XD | DMA_FL_PTE_US | DMA_FL_PTE_ACCESS;
+
 			if (cmpxchg64(&pte->val, 0ULL, pteval))
 				/* Someone else set it while we were thinking; use theirs. */
 				free_pgtable_page(tmp_page);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] iommu/vt-d: Set SRE bit only when hardware has SRS cap
  2022-11-16  5:15 [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6 Lu Baolu
  2022-11-16  5:15 ` [PATCH 1/2] iommu/vt-d: Preset Access bit for IOVA in FL non-leaf paging entries Lu Baolu
@ 2022-11-16  5:15 ` Lu Baolu
  2022-11-19  9:47 ` [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6 Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Lu Baolu @ 2022-11-16  5:15 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: Tina Zhang, iommu, linux-kernel

From: Tina Zhang <tina.zhang@intel.com>

SRS cap is the hardware cap telling if the hardware IOMMU can support
requests seeking supervisor privilege or not. SRE bit in scalable-mode
PASID table entry is treated as Reserved(0) for implementation not
supporting SRS cap.

Checking SRS cap before setting SRE bit can avoid the non-recoverable
fault of "Non-zero reserved field set in PASID Table Entry" caused by
setting SRE bit while there is no SRS cap support. The fault messages
look like below:

 DMAR: DRHD: handling fault status reg 2
 DMAR: [DMA Read NO_PASID] Request device [00:0d.0] fault addr 0x1154e1000
       [fault reason 0x5a]
       SM: Non-zero reserved field set in PASID Table Entry

Fixes: 6f7db75e1c46 ("iommu/vt-d: Add second level page table interface")
Cc: stable@vger.kernel.org
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
Link: https://lore.kernel.org/r/20221115070346.1112273-1-tina.zhang@intel.com
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
 drivers/iommu/intel/pasid.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c
index c30ddac40ee5..e13d7e5273e1 100644
--- a/drivers/iommu/intel/pasid.c
+++ b/drivers/iommu/intel/pasid.c
@@ -642,7 +642,7 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,
 	 * Since it is a second level only translation setup, we should
 	 * set SRE bit as well (addresses are expected to be GPAs).
 	 */
-	if (pasid != PASID_RID2PASID)
+	if (pasid != PASID_RID2PASID && ecap_srs(iommu->ecap))
 		pasid_set_sre(pte);
 	pasid_set_present(pte);
 	spin_unlock(&iommu->lock);
@@ -685,7 +685,8 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
 	 * We should set SRE bit as well since the addresses are expected
 	 * to be GPAs.
 	 */
-	pasid_set_sre(pte);
+	if (ecap_srs(iommu->ecap))
+		pasid_set_sre(pte);
 	pasid_set_present(pte);
 	spin_unlock(&iommu->lock);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6
  2022-11-16  5:15 [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6 Lu Baolu
  2022-11-16  5:15 ` [PATCH 1/2] iommu/vt-d: Preset Access bit for IOVA in FL non-leaf paging entries Lu Baolu
  2022-11-16  5:15 ` [PATCH 2/2] iommu/vt-d: Set SRE bit only when hardware has SRS cap Lu Baolu
@ 2022-11-19  9:47 ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2022-11-19  9:47 UTC (permalink / raw)
  To: Lu Baolu; +Cc: Tina Zhang, iommu, linux-kernel

On Wed, Nov 16, 2022 at 01:15:42PM +0800, Lu Baolu wrote:
> Tina Zhang (2):
>   iommu/vt-d: Preset Access bit for IOVA in FL non-leaf paging entries
>   iommu/vt-d: Set SRE bit only when hardware has SRS cap
> 
>  drivers/iommu/intel/iommu.c | 8 +++-----
>  drivers/iommu/intel/pasid.c | 5 +++--
>  2 files changed, 6 insertions(+), 7 deletions(-)

Applied for v6.1, thanks Baolu and Tina.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-19  9:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-16  5:15 [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6 Lu Baolu
2022-11-16  5:15 ` [PATCH 1/2] iommu/vt-d: Preset Access bit for IOVA in FL non-leaf paging entries Lu Baolu
2022-11-16  5:15 ` [PATCH 2/2] iommu/vt-d: Set SRE bit only when hardware has SRS cap Lu Baolu
2022-11-19  9:47 ` [PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc6 Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox