All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Armas Spann" <zappel@simple-co.de>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v1 1/9] drm/amdgpu/mes: distinguish rejected from timed out commands
Date: Tue, 24 Nov 2026 16:19:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-231541@kernel.org> (raw)
In-Reply-To: <20261124143433.49736-2-zappel@simple-co.de>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/amdgpu/mes: global fw_gen incremented per XCC in
  mes_v12_1_xcc_hw_init()
- [Medium] drm/amdgpu/mes: 32-bit status_ptr in
  mes_v12_1_submit_pkt_ticket() drops upper status
- [Medium] drm/amdgpu/mes: missing dma_rmb() in amdgpu_mes_ticket_poll()
--

commit 8b562c80dbe629587cfa83feaa73d36461087d6f
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
completes a command with a failure status instead of timing out, and adds
command tickets and a firmware generation counter to track timed-out
REMOVE_QUEUE commands.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
> index b71684d79b21a..fd1d3d7541a0a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
> @@ -329,6 +330,84 @@ 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 != (u32)atomic_read(&adev->mes.fw_gen))
> +		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. */
> +	return lower_32_bits(READ_ONCE(*status)) ?
> +		AMDGPU_MES_TICKET_DONE : AMDGPU_MES_TICKET_FAILED;
> +}

[Severity: Medium]
Should a dma_rmb() separate the load of *ring->fence_drv.cpu_addr in
amdgpu_mes_fence_passed() from the second READ_ONCE(*status)?

The control dependency on amdgpu_mes_fence_passed() does not order
load-to-load on weakly-ordered architectures.  When a timed-out command
completes concurrently with amdgpu_mes_ticket_poll(), the CPU can satisfy
the second READ_ONCE(*status) from the stale 0 value loaded before the
fence check, returning AMDGPU_MES_TICKET_FAILED for a command that
succeeded.

[ ... ]

> diff --git a/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c b/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c
> index 5c046f64b0229..a2e0156ae66b7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c
> +++ b/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c

[ ... ]

> @@ -238,7 +241,18 @@ static int mes_v12_1_submit_pkt_and_poll_completion(struct amdgpu_mes *mes,
>  
>  	r = amdgpu_fence_wait_polling(ring, seq, timeout);
>  	if (r < 1 || !*status_ptr) {
> -		if (misc_op_str)
> +		/* The fence was reached, so MES processed the command */
> +		bool answered = r >= 1;
> +
> +		if (answered)
> +			dev_err(adev->dev,
> +				"MES(%d, %d) rejected msg=%s (opcode %d), status 0x%016llx\n",
> +				xcc_id, pipe,
> +				misc_op_str ? misc_op_str :
> +				op_str ? op_str : "unknown",
> +				x_pkt->header.opcode,
> +				(unsigned long long)*status_ptr);

[Severity: Medium]
Does dereferencing status_ptr here always print 0x0000000000000000 when
answered is true?

Unlike mes_v11_0 and mes_v12_0, which declare status_ptr as u64 *,
mes_v12_1_submit_pkt_ticket() declares status_ptr as u32 *:

drivers/gpu/drm/amd/amdgpu/mes_v12_1.c:mes_v12_1_submit_pkt_ticket() {
	...
	u32 *status_ptr;
	...
	status_ptr = &adev->wb.wb[status_offset];
	*status_ptr = 0;
}

Because entering this branch with r >= 1 requires !*status_ptr, the
32-bit *status_ptr is guaranteed to be 0 and the firmware error code in
the upper 32 bits of the 64-bit MES_API_STATUS writeback slot is never
read (nor is the upper half cleared before submission).

[ ... ]

> @@ -1901,6 +1941,9 @@ static int mes_v12_1_xcc_hw_init(struct amdgpu_ip_block *ip_block, int xcc_id)
>  	if (r)
>  		goto failure;
>  
> +	/* A new scheduler instance is up, it knows none of the old queues */
> +	atomic_inc(&adev->mes.fw_gen);
> +
>  	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: High]
Does incrementing a single device-wide adev->mes.fw_gen in
mes_v12_1_xcc_hw_init() invalidate live tickets on other XCCs?

On GFX 12.1 each XCC runs its own MES scheduler instance and can be
reinitialized independently during a partition reset via
gfx_v12_1_xcp_resume() -> gfx_v12_1_xcc_cp_resume() ->
amdgpu_mes_kiq_hw_init() -> mes_v12_1_xcc_hw_init().  Bumping the shared
adev->mes.fw_gen causes amdgpu_mes_ticket_poll() to return
AMDGPU_MES_TICKET_STALE and amdgpu_mes_ticket_answered() to return true
for pending tickets on unreset XCCs, allowing amdgpu_mes_ticket_release()
to free their status writeback slots while those XCCs' MES instances can
still write to them.  Tracking fw_gen per ring or per XCC would avoid
this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124143433.49736-1-zappel@simple-co.de?part=1

  reply	other threads:[~2026-11-24 16:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 14:34 [PATCH v1 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-GPU Armas Spann
2026-11-24 14:34 ` [PATCH v1 1/9] drm/amdgpu/mes: distinguish rejected from timed out commands Armas Spann
2026-11-24 16:19   ` sashiko-bot [this message]
2026-11-24 14:34 ` [PATCH v1 2/9] drm/amdkfd: factor out freeing of per-queue MES resources Armas Spann
2026-11-24 16:09   ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 3/9] drm/amdkfd: track whether MES knows each queue Armas Spann
2026-11-24 16:30   ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 4/9] drm/amdkfd: add a quarantine for queues MES has not retired Armas Spann
2026-11-24 16:29   ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 5/9] drm/amdkfd: keep queue storage until MES confirmed retirement Armas Spann
2026-11-24 16:29   ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 6/9] drm/amdkfd: keep eviction and restore consistent when MES fails Armas Spann
2026-11-24 16:30   ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 7/9] drm/amdkfd: apply queue property updates only after unmap Armas Spann
2026-11-24 16:42   ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 8/9] drm/amdkfd: reconcile queue state with MES after a restart Armas Spann
2026-11-24 16:53   ` sashiko-bot
2026-11-24 14:34 ` [PATCH v1 9/9] drm/amdkfd: force CWSR on with more than one MES GPU Armas Spann
2026-11-25 14:15 ` [PATCH v1 0/9] drm/amdgpu/amdkfd: fix MES queue lifecycle on multi-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-231541@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.