From: netdev-bot+sashiko@kernel.org
To: kerneljasonxing@gmail.com
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
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 [thread overview]
Message-ID: <179586644541.3135.15029891543705593854@kernel.org> (raw)
In-Reply-To: <20261127105347.72997-3-kerneljasonxing@gmail.com>
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), ð_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
prev parent reply other threads:[~2026-11-28 11:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:53 [PATCH net v2 0/2] xsk: handle two header issues Jason Xing
2026-11-27 10:53 ` [PATCH net v2 1/2] net: reset the mac header in __dev_direct_xmit() Jason Xing
2026-11-27 14:38 ` Björn Töpel
2026-11-27 10:53 ` [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload Jason Xing
2026-11-27 16:40 ` Björn Töpel
2026-11-28 11:47 ` netdev-bot+sashiko [this message]
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=179586644541.3135.15029891543705593854@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=stable@vger.kernel.org \
--cc=willemb@google.com \
/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