Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH v2 0/7] iommu/amd: Trivial fixes
@ 2025-02-27 16:23 Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 1/7] iommu/amd: Log IOMMU control register in event log path Vasant Hegde
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-27 16:23 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Vasant Hegde

This series contains minor cleanup and trivial fixes.

Changes from v1 -> v2:
  - Consolidated protection domain free code and removed
    protection_domain_free()
  - Added Reviewed-by tags


v1: https://lore.kernel.org/linux-iommu/20250225105345.52143-1-vasant.hegde@amd.com/T/#t


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: Consolidate protection domain free code

 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           | 19 ++++++++-----------
 drivers/iommu/amd/pasid.c           |  2 +-
 7 files changed, 13 insertions(+), 29 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/7] iommu/amd: Log IOMMU control register in event log path
  2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
@ 2025-02-27 16:23 ` Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 2/7] iommu/amd: Remove unused variable Vasant Hegde
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-27 16:23 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Vasant Hegde

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

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index b48a72bd7b23..797c8612966a 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -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:
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/7] iommu/amd: Remove unused variable
  2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 1/7] iommu/amd: Log IOMMU control register in event log path Vasant Hegde
@ 2025-02-27 16:23 ` Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 3/7] iommu/amd/pgtbl_v2: Improve error handling Vasant Hegde
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-27 16:23 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Vasant Hegde

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

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/amd_iommu_types.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index 23caea22f8dc..3f57bdd0a659 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -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 */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/7] iommu/amd/pgtbl_v2: Improve error handling
  2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 1/7] iommu/amd: Log IOMMU control register in event log path Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 2/7] iommu/amd: Remove unused variable Vasant Hegde
@ 2025-02-27 16:23 ` Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 4/7] iommu/amd: Remove outdated comment Vasant Hegde
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-27 16:23 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Vasant Hegde

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

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/io_pgtable_v2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/io_pgtable_v2.c b/drivers/iommu/amd/io_pgtable_v2.c
index c616de2c5926..a56a27396305 100644
--- a/drivers/iommu/amd/io_pgtable_v2.c
+++ b/drivers/iommu/amd/io_pgtable_v2.c
@@ -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;
 		}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/7] iommu/amd: Remove outdated comment
  2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
                   ` (2 preceding siblings ...)
  2025-02-27 16:23 ` [PATCH v2 3/7] iommu/amd/pgtbl_v2: Improve error handling Vasant Hegde
@ 2025-02-27 16:23 ` Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 5/7] iommu/amd: Fix header file Vasant Hegde
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-27 16:23 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Vasant Hegde

Remove outdated comment.

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/io_pgtable.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/iommu/amd/io_pgtable.c b/drivers/iommu/amd/io_pgtable.c
index f3399087859f..26cf562dde11 100644
--- a/drivers/iommu/amd/io_pgtable.c
+++ b/drivers/iommu/amd/io_pgtable.c
@@ -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);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/7] iommu/amd: Fix header file
  2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
                   ` (3 preceding siblings ...)
  2025-02-27 16:23 ` [PATCH v2 4/7] iommu/amd: Remove outdated comment Vasant Hegde
@ 2025-02-27 16:23 ` Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 6/7] iommu/amd: Remove unused forward declaration Vasant Hegde
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-27 16:23 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, jgg, 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 <suravee.suthikulpanit@amd.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/amd_iommu.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
index 68debf5ee2d7..e3bf27da1339 100644
--- a/drivers/iommu/amd/amd_iommu.h
+++ b/drivers/iommu/amd/amd_iommu.h
@@ -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 */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 6/7] iommu/amd: Remove unused forward declaration
  2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
                   ` (4 preceding siblings ...)
  2025-02-27 16:23 ` [PATCH v2 5/7] iommu/amd: Fix header file Vasant Hegde
@ 2025-02-27 16:23 ` Vasant Hegde
  2025-02-27 16:23 ` [PATCH v2 7/7] iommu/amd: Consolidate protection domain free code Vasant Hegde
  2025-03-10  8:27 ` [PATCH v2 0/7] iommu/amd: Trivial fixes Joerg Roedel
  7 siblings, 0 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-27 16:23 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Vasant Hegde

Remove unused forward declaration.

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/init.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index cb536d372b12..94aaa4b2a903 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -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;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 7/7] iommu/amd: Consolidate protection domain free code
  2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
                   ` (5 preceding siblings ...)
  2025-02-27 16:23 ` [PATCH v2 6/7] iommu/amd: Remove unused forward declaration Vasant Hegde
@ 2025-02-27 16:23 ` Vasant Hegde
  2025-03-10  8:27 ` [PATCH v2 0/7] iommu/amd: Trivial fixes Joerg Roedel
  7 siblings, 0 replies; 9+ messages in thread
