1
0
Fork 0
alistair23-linux/drivers/iommu
Stanislaw Gruszka 4e50ce0397 iommu/amd: fix sg->dma_address for sg->offset bigger than PAGE_SIZE
Take into account that sg->offset can be bigger than PAGE_SIZE when
setting segment sg->dma_address. Otherwise sg->dma_address will point
at diffrent page, what makes DMA not possible with erros like this:

xhci_hcd 0000:38:00.3: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0000 address=0x00000000fdaa70c0 flags=0x0020]
xhci_hcd 0000:38:00.3: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0000 address=0x00000000fdaa7040 flags=0x0020]
xhci_hcd 0000:38:00.3: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0000 address=0x00000000fdaa7080 flags=0x0020]
xhci_hcd 0000:38:00.3: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0000 address=0x00000000fdaa7100 flags=0x0020]
xhci_hcd 0000:38:00.3: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0000 address=0x00000000fdaa7000 flags=0x0020]

Additinally with wrong sg->dma_address unmap_sg will free wrong pages,
what what can cause crashes like this:

Feb 28 19:27:45 kernel: BUG: Bad page state in process cinnamon  pfn:39e8b1
Feb 28 19:27:45 kernel: Disabling lock debugging due to kernel taint
Feb 28 19:27:45 kernel: flags: 0x2ffff0000000000()
Feb 28 19:27:45 kernel: raw: 02ffff0000000000 0000000000000000 ffffffff00000301 0000000000000000
Feb 28 19:27:45 kernel: raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
Feb 28 19:27:45 kernel: page dumped because: nonzero _refcount
Feb 28 19:27:45 kernel: Modules linked in: ccm fuse arc4 nct6775 hwmon_vid amdgpu nls_iso8859_1 nls_cp437 edac_mce_amd vfat fat kvm_amd ccp rng_core kvm mt76x0u mt76x0_common mt76x02_usb irqbypass mt76_usb mt76x02_lib mt76 crct10dif_pclmul crc32_pclmul chash mac80211 amd_iommu_v2 ghash_clmulni_intel gpu_sched i2c_algo_bit ttm wmi_bmof snd_hda_codec_realtek snd_hda_codec_generic drm_kms_helper snd_hda_codec_hdmi snd_hda_intel drm snd_hda_codec aesni_intel snd_hda_core snd_hwdep aes_x86_64 crypto_simd snd_pcm cfg80211 cryptd mousedev snd_timer glue_helper pcspkr r8169 input_leds realtek agpgart libphy rfkill snd syscopyarea sysfillrect sysimgblt fb_sys_fops soundcore sp5100_tco k10temp i2c_piix4 wmi evdev gpio_amdpt pinctrl_amd mac_hid pcc_cpufreq acpi_cpufreq sg ip_tables x_tables ext4(E) crc32c_generic(E) crc16(E) mbcache(E) jbd2(E) fscrypto(E) sd_mod(E) hid_generic(E) usbhid(E) hid(E) dm_mod(E) serio_raw(E) atkbd(E) libps2(E) crc32c_intel(E) ahci(E) libahci(E) libata(E) xhci_pci(E) xhci_hcd(E)
Feb 28 19:27:45 kernel:  scsi_mod(E) i8042(E) serio(E) bcache(E) crc64(E)
Feb 28 19:27:45 kernel: CPU: 2 PID: 896 Comm: cinnamon Tainted: G    B   W   E     4.20.12-arch1-1-custom #1
Feb 28 19:27:45 kernel: Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./B450M Pro4, BIOS P1.20 06/26/2018
Feb 28 19:27:45 kernel: Call Trace:
Feb 28 19:27:45 kernel:  dump_stack+0x5c/0x80
Feb 28 19:27:45 kernel:  bad_page.cold.29+0x7f/0xb2
Feb 28 19:27:45 kernel:  __free_pages_ok+0x2c0/0x2d0
Feb 28 19:27:45 kernel:  skb_release_data+0x96/0x180
Feb 28 19:27:45 kernel:  __kfree_skb+0xe/0x20
Feb 28 19:27:45 kernel:  tcp_recvmsg+0x894/0xc60
Feb 28 19:27:45 kernel:  ? reuse_swap_page+0x120/0x340
Feb 28 19:27:45 kernel:  ? ptep_set_access_flags+0x23/0x30
Feb 28 19:27:45 kernel:  inet_recvmsg+0x5b/0x100
Feb 28 19:27:45 kernel:  __sys_recvfrom+0xc3/0x180
Feb 28 19:27:45 kernel:  ? handle_mm_fault+0x10a/0x250
Feb 28 19:27:45 kernel:  ? syscall_trace_enter+0x1d3/0x2d0
Feb 28 19:27:45 kernel:  ? __audit_syscall_exit+0x22a/0x290
Feb 28 19:27:45 kernel:  __x64_sys_recvfrom+0x24/0x30
Feb 28 19:27:45 kernel:  do_syscall_64+0x5b/0x170
Feb 28 19:27:45 kernel:  entry_SYSCALL_64_after_hwframe+0x44/0xa9

