All of lore.kernel.org
 help / color / mirror / Atom feed
* [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
  2026-11-17 19:44 ` [PATCH V1 1/2] accel/amdxdna: Check the fence error after waiting for a driver command sashiko-bot
  0 siblings, 2 replies; 3+ 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 related	[flat|nested] 3+ 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
  2026-11-17 19:44 ` [PATCH V1 1/2] accel/amdxdna: Check the fence error after waiting for a driver command sashiko-bot
  1 sibling, 0 replies; 3+ 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 related	[flat|nested] 3+ messages in thread

* Re: [PATCH V1 1/2] accel/amdxdna: Check the fence error after waiting for a driver command
  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
@ 2026-11-17 19:44 ` sashiko-bot
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-17 19:44 UTC (permalink / raw)
  To: Lizhi Hou, dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] accel/amdxdna: false -EINVAL in aie2_cmd_wait() when fence is
  garbage-collected
--

commit c14f81e589ab4e7ef12c7146189062d34baca05a
Author: Lizhi Hou <lizhi.hou@amd.com>

accel/amdxdna: Check the fence error after waiting for a driver command

This commit returns the out_fence error from aie2_cmd_wait() and checks
that return value in aie2_hwctx_cfg_debug_bo() and
aie2_hwctx_sync_debug_bo() so driver commands that fail before reaching
firmware are not treated as successful.

> diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
> index 74d7019268cb6..87bd6117e943f 100644
> --- a/drivers/accel/amdxdna/aie2_ctx.c
> +++ b/drivers/accel/amdxdna/aie2_ctx.c
> @@ -980,20 +980,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;
>  	}

[Severity: Medium]
Can aie2_cmd_wait() return -EINVAL for a command that already succeeded if
a concurrent submission on the same hwctx advances hwctx->priv->syncobj
before aie2_cmd_get_out_fence() runs?

drivers/accel/amdxdna/aie2_ctx.c:aie2_cmd_get_out_fence() {
    ...
	ret = dma_fence_chain_find_seqno(&fence,  seq);
	if (ret)
		goto out;

	out_fence = dma_fence_get(dma_fence_chain_contained(fence));
    ...
}

aie2_cmd_submit() drops hwctx->priv->io_lock after adding the timeline
point to hwctx->priv->syncobj, and regular command submissions via
amdxdna_drm_submit_cmd_ioctl() do not hold xdna->dev_lock:

CPU0                                  CPU1
aie2_hwctx_cfg_debug_bo()
  amdxdna_cmd_submit(..., &seq)
    ...
    drm_syncobj_add_point(..., seq)
    mutex_unlock(&hwctx->priv->io_lock)
  <job at seq finishes and signals>
                                      amdxdna_drm_submit_cmd_ioctl()
                                        ...
                                        drm_syncobj_add_point(..., seq + 1)
  aie2_cmd_wait(hwctx, seq)
    aie2_cmd_get_out_fence(hwctx, seq)
      dma_fence_chain_find_seqno(&fence, seq)
        dma_fence_chain_walk()
          /* seq is signaled: sets fence = NULL, returns 0 */
    if (!out_fence)
      return -EINVAL;  <-- false failure

When aie2_hwctx_cfg_debug_bo() hits this race, it jumps to put_cmd without
updating abo->assigned_hwctx even though firmware already executed
ATTACH_DEBUG_BO or DETACH_DEBUG_BO, leaving abo->assigned_hwctx out of
sync with firmware.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117192157.154516-1-lizhi.hou@amd.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-17 19:44 UTC | newest]

Thread overview: 3+ 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
2026-11-17 19:44 ` [PATCH V1 1/2] accel/amdxdna: Check the fence error after waiting for a driver command sashiko-bot

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.