From: Vasant Hegde @ 2025-02-27 16:23 UTC (permalink / raw)
  To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Vasant Hegde

Consolidate protection domain free code inside amd_iommu_domain_free()
and remove protection_domain_free() function.

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/amd/amd_iommu.h |  1 -
 drivers/iommu/amd/iommu.c     | 15 +++++----------
 drivers/iommu/amd/pasid.c     |  2 +-
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
index e3bf27da1339..220c598b7e14 100644
--- a/drivers/iommu/amd/amd_iommu.h
+++ b/drivers/iommu/amd/amd_iommu.h
@@ -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);
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 797c8612966a..534585ea0939 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2434,15 +2434,6 @@ static struct iommu_group *amd_iommu_device_group(struct device *dev)
  *
  *****************************************************************************/
 
-void protection_domain_free(struct protection_domain *domain)
-{
-	WARN_ON(!list_empty(&domain->dev_list));
-	if (domain->domain.type & __IOMMU_DOMAIN_PAGING)
-		free_io_pgtable_ops(&domain->iop.pgtbl.ops);
-	pdom_id_free(domain->id);
-	kfree(domain);
-}
-
 static void protection_domain_init(struct protection_domain *domain)
 {
 	spin_lock_init(&domain->lock);
@@ -2580,7 +2571,11 @@ void amd_iommu_domain_free(struct iommu_domain *dom)
 {
 	struct protection_domain *domain = to_pdomain(dom);
 
-	protection_domain_free(domain);
+	WARN_ON(!list_empty(&domain->dev_list));
+	if (domain->domain.type & __IOMMU_DOMAIN_PAGING)
+		free_io_pgtable_ops(&domain->iop.pgtbl.ops);
+	pdom_id_free(domain->id);
+	kfree(domain);
 }
 
 static int blocked_domain_attach_device(struct iommu_domain *domain,
diff --git a/drivers/iommu/amd/pasid.c b/drivers/iommu/amd/pasid.c
index 11150cfd6718..77c8e9a91cbc 100644
--- a/drivers/iommu/amd/pasid.c
+++ b/drivers/iommu/amd/pasid.c
@@ -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);
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/7] iommu/amd: Trivial fixes
  2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
                   ` (6 preceding siblings ...)
  2025-02-27 16:23 ` [PATCH v2 7/7] iommu/amd: Consolidate protection domain free code Vasant Hegde
@ 2025-03-10  8:27 ` Joerg Roedel
  7 siblings, 0 replies; 9+ messages in thread
From: Joerg Roedel @ 2025-03-10  8:27 UTC (permalink / raw)
  To: Vasant Hegde; +Cc: iommu, will, robin.murphy, suravee.suthikulpanit, jgg

On Thu, Feb 27, 2025 at 04:23:13PM +0000, Vasant Hegde wrote:
> This series contains minor cleanup and trivial fixes.
> 
> Changes from v1 -> v2:
>   - Consolidated protection domain free code and removed
>     protection_domain_free()
>   - Added Reviewed-by tags
> 
> 
> v1: https://lore.kernel.org/linux-iommu/20250225105345.52143-1-vasant.hegde@amd.com/T/#t
> 
> 
> 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: Consolidate protection domain free code
> 
>  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           | 19 ++++++++-----------
>  drivers/iommu/amd/pasid.c           |  2 +-
>  7 files changed, 13 insertions(+), 29 deletions(-)

Applied, thanks Vasant.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-03-10  8:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 16:23 [PATCH v2 0/7] iommu/amd: Trivial fixes Vasant Hegde
2025-02-27 16:23 ` [PATCH v2 1/7] iommu/amd: Log IOMMU control register in event log path Vasant Hegde
2025-02-27 16:23 ` [PATCH v2 2/7] iommu/amd: Remove unused variable Vasant Hegde
2025-02-27 16:23 ` [PATCH v2 3/7] iommu/amd/pgtbl_v2: Improve error handling Vasant Hegde
2025-02-27 16:23 ` [PATCH v2 4/7] iommu/amd: Remove outdated comment Vasant Hegde
2025-02-27 16:23 ` [PATCH v2 5/7] iommu/amd: Fix header file Vasant Hegde
2025-02-27 16:23 ` [PATCH v2 6/7] iommu/amd: Remove unused forward declaration Vasant Hegde
2025-02-27 16:23 ` [PATCH v2 7/7] iommu/amd: Consolidate protection domain free code Vasant Hegde
2025-03-10  8:27 ` [PATCH v2 0/7] iommu/amd: Trivial fixes Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox