linux/drivers/iommu
Vasant Hegde 526606b0a1 iommu/amd: Fix Invalid wait context issue
With commit c4cb231111 ("iommu/amd: Add support for enable/disable IOPF")
we are hitting below issue. This happens because in IOPF enablement path
it holds spin lock with irq disable and then tries to take mutex lock.

dmesg:
-----
[    0.938739] =============================
[    0.938740] [ BUG: Invalid wait context ]
[    0.938742] 6.10.0-rc1+ #1 Not tainted
[    0.938745] -----------------------------
[    0.938746] swapper/0/1 is trying to lock:
[    0.938748] ffffffff8c9f01d8 (&port_lock_key){....}-{3:3}, at: serial8250_console_write+0x78/0x4a0
[    0.938767] other info that might help us debug this:
[    0.938768] context-{5:5}
[    0.938769] 7 locks held by swapper/0/1:
[    0.938772]  #0: ffff888101a91310 (&group->mutex){+.+.}-{4:4}, at: bus_iommu_probe+0x70/0x160
[    0.938790]  #1: ffff888101d1f1b8 (&domain->lock){....}-{3:3}, at: amd_iommu_attach_device+0xa5/0x700
[    0.938799]  #2: ffff888101cc3d18 (&dev_data->lock){....}-{3:3}, at: amd_iommu_attach_device+0xc5/0x700
[    0.938806]  #3: ffff888100052830 (&iommu->lock){....}-{2:2}, at: amd_iommu_iopf_add_device+0x3f/0xa0
[    0.938813]  #4: ffffffff8945a340 (console_lock){+.+.}-{0:0}, at: _printk+0x48/0x50
[    0.938822]  #5: ffffffff8945a390 (console_srcu){....}-{0:0}, at: console_flush_all+0x58/0x4e0
[    0.938867]  #6: ffffffff82459f80 (console_owner){....}-{0:0}, at: console_flush_all+0x1f0/0x4e0
[    0.938872] stack backtrace:
[    0.938874] CPU: 2 PID: 1 Comm: swapper/0 Not tainted 6.10.0-rc1+ #1
[    0.938877] Hardware name: HP HP EliteBook 745 G3/807E, BIOS N73 Ver. 01.39 04/16/2019

Fix above issue by re-arranging code in attach device path:
  - move device PASID/IOPF enablement outside lock in AMD IOMMU driver.
    This is safe as core layer holds group->mutex lock before calling
    iommu_ops->attach_dev.

