iommu/amd: Cleanup and fixes
Subsystems (2)
cover iommu/amd: Cleanup and fixes
This series contains various cleanup and trivial fixes.
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 | 16 ++++++++++++---- drivers/iommu/amd/iommu_v2.c | 35 +++++++++++++++++------------------ 3 files changed, 29 insertions(+), 26 deletions(-)
Signature · 6 lines
2.27.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 1/5 iommu/amd: Improve error handling for amd_iommu_init_pci
From: Suravee Suthikulpanit <[email protected]>
Add error messages to prevent silent failure.
--- drivers/iommu/amd/init.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/iommu/amd/init.c +9 -3
@@ -1942,9 +1942,10 @@ 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!\n" , iommu->index); + goto out; + }/* Need to setup range after PCI init */ iommu_set_cwwb_range (iommu); }
@@ -1960,6 +1961,10 @@ static int __init amd_iommu_init_pci(void)* active. */ ret =amd_iommu_init_api (); +if (ret) { +pr_err ("IOMMU: Failed to initialize api!\n" ); + goto out; + }init_device_table_dma ();
@@ -1969,6 +1974,7 @@ static int __init amd_iommu_init_pci(void)if (!ret)print_iommu_info (); +out:return ret; }
Signature · 6 lines
2.27.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [PATCH 1/5] iommu/amd: Improve error handling for amd_iommu_init_pci
Quoted 15 lines · Vasant Hegde
From: Suravee Suthikulpanit <[email protected]>
Add error messages to prevent silent failure.
Signed-off-by Suravee Suthikulpanit <[email protected]>Signed-off-by Vasant Hegde <[email protected]>--- drivers/iommu/amd/init.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/iommu/amd/init.c +0
-0
drivers/iommu/amd/init.c static int __init amd_iommu_init_pci(void) · line 1946
Quoted 8 lines
drivers/iommu/amd/init.c +2
-3@@ -1942,9 +1942,10 @@ 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!\n" , iommu->index);
Please make that message "IOMMU%d: Failed to initialize IOMMU Hardware (error=%d)!\n".
drivers/iommu/amd/init.c static int __init amd_iommu_init_pci(void) · line 1965
Quoted 11 lines
drivers/iommu/amd/init.c +4
-0+ goto out; + }/* Need to setup range after PCI init */ iommu_set_cwwb_range (iommu); }@@ -1960,6 +1961,10 @@ static int __init amd_iommu_init_pci(void)* active. */ ret =amd_iommu_init_api (); +if (ret) { +pr_err ("IOMMU: Failed to initialize api!\n" );
And that "IOMMU: Failed to initialize IOMMU-API interface (error=%d)!\n"
Quoted 15 lines
drivers/iommu/amd/init.c +3
-0+ goto out; + }init_device_table_dma ();@@ -1969,6 +1974,7 @@ static int __init amd_iommu_init_pci(void)if (!ret)print_iommu_info (); +out:return ret; }Signature · 1 line
2.27.0
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 1/5] iommu/amd: Improve error handling for amd_iommu_init_pci
Quoted 17 lines · Joerg Roedel
Quoted 16 lines · Vasant Hegde
From: Suravee Suthikulpanit <[email protected]>
Add error messages to prevent silent failure.
Signed-off-by Suravee Suthikulpanit <[email protected]>Signed-off-by Vasant Hegde <[email protected]>--- drivers/iommu/amd/init.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/iommu/amd/init.c +0
-0@@ -1942,9 +1942,10 @@ static int __init amd_iommu_init_pci(void)
Quoted 9 lines
drivers/iommu/amd/init.c static int __init amd_iommu_init_pci(void) · line 1946
Quoted 7 lines
drivers/iommu/amd/init.c +2
-3for_each_iommu (iommu) { ret =iommu_init_pci (iommu); -if (ret) -break ; - +if (ret) { +pr_err ("IOMMU:%d Failed to initialize!\n" , iommu->index);Please make that message "IOMMU%d: Failed to initialize IOMMU Hardware (error=%d)!\n".
Thanks Joerg for the review. I have fixed it in v2.
Quoted 14 lines
drivers/iommu/amd/init.c static int __init amd_iommu_init_pci(void) · line 1965
Quoted 12 lines
drivers/iommu/amd/init.c +4
-0+ goto out; + }/* Need to setup range after PCI init */ iommu_set_cwwb_range (iommu); }@@ -1960,6 +1961,10 @@ static int __init amd_iommu_init_pci(void)* active. */ ret =amd_iommu_init_api (); +if (ret) { +pr_err ("IOMMU: Failed to initialize api!\n" );And that "IOMMU: Failed to initialize IOMMU-API interface (error=%d)!\n"
Fixed in v2.
-Vasant
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 2/5 iommu/amd: Call memunmap in error path
In reply to Vasant Hegde via iommuFrom: Vasant Hegde <[email protected]>
Unmap old_devtb in error path.
--- drivers/iommu/amd/init.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iommu/amd/init.c +2 -0
@@ -979,6 +979,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; }
@@ -1009,6 +1010,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; }
Signature · 6 lines
2.27.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 3/5 iommu/amd: Clean up function declarations
In reply to Vasant Hegde via iommuRemove unused declarations and add static keyword as needed.
--- drivers/iommu/amd/amd_iommu.h | 4 ---- drivers/iommu/amd/init.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-)
drivers/iommu/amd/amd_iommu.h +0 -4
@@ -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
drivers/iommu/amd/init.c +1 -1
@@ -660,7 +660,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 );
Signature · 6 lines
2.27.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 4/5 iommu/amd: Remove unused struct fault.devid
In reply to Vasant Hegde via iommuThis variable has not been used since it was introduced.
--- drivers/iommu/amd/iommu_v2.c | 1 - 1 file changed, 1 deletion(-)
drivers/iommu/amd/iommu_v2.c +0 -1
@@ -71,7 +71,6 @@ struct fault {struct pasid_state *state;struct mm_struct *mm;u64 address; -u16 devid;u32 pasid;u16 tag;u16 finish;
Signature · 6 lines
2.27.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH 5/5 iommu/amd: Improve amd_iommu_v2_exit()
In reply to Vasant Hegde via iommuFrom: Suravee Suthikulpanit <[email protected]>
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.
--- drivers/iommu/amd/iommu_v2.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/iommu/amd/iommu_v2.c +17 -17
@@ -24,7 +24,6 @@MODULE_LICENSE ("GPL v2" );MODULE_AUTHOR ("Joerg Roedel <[email protected]>" ); -#define MAX_DEVICES 0x10000#define PRI_QUEUE_SIZE 512struct 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); }
Signature · 6 lines
2.27.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerQuoted 11 lines · Vasant Hegde
This series contains various cleanup and trivial fixes.
Suravee Suthikulpanit (2):
iommu/amd: Improve error handling foramd_iommu_init_pciiommu/amd: Improveamd_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
Quoted 4 lines
drivers/iommu/amd/amd_iommu.h | 4 ---- drivers/iommu/amd/init.c | 16 ++++++++++++---- drivers/iommu/amd/iommu_v2.c | 35 +++++++++++++++++------------------ 3 files changed, 29 insertions(+), 26 deletions(-)
Besides the error messages in the first patch this looks good to me. Please re-send with the updates and I consider it for v5.18.
Thanks,
Joerg
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu