2022-10-19 01:22:38

by Lu Baolu

[permalink] [raw]
Subject: [PATCH 0/4] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc2

Hi Joerg,

Below fixes are queued for v6.1. They aim to fix:

- A lockdep splat issue in intel_iommu_init().
- Allow NVS regions to pass RMRR check.
- Domain cleanup in error path.

This series is also available at github.
https://github.com/LuBaolu/intel-iommu/commits/vtd-fix-for-v6.1-rc2

Please consider it for the iommu/fix branch.

Best regards,
Lu Baolu

Charlotte Tan (1):
iommu/vt-d: Allow NVS regions in arch_rmrr_sanity_check()

Jerry Snitselaar (1):
iommu/vt-d: Clean up si_domain in the init_dmars() error path

Lu Baolu (2):
iommu: Add gfp parameter to iommu_alloc_resv_region
iommu/vt-d: Use rcu_lock in get_resv_regions

include/linux/iommu.h | 2 +-
arch/x86/include/asm/iommu.h | 4 +++-
drivers/acpi/arm64/iort.c | 3 ++-
drivers/iommu/amd/iommu.c | 7 ++++---
drivers/iommu/apple-dart.c | 2 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 +-
drivers/iommu/arm/arm-smmu/arm-smmu.c | 2 +-
drivers/iommu/intel/iommu.c | 17 ++++++++++++-----
drivers/iommu/iommu.c | 7 ++++---
drivers/iommu/mtk_iommu.c | 3 ++-
drivers/iommu/virtio-iommu.c | 9 ++++++---
11 files changed, 37 insertions(+), 21 deletions(-)

--
2.34.1


2022-10-19 01:42:56

by Lu Baolu

[permalink] [raw]
Subject: [PATCH 2/4] iommu/vt-d: Use rcu_lock in get_resv_regions

Commit 5f64ce5411b46 ("iommu/vt-d: Duplicate iommu_resv_region objects
per device list") converted rcu_lock in get_resv_regions to
dmar_global_lock to allow sleeping in iommu_alloc_resv_region(). This
introduced possible recursive locking if get_resv_regions is called from
within a section where intel_iommu_init() already holds dmar_global_lock.

Especially, after commit 57365a04c921 ("iommu: Move bus setup to IOMMU
device registration"), below lockdep splats could always be seen.

============================================
WARNING: possible recursive locking detected
6.0.0-rc4+ #325 Tainted: G I
--------------------------------------------
swapper/0/1 is trying to acquire lock:
ffffffffa8a18c90 (dmar_global_lock){++++}-{3:3}, at:
intel_iommu_get_resv_regions+0x25/0x270

but task is already holding lock:
ffffffffa8a18c90 (dmar_global_lock){++++}-{3:3}, at:
intel_iommu_init+0x36d/0x6ea

...

Call Trace:
<TASK>
dump_stack_lvl+0x48/0x5f
__lock_acquire.cold.73+0xad/0x2bb
lock_acquire+0xc2/0x2e0
? intel_iommu_get_resv_regions+0x25/0x270
? lock_is_held_type+0x9d/0x110
down_read+0x42/0x150
? intel_iommu_get_resv_regions+0x25/0x270
intel_iommu_get_resv_regions+0x25/0x270
iommu_create_device_direct_mappings.isra.28+0x8d/0x1c0
? iommu_get_dma_cookie+0x6d/0x90
bus_iommu_probe+0x19f/0x2e0
iommu_device_register+0xd4/0x130
intel_iommu_init+0x3e1/0x6ea
? iommu_setup+0x289/0x289
? rdinit_setup+0x34/0x34
pci_iommu_init+0x12/0x3a
do_one_initcall+0x65/0x320
? rdinit_setup+0x34/0x34
? rcu_read_lock_sched_held+0x5a/0x80
kernel_init_freeable+0x28a/0x2f3
? rest_init+0x1b0/0x1b0
kernel_init+0x1a/0x130
ret_from_fork+0x1f/0x30
</TASK>

This rolls back dmar_global_lock to rcu_lock in get_resv_regions to avoid
the lockdep splat.

Fixes: 57365a04c921 ("iommu: Move bus setup to IOMMU device registration")
Signed-off-by: Lu Baolu <[email protected]>
Tested-by: Alex Williamson <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
drivers/iommu/intel/iommu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index d5965b4f8b60..b3cf0f991e29 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4534,7 +4534,7 @@ static void intel_iommu_get_resv_regions(struct device *device,
struct device *i_dev;
int i;

- down_read(&dmar_global_lock);
+ rcu_read_lock();
for_each_rmrr_units(rmrr) {
for_each_active_dev_scope(rmrr->devices, rmrr->devices_cnt,
i, i_dev) {
@@ -4553,14 +4553,14 @@ static void intel_iommu_get_resv_regions(struct device *device,

resv = iommu_alloc_resv_region(rmrr->base_address,
length, prot, type,
- GFP_KERNEL);
+ GFP_ATOMIC);
if (!resv)
break;

list_add_tail(&resv->list, head);
}
}
- up_read(&dmar_global_lock);
+ rcu_read_unlock();

#ifdef CONFIG_INTEL_IOMMU_FLOPPY_WA
if (dev_is_pci(device)) {
--
2.34.1

2022-10-21 09:10:37

by Joerg Roedel

[permalink] [raw]
Subject: Re: [PATCH 0/4] [PULL REQUEST] iommu/vt-d: Fixes for v6.1-rc2

On Wed, Oct 19, 2022 at 08:44:43AM +0800, Lu Baolu wrote:
> Hi Joerg,
>
> Below fixes are queued for v6.1. They aim to fix:
>
> - A lockdep splat issue in intel_iommu_init().
> - Allow NVS regions to pass RMRR check.
> - Domain cleanup in error path.
>
> This series is also available at github.
> https://github.com/LuBaolu/intel-iommu/commits/vtd-fix-for-v6.1-rc2

Applied, thanks Baolu.