dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rob Herring (Arm)" <robh@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 26/31] accel: ethosu: Split U65 and U85 DMA length validation
Date: Thu, 29 Oct 2026 15:32:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-189611@kernel.org> (raw)
In-Reply-To: <20261029-ethosu-fixes-v4-26-4aa25e22578e@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] accel: ethosu: missing size0/size1 scaling for 1D side in mixed-mode DMA
--

commit 186c2e0ed128e4d62938b05418f963aa19e82266
Author: Rob Herring (Arm) <robh@kernel.org>

accel: ethosu: Split U65 and U85 DMA length validation

This commit splits DMA length validation in the Ethos-U driver into separate
functions for U65 and U85 to account for their different stride and skip
models. It also updates the command stream validator to populate shared U65
strides and sign-extended U85 strides for source and destination DMA.

> diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c
> index 117046e5a61f8..04c0de8336cd1 100644
> --- a/drivers/accel/ethosu/ethosu_gem.c
> +++ b/drivers/accel/ethosu/ethosu_gem.c
> @@ -245,40 +245,97 @@ static bool dma_params_valid(struct ethosu_device *edev, struct cmd_state *st,
>  	return true;
>  }
>  
> -static u64 dma_length(struct ethosu_device *edev,
> -		      struct ethosu_validated_cmdstream_info *info,
> -		      struct cmd_state *st, struct dma_state *dma_st,
> -		      struct dma *dma, u16 region_cmd, u16 addr_cmd)
> +static u64 dma_length_finish(struct ethosu_validated_cmdstream_info *info,
> +			     const struct dma *dma, u64 len)
> +{
> +	if (dma->region >= 0) {
> +		u64 end;
> +
> +		if (check_add_overflow(len, dma->offset, &end))
> +			return U64_MAX;
> +		info->region_size[dma->region] =
> +			max(info->region_size[dma->region], end);
> +	}
> +
> +	return len;
> +}
> +
> +static u64 dma_length_u65(struct ethosu_validated_cmdstream_info *info,
> +			  struct dma_state *dma_st,
> +			  struct dma *dma)
>  {
>  	s8 mode = dma->mode;
>  	u64 len = dma->len;
> +	u64 stride;
>  
> -	if (!dma_params_valid(edev, st, dma_st, dma, region_cmd, addr_cmd))
> -		return U64_MAX;
> +	if (mode >= 1) {
> +		if (check_mul_overflow(len, (u64)dma_st->size0, &len) ||
> +		    check_mul_overflow((u64)dma->stride[0],
> +				       (u64)dma_st->size0 - 1, &stride) ||
> +		    check_add_overflow(len, stride, &len))
> +			return U64_MAX;
> +	}
> +	if (mode == 2) {
> +		if (check_mul_overflow(len, (u64)dma_st->size1, &len) ||
> +		    check_mul_overflow((u64)dma->stride[1],
> +				       (u64)dma_st->size1 - 1, &stride) ||
> +		    check_add_overflow(len, stride, &len))
> +			return U64_MAX;
> +	}
> +
> +	return dma_length_finish(info, dma, len);
> +}
> +
> +static u64 dma_length_u85(struct ethosu_validated_cmdstream_info *info,
> +			  struct dma_state *dma_st,
> +			  struct dma *dma)
> +{
> +	s8 mode = dma->mode;
> +	s64 min = 0;
> +	u64 max = dma->len;
> +	s64 stride;
>  
>  	if (mode >= 1) {
> -		if (dma->stride[0] < 0 && (u64)(-dma->stride[0]) > len)
> +		if (check_mul_overflow(dma->stride[0],
> +				       (s64)dma_st->size0 - 1, &stride))
>  			return U64_MAX;
> -		len += dma->stride[0];
> -		if (check_mul_overflow(len, (u64)dma_st->size0, &len))
> +		if (stride < 0) {
> +			if (check_add_overflow(min, stride, &min))
> +				return U64_MAX;
> +		} else if (check_add_overflow(max, (u64)stride, &max)) {
>  			return U64_MAX;
> +		}
>  	}
>  	if (mode == 2) {
> -		if (dma->stride[1] < 0 && (u64)(-dma->stride[1]) > len)
> +		if (check_mul_overflow(dma->stride[1],
> +				       (s64)dma_st->size1 - 1, &stride))
>  			return U64_MAX;
> -		len += dma->stride[1];
> -		if (check_mul_overflow(len, (u64)dma_st->size1, &len))
> +		if (stride < 0) {
> +			if (check_add_overflow(min, stride, &min))
> +				return U64_MAX;
> +		} else if (check_add_overflow(max, (u64)stride, &max)) {
>  			return U64_MAX;
> +		}
>  	}
> -	if (dma->region >= 0) {
> -		u64 end;
>  
> -		if (check_add_overflow(len, dma->offset, &end))
> -			return U64_MAX;
> -		info->region_size[dma->region] = max(info->region_size[dma->region], end);
> -	}
> +	if (min < 0 && -(u64)min > dma->offset)
> +		return U64_MAX;
>  
> -	return len;
> +	return dma_length_finish(info, dma, max);
> +}

[Severity: High]
When ethosu_gem_cmdstream_copy_and_validate() handles NPU_OP_DMA_START in
drivers/accel/ethosu/ethosu_gem.c, it validates the source and destination
endpoints independently via dma_length():

		case NPU_OP_DMA_START:
			srclen = dma_length(edev, info, &st, &st.dma, &st.dma.src,
					    NPU_SET_DMA0_SRC_REGION, NPU_SET_DMA0_SRC);
			dstlen = dma_length(edev, info, &st, &st.dma, &st.dma.dst,
					    NPU_SET_DMA0_DST_REGION, NPU_SET_DMA0_DST);