Cc: stable@vger.kernel.org
Reported-and-tested-by: Jan Viktorin <jan.viktorin@gmail.com>
Reviewed-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Fixes: 80187fd39d ('iommu/amd: Optimize map_sg and unmap_sg')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
2019-03-18 11:13:35 +01:00
..
Kconfig Merge branches 'iommu/fixes', 'arm/msm', 'arm/tegra', 'arm/mediatek', 'x86/vt-d', 'x86/amd', 'hyper-v' and 'core' into next 2019-03-01 11:24:51 +01:00
Makefile iommu/hyper-v: Add Hyper-V stub IOMMU driver 2019-02-28 11:12:16 +01:00
amd_iommu.c iommu/amd: fix sg->dma_address for sg->offset bigger than PAGE_SIZE 2019-03-18 11:13:35 +01: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: Use dev_printk() when possible 2019-02-11 12:06:39 +01: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: Ignore page-mode 7 in free_sub_pt() 2018-11-15 16:40:53 +01:00
amd_iommu_v2.c iommu/amd: Remove clear_flush_young notifier 2019-01-30 17:30:46 +01:00
arm-smmu-regs.h iommu/arm-smmu: Split out register defines 2017-08-15 17:34:48 +02:00
arm-smmu-v3.c iommu: Allow io-pgtable to be used outside of drivers/iommu/ 2019-02-11 11:26:48 +01:00
arm-smmu.c iommu: Allow io-pgtable to be used outside of drivers/iommu/ 2019-02-11 11:26:48 +01:00
dma-iommu.c iommu/dma: Remove unused variable 2019-01-24 15:14:35 +01:00
dmar.c mm: replace all open encodings for NUMA_NO_NODE 2019-03-05 21:07:14 -08:00
exynos-iommu.c IOMMU: Make dwo drivers use stateless device links 2019-02-01 10:04:08 +01:00
fsl_pamu.c iommu: fsl_pamu: use for_each_of_cpu_node iterator 2018-09-28 14:25:58 -05:00
fsl_pamu.h iommu/pamu: Fix PAMU boot crash 2017-08-23 16:28:09 +02:00
fsl_pamu_domain.c Merge branches 'arm/renesas', 'arm/smmu', 'ppc/pamu', 'x86/vt-d', 'x86/amd' and 'core' into next 2018-10-10 18:09:37 +02:00
fsl_pamu_domain.h iommu/pamu: Fix PAMU boot crash 2017-08-23 16:28:09 +02:00
hyperv-iommu.c iommu/hyper-v: Add Hyper-V stub IOMMU driver 2019-02-28 11:12:16 +01:00
intel-iommu-debugfs.c iommu/vt-d: Add debugfs support to show context internals 2018-09-25 14:33:44 +02:00
intel-iommu.c IOMMU Updates for Linux v5.1 2019-03-10 12:29:52 -07:00
intel-pasid.c iommu/vt-d: Get domain ID before clear pasid entry 2019-03-01 10:23:36 +01:00
intel-pasid.h iommu/vt-d: Shared virtual address in scalable mode 2018-12-11 10:46:00 +01:00
intel-svm.c iommu/vt-d: Fix NULL pointer reference in intel_svm_bind_mm() 2019-03-01 10:23:36 +01:00
intel_irq_remapping.c iommu/vt-d: Allow interrupts from the entire bus for aliased devices 2019-02-26 10:34:03 +01:00
io-pgtable-arm-v7s.c iommu/io-pgtable-arm-v7s: Only kmemleak_ignore L2 tables 2019-02-26 10:16:06 +01:00
io-pgtable-arm.c iommu: Allow io-pgtable to be used outside of drivers/iommu/ 2019-02-11 11:26:48 +01:00
io-pgtable.c iommu: Allow io-pgtable to be used outside of drivers/iommu/ 2019-02-11 11:26:48 +01:00
iommu-debugfs.c iommu: Fix IOMMU debugfs fallout 2019-02-26 11:15:58 +01:00
iommu-sysfs.c iommu/sysfs: Rename iommu_release_device() 2018-12-17 12:47:49 +01:00
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 Merge branches 'iommu/fixes', 'arm/msm', 'arm/tegra', 'arm/mediatek', 'x86/vt-d', 'x86/amd', 'hyper-v' and 'core' into next 2019-03-01 11:24:51 +01:00
iova.c iommu/iova: Optimise attempts to allocate iova from 32bit address range 2018-09-25 10:18:27 +02:00
ipmmu-vmsa.c iommu: Allow io-pgtable to be used outside of drivers/iommu/ 2019-02-11 11:26:48 +01:00
irq_remapping.c iommu/hyper-v: Add Hyper-V stub IOMMU driver 2019-02-28 11:12:16 +01:00
irq_remapping.h iommu/hyper-v: Add Hyper-V stub IOMMU driver 2019-02-28 11:12:16 +01:00
msm_iommu.c Merge branches 'iommu/fixes', 'arm/msm', 'arm/tegra', 'arm/mediatek', 'x86/vt-d', 'x86/amd', 'hyper-v' and 'core' into next 2019-03-01 11:24:51 +01:00
msm_iommu.h iommu/msm: Make use of iommu_device_register interface 2017-02-10 13:44:57 +01:00
msm_iommu_hw-8xxx.h iommu/msm: Move mach includes to iommu directory 2013-08-06 11:18:03 -07:00
mtk_iommu.c Merge branches 'iommu/fixes', 'arm/renesas', 'arm/mediatek', 'arm/tegra', 'arm/omap', 'arm/smmu', 'x86/vt-d', 'x86/amd' and 'core' into next 2018-12-20 10:05:20 +01:00
mtk_iommu.h iommu: Allow io-pgtable to be used outside of drivers/iommu/ 2019-02-11 11:26:48 +01:00
mtk_iommu_v1.c iommu/mediatek: Fix semicolon code style issue 2019-03-01 10:17:56 +01:00
of_iommu.c iommu/of: Fix probe-deferral 2019-01-11 12:28:24 +01:00
omap-iommu-debug.c iommu/omap: Remove DEBUG_SEQ_FOPS_RO() 2018-11-22 17:10:43 +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 iommu/omap: Add support to program multiple iommus 2017-09-19 11:32:05 +02:00
omap-iopgtable.h iommu/omap: Use BIT(x) macros in omap-iopgtable.h 2015-08-03 16:04:42 +02:00
qcom_iommu.c iommu: Allow io-pgtable to be used outside of drivers/iommu/ 2019-02-11 11:26:48 +01:00
rockchip-iommu.c IOMMU: Make dwo drivers use stateless device links 2019-02-01 10:04:08 +01: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/tegra: gart: Perform code refactoring 2019-01-16 13:54:16 +01:00
tegra-smmu.c memory: tegra: Do not try to probe SMMU on Tegra20 2019-01-16 13:54:13 +01:00