linux/include/drm
Rob Herring edbd7f318c drm/shmem: Use mutex_trylock in drm_gem_shmem_purge
Lockdep reports a circular locking dependency with pages_lock taken in
the shrinker callback. The deadlock can't actually happen with current
users at least as a BO will never be purgeable when pages_lock is held.
To be safe, let's use mutex_trylock() instead and bail if a BO is locked
already.

WARNING: possible circular locking dependency detected
5.3.0-rc1+ #100 Tainted: G             L
------------------------------------------------------
kswapd0/171 is trying to acquire lock:
000000009b9823fd (&shmem->pages_lock){+.+.}, at: drm_gem_shmem_purge+0x20/0x40

but task is already holding lock:
00000000f82369b6 (fs_reclaim){+.+.}, at: __fs_reclaim_acquire+0x0/0x40

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (fs_reclaim){+.+.}:
       fs_reclaim_acquire.part.18+0x34/0x40
       fs_reclaim_acquire+0x20/0x28
       __kmalloc_node+0x6c/0x4c0
       kvmalloc_node+0x38/0xa8
       drm_gem_get_pages+0x80/0x1d0
       drm_gem_shmem_get_pages+0x58/0xa0
       drm_gem_shmem_get_pages_sgt+0x48/0xd0
       panfrost_mmu_map+0x38/0xf8 [panfrost]
       panfrost_gem_open+0xc0/0xe8 [panfrost]
       drm_gem_handle_create_tail+0xe8/0x198
       drm_gem_handle_create+0x3c/0x50
       panfrost_gem_create_with_handle+0x70/0xa0 [panfrost]
       panfrost_ioctl_create_bo+0x48/0x80 [panfrost]
       drm_ioctl_kernel+0xb8/0x110
       drm_ioctl+0x244/0x3f0
       do_vfs_ioctl+0xbc/0x910
       ksys_ioctl+0x78/0xa8
       __arm64_sys_ioctl+0x1c/0x28
       el0_svc_common.constprop.0+0x90/0x168
       el0_svc_handler+0x28/0x78
       el0_svc+0x8/0xc

-> #0 (&shmem->pages_lock){+.+.}:
       __lock_acquire+0xa2c/0x1d70
       lock_acquire+0xdc/0x228
       __mutex_lock+0x8c/0x800
       mutex_lock_nested+0x1c/0x28
       drm_gem_shmem_purge+0x20/0x40
       panfrost_gem_shrinker_scan+0xc0/0x180 [panfrost]
       do_shrink_slab+0x208/0x500
       shrink_slab+0x10c/0x2c0
       shrink_node+0x28c/0x4d8
       balance_pgdat+0x2c8/0x570
       kswapd+0x22c/0x638
       kthread+0x128/0x130
       ret_from_fork+0x10/0x18

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(fs_reclaim);
                               lock(&shmem->pages_lock);
                               lock(fs_reclaim);
  lock(&shmem->pages_lock);

 *** DEADLOCK ***

3 locks held by kswapd0/171:
 #0: 00000000f82369b6 (fs_reclaim){+.+.}, at: __fs_reclaim_acquire+0x0/0x40
 #1: 00000000ceb37808 (shrinker_rwsem){++++}, at: shrink_slab+0xbc/0x2c0
 #2: 00000000f31efa81 (&pfdev->shrinker_lock){+.+.}, at: panfrost_gem_shrinker_scan+0x34/0x180 [panfrost]

