linux_dsm_epyc7002/drivers/gpu/drm
Imre Deak e227330223 drm/i915: avoid leaking DMA mappings
We have 3 types of DMA mappings for GEM objects:
1. physically contiguous for stolen and for objects needing contiguous
   memory
2. DMA-buf mappings imported via a DMA-buf attach operation
3. SG DMA mappings for shmem backed and userptr objects

For 1. and 2. the lifetime of the DMA mapping matches the lifetime of the
corresponding backing pages and so in practice we create/release the
mapping in the object's get_pages/put_pages callback.

For 3. the lifetime of the mapping matches that of any existing GPU binding
of the object, so we'll create the mapping when the object is bound to
the first vma and release the mapping when the object is unbound from its
last vma.

Since the object can be bound to multiple vmas, we can end up creating a
new DMA mapping in the 3. case even if the object already had one. This
is not allowed by the DMA API and can lead to leaked mapping data and
IOMMU memory space starvation in certain cases. For example HW IOMMU
drivers (intel_iommu) allocate a new range from their memory space
whenever a mapping is created, silently overriding a pre-existing
mapping.

Fix this by moving the creation/removal of DMA mappings to the object's
get_pages/put_pages callbacks. These callbacks already check for and do
an early return in case of any nested calls. This way objects of the 3.
case also become more like the other object types.

I noticed this issue by enabling DMA debugging, which got disabled after
a while due to its internal mapping tables getting full. It also reported
errors in connection to random other drivers that did a DMA mapping for
an address that was previously mapped by i915 but was never released.
Besides these diagnostic messages and the memory space starvation
problem for IOMMUs, I'm not aware of this causing a real issue.

The fix is based on a patch from Chris.

v2:
- move the DMA mapping create/remove calls to the get_pages/put_pages
  callbacks instead of adding new callbacks for these (Chris)
v3:
- also fix the get_page cache logic on the userptr async path (Chris)

