* [PATCH v3 0/2] vtd: Minor cleanup
@ 2024-10-24 9:21 Zhenzhong Duan
2024-10-24 9:21 ` [PATCH v3 1/2] iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes() Zhenzhong Duan
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Zhenzhong Duan @ 2024-10-24 9:21 UTC (permalink / raw)
To: iommu, linux-kernel
Cc: dwmw2, baolu.lu, joro, will, robin.murphy, chao.p.peng, Zhenzhong Duan
Hi,
This cleanup the vtd dump code to dump lower entry after check current
level entry's present bit. Also fix the print to avoid confusing.
See patch log for details.
Thanks
Zhenzhong
Changelog:
v3:
- Fix a missed check
- Refine commit log further
v2:
- Add Fixes tag in patch1 (Baolu)
- Refine commit log in patch2 (Baolu)
Zhenzhong Duan (2):
iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes()
iommu/vt-d: Fix checks and print in pgtable_walk()
drivers/iommu/intel/iommu.c | 40 ++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 14 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 1/2] iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes()
2024-10-24 9:21 [PATCH v3 0/2] vtd: Minor cleanup Zhenzhong Duan
@ 2024-10-24 9:21 ` Zhenzhong Duan
2024-10-24 9:21 ` [PATCH v3 2/2] iommu/vt-d: Fix checks and print in pgtable_walk() Zhenzhong Duan
2024-10-29 4:42 ` [PATCH v3 0/2] vtd: Minor cleanup Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Zhenzhong Duan @ 2024-10-24 9:21 UTC (permalink / raw)
To: iommu, linux-kernel
Cc: dwmw2, baolu.lu, joro, will, robin.murphy, chao.p.peng,
Zhenzhong Duan, Kyung Min Park
There are some issues in dmar_fault_dump_ptes():
1. return value of phys_to_virt() is used for checking if an entry is
present.
2. dump is confusing, e.g., "pasid table entry is not present", confusing
by unpresent pasid table vs. unpresent pasid table entry. Current code
means the former.
3. pgtable_walk() is called without checking if page table is present.
Fix 1 by checking present bit of an entry before dump a lower level entry.
Fix 2 by removing "entry" string, e.g., "pasid table is not present".
Fix 3 by checking page table present before walk.
Take issue 3 for example, before fix:
[ 442.240357] DMAR: pasid dir entry: 0x000000012c83e001
[ 442.246661] DMAR: pasid table entry[0]: 0x0000000000000000
[ 442.253429] DMAR: pasid table entry[1]: 0x0000000000000000
[ 442.260203] DMAR: pasid table entry[2]: 0x0000000000000000
[ 442.266969] DMAR: pasid table entry[3]: 0x0000000000000000
[ 442.273733] DMAR: pasid table entry[4]: 0x0000000000000000
[ 442.280479] DMAR: pasid table entry[5]: 0x0000000000000000
[ 442.287234] DMAR: pasid table entry[6]: 0x0000000000000000
[ 442.293989] DMAR: pasid table entry[7]: 0x0000000000000000
[ 442.300742] DMAR: PTE not present at level 2
After fix:
...
[ 357.241214] DMAR: pasid table entry[6]: 0x0000000000000000
[ 357.248022] DMAR: pasid table entry[7]: 0x0000000000000000
[ 357.254824] DMAR: scalable mode page table is not present
Fixes: 914ff7719e8a ("iommu/vt-d: Dump DMAR translation structure when DMA fault occurs")
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
drivers/iommu/intel/iommu.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index a564eeaf2375..e7a711a42528 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -737,11 +737,11 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,
pr_info("Dump %s table entries for IOVA 0x%llx\n", iommu->name, addr);
/* root entry dump */
- rt_entry = &iommu->root_entry[bus];
- if (!rt_entry) {
- pr_info("root table entry is not present\n");
+ if (!iommu->root_entry) {
+ pr_info("root table is not present\n");
return;
}
+ rt_entry = &iommu->root_entry[bus];
if (sm_supported(iommu))
pr_info("scalable mode root entry: hi 0x%016llx, low 0x%016llx\n",
@@ -752,7 +752,7 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,
/* context entry dump */
ctx_entry = iommu_context_addr(iommu, bus, devfn, 0);
if (!ctx_entry) {
- pr_info("context table entry is not present\n");
+ pr_info("context table is not present\n");
return;
}
@@ -761,17 +761,23 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,
/* legacy mode does not require PASID entries */
if (!sm_supported(iommu)) {
+ if (!context_present(ctx_entry)) {
+ pr_info("legacy mode page table is not present\n");
+ return;
+ }
level = agaw_to_level(ctx_entry->hi & 7);
pgtable = phys_to_virt(ctx_entry->lo & VTD_PAGE_MASK);
goto pgtable_walk;
}
- /* get the pointer to pasid directory entry */
- dir = phys_to_virt(ctx_entry->lo & VTD_PAGE_MASK);
- if (!dir) {
- pr_info("pasid directory entry is not present\n");
+ if (!context_present(ctx_entry)) {
+ pr_info("pasid directory table is not present\n");
return;
}
+
+ /* get the pointer to pasid directory entry */
+ dir = phys_to_virt(ctx_entry->lo & VTD_PAGE_MASK);
+
/* For request-without-pasid, get the pasid from context entry */
if (intel_iommu_sm && pasid == IOMMU_PASID_INVALID)
pasid = IOMMU_NO_PASID;
@@ -783,7 +789,7 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,
/* get the pointer to the pasid table entry */
entries = get_pasid_table_from_pde(pde);
if (!entries) {
- pr_info("pasid table entry is not present\n");
+ pr_info("pasid table is not present\n");
return;
}
index = pasid & PASID_PTE_MASK;
@@ -791,6 +797,11 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,
for (i = 0; i < ARRAY_SIZE(pte->val); i++)
pr_info("pasid table entry[%d]: 0x%016llx\n", i, pte->val[i]);
+ if (!pasid_pte_is_present(pte)) {
+ pr_info("scalable mode page table is not present\n");
+ return;
+ }
+
if (pasid_pte_get_pgtt(pte) == PASID_ENTRY_PGTT_FL_ONLY) {
level = pte->val[2] & BIT_ULL(2) ? 5 : 4;
pgtable = phys_to_virt(pte->val[2] & VTD_PAGE_MASK);
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v3 2/2] iommu/vt-d: Fix checks and print in pgtable_walk()
2024-10-24 9:21 [PATCH v3 0/2] vtd: Minor cleanup Zhenzhong Duan
2024-10-24 9:21 ` [PATCH v3 1/2] iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes() Zhenzhong Duan
@ 2024-10-24 9:21 ` Zhenzhong Duan
2024-10-29 4:42 ` [PATCH v3 0/2] vtd: Minor cleanup Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Zhenzhong Duan @ 2024-10-24 9:21 UTC (permalink / raw)
To: iommu, linux-kernel
Cc: dwmw2, baolu.lu, joro, will, robin.murphy, chao.p.peng,
Zhenzhong Duan, Kyung Min Park
There are some issues in pgtable_walk():
1. Super page is dumped as non-present page
2. dma_pte_superpage() should not check against leaf page table entries
3. Pointer pte is never NULL so checking it is meaningless
4. When an entry is not present, it still makes sense to dump the entry
content.
Fix 1,2 by checking dma_pte_superpage()'s returned value after level check.
Fix 3 by removing pte check.
Fix 4 by checking persent bit after printing.
By this chance, change to print "page table not present" instead of "PTE
not present" to be clearer.
Fixes: 914ff7719e8a ("iommu/vt-d: Dump DMAR translation structure when DMA fault occurs")
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
drivers/iommu/intel/iommu.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index e7a711a42528..6c9a69a89b81 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -707,14 +707,15 @@ static void pgtable_walk(struct intel_iommu *iommu, unsigned long pfn,
while (1) {
offset = pfn_level_offset(pfn, level);
pte = &parent[offset];
- if (!pte || (dma_pte_superpage(pte) || !dma_pte_present(pte))) {
- pr_info("PTE not present at level %d\n", level);
- break;
- }
pr_info("pte level: %d, pte value: 0x%016llx\n", level, pte->val);
- if (level == 1)
+ if (!dma_pte_present(pte)) {
+ pr_info("page table not present at level %d\n", level - 1);
+ break;
+ }
+
+ if (level == 1 || dma_pte_superpage(pte))
break;
parent = phys_to_virt(dma_pte_addr(pte));
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 0/2] vtd: Minor cleanup
2024-10-24 9:21 [PATCH v3 0/2] vtd: Minor cleanup Zhenzhong Duan
2024-10-24 9:21 ` [PATCH v3 1/2] iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes() Zhenzhong Duan
2024-10-24 9:21 ` [PATCH v3 2/2] iommu/vt-d: Fix checks and print in pgtable_walk() Zhenzhong Duan
@ 2024-10-29 4:42 ` Baolu Lu
2 siblings, 0 replies; 4+ messages in thread
From: Baolu Lu @ 2024-10-29 4:42 UTC (permalink / raw)
To: Zhenzhong Duan, iommu, linux-kernel
Cc: baolu.lu, dwmw2, joro, will, robin.murphy, chao.p.peng
On 2024/10/24 17:21, Zhenzhong Duan wrote:
> Hi,
>
> This cleanup the vtd dump code to dump lower entry after check current
> level entry's present bit. Also fix the print to avoid confusing.
>
> See patch log for details.
>
> Thanks
> Zhenzhong
>
> Changelog:
> v3:
> - Fix a missed check
> - Refine commit log further
>
> v2:
> - Add Fixes tag in patch1 (Baolu)
> - Refine commit log in patch2 (Baolu)
>
>
> Zhenzhong Duan (2):
> iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes()
> iommu/vt-d: Fix checks and print in pgtable_walk()
>
> drivers/iommu/intel/iommu.c | 40 ++++++++++++++++++++++++-------------
> 1 file changed, 26 insertions(+), 14 deletions(-)
Queued for v6.13. Thank you!
--
baolu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-29 4:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-24 9:21 [PATCH v3 0/2] vtd: Minor cleanup Zhenzhong Duan
2024-10-24 9:21 ` [PATCH v3 1/2] iommu/vt-d: Fix checks and print in dmar_fault_dump_ptes() Zhenzhong Duan
2024-10-24 9:21 ` [PATCH v3 2/2] iommu/vt-d: Fix checks and print in pgtable_walk() Zhenzhong Duan
2024-10-29 4:42 ` [PATCH v3 0/2] vtd: Minor cleanup Baolu Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®