Fixes: 17acb9f35e ("drm/shmem: Add madvise state and purge helpers")
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Sean Paul <sean@poorly.run>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Rob Herring <robh@kernel.org>
Reviewed-by: Steven Price <steven.price@arm.com>
Acked-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190823021216.5862-6-robh@kernel.org
2019-08-28 10:02:39 -05:00
..
bridge drm/bridge: dw-hdmi: move audio channel setup out of ahb 2019-08-14 15:03:11 +02:00
i2c
ttm drm-misc-next for 5.4: 2019-08-21 16:44:41 +10:00
amd_asic_type.h drm/amdgpu: add renoir asic_type enum 2019-08-12 12:47:49 -05:00
ati_pcigart.h
drm_agpsupport.h drm/agp: Remove unused function drm_agp_bind_pages 2019-07-15 18:11:30 +02:00
drm_atomic_helper.h drm/atomic: Move __drm_atomic_helper_disable_plane/set_config() 2019-06-08 16:46:37 +02:00
drm_atomic_state_helper.h drm/atomic: Add a function to reset connector TV properties 2019-06-19 12:17:52 +02:00
drm_atomic_uapi.h drm: extract drm_atomic_uapi.c 2018-09-09 14:19:18 +02:00
drm_atomic.h drm: Add helpers to kick off self refresh mode in drivers 2019-06-13 14:31:10 -04:00
drm_audio_component.h Prep patches + headers for the mei-hdcp/i915 component interfaces 2019-02-20 11:53:48 +02:00
drm_auth.h drm: make drm/drm_auth.h self contained 2019-05-27 18:05:44 +02:00
drm_blend.h
drm_bridge.h drm-misc-next for v5.3: 2019-06-14 11:44:24 +02:00
drm_cache.h drm: change func to better detect wether swiotlb is needed 2019-02-20 13:29:29 +01:00
drm_client.h drm/client: Support unmapping of DRM client buffers 2019-08-01 15:01:22 +02:00
drm_color_mgmt.h drm: Constify drm_color_lut_check() 2019-01-29 23:26:12 +02:00
drm_connector.h drm: Fix kerneldoc warns in connector-related docs 2019-08-12 10:16:39 -04:00
drm_crtc_helper.h drm: Split out drm_probe_helper.h 2019-01-24 13:20:42 +01:00
drm_crtc.h drm/crc-debugfs: Add notes about CRC<->commit interactions 2019-08-06 18:27:53 +01:00
drm_damage_helper.h drm/damage-helper: Add drm_atomic_helper_damage_merged() 2019-01-17 10:56:54 +01:00
drm_debugfs_crc.h
drm_debugfs.h drm: drm_debugfs.h self-contained 2019-06-10 22:30:24 +02:00
drm_device.h drm: Integrate VRAM MM into struct drm_device 2019-05-15 16:17:06 +02:00
drm_displayid.h drm/edid: parse CEA blocks embedded in DisplayID 2019-06-25 14:32:26 +10:00
drm_dp_dual_mode_helper.h
drm_dp_helper.h drm/dp_mst: Enable registration of AUX devices for MST ports 2019-07-25 16:39:35 -04:00
drm_dp_mst_helper.h drm/dp_mst: Enable registration of AUX devices for MST ports 2019-07-25 16:39:35 -04:00
drm_drv.h drm/prime: Ditch gem_prime_res_obj hook 2019-07-31 10:19:23 +02:00
drm_dsc.h drm/dsc: Split DSC PPS and SDP header initialisations 2019-03-05 13:24:34 -05:00
drm_edid.h Linux 5.2-rc5 2019-06-19 12:07:29 +02:00
drm_encoder_slave.h drm: remove include of drmP.h from drm_encoder_slave.h 2019-01-09 22:35:35 +01:00
drm_encoder.h drm: Add drm/drm_util.h header file 2018-09-09 14:18:11 +02:00
drm_fb_cma_helper.h drm/cma-helper: Remove unused fbdev code 2019-01-17 10:56:38 +01:00
drm_fb_helper.h drm/fb-helper: Prepare to move out modeset config code 2019-06-11 14:47:17 +02:00
drm_file.h drm/legacy: remove some legacy lock struct members 2019-04-24 12:36:32 +10:00
drm_fixed.h
drm_flip_work.h
drm_format_helper.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
drm_fourcc.h drm/fourcc: Fix the parameters name in the documentation 2019-05-21 16:58:05 +02:00
drm_framebuffer.h drm/fb: document dirty helper better 2019-06-11 18:02:48 +02:00
drm_gem_cma_helper.h drm: remove drmP.h from drm_gem_cma_helper.h 2019-01-09 22:54:08 +01:00
drm_gem_framebuffer_helper.h drm/fb: remove unused function: drm_gem_fbdev_fb_create() 2019-07-21 19:32:38 +02:00
drm_gem_shmem_helper.h drm/shmem: Use mutex_trylock in drm_gem_shmem_purge 2019-08-28 10:02:39 -05:00
drm_gem_vram_helper.h drm/vram: use embedded gem object 2019-08-06 08:21:53 +02:00
drm_gem.h dma-buf: rename reservation_object to dma_resv 2019-08-13 09:09:30 +02:00
drm_hashtab.h
drm_hdcp.h drm/hdcp: update content protection property with uevent 2019-08-06 13:17:23 +05:30
drm_ioctl.h drm/ioctl: Ditch DRM_UNLOCKED except for the legacy vblank ioctl 2019-06-21 19:13:10 +02:00
drm_irq.h
drm_lease.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 2019-05-30 11:26:37 -07:00
drm_legacy.h drm: make drm/drm_legacy.h self-contained 2019-05-27 18:06:15 +02:00
drm_mipi_dbi.h drm/tinydrm: Move mipi-dbi 2019-07-25 10:45:07 +02:00
drm_mipi_dsi.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
drm_mm.h
drm_mode_config.h drm: Add Content protection type property 2019-08-06 13:14:07 +05:30
drm_mode_object.h
drm_modes.h drm/selftests: reduce stack usage 2019-07-01 09:50:58 +02:00
drm_modeset_helper_vtables.h Linux 5.2-rc5 2019-06-19 12:07:29 +02:00
drm_modeset_helper.h drm: remove drmP.h from drm_modeset_helper.h 2019-02-07 21:48:34 +01:00
drm_modeset_lock.h drm: Trivial comment grammar cleanups 2019-02-04 10:21:17 +01:00
drm_of.h
drm_os_linux.h
drm_panel.h drm/panel: drop return code from drm_panel_detach() 2019-08-10 15:41:48 +02:00
drm_pci.h
drm_pciids.h drm/radeon: change SPDX identifier to MIT 2018-10-15 16:16:12 -05:00
drm_plane_helper.h drm: Unexport drm_plane_helper_check_update 2018-10-05 22:45:19 +02:00
drm_plane.h drm/docs: More links for implicit/explicit fencing. 2019-06-03 17:11:33 +02:00
drm_prime.h drm/prime: Align gem_prime_export with obj_funcs.export 2019-06-21 17:30:49 +02:00
drm_print.h drm: fix build errors with drm_print.h 2019-06-10 22:58:53 +02:00
drm_probe_helper.h drm: Split out drm_probe_helper.h 2019-01-24 13:20:42 +01:00
drm_property.h drm: Fix kernel doc for DRM_MODE_PROP_IMMUTABLE 2018-10-03 13:05:12 -07:00
drm_rect.h drm: Nuke drm_calc_{h,v}scale_relaxed() 2019-02-07 13:14:06 +02:00
drm_scdc_helper.h
drm_self_refresh_helper.h drm: Add helpers to kick off self refresh mode in drivers 2019-06-13 14:31:10 -04:00
drm_simple_kms_helper.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
drm_syncobj.h drm/syncobj: add new drm_syncobj_add_point interface v4 2019-04-01 12:05:53 +02:00
drm_sysfs.h drm: uevent for connector status change 2019-08-06 13:16:54 +05:30
drm_util.h drm: fix drm_can_sleep() comment 2019-01-21 10:30:12 +01:00
drm_utils.h drm: export drm_timeout_abs_to_jiffies 2019-03-07 12:00:30 -06:00
drm_vblank.h drm: drop uapi dependency from drm_vblank.h 2019-07-19 23:24:16 +02:00
drm_vma_manager.h drm: increase drm mmap_range size to 1TB 2019-04-24 16:20:23 -05:00
drm_vram_mm_helper.h drm: add missing include to drm_vram_mm_helper.h 2019-07-15 18:11:31 +02:00
drm_writeback.h drm: writeback: Add job prepare and cleanup operations 2019-03-18 17:24:38 +02:00
drmP.h dma-buf: rename reservation_object to dma_resv 2019-08-13 09:09:30 +02:00
gma_drm.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 335 2019-06-05 17:37:06 +02:00
gpu_scheduler.h drm/scheduler: Add flag to hint the release of guilty job. 2019-05-02 15:50:55 -05:00
i915_component.h drm/i915/tgl: Add additional ports for Tiger Lake 2019-07-11 16:31:14 -07:00
i915_drm.h drm/i915: Drop extern qualifiers from header function prototypes 2019-07-12 13:04:54 +01:00
i915_mei_hdcp_interface.h drm/i915: header for i915 - MEI_HDCP interface 2019-02-15 18:56:35 +01:00
i915_pciids.h drm/i915/cml: Add Missing PCI IDs 2019-08-15 12:55:54 -07:00
intel_lpe_audio.h
intel-gtt.h drm: include kernel.h and agp_backend.h from intel-gtt.h 2019-01-02 11:37:47 +02:00
spsc_queue.h