🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24131

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

#24131
From: Jason Xing
Date: Sun, 29 Nov 2026 11:10
127 lines
14801 bytes
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));
+
 	return 0;
 }
 
@@ -1281,7 +1324,7 @@ static int __xsk_generic_xmit(struct sock *sk)
 			continue;
 		}
 
-		err = xsk_skb_sw_csum(skb, xs->pool);
+		err = xsk_skb_csum(skb, xs->pool);
 		if (unlikely(err)) {
 			xsk_drop_skb(skb);
 			goto out;
-- 
2.43.7
Technical Details
Message-ID: <20261129111056.11124-3-kerneljasonxing@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.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-373463-linux-kernel-netdev=dewy.ru
References: <20261129111056.11124-1-kerneljasonxing@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.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-373463-linux-kernel-netdev=dewy.ru
From: kerneljasonxing@gmail.com (Jason Xing)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload
Date: Sun, 29 Nov 2026 19:10:56 +0800
Organization: Usenet Network
Message-ID: <20261129111056.11124-3-kerneljasonxing@gmail.com>
References: <20261129111056.11124-1-kerneljasonxing@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1156872"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Vny4HZ7zxpP/OeGly7IY3ewGltw= sha256:D/JmIDA/WV0MfRuajHX3Z4YkS3smSuMYEow5Z6oSMzw=
	sha1:DlMJzhKCkS/8Q3Iao/hON9yTHkE= sha256:gGe7KlIRoBUkpoYcB2MCkitPkprxPcmhNbMxevYLynw=
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 CC647125F94; Sun, 29 Nov 2026 14:11:35 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=gmail.com
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 tsH2X5TO5vmY;
	Sun, 29 Nov 2026 14:11:32 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-373463-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 259E9125F97; Sun, 29 Nov 2026 14:11:23 +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 869B225894; Sun, 29 Nov 2026 11:11:19 +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=1795950678;
	b=SogQJNqN9wKdmbPhsY2VuC0iawDJJD7gwGrDjjJx1XRUri+y6s7NyKaos44Sy9FMafWY
	 Q6tlQdueQ/Fxy/HZivEVoDewWqJImjtEUcwSVCZRiDI2+ANw1ASpJtmBDHvbPlL3UG7Du
	 fTqL674GAJAfHEY6xwHzmLYRWbvZVpGy/4Kwesdb+Q9V32J8cSbMW+JG5VVy1Vewf2pV6
	 T8JwXlYTcQuFwRaDCaJhyknmVuY/RXPI5rVVUOL8oIsl7AIU+TlWY1jg0lNWP713Nq3U9
	 VjOV2oKSChjf/2ThW59z7jpdLqll6uD9L6ooKRCbdFeIOLF4Qmm4C/GyGB9VPe1ZGmg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795950678;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=dcz0u5+aazAqwSp97PVqRU7Q6JD2U4si0wKMWO4sCcU=;
	b=P4YK1xHMZ5gqu1Q/A7L2af8m4K69YK4D1un8COsa//JIm/y1EieVu7pX7tNfOeiCY6IN
	 MCylObrgY/zTKkykf878qU7ILK8pIDBZQWZtwV29c2RESbzOJWfffJiATf49ojULm1lDf
	 1GZU0tRs8kTUSfWkPjnQHJTf64LEh6vl9jPnKVl4hgyXtBuerCTo4i5QgbdDwwEtGSUJ8
	 lkO5HQ9s8RVKyGgtXSj6frKTDehJl9IqUPuVSKNw2638xLjL4pqYM/z2C9qiHSsqctvli
	 r+VLF4bpHkq9yljpe7i/JbvUaDUaCE4FFgM0rQcAa0Hf+M+hRcxFZa3yXqLe7wIw0tg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cb8ZIYbV;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 C7E46606A31C;
	Sun, 29 Nov 2026 11:11:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cb8ZIYbV
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.171
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795950678;
	b=zNqTbYNy7Fp3+UiWEQl3ZJL5Xd9GAQAWCnerFcMBImcPaUMkVlAohH7DpDRmAUrUJnsK
	 17kmchk3pS4aFIP6Rr009ddPSER/8aS1HbAJcfv7bhOHfkPabcq7yb/mwhguZdl/2TNRG
	 aN7zHwAGm0frNIXklFEekP1eMMRE+bTLeh3nfgkOsgpZdrTyfqWUCekt7n0fNYMUNWxHe
	 SKQEWyWU/FRkUeraS/CO72ApH5S/nizOE/vE9q4rFKIfjh6ejrnm4keAQw6LrEiQCa8Fj
	 0Lgnqe0OC/tcPm8F5lBj2ZaiYgjjilf+Su4bMOc3NMOvGC1rnKwJaiEAcqBq0asjwgw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795950678;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=dcz0u5+aazAqwSp97PVqRU7Q6JD2U4si0wKMWO4sCcU=;
	b=YZrlNf7jIUOTDikIHLQ09n9vutK+fO5x57YRL6NypL3IEyexm/eIIrJJsZKI4pRW9W5P
	 hdtXkDuD0vTaVAkaZP3wYYDiRwdqePaKBJTSeUJv9mjUIa05PQUg8M6g4P+wlV4I4ff7h
	 UEfFrKPcJw1xab5uAy+6eUdAyr8jVsopJDHD1uLHoXexCkaFRQFaVNV4yXDTjpESdhgNP
	 qGPZau3PYQ9en+jY1Ym0fP4YHSTBZwTuOdmvpOgzbyc4bawmoUkp5gd2dToRYa+ZoKli1
	 Sfx1M4vMPt6abixOkehfmNEbCAGlLFhJxDbK+8MJuQpCTe6hMIsLgzbcH+KNQaL1ZUA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cb8ZIYbV;
	arc=none smtp.remote-ip=74.125.82.171
X-Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E56A0606A327
	for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 11:11:16 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E56A0606A327
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-38644aedba1so15670791eec.0
        for <netdev@vger.kernel.org>; Sun, 29 Nov 2026 03:11:16 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795950676; x=1796555476; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=dcz0u5+aazAqwSp97PVqRU7Q6JD2U4si0wKMWO4sCcU=;
        b=cb8ZIYbVwo6rzRt5kYGAp9JQhIDPeH2D1POLvf1DykHErnnIjfHKO11DjEFQXwe05g
         3MK5DHkOnPqS9+tJ5aK4No5sEAx0G9mJtXEd+UCaF/Yl6H8kqXrFUL86UUFffbZxnNNC
         dIlnMjcofhC8vC5wP+V1M/Tf/6UbEj4nRTyeUz5VE1tzaCiMxsMK4nomnPPTnRs6rYws
         SumIjA5P9s5VjbFbesZb98g2ZoJKBRT8tw0F3yL6WF1hj7mpR9xz3puxdc0x/xYcJHNA
         HG2/h7C+xX4ovZfHQyYhG+gYCZow2C+Gr4neOsTcgKKmaZF/AT6BkW3hhs9Uq48xtRw+
         sn2Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795950676; x=1796555476;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=dcz0u5+aazAqwSp97PVqRU7Q6JD2U4si0wKMWO4sCcU=;
        b=PtQXJ1f6APnQNBHQHNxzRhb0zm8Of2ba6L34mDu31HnSZh6W5+JHTWhxMt0DJQc8pj
         HdFbhhERBNJdsWkwTWQN0p2VakiXaHIETUjLwAm/xdDFAEfBCLjDsfN1VyEl6b5VQo4u
         fOG/K+F6L4nst1/M4WT9Ve6M/Lfco1YHnrZc+Y+mowC01SoWEd8Sma/0SJngl/Qtlpkj
         dw/8M3HFZQGNhgbMU2hps83r/qKsZDRpAYrAE8NUl2MzkSOOS0vi6le1UtsbjYPITMlP
         w18Xs/2rBkKjLFwd4oqxa5UjiHWv8O3jwQvE9TA6COtdbJi1XpYGZUsKuTTsBG1GcV82
         I6wg==
X-Gm-Message-State: APuU4Z9jClS4CyY8Sy7tiZn066Qu7vObd32njnI9aRkHlHTcuOA41mBy
	1nhUs9ODQzyLxUNc+h1Ll9E5xxZ2Rlcbl4/Vp+sGz3P+v0cmNq2wRGl6
X-Gm-Gg: AZFdTZfEKPFyINmkRVAwyClK9JQiV4Nk+0szqZ1GOfTpPLQU6RVSSiPdOXDg7l1Cz2m
	KPfIxeVR/Keq1Llgwi2/wPLlRTWyyNcal2d1qqqaGdYiF1gJ3v/iCxrap3U+LqZJYYn57VnClfc
	MldrhI1athvsUyE2Nou7AjC1AN71hnWqb1ICOtlgIhYDyUjtJ3LRat01OtUwxZ1xCJAc705m5l/
	AFmsNUFA32PGXdzw517pnwXECr7S/SEkUkqjax34rj2PnixNYQP6FyGXI4Zc8X2X4/1HeKEBGbw
	wo0/ZUrqg9sXXNCc0T++X/oTcnoQk6FjsLyCoZyfm/dru2opbVmu3J7w/oXKvGCy5DUhQNirw7U
	Lo2aomwKu1FO0703UTaw4mZtq4wpHHG5gAhY+oZ7Opf/+gPcwIrsnYiTyy/ppx/vNBbKUKZ14CK
	twTT/w3EKKEb84mGun5GeWUTTsRhmipVDJ29RtECj5VYLCJj3kRoFmU9nmbHSvukePJAsnQdNJ3
	R6v2w8WOnzNHfN6O6WTH3KUVCA3aYnw/jldr05lJQ6ba2O8SsDcssDn8P02iOfAPxPXjmfLrg2L
	OhXDyxmvg9hIkQ8oSh02yzJKh1FE3CHpTM9hIVx0WJl2eQ/ZqRY9EPWm/k9MeNNFVkx1rJWecBA
	GI9HfPTh3pIcjME4vzm/wMiRoLo2Nk0jchnTckwvwBoyzsIL2slhrXBzYwyX5QfP44Xkyfv0y
X-Received: by 2002:a05:693c:890a:b0:386:a93c:a637 with SMTP id 5a478bee46e88-386a93cad9bmr19726445eec.34.1795950675986;
        Sun, 29 Nov 2026 03:11:15 -0800 (PST)
X-Received: from localhost.localdomain ([38.114.108.154])
        by smtp.gmail.com with ESMTPSA id 5a478bee46e88-38567ea2cc5sm81277415eec.29.2026.11.29.03.11.12
        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
        Sun, 29 Nov 2026 03:11:15 -0800 (PST)
X-Cc: netdev@vger.kernel.org,
	bpf@vger.kernel.org,
	Jason Xing <kerneljasonxing@gmail.com>,
	stable@vger.kernel.org
X-Mailer: git-send-email 2.50.1
X-In-Reply-To: <20261129111056.11124-1-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