Commit 8ee37d0b authored by Yunfei Wang's avatar Yunfei Wang Committed by Suren Baghdasaryan
Browse files

BACKPORT: iommu/dma: Fix race condition during iova_domain initialization



When many devices share the same iova domain, iommu_dma_init_domain()
may be called at the same time. The checking of iovad->start_pfn will
all get false in iommu_dma_init_domain() and both enter init_iova_domain()
to do iovad initialization.

Fix this by protecting init_iova_domain() with iommu_dma_cookie->mutex.

Exception backtrace:
rb_insert_color(param1=0xFFFFFF80CD2BDB40, param3=1) + 64
init_iova_domain() + 180
iommu_setup_dma_ops() + 260
arch_setup_dma_ops() + 132
of_dma_configure_id() + 468
platform_dma_configure() + 32
really_probe() + 1168
driver_probe_device() + 268
__device_attach_driver() + 524
__device_attach() + 524
bus_probe_device() + 64
deferred_probe_work_func() + 260
process_one_work() + 580
worker_thread() + 1076
kthread() + 332
ret_from_fork() + 16

Signed-off-by: default avatarNing Li <ning.li@mediatek.com>
Signed-off-by: default avatarYunfei Wang <yf.wang@mediatek.com>
Acked-by: default avatarRobin Murphy <robin.murphy@arm.com>
Reviewed-by: default avatarMiles Chen <miles.chen@mediatek.com>
Link: https://lore.kernel.org/r/20220530120748.31733-1-yf.wang@mediatek.com


Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>

Bug: 236922015
(cherry picked from commit ac9a5d52
 https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git

 core)
[Yunfei: Embed iommu_dma_cookie into iommu_dma_cookie_ext to avoid
 changing struct iommu_dma_cookie]
Signed-off-by: default avatarYunfei Wang <yf.wang@mediatek.com>
Change-Id: I9b7931bea912837f17d2322713ba68a37122499d
(cherry picked from commit 8a410d77)
parent 321bf845
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment