Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm: gpu: msm: forbid mem reclaim from reset

We sometimes get into a situtation where GPU hangcheck fails to
recover GPU:

[..]
msm_dpu ae01000.display-controller: [drm:hangcheck_handler] *ERROR* (IPv4: 1): hangcheck detected gpu lockup rb 0!
msm_dpu ae01000.display-controller: [drm:hangcheck_handler] *ERROR* (IPv4: 1): completed fence: 7840161
msm_dpu ae01000.display-controller: [drm:hangcheck_handler] *ERROR* (IPv4: 1): submitted fence: 7840162
msm_dpu ae01000.display-controller: [drm:hangcheck_handler] *ERROR* (IPv4: 1): hangcheck detected gpu lockup rb 0!
msm_dpu ae01000.display-controller: [drm:hangcheck_handler] *ERROR* (IPv4: 1): completed fence: 7840162
msm_dpu ae01000.display-controller: [drm:hangcheck_handler] *ERROR* (IPv4: 1): submitted fence: 7840163
[..]

The problem is that msm_job worker is blocked on gpu->lock

INFO: task ring0:155 blocked for more than 122 seconds.
Not tainted 6.6.99-08727-gaac38b365d2c #1
task:ring0 state:D stack:0 pid:155 ppid:2 flags:0x00000008
Call trace:
__switch_to+0x108/0x208
schedule+0x544/0x11f0
schedule_preempt_disabled+0x30/0x50
__mutex_lock_common+0x410/0x850
__mutex_lock_slowpath+0x28/0x40
mutex_lock+0x5c/0x90
msm_job_run+0x9c/0x140
drm_sched_main+0x514/0x938
kthread+0x114/0x138
ret_from_fork+0x10/0x20

which is owned by recover worker, which is waiting for DMA fences
from a memory reclaim path, under the very same gpu->lock

INFO: task ring0:155 is blocked on a mutex likely owned by task gpu-worker:154.
task:gpu-worker state:D stack:0 pid:154 ppid:2 flags:0x00000008
Call trace:
__switch_to+0x108/0x208
schedule+0x544/0x11f0
schedule_timeout+0x1f8/0x770
dma_fence_default_wait+0x108/0x218
dma_fence_wait_timeout+0x6c/0x1c0
dma_resv_wait_timeout+0xe4/0x118
active_purge+0x34/0x98
drm_gem_lru_scan+0x1d0/0x388
msm_gem_shrinker_scan+0x1cc/0x2e8
shrink_slab+0x228/0x478
shrink_node+0x380/0x730
try_to_free_pages+0x204/0x510
__alloc_pages_direct_reclaim+0x90/0x158
__alloc_pages_slowpath+0x1d4/0x4a0
__alloc_pages+0x9f0/0xc88
vm_area_alloc_pages+0x17c/0x260
__vmalloc_node_range+0x1c0/0x420
kvmalloc_node+0xe8/0x108
msm_gpu_crashstate_capture+0x1e4/0x280
recover_worker+0x1c0/0x638
kthread_worker_fn+0x150/0x2d8
kthread+0x114/0x138

So no one can make any further progress.

Forbid recover/fault worker to enter memory reclaim (under
gpu->lock) to address this deadlock scenario.

Cc: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Rob Clark <rob.clark@oss.qualcomm.com>
Patchwork: https://patchwork.freedesktop.org/patch/700978/
Message-ID: <20260127073341.2862078-1-senozhatsky@chromium.org>
Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>

authored by

Sergey Senozhatsky and committed by
Rob Clark
4625fe5b cebf747a

+11
+11
drivers/gpu/drm/msm/msm_gpu.c
··· 17 17 #include <linux/string_helpers.h> 18 18 #include <linux/devcoredump.h> 19 19 #include <linux/sched/task.h> 20 + #include <linux/sched/mm.h> 20 21 21 22 /* 22 23 * Power Management: ··· 470 469 struct msm_gem_submit *submit; 471 470 struct msm_ringbuffer *cur_ring = gpu->funcs->active_ring(gpu); 472 471 char *comm = NULL, *cmd = NULL; 472 + unsigned int noreclaim_flag; 473 473 struct task_struct *task; 474 474 int i; 475 475 ··· 508 506 msm_gem_vm_unusable(submit->vm); 509 507 } 510 508 509 + noreclaim_flag = memalloc_noreclaim_save(); 510 + 511 511 get_comm_cmdline(submit, &comm, &cmd); 512 512 513 513 if (comm && cmd) { ··· 527 523 /* Record the crash state */ 528 524 pm_runtime_get_sync(&gpu->pdev->dev); 529 525 msm_gpu_crashstate_capture(gpu, submit, NULL, comm, cmd); 526 + 527 + memalloc_noreclaim_restore(noreclaim_flag); 530 528 531 529 kfree(cmd); 532 530 kfree(comm); ··· 594 588 struct msm_gem_submit *submit; 595 589 struct msm_ringbuffer *cur_ring = gpu->funcs->active_ring(gpu); 596 590 char *comm = NULL, *cmd = NULL; 591 + unsigned int noreclaim_flag; 597 592 598 593 mutex_lock(&gpu->lock); 599 594 600 595 submit = find_submit(cur_ring, cur_ring->memptrs->fence + 1); 601 596 if (submit && submit->fault_dumped) 602 597 goto resume_smmu; 598 + 599 + noreclaim_flag = memalloc_noreclaim_save(); 603 600 604 601 if (submit) { 605 602 get_comm_cmdline(submit, &comm, &cmd); ··· 618 609 pm_runtime_get_sync(&gpu->pdev->dev); 619 610 msm_gpu_crashstate_capture(gpu, submit, fault_info, comm, cmd); 620 611 pm_runtime_put_sync(&gpu->pdev->dev); 612 + 613 + memalloc_noreclaim_restore(noreclaim_flag); 621 614 622 615 kfree(cmd); 623 616 kfree(comm);