linux-stable/drivers/iommu
Dmitry Safonov 4fd0eb60ba iommu/vt-d: Don't queue_iova() if there is no flush queue
commit effa467870 upstream.

Intel VT-d driver was reworked to use common deferred flushing
implementation. Previously there was one global per-cpu flush queue,
afterwards - one per domain.

Before deferring a flush, the queue should be allocated and initialized.

Currently only domains with IOMMU_DOMAIN_DMA type initialize their flush
queue. It's probably worth to init it for static or unmanaged domains
too, but it may be arguable - I'm leaving it to iommu folks.

Prevent queuing an iova flush if the domain doesn't have a queue.
The defensive check seems to be worth to keep even if queue would be
initialized for all kinds of domains. And is easy backportable.

On 4.19.43 stable kernel it has a user-visible effect: previously for
devices in si domain there were crashes, on sata devices:

 BUG: spinlock bad magic on CPU#6, swapper/0/1
  lock: 0xffff88844f582008, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
 CPU: 6 PID: 1 Comm: swapper/0 Not tainted 4.19.43 #1
 Call Trace:
  <IRQ>
  dump_stack+0x61/0x7e
  spin_bug+0x9d/0xa3
  do_raw_spin_lock+0x22/0x8e
  _raw_spin_lock_irqsave+0x32/0x3a
  queue_iova+0x45/0x115
  intel_unmap+0x107/0x113
  intel_unmap_sg+0x6b/0x76
  __ata_qc_complete+0x7f/0x103
  ata_qc_complete+0x9b/0x26a
  ata_qc_complete_multiple+0xd0/0xe3
  ahci_handle_port_interrupt+0x3ee/0x48a
  ahci_handle_port_intr+0x73/0xa9
  ahci_single_level_irq_intr+0x40/0x60
  __handle_irq_event_percpu+0x7f/0x19a
  handle_irq_event_percpu+0x32/0x72
  handle_irq_event+0x38/0x56
  handle_edge_irq+0x102/0x121
  handle_irq+0x147/0x15c
  do_IRQ+0x66/0xf2
  common_interrupt+0xf/0xf
 RIP: 0010:__do_softirq+0x8c/0x2df