What happens when a DMA operation uses mixed modes between source and
destination, such as copying between a 1D contiguous buffer (mode == 0) and
a 2D or 3D strided buffer (mode == 1 or 2)?

On U65 in particular, NPU_SET_DMA0_SRC_STRIDE0 and NPU_SET_DMA0_SRC_STRIDE1
are shared between source and destination, so copying between a contiguous
buffer and a strided buffer requires one side to use mode == 0 while the
other uses mode == 1 or 2.

Both dma_length_u65() and dma_length_u85() only inspect dma->mode of the
endpoint currently being evaluated. When dma->mode == 0 while the other
endpoint has mode >= 1, the 1D endpoint's length is left as dma->len (a
single 1D transfer) rather than being scaled by dma_st->size0 (and
dma_st->size1 for 3D) to cover all transfers performed by the DMA engine.

Could this under-compute info->region_size[dma->region] in
dma_length_finish() for the 1D endpoint and allow out-of-bounds DMA reads or
writes past the end of the backing GEM buffer object?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261029-ethosu-fixes-v4-0-4aa25e22578e@kernel.org?part=26

  reply	other threads:[~2026-10-29 15:32 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 13:35 [PATCH v4 00/31] accel: ethosu: Another batch of fixes Rob Herring (Arm)
2026-10-29 13:35 ` [PATCH v4 01/31] accel: ethosu: Suspend after initialization Rob Herring (Arm)
2026-10-29 15:42   ` Frank Li
2026-10-29 13:35 ` [PATCH v4 02/31] accel: ethosu: Ensure suspended on removal Rob Herring (Arm)
2026-10-29 14:02   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 03/31] accel: ethosu: Fix probe error cleanup Rob Herring (Arm)
2026-10-29 15:52   ` Frank Li
2026-10-29 16:00     ` Rob Herring
2026-10-29 16:20       ` Frank Li
2026-10-29 13:35 ` [PATCH v4 04/31] accel: ethosu: Disable clocks on PM setup failure Rob Herring (Arm)
2026-10-29 14:01   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 05/31] accel: ethosu: Quiesce jobs before scheduler teardown Rob Herring (Arm)
2026-10-29 14:07   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 06/31] accel: ethosu: Fix runtime PM get error handling Rob Herring (Arm)
2026-10-29 16:03   ` Frank Li
2026-10-29 16:38   ` Frank Li
2026-10-29 13:35 ` [PATCH v4 07/31] accel: ethosu: Limit perfmon counters to UAPI Rob Herring (Arm)
2026-10-29 13:35 ` [PATCH v4 08/31] accel: ethosu: Serialize job completion Rob Herring (Arm)
2026-10-29 14:25   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 09/31] accel: ethosu: Guard operations after unplug Rob Herring (Arm)
2026-10-29 14:26   ` sashiko-bot
2026-10-29 19:01     ` Rob Herring
2026-10-29 13:35 ` [PATCH v4 10/31] accel: ethosu: Keep scheduler " Rob Herring (Arm)
2026-10-29 14:29   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 11/31] accel: ethosu: Clear SRAM before submission Rob Herring (Arm)
2026-10-29 14:36   ` sashiko-bot
2026-10-29 13:35 ` [PATCH v4 12/31] accel: ethosu: Validate timeout command offset Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 13/31] accel: ethosu: Prevent command stream export Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 14/31] accel: ethosu: Move DMA mode to src/dst struct Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 15/31] accel: ethosu: Track command stream register setup Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 16/31] accel: ethosu: Factor buffer bounds checks Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 17/31] accel: ethosu: Fix NHCWB16 bounds calculation Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 18/31] accel: ethosu: Validate secondary streams Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 19/31] accel: ethosu: Reject unsupported commands and params Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 20/31] accel: ethosu: Validate all feature map tiles Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 21/31] accel: ethosu: Account for feature map element size Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 22/31] accel: ethosu: Validate convolution parameter Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 23/31] accel: ethosu: Account for kernel dilation in IFM size Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 24/31] accel: ethosu: Validate accumulator input Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 25/31] accel: ethosu: Restrict dynamic IFM2 weights Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 26/31] accel: ethosu: Split U65 and U85 DMA length validation Rob Herring (Arm)
2026-10-29 15:32   ` sashiko-bot [this message]
2026-10-29 13:36 ` [PATCH v4 27/31] accel: ethosu: Validate OFM transpose Rob Herring (Arm)
2026-10-29 15:03   ` sashiko-bot
2026-10-29 13:36 ` [PATCH v4 28/31] accel: ethosu: Validate resize operations Rob Herring (Arm)
2026-10-29 15:14   ` sashiko-bot
2026-10-29 13:36 ` [PATCH v4 29/31] accel: ethosu: Ensure cmd stream is multiple of 4 bytes Rob Herring (Arm)
2026-10-29 13:36 ` [PATCH v4 30/31] accel: ethosu: Require active weight streams setup Rob Herring (Arm)
2026-10-29 15:18   ` sashiko-bot
2026-10-29 13:36 ` [PATCH v4 31/31] accel: ethosu: Support U85 IFM upscaling Rob Herring (Arm)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-189611@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox