vtd: Minor cleanup
Subsystems (2)
cover vtd: Minor cleanup
Hi,
This cleanup the vtd dump code to dump entry when it's present. See patch log for details.
Thanks
Zhenzhong
Zhenzhong Duan (2):
iommu/vt-d: Fix checks in dmar_fault_dump_ptes() iommu/vt-d: Fix checks in pgtable_walk()
drivers/iommu/intel/iommu.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 iommu/vt-d: Fix checks in dmar_fault_dump_ptes()
In dmar_fault_dump_ptes(), return value of phys_to_virt() is used for checking if an entry is present. It's never NULL on x86 platform at least. This makes some zero entries are dumped like below:
[ 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
Fix it by checking present bit in all entries.
--- drivers/iommu/intel/iommu.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/iommu/intel/iommu.c +20 -11
@@ -733,12 +733,17 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,u8 devfn = source_id &0xff ;u8 bus = source_id >>8 ;struct dma_pte *pgtable; +u64 entry;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) { + entry = rt_entry->lo; +if (sm_supported (iommu) && devfn >=0x80 ) + entry = rt_entry->hi; + +if (!(entry &1 )) {pr_info ("root table entry is not present\n" );return ; }
@@ -766,28 +771,32 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, goto pgtable_walk; } +/* For request-without-pasid, get the pasid from context entry */ +if (pasid ==IOMMU_PASID_INVALID ) + pasid =IOMMU_NO_PASID ; +/* get the pointer to pasid directory entry */ dir =phys_to_virt (ctx_entry->lo &VTD_PAGE_MASK ); -if (!dir) { + dir_index = pasid >>PASID_PDE_SHIFT ; + pde = &dir[dir_index]; + +if (!pasid_pde_is_present (pde)) {pr_info ("pasid directory entry is not present\n" );return ; } -/* For request-without-pasid, get the pasid from context entry */ -if (intel_iommu_sm && pasid ==IOMMU_PASID_INVALID ) - pasid =IOMMU_NO_PASID ; - dir_index = pasid >>PASID_PDE_SHIFT ; - pde = &dir[dir_index];pr_info ("pasid dir entry: 0x%016llx\n" , pde->val);/* get the pointer to the pasid table entry */ - entries =get_pasid_table_from_pde (pde); -if (!entries) { + entries =phys_to_virt (READ_ONCE (pde->val) &PDE_PFN_MASK ); + index = pasid &PASID_PTE_MASK ; + pte = &entries[index]; + +if (!pasid_pte_is_present (pte)) {pr_info ("pasid table entry is not present\n" );return ; } - index = pasid &PASID_PTE_MASK ; - pte = &entries[index]; +for (i =0 ; i <ARRAY_SIZE (pte->val); i++)pr_info ("pasid table entry[%d]: 0x%016llx\n" , i, pte->val[i]);
Signature · 1 line
2.34.1
Baolu Lu
maintainerRe: [PATCH 1/2] iommu/vt-d: Fix checks in dmar_fault_dump_ptes()
Quoted 15 lines · Zhenzhong Duan
In
dmar_fault_dump_ptes(), return value ofphys_to_virt()is used for checking if an entry is present. It's never NULL on x86 platform at least. This makes some zero entries are dumped like below:[ 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
Quoted 3 lines
Fix it by checking present bit in all entries.
Signed-off-by Zhenzhong Duan <[email protected]>
It seems that we still need a Fixes tag here.
Quoted 28 lines
--- drivers/iommu/intel/iommu.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)drivers/iommu/intel/iommu.c +6
-1@@ -733,12 +733,17 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,u8 devfn = source_id &0xff ;u8 bus = source_id >>8 ;struct dma_pte *pgtable; +u64 entry;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) { + entry = rt_entry->lo; +if (sm_supported (iommu) && devfn >=0x80 ) + entry = rt_entry->hi; + +if (!(entry &1 )) {pr_info ("root table entry is not present\n" );return ; }
drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, · line 779
Quoted 9 lines
drivers/iommu/intel/iommu.c +4
-0@@ -766,28 +771,32 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, goto pgtable_walk; } +/* For request-without-pasid, get the pasid from context entry */ +if (pasid ==IOMMU_PASID_INVALID ) + pasid =IOMMU_NO_PASID ; +/* get the pointer to pasid directory entry */ dir =phys_to_virt (ctx_entry->lo &VTD_PAGE_MASK );
Is above code correct in the scalable mode?
Quoted 23 lines
drivers/iommu/intel/iommu.c +8
-8-if (!dir) { + dir_index = pasid >>PASID_PDE_SHIFT ; + pde = &dir[dir_index]; + +if (!pasid_pde_is_present (pde)) {pr_info ("pasid directory entry is not present\n" );return ; } -/* For request-without-pasid, get the pasid from context entry */ -if (intel_iommu_sm && pasid ==IOMMU_PASID_INVALID ) - pasid =IOMMU_NO_PASID ; - dir_index = pasid >>PASID_PDE_SHIFT ; - pde = &dir[dir_index];pr_info ("pasid dir entry: 0x%016llx\n" , pde->val);/* get the pointer to the pasid table entry */ - entries =get_pasid_table_from_pde (pde); -if (!entries) { + entries =phys_to_virt (READ_ONCE (pde->val) &PDE_PFN_MASK ); + index = pasid &PASID_PTE_MASK ; + pte = &entries[index]; +
drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, · line 802
Quoted 10 lines
drivers/iommu/intel/iommu.c +2
-2+if (!pasid_pte_is_present (pte)) {pr_info ("pasid table entry is not present\n" );return ; } - index = pasid &PASID_PTE_MASK ; - pte = &entries[index]; +for (i =0 ; i <ARRAY_SIZE (pte->val); i++)pr_info ("pasid table entry[%d]: 0x%016llx\n" , i, pte->val[i]);
Thanks,
baolu
RE: [PATCH 1/2] iommu/vt-d: Fix checks in dmar_fault_dump_ptes()
Quoted 22 lines
-----Original Message-----
From: Baolu Lu <[email protected]>
Subject: Re: [PATCH 1/2] iommu/vt-d: Fix checks indmar_fault_dump_ptes()Quoted 15 lines · Zhenzhong Duan
In
dmar_fault_dump_ptes(), return value ofphys_to_virt()is used for checking if an entry is present. It's never NULL on x86 platform at least. This makes some zero entries are dumped like below:[ 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
Quoted 5 lines
Quoted 3 lines
Fix it by checking present bit in all entries.
Signed-off-by Zhenzhong Duan <[email protected]>It seems that we still need a Fixes tag here.
OK, will add.
Quoted 34 lines
drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu
Quoted 10 lines
--- drivers/iommu/intel/iommu.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)drivers/iommu/intel/iommu.c +0
-0@@ -733,12 +733,17 @@ void dmar_fault_dump_ptes(struct intel_iommu*iommu, u16
source_id,drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu
Quoted 19 lines
drivers/iommu/intel/iommu.c +6
-1u8 devfn = source_id &0xff ;u8 bus = source_id >>8 ;struct dma_pte *pgtable; +u64 entry;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) { + entry = rt_entry->lo; +if (sm_supported (iommu) && devfn >=0x80 ) + entry = rt_entry->hi; + +if (!(entry &1 )) {pr_info ("root table entry is not present\n" );return ; }@@ -766,28 +771,32 @@ void dmar_fault_dump_ptes(struct intel_iommu*iommu, u16
source_id,Quoted 3 lines
drivers/iommu/intel/iommu.c +0
-0goto pgtable_walk; }
Quoted 8 lines
drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, · line 779
Quoted 6 lines
drivers/iommu/intel/iommu.c +4
-0+/* For request-without-pasid, get the pasid from context entry */ +if (pasid ==IOMMU_PASID_INVALID ) + pasid =IOMMU_NO_PASID ; +/* get the pointer to pasid directory entry */ dir =phys_to_virt (ctx_entry->lo &VTD_PAGE_MASK );Is above code correct in the scalable mode?
I didn't find issue, could you show some light?
Thanks
Zhenzhong
Quoted 37 lines
Quoted 24 lines
drivers/iommu/intel/iommu.c +8
-8-if (!dir) { + dir_index = pasid >>PASID_PDE_SHIFT ; + pde = &dir[dir_index]; + +if (!pasid_pde_is_present (pde)) {pr_info ("pasid directory entry is not present\n" );return ; } -/* For request-without-pasid, get the pasid from context entry */ -if (intel_iommu_sm && pasid ==IOMMU_PASID_INVALID ) - pasid =IOMMU_NO_PASID ; - dir_index = pasid >>PASID_PDE_SHIFT ; - pde = &dir[dir_index];pr_info ("pasid dir entry: 0x%016llx\n" , pde->val);/* get the pointer to the pasid table entry */ - entries =get_pasid_table_from_pde (pde); -if (!entries) { + entries =phys_to_virt (READ_ONCE (pde->val) &PDE_PFN_MASK ); + index = pasid &PASID_PTE_MASK ; + pte = &entries[index]; +drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, · line 802
Quoted 10 lines
drivers/iommu/intel/iommu.c +2
-2+if (!pasid_pte_is_present (pte)) {pr_info ("pasid table entry is not present\n" );return ; } - index = pasid &PASID_PTE_MASK ; - pte = &entries[index]; +for (i =0 ; i <ARRAY_SIZE (pte->val); i++)pr_info ("pasid table entry[%d]: 0x%016llx\n" , i, pte->val[i]);Thanks,
baolu
Baolu Lu
maintainerRe: [PATCH 1/2] iommu/vt-d: Fix checks in dmar_fault_dump_ptes()
Quoted 33 lines · Zhenzhong
Quoted 33 lines
drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu
Quoted 9 lines
--- drivers/iommu/intel/iommu.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-)drivers/iommu/intel/iommu.c +0
-0@@ -733,12 +733,17 @@ void dmar_fault_dump_ptes(struct intel_iommu*iommu, u16
source_id,drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu
Quoted 19 lines
drivers/iommu/intel/iommu.c +6
-1u8 devfn = source_id &0xff ;u8 bus = source_id >>8 ;struct dma_pte *pgtable; +u64 entry;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) { + entry = rt_entry->lo; +if (sm_supported (iommu) && devfn >=0x80 ) + entry = rt_entry->hi; + +if (!(entry &1 )) {pr_info ("root table entry is not present\n" );return ; }@@ -766,28 +771,32 @@ void dmar_fault_dump_ptes(struct intel_iommu*iommu, u16
source_id,Quoted 3 lines
drivers/iommu/intel/iommu.c +0
-0goto pgtable_walk; }
Quoted 8 lines
Quoted 7 lines
drivers/iommu/intel/iommu.c void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, · line 779
Quoted 6 lines
drivers/iommu/intel/iommu.c +4
-0+/* For request-without-pasid, get the pasid from context entry */ +if (pasid ==IOMMU_PASID_INVALID ) + pasid =IOMMU_NO_PASID ; +/* get the pointer to pasid directory entry */ dir =phys_to_virt (ctx_entry->lo &VTD_PAGE_MASK );Is above code correct in the scalable mode?
I didn't find issue, could you show some light?
It's fine. I just mixed it with the root entry.
Thanks,
baolu
PATCH 2/2 iommu/vt-d: Fix checks in pgtable_walk()
In reply to Zhenzhong DuanIt's not accurate to dump super page as non-present page, meanwhile bit7 in first level page table entry is PAT bit, also pointer pte is never NULL in pgtable_walk() context.
--- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +2 -2
@@ -707,14 +707,14 @@ 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))) { +if (!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 (level ==1 ||dma_pte_superpage (pte))break ; parent =phys_to_virt (dma_pte_addr (pte));
Signature · 1 line
2.34.1
Baolu Lu
maintainerRe: [PATCH 2/2] iommu/vt-d: Fix checks in pgtable_walk()
Quoted 2 lines · Zhenzhong Duan
It's not accurate to dump super page as non-present page, meanwhile bit7 in first level page table entry is PAT bit,
Can you please explain how the 'bit7 in first level page table entry' is relevant to the changes made in this patch?
Also, please make full use of the maximum length of the commit message line.
Quoted 19 lines
also pointer pte is never NULL in
pgtable_walk()context.Fixes 914ff7719e8a ("iommu/vt-d: Dump DMAR translation structure when DMA fault occurs")Signed-off-by Zhenzhong Duan <[email protected]>--- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iommu/intel/iommu.c +1
-1@@ -707,14 +707,14 @@ 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))) { +if (!dma_pte_present (pte)) {pr_info ("PTE not present at level %d\n" , level);
drivers/iommu/intel/iommu.c static void pgtable_walk(struct intel_iommu *iommu, unsigned long pfn, · line 720
Quoted 10 lines
drivers/iommu/intel/iommu.c +1
-1break ; }pr_info ("pte level: %d, pte value: 0x%016llx\n" , level, pte->val); -if (level ==1 ) +if (level ==1 ||dma_pte_superpage (pte))break ; parent =phys_to_virt (dma_pte_addr (pte));
Thanks,
baolu
RE: [PATCH 2/2] iommu/vt-d: Fix checks in pgtable_walk()
Quoted 7 lines
-----Original Message-----
From: Baolu Lu <[email protected]>
Sent: Wednesday, October 23, 2024 12:50 PM
Subject: Re: [PATCH 2/2] iommu/vt-d: Fix checks inpgtable_walk()
Quoted 6 lines
Quoted 2 lines · Zhenzhong Duan
It's not accurate to dump super page as non-present page, meanwhile bit7 in first level page table entry is PAT bit,
Can you please explain how the 'bit7 in first level page table entry' is relevant to the changes made in this patch?
When iterate to level 1, it is leaf page table entry, bit 7 is PAT bit instead of PS bit. dma_pte_superpage(pte) may return true, then " PTE not present at level 1" may be printed out.
Quoted 3 lines
Also, please make full use of the maximum length of the commit message line.
Sure.
Thanks
Zhenzhong
Quoted 35 lines
Quoted 4 lines
also pointer pte is never NULL in
pgtable_walk()context.Fixes 914ff7719e8a ("iommu/vt-d: Dump DMAR translation structure whenDMA fault occurs")
drivers/iommu/intel/iommu.c static void pgtable_walk(struct intel_iommu *iommu,
Quoted 10 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iommu/intel/iommu.c +0
-0@@ -707,14 +707,14 @@ static void pgtable_walk(struct intel_iommu *iommu,unsigned long pfn,
Quoted 6 lines
drivers/iommu/intel/iommu.c +1
-1while (1 ) { offset =pfn_level_offset (pfn, level); pte = &parent[offset]; -if (!pte || (dma_pte_superpage (pte) || !dma_pte_present (pte))) { +if (!dma_pte_present (pte)) {pr_info ("PTE not present at level %d\n" , level);drivers/iommu/intel/iommu.c static void pgtable_walk(struct intel_iommu *iommu, unsigned long pfn, · line 720
Quoted 10 lines
drivers/iommu/intel/iommu.c +1
-1break ; }pr_info ("pte level: %d, pte value: 0x%016llx\n" , level, pte->val); -if (level ==1 ) +if (level ==1 ||dma_pte_superpage (pte))break ; parent =phys_to_virt (dma_pte_addr (pte));Thanks,
baolu
Baolu Lu
maintainerRe: [PATCH 2/2] iommu/vt-d: Fix checks in pgtable_walk()
Quoted 5 lines · Zhenzhong
Quoted 5 lines
-----Original Message-----
From: Baolu Lu<[email protected]>
Sent: Wednesday, October 23, 2024 12:50 PM
Subject: Re: [PATCH 2/2] iommu/vt-d: Fix checks inpgtable_walk()
Quoted 8 lines
Quoted 5 lines · Zhenzhong Duan
Quoted 2 lines
It's not accurate to dump super page as non-present page, meanwhile bit7 in first level page table entry is PAT bit,
Can you please explain how the 'bit7 in first level page table entry' is relevant to the changes made in this patch?
When iterate to level 1, it is leaf page table entry, bit 7 is PAT bit instead of PS bit.
dma_pte_superpage(pte)may return true, then " PTE not present at level 1" may be printed out.
I see. Thank you!
If you have a new version, can you please make it a bit clearer? My understanding is that dma_pte_superpage(pte) should not check against the leaf page table entries, right?
Thanks,
baolu
RE: [PATCH 2/2] iommu/vt-d: Fix checks in pgtable_walk()
Quoted 20 lines
-----Original Message-----
From: Baolu Lu <[email protected]>
Subject: Re: [PATCH 2/2] iommu/vt-d: Fix checks inpgtable_walk()Quoted 11 lines · Zhenzhong
Quoted 10 lines
-----Original Message-----
From: Baolu Lu<[email protected]>
Sent: Wednesday, October 23, 2024 12:50 PM
Subject: Re: [PATCH 2/2] iommu/vt-d: Fix checks inpgtable_walk()Quoted 2 lines · Zhenzhong Duan
It's not accurate to dump super page as non-present page, meanwhile bit7 in first level page table entry is PAT bit,
Can you please explain how the 'bit7 in first level page table entry' is relevant to the changes made in this patch?
When iterate to level 1, it is leaf page table entry, bit 7 is PAT bit instead of PS
bit.
Quoted 1 line
dma_pte_superpage(pte)may return true, then " PTE not present at level 1"
Quoted 8 lines
may
Quoted 1 line
be printed out.
I see. Thank you!
If you have a new version, can you please make it a bit clearer? My understanding is that
dma_pte_superpage(pte)should not check against the leaf page table entries, right?
Right, will do.
Thanks
Zhenzhong