All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] iommu/amd: Cleanup and fixes
@ 2022-03-01  8:56 Vasant Hegde via iommu
  2022-03-01  8:56 ` [PATCH v2 1/5] iommu/amd: Improve error handling for amd_iommu_init_pci Vasant Hegde via iommu
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Vasant Hegde via iommu @ 2022-03-01  8:56 UTC (permalink / raw)
  To: joro, iommu; +Cc: Vasant Hegde

This series contains various cleanup and trivial fixes.

Changes in v2:
  - Fixed error log message in patch 1 as suggested by Joerg.


Suravee Suthikulpanit (2):
  iommu/amd: Improve error handling for amd_iommu_init_pci
  iommu/amd: Improve amd_iommu_v2_exit()

Vasant Hegde (3):
  iommu/amd: Call memunmap in error path
  iommu/amd: Clean up function declarations
  iommu/amd: Remove unused struct fault.devid

 drivers/iommu/amd/amd_iommu.h |  4 ----
 drivers/iommu/amd/init.c      | 18 ++++++++++++++----
 drivers/iommu/amd/iommu_v2.c  | 35 +++++++++++++++++------------------
 3 files changed, 31 insertions(+), 26 deletions(-)

-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH v2 1/5] iommu/amd: Improve error handling for amd_iommu_init_pci
  2022-03-01  8:56 [PATCH v2 0/5] iommu/amd: Cleanup and fixes Vasant Hegde via iommu
@ 2022-03-01  8:56 ` Vasant Hegde via iommu
  2022-03-01  8:56 ` [PATCH v2 2/5] iommu/amd: Call memunmap in error path Vasant Hegde via iommu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Vasant Hegde via iommu @ 2022-03-01  8:56 UTC (permalink / raw)
  To: joro, iommu; +Cc: Vasant Hegde

From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>

Add error messages to prevent silent failure.

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 drivers/iommu/amd/init.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index b10fb52ea442..6b5af568f3d5 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -1943,9 +1943,11 @@ static int __init amd_iommu_init_pci(void)
 
 	for_each_iommu(iommu) {
 		ret = iommu_init_pci(iommu);
-		if (ret)
-			break;
-
+		if (ret) {
+			pr_err("IOMMU%d: Failed to initialize IOMMU Hardware (error=%d)!\n",
+			       iommu->index, ret);
+			goto out;
+		}
 		/* Need to setup range after PCI init */
 		iommu_set_cwwb_range(iommu);
 	}
@@ -1961,6 +1963,11 @@ static int __init amd_iommu_init_pci(void)
 	 * active.
 	 */
 	ret = amd_iommu_init_api();
+	if (ret) {
+		pr_err("IOMMU: Failed to initialize IOMMU-API interface (error=%d)!\n",
+		       ret);
+		goto out;
+	}
 
 	init_device_table_dma();
 
@@ -1970,6 +1977,7 @@ static int __init amd_iommu_init_pci(void)
 	if (!ret)
 		print_iommu_info();
 
+out:
 	return ret;
 }
 
-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH v2 2/5] iommu/amd: Call memunmap in error path
  2022-03-01  8:56 [PATCH v2 0/5] iommu/amd: Cleanup and fixes Vasant Hegde via iommu
  2022-03-01  8:56 ` [PATCH v2 1/5] iommu/amd: Improve error handling for amd_iommu_init_pci Vasant Hegde via iommu
@ 2022-03-01  8:56 ` Vasant Hegde via iommu
  2022-03-01  8:56 ` [PATCH v2 3/5] iommu/amd: Clean up function declarations Vasant Hegde via iommu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Vasant Hegde via iommu @ 2022-03-01  8:56 UTC (permalink / raw)
  To: joro, iommu; +Cc: Vasant Hegde

Unmap old_devtb in error path.

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
 drivers/iommu/amd/init.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 6b5af568f3d5..f7e7d208063c 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -980,6 +980,7 @@ static bool copy_device_table(void)
 				get_order(dev_table_size));
 	if (old_dev_tbl_cpy == NULL) {
 		pr_err("Failed to allocate memory for copying old device table!\n");
+		memunmap(old_devtb);
 		return false;
 	}
 
@@ -1010,6 +1011,7 @@ static bool copy_device_table(void)
 			if ((int_ctl != DTE_IRQ_REMAP_INTCTL) ||
 			    (int_tab_len != DTE_INTTABLEN)) {
 				pr_err("Wrong old irq remapping flag: %#x\n", devid);
+				memunmap(old_devtb);
 				return false;
 			}
 
-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH v2 3/5] iommu/amd: Clean up function declarations
  2022-03-01  8:56 [PATCH v2 0/5] iommu/amd: Cleanup and fixes Vasant Hegde via iommu
  2022-03-01  8:56 ` [PATCH v2 1/5] iommu/amd: Improve error handling for amd_iommu_init_pci Vasant Hegde via iommu
  2022-03-01  8:56 ` [PATCH v2 2/5] iommu/amd: Call memunmap in error path Vasant Hegde via iommu
