Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Critical] accel: ethosu: missing NHCWB16 format check when OFM
  transpose is set
--

commit 819bad25b9dbcbe54db35bf0c5afd5f5f47c3c99
Author: Rob Herring (Arm) <[email protected]>

accel: ethosu: Validate OFM transpose

This commit adds validation for Ethos-U85 output feature map (OFM)
transpose encodings and permutes the OFM dimensions before validating
tile and stride accesses.

> diff --git a/drivers/accel/ethosu/ethosu_gem.c 
> b/drivers/accel/ethosu/ethosu_gem.c
> index 0ab73b99c458c..b8f840ab1ceed 100644
> --- a/drivers/accel/ethosu/ethosu_gem.c
> +++ b/drivers/accel/ethosu/ethosu_gem.c

[ ... ]

> @@ -1029,8 +1083,19 @@ static int 
> ethosu_gem_cmdstream_copy_and_validate(struct drm_device *ddev,
>               case NPU_SET_OFM_PRECISION:
>                       if (((param >> 6) & 0x3) > 1)
>                               return -EINVAL;
> -                     if (!ethosu_is_u65(edev) && (param & GENMASK(13, 11)))
> -                             return -EINVAL;
> +                     if (!ethosu_is_u65(edev)) {
> +                             u32 transpose = 
> FIELD_GET(NPU_OFM_TRANSPOSE_MASK, param);
> +
> +                             switch (transpose) {
> +                             case 4:
> +                             case 5:
> +                                     return -EINVAL;
> +                             }
> +                             if (transpose && ((param >> 1) & 0x3) == 3)
> +                                     return -EINVAL;
> +                             if ((param >> 14) == 2 && transpose)
> +                                     return -EINVAL;
> +                     }
>                       st.ofm.precision = param;
>                       break;
>               case NPU_SET_OFM_REGION:

[Severity: Critical]
Should NPU_SET_OFM_PRECISION also reject a non-zero transpose when the
activation format is NHCWB16 (((param >> 6) & 0x3) == 1)?

OFM transposition on U85 is only valid with the linear NHWC format.  If
NHCWB16 is combined with a non-zero transpose, feat_matrix_validate() only
requires NPU_SET_OFM_STRIDE_C to be set, and feat_matrix_length() computes
the NHCWB16 brick offset on the coordinates already permuted by
feat_matrix_permute() while ignoring fm->stride_x.  That can underestimate
info->region_size[fm->region] and allow out-of-bounds NPU DMA writes past
the end of the GEM buffer.

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

Reply via email to