From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795950677; b=05UYvdlKfL4Aj0/7sQXdmujxFxqNBNMZqZZYJWnYd979HoleN0l0242YJdvgNG5KQHGF o4kORGvZocdq27iSn6LfR9zdZ31uNEFB3EKo+aSGQqEGSJ87GhbIH5Kt8OE5aTCOb2UUT O/uG/CxAi9EkC1nMM/KbXMWE77lRiCWexWrCCiWOdy5tG6oPJQaxFrj3Rh24jnF4nKec8 6/BMZk44ADQheJyTKn0O73IXJFkmNici3au1K5CYT82R+9+wHJ2ZCZbrvazyqGLX08LX0 ASfoiy0eo88LMkxwZl5V430/wYzboHK+n24oAmtc0+Eys8HVzk5zbIFVRzRaj69y4eQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795950677; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=AZYk0NlXqyWd/Lw1am7pR8UKv+F1NOirJMSZxkfwg7TmB8Twuzb6jFUQp2Ol1khGOMR0 8PUaCtwrAYdNo8oBuw44KkqLL0EFKumnw7K+O+3bVJKxEqjIwhVOQvFTEc+BESvRz7yO4 4fi/ZiIkha9LTN5ctDdWbhn2jOlT3ldcCNA4efdCoZEqVWnYilBs14shwblG7icaC0oUK D4f/x3QDj7JBxJwXgFBfKYDDSVKnVRwLOb+Mw+sZQHrhvUH3y1IjD5FAG6iKz7UGVn7O/ zTvy5jo9L4P3uBm0ibjl5lvcWuxqusuPQJhAfxuclErSjeQsUXdEHHES+UB9ToQBeUA== 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.170 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 E9828606A32C for ; Sun, 29 Nov 2026 11:11:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E9828606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-38644aedba1so15670790eec.0 for ; Sun, 29 Nov 2026 03:11:16 -0800 (PST) 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=Zp96NmCKtp0m+X2u139eQDb+0K6YOp4zFYbfccn0xuUvKesH9DMKkdG4/PhSu9jSI+ VVXJudgE4FTzK6iYKP+vAWnp0l88LsD6YJuO6FooedoHx4ERMVA/9E7wLeXuKe/7BI21 zphtszBCCWwmAPLU8TvOAbAK0U4gHfdy8rF8l2xTyRvdPjOLxnCUtmOM/mNMtJb07Wdq a6isA4hVaqUhzkXt9w6AKUtIB2slHFCq71FJ+anZnysb/1NXTI3oqdy7lC+M+otfickN d/I6Fs9uQ9NgSY2A9G+pUaogKp+r1GZOSi16kA1gX5IE1CFt8ooo6a8XKqY14m1fvHuA FY8Q== X-Forwarded-Encrypted: i=1; AL+hErE7UZJXlD2xJZumKeA+UVOFVjbbZWt3D5Sx/paeIeGiuyURqd6N3nOqXKaI36FRfBVsrPE=@vger.kernel.org X-Gm-Message-State: APuU4Z/2PqADbCYbzpE/kKg7SqtQzxTh4r5/SOMFl9r6uKZkXJk8ghTx EiFD6DayUhK3CZpovEvcvtsdmFsEY6efMBMXGEjgoROvD4PUGIfV+Hl9JAU2m6nZ X-Gm-Gg: AZFdTZc/v+NnwegL1751rwVjA/AmrlP+bcaguZyEgJx+63mq0Jqo+4kS75pcBOZmpq2 vQmtvoo+/scswna4UUAFAvbQIdxhbzY6qNtRDCP8cxVKdYeuz8RmX5AkzcZr8qEArLIGHzdZAnv i6T8W34WT7I0aS9ejXMBRf3E6Y8zqPhqXS/aBY13AlcK5ZvM/YEmAJgGjAul8Mm7BHkBSCOJ7Df 2F1R0BE6XmaoONcQBl2JDlEdJSmURN8pWAylaYs58zdBR8INDPCUTUEu8dMcSEWsZelpS8ZaCSM 3QQXW8LC/FAx/LgN9DOnaFwXTh0941VmYFXzfcdR8Pj/XO1r2z45yyloDcJg5zKcF67ScijDdL+ 3YjgrGwyJGXLkvcdyy+hzO0fdbDWYF2ah997MqUCf7Zx4KBfqeL8AKoVnIdWUeaLfJ0osFX8Xpn qZX4tCw4/TYT+2ckhOSI4rlH5HGqbDGRdT6u92bvTWxuRBCQE5NeSXGuzupGPDX1r/grrOC1sRM 0fPSXiaDgDOY6kdJ0jXnstwkNbtfdpDAvUi9dxqIF5E7XZEoxPXcjcNx1zoGxzF5PbB5FG7l1c3 +2Sqsvjt4N/VFK7yo98UwhgloAdISpG4Dz4pXL4btM+IXNooIoEtD4f8CB+Ym7HrhIDsCQHlquJ Vt41B3ONFzEEt61JWV3ULEVd5yWt1kK2Yl2IdrjCWWBHUu82gR7q1gO6CuZ+dj3dj4AzfKaey 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) 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) From: Jason Xing To: 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 Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Jason Xing , stable@vger.kernel.org Subject: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload Date: Sun, 29 Nov 2026 19:10:56 +0800 Message-ID: <20261129111056.11124-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261129111056.11124-1-kerneljasonxing@gmail.com> References: <20261129111056.11124-1-kerneljasonxing@gmail.com> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jason Xing --- 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 +#include #include #include +#include +#include #include #include #include @@ -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), ð_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