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 <[email protected]>
---
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

Reply via email to