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 C8D17606A32C for ; Fri, 4 Dec 2026 14:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jcNjokOT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6A19110E864; Fri, 4 Dec 2026 14:30:24 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id D568D10E88B for ; Fri, 4 Dec 2026 14:30:17 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id A2524453D0; Fri, 4 Dec 2026 14:30:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 600EF1F00934; Fri, 4 Dec 2026 14:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796394617; bh=PziMmg3spglX2V9wTTrnVAeFZdWpNtAXmLGnOM/Wksk=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=jcNjokOTo4U7U+cZ8bWNeCyXga4LUr9soS/uwF+zHmm4DzBrtzoKts78z9B97UAL0 7HQy4dfft51xRUKZTo5icJjPYvOe8at6ai3sbiwHbiaig9dS8HfKBI1J8+4DYh4HtU ecLX2dmpmuwIq9GRZjPJvL8H/kX4z5Ivd82LRyc6/dhS9dF88HTygRNe8T6k5h9fSi Ilmo9AzmA8Q0AOnbXg/P2ul0JWLwziXHzQ0L+5Fn35J1iSI8RuITrOUgYWqJh89jVp m/jw1MBUSaK/nJYDfQt5/Qt15DO+C44VxRzHYbdylR4a3dmC30iAUl9ZHkI/Khm8xn MPxLAR/WI8o5g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/8] drm/amdgpu/mes: distinguish rejected from timed out commands To: "Armas Spann" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261204125251.10703-2-zappel@simple-co.de> References: <20261204125251.10703-1-zappel@simple-co.de> <20261204125251.10703-2-zappel@simple-co.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:30:16 +0000 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: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] drm/amdgpu/mes: failed reset breaks amdgpu_mes_ticket_poll() reset check - [Medium] drm/amdgpu/mes: mes_v*_submit_pkt_ticket() misclassifies reset-forced fence - [Medium] drm/amdgpu: amdgpu_mes_ticket_poll() misreports state on failed reset/resume - [Low] drm/amdgpu/mes: missing writer barriers pairing with ticket smp_rmb() -- commit 1712012870309920f5ca4962dcbb7f16034640d2 Author: Armas Spann drm/amdgpu/mes: distinguish rejected from timed out commands This commit returns AMDGPU_MES_CMD_REJECTED (-EREMOTEIO) instead of -ETIMEDOUT when MES answers a command with a failure status, and adds a per-XCC firmware generation counter and command tickets so callers can track late completions of timed out REMOVE_QUEUE commands. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c b/drivers/gpu/drm/am= d/amdgpu/amdgpu_mes.c > index 27d6371d8d791..ef226183d7eb5 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c [ ... ] > + /* > + * The fence was passed without a success status. That is a failure > + * reported by MES only if MES moved the fence. A GPU reset moves it > + * as well (amdgpu_device_pre_asic_reset()), and so does the first > + * command of the next firmware instance, both before fw_gen is > + * incremented. Neither says anything about a command the old > + * instance never answered. The reset flag is set before the fence > + * is forced and cleared after fw_gen went up, so it is read after > + * the fence and before the generation. > + */ > + if (amdgpu_in_reset(adev)) > + return AMDGPU_MES_TICKET_STALE; > + /* Read the generation after the reset flag, see above */ > + smp_rmb(); > + if (ticket->fw_gen !=3D amdgpu_mes_fw_gen(&adev->mes, ticket->xcc_id)) > + return AMDGPU_MES_TICKET_STALE; > + > + return AMDGPU_MES_TICKET_FAILED; > +} [Severity: Medium] Does the invariant that in_gpu_reset is only cleared after fw_gen goes up hold when a GPU reset fails or aborts? amdgpu_device_pre_asic_reset() forces *mes_ring->fence_drv.cpu_addr to sync_seq before the reset runs. If amdgpu_device_asic_reset() then aborts early (for example, amdgpu_ras_is_rma() returning -ENODEV before MES is halted), amdgpu_device_gpu_recover() jumps to reset_unlock and clears in_gpu_reset without incrementing fw_gen. Once in_gpu_reset is 0, amdgpu_mes_ticket_poll() permanently returns AMDGPU_MES_TICKET_FAILED and amdgpu_mes_ticket_answered() returns true for a command MES never processed. If KFD later resumes scheduling without reinitializing MES (such as on the unwind_userq path of amdgpu_device_suspend()), callers can call amdgpu_mes_ticket_release() and return the writeback status slot to adev->wb.used while the unanswered command is still in the live MES ring, allowing a late DMA write to corrupt the next owner of that slot. > +bool amdgpu_mes_ticket_answered(struct amdgpu_device *adev, > + const struct amdgpu_mes_cmd_ticket *ticket) > +{ > + bool passed; > + > + if (!ticket->valid || > + ticket->fw_gen !=3D amdgpu_mes_fw_gen(&adev->mes, ticket->xcc_id)) > + return true; > + > + passed =3D amdgpu_mes_fence_passed(&adev->mes.ring[ticket->ring_idx], > + ticket->seq); > + > + /* > + * A GPU reset forces the fence, see amdgpu_mes_ticket_poll(). The > + * flag is set before that happens, so read it after the fence. > + */ > + smp_rmb(); > + if (amdgpu_in_reset(adev)) > + return false; > + > + return passed; > +} [Severity: Low] Are the smp_rmb() barriers in amdgpu_mes_ticket_poll() and amdgpu_mes_ticket_answered() paired with explicit write barriers on the writer side? atomic_inc(&adev->mes.fw_gen[...]) is relaxed, and amdgpu_device_unlock_reset_domain() clears in_gpu_reset with a relaxed atomic_set() before up_write(), so nothing explicitly orders the fw_gen increment before in_gpu_reset becomes 0. Likewise, amdgpu_device_lock_reset_domain() sets in_gpu_reset with a relaxed atomic_set() before acquire-only down_write(), and amdgpu_fence_write() writes *drv->cpu_addr with an unmarked plain store rather than WRITE_ONCE(). On weakly ordered SMP architectures, store reordering can let amdgpu_mes_ticket_poll() observe in_gpu_reset =3D=3D 0 with the old fw_gen = and return AMDGPU_MES_TICKET_FAILED instead of AMDGPU_MES_TICKET_STALE, or let amdgpu_mes_ticket_answered() observe the forced fence with in_gpu_reset =3D=3D 0 and return true mid-reset. The unmarked store in amdgpu_fence_write() is also a KCSAN data race against READ_ONCE() in amdgpu_mes_fence_passed(). Adding smp_wmb() around the in_gpu_reset updates (or atomic_set_release() on unlock) and WRITE_ONCE() in amdgpu_fence_write() would pair the barriers properly. > diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c b/drivers/gpu/drm/amd= /amdgpu/mes_v11_0.c > index 7d8a56859fce5..fc8822458adda 100644 > --- a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c > +++ b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c [ ... ] > @@ -264,9 +271,20 @@ static int mes_v11_0_submit_pkt_and_poll_completion(= struct amdgpu_mes *mes, > x_pkt->header.opcode); > =20 > r =3D amdgpu_fence_wait_polling(ring, seq, timeout); > + /* The status is written before the fence, read it after the fence */ > + dma_rmb(); > if (r < 1 || !*status_ptr) { > + /* The fence was reached, so MES processed the command */ > + bool answered =3D r >=3D 1; [Severity: Medium] Can a reset-forced ring fence cause mes_v11_0_submit_pkt_ticket() to misclassify an unanswered command as rejected by MES? CPU0 CPU1 kfd_dbg_set_mes_debug_mode() amdgpu_device_pre_asic_reset() mes_v11_0_submit_pkt_ticket() amdgpu_fence_wait_polling() amdgpu_fence_driver_force_completion() /* r >=3D 1, *status_ptr =3D=3D 0 */ answered =3D true; <-- returns AMDGPU_MES_CMD_REJECTED amdgpu_device_pre_asic_reset() forces every ready MES ring fence to sync_seq without holding adev->mes.mutex_hidden and before amdgpu_device_ip_suspend() stops MES. Several callers submit MES packets without adev->reset_domain->sem, including kfd_dbg_set_mes_debug_mode(), mes_notify_unmap_work_handler(), and amdgpu_userq_preempt_helper(). When the forced fence wakes a concurrent poller with status 0, this path logs a bogus rejection with status 0, returns AMDGPU_MES_CMD_REJECTED (-EREMOTEIO) instead of -ETIMEDOUT (propagating -EREMOTEIO to userspace on KFD debug ioctls), and frees the writeback slot before MES is stopped. The same issue is present in mes_v12_0_submit_pkt_ticket(), mes_v12_1_submit_pkt_ticket(), and mes_v13_0_submit_pkt_ticket(). > diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c b/drivers/gpu/drm/amd= /amdgpu/mes_v12_1.c > index 84a3693db6ad4..d7cdce5be4af3 100644 > --- a/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c > +++ b/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c [ ... ] > @@ -1909,6 +1966,12 @@ static int mes_v12_1_xcc_hw_init(struct amdgpu_ip_= block *ip_block, int xcc_id) > if (r) > goto failure; > =20 > + /* > + * A new scheduler instance is up on this XCC, it knows none of the > + * old queues. The other XCCs keep theirs. > + */ > + atomic_inc(&adev->mes.fw_gen[xcc_id]); > + > mes_v12_1_set_hw_resources_1(&adev->mes, AMDGPU_MES_SCHED_PIPE, xcc_id); > mes_v12_1_init_aggregated_doorbell(&adev->mes, xcc_id); [Severity: Medium] Does advancing the MES ring fence in mes_v12_1_set_hw_resources() before incrementing adev->mes.fw_gen[xcc_id] break ticket polling outside GPU reset? During S3/S4 resume or a suspend error unwind, amdgpu_in_reset(adev) is 0. mes_v12_1_set_hw_resources() submits a command that moves *ring->fence_drv.cpu_addr past any prior ticket's seq before fw_gen is incremented, and if that command is rejected, goto failure skips the atomic_inc() altogether. A ticket created before suspend then sees a passed fence with status 0, in_gpu_reset =3D=3D 0, and an unchanged fw_gen, so amdgpu_mes_ticket_poll() returns AMDGPU_MES_TICKET_FAILED instead of AMDGPU_MES_TICKET_STALE and amdgpu_mes_ticket_answered() returns true. On a suspend unwind into amdgpu_amdkfd_resume(), that lets amdgpu_mes_ticket_release() free the writeback status slot prematurely. The same ordering exists in mes_v11_0_hw_init(), mes_v12_0_hw_init(), and mes_v13_0_hw_init(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204125251.1070= 3-1-zappel@simple-co.de?part=3D1