🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7809

Re: [PATCH net 6/6] net: stmmac: fix XDP RX buffer DMA sync length

#7809
From: netdev-bot+sashiko
Date: Tue, 27 Oct 2026 09:10
110 lines
12480 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] In stmmac_rx()
  (drivers/net/ethernet/stmicro/stmmac/stmmac_main.c), the length passed…

--

net: stmmac: fix XDP RX buffer DMA sync length

This commit changes the XDP path in stmmac_rx() so that pre_len and
sync_len are measured from data_hard_start, and buf->page_offset is no
longer subtracted. That matches the page_pool DMA window, which now
starts at offset 0. The goal is for page_pool_put_page() on the
consumed XDP path to sync the whole region the CPU touched.

> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 32b2c5834c340..c51358c51fae7 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -5980,8 +5980,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
>  			xdp_prepare_buff(&ctx.xdp, page_address(buf->page),
>  					 buf->page_offset, buf1_len, true);
>  
> -			pre_len = ctx.xdp.data_end - ctx.xdp.data_hard_start -
> -				  buf->page_offset;
> +			pre_len = ctx.xdp.data_end - ctx.xdp.data_hard_start;
>  
>  			ctx.priv = priv;
>  			ctx.desc = p;
> @@ -5991,8 +5990,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
>  			/* Due xdp_adjust_tail: DMA sync for_device
>  			 * cover max len CPU touch
>  			 */
> -			sync_len = ctx.xdp.data_end - ctx.xdp.data_hard_start -
> -				   buf->page_offset;
> +			sync_len = ctx.xdp.data_end - ctx.xdp.data_hard_start;
>  			sync_len = max(sync_len, pre_len);

[Severity: High]

Does this cover the furthest point the CPU touched if the XDP program
grows the tail and then shrinks it again before it returns?

The comment says the sync covers the "max len CPU touch". However,
max(sync_len, pre_len) only looks at data_end before the program runs
and after it returns. bpf_xdp_adjust_tail() writes to the grown area
when the tail grows:

net/core/filter.c:bpf_xdp_adjust_tail() {
    ...
	/* Clear memory area on grow, can contain uninit kernel memory */
	if (offset > 0)
		memset(xdp->data_end, 0, offset);

	xdp->data_end = data_end;
    ...
}

A later negative adjust only moves data_end back.

Take a 64 byte frame at page_offset 256 and a program that does
adjust_tail(+512), then adjust_tail(-512), then returns XDP_DROP. Both
pre_len and sync_len end up at the original end, around 316. The memset
dirtied the cache lines in [316, 828), but this call does not clean
them:

    page_pool_put_page(rx_q->page_pool,
                       virt_to_head_page(ctx.xdp.data),
                       sync_len, true);

__page_pool_dma_sync_for_device() caps the length at p.max_len but
never extends it. The direct recycle cache does no further sync.
stmmac_rx_refill() gives the buffer back to the device after dma_wmb(),
with no more cache maintenance.

max_len is dma_buf_sz + stmmac_rx_offset(priv), which is 1792 with
dma_buf_sz = 1536. So that range lies inside the window the device DMAs
into.

On a non-coherent platform, could one of those dirty lines be evicted
after the device has written the next frame into the recycled page, and
corrupt that frame? It looks like the same failure the commit message
describes:

    Dirty cache lines in the tail of the frame can be written back
    after the device has DMA'd a new frame into that page.

The commit message names "grow the tail" as a trigger and says "the
whole CPU-touched window is synced". The max(pre, post) approach was
already there before this patch.

Would it be better for the STMMAC_XDP_CONSUMED path to sync the full
pool window instead of checking only the two endpoints? Passing
p.max_len, or using page_pool_recycle_direct(), would do that.

>  
>  			/* For Not XDP_PASS verdict */

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261023-stmmac-xdp-fixes-v1-0-efb37e19f5bd%40oss.qualcomm.com
Technical Details
Message-ID: <179309225887.3134.17502896212947474889@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352314-linux-kernel-netdev=dewy.ru
References: <20261023-stmmac-xdp-fixes-v1-6-efb37e19f5bd@oss.qualcomm.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352314-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 6/6] net: stmmac: fix XDP RX buffer DMA sync length
Date: Tue, 27 Oct 2026 09:10:58 +0000
Organization: Usenet Network
Message-ID: <179309225887.3134.17502896212947474889@kernel.org>
References: <20261023-stmmac-xdp-fixes-v1-6-efb37e19f5bd@oss.qualcomm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1500013"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:66DFUyMGSQFPeo+rzr8yKCdcMK4= sha256:RdSI3WL+ZkWFleRECfJm+J0ac7ifqQY9nXaBH53U5Dg=
	sha1:4U5WjB93gJ1mYLlQ+xF52Nmgal0= sha256:LMU17TzibdUyueY9mcPIDbM+iukrm+1IHPip8rTkDPo=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id A0A00125BE4; Tue, 27 Oct 2026 12:12:30 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.838
