🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24776

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

#24776
From: Björn Töpel
Date: Mon, 30 Nov 2026 19:53
125 lines
11951 bytes
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:
> 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 is left
> untouched, so validate_xmit_skb() keeps deciding between hardware offload
> and software checksum 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 | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 47 insertions(+), 4 deletions(-)
>
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 52d538160e0a..58f77af6100d 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>
> @@ -1025,12 +1029,51 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer,
>  	return 0;
>  }
>  
> -static int xsk_skb_sw_csum(struct sk_buff *skb, struct xsk_buff_pool *pool)
> +static int xsk_skb_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 0;
> +
> +	proto = eth->h_proto;
> +	if (eth_type_vlan(proto)) {
> +		proto = __vlan_get_protocol(skb, proto, &nhoff);
> +		if (unlikely(!proto))
> +			return 0;
> +	}
> +
> +	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 0;
> +	}
> +
> +	if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min))
> +		return 0;
> +
> +	skb->protocol = eth->h_proto;
> +	skb_set_network_header(skb, nhoff);
> +	skb_set_transport_header(skb, skb_checksum_start_offset(skb));

I think you can drop skb_set_transport_header(). The core does it in
validate_xmit_skb().

(Sashiko's medium one is IMO correct...)


Björn
Technical Details
Message-ID: <87tskyyu3b.fsf@all.your.base.are.belong.to.us>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374429-linux-kernel-netdev=dewy.ru
References: <20261129111056.11124-1-kerneljasonxing@gmail.com> <20261129111056.11124-3-kerneljasonxing@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374429-linux-kernel-netdev=dewy.ru
From: bjorn@kernel.org (Björn Töpel)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum
 offload
Date: Mon, 30 Nov 2026 20:53:12 +0100
Organization: Usenet Network
Message-ID: <87tskyyu3b.fsf@all.your.base.are.belong.to.us>
References: <20261129111056.11124-1-kerneljasonxing@gmail.com>
 <20261129111056.11124-3-kerneljasonxing@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1523191"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:aq9EyklsT5/1qSfdTGA1lyf6SFY= sha256:Ik+9OTJgc/qw4LvLW2yT/aCHYllXrqd65Qyo9V3wieg=
	sha1:zq1KQDgrni2/AncaYCh+m49gPdY= sha256:qBi/5YfROdx5DbajiPcBDT5l4mKaAASiKmMqGauXAqk=
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 12730126001; Mon, 30 Nov 2026 22:53:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[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]
	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 Th8Mx_qLoiFh;
	Mon, 30 Nov 2026 22:53:30 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374429-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 619BE125FFC; Mon, 30 Nov 2026 22:53:22 +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 04E33283BF; Mon, 30 Nov 2026 19:53:21 +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=1796068397;
	b=OQFuIQaZSpuBCZq0MF2XeKo+6ywIyK3pS03e9CzZkY0BJo6qSTf8Hqoyzm6gn98BJQfm
	 GKmy4Nu8u8lxDImldXqEnmv1ROxmR+zoku6NSM4km9fp0yx6rePdNpqy5B4hi4a/2OX1Y
	 DaHWpRA5QspD9F30hE/nFEsGj3zLghSa7iAKx6s/btRiCr3+xN1v6gk7u3h/cduLXkXRb
	 a5XaDkK4vCsUDE+SSi61cpZxbK9O8VbAaHe7eSs1tsBut8jVtPWH/lHdUJSAUpsdAE+WV
	 RJjRf/pOy+NNFkqDoY9KneNmuXHrF/UJP9YDIrIL4mW4VEZz0ZU69ODz2fv1nZmP+CQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796068397;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 In-Reply-To:References:Date:Message-ID:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=o+a0LQGIw9yTI/BKGmDgQuZcjg1fAt5CxjPSz1idsxk=;
	b=s1qYv4jvPDcErx0ZFRCptUU3cuid2plRaeovoJKTRi2cuzPVkFtpSVaAqKk4y0IGeKu8
	 Gy6UyvzqB136bH/nsBkuFmDbFTbhingNJOkwZRM4Um0ikk1yUkEJKfYML//YHVYIyGHHi
	 DtH5tWc+hvffr7ziZghaP1tKzNVhZYfO6sZqdQak0PVdc4+Itm+wB1hV8RP1LzLflxBRO
	 lQ+kzv55p58eU+uHQSJQ+Hy68dXpgytlsNykIVY+mKx4jNugKYblUHautKhnRcrCyCdgF
	 TVoYIOCL0gJwLzSlYkv0ouPfbc3RnDI4vAb/uiua2JWMvrW0XkNP86eYCZuTIQfcyeg==
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=n9wTPFAv;
	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 944B2606A335;
	Mon, 30 Nov 2026 19:53:17 +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=n9wTPFAv
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=1796068396;
	b=XuGlr4SY7RRXsRK4adm+uKTERokgEA5E0FVvVuah6kbYTVmPzUwhitMgoyPnAjYqcvvM
	 u7UNHia44eGBd+mecf+P4/VXv/CgOKee7MQxoc7Lwi4wqtRP+E7ZG22nG28D7ufg4YI0F
	 HhabnFBHBIF3LlKqrkZqCsCxlR+5AIQB6wgkHRgl8bzVF+Q37EYnRXrYuDT7oZv8RzNuO
	 eQqz7A5xBbEq/HHE4cOn9igjPCZOglKMxrf7oyWSeSqA/WvUu3dCOoieOpx0Ngl5rZSbK
	 FVDLePZtcMEWBXZAJftXS4k7ugxYwOpAkFxhUscliZMbOSUjqyQ+aa+9NKyGfptfADg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796068396;
	h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References:
	 Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=o+a0LQGIw9yTI/BKGmDgQuZcjg1fAt5CxjPSz1idsxk=;
	b=voBDqjV+0loA3TI59fi50egTP4NqCG7UdsKLggBulfZI8MLviffF2UWfjtfFsM7PlYBA
	 LKXempq3TmSRlhwYGOB+khmBQ/0oh8VgMjTEAdTekdGi4g6A7hl3aQhD2OgpChswHnuOs
	 vM6+OnxLCpRKyKJLZHZ1Fn9V91m0y1OC2Y/jEGBlUIlPEicj41temV7WyZqpvPdNyvBOY
	 cD+BtMcAM87wYENofF4BF5H4+huUemL/tHzx2X0AQrKGYXlmplZNeX2vK3C5GaDIWYzoL
	 tgDltEjMmaGKvLSC6y2fUBB30Cf5nNLXDw5qVSigl0ViuFYYCcYxUnlvznrUVNTbilQ==
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=n9wTPFAv;
	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 B0E27606A325;
	Mon, 30 Nov 2026 19:53:16 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9718F1F0089C;
	Mon, 30 Nov 2026 19:53:15 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796068396;
	bh=o+a0LQGIw9yTI/BKGmDgQuZcjg1fAt5CxjPSz1idsxk=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date;
	b=n9wTPFAvfAe9PHyjdQP3rrmkup44ALegpi+2RCr8fapNgxygF5F5PH6qLAE1eM6Q6
	 ybgphM7CltT8WerZYwU1zzvsAtNiYHaGectytamIqTTlilhO8e5ELAvRrTO0Ys8nvm
	 SNGgLVEobdKHjLsW0jG2Uh12YWPU8717Em9piT4EJZ82lrLY7i4ww9YHzmlY8TChO2
	 oxfj9csV2A/IGjr07lvsdLbts3dG9jJj8u7UEOBnmzQsHZPa0xUx00DwrcLIfuWZjk
	 PNgeORSKjPI36vYhFOmUY5IqHxZcCvcMBEeMFaZkwqmufOg8bSBx4Ge4/uM7MhXXQX
	 tsXpoRigSz4/w==
X-Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Jason Xing
 <kerneljasonxing@gmail.com>, stable@vger.kernel.org
X-In-Reply-To: <20261129111056.11124-3-kerneljasonxing@gmail.com>
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