From: sashiko-bot@kernel.org
To: "Armas Spann" <zappel@simple-co.de>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 1/9] drm/amdgpu/mes: distinguish rejected from timed out commands
Date: Thu, 26 Nov 2026 08:36:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-235042@kernel.org> (raw)
In-Reply-To: <20261125141933.154222-2-zappel@simple-co.de>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/amdgpu/mes: fence advances before fw_gen increment on MES
reset/init
- [Medium] drm/amdgpu/mes: uninitialized ticket on ring-full timeout and
poll check
--
commit e4539326964865817146e78f0e47609a33f0c453
Author: Armas Spann <zappel@simple-co.de>
drm/amdgpu/mes: distinguish rejected from timed out commands
This commit returns AMDGPU_MES_CMD_REJECTED (-EREMOTEIO) when MES responds
to a command with a failure status instead of timing out, and adds a
command ticket mechanism and per-XCC firmware generation counter to track
timed-out REMOVE_QUEUE commands across late completions and MES restarts.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
> index b71684d79b21a..c7beee52a790b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
[ ... ]
> @@ -329,6 +331,89 @@ void amdgpu_mes_fini(struct amdgpu_device *adev)
> mutex_destroy(&adev->mes.dbgext_drain_lock);
> }
>
> +/* True when MES has processed the command stream up to @seq. */
> +static bool amdgpu_mes_fence_passed(struct amdgpu_ring *ring, u32 seq)
> +{
> + u32 cur = le32_to_cpu(READ_ONCE(*ring->fence_drv.cpu_addr));
> +
> + return (s32)(seq - cur) <= 0;
> +}
> +
> +/**
> + * amdgpu_mes_ticket_poll - check on a command that timed out earlier
> + *
> + * @adev: amdgpu_device pointer
> + * @ticket: ticket filled in by the command path
> + *
> + * Does not sleep and takes no locks. The caller serialises against
> + * amdgpu_mes_ticket_release() on the same ticket.
> + */
> +enum amdgpu_mes_ticket_state
> +amdgpu_mes_ticket_poll(struct amdgpu_device *adev,
> + const struct amdgpu_mes_cmd_ticket *ticket)
> +{
> + const u64 *status;
> +
> + if (!ticket->valid ||
> + ticket->fw_gen != amdgpu_mes_fw_gen(&adev->mes, ticket->xcc_id))
> + return AMDGPU_MES_TICKET_STALE;
> +
> + status = (const u64 *)&adev->wb.wb[ticket->status_offs];
> + if (lower_32_bits(READ_ONCE(*status)))
> + return AMDGPU_MES_TICKET_DONE;
> +
> + if (!amdgpu_mes_fence_passed(&adev->mes.ring[ticket->ring_idx],
> + ticket->seq))
> + return AMDGPU_MES_TICKET_PENDING;
> +
> + /*
> + * MES writes the status before the trailing fence. Look again, and
> + * do not let that look be satisfied by a load made before the fence
> + * was seen.
> + */
> + dma_rmb();
> + return lower_32_bits(READ_ONCE(*status)) ?
> + AMDGPU_MES_TICKET_DONE : AMDGPU_MES_TICKET_FAILED;
> +}
[Severity: Medium]
Can amdgpu_mes_ticket_poll() misreport a stale ticket as
AMDGPU_MES_TICKET_FAILED across a reset or MES re-initialization?
Both during GPU reset and during MES hardware initialization, the
scheduler ring's trailing fence advances to or past ticket->seq before
adev->mes.fw_gen[xcc_id] is incremented:
1. In amdgpu_device_pre_asic_reset(), amdgpu_fence_driver_force_completion()
writes ring->fence_drv.sync_seq (>= ticket->seq) to
*ring->fence_drv.cpu_addr before MES is suspended or re-initialized.
2. In mes_v11_0_hw_init(), mes_v12_0_hw_init(), and
mes_v12_1_xcc_hw_init(), mes_v*_queue_init() clears the scheduler ring
and mes_v*_set_hw_resources() submits a command on that ring that
waits for the new MES instance to write a new sequence number
(> ticket->seq) to *ring->fence_drv.cpu_addr before atomic_inc() updates
fw_gen.
CPU0 CPU1
amdgpu_mes_ticket_poll() mes_v12_0_hw_init()
mes_v12_0_queue_init()
amdgpu_ring_clear_ring()
mes_v12_0_set_hw_resources()
/* fence advances past ticket->seq */
ticket->fw_gen == fw_gen
amdgpu_mes_fence_passed() == true
*status == 0
return AMDGPU_MES_TICKET_FAILED; <-- stale ticket reported as failed
atomic_inc(&adev->mes.fw_gen[0]);
Because *status is still 0 after the unanswered command was wiped,
amdgpu_mes_ticket_poll() returns AMDGPU_MES_TICKET_FAILED instead of
AMDGPU_MES_TICKET_STALE, and amdgpu_mes_ticket_answered() returns true
before MES is halted or fw_gen reflects the new instance. In addition,
amdgpu_mes_ticket_poll() does not re-check fw_gen after observing
amdgpu_mes_fence_passed(), and mes_v*_submit_pkt_ticket() records
ticket->fw_gen after the 2.1s poll timeout rather than under ring_lock at
submission time.
> +
> +/**
> + * amdgpu_mes_ticket_answered - has MES got past a timed out command
> + *
> + * @adev: amdgpu_device pointer
> + * @ticket: ticket, or a copy of one
> + *
> + * Unlike amdgpu_mes_ticket_poll() this does not look at the status slot,
> + * so it may be used on a copy whose original has been released.
> + */
> +bool amdgpu_mes_ticket_answered(struct amdgpu_device *adev,
> + const struct amdgpu_mes_cmd_ticket *ticket)
> +{
> + if (ticket->fw_gen != amdgpu_mes_fw_gen(&adev->mes, ticket->xcc_id))
> + return true;
> +
> + return amdgpu_mes_fence_passed(&adev->mes.ring[ticket->ring_idx],
> + ticket->seq);
> +}
> diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c b/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c
> index 5c046f64b0229..5fabf05d5584a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c
> +++ b/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c
> @@ -154,9 +154,10 @@ static const char *mes_v12_1_get_misc_op_string(union MESAPI__MISC *x_pkt)
> return op_str;
> }
>
> -static int mes_v12_1_submit_pkt_and_poll_completion(struct amdgpu_mes *mes,
> - int xcc_id, int pipe, void *pkt,
> - int size, int api_status_off)
> +static int mes_v12_1_submit_pkt_ticket(struct amdgpu_mes *mes,
> + int xcc_id, int pipe, void *pkt,
> + int size, int api_status_off,
> + struct amdgpu_mes_cmd_ticket *ticket)
> {
[ ... ]
> @@ -200,8 +201,10 @@ static int mes_v12_1_submit_pkt_and_poll_completion(struct amdgpu_mes *mes,
> r = amdgpu_fence_wait_polling(ring,
> seq - ring->fence_drv.num_fences_mask,
> timeout);
> - if (r < 1)
> + if (r < 1) {
> + r = -ETIMEDOUT;
> goto error_undo;
> + }
[Severity: Medium]
What happens to *ticket when mes_v11_0_submit_pkt_ticket(),
mes_v12_0_submit_pkt_ticket(), or mes_v12_1_submit_pkt_ticket() returns
-ETIMEDOUT on the error_undo path because the ring is full?
On that path the command is undone with amdgpu_ring_undo(), status_offset
is freed, and the function returns -ETIMEDOUT without initializing or
clearing *ticket. A caller that receives -ETIMEDOUT from remove_hw_queue()
and inspects the ticket will either read uninitialized fields or, if the
ticket was zeroed by the caller, see ticket->valid == false (which makes
amdgpu_mes_ticket_poll() return AMDGPU_MES_TICKET_STALE) and
ticket->fw_gen == 0 (which makes amdgpu_mes_ticket_answered(), as it does
not check ticket->valid, compare 0 against fw_gen >= 1 and return true, or
index adev->mes.fw_gen[ticket->xcc_id] and
adev->mes.ring[ticket->ring_idx] with untrusted values).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125141933.154222-1-zappel@simple-co.de?part=1
next prev parent reply other threads:[~2026-11-26 8:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 14:19 [PATCH v2 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-GPU Armas Spann
2026-11-25 14:19 ` [PATCH v2 1/9] drm/amdgpu/mes: distinguish rejected from timed out commands Armas Spann
2026-11-26 8:36 ` sashiko-bot [this message]
2026-11-25 14:19 ` [PATCH v2 2/9] drm/amdkfd: factor out freeing of per-queue MES resources Armas Spann
2026-11-25 14:19 ` [PATCH v2 3/9] drm/amdkfd: track whether MES knows each queue Armas Spann
2026-11-26 8:46 ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 4/9] drm/amdkfd: add a quarantine for queues MES has not retired Armas Spann
2026-11-26 8:49 ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 5/9] drm/amdkfd: keep queue storage until MES confirmed retirement Armas Spann
2026-11-26 8:39 ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 6/9] drm/amdkfd: keep eviction and restore consistent when MES fails Armas Spann
2026-11-26 8:36 ` sashiko-bot
2026-11-25 14:19 ` [PATCH v2 7/9] drm/amdkfd: apply queue property updates only after unmap Armas Spann
2026-11-25 14:19 ` [PATCH v2 8/9] drm/amdkfd: reconcile queue state with MES after a restart Armas Spann
2026-11-25 14:19 ` [PATCH v2 9/9] drm/amdkfd: force CWSR on with more than one MES GPU Armas Spann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-235042@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zappel@simple-co.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.