From: "Björn Töpel" <bjorn@kernel.org>
To: Jason Xing <kerneljasonxing@gmail.com>,
willemb@google.com, magnus.karlsson@intel.com,
maciej.fijalkowski@intel.com, sdf@fomichev.me,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
Jason Xing <kerneljasonxing@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH net v2 2/2] xsk: fill in header offsets for TX checksum offload
Date: Fri, 27 Nov 2026 17:40:36 +0100 [thread overview]
Message-ID: <87y0aefcsb.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <20261127105347.72997-3-kerneljasonxing@gmail.com>
Jason Xing <kerneljasonxing@gmail.com> writes:
> 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.
>
> However skb->protocol stays 0, the offload never actually reaches
> the hardware and checksum ends up being computed in software every time
> (please see skb_checksum_help() in xsk path):
> 1. harmonize_features() strips the checksum features on devices.
> 2. ice_features_check() rejects the frame on NETIF_F_HW_CSUM capable ice.
>
> 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.
>
> skb->protocol is set to the outer ethertype, as the rest of the stack does
> for in-band VLAN tags, so skb_vlan_tagged() and vlan_features_check()
> keep seeing the tags. can_checksum_protocol() and the drivers get the L3
> type through vlan_get_protocol(). The mac header is anchored by
> __dev_direct_xmit() in the previous patch.
>
> A frame whose L2 header cannot be parsed, whose L3 type is not IPv4 or
> IPv6, or whose csum_start does not leave room for an L3 header cannot be
> described to the hardware, so it keeps being checksummed in software
> exactly as before.
>
> 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.
>
> [1]: https://lore.kernel.org/all/arKm5gCaERk6MaGA@boxer/
>
> Fixes: 48eb03dd2630 ("xsk: Add TX timestamp and TX checksum offload support")
> Cc: stable@vger.kernel.org
> Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
> ---
> net/xdp/xsk.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 45 insertions(+), 2 deletions(-)
>
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 52d538160e0a..8f566996a6dd 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -11,8 +11,12 @@
>
> #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/ip.h>
> +#include <linux/ipv6.h>
> #include <linux/sched/mm.h>
> #include <linux/sched/signal.h>
> #include <linux/sched/task.h>
> @@ -1027,9 +1031,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)
nit: Name! Now this helper has a second job; parse the Ethernet/VLAN
headers and set up the skb for hardware offload, even though the
application didn't ask to force software.
> {
> - 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);
> +
> + 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);
> + }
> +
> + if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
> + return skb_checksum_help(skb);
> +
Forcing software csum when parsing fails seems wrong. Can we return 0
and leave the skb unchanged instead?
Take Ethernet/MPLS/IPv4/UDP with one MPLS label. UDP starts at byte 38
and its checksum field is at byte 44. The parser stops at MPLS, but with
TX checksum offload enabled, virtio can still pass csum_start=38 and
csum_offset=6 to the backend.
skb_checksum_help() can sum bytes in fragments, but it requires the
checksum start and the result field to be in the linear head. Virtio
sets IFF_TX_SKB_NO_LINEAR, so AF_XDP puts all packet bytes in fragments.
The helper returns -EINVAL and AF_XDP drops the packet.
Returning 0 leaves CHECKSUM_PARTIAL and both offsets intact, so the
normal TX path can handle the request as before. The old
XDP_UMEM_TX_SW_CSUM should case is ok!
Björn
prev parent reply other threads:[~2026-11-27 16:40 UTC|newest]
Thread overview: 5+ 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 [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=87y0aefcsb.fsf@all.your.base.are.belong.to.us \
--to=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