Signed-off-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-07-13 22:42:40 +02:00
..
amd Merge tag 'drm-amdkfd-fixes-2015-07-09' of git://people.freedesktop.org/~gabbayo/linux into drm-fixes 2015-07-10 15:56:19 +10:00
armada Merge branch 'drm-armada-devel' of git://ftp.arm.linux.org.uk/~rmk/linux-arm into drm-next 2015-05-15 15:24:41 +10:00
ast
atmel-hlcdc
bochs
bridge drm/exynos: atomic dpms support 2015-06-20 00:32:52 +09:00
cirrus
exynos drm/exynos: dsi: do not set TE GPIO direction by input 2015-06-22 20:05:03 +09:00
gma500
i2c Merge branch 'drm-tda998x-devel' of git://ftp.arm.linux.org.uk/~rmk/linux-arm into drm-next 2015-05-29 09:19:59 +10:00
i810
i915 drm/i915: avoid leaking DMA mappings 2015-07-13 22:42:40 +02:00
imx Merge branch 'drm-dwhdmi-devel' of git://ftp.arm.linux.org.uk/~rmk/linux-arm into drm-next 2015-04-16 08:33:30 +10:00
mga
mgag200 drm/mgag200: Reject non-character-cell-aligned mode widths 2015-06-16 10:01:16 +10:00
msm drm/msm: restart queued submits after hang 2015-06-11 13:11:06 -04:00
nouveau drm/nouveau/gem: use kvfree() in u_free() 2015-06-30 19:44:59 -07:00
omapdrm drm/omap: replace ALIGN(PAGE_SIZE) by PAGE_ALIGN 2015-07-02 15:58:07 +03:00
panel drm/panel: simple: Add bus format for HannStar HSD100PXN1 2015-06-12 16:40:42 +02:00
qxl drm/qxl: Propagate correctly errors from qxlhw_handle_to_bo 2015-06-05 11:00:52 +10:00
r128
radeon drm/radeon: disable vce init on cayman (v2) 2015-07-09 11:40:12 -04:00
rcar-du drm: rcar-du: Use the drm atomic state duplication helpers for planes 2015-06-16 14:25:55 +03:00
rockchip drivers/gpu: include <module.h> for modular rockchip code 2015-06-16 14:12:25 -04:00
savage
shmobile
sis
sti drm/sti: vtg fix CEA-861E video format timing error 2015-06-08 15:28:28 +02:00
tdfx
tegra drm/tegra: Changes for v4.2-rc1 2015-06-18 12:53:54 +10:00
tilcdc drm/tilcdc: Add DRM_TILCDC_SLAVE_COMPAT for ti,tilcdc,slave binding support 2015-05-27 13:13:33 +03:00
ttm drm/ttm: dma: Don't crash on memory in the vmalloc range 2015-06-02 17:24:49 +10:00
udl dma-buf: cleanup dma_buf_export() to make it easily extensible 2015-04-21 14:47:16 +05:30
vgem drm/vgem: Set unique to "vgem" 2015-06-24 11:20:46 +10:00
via
virtio virtio-gpu: add locking for vbuf pool 2015-06-16 11:22:41 +02:00
vmwgfx
ati_pcigart.c
drm_agpsupport.c
drm_atomic_helper.c drm/atomic: Don't set crtc_state->enable manually 2015-06-22 13:45:33 +02:00
drm_atomic.c drm/atomic: Extract needs_modeset function 2015-06-19 17:25:01 +02:00
drm_auth.c drm: simplify authentication management 2015-05-05 09:45:57 +02:00
drm_bridge.c drm/DocBook: Add more drm_bridge documentation 2015-05-21 13:56:51 +02:00
drm_bufs.c
drm_cache.c drm: Avoid the double clflush on the last cache line in drm_clflush_virt_range() 2015-06-19 17:25:17 +02:00
drm_context.c
drm_crtc_helper.c drm: Add drm_atomic_set_mode_for_crtc 2015-05-26 15:50:34 +02:00
drm_crtc_internal.h
drm_crtc.c drm/crtc: Fix edid length computation 2015-07-04 00:52:34 +02:00
drm_debugfs.c
drm_dma.c
drm_dp_helper.c drm: Fix for DP CTS test 4.2.2.5 - I2C DEFER handling 2015-04-20 09:29:41 -07:00
drm_dp_mst_topology.c drm/dp/mst: close deadlock in connector destruction. 2015-06-25 11:57:23 +10:00
drm_drv.c drm: Always enable atomic API 2015-06-24 11:21:35 +10:00
drm_edid_load.c drm: Add edid_corrupt flag for Displayport Link CTS 4.2.2.6 2015-05-08 13:03:46 +02:00
drm_edid.c Merge tag 'topic/drm-misc-2015-05-19' of git://anongit.freedesktop.org/drm-intel into drm-next 2015-05-20 09:19:58 +10:00
drm_encoder_slave.c
drm_fb_cma_helper.c
drm_fb_helper.c
drm_flip_work.c drm/core: get rid of -Iinclude/drm 2015-05-13 11:28:22 +02:00
drm_fops.c drm/mode: Add user blob-creation ioctl 2015-05-22 16:18:28 +02:00
drm_gem_cma_helper.c drm/cma: Fix 64-bit size_t build warnings 2015-06-15 07:45:49 +02:00
drm_gem.c
drm_global.c
drm_hashtab.c
drm_info.c
drm_internal.h drm: simplify authentication management 2015-05-05 09:45:57 +02:00
drm_ioc32.c
drm_ioctl.c Merge branch 'drm-next' of git://people.freedesktop.org/~airlied/linux 2015-06-26 13:18:51 -07:00
drm_irq.c Merge branch 'virtio-gpu-drm-next' of git://git.kraxel.org/linux into drm-next 2015-06-04 09:36:39 +10:00
drm_legacy.h
drm_lock.c
drm_memory.c
drm_mipi_dsi.c
drm_mm.c drm: clean up drm_mm debugfs output 2015-05-29 09:17:57 +10:00
drm_modes.c drm/mode: Unstatic kernel-userspace mode conversion 2015-05-22 16:18:21 +02:00
drm_modeset_lock.c drm: fix a memleak on mutex failure path 2015-05-05 09:26:43 +02:00
drm_of.c
drm_panel.c
drm_pci.c
drm_plane_helper.c drm/plane-helper: Adapt cursor hack to transitional helpers 2015-05-22 08:48:08 +03:00
drm_platform.c
drm_prime.c drm: prime: Document gem_prime_mmap 2015-06-19 17:50:05 +02:00
drm_probe_helper.c Merge tag 'topic/drm-misc-2015-05-06' of git://anongit.freedesktop.org/drm-intel into drm-next 2015-05-07 13:02:39 +10:00
drm_rect.c
drm_scatter.c
drm_sysfs.c Merge branch 'drm-next' of git://people.freedesktop.org/~airlied/linux 2015-06-26 13:18:51 -07:00
drm_trace_points.c
drm_trace.h
drm_vm.c
drm_vma_manager.c
Kconfig drm/amdgpu: add core driver (v4) 2015-06-03 21:03:15 -04:00
Makefile drm/amdgpu: add core driver (v4) 2015-06-03 21:03:15 -04:00