Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] accel/amdxdna: callers of aie2_query_status() and telemetry
  still log XDNA_ERR
- [Low] accel/amdxdna: hwctx init callers still log XDNA_ERR on user
  argument errors
- [Low] accel/amdxdna: missed user-triggered XDNA_ERR logs in aie2_ctx
  and aie4_ctx
--

commit fd97c1b6e4406ad375e1432c6e04b4230da9f6c0
Author: Lizhi Hou <[email protected]>

accel/amdxdna: Downgrade user triggered error messages to debug

This commit downgrades error messages triggered by invalid user space
ioctl arguments from XDNA_ERR to XDNA_DBG across the amdxdna driver.

> diff --git a/drivers/accel/amdxdna/aie2_ctx.c 
> b/drivers/accel/amdxdna/aie2_ctx.c
> index 582e171b5fd73..f1396d7feff5b 100644
> --- a/drivers/accel/amdxdna/aie2_ctx.c
> +++ b/drivers/accel/amdxdna/aie2_ctx.c
> @@ -548,7 +548,7 @@ static int aie2_hwctx_col_list(struct amdxdna_hwctx 
> *hwctx)
>  
>       hwctx->num_col = hwctx->num_tiles / ndev->aie.metadata.core.row_count;
>       if (!hwctx->num_col || hwctx->num_col > ndev->total_col) {
> -             XDNA_ERR(xdna, "Invalid num_col %d", hwctx->num_col);
> +             XDNA_DBG(xdna, "Invalid num_col %d", hwctx->num_col);
>               return -EINVAL;
>       }

[Severity: Low]
When aie2_hwctx_col_list() rejects an invalid user num_tiles here (or when
aie4_hwctx_umq_init() rejects an invalid or undersized umq_bo handle), do the
callers still log XDNA_ERR?  aie2_hwctx_init() logs XDNA_ERR("Create col list
failed, ret %d", ret) and amdxdna_drm_create_hwctx_ioctl() logs XDNA_ERR("Init
hwctx failed, ret %d", ret) whenever hwctx_init() fails, so bad user arguments
to DRM_IOCTL_AMDXDNA_CREATE_HWCTX still produce error-level log messages.

> @@ -953,7 +953,7 @@ static int aie2_hwctx_cu_config(struct amdxdna_hwctx 
> *hwctx, void *buf, u32 size
>               return -EINVAL;
>  
>       if (hwctx->cus) {
> -             XDNA_ERR(xdna, "Not support re-config CU");
> +             XDNA_DBG(xdna, "Not support re-config CU");
>               return -EINVAL;
>       }
>  
> diff --git a/drivers/accel/amdxdna/aie2_message.c 
> b/drivers/accel/amdxdna/aie2_message.c
> index d95a18af9b091..078a53586e844 100644
> --- a/drivers/accel/amdxdna/aie2_message.c
> +++ b/drivers/accel/amdxdna/aie2_message.c
> @@ -402,14 +402,14 @@ int aie2_query_status(struct amdxdna_dev_hdl *ndev, 
> char __user *buf,
>  
>       if (buf_sz < resp.size) {
>               ret = -EINVAL;
> -             XDNA_ERR(xdna, "Bad buffer size. Available: %u. Needs: %u", 
> buf_sz, resp.size);
> +             XDNA_DBG(xdna, "Bad buffer size. Available: %u. Needs: %u", 
> buf_sz, resp.size);
>               goto fail;
>       }
>  
>       size = min(size, resp.size);
>       if (copy_to_user(buf, buff_addr, size)) {
>               ret = -EFAULT;
> -             XDNA_ERR(xdna, "Failed to copy NPU status to user space");
> +             XDNA_DBG(xdna, "Failed to copy NPU status to user space");
>               goto fail;
>       }
>  
> @@ -452,14 +452,14 @@ int aie2_query_telemetry(struct amdxdna_dev_hdl *ndev,
>  
>       if (buf_sz < resp.size) {
>               ret = -EINVAL;
> -             XDNA_ERR(xdna, "Bad buffer size. Available: %u. Needs: %u", 
> buf_sz, resp.size);
> +             XDNA_DBG(xdna, "Bad buffer size. Available: %u. Needs: %u", 
> buf_sz, resp.size);
>               goto free_buf;
>       }
>  
>       size = min(size, resp.size);
>       if (copy_to_user(buf, addr, size)) {
>               ret = -EFAULT;
> -             XDNA_ERR(xdna, "Failed to copy telemetry to user space");
> +             XDNA_DBG(xdna, "Failed to copy telemetry to user space");
>               goto free_buf;
>       }

[Severity: Low]
Should the callers aie2_get_aie_status() and aie2_get_telemetry() in
drivers/accel/amdxdna/aie2_pci.c also downgrade or drop their XDNA_ERR logs
when aie2_query_status() and aie2_query_telemetry() fail?  Both callers still
unconditionally log XDNA_ERR on any non-zero return, so a bad user buffer
pointer, an undersized telemetry buffer, or an invalid header->type will still
log at error level.

> diff --git a/drivers/accel/amdxdna/aie4_ctx.c 
> b/drivers/accel/amdxdna/aie4_ctx.c
> index 7904e05ca8269..175f431ee6424 100644
> --- a/drivers/accel/amdxdna/aie4_ctx.c
> +++ b/drivers/accel/amdxdna/aie4_ctx.c

[ ... ]

> @@ -800,7 +800,7 @@ static int validate_cmd_abo(struct amdxdna_dev *xdna, 
> struct amdxdna_gem_obj *cm
>               u64 dtrace_buf = READ_ONCE(dpu->dtrace_buffer);
>  
>               if (upper_32_bits(dtrace_buf) > U16_MAX) {
> -                     XDNA_ERR(xdna, "Invalid dtrace buffer address 0x%llx", 
> dtrace_buf);
> +                     XDNA_DBG(xdna, "Invalid dtrace buffer address 0x%llx", 
> dtrace_buf);
>                       return -EINVAL;
>               }
>       } else {
> @@ -809,11 +809,11 @@ static int validate_cmd_abo(struct amdxdna_dev *xdna, 
> struct amdxdna_gem_obj *cm
>                       u64 dtrace_buf = READ_ONCE(dpu[i].dtrace_buffer);
>  
>                       if (uci >= HSA_MAX_LEVEL1_INDIRECT_ENTRIES) {
> -                             XDNA_ERR(xdna, "Invalid uc index %u", uci);
> +                             XDNA_DBG(xdna, "Invalid uc index %u", uci);
>                               return -EINVAL;
>                       }
>                       if (upper_32_bits(dtrace_buf) > U16_MAX) {
> -                             XDNA_ERR(xdna, "Invalid dtrace buffer address 
> 0x%llx", dtrace_buf);
> +                             XDNA_DBG(xdna, "Invalid dtrace buffer address 
> 0x%llx", dtrace_buf);
>                               return -EINVAL;
>                       }
>               }

[Severity: Low]
Were a few adjacent user-input checks in aie4_ctx.c and aie2_ctx.c missed?  In
aie4_ctx.c, the identical upper_32_bits(dtrace_buf) > U16_MAX check in
fill_direct_pkt() still uses XDNA_ERR (reachable if user space modifies the
shared command BO after validate_cmd_abo()).  In aie2_ctx.c, the 
!hwctx->num_tiles
check in aie2_hwctx_col_list() and the !config->num_cus and total_size > size
checks in aie2_hwctx_cu_config() also still log with XDNA_ERR.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1

Reply via email to