@ 2022-03-01  8:56 ` Vasant Hegde via iommu
  2022-03-01  8:56 ` [PATCH v2 4/5] iommu/amd: Remove unused struct fault.devid Vasant Hegde via iommu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Vasant Hegde via iommu @ 2022-03-01  8:56 UTC (permalink / raw)
  To: joro, iommu; +Cc: Vasant Hegde

Remove unused declarations and add static keyword as needed.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
 drivers/iommu/amd/amd_iommu.h | 4 ----
 drivers/iommu/amd/init.c      | 2 +-
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
index 416815a525d6..94d33626d692 100644
--- a/drivers/iommu/amd/amd_iommu.h
+++ b/drivers/iommu/amd/amd_iommu.h
@@ -14,10 +14,6 @@
 extern irqreturn_t amd_iommu_int_thread(int irq, void *data);
 extern irqreturn_t amd_iommu_int_handler(int irq, void *data);
 extern void amd_iommu_apply_erratum_63(u16 devid);
-extern void amd_iommu_reset_cmd_buffer(struct amd_iommu *iommu);
-extern int amd_iommu_init_devices(void);
-extern void amd_iommu_uninit_devices(void);
-extern void amd_iommu_init_notifier(void);
 extern int amd_iommu_init_api(void);
 
 #ifdef CONFIG_AMD_IOMMU_DEBUGFS
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index f7e7d208063c..07d6dd302989 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -661,7 +661,7 @@ static int __init alloc_command_buffer(struct amd_iommu *iommu)
  * This function resets the command buffer if the IOMMU stopped fetching
  * commands from it.
  */
-void amd_iommu_reset_cmd_buffer(struct amd_iommu *iommu)
+static void amd_iommu_reset_cmd_buffer(struct amd_iommu *iommu)
 {
 	iommu_feature_disable(iommu, CONTROL_CMDBUF_EN);
 
-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH v2 4/5] iommu/amd: Remove unused struct fault.devid
  2022-03-01  8:56 [PATCH v2 0/5] iommu/amd: Cleanup and fixes Vasant Hegde via iommu
                   ` (2 preceding siblings ...)
  2022-03-01  8:56 ` [PATCH v2 3/5] iommu/amd: Clean up function declarations Vasant Hegde via iommu
