Skip to content

Commit d706162

Browse files
fenghusthujoergroedel
authored andcommitted
iommu/iova: Fix race between FQ timeout and teardown
It turns out to be possible for hotplugging out a device to reach the stage of tearing down the device's group and default domain before the domain's flush queue has drained naturally. At this point, it is then possible for the timeout to expire just before the del_timer() call in free_iova_flush_queue(), such that we then proceed to free the FQ resources while fq_flush_timeout() is still accessing them on another CPU. Crashes due to this have been observed in the wild while removing NVMe devices. Close the race window by using del_timer_sync() to safely wait for any active timeout handler to finish before we start to free things. We already avoid any locking in free_iova_flush_queue() since the FQ is supposed to be inactive anyway, so the potential deadlock scenario does not apply. Fixes: 9a005a8 ("iommu/iova: Add flush timer") Reviewed-by: John Garry <[email protected]> Signed-off-by: Xiongfeng Wang <[email protected]> [ rm: rewrite commit message ] Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/0a365e5b07f14b7344677ad6a9a734966a8422ce.1639753638.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent 972bf25 commit d706162

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/iommu/iova.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ static void free_iova_flush_queue(struct iova_domain *iovad)
8383
if (!has_iova_flush_queue(iovad))
8484
return;
8585

86-
if (timer_pending(&iovad->fq_timer))
87-
del_timer(&iovad->fq_timer);
86+
del_timer_sync(&iovad->fq_timer);
8887

8988
fq_destroy_all_entries(iovad);
9089

0 commit comments

Comments
 (0)