Skip to contentSkip to conversation

iommu/amd: Trivial fixes

PATCH Superseded Vasant Hegde 2 participants 16 messages Feb 25, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Vasant Hegde

author maintainer
#0 lore raw

cover iommu/amd: Trivial fixes

This series contains minor cleanup and trivial fixes.

base-commit: v6.14-rc3

Vasant Hegde (7):
iommu/amd: Log IOMMU control register in event log path iommu/amd: Remove unused variable iommu/amd/pgtbl_v2: Improve error handling iommu/amd: Remove outdated comment
iommu/amd: Fix header file
iommu/amd: Remove unused forward declaration iommu/amd: Make protection_domain as static

 drivers/iommu/amd/amd_iommu.h       | 8 +++-----
 drivers/iommu/amd/amd_iommu_types.h | 3 ---
 drivers/iommu/amd/init.c            | 1 -
 drivers/iommu/amd/io_pgtable.c      | 7 -------
 drivers/iommu/amd/io_pgtable_v2.c   | 2 +-
 drivers/iommu/amd/iommu.c           | 6 ++++--
 drivers/iommu/amd/pasid.c           | 2 +-
 7 files changed, 9 insertions(+), 20 deletions(-)
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/7 iommu/amd: Log IOMMU control register in event log path

Useful for debugging ILLEGAL_DEV_TABLE_ENTRY events as some of the DTE settings depends on Control register settings.

---
 drivers/iommu/amd/iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +3 -1
index b48a72bd7b23..797c8612966a 100644
@@ -868,7 +868,7 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
 	int type, devid, flags, tag;
 	volatile u32 *event = __evt;
 	int count = 0;
-	u64 address;
+	u64 address, ctrl;
 	u32 pasid;
 
 retry:
@@ -878,6 +878,7 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
 		  (event[1] & EVENT_DOMID_MASK_LO);
 	flags   = (event[1] >> EVENT_FLAGS_SHIFT) & EVENT_FLAGS_MASK;
 	address = (u64)(((u64)event[3]) << 32) | event[2];
+	ctrl    = readq(iommu->mmio_base + MMIO_CONTROL_OFFSET);
 
 	if (type == 0) {
 		/* Did we hit the erratum? */
@@ -899,6 +900,7 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
 		dev_err(dev, "Event logged [ILLEGAL_DEV_TABLE_ENTRY device=%04x:%02x:%02x.%x pasid=0x%05x address=0x%llx flags=0x%04x]\n",
 			iommu->pci_seg->id, PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
 			pasid, address, flags);
+		dev_err(dev, "Control Reg : 0x%llx\n", ctrl);
 		dump_dte_entry(iommu, devid);
 		break;
 	case EVENT_TYPE_DEV_TAB_ERR:
Signature · 1 line
2.31.1
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] iommu/amd: Log IOMMU control register in event log path

Quoted 7 lines · Vasant Hegde

Useful for debugging ILLEGAL_DEV_TABLE_ENTRY events as some of the DTE settings depends on Control register settings.

---
 drivers/iommu/amd/iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Jason

author maintainer
#3 lore raw

PATCH 2/7 iommu/amd: Remove unused variable

In reply to Vasant Hegde

Remove 'amd_iommu_aperture_order' as its not used since commit d9cfed925448.

---
 drivers/iommu/amd/amd_iommu_types.h | 3 ---
 1 file changed, 3 deletions(-)
