* [PATCH V1 1/2] accel/amdxdna: Check the fence error after waiting for a driver command
@ 2026-11-17 19:21 Lizhi Hou
2026-11-17 19:21 ` [PATCH V1 2/2] accel/amdxdna: Abort jobs when the firmware context is gone Lizhi Hou
0 siblings, 1 reply; 2+ messages in thread
From: Lizhi Hou @ 2026-11-17 19:21 UTC (permalink / raw)
To: ogabbay, quic_jhugo, dri-devel, mario.limonciello,
karol.wachowski, max.zhen
Cc: Lizhi Hou, linux-kernel, sonal.santan
aie2_cmd_wait() discarded the result of the wait, and both callers,
aie2_hwctx_cfg_debug_bo() and aie2_hwctx_sync_debug_bo(), decided
success solely from cmd->result.
cmd->result is only written by aie2_sched_drvcmd_resp_handler(), which
runs when firmware responds. If the job fails before it reaches
firmware, for example aie2_sync_bo() or aie2_config_debug_bo() fail to
send the mailbox message, the error is recorded on the fence and no
response handler runs. cmd is zero allocated, so cmd->result stays 0 and
the caller treats the failed command as successful.
aie2_hwctx_cfg_debug_bo() then goes on to update abo->assigned_hwctx.
Return the fence error from aie2_cmd_wait() and check it in both
callers. This also covers a fence errored after the command was posted,
and the case where aie2_cmd_get_out_fence() finds no fence at all, which
previously fell through to the same false success.
Fixes: 7ea046838021 ("accel/amdxdna: Support firmware debug buffer")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
drivers/accel/amdxdna/aie2_ctx.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
index 11f5421e497a..0a1914f0f1c0 100644
--- a/drivers/accel/amdxdna/aie2_ctx.c
+++ b/drivers/accel/amdxdna/aie2_ctx.c
@@ -984,20 +984,30 @@ static int aie2_hwctx_cu_config(struct amdxdna_hwctx *hwctx, void *buf, u32 size
return ret;
}
-static void aie2_cmd_wait(struct amdxdna_hwctx *hwctx, u64 seq)
+static int aie2_cmd_wait(struct amdxdna_hwctx *hwctx, u64 seq)
{
struct dma_fence *out_fence = aie2_cmd_get_out_fence(hwctx, seq);
struct amdxdna_dev *xdna = hwctx->client->xdna;
+ int ret;
if (!out_fence) {
XDNA_ERR(xdna, "Failed to get fence");
- return;
+ return -EINVAL;
}
mutex_unlock(&xdna->dev_lock);
dma_fence_wait_timeout(out_fence, false, MAX_SCHEDULE_TIMEOUT);
mutex_lock(&xdna->dev_lock);
+ /*
+ * The job may never reach firmware, for example the submission to
+ * the mailbox failed. In that case there is no response and
+ * cmd->result stays untouched, so the fence error is the only way
+ * to tell the command did not complete.
+ */
+ ret = out_fence->error;
dma_fence_put(out_fence);
+
+ return ret;
}
static int aie2_hwctx_cfg_debug_bo(struct amdxdna_hwctx *hwctx, u32 bo_hdl,
@@ -1044,7 +1054,12 @@ static int aie2_hwctx_cfg_debug_bo(struct amdxdna_hwctx *hwctx, u32 bo_hdl,
goto put_cmd;
}
- aie2_cmd_wait(hwctx, seq);
+ ret = aie2_cmd_wait(hwctx, seq);
+ if (ret) {
+ XDNA_ERR(xdna, "Command failed, ret %d", ret);
+ goto put_cmd;
+ }
+
if (cmd->result) {
XDNA_ERR(xdna, "Response failure 0x%x", cmd->result);
ret = -EINVAL;
@@ -1104,7 +1119,12 @@ int aie2_hwctx_sync_debug_bo(struct amdxdna_hwctx *hwctx, u32 debug_bo_hdl)
goto put_cmd;
}
- aie2_cmd_wait(hwctx, seq);
+ ret = aie2_cmd_wait(hwctx, seq);
+ if (ret) {
+ XDNA_ERR(xdna, "Command failed, ret %d", ret);
+ goto put_cmd;
+ }
+
if (cmd->result) {
XDNA_ERR(xdna, "Response failure 0x%x", cmd->result);
ret = -EINVAL;
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH V1 2/2] accel/amdxdna: Abort jobs when the firmware context is gone
2026-11-17 19:21 [PATCH V1 1/2] accel/amdxdna: Check the fence error after waiting for a driver command Lizhi Hou
@ 2026-11-17 19:21 ` Lizhi Hou
0 siblings, 0 replies; 2+ messages in thread
From: Lizhi Hou @ 2026-11-17 19:21 UTC (permalink / raw)
To: ogabbay, quic_jhugo, dri-devel, mario.limonciello,
karol.wachowski, max.zhen
Cc: Lizhi Hou, linux-kernel, sonal.santan
aie2_sched_job_run() returned NULL when the firmware context is gone
(mbox_chann pointer is NULL). The DRM scheduler treats a NULL return as
a job that completed without an error.
Return ERR_PTR(-ECANCELED) so the error is recorded on the fence, and mark
the command BO aborted.
Fixes: 6b13cb8f48a4 ("accel/amdxdna: Fix runtime suspend deadlock when there is pending job")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
drivers/accel/amdxdna/aie2_ctx.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
index 0a1914f0f1c0..3b898c05513e 100644
--- a/drivers/accel/amdxdna/aie2_ctx.c
+++ b/drivers/accel/amdxdna/aie2_ctx.c
@@ -404,8 +404,18 @@ aie2_sched_job_run(struct drm_sched_job *sched_job)
trace_xdna_job(sched_job, hwctx->name, "job run",
job->seq, job->drv_cmd ? job->drv_cmd->opcode : DEFAULT_IO);
- if (!hwctx->priv->mbox_chann)
- return NULL;
+ /*
+ * The firmware context is gone, but the scheduler keeps draining the
+ * entity, for example from drm_sched_entity_destroy(). Returning NULL
+ * would make the DRM scheduler signal the job fence without an error
+ * and user space would see the command as successfully completed.
+ * Abort the job instead. Driver internal commands have no command BO.
+ */
+ if (!hwctx->priv->mbox_chann) {
+ if (cmd_abo)
+ amdxdna_cmd_set_state(cmd_abo, ERT_CMD_STATE_ABORT);
+ return ERR_PTR(-ECANCELED);
+ }
if (!mmget_not_zero(job->mm))
return ERR_PTR(-ESRCH);
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 19:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 19:21 [PATCH V1 1/2] accel/amdxdna: Check the fence error after waiting for a driver command Lizhi Hou
2026-11-17 19:21 ` [PATCH V1 2/2] accel/amdxdna: Abort jobs when the firmware context is gone Lizhi Hou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®