Skip to content

Commit a8ce9eb

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Preset Access/Dirty bits for IOVA over FL
The Access/Dirty bits in the first level page table entry will be set whenever a page table entry was used for address translation or write permission was successfully translated. This is always true when using the first-level page table for kernel IOVA. Instead of wasting hardware cycles to update the certain bits, it's better to set them up at the beginning. Suggested-by: Ashok Raj <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent f2dd871 commit a8ce9eb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,11 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,
10171017

10181018
domain_flush_cache(domain, tmp_page, VTD_PAGE_SIZE);
10191019
pteval = ((uint64_t)virt_to_dma_pfn(tmp_page) << VTD_PAGE_SHIFT) | DMA_PTE_READ | DMA_PTE_WRITE;
1020-
if (domain_use_first_level(domain))
1020+
if (domain_use_first_level(domain)) {
10211021
pteval |= DMA_FL_PTE_XD | DMA_FL_PTE_US;
1022+
if (domain->domain.type == IOMMU_DOMAIN_DMA)
1023+
pteval |= DMA_FL_PTE_ACCESS;
1024+
}
10221025
if (cmpxchg64(&pte->val, 0ULL, pteval))
10231026
/* Someone else set it while we were thinking; use theirs. */
10241027
free_pgtable_page(tmp_page);
@@ -2310,9 +2313,16 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
23102313
return -EINVAL;
23112314

23122315
attr = prot & (DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP);
2313-
if (domain_use_first_level(domain))
2316+
if (domain_use_first_level(domain)) {
23142317
attr |= DMA_FL_PTE_PRESENT | DMA_FL_PTE_XD | DMA_FL_PTE_US;
23152318

2319+
if (domain->domain.type == IOMMU_DOMAIN_DMA) {
2320+
attr |= DMA_FL_PTE_ACCESS;
2321+
if (prot & DMA_PTE_WRITE)
2322+
attr |= DMA_FL_PTE_DIRTY;
2323+
}
2324+
}
2325+
23162326
pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | attr;
23172327

23182328
while (nr_pages > 0) {

include/linux/intel-iommu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
#define DMA_FL_PTE_PRESENT BIT_ULL(0)
4444
#define DMA_FL_PTE_US BIT_ULL(2)
45+
#define DMA_FL_PTE_ACCESS BIT_ULL(5)
46+
#define DMA_FL_PTE_DIRTY BIT_ULL(6)
4547
#define DMA_FL_PTE_XD BIT_ULL(63)
4648

4749
#define ADDR_WIDTH_5LEVEL (57)

0 commit comments

Comments
 (0)