X-Spam-Status: No, score=-3.838 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.339, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ywIBLeFlnu_D;
	Tue, 27 Oct 2026 12:12:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-352314-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 9D4F9125BE0; Tue, 27 Oct 2026 12:11:57 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id C3F7729DAE; Tue, 27 Oct 2026 09:11:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793092261;
	b=HogX63wa2t+3L2C2gVcskd/HQIK2N6X+ea8XXSC/V+MIVK2aUXHmirCefBj3/GNeR/qR
	 kg5XqZQ1JAlsn32BtFx2molhB+Tdksqy8oHMHZjrQigpa1/YYQWmi5B5Kxj0IB9+5rBeN
	 olzYrPmBoChjb5V/v2l7ZKv1X+5XdlLxS2PyaSJk07hsvxJNd0eGfjRsM+ACpN+CX7Vos
	 XgKxs0FpGs4as7j9+T0jcTAeAhVTS90RskyAg7JPfQsGiXjyDgX0AD74jVS0785j5P7MC
	 rI+i135OaGutKjnT/PPhN33xGvgHexxAPQ0vcGRpjQoxnJOdXLqCQlNmRTbwnLMIMFA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793092261;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=NMwzOBgLak0sHODIyBF4CYGTZyqMPZeg2NfCnH9H41E=;
	b=rB2vYZgdCm0Eh4WNhBRehD8ofmbyvIktxyQ02YESb7dFNl4/M02S5arWPC1SZ5C7W0Bo
	 gf5d2ce1RumCbLo5u1Vumer9MBHiHOVrY7nt6M+IdCIg3SZvDr87KgWdKgvZJhaRLmlX4
	 RH3ovhHWrXT7wrfmQrvrFwQdWpEdjfYJYmozrwwyQOGWebgZ37gyP239MJlElGoKTR49/
	 P2ZWwlkhFuL0zioJD4s6kIVNfByFGKsrrs3oQ61u5vZmln0InGmPXKjs5HItJC/XQZsKr
	 8xhUOyesXV0l2Sj/TFqSFog0HK/BTcTQWoTdsUXhktGQ+GsS5Ecx94BGXNvKIATaOpQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ivj4YrMJ;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 87E4E606A320;
	Tue, 27 Oct 2026 09:11:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ivj4YrMJ
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793092260;
	b=hA+knpKWFM0zmadA54P0X5d19nO1qvddtMuGLhwKrBezacphoZz+wGq31isWLCPeDOdL
	 ELGzZk96wE7vSO4sUo27/4zdBgUtNVlAnGvt3zvvxtfazvQ74N15P6E602Qx17hFdTZ6X
	 IUiMHwId6dfQzkaqewiS+TNk/T9Tg+IaCe6Quh19tDkCQ5tpDYbro1eKmTp3u8NctkW5/
	 4fYiV+Y3Wh4OF6ZroytI+ynyeBvff0gyMIjWHaM/HLoWNt0PSBnxK39Ov17z1dq8JzwXe
	 G0OaphMGmG7I/N85jhoNgwN8hNp7aOe712obOH23DAaIRZSVzEJz4ClidXp+RK0mvSg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793092260;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=NMwzOBgLak0sHODIyBF4CYGTZyqMPZeg2NfCnH9H41E=;
	b=W8Iuf7p2D41bSXv0AZfLqAf91yqyNhlbc0qlbvibnXWeTw+NciMsrBlGzaH4SRgjEgqz
	 vIPw7ERw6Wa7XWAHQzsTaeGXsa4cTmSW2ErsnPd9iJKo7R3HU8MH1qKX+ekfLMpvDncrU
	 cKtYiqeUmJEzLrYrHyJN0oLh/AMZRKttPx3jP2HYsF92MrqfbCx7KP42uTKYU0M8B+VKZ
	 rTRAgd2V+IlIKJsRzP+5h6oQVX1ZvAHVazAxeODn7aRfo1sqeqZuqAlfdaOo1zft7PUTR
	 RWddxEgrSUwZGl9569F+ERYX/DzbDTJwJr5vQK4AnPRtvu+KUBb1IEO+SU911mHJqkw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ivj4YrMJ;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65E90606A31D;
	Tue, 27 Oct 2026 09:11:00 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 473211F01825;
	Tue, 27 Oct 2026 09:10:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793092260;
	bh=NMwzOBgLak0sHODIyBF4CYGTZyqMPZeg2NfCnH9H41E=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Ivj4YrMJUMYBYm++ZtfNi8DsvatmvdbpZhlDJ/0FzEzKVTh4qKyW2ctQlHCPBDo2x
	 e/6nOVVWxx3NOxYdLBnAA4ny7IwV7xP/svJzlQ+2x9qLK07sHBK0FhDzea706Y6iBo
	 QeBjfnKuwCFiuC5og/0i+ybPPaBgg98We38cW14aizhB3MYTGdOM7t2eMvz1vySB/h
	 wrgJJdQWYInNndHboKVqsOPQIW8rYFtLKEUjnrFfElGuAfz6AmJSfkmDrfpSeZk2Dz
	 CToDXnRpczImzHyOIZ+UhAOF37BUdxppn/3K05DJuYbGZ0ZRODkJnc8qlgBbjPSfuc
	 Z/n+7Dn/jRrFg==
X-Cc: maxime.chevallier@bootlin.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, ast@kernel.org,
 daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
 sdf@fomichev.me, Jose.Abreu@synopsys.com, boon.leong.ong@intel.com,
 o.rempel@pengutronix.de, netdev@vger.kernel.org,
 linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org
X-In-Reply-To: <20261023-stmmac-xdp-fixes-v1-6-efb37e19f5bd@oss.qualcomm.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list