From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C28D606A688 for ; Wed, 2 Dec 2026 22:36:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=uumosmlT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C6D191125AB; Wed, 2 Dec 2026 22:36:39 +0000 (UTC) Received: from mail-yx1-f41.google.com (mail-yx1-f41.google.com [74.125.224.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id 15D851125A4 for ; Wed, 2 Dec 2026 22:36:33 +0000 (UTC) Received: by mail-yx1-f41.google.com with SMTP id 956f58d0204a3-6798eb0d190so11006680d50.3 for ; Wed, 02 Dec 2026 14:36:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796250992; x=1796855792; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DM3OJUVbmjOAv+ZuqsdxO47SlfGR+fOHrugVLuVolnI=; b=uumosmlTnZM0DRsQ2UkEc3/9BKK8xbYObHDUf5+i/i2bN9f1uJ+XK9dqFsgOj2JftB t7fHbQN5Fipq8PIHJX8NkuFsirKcw97BSPVBi6NToud65aKmE6EXHtbEL8HYsgBRWY2/ /RLf7gW+d0sAcEJZ/T+LcXUgxxFa6Ah1Y9+a1rnqrT6s/nytSwOvW/VMiZvpZu+/lCbt +F5eXeCekmBi6PpsSlASGCbKZXmgAA2a+a2VnaesickzG6CmYDfH4VWuOvpn8xMDcdg+ auXbloJMyaqgpwY660pyFVc40g4uyNYgW954cdP9R8xJ3Vqhs4GSD9P4FBn4BWQ/qMuz w7jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796250992; x=1796855792; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=DM3OJUVbmjOAv+ZuqsdxO47SlfGR+fOHrugVLuVolnI=; b=XNnmlTV0ycJHbt7dbBW7ZlOIwNLudnfr6+aMdA/hkmiVNO8uu5cGXEiczESritSbww qlN8wQU0jE24QlFsODYPII7YNsUmW/SeHmvheP7+uU3TRFycJ34mGIwzRu60YpfItmmT ReAcmskfTrdKERVW74K55qnxt/bKggnbcX3dKMKMjw/iohRcs10vgFPqwERTXnH7bUyN 1zfPUwCsiZDZlMCL8pvHmEzNyNlZCY0vFNENe46Tnx6S397d/Ol9h8zYx5ht3ZxncCnP zrbz0vCmtmNQRFmQ0XDVvBv7+len8qRc072WsYxiZ+g+IJM3X6QCL8hqGiVpdYmv5Cff FNKQ== X-Gm-Message-State: APuU4Z/AOC/Gi3W2wGLfMl2TzsN8GoALE8nlQ38novp23CIYLDAAAdAT FY+uu628l0ehsN/R4zl5JS5zDwoNDpjBqGGWDCtJj82sHuD9HMvi9wajcOpTjB+Tlss= X-Gm-Gg: AZFdTZcdM6A4x+K6grpne7HKp96TmTcZ8+F9cAOv//dC9dYm/j/sDloncLh6Q6P5t9q zXbHj1yw9ZgtzfuJbLveEofu5pb8vA3icu26HyJPIToT88kXkMPGvArB8YVQNfBoI2uhudLguY4 EyJTPFL3Uz6UxNmwfrZ8P+3RlKQXLX+br+16N/j66P3qdaLk6GEcn5S6lIaSfzBvSfiML5tiv53 4KQkROxw//JMlv7EKlLIHgEJlF+rAsHWh3cVGW62JGraZYO/9Ncp7pctT5lTHPAeGB3C70HtbPw cM26GOTvFOnKzJ2Dx45lq4Cv6FVoXtpxI/GKxlclTZ7Cvim00yP6mXRV0wU96YhrzK+x3UAIOlG Xt8orlR8L4oGwXrexz4u5XxG6RVvxwyVSFvr044yjcmXp9EH+xCauMyjWb0HZRVOGrrtn+G9+XO IcRKkHBwAj8rymZZAQsBEShOqhGKCC2ofylksGsgUmahL9WpdDRUuz/wVzcYYb7T28BVlRcwj/Q XgipvmiUfmOQiGUE5XV2Jz3VgmSRdCpboeY2J2wpBBT9XN0u9YK0J1cYN9o+7R+KkreT35bdY3Y DSRU9zGGxXvM1efYbqph/nr5JAoof+n5ehjAiyDm2YRXu8jCQVGBsU+wC9dxpNri78ryO4/KwoF MN/pVdIQLZYpScZjLEJfA3RpwPeRxB1nCbeHUeg0XMiz9FZ6vnxxIwuW5QGHAwd1sewQgw9VouZ bMZF3wjeO/Yygj+ow6oPU= X-Received: by 2002:a05:690e:438d:b0:67c:2491:3754 with SMTP id 956f58d0204a3-67df4457d52mr11518792d50.81.1796250991874; Wed, 02 Dec 2026 14:36:31 -0800 (PST) Received: from localhost (107-220-129-194.lightspeed.chrlnc.sbcglobal.net. [107.220.129.194]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67df3378f59sm18008139d50.14.2026.12.02.14.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 14:36:31 -0800 (PST) From: Matt Turner Date: Wed, 02 Dec 2026 17:36:16 -0500 Subject: [PATCH 10/14] drm/amdgpu: dump the unsignaled fences of each ring in the coredump X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-amdgpu-devcoredump-v1-10-3dfa0e033b97@gmail.com> References: <20261202-amdgpu-devcoredump-v1-0-3dfa0e033b97@gmail.com> In-Reply-To: <20261202-amdgpu-devcoredump-v1-0-3dfa0e033b97@gmail.com> To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sunil Khatri , Trigger Huang Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Matt Turner , Gregoire Pean X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7473; i=mattst88@gmail.com; h=from:subject:message-id; bh=8COZy3ITBs8e6QlPKtgDQvQiEDoxZPuaB25jblwzmuE=; b=owGbwMvMwCW25rVmCc8sv+mMp9WSGLIF5kaI6061LbQ7vLUx5tvEOze+7r0f0uO1wdBblsnkt nTusdBjHR9ZGMS4GGaKKbLErVdkmdW2Y6nPaelfMHNYmUCGSIs0MAABCwNfbmJeqZGOkZ6ptqGe IZChYxQPkdNj0MgsLi5NLdJNKyhyyMsvSSzJzM8r1ssvSM0rSC/QS8tMK8nIyC8qTgUaoZeXWmL q6uhmZGhgYuloYeZk4Whq4uzsZOjk5ujo7OpkZGluYuBs6WjiamnOwMUpAHPNik8M/5RL58hJ7u 7VS+H9wS6o8u7+YrO1JXN2TTll+/6b55KN4cUM/4v9zefz2PJbJj//lFqvleH6Yf5KmSStj1OfC ntN+bXsKSsA X-Developer-Key: i=mattst88@gmail.com; a=openpgp; fpr=3BB639E56F861FA2E86505690FDD682D974CA72A X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The coredump has the ring contents and read and write pointers, but nothing to tell which part of the ring belongs to which submission, or which submissions were queued behind the hung one. For each ring in the dump, record the last signaled and last emitted sequence numbers and, for every unsignaled fence, its fence context, the ring position and size of its commands as recorded for queue reset, and how long ago it was emitted. This is captured along with the ring contents, reading the fences under the fence driver lock into a GFP_NOWAIT allocation. Emitting a fence reuses its slot without the fence driver lock, and polled fences take a seq without a slot, so a slot whose fence has a different seqno is skipped. amdgpu_ib_schedule() sets the size of a job's commands after emitting its fence, so mark that store and the read with WRITE_ONCE() and READ_ONCE(). Suggested-by: Gregoire Pean Signed-off-by: Matt Turner --- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 84 +++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 15 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 9 ++- 3 files changed, 104 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c index 62a0ae0aff87..3cb1927b0f47 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c @@ -571,6 +571,84 @@ amdgpu_devcoredump_print_ibs(struct drm_printer *p, } } +/* + * Record the unsignaled fences of @ring: for each, where the job was written + * to the ring and how long ago it was emitted. Together with the ring + * contents this shows which submissions were queued behind the hung one. + */ +static void amdgpu_devcoredump_capture_fences(struct amdgpu_ring *ring, + struct amdgpu_coredump_ring *cdump) +{ + struct amdgpu_fence_driver *drv = &ring->fence_drv; + unsigned long flags; + u32 count, seq; + + cdump->last_seq = atomic_read(&drv->last_seq); + cdump->sync_seq = READ_ONCE(drv->sync_seq); + + count = min(cdump->sync_seq - cdump->last_seq, drv->num_fences_mask + 1); + if (!count) + return; + + cdump->fences = kvzalloc_objs(struct amdgpu_coredump_fence, count, + GFP_NOWAIT | __GFP_NOWARN); + if (!cdump->fences) + return; + + spin_lock_irqsave(&drv->lock, flags); + rcu_read_lock(); + for (seq = cdump->sync_seq - count + 1; count--; seq++) { + struct amdgpu_coredump_fence *cf; + struct dma_fence *f; + struct amdgpu_fence *af; + + /* + * drv->lock doesn't keep the slots from being reused, and + * polled fences take a seq without a slot, so the slot may + * hold an older or newer fence. + */ + f = rcu_dereference(drv->fences[seq & drv->num_fences_mask]); + if (!f || f->seqno != seq || dma_fence_test_signaled_flag(f)) + continue; + + af = container_of(f, struct amdgpu_fence, base); + cf = &cdump->fences[cdump->num_fences++]; + cf->seq = seq; + cf->context = af->context; + cf->ib_wptr = af->ib_wptr; + /* 0 while the job is still being written to the ring */ + cf->ib_dw_size = READ_ONCE(af->ib_dw_size); + cf->skip_ib_dw_start = af->skip_ib_dw_start_offset; + cf->skip_ib_dw_end = af->skip_ib_dw_end_offset; + /* Set before the slot, so it is not after this ktime_get(). */ + cf->age_us = ktime_us_delta(ktime_get(), af->start_timestamp); + } + rcu_read_unlock(); + spin_unlock_irqrestore(&drv->lock, flags); +} + +static void amdgpu_devcoredump_print_fences(struct drm_printer *p, + struct amdgpu_coredump_ring *cdump) +{ + drm_printf(p, "Signaled seq: 0x%08x Emitted seq: 0x%08x\n", + cdump->last_seq, cdump->sync_seq); + + if (cdump->last_seq != cdump->sync_seq && !cdump->fences) { + drm_printf(p, "Unsignaled fences unavailable\n"); + return; + } + + for (u32 i = 0; i < cdump->num_fences; i++) { + struct amdgpu_coredump_fence *cf = &cdump->fences[i]; + + drm_printf(p, + "fence seq: 0x%08x context: %llu wptr: 0x%llx dw: %u skip: %u-%u age: %lld us\n", + cf->seq, cf->context, cf->ib_wptr, cf->ib_dw_size, + cf->skip_ib_dw_start, cf->skip_ib_dw_end, + cf->age_us); + } +} + static ssize_t amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_info *coredump) { @@ -701,6 +779,7 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_inf ring->buf_mask); drm_printf(&p, "Ring size in dwords: %d\n", ring->ring_size / 4); + amdgpu_devcoredump_print_fences(&p, &coredump->rings[i]); if (!coredump->rings[i].ring_dw) { drm_printf(&p, "Ring contents unavailable\n"); @@ -766,8 +845,10 @@ static void amdgpu_devcoredump_free(void *data) kvfree(coredump->formatted); amdgpu_devcoredump_free_blobs(coredump); - for (i = 0; i < coredump->num_rings; i++) + for (i = 0; i < coredump->num_rings; i++) { kvfree(coredump->rings[i].ring_dw); + kvfree(coredump->rings[i].fences); + } kvfree(coredump->rings); kvfree(data); } @@ -946,6 +1027,7 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, cdump_ring->ring_index = ring->idx; cdump_ring->rptr = amdgpu_ring_get_rptr(ring); cdump_ring->wptr = amdgpu_ring_get_wptr(ring); + amdgpu_devcoredump_capture_fences(ring, cdump_ring); idx++; } coredump->num_rings = idx; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h index c0192d0c583a..6a51fbe357dc 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h @@ -31,11 +31,26 @@ #define AMDGPU_COREDUMP_VERSION "1" +struct amdgpu_coredump_fence { + u64 context; + u64 ib_wptr; + s64 age_us; + u32 seq; + u32 ib_dw_size; + u32 skip_ib_dw_start; + u32 skip_ib_dw_end; +}; + struct amdgpu_coredump_ring { u64 rptr; u64 wptr; u32 *ring_dw; u32 ring_index; + u32 last_seq; + u32 sync_seq; + /* unsignaled fences, oldest first */ + struct amdgpu_coredump_fence *fences; + u32 num_fences; }; /* A range of GPU memory copied into the coredump */ diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c index ae028eeacaed..5d16d6f5f9da 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c @@ -199,8 +199,10 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, struct amdgpu_job *job, /* VM sequence */ vm_af->ib_wptr = ring->wptr; amdgpu_vm_flush(ring, job, &need_pipe_sync, &emit_gds_needed); - vm_af->ib_dw_size = - amdgpu_ring_get_dw_distance(ring, vm_af->ib_wptr, ring->wptr); + /* The devcoredump reads it locklessly once the fence is emitted. */ + WRITE_ONCE(vm_af->ib_dw_size, + amdgpu_ring_get_dw_distance(ring, vm_af->ib_wptr, + ring->wptr)); /* IB sequence */ af->ib_wptr = ring->wptr; @@ -318,7 +320,8 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, struct amdgpu_job *job, amdgpu_ring_ib_end(ring); - af->ib_dw_size = amdgpu_ring_get_dw_distance(ring, af->ib_wptr, ring->wptr); + WRITE_ONCE(af->ib_dw_size, + amdgpu_ring_get_dw_distance(ring, af->ib_wptr, ring->wptr)); amdgpu_ring_commit(ring); -- 2.56.1