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 <[email protected]> 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/[email protected]?part=1
