Skip to contentSkip to conversation

iommu/vt-d: Present Access bit for IOVA in FL non-leaf paging entries

PATCH In review Tina Zhang 2 participants 3 messages Nov 13, 2022 – Nov 16, 2022

Subsystems (2)
lore
Share & tools
lore

Tina Zhang

author
#0 lore raw

PATCH 1/1 iommu/vt-d: Present Access bit for IOVA in FL non-leaf paging entries

The A/D bits are presented 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).

Preseting A bit in FL requires to present the bit in very related paging entries, including the non-leaf ones. Otherwise, DMA fault may come out. For example, in a case of ECAP_REG.SMPWC==0, the DMA fault would be "SM: A/D bit update needed in first-level entry when set up in no snoop".

---
 drivers/iommu/intel/iommu.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iommu/intel/iommu.c +3 -5
index 48cdcd0a5cf3..996a8b5ee5ee 100644
@@ -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);
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 11 lines · Tina Zhang

The A/D bits are presented 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).

Preseting A bit in FL requires to present the bit in very related paging entries, including the non-leaf ones. Otherwise, DMA fault may come out. For example, in a case of ECAP_REG.SMPWC==0, the DMA fault would be "SM: A/D bit update needed in first-level entry when set up in no snoop".

Thanks for this patch.

Fixes 289b3b005cb9 ("iommu/vt-d: Preset A/D bits for user space DMA usage")

Best regards,
baolu

Quoted 23 lines
---
  drivers/iommu/intel/iommu.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
drivers/iommu/intel/iommu.c +3 -5
index 48cdcd0a5cf3..996a8b5ee5ee 100644
@@ -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);
maintainer
#2 lore raw
In reply to Tina Zhang
Quoted 11 lines · Tina Zhang

The A/D bits are presented 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).

Preseting A bit in FL requires to present the bit in very related paging entries, including the non-leaf ones. Otherwise, DMA fault may come out. For example, in a case of ECAP_REG.SMPWC==0, the DMA fault would be "SM: A/D bit update needed in first-level entry when set up in no snoop".

Patch queued for v6.1. Thank you!

https://lore.kernel.org/linux-iommu/[email protected]/

Best regards,
baolu