Reported-by: Borislav Petkov <bp@alien8.de>
Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Reported-by: Chris Bainbridge <chris.bainbridge@gmail.com>
Fixes: c4cb231111 ("iommu/amd: Add support for enable/disable IOPF")
Tested-by: Borislav Petkov <bp@alien8.de>
Tested-by: Chris Bainbridge <chris.bainbridge@gmail.com>
Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Link: https://lore.kernel.org/r/20240530084801.10758-1-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2024-06-04 14:00:59 +02:00
..
amd iommu/amd: Fix Invalid wait context issue 2024-06-04 14:00:59 +02:00
arm Merge branches 'arm/renesas', 'arm/smmu', 'x86/amd', 'core' and 'x86/vt-d' into next 2024-05-13 14:06:54 +02:00
intel tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
iommufd iommufd: Add missing IOMMUFD_DRIVER kconfig for the selftest 2024-04-14 13:52:08 -03:00
apple-dart.c iommu: constify of_phandle_args in xlate 2024-03-01 13:46:57 +01:00
dma-iommu.c iommu/dma: Fix domain init 2024-06-04 13:54:09 +02:00
dma-iommu.h iommu/dma: Centralise iommu_setup_dma_ops() 2024-04-26 12:07:26 +02:00
exynos-iommu.c iommu/exynos: use page allocation function provided by iommu-pages.h 2024-04-15 14:31:45 +02:00
fsl_pamu_domain.c iommu/fsl_pamu: Implement a PLATFORM domain 2023-09-25 11:40:54 +02:00
fsl_pamu_domain.h
fsl_pamu.c iommu/fsl: fix all kernel-doc warnings in fsl_pamu.c 2023-03-22 14:50:15 +01:00
fsl_pamu.h iommu/fsl_pamu: hardcode the window address and size in pamu_config_ppaace 2021-04-07 10:56:52 +02:00
hyperv-iommu.c x86/vector: Rename send_cleanup_vector() to vector_schedule_cleanup() 2023-08-06 14:15:09 +02:00
io-pgfault.c iommu: Make iommu_report_device_fault() return void 2024-02-16 15:19:37 +01:00
io-pgtable-arm-v7s.c iommu/io-pgtable-arm-v7s: Remove map/unmap 2022-11-19 10:44:15 +01:00
io-pgtable-arm.c iommu/io-pgtable-arm: use page allocation function provided by iommu-pages.h 2024-04-15 14:31:44 +02:00
io-pgtable-arm.h
io-pgtable-dart.c iommu/io-pgtable-dart: use page allocation function provided by iommu-pages.h 2024-04-15 14:31:44 +02:00
io-pgtable.c iommu: Allow passing custom allocators to pgtable drivers 2023-11-27 11:10:12 +01:00
iommu-debugfs.c
iommu-pages.h iommu: account IOMMU allocated memory 2024-04-15 14:31:48 +02:00
iommu-priv.h iommu: constify pointer to bus_type 2024-03-01 13:46:57 +01:00
iommu-sva.c iommu: Add ops->domain_alloc_sva() 2024-04-26 12:16:07 +02:00
iommu-sysfs.c iommu: Do not export iommu_device_link/unlink() 2023-07-14 16:14:15 +02:00
iommu-traces.c iommu: Remove detach_dev callback 2023-01-13 16:39:18 +01:00
iommu.c iommu/dma: Centralise iommu_setup_dma_ops() 2024-04-26 12:07:26 +02:00
iova.c iommu/iova: use named kmem_cache for iova magazines 2024-02-09 11:45:47 +01:00
ipmmu-vmsa.c Merge branches 'arm/mediatek', 'arm/renesas', 'arm/smmu', 'x86/vt-d', 'x86/amd' and 'core' into next 2024-03-08 09:05:59 +01:00
irq_remapping.c IOMMU Updates for Linux v6.10 2024-05-18 10:55:13 -07:00
irq_remapping.h iommu/vt-d: Allocate DMAR fault interrupts locally 2024-04-26 11:57:36 +02:00
Kconfig iommu/arm-smmu-v3: Make the kunit into a module 2024-05-10 14:14:14 +02:00
Makefile iommu: Separate SVA and IOPF 2024-02-16 15:19:29 +01:00
msm_iommu_hw-8xxx.h
msm_iommu.c iommu: constify of_phandle_args in xlate 2024-03-01 13:46:57 +01:00
msm_iommu.h
mtk_iommu_v1.c iommu: mtk: fix module autoloading 2024-04-12 12:04:50 +02:00
mtk_iommu.c iommu: mtk: fix module autoloading 2024-04-12 12:04:50 +02:00
of_iommu.c iommu: re-use local fwnode variable in iommu_ops_from_fwnode() 2024-03-01 13:47:01 +01:00
omap-iommu-debug.c iommu/omap: Fix buffer overflow in debugfs 2022-09-07 10:42:28 +02:00
omap-iommu.c iommu: Mark dev_iommu_priv_set() with a lockdep 2023-12-12 10:18:49 +01:00
omap-iommu.h iommu/omap: Convert to generic_single_device_group() 2023-09-25 11:52:08 +02:00
omap-iopgtable.h
rockchip-iommu.c iommu/rockchip: use page allocation function provided by iommu-pages.h 2024-04-15 14:31:45 +02:00
s390-iommu.c iommu/dma: Centralise iommu_setup_dma_ops() 2024-04-26 12:07:26 +02:00
sprd-iommu.c iommu: constify of_phandle_args in xlate 2024-03-01 13:46:57 +01:00
sun50i-iommu.c iommu/sun50i: use page allocation function provided by iommu-pages.h 2024-04-15 14:31:46 +02:00
tegra-smmu.c iommu/tegra-smmu: use page allocation function provided by iommu-pages.h 2024-04-15 14:31:46 +02:00
virtio-iommu.c virtio: features, fixes, cleanups 2024-05-23 12:04:36 -07:00