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

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

Reply via email to