xsk: fill in header offsets for TX checksum offload
Subsystems (5)
PATCH 1/1 xsk: fill in header offsets for TX checksum offload
An XDP_TXMD_FLAGS_CHECKSUM request is turned into an skb carrying CHECKSUM_PARTIAL by xsk_skb_metadata() where csum_start/csum_offset/ ip_summed are set, which will be handled in the csum offload like ice_tx_csum(). Drivers like ICE do read network_header/transport_header fields which actually point to the wrong place, leading to wrong action.
The frame layout comes from user space, and request.csum_start is already the offset of the L4 header from the start of the frame, so the transport header is known exactly. Only the L2 length has to be found, by parsing the Ethernet header and, when present, the VLAN tag stack. skb_header_pointer() is used for that, so it works for frames whose data is not in the linear part of the skb. Also, initialize skb->protocol because of some drivers (e.g. mana_start_xmit()) using it.
A frame whose csum_start points into the L2 header disagrees with its own metadata, so it is rejected and dropped instead of being handed to the driver with a layout it cannot use.
Only Ethernet framing is parsed while other device types keep existing behaviour.
---
V1
Previous discussions: https://lore.kernel.org/all/arKm5gCaERk6MaGA@boxer/
The patch is based on Maciej suggestion: 1) do not rely on mac header that probe in AF_PACKET uses, 2) use skb_header_pointer and walk vlan tags to inspect the accurate location of each field that existing drivers possibly use.
--- net/xdp/xsk.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
net/xdp/xsk.c +31 -2
@@ -11,6 +11,8 @@#define pr_fmt (fmt) "AF_XDP: %s: " fmt, __func__ +#include <linux/if_arp.h> +#include <linux/if_vlan.h> #include <linux/if_xdp.h> #include <linux/init.h> #include <linux/sched/mm.h>
@@ -1027,10 +1029,37 @@ 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 ; +__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 -EINVAL ; + + proto = eth->h_proto; +if (eth_type_vlan (proto)) { + proto =__vlan_get_protocol (skb, proto, &nhoff); +if (unlikely (!proto)) +return -EINVAL ; + } + +if (unlikely (skb_checksum_start_offset (skb) < nhoff)) +return -EINVAL ; + + skb->protocol = proto; +skb_set_network_header (skb, nhoff); +skb_set_transport_header (skb,skb_checksum_start_offset (skb)); +return 0 ; }
Signature · 1 line
2.43.7
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] xsk: missing skb_reset_mac_header() in xsk_skb_sw_csum() - [Medium] xsk: xsk_skb_sw_csum()…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] xsk: missing skb_reset_mac_header() in xsk_skb_sw_csum()
- [Medium] xsk: xsk_skb_sw_csum() overwrites skb->protocol on VLAN frames
- [Medium] xsk: insufficient header and protocol validation in xsk_skb_sw_csum()
--
commit 751e231dd95b04f38f8084599c2e73e9184ffdfe
Author: Jason Xing <[email protected]>
xsk: fill in header offsets for TX checksum offload
This commit parses the Ethernet header and VLAN tag stack in xsk_skb_sw_csum() to populate skb->protocol, the network header offset, and the transport header offset for CHECKSUM_PARTIAL frames.
Quoted 4 lines
net/xdp/xsk.c +0
-0
[ ... ]
Quoted 19 lines
net/xdp/xsk.c +11
-2@@ -1026,10 +1028,37 @@ 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 ; +__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 ; +
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1053
Quoted 10 lines
net/xdp/xsk.c +10
-0+ eth =skb_header_pointer (skb,0 ,sizeof (*eth), ð_buf); +if (unlikely (!eth)) +return -EINVAL ; + + proto = eth->h_proto; +if (eth_type_vlan (proto)) { + proto =__vlan_get_protocol (skb, proto, &nhoff); +if (unlikely (!proto)) +return -EINVAL ; + }
[Severity: Medium]
Should skb->protocol keep the outer eth->h_proto on VLAN frames instead of being overwritten with the inner L3 protocol returned by __vlan_get_protocol()?
AF_XDP TX frames carry VLAN tags in-band in skb->data with skb_vlan_tag_present(skb) false. When skb->protocol is set to the inner EtherType, skb_vlan_tagged() and skb_vlan_tagged_multi() return false in validate_xmit_skb(), which skips the dev->vlan_features intersection in __netif_skb_features(), bypasses multi-VLAN checksum offload masking in vlan_features_check(), and breaks driver TX checks such as ice_tx_prepare_vlan_flags() that test eth_type_vlan(skb->protocol) for in-band VLAN tags.
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1057
Quoted 3 lines
net/xdp/xsk.c +3
-0+ +if (unlikely (skb_checksum_start_offset (skb) < nhoff)) +return -EINVAL ;
[Severity: Medium]
Should this check reject skb_checksum_start_offset(skb) <= nhoff and verify that the L3 and L4 headers fit within the skb?
Allowing skb_checksum_start_offset(skb) == nhoff sets the network and transport headers to the same offset (skb_network_header_len(skb) == 0), which passes ice_features_check() and causes ice_tx_csum() to read the same offset as both the IP and L4 headers. In addition, because xsk_skb_metadata() only bounds-checks csum_start + csum_offset + 2 against desc->len, a short frame with valid csum_start and csum_offset allows drivers such as ice_tx_csum() and mana_checksum_info() to dereference IP and TCP header fields past skb->tail. Finally, on IFF_TX_SKB_NO_LINEAR devices such as virtio_net where xsk_build_skb_zerocopy() leaves skb_headlen(skb) == 0, setting skb->protocol to an EtherType rejected by can_checksum_protocol() (such as ETH_P_FCOE) causes harmonize_features() to strip NETIF_F_CSUM_MASK without linearizing the skb, triggering the offset >= skb_headlen(skb) WARN_ONCE in skb_checksum_help().
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1061
Quoted 4 lines
net/xdp/xsk.c +4
-0+ + skb->protocol = proto; +skb_set_network_header (skb, nhoff); +skb_set_transport_header (skb,skb_checksum_start_offset (skb));
[Severity: High]
Does xsk_skb_sw_csum() also need to call skb_reset_mac_header(skb)?
Because __xsk_generic_xmit() transmits directly via __dev_direct_xmit(), nothing resets skb->mac_header from its initial ~0U (0xffff) sentinel. When a CHECKSUM_PARTIAL frame reaches drivers that compute offsets or read headers relative to skb->mac_header, such as ice_tx_csum() (which computes (skb->csum_start - skb->mac_header) / 2 for NETIF_F_HW_CSUM), fbnic_tx_offloads() (via skb_mac_header_len()), or ice_xmit_frame_ring() (which dereferences skb_mac_header(skb)), the driver programs a bogus checksum start offset or reads out of bounds at skb->head + 0xffff.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 3
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] xsk_skb_sw_csum() sets protocol, network_header and transport_header but leaves skb->mac_header at the ~0 (0xffff)…
- [Medium] The commit message says ICE (ice_tx_csum) and mana (skb->protocol) misbehave on AF_XDP copy-mode checksum requests.
- [Medium] For frames with in-band 802.1Q/802.1AD tags, xsk_skb_sw_csum() sets skb->protocol to the innermost ethertype returned by…
- [Low] xsk_skb_sw_csum() adds a rejection that the commit message does not mention.
- [Low] The new 'csum_start must not point into the L2 header' rule applies in only one configuration: AF_XDP copy mode, without…
- [Low] Before setting skb->protocol to a user-chosen ETH_P_IP/ETH_P_IPV6 and network_header to nhoff, xsk_skb_sw_csum() only checks…
--
xsk: fill in header offsets for TX checksum offload
This patch makes xsk_skb_sw_csum() parse the Ethernet header and any in-band VLAN tags of AF_XDP copy-mode frames that request TX checksum offload. It then sets skb->protocol, the network header and the transport header. Frames whose csum_start points into the L2 header are rejected with -EINVAL.
Quoted 2 lines
Drivers like ICE do read network_header/transport_header fields which actually point to the wrong place, leading to wrong action.
[ ... ]
Quoted 2 lines
Also, initialize
skb->protocol
because of some drivers (e.g.mana_start_xmit()) using it.
[Severity: Medium]
Could this description be made more accurate? Before this patch, could ICE or mana ever get a CHECKSUM_PARTIAL skb from this path?
xsk never set skb->protocol, so it stayed 0. On the __dev_direct_xmit()->validate_xmit_skb()->netif_skb_features() path, harmonize_features() then cleared the checksum features on any device without NETIF_F_HW_CSUM:
net/core/dev.c:harmonize_features() {
...
if (skb->ip_summed != CHECKSUM_NONE &&
!can_checksum_protocol(features, type)) {
features &= ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
}
...
}skb_csum_hwoffload_help() then fell back to skb_checksum_help(), which computed the checksum correctly in software.
By default ICE only advertises NETIF_F_IP_CSUM, NETIF_F_IPV6_CSUM and NETIF_F_SCTP_CRC (see ice_set_netdev_features()). On E830 with HW_CSUM enabled, ice_features_check() still removed the checksum features, because skb_network_offset() was negative with network_header at 0.
mana only advertises NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM in mana_probe_port(), so it also always got a software checksum.
So for these devices, doesn't the patch actually turn on hardware TX checksum offload in AF_XDP copy mode, where the checksum used to be done in software? The commit message doesn't say this, and the patch is tagged for stable.
About the transport header: validate_xmit_skb() already sets it from csum_start before ndo_start_xmit() runs:
net/core/dev.c:validate_xmit_skb() {
...
else
skb_set_transport_header(skb,
skb_checksum_start_offset(skb));
if (skb_csum_hwoffload_help(skb, features))
...
}So by driver xmit time, only network_header and protocol were wrong. The new transport header setter still helps ndo_features_check callbacks such as ice_features_check(), because they run before this point.
Quoted 4 lines
net/xdp/xsk.c +0
-0
[ ... ]
Quoted 18 lines
net/xdp/xsk.c +10
-2@@ -1026,10 +1028,37 @@ 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 ; +__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 ;
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1052
Quoted 10 lines
net/xdp/xsk.c +10
-0+ + eth =skb_header_pointer (skb,0 ,sizeof (*eth), ð_buf); +if (unlikely (!eth)) +return -EINVAL ; + + proto = eth->h_proto; +if (eth_type_vlan (proto)) { + proto =__vlan_get_protocol (skb, proto, &nhoff); +if (unlikely (!proto)) +return -EINVAL ;
[Severity: Low]
Is this rejection intended for deeply nested tags? __vlan_get_protocol() also returns 0 when the VLAN_MAX_DEPTH parse limit is hit, i.e. with 8 or more 802.1Q/802.1AD tags:
net/core/skbuff.c:__vlan_get_protocol_offset() {
unsigned int vlan_depth = skb->mac_len, parse_depth = VLAN_MAX_DEPTH;
...
if (unlikely(!vh || !--parse_depth))
return (struct vlan_type_depth) { 0 };
...
}When that happens, __xsk_generic_xmit() calls xsk_drop_skb() and the TX batch fails with EINVAL. This happens even when csum_start is well past the L2 header. Before the patch these frames were sent, and got a correct software checksum on non-HW_CSUM devices.
The commit message only talks about rejecting frames whose csum_start points into the L2 header. Should this case be mentioned too?
Short frames and truncated VLAN headers are rejected too, but there csum_start does have to point into the L2 header, so the described rule covers them.
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1057
Quoted 4 lines
net/xdp/xsk.c +4
-0+ } + +if (unlikely (skb_checksum_start_offset (skb) < nhoff)) +return -EINVAL ;
[Severity: Low]
This check only runs in one configuration: copy mode, without XDP_UMEM_TX_SW_CSUM, on an ARPHRD_ETHER device.
The same XDP_TXMD_FLAGS_CHECKSUM request is still accepted in these cases:
- with tx_sw_csum, because skb_checksum_help() runs first
- on non-Ethernet devices, because of the early return above
- in zero-copy mode, where csum_start goes to the driver's tmo_request_checksum without any check
Documentation/networking/xsk-tx-metadata.rst just describes csum_start as the byte offset where checksumming should start. It gives no lower bound relative to L2 and no error behaviour.
How is user space supposed to know whether such a descriptor will be sent or fail with EINVAL? Since this change is going to stable, should the uAPI documentation describe the new constraint?
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1058
Quoted 2 lines
net/xdp/xsk.c +2
-0+ + skb->protocol = proto;
[Severity: Medium]
For frames with in-band VLAN tags, this sets skb->protocol to the innermost ethertype (e.g. ETH_P_IP), not the outer 802.1Q/802.1AD type. Doesn't that hide the tags from the core's VLAN-aware feature masking?
include/linux/if_vlan.h:skb_vlan_tagged() {
if (!skb_vlan_tag_present(skb) &&
likely(!eth_type_vlan(skb->protocol)))
return false;
...
}With the inner protocol here, __netif_skb_features() never intersects dev->vlan_features. vlan_features_check()->skb_vlan_tagged_multi() also returns false right away. QinQ frames therefore skip the mask that limits checksum offload to NETIF_F_HW_CSUM devices.
That mask is used by dflt_features_check() and by drivers like r8169 (rtl8169_features_check() ends with return vlan_features_check(skb, features)), stmmac, bnxt, bnx2x and mlx4/mlx5.
Before the patch, skb->protocol was 0, so IP_CSUM-only devices got a software checksum for these frames. Now they get CHECKSUM_PARTIAL single- and multi-tagged frames that the core normally keeps away from their hardware. Could that put wrong checksums on the wire?
AF_PACKET does this differently in packet_parse_headers(). It keeps the outer h_proto in skb->protocol, resets the mac header, and only moves network_header past the tags:
net/packet/af_packet.c:packet_parse_headers() {
skb_reset_mac_header(skb);
if (!skb->protocol && sock->type == SOCK_RAW)
skb->protocol = dev_parse_header_protocol(skb);
...
if (likely(skb->dev->type == ARPHRD_ETHER) &&
eth_type_vlan(skb->protocol) &&
vlan_get_protocol_and_depth(skb, skb->protocol, &depth) != 0)
skb_set_network_header(skb, depth);
}Would setting skb->protocol = eth->h_proto and resetting the mac header fit better? skb_vlan_tagged_multi() reads skb_vlan_eth_hdr(), which depends on skb_mac_header().
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1060
Quoted 1 line
net/xdp/xsk.c +1
-0+skb_set_network_header (skb, nhoff);
[Severity: Low]
Should there be a check that an L3 header of type proto fits between nhoff and csum_start?
The only layout check above is csum_start >= nhoff, and xsk_skb_metadata() only requires csum_start + csum_offset + 2 <= desc->len.
Take a 22-byte frame on ICE with h_proto 0x0800, csum_start 14 and csum_offset 6:
- ice_features_check() sees network offset 14 and an L3 length of 0, and lets the frame through.
- skb_csum_hwoffload_help() accepts csum_offset 6, which equals offsetof(struct udphdr, check).
- ice_tx_csum() then reads l4_proto = ip.v4->protocol at frame offset
23. That is past skb->tail, in tailroom that sock_alloc_send_skb() does not zero.
That uninitialized byte then picks the L4 type and length written into the TX descriptor, with an IP length of 0. Before the patch, such frames got a software checksum.
Would a minimal check help here? For example, require csum_start - nhoff to be at least sizeof(struct iphdr) or sizeof(struct ipv6hdr), and leave protocol unset otherwise. That would keep these frames on the old software checksum path.
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1061
Quoted 1 line
net/xdp/xsk.c +1
-0+skb_set_transport_header (skb,skb_checksum_start_offset (skb));
[Severity: High]
Should the mac header be set here too? skb->mac_header still holds the ~0 sentinel from __finalize_skb_around(), and mac_len is 0. Neither the xsk TX path nor __dev_direct_xmit() calls skb_reset_mac_header().
With the correct network offset, ice_features_check() now lets these skbs through for hardware offload. On E830 with NETIF_F_HW_CSUM (GCS) enabled, ice_tx_csum() computes:
drivers/net/ethernet/intel/ice/ice_txrx.c:ice_tx_csum() {
...
/* Set GCS */
u16 csum_start = (skb->csum_start - skb->mac_header) / 2;
...
}It then writes this value through FIELD_PREP(ICE_TX_GCS_DESC_START_M, ...), where ICE_TX_GCS_DESC_START_M is GENMASK(7, 0).
For example, take headroom 64 and an IPv4/UDP frame with csum_start 34. That gives skb->csum_start = 98:
- (98 - 65535) / 2 = -32718, which is 0x8032 as a u16 and 0x32 after the mask.
- The NIC is then told the checksum starts 100 bytes into the frame instead of 34.
Wouldn't that put a corrupted frame on the wire? Before the patch, ice_features_check() stripped the checksum features and the stack computed a correct software checksum. That makes this a regression on the driver the commit message says it fixes.
There is also a related issue that predates this patch. ice_xmit_frame_ring() reads the mac header for every xsk copy-mode skb whose priority is not TC_PRIO_CONTROL:
drivers/net/ethernet/intel/ice/ice_txrx.c:ice_xmit_frame_ring() {
...
eth = (struct ethhdr *)skb_mac_header(skb);
...
}With mac_header unset, eth->h_proto is read from skb->head + 0xffff +
12. Resetting the mac header only for CHECKSUM_PARTIAL skbs would not fully fix that.
Would it help to call skb_reset_mac_header(skb) and set skb->mac_len = nhoff next to the new header setters? That may be needed for every xsk generic TX skb on Ethernet devices, not only CHECKSUM_PARTIAL ones.
Quoted 3 lines
net/xdp/xsk.c +1
-0+return 0 ; }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124083520.45547-1-kerneljasonxing%40gmail.com
Quoted 38 lines · On Wed, Nov 25, 2026 at 4:39 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 3
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]
xsk_skb_sw_csum()sets protocol,network_headerandtransport_headerbut leavesskb->mac_headerat the ~0 (0xffff)…
- [Medium] The commit message says ICE (ice_tx_csum) and mana (skb->protocol) misbehave onAF_XDPcopy-mode checksum requests.
- [Medium] For frames with in-band 802.1Q/802.1AD tags,xsk_skb_sw_csum()setsskb->protocolto the innermost ethertype returned by…
- [Low]xsk_skb_sw_csum()adds a rejection that the commit message does not mention.
- [Low] The new 'csum_startmust not point into the L2 header' rule applies in only one configuration:AF_XDPcopy mode, without…
- [Low] Before settingskb->protocolto a user-chosen ETH_P_IP/ETH_P_IPV6 andnetwork_headerto nhoff,xsk_skb_sw_csum()only checks…--
xsk: fill in header offsets for TX checksum offload
This patch makes
xsk_skb_sw_csum()parse the Ethernet header and any in-band VLAN tags ofAF_XDPcopy-mode frames that request TX checksum offload. It then setsskb->protocol, the network header and the transport header. Frames whosecsum_startpoints into the L2 header are rejected with-EINVAL.Quoted 2 lines
Drivers like ICE do read network_header/transport_header fields which actually point to the wrong place, leading to wrong action.
Quoted 8 lines
[ ... ]
Quoted 2 lines
Also, initialize
skb->protocol
because of some drivers (e.g.mana_start_xmit()) using it.[Severity: Medium]
Could this description be made more accurate? Before this patch, could ICE or mana ever get aCHECKSUM_PARTIALskb from this path?
I'd remove or revise this. As you pointed out, initializing this field changes the previous behavior in harmonize_features().
Quoted 101 lines
xsk never set
skb->protocol, so it stayed 0. On the __dev_direct_xmit()->validate_xmit_skb()->netif_skb_features() path,harmonize_features()then cleared the checksum features on any device withoutNETIF_F_HW_CSUM:net/core/dev.c:harmonize_features() { ... if (skb->ip_summed != CHECKSUM_NONE && !can_checksum_protocol(features, type)) { features &= ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); } ... }
skb_csum_hwoffload_help()then fell back toskb_checksum_help(), which computed the checksum correctly in software.By default ICE only advertises
NETIF_F_IP_CSUM,NETIF_F_IPV6_CSUMandNETIF_F_SCTP_CRC(seeice_set_netdev_features()). On E830 withHW_CSUMenabled,ice_features_check()still removed the checksum features, becauseskb_network_offset()was negative withnetwork_headerat 0.mana only advertises
NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUMinmana_probe_port(), so it also always got a software checksum.So for these devices, doesn't the patch actually turn on hardware TX checksum offload in
AF_XDPcopy mode, where the checksum used to be done in software? The commit message doesn't say this, and the patch is tagged for stable.About the transport header:
validate_xmit_skb()already sets it fromcsum_startbeforendo_start_xmit()runs:net/core/dev.c:validate_xmit_skb() { ... else skb_set_transport_header(skb, skb_checksum_start_offset(skb)); if (skb_csum_hwoffload_help(skb, features)) ... }So by driver xmit time, only
network_headerand protocol were wrong. The new transport header setter still helpsndo_features_checkcallbacks such asice_features_check(), because they run before this point.Quoted 4 lines
net/xdp/xsk.c +0
-0[ ... ]
Quoted 18 lines
net/xdp/xsk.c +10
-2@@ -1026,10 +1028,37 @@ 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 ; +__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 ;net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1052
Quoted 10 lines
net/xdp/xsk.c +10
-0+ + eth =skb_header_pointer (skb,0 ,sizeof (*eth), ð_buf); +if (unlikely (!eth)) +return -EINVAL ; + + proto = eth->h_proto; +if (eth_type_vlan (proto)) { + proto =__vlan_get_protocol (skb, proto, &nhoff); +if (unlikely (!proto)) +return -EINVAL ;[Severity: Low]
Is this rejection intended for deeply nested tags?__vlan_get_protocol()also returns 0 when theVLAN_MAX_DEPTHparse limit is hit, i.e. with 8 or more 802.1Q/802.1AD tags:net/core/skbuff.c:__vlan_get_protocol_offset() { unsigned int vlan_depth = skb->mac_len, parse_depth = VLAN_MAX_DEPTH; ... if (unlikely(!vh || !--parse_depth)) return (struct vlan_type_depth) { 0 }; ... }When that happens,
__xsk_generic_xmit()callsxsk_drop_skb()and the TX batch fails with EINVAL. This happens even whencsum_startis well past the L2 header. Before the patch these frames were sent, and got a correct software checksum on non-HW_CSUM devices.
Quoted 6 lines
The commit message only talks about rejecting frames whose
csum_startpoints into the L2 header. Should this case be mentioned too?Short frames and truncated VLAN headers are rejected too, but there
csum_startdoes have to point into the L2 header, so the described rule covers them.
It makes sense. I would add the following code to keep the previous behavior (falling back to software computation):
---diff---
eth = skb_header_pointer(skb, 0, sizeof(*eth), ð_buf); if (unlikely(!eth))
- return -EINVAL;
+ return skb_checksum_help(skb);
proto = eth->h_proto;
if (eth_type_vlan(proto)) {
proto = __vlan_get_protocol(skb, proto, &nhoff); if (unlikely(!proto))
- return -EINVAL;
+ return skb_checksum_help(skb);
}
Quoted 18 lines
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1057
Quoted 5 lines
net/xdp/xsk.c +4
-0+ } + +if (unlikely (skb_checksum_start_offset (skb) < nhoff)) +return -EINVAL ;[Severity: Low]
This check only runs in one configuration: copy mode, withoutXDP_UMEM_TX_SW_CSUM, on anARPHRD_ETHERdevice.The same
XDP_TXMD_FLAGS_CHECKSUMrequest is still accepted in these cases:- with
tx_sw_csum, becauseskb_checksum_help()runs first
- on non-Ethernet devices, because of the early return above
- in zero-copy mode, wherecsum_startgoes to the driver'stmo_request_checksumwithout any check
Quoted 7 lines
Documentation/networking/xsk-tx-metadata.rstjust describescsum_startas the byte offset where checksumming should start. It gives no lower bound relative to L2 and no error behaviour.How is user space supposed to know whether such a descriptor will be sent or fail with EINVAL? Since this change is going to stable, should the uAPI documentation describe the new constraint?
The same here. I would use this with a new variable (l3_min):
- if (unlikely(skb_checksum_start_offset(skb) < nhoff))
- return -EINVAL;
+ if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
+ return skb_checksum_help(skb);
Quoted 46 lines
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1058
Quoted 3 lines
net/xdp/xsk.c +2
-0+ + skb->protocol = proto;[Severity: Medium]
For frames with in-band VLAN tags, this setsskb->protocolto the innermost ethertype (e.g.ETH_P_IP), not the outer 802.1Q/802.1AD type. Doesn't that hide the tags from the core's VLAN-aware feature masking?include/linux/if_vlan.h:skb_vlan_tagged() { if (!skb_vlan_tag_present(skb) && likely(!eth_type_vlan(skb->protocol))) return false; ... }With the inner protocol here,
__netif_skb_features()never intersectsdev->vlan_features. vlan_features_check()->skb_vlan_tagged_multi() also returns false right away. QinQ frames therefore skip the mask that limits checksum offload toNETIF_F_HW_CSUMdevices.That mask is used by
dflt_features_check()and by drivers like r8169 (rtl8169_features_check()ends with returnvlan_features_check(skb, features)), stmmac, bnxt, bnx2x and mlx4/mlx5.Before the patch,
skb->protocolwas 0, so IP_CSUM-only devices got a software checksum for these frames. Now they getCHECKSUM_PARTIALsingle- and multi-tagged frames that the core normally keeps away from their hardware. Could that put wrong checksums on the wire?
AF_PACKETdoes this differently inpacket_parse_headers(). It keeps the outerh_protoinskb->protocol, resets the mac header, and only movesnetwork_headerpast the tags:net/packet/af_packet.c:packet_parse_headers() { skb_reset_mac_header(skb); if (!skb->protocol && sock->type == SOCK_RAW) skb->protocol = dev_parse_header_protocol(skb); ... if (likely(skb->dev->type == ARPHRD_ETHER) && eth_type_vlan(skb->protocol) && vlan_get_protocol_and_depth(skb, skb->protocol, &depth) != 0) skb_set_network_header(skb, depth); }
Quoted 5 lines
Would setting
skb->protocol=eth->h_protoand resetting the mac header fit better?skb_vlan_tagged_multi()readsskb_vlan_eth_hdr(), which depends onskb_mac_header().Quoted 1 line
net/xdp/xsk.c +1
-0+skb_set_network_header (skb, nhoff);
I need some time to rethink about this...
Quoted 20 lines
[Severity: Low]
Should there be a check that an L3 header of type proto fits between nhoff andcsum_start?The only layout check above is
csum_start>= nhoff, andxsk_skb_metadata()only requirescsum_start+csum_offset+ 2 <=desc->len.Take a 22-byte frame on ICE with
h_proto0x0800,csum_start14 andcsum_offset6:-
ice_features_check()sees network offset 14 and an L3 length of 0, and lets the frame through.
-skb_csum_hwoffload_help()acceptscsum_offset6, which equalsoffsetof(struct udphdr, check).
-ice_tx_csum()then readsl4_proto=ip.v4->protocolat frame offset
23. That is pastskb->tail, in tailroom thatsock_alloc_send_skb()does not zero.
Quoted 8 lines
That uninitialized byte then picks the L4 type and length written into the TX descriptor, with an IP length of 0. Before the patch, such frames got a software checksum.
Would a minimal check help here? For example, require
csum_start- nhoff to be at least sizeof(struct iphdr) or sizeof(struct ipv6hdr), and leave protocol unset otherwise. That would keep these frames on the old software checksum path.
I'll double check that. Probably like this:
+ 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);
+ }
Quoted 12 lines
net/xdp/xsk.c static int xsk_skb_metadata(struct sk_buff *skb, void *buffer, · line 1061
Quoted 2 lines
net/xdp/xsk.c +1
-0+skb_set_transport_header (skb,skb_checksum_start_offset (skb));[Severity: High]
Should the mac header be set here too?skb->mac_headerstill holds the ~0 sentinel from__finalize_skb_around(), andmac_lenis 0. Neither the xsk TX path nor__dev_direct_xmit()callsskb_reset_mac_header().With the correct network offset,
ice_features_check()now lets these skbs through for hardware offload. On E830 withNETIF_F_HW_CSUM(GCS) enabled,ice_tx_csum()computes:
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_txrx.c:ice_tx_csum() {
...
/* Set GCS */
u16 csum_start = (skb->csum_start - skb->mac_header) / 2;
...
}To solve this, there are a few options:
1. reset the header in xsk, which was actually rejected by Eric[1]. I think it makes sense that we should fix it in a more general layer (__dev_direct_xmit()) to cover xsk/af packet/other types of situations.
2. avoid using mac_header on ICE side.
At least for now, I think we need both of them in the next iteration.
[1]: https://lore.kernel.org/all/CANn89i+aacS2PfaMXnimzGgbCLz-JSnqo6QyoS122Gf+kxya3w@mail.gmail.com/
Quoted 27 lines
It then writes this value through
FIELD_PREP(ICE_TX_GCS_DESC_START_M, ...), whereICE_TX_GCS_DESC_START_MisGENMASK(7, 0).For example, take headroom 64 and an IPv4/UDP frame with
csum_start34. That givesskb->csum_start= 98:- (98 - 65535) / 2 = -32718, which is
0x8032as a u16 and0x32after the mask.
- The NIC is then told the checksum starts 100 bytes into the frame instead of 34.Wouldn't that put a corrupted frame on the wire? Before the patch,
ice_features_check()stripped the checksum features and the stack computed a correct software checksum. That makes this a regression on the driver the commit message says it fixes.There is also a related issue that predates this patch.
ice_xmit_frame_ring()reads the mac header for every xsk copy-mode skb whose priority is notTC_PRIO_CONTROL:drivers/net/ethernet/intel/ice/ice_txrx.c:ice_xmit_frame_ring() { ... eth = (struct ethhdr *)skb_mac_header(skb); ... }
Quoted 7 lines
With
mac_headerunset,eth->h_protois read fromskb->head+0xffff+
12. Resetting the mac header only forCHECKSUM_PARTIALskbs would not fully fix that.Would it help to call
skb_reset_mac_header(skb)and setskb->mac_len= nhoff next to the new header setters? That may be needed for every xsk generic TX skb on Ethernet devices, not onlyCHECKSUM_PARTIALones.
Not really. See the comments above.
Thanks,
Jason