The same for usb devices that use ehci-pci:
 BUG: spinlock bad magic on CPU#0, swapper/0/1
  lock: 0xffff88844f402008, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.19.43 #4
 Call Trace:
  <IRQ>
  dump_stack+0x61/0x7e
  spin_bug+0x9d/0xa3
  do_raw_spin_lock+0x22/0x8e
  _raw_spin_lock_irqsave+0x32/0x3a
  queue_iova+0x77/0x145
  intel_unmap+0x107/0x113
  intel_unmap_page+0xe/0x10
  usb_hcd_unmap_urb_setup_for_dma+0x53/0x9d
  usb_hcd_unmap_urb_for_dma+0x17/0x100
  unmap_urb_for_dma+0x22/0x24
  __usb_hcd_giveback_urb+0x51/0xc3
  usb_giveback_urb_bh+0x97/0xde
  tasklet_action_common.isra.4+0x5f/0xa1
  tasklet_action+0x2d/0x30
  __do_softirq+0x138/0x2df
  irq_exit+0x7d/0x8b
  smp_apic_timer_interrupt+0x10f/0x151
  apic_timer_interrupt+0xf/0x20
  </IRQ>
 RIP: 0010:_raw_spin_unlock_irqrestore+0x17/0x39

Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Lu Baolu <baolu.lu@linux.intel.com>
Cc: iommu@lists.linux-foundation.org
Cc: <stable@vger.kernel.org> # 4.14+
Fixes: 13cf017446 ("iommu/vt-d: Make use of iova deferred flushing")
Signed-off-by: Dmitry Safonov <dima@arista.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
[v4.14-port notes:
o minor conflict with untrusted IOMMU devices check under if-condition]
Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-04 09:30:54 +02:00
..
amd_iommu.c iommu/amd: Reserve exclusion range in iova-domain 2019-05-04 09:20:22 +02:00
amd_iommu_debugfs.c iommu/amd: Add basic debugfs infrastructure for AMD IOMMU 2018-07-06 14:06:30 +02:00
amd_iommu_init.c iommu/amd: Set exclusion range correctly 2019-05-10 17:54:10 +02:00
amd_iommu_proto.h iommu/amd: Add basic debugfs infrastructure for AMD IOMMU 2018-07-06 14:06:30 +02:00
amd_iommu_types.h iommu/amd: Reserve exclusion range in iova-domain 2019-05-04 09:20:22 +02:00
amd_iommu_v2.c mm: convert return type of handle_mm_fault() caller to vm_fault_t 2018-08-17 16:20:28 -07:00
arm-smmu-regs.h
arm-smmu-v3.c iommu/arm-smmu-v3: Don't disable SMMU in kdump kernel 2019-06-15 11:54:07 +02:00
arm-smmu.c iommu/arm-smmu: Avoid constant zero in TLBI writes 2019-06-19 08:18:00 +02:00
dma-iommu.c iommu/dma: Respect bus DMA limit for IOVAs 2018-07-27 19:01:06 +02:00
dmar.c iommu/dmar: Fix buffer overflow during PCI bus notification 2019-04-20 09:16:03 +02:00
exynos-iommu.c IOMMU Update for Linux v4.19 2018-08-24 13:10:38 -07:00
fsl_pamu.c
fsl_pamu.h
fsl_pamu_domain.c
fsl_pamu_domain.h
intel-iommu.c iommu/vt-d: Don't queue_iova() if there is no flush queue 2019-08-04 09:30:54 +02:00
intel-pasid.c iommu/vt-d: Per PCI device pasid table interfaces 2018-07-20 14:44:24 +02:00
intel-pasid.h iommu/vt-d: Handle memory shortage on pasid table allocation 2018-09-25 14:33:02 +02:00
intel-svm.c iommu/vt-d: Fix NULL pointer dereference in prq_event_thread() 2018-12-13 09:16:09 +01:00
intel_irq_remapping.c irq_remapping: Use apic_ack_irq() 2018-06-06 15:18:20 +02:00
io-pgtable-arm-v7s.c iommu/io-pgtable-arm-v7s: Only kmemleak_ignore L2 tables 2019-04-05 22:33:02 +02:00
io-pgtable-arm.c iommu/io-pgtable-arm: Fix pgtable allocation in selftest 2018-07-26 11:34:58 +01:00
io-pgtable.c
io-pgtable.h iommu/io-pgtable: Use size_t return type for all foo_unmap 2018-02-13 19:31:32 +01:00
iommu-debugfs.c iommu: Enable debugfs exposure of IOMMU driver internals 2018-07-06 14:06:30 +02:00
iommu-sysfs.c
iommu-traces.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
iommu.c iommu: Fix a leak in iommu_insert_resv_region 2019-07-26 09:14:06 +02:00
iova.c iommu/vt-d: Don't queue_iova() if there is no flush queue 2019-08-04 09:30:54 +02:00
ipmmu-vmsa.c iommu/ipmmu-vmsa: Fix crash on early domain free 2018-12-13 09:16:10 +01:00
irq_remapping.c irq_remapping: Use apic_ack_irq() 2018-06-06 15:18:20 +02:00
irq_remapping.h irq_remapping: Use apic_ack_irq() 2018-06-06 15:18:20 +02:00
Kconfig Merge branches 'arm/shmobile', 'arm/renesas', 'arm/msm', 'arm/smmu', 'arm/omap', 'x86/amd', 'x86/vt-d' and 'core' into next 2018-08-08 12:02:27 +02:00
Makefile Merge branches 'arm/shmobile', 'arm/renesas', 'arm/msm', 'arm/smmu', 'arm/omap', 'x86/amd', 'x86/vt-d' and 'core' into next 2018-08-08 12:02:27 +02:00
msm_iommu.c IOMMU Update for Linux v4.19 2018-08-24 13:10:38 -07:00
msm_iommu.h
msm_iommu_hw-8xxx.h
mtk_iommu.c iommu: Remove the ->map_sg indirection 2018-08-08 11:06:20 +02:00
mtk_iommu.h iommu/mediatek: Fix protect memory setting 2018-03-21 06:13:57 -05:00
mtk_iommu_v1.c iommu: Remove the ->map_sg indirection 2018-08-08 11:06:20 +02:00
of_iommu.c iommu: Remove IOMMU_OF_DECLARE 2018-07-10 17:22:35 +02:00
omap-iommu-debug.c iommu/omap: Fix debugfs_create_*() usage 2018-01-17 14:23:33 +01:00
omap-iommu.c Merge branches 'arm/shmobile', 'arm/renesas', 'arm/msm', 'arm/smmu', 'arm/omap', 'x86/amd', 'x86/vt-d' and 'core' into next 2018-08-08 12:02:27 +02:00
omap-iommu.h
omap-iopgtable.h
qcom_iommu.c IOMMU Update for Linux v4.19 2018-08-24 13:10:38 -07:00
rockchip-iommu.c iommu/rockchip: Free irqs in shutdown handler 2018-09-25 11:13:34 +02:00
s390-iommu.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
tegra-gart.c iommu: Remove the ->map_sg indirection 2018-08-08 11:06:20 +02:00
tegra-smmu.c iommu/tegra-smmu: Fix invalid ASID bits on Tegra30/114 2019-05-25 18:23:30 +02:00