drivers/iommu/amd/amd_iommu_types.h +0 -3
index 23caea22f8dc..3f57bdd0a659 100644
@@ -928,9 +928,6 @@ struct unity_map_entry {
  * Data structures for device handling
  */
 
-/* size of the dma_ops aperture as power of 2 */
-extern unsigned amd_iommu_aperture_order;
-
 extern bool amd_iommu_force_isolation;
 
 /* Max levels of glxval supported */
Signature · 1 line
2.31.1
author maintainer
#5 lore raw

PATCH 3/7 iommu/amd/pgtbl_v2: Improve error handling

In reply to Vasant Hegde

Return -ENOMEM if v2_alloc_pte() fails to allocate memory.

---
 drivers/iommu/amd/io_pgtable_v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/amd/io_pgtable_v2.c +1 -1
index c616de2c5926..a56a27396305 100644
@@ -254,7 +254,7 @@ static int iommu_v2_map_pages(struct io_pgtable_ops *ops, unsigned long iova,
 		pte = v2_alloc_pte(cfg->amd.nid, pgtable->pgd,
 				   iova, map_size, gfp, &updated);
 		if (!pte) {
-			ret = -EINVAL;
+			ret = -ENOMEM;
 			goto out;
 		}
 
Signature · 1 line
2.31.1
author maintainer
#7 lore raw

PATCH 4/7 iommu/amd: Remove outdated comment

In reply to Vasant Hegde

Remove outdated comment.

---
 drivers/iommu/amd/io_pgtable.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/iommu/amd/io_pgtable.c +0 -7
index f3399087859f..26cf562dde11 100644
@@ -47,13 +47,6 @@ static u64 *first_pte_l7(u64 *pte, unsigned long *page_size,
 	return fpte;
 }
 
-/****************************************************************************
- *
- * The functions below are used the create the page table mappings for
- * unity mapped regions.
- *
- ****************************************************************************/
-
 static void free_pt_page(u64 *pt, struct list_head *freelist)
 {
 	struct page *p = virt_to_page(pt);
Signature · 1 line
2.31.1
author maintainer
#9 lore raw

PATCH 5/7 iommu/amd: Fix header file

In reply to Vasant Hegde

Move function declaration inside AMD_IOMMU_H defination.

Fixes fd5dff9de4be ("iommu/amd: Modify set_dte_entry() to use 256-bit DTE helpers")
Fixes 457da5764668 ("iommu/amd: Lock DTE before updating the entry with WRITE_ONCE()")
Cc Suravee Suthikulpanit <[email protected]>
---
 drivers/iommu/amd/amd_iommu.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iommu/amd/amd_iommu.h +3 -4
index 68debf5ee2d7..e3bf27da1339 100644
@@ -176,12 +176,11 @@ void amd_iommu_apply_ivrs_quirks(void);
 #else
 static inline void amd_iommu_apply_ivrs_quirks(void) { }
 #endif
+struct dev_table_entry *amd_iommu_get_ivhd_dte_flags(u16 segid, u16 devid);
 
 void amd_iommu_domain_set_pgtable(struct protection_domain *domain,
 				  u64 *root, int mode);
 struct dev_table_entry *get_dev_table(struct amd_iommu *iommu);
-
-#endif
-
-struct dev_table_entry *amd_iommu_get_ivhd_dte_flags(u16 segid, u16 devid);
 struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid);
+
+#endif /* AMD_IOMMU_H */
Signature · 1 line
2.31.1
Reviewed-by on v1 5/7
#10 lore raw

Re: [PATCH 5/7] iommu/amd: Fix header file

Quoted 9 lines · Vasant Hegde

Move function declaration inside AMD_IOMMU_H defination.

Fixes fd5dff9de4be ("iommu/amd: Modify set_dte_entry() to use 256-bit DTE helpers")
Fixes 457da5764668 ("iommu/amd: Lock DTE before updating the entry with WRITE_ONCE()")
Cc Suravee Suthikulpanit <[email protected]>
---
 drivers/iommu/amd/amd_iommu.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Oh weird that happened

Jason

author maintainer
#11 lore raw

PATCH 6/7 iommu/amd: Remove unused forward declaration

In reply to Vasant Hegde

Remove unused forward declaration.

---
 drivers/iommu/amd/init.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iommu/amd/init.c +0 -1
index cb536d372b12..94aaa4b2a903 100644
@@ -219,7 +219,6 @@ static bool __initdata cmdline_maps;
 static enum iommu_init_state init_state = IOMMU_START_STATE;
 
 static int amd_iommu_enable_interrupts(void);
-static int __init iommu_go_to_state(enum iommu_init_state state);
 static void init_device_table_dma(struct amd_iommu_pci_seg *pci_seg);
 
 static bool amd_iommu_pre_enabled = true;
Signature · 1 line
2.31.1
author maintainer
#13 lore raw

PATCH 7/7 iommu/amd: Make protection_domain as static

In reply to Vasant Hegde

And update amd_iommu_domain_alloc_sva() error path to call amd_iommu_domain_free() directly.

---
 drivers/iommu/amd/amd_iommu.h | 1 -
 drivers/iommu/amd/iommu.c     | 2 +-
 drivers/iommu/amd/pasid.c     | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)
drivers/iommu/amd/amd_iommu.h +0 -1
index e3bf27da1339..220c598b7e14 100644
@@ -47,7 +47,6 @@ extern unsigned long amd_iommu_pgsize_bitmap;
 /* Protection domain ops */
 void amd_iommu_init_identity_domain(void);
 struct protection_domain *protection_domain_alloc(void);
-void protection_domain_free(struct protection_domain *domain);
 struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
 						struct mm_struct *mm);
 void amd_iommu_domain_free(struct iommu_domain *dom);
drivers/iommu/amd/iommu.c +1 -1
index 797c8612966a..f4c12dd10adf 100644
@@ -2434,7 +2434,7 @@ static struct iommu_group *amd_iommu_device_group(struct device *dev)
  *
  *****************************************************************************/
 
-void protection_domain_free(struct protection_domain *domain)
+static void protection_domain_free(struct protection_domain *domain)
 {
 	WARN_ON(!list_empty(&domain->dev_list));
 	if (domain->domain.type & __IOMMU_DOMAIN_PAGING)
drivers/iommu/amd/pasid.c +1 -1
index 11150cfd6718..77c8e9a91cbc 100644
@@ -195,7 +195,7 @@ struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
 
 	ret = mmu_notifier_register(&pdom->mn, mm);
 	if (ret) {
-		protection_domain_free(pdom);
+		amd_iommu_domain_free(&pdom->domain);
 		return ERR_PTR(ret);
 	}
 
Signature · 1 line
2.31.1
Reviewed-by on v1 7/7
#14 lore raw

Re: [PATCH 7/7] iommu/amd: Make protection_domain as static

Quoted 9 lines · Vasant Hegde

And update amd_iommu_domain_alloc_sva() error path to call amd_iommu_domain_free() directly.

---
 drivers/iommu/amd/amd_iommu.h | 1 -
 drivers/iommu/amd/iommu.c     | 2 +-
 drivers/iommu/amd/pasid.c     | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

Why do we even have protection_domain_free() just fold it into amd_iommu_domain_free()?

Jason

author maintainer
#15 lore raw

Re: [PATCH 7/7] iommu/amd: Make protection_domain as static

Jason,

Quoted 11 lines · Jason Gunthorpe
Quoted 9 lines · Vasant Hegde

And update amd_iommu_domain_alloc_sva() error path to call amd_iommu_domain_free() directly.

---
 drivers/iommu/amd/amd_iommu.h | 1 -
 drivers/iommu/amd/iommu.c     | 2 +-
 drivers/iommu/amd/pasid.c     | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)
Quoted 2 lines

Why do we even have protection_domain_free() just fold it into amd_iommu_domain_free()?

Yeah. We can do that. Will update.

Quoted 2 lines

Thanks
-Vasant