summaryrefslogtreecommitdiffstats
path: root/drivers/iommu/intel-iommu.c
diff options
context:
space:
mode:
authorDave Jiang <dave.jiang@intel.com>2019-05-21 03:30:15 -0400
committerJoerg Roedel <jroedel@suse.de>2019-05-27 10:32:43 -0400
commit7560cc3ca7d9d11555f80c830544e463fcdb28b8 (patch)
tree4dbbd621caa750f194003731655fc8e4577415f4 /drivers/iommu/intel-iommu.c
parent24f307d8abf79486dd3c1b645037df7d91602aaa (diff)
iommu/vt-d: Fix lock inversion between iommu->lock and device_domain_lock
Lockdep debug reported lock inversion related with the iommu code caused by dmar_insert_one_dev_info() grabbing the iommu->lock and the device_domain_lock out of order versus the code path in iommu_flush_dev_iotlb(). Expanding the scope of the iommu->lock and reversing the order of lock acquisition fixes the issue. [ 76.238180] dsa_bus wq0.0: dsa wq wq0.0 disabled [ 76.248706] [ 76.250486] ======================================================== [ 76.257113] WARNING: possible irq lock inversion dependency detected [ 76.263736] 5.1.0-rc5+ #162 Not tainted [ 76.267854] -------------------------------------------------------- [ 76.274485] systemd-journal/521 just changed the state of lock: [ 76.280685] 0000000055b330f5 (device_domain_lock){..-.}, at: iommu_flush_dev_iotlb.part.63+0x29/0x90 [ 76.290099] but this lock took another, SOFTIRQ-unsafe lock in the past: [ 76.297093] (&(&iommu->lock)->rlock){+.+.} [ 76.297094] [ 76.297094] [ 76.297094] and interrupts could create inverse lock ordering between them. [ 76.297094] [ 76.314257] [ 76.314257] other info that might help us debug this: [ 76.321448] Possible interrupt unsafe locking scenario: [ 76.321448] [ 76.328907] CPU0 CPU1 [ 76.333777] ---- ---- [ 76.338642] lock(&(&iommu->lock)->rlock); [ 76.343165] local_irq_disable(); [ 76.349422] lock(device_domain_lock); [ 76.356116] lock(&(&iommu->lock)->rlock); [ 76.363154] <Interrupt> [ 76.366134] lock(device_domain_lock); [ 76.370548] [ 76.370548] *** DEADLOCK *** Fixes: 745f2586e78e ("iommu/vt-d: Simplify function get_domain_for_dev()") Signed-off-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu/intel-iommu.c')
-rw-r--r--drivers/iommu/intel-iommu.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a209199f3af6..91f4912c09c6 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -2512,6 +2512,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
2512 } 2512 }
2513 } 2513 }
2514 2514
2515 spin_lock(&iommu->lock);
2515 spin_lock_irqsave(&device_domain_lock, flags); 2516 spin_lock_irqsave(&device_domain_lock, flags);
2516 if (dev) 2517 if (dev)
2517 found = find_domain(dev); 2518 found = find_domain(dev);
@@ -2527,17 +2528,16 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
2527 2528
2528 if (found) { 2529 if (found) {
2529 spin_unlock_irqrestore(&device_domain_lock, flags); 2530 spin_unlock_irqrestore(&device_domain_lock, flags);
2531 spin_unlock(&iommu->lock);
2530 free_devinfo_mem(info); 2532 free_devinfo_mem(info);
2531 /* Caller must free the original domain */ 2533 /* Caller must free the original domain */
2532 return found; 2534 return found;
2533 } 2535 }
2534 2536
2535 spin_lock(&iommu->lock);
2536 ret = domain_attach_iommu(domain, iommu); 2537 ret = domain_attach_iommu(domain, iommu);
2537 spin_unlock(&iommu->lock);
2538
2539 if (ret) { 2538 if (ret) {
2540 spin_unlock_irqrestore(&device_domain_lock, flags); 2539 spin_unlock_irqrestore(&device_domain_lock, flags);
2540 spin_unlock(&iommu->lock);
2541 free_devinfo_mem(info); 2541 free_devinfo_mem(info);
2542 return NULL; 2542 return NULL;
2543 } 2543 }
@@ -2547,6 +2547,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu,
2547 if (dev) 2547 if (dev)
2548 dev->archdata.iommu = info; 2548 dev->archdata.iommu = info;
2549 spin_unlock_irqrestore(&device_domain_lock, flags); 2549 spin_unlock_irqrestore(&device_domain_lock, flags);
2550 spin_unlock(&iommu->lock);
2550 2551
2551 /* PASID table is mandatory for a PCI device in scalable mode. */ 2552 /* PASID table is mandatory for a PCI device in scalable mode. */
2552 if (dev && dev_is_pci(dev) && sm_supported(iommu)) { 2553 if (dev && dev_is_pci(dev) && sm_supported(iommu)) {