All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response
@ 2026-11-17 21:27 Lizhi Hou
  2026-11-17 21:27 ` [PATCH V2 2/2] accel/amdxdna: Abort jobs when the firmware context is gone Lizhi Hou
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lizhi Hou @ 2026-11-17 21:27 UTC (permalink / raw)
  To: ogabbay, quic_jhugo, dri-devel, mario.limonciello,
	karol.wachowski, max.zhen
  Cc: Lizhi Hou, linux-kernel, sonal.santan

aie2_hwctx_cfg_debug_bo() and aie2_hwctx_sync_debug_bo() decide 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, 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, leaving it out of sync with firmware.

Set cmd->result to U32_MAX before submitting, so a command which gets
no response is reported as a failure.

Fixes: 7ea046838021 ("accel/amdxdna: Support firmware debug buffer")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
V2:
   Use a simplier fix to address sashiko comment.

 drivers/accel/amdxdna/aie2_ctx.c    | 12 +++++++++---
 drivers/accel/amdxdna/amdxdna_ctx.h |  5 +++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
index 11f5421e497aa..32458d05635f9 100644
--- a/drivers/accel/amdxdna/aie2_ctx.c
+++ b/drivers/accel/amdxdna/aie2_ctx.c
@@ -989,10 +989,14 @@ static void 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;
 
-	if (!out_fence) {
-		XDNA_ERR(xdna, "Failed to get fence");
+	/*
+	 * No fence to wait for. Either seq has already signaled and a later
+	 * point pruned it out of the timeline chain, or the syncobj was
+	 * reset. Neither means the command failed, so leave the verdict to
+	 * the caller, which inspects cmd->result.
+	 */
+	if (!out_fence)
 		return;
-	}
 
 	mutex_unlock(&xdna->dev_lock);
 	dma_fence_wait_timeout(out_fence, false, MAX_SCHEDULE_TIMEOUT);
@@ -1022,6 +1026,7 @@ static int aie2_hwctx_cfg_debug_bo(struct amdxdna_hwctx *hwctx, u32 bo_hdl,
 		goto put_obj;
 	}
 	kref_init(&cmd->refcnt);
+	cmd->result = U32_MAX;
 
 	if (attach) {
 		if (abo->assigned_hwctx != AMDXDNA_INVALID_CTX_HANDLE) {
@@ -1095,6 +1100,7 @@ int aie2_hwctx_sync_debug_bo(struct amdxdna_hwctx *hwctx, u32 debug_bo_hdl)
 	if (!cmd)
 		return -ENOMEM;
 	kref_init(&cmd->refcnt);
+	cmd->result = U32_MAX;
 
 	cmd->opcode = SYNC_DEBUG_BO;
 	ret = amdxdna_cmd_submit(client, cmd, AMDXDNA_INVALID_BO_HANDLE,
diff --git a/drivers/accel/amdxdna/amdxdna_ctx.h b/drivers/accel/amdxdna/amdxdna_ctx.h
index 2e6b300d652f8..bf248d3f16ed1 100644
--- a/drivers/accel/amdxdna/amdxdna_ctx.h
+++ b/drivers/accel/amdxdna/amdxdna_ctx.h
@@ -145,6 +145,11 @@ enum amdxdna_job_opcode {
 
 struct amdxdna_drv_cmd {
 	enum amdxdna_job_opcode	opcode;
+	/*
+	 * Written by the firmware response handler only. Set it to U32_MAX
+	 * before submitting, so a job which never reaches firmware, and thus
+	 * gets no response, is not mistaken for a successful command.
+	 */
 	u32			result;
 	struct kref		refcnt;
 };
-- 
2.34.1


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

* [PATCH V2 2/2] accel/amdxdna: Abort jobs when the firmware context is gone
  2026-11-17 21:27 [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response Lizhi Hou
@ 2026-11-17 21:27 ` Lizhi Hou
  2026-11-17 21:54   ` Max Zhen
  2026-11-17 21:41 ` [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response sashiko-bot
  2026-11-17 21:54 ` Max Zhen
  2 siblings, 1 reply; 5+ messages in thread
From: Lizhi Hou @ 2026-11-17 21:27 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 32458d05635f9..c42ea1b4e08d2 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] 5+ messages in thread

* Re: [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response
  2026-11-17 21:27 [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response Lizhi Hou
  2026-11-17 21:27 ` [PATCH V2 2/2] accel/amdxdna: Abort jobs when the firmware context is gone Lizhi Hou
@ 2026-11-17 21:41 ` sashiko-bot
  2026-11-17 21:54 ` Max Zhen
  2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-17 21:41 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: premature return in aie2_cmd_wait() when
  syncobj is reset
--

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

accel/amdxdna: Detect a driver command without firmware response

This commit initializes cmd->result to U32_MAX before submitting debug BO
driver commands so that commands which never receive a firmware response are
reported as failures.

> diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
> index 74d7019268cb6..7525fefa6f1ef 100644
> --- a/drivers/accel/amdxdna/aie2_ctx.c
> +++ b/drivers/accel/amdxdna/aie2_ctx.c
> @@ -985,10 +985,14 @@ static void 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;
>  
> -	if (!out_fence) {
> -		XDNA_ERR(xdna, "Failed to get fence");
> +	/*
> +	 * No fence to wait for. Either seq has already signaled and a later
> +	 * point pruned it out of the timeline chain, or the syncobj was
> +	 * reset. Neither means the command failed, so leave the verdict to
> +	 * the caller, which inspects cmd->result.
> +	 */
> +	if (!out_fence)
>  		return;
> -	}
>  
>  	mutex_unlock(&xdna->dev_lock);
>  	dma_fence_wait_timeout(out_fence, false, MAX_SCHEDULE_TIMEOUT);
> @@ -1018,6 +1022,7 @@ static int aie2_hwctx_cfg_debug_bo(struct amdxdna_hwctx *hwctx, u32 bo_hdl,
>  		goto put_obj;
>  	}
>  	kref_init(&cmd->refcnt);
> +	cmd->result = U32_MAX;

[Severity: Medium]
Can aie2_hwctx_cfg_debug_bo() and aie2_hwctx_sync_debug_bo() observe
cmd->result == U32_MAX while the job is still running if the syncobj was
reset?

aie2_ctx_syncobj_create() exports hwctx->priv->syncobj to userspace as
hwctx->syncobj_hdl.  If userspace resets that syncobj while a debug BO
command is in flight, aie2_cmd_get_out_fence() returns NULL and
aie2_cmd_wait() returns immediately without waiting for the job to
finish:

CPU0                              CPU1
aie2_hwctx_cfg_debug_bo()
  cmd->result = U32_MAX
  amdxdna_cmd_submit()
                                  DRM_IOCTL_SYNCOBJ_RESET
                                    drm_syncobj_replace_fence(..., NULL)
  aie2_cmd_wait()
    out_fence = NULL
    return
  if (cmd->result)                <-- sees U32_MAX, returns -EINVAL
                                  aie2_sched_drvcmd_resp_handler()
                                    job->drv_cmd->result = 0

Unlike the pruned timeline point case where seq has already signaled,
resetting the syncobj drops the fence before the firmware responds.
aie2_hwctx_cfg_debug_bo() then sees cmd->result == U32_MAX and skips
updating abo->assigned_hwctx even though firmware still executes the
attach or detach command, leaving abo->assigned_hwctx out of sync with
firmware.

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

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

* Re: [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response
  2026-11-17 21:27 [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response Lizhi Hou
  2026-11-17 21:27 ` [PATCH V2 2/2] accel/amdxdna: Abort jobs when the firmware context is gone Lizhi Hou
  2026-11-17 21:41 ` [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response sashiko-bot
@ 2026-11-17 21:54 ` Max Zhen
  2 siblings, 0 replies; 5+ messages in thread
From: Max Zhen @ 2026-11-17 21:54 UTC (permalink / raw)
  To: Lizhi Hou, ogabbay, quic_jhugo, dri-devel, mario.limonciello,
	karol.wachowski
  Cc: linux-kernel, sonal.santan



On 11/17/2026 Tue 13:27, Lizhi Hou wrote:
> aie2_hwctx_cfg_debug_bo() and aie2_hwctx_sync_debug_bo() decide 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, 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, leaving it out of sync with firmware.
> 
> Set cmd->result to U32_MAX before submitting, so a command which gets
> no response is reported as a failure.
> 
> Fixes: 7ea046838021 ("accel/amdxdna: Support firmware debug buffer")
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Max Zhen <max.zhen@amd.com>
> ---
> V2:
>     Use a simplier fix to address sashiko comment.
> 
>   drivers/accel/amdxdna/aie2_ctx.c    | 12 +++++++++---
>   drivers/accel/amdxdna/amdxdna_ctx.h |  5 +++++
>   2 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
> index 11f5421e497aa..32458d05635f9 100644
> --- a/drivers/accel/amdxdna/aie2_ctx.c
> +++ b/drivers/accel/amdxdna/aie2_ctx.c
> @@ -989,10 +989,14 @@ static void 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;
>   
> -	if (!out_fence) {
> -		XDNA_ERR(xdna, "Failed to get fence");
> +	/*
> +	 * No fence to wait for. Either seq has already signaled and a later
> +	 * point pruned it out of the timeline chain, or the syncobj was
> +	 * reset. Neither means the command failed, so leave the verdict to
> +	 * the caller, which inspects cmd->result.
> +	 */
> +	if (!out_fence)
>   		return;
> -	}
>   
>   	mutex_unlock(&xdna->dev_lock);
>   	dma_fence_wait_timeout(out_fence, false, MAX_SCHEDULE_TIMEOUT);
> @@ -1022,6 +1026,7 @@ static int aie2_hwctx_cfg_debug_bo(struct amdxdna_hwctx *hwctx, u32 bo_hdl,
>   		goto put_obj;
>   	}
>   	kref_init(&cmd->refcnt);
> +	cmd->result = U32_MAX;
>   
>   	if (attach) {
>   		if (abo->assigned_hwctx != AMDXDNA_INVALID_CTX_HANDLE) {
> @@ -1095,6 +1100,7 @@ int aie2_hwctx_sync_debug_bo(struct amdxdna_hwctx *hwctx, u32 debug_bo_hdl)
>   	if (!cmd)
>   		return -ENOMEM;
>   	kref_init(&cmd->refcnt);
> +	cmd->result = U32_MAX;
>   
>   	cmd->opcode = SYNC_DEBUG_BO;
>   	ret = amdxdna_cmd_submit(client, cmd, AMDXDNA_INVALID_BO_HANDLE,
> diff --git a/drivers/accel/amdxdna/amdxdna_ctx.h b/drivers/accel/amdxdna/amdxdna_ctx.h
> index 2e6b300d652f8..bf248d3f16ed1 100644
> --- a/drivers/accel/amdxdna/amdxdna_ctx.h
> +++ b/drivers/accel/amdxdna/amdxdna_ctx.h
> @@ -145,6 +145,11 @@ enum amdxdna_job_opcode {
>   
>   struct amdxdna_drv_cmd {
>   	enum amdxdna_job_opcode	opcode;
> +	/*
> +	 * Written by the firmware response handler only. Set it to U32_MAX
> +	 * before submitting, so a job which never reaches firmware, and thus
> +	 * gets no response, is not mistaken for a successful command.
> +	 */
>   	u32			result;
>   	struct kref		refcnt;
>   };


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

* Re: [PATCH V2 2/2] accel/amdxdna: Abort jobs when the firmware context is gone
  2026-11-17 21:27 ` [PATCH V2 2/2] accel/amdxdna: Abort jobs when the firmware context is gone Lizhi Hou
@ 2026-11-17 21:54   ` Max Zhen
  0 siblings, 0 replies; 5+ messages in thread
From: Max Zhen @ 2026-11-17 21:54 UTC (permalink / raw)
  To: Lizhi Hou, ogabbay, quic_jhugo, dri-devel, mario.limonciello,
	karol.wachowski
  Cc: linux-kernel, sonal.santan



On 11/17/2026 Tue 13:27, Lizhi Hou wrote:
> 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>
Reviewed-by: Max Zhen <max.zhen@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 32458d05635f9..c42ea1b4e08d2 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);


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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 21:27 [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response Lizhi Hou
2026-11-17 21:27 ` [PATCH V2 2/2] accel/amdxdna: Abort jobs when the firmware context is gone Lizhi Hou
2026-11-17 21:54   ` Max Zhen
2026-11-17 21:41 ` [PATCH V2 1/2] accel/amdxdna: Detect a driver command without firmware response sashiko-bot
2026-11-17 21:54 ` Max Zhen

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.