🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23853

Re: [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload

#23853
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 11:47
293 lines
18067 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 3 · 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] This patch adds `skb_checksum_help()` calls in
  `xsk_skb_sw_csum()` (net/xdp/xsk.c) that run even when…
- [Medium] When `pool->tx_sw_csum` is false, `xsk_skb_sw_csum()` now
  checksums on the CPU every Ethernet CHECKSUM_PARTIAL frame it cannot…
- [Medium] `xsk_skb_sw_csum()` now sets skb->protocol, network_header and
  transport_header from a frame fully controlled by user space.
- [Medium] `xsk_skb_sw_csum()` now passes AF_XDP copy-mode
  CHECKSUM_PARTIAL frames to protocol-aware or unit-constrained hardware…

--

xsk: fill in header offsets for TX checksum offload

This patch makes xsk_skb_sw_csum() parse the Ethernet and VLAN headers of
CHECKSUM_PARTIAL AF_XDP copy-mode frames. It then sets skb->protocol and
the network and transport headers so the checksum request can be offloaded
to hardware. Frames whose L2 header can't be parsed, that aren't IPv4/IPv6,
or whose csum_start leaves no room for an L3 header fall back to
skb_checksum_help().

> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 18cbd50047d80..3827d8e4b642a 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c

[ ... ]

> @@ -1028,9 +1032,48 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer,
>  
>  static int xsk_skb_sw_csum(struct sk_buff *skb, struct xsk_buff_pool *pool)
>  {
> -	if (unlikely(pool->tx_sw_csum &&
> -		     skb->ip_summed == CHECKSUM_PARTIAL))
> +	struct ethhdr eth_buf, *eth;
> +	int nhoff = ETH_HLEN;
> +	unsigned int l3_min;
> +	__be16 proto;
> +
> +	if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL))
> +		return 0;
> +
> +	if (unlikely(pool->tx_sw_csum))
> +		return skb_checksum_help(skb);
> +
> +	if (unlikely(skb->dev->type != ARPHRD_ETHER))
> +		return 0;
> +
> +	eth = skb_header_pointer(skb, 0, sizeof(*eth), &eth_buf);
> +	if (unlikely(!eth))
> +		return skb_checksum_help(skb);

[Severity: High]
Can this fallback, and the other new skb_checksum_help() fallbacks below,
break copy-mode transmit on IFF_TX_SKB_NO_LINEAR devices such as
virtio_net?

On those devices xsk_build_skb() goes through xsk_build_skb_zerocopy(),
which only reserves headroom in the linear area:

net/xdp/xsk.c:xsk_build_skb_zerocopy() {
    ...
		skb = sock_alloc_send_skb(&xs->sk, hr, 1, &err);
		...
		skb_reserve(skb, hr);
    ...
}

That leaves skb_headlen() at 0. All of the payload sits in page frags
attached with skb_fill_page_desc(), which doesn't set SKBFL_SHARED_FRAG.
So skb_checksum_help() doesn't linearize, and it hits this check:

net/core/dev.c:skb_checksum_help() {
    ...
	if (unlikely(offset >= skb_headlen(skb))) {
		DO_ONCE_LITE(skb_dump, KERN_ERR, skb, false);
		WARN_ONCE(true, "offset (%d) >= skb_headlen() (%u)\n",
    ...
}

It then returns -EINVAL, so __xsk_generic_xmit() drops the frame and
sendmsg() fails:

		err = xsk_skb_sw_csum(skb, xs->pool);
		if (unlikely(err)) {
			xsk_drop_skb(skb);
			goto out;
		}

User space can reach every one of these fallbacks, because
xsk_skb_metadata() only checks csum_start + csum_offset + 2 <= desc->len.
Any of these frames will do:

- a frame shorter than ETH_HLEN
- an unparsable VLAN stack
- a non-IPv4/IPv6 ethertype
- a csum_start below nhoff + 20 (IPv4) or nhoff + 40 (IPv6)

Before this patch, these frames returned 0 here when tx_sw_csum was off.
xp_assign_dev() also refuses tx_sw_csum on these devices, precisely so
that skb_checksum_help() is never reached for them:

	if (pool->tx_sw_csum && (netdev->priv_flags & IFF_TX_SKB_NO_LINEAR))
		return -EOPNOTSUPP;

virtio_net advertises NETIF_F_HW_CSUM, so the device computed the
checksum. With this patch the frame is dropped instead, and the user can
trigger a WARN_ONCE plus skb_dump. On panic_on_warn systems that is a
panic.

The commit message says these frames "keep being checksummed in software
exactly as before". Would returning 0 in the fallback cases work better?
That would leave the decision to validate_xmit_skb() as it was before.

> +
> +	proto = eth->h_proto;
> +	if (eth_type_vlan(proto)) {
> +		proto = __vlan_get_protocol(skb, proto, &nhoff);
> +		if (unlikely(!proto))
> +			return skb_checksum_help(skb);
> +	}
> +
> +	switch (proto) {
> +	case htons(ETH_P_IP):
> +		l3_min = sizeof(struct iphdr);
> +		break;
> +	case htons(ETH_P_IPV6):
> +		l3_min = sizeof(struct ipv6hdr);
> +		break;
> +	default:
>  		return skb_checksum_help(skb);

[Severity: Medium]
Leaving the non-linear case aside, does this take checksum offload away
from frames that were offloaded before this patch?

Even with skb->protocol == 0, a NETIF_F_HW_CSUM device still offloaded
the frame:

include/linux/netdevice.h:can_checksum_protocol() {
    ...
	if (features & NETIF_F_HW_CSUM) {
		/* Can checksum everything */
		return true;
	}
    ...
}

skb_csum_hwoffload_help() also returns 0 for NETIF_F_HW_CSUM. On
virtio_net, veth and other HW_CSUM devices, non-IP or unparsable frames
are now checksummed on the CPU instead.

The policy also looks inconsistent. Non-ARPHRD_ETHER devices return 0
and keep offload, but Ethernet devices with an unknown L3 type are forced
into software.

Documentation/networking/xsk-tx-metadata.rst says XDP_TXMD_FLAGS_CHECKSUM
asks the device to compute the checksum. It describes CPU checksumming as
the XDP_UMEM_TX_SW_CSUM option.

For HW_CSUM devices the commit message doesn't match this behaviour
either:

  However skb->protocol stays 0, the offload never actually reaches
  the hardware and checksum ends up being computed in software every time

and:

  ... cannot be described to the hardware, so it keeps being checksummed
  in software exactly as before.

Since this is tagged for stable, could the commit message describe the
behaviour change accurately? Alternatively, could these fallbacks return
0 so the core path keeps making the decision?

> +	}
> +
> +	if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
> +		return skb_checksum_help(skb);

[Severity: Medium]
Is checking only the minimal L3 header size enough before handing the
frame to protocol-aware driver checksum paths?

xsk_skb_metadata() only guarantees csum_start + csum_offset + 2 <=
desc->len. Nothing guarantees that a full L4 header exists at
csum_start.

Before this patch, harmonize_features() or ice_features_check() kept
these frames away from the driver offload path. Now take ice E810, which
has IP_CSUM|IPV6_CSUM but no HW_CSUM. ice_tx_csum() takes the L4 protocol
from the user-controlled ip.v4->protocol, and for TCP it reads:

drivers/net/ethernet/intel/ice/ice_txrx.c:ice_tx_csum() {
    ...
	case IPPROTO_TCP:
		/* enable checksum offloads */
		cmd |= ICE_TX_DESC_CMD_L4T_EOFT_TCP;
		l4_len = l4.tcp->doff;
    ...
}

For example, take eth(14) + IPv4 with protocol=TCP, csum_start=34,
csum_offset=6 and desc->len=42:

- skb_csum_hwoffload_help() accepts it, since csum_offset 6 equals
  offsetof(struct udphdr, check)
- ice_features_check() accepts MACLEN 14 and IPLEN 20

doff is then read at transport_header + 12, up to 5 bytes past
skb->tail. The read stays inside the skb head allocation, but that memory
is uninitialized and KMSAN would flag it.

The value read is programmed into the descriptor's L4LEN field. Whether
a bogus L4LEN can trigger NIC malicious driver detection or TX hangs
hasn't been verified.

AF_PACKET with vnet_hdr has a similar weakness, but this patch newly
exposes the AF_XDP path to it.

Should this require a full TCP/UDP header past csum_start, consistent
with csum_offset, before setting the transport header and skipping the
software checksum?

> +
> +	skb->protocol = eth->h_proto;
> +	skb_set_network_header(skb, nhoff);
> +	skb_set_transport_header(skb, skb_checksum_start_offset(skb));

[Severity: Medium]
Can the hardware end up writing the checksum somewhere other than the
requested csum_start/csum_offset?

Only the ethertype and csum_start >= nhoff + l3_min are checked here.
Drivers, though, program these offsets in coarser units or take the L4
type from the packet itself. Three cases on ice show this.

First, the legacy path (E810) programs IPLEN in dwords:

	l3_len = l4.hdr - ip.hdr;
	offset |= (l3_len / 4) << ICE_TX_DESC_LEN_IPLEN_S;

ice_features_check() only rejects odd or oversized lengths:

	len = skb_network_header_len(skb);
	if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
		goto out_rm_features;

An L3 length of 22 therefore becomes 5 dwords, and the L4 checksum starts
2 bytes before csum_start.

Second, the L4 type comes from ip.v4->protocol or the IPv6 nexthdr, not
from csum_offset. skb_csum_hwoffload_help() only requires csum_offset to
be 16 or 6.

With protocol=TCP and csum_offset=6, the device writes the TCP checksum
at L4+16 rather than L4+6. With protocol=SCTP (csum_not_inet is 0), it
writes a CRC32c at L4+8 rather than a 16-bit Internet checksum.

Third, the GCS path (E830, HW_CSUM) uses:

		u16 csum_offset = skb->csum_offset / 2;

That rounds an odd csum_offset down, so the result lands one byte early.

Before this patch, skb_checksum_help() computed all of these at exactly
csum_start/csum_offset. With this patch, other bytes of the transmitted
frame get overwritten. So the commit message's "exactly as before" claim
doesn't hold for these frames either.

Would it make sense to add these checks, or else leave the decision to
the core path?

- IPv4 ihl * 4 (or the IPv6 header plus extension headers) equals
  csum_start - nhoff
- the L4 protocol is TCP or UDP with a matching csum_offset (16 or 6)
- the offsets are even

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127105347.72997-1-kerneljasonxing%40gmail.com
Technical Details
Message-ID: <179586644541.3135.15029891543705593854@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373104-linux-kernel-netdev=dewy.ru
References: <20261127105347.72997-3-kerneljasonxing@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373104-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload
Date: Sat, 28 Nov 2026 11:47:25 +0000
Organization: Usenet Network
Message-ID: <179586644541.3135.15029891543705593854@kernel.org>
References: <20261127105347.72997-3-kerneljasonxing@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="940437"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:uYilginqHoDR86XpDdIs/xjs4oU= sha256:/CW0pkIK25niX8EQ9u8r9ZAIm9amHjHVIIh36o0z+WQ=
	sha1:o1Ecj2pmtSh7oxbpZJiFHnmXSyw= sha256:rPndcqu5qah4LBRjTevISgNlVJWFsqIYy71JsgnbE00=
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 127BE125F76; Sat, 28 Nov 2026 14:47:52 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 1j3_d7riUjH2;
	Sat, 28 Nov 2026 14:47:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373104-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 92A96125F72; Sat, 28 Nov 2026 14:47:34 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id CF675297A9; Sat, 28 Nov 2026 11:47:28 +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=1795866448;
	b=o5wGJcWcFT8Xmn6Qw1PO4J6IA/ClfCWhpYbTcejHP33agoIu4lYQEH/KRt3uXtirWlyp
	 vYQwAu9RQ04DGyYcSh6kBFOqvXDkwvGrU5O/wAEwXTaBh8iIEBq4jHeNJsDZpo8swHIqY
	 KPFwR8PWE0yl29IhF7nOKY9COjV65FsrpRRORDW6LaFc+3ZQ5fl4p5Lp9l/6kjyl/BJx9
	 ao0D++P6/X2DSR7LEYLHRBXB8KDXugfXkVGXQH2/QwxJGAadaRUw9ReRDmrdGmPgfBOM5
	 el1vM3tJJv5EpqBr21rI6yKKcz3BnOrCrXWB5qg2Skq3LK5+44cWOUdovakw8Eai49A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795866448;
	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=6JF9EI2l94MzBVRIwSaYP0GqXCFWuq3VNcdzQFYVjwk=;
	b=Ksm/LTQN7gBrB6SgvlrHopFphpfsO61bqfnBBWJtYOObmxUuergHywrC2JWxl3v2kAss
	 6BiwTLjErROfbAvY8VLyJJFKUdO7P3BdYhQCOBkknFPgLypJkQ6+Sm78QlUon9s+o2tdU
	 Anq/kfuIdzBuiPq7GFz7ph4jFup6YIaKrwZ84fmJ81JkXkbPew4C5c7gXXUKFZSTLsgrJ
	 SaFKCFV+74rEQ8h7ebCUOm+8Sq592yqfdwIK73rVHqG/B5iiHU0gPl57Zia559o/qUNY5
	 fMxOuIZ9kt4TbDo7FRBEFR7cN7wRAyCekIKFSmZYTQrf8uyMff3ivjM8D2a3Rm0kUiA==
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=gyLG54eB;
	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 46E8F606A32F;
	Sat, 28 Nov 2026 11:47:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gyLG54eB
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=1795866447;
	b=b4d6tDscoEIXEl7TYS0fUoNsk3nQ/GZ1ge/4lk69LaxEfhR7njOFYBtS61rdMhRHIJLM
	 ocxVD5RBDK7ZDV3IBRBCWTT7j1wnXiccEI0lZdwaoJAJWWwpziGifzJSfqcdUc5wwhQxO
	 E+9L6lVcU7sLr2h0nXU0heF1S15P6qPV5vHfwiLOoWUj378QYFWrCIpt9lG7f2xCWuw63
	 p2St9I3IKWRmbLjGBmPvY+wl2tDdlU0T5ZFQyKl4Gry2WBgndKoY+x2G+W2xc2KNNPE79
	 bNKdPUT/moxGHw6zYAyuzRim7J+L88dztofDsk9X40ToEnoPKhCRNa3FVbRXJT2pHYQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795866447;
	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=6JF9EI2l94MzBVRIwSaYP0GqXCFWuq3VNcdzQFYVjwk=;
	b=RyFeh0nIyKNipPIKU/2wa52QoHd9UGieQ2LoEyUTxIbZ5EsKOIXRYAMsMtWgciQ11QxW
	 aCOYaJU8QKzw7uPsgNwEBoOCPZhaCaATWMiSd/GjS5hGxbLnToz8Kj8e7fzlTgVUCPEKK
	 Zg54sTQK9rW1czBPyzaSMAfiT6/a8HDg8v3Nx9+PQqsE4Iuqfn7BG4R7HFIs7923HMeGg
	 rw5grwt+62vvt9IKUw6DXUkZ26hYBuAw3dnvbQMSJJaBtTn3R3lRH3tGRtWgVy2VLEKpe
	 HrEG3Ph93fqMdXqffP0sozk6lo17qG/uGJltXesG6cwGT5TcMZThueAiQmIgu4LfteA==
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=gyLG54eB;
	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 66E20606A31C;
	Sat, 28 Nov 2026 11:47:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC2911F00898;
	Sat, 28 Nov 2026 11:47:25 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795866446;
	bh=6JF9EI2l94MzBVRIwSaYP0GqXCFWuq3VNcdzQFYVjwk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=gyLG54eBFFztDDBy7wmc8dT0ca5//QrPTMqntJ/FMo/M8LrR5/QQtIsbDZohHqshH
	 /z4tjAq/dczbKRv65oGb8EY7mTmU8VGNicvaIW9Tn9unpUSyxC9mBKLc+7WRtaLXbN
	 10RiuADeszXmqnBH9CCNh6Lm02raG763QqiWMRpPAUTMYPPdTsR5wbVMtXe3bjn5FN
	 qcPC1+odjl3uiJLkmvCki+AeNqmqsqGt2TQK8UnnQ3J29FMfGPw3Cd2hgxx44plabG
	 4XryQg6+owup3mP2r96G+bRUrZMTO4TnbaPAy7psFfyVrvsC78TN9J0G0vpQan3fOI
	 7ipjYN19X1t9A==
X-Cc: willemb@google.com, magnus.karlsson@intel.com,
 maciej.fijalkowski@intel.com, sdf@fomichev.me, bjorn@kernel.org,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 horms@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org,
 stable@vger.kernel.org
X-In-Reply-To: <20261127105347.72997-3-kerneljasonxing@gmail.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