Skip to content

Commit 5edde87

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Do not call sleep while holding spinlock
Smatch static checker warns: drivers/iommu/amd/iommu_v2.c:133 free_device_state() warn: sleeping in atomic context Fixes by storing the list of struct device_state in a temporary list, and then free the memory after releasing the spinlock. Reported-by: Dan Carpenter <[email protected]> Fixes: 9f968fc ("iommu/amd: Improve amd_iommu_v2_exit()") Signed-off-by: Suravee Suthikulpanit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent af2d861 commit 5edde87

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/iommu/amd/iommu_v2.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ static void __exit amd_iommu_v2_exit(void)
956956
{
957957
struct device_state *dev_state, *next;
958958
unsigned long flags;
959+
LIST_HEAD(freelist);
959960

960961
if (!amd_iommu_v2_supported())
961962
return;
@@ -975,11 +976,20 @@ static void __exit amd_iommu_v2_exit(void)
975976

976977
put_device_state(dev_state);
977978
list_del(&dev_state->list);
978-
free_device_state(dev_state);
979+
list_add_tail(&dev_state->list, &freelist);
979980
}
980981

981982
spin_unlock_irqrestore(&state_lock, flags);
982983

984+
/*
985+
* Since free_device_state waits on the count to be zero,
986+
* we need to free dev_state outside the spinlock.
987+
*/
988+
list_for_each_entry_safe(dev_state, next, &freelist, list) {
989+
list_del(&dev_state->list);
990+
free_device_state(dev_state);
991+
}
992+
983993
destroy_workqueue(iommu_wq);
984994
}
985995

0 commit comments

Comments
 (0)