@ 2022-03-01  8:56 ` Vasant Hegde via iommu
  2022-03-01  8:56 ` [PATCH v2 5/5] iommu/amd: Improve amd_iommu_v2_exit() Vasant Hegde via iommu
  2022-03-04  9:39 ` [PATCH v2 0/5] iommu/amd: Cleanup and fixes Joerg Roedel
  5 siblings, 0 replies; 7+ messages in thread
From: Vasant Hegde via iommu @ 2022-03-01  8:56 UTC (permalink / raw)
  To: joro, iommu; +Cc: Vasant Hegde

This variable has not been used since it was introduced.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
 drivers/iommu/amd/iommu_v2.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c
index 58da08cc3d01..2daf37c21b85 100644
--- a/drivers/iommu/amd/iommu_v2.c
+++ b/drivers/iommu/amd/iommu_v2.c
@@ -71,7 +71,6 @@ struct fault {
 	struct pasid_state *state;
 	struct mm_struct *mm;
 	u64 address;
-	u16 devid;
 	u32 pasid;
 	u16 tag;
 	u16 finish;
-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* [PATCH v2 5/5] iommu/amd: Improve amd_iommu_v2_exit()
  2022-03-01  8:56 [PATCH v2 0/5] iommu/amd: Cleanup and fixes Vasant Hegde via iommu
                   ` (3 preceding siblings ...)
  2022-03-01  8:56 ` [PATCH v2 4/5] iommu/amd: Remove unused struct fault.devid Vasant Hegde via iommu
@ 2022-03-01  8:56 ` Vasant Hegde via iommu
  2022-03-04  9:39 ` [PATCH v2 0/5] iommu/amd: Cleanup and fixes Joerg Roedel
  5 siblings, 0 replies; 7+ messages in thread
From: Vasant Hegde via iommu @ 2022-03-01  8:56 UTC (permalink / raw)
  To: joro, iommu; +Cc: Vasant Hegde

From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>

During module exit, the current logic loops through all possible
16-bit device ID space to search for existing devices and clean up
device state structures. This can be simplified by looping through
the device state list.

Also, refactor various clean up logic into free_device_state()
for better reusability.

Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 drivers/iommu/amd/iommu_v2.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c
index 2daf37c21b85..c72969ac4956 100644
--- a/drivers/iommu/amd/iommu_v2.c
+++ b/drivers/iommu/amd/iommu_v2.c
@@ -24,7 +24,6 @@
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Joerg Roedel <jroedel@suse.de>");
 
-#define MAX_DEVICES		0x10000
 #define PRI_QUEUE_SIZE		512
 
 struct pri_queue {
@@ -124,6 +123,15 @@ static void free_device_state(struct device_state *dev_state)
 {
 	struct iommu_group *group;
 
+	/* Get rid of any remaining pasid states */
+	free_pasid_states(dev_state);
+
+	/*
+	 * Wait until the last reference is dropped before freeing
+	 * the device state.
+	 */
+	wait_event(dev_state->wq, !atomic_read(&dev_state->count));
+
 	/*
 	 * First detach device from domain - No more PRI requests will arrive
 	 * from that device after it is unbound from the IOMMUv2 domain.
@@ -849,15 +857,7 @@ void amd_iommu_free_device(struct pci_dev *pdev)
 
 	spin_unlock_irqrestore(&state_lock, flags);
 
-	/* Get rid of any remaining pasid states */
-	free_pasid_states(dev_state);
-
 	put_device_state(dev_state);
-	/*
-	 * Wait until the last reference is dropped before freeing
-	 * the device state.
-	 */
-	wait_event(dev_state->wq, !atomic_read(&dev_state->count));
 	free_device_state(dev_state);
 }
 EXPORT_SYMBOL(amd_iommu_free_device);
@@ -954,8 +954,8 @@ static int __init amd_iommu_v2_init(void)
 
 static void __exit amd_iommu_v2_exit(void)
 {
-	struct device_state *dev_state;
-	int i;
+	struct device_state *dev_state, *next;
+	unsigned long flags;
 
 	if (!amd_iommu_v2_supported())
 		return;
@@ -968,18 +968,18 @@ static void __exit amd_iommu_v2_exit(void)
 	 * The loop below might call flush_workqueue(), so call
 	 * destroy_workqueue() after it
 	 */
-	for (i = 0; i < MAX_DEVICES; ++i) {
-		dev_state = get_device_state(i);
-
-		if (dev_state == NULL)
-			continue;
+	spin_lock_irqsave(&state_lock, flags);
 
+	list_for_each_entry_safe(dev_state, next, &state_list, list) {
 		WARN_ON_ONCE(1);
 
 		put_device_state(dev_state);
-		amd_iommu_free_device(dev_state->pdev);
+		list_del(&dev_state->list);
+		free_device_state(dev_state);
 	}
 
+	spin_unlock_irqrestore(&state_lock, flags);
+
 	destroy_workqueue(iommu_wq);
 }
 
-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

* Re: [PATCH v2 0/5] iommu/amd: Cleanup and fixes
  2022-03-01  8:56 [PATCH v2 0/5] iommu/amd: Cleanup and fixes Vasant Hegde via iommu
                   ` (4 preceding siblings ...)
  2022-03-01  8:56 ` [PATCH v2 5/5] iommu/amd: Improve amd_iommu_v2_exit() Vasant Hegde via iommu
@ 2022-03-04  9:39 ` Joerg Roedel
  5 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2022-03-04  9:39 UTC (permalink / raw)
  To: Vasant Hegde; +Cc: iommu

On Tue, Mar 01, 2022 at 02:26:21PM +0530, Vasant Hegde wrote:
> This series contains various cleanup and trivial fixes.
> 
> Changes in v2:
>   - Fixed error log message in patch 1 as suggested by Joerg.
> 
> 
> Suravee Suthikulpanit (2):
>   iommu/amd: Improve error handling for amd_iommu_init_pci
>   iommu/amd: Improve amd_iommu_v2_exit()
> 
> Vasant Hegde (3):
>   iommu/amd: Call memunmap in error path
>   iommu/amd: Clean up function declarations
>   iommu/amd: Remove unused struct fault.devid

Applied, thanks Vasant and Suravee.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

end of thread, other threads:[~2022-03-04  9:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01  8:56 [PATCH v2 0/5] iommu/amd: Cleanup and fixes Vasant Hegde via iommu
2022-03-01  8:56 ` [PATCH v2 1/5] iommu/amd: Improve error handling for amd_iommu_init_pci Vasant Hegde via iommu
2022-03-01  8:56 ` [PATCH v2 2/5] iommu/amd: Call memunmap in error path Vasant Hegde via iommu
2022-03-01  8:56 ` [PATCH v2 3/5] iommu/amd: Clean up function declarations Vasant Hegde via iommu
2022-03-01  8:56 ` [PATCH v2 4/5] iommu/amd: Remove unused struct fault.devid Vasant Hegde via iommu
2022-03-01  8:56 ` [PATCH v2 5/5] iommu/amd: Improve amd_iommu_v2_exit() Vasant Hegde via iommu
2022-03-04  9:39 ` [PATCH v2 0/5] iommu/amd: Cleanup and fixes Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.