Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796111871; b=4ZpavNBtRwwcQYmOcAKYxw6HxYWVbpoBAMWl/EAwUO0eVYWtDG19BGEMdpLtQVeJ75pK M/vxsRVlyxJnjnT3r5MAg/1tLPfWNOtXtfHkuHfMMKjkhW/WAV/9KfG4F4v3wB6JNKLD/ 4xaQ2WFB5gAbopWD2b/udViM2uSXu+PPvVTAjUCyIRQYtWHFPcjHWufAtxylhLatMbdUL vucAIu6/V/1Q2aqTh2gDfFXE/0iGK6G9AEIFGs64TUThmvuLq/FvdZlYiJMvhjRghoCb7 Ceq/dPy/53zslWRyc/7m6ScKwmXK8CXFccJ0j9OcAG+H//6fbznld2QTYHl7fhzkZRg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796111871; 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=F0q34GV9sHhzsI6E0/kbhK2TNBd1c6tP6TioH6xbS5M=; b=F6u8XD0DI3daFNvjJgV7I01vLkrMhtGVW4CuHE5H6kUtCEtQMmZbysX7nZPeR4/qmuOY gHJMAFfQ4MchaW/yFLb4OztmpuWc5bB3fdoCdARBP7mLVUI/Q50GnG90vSJNYR6wKyzlU iJzX8KFMHsKxB2n/oiss94+A9q5ga4dy13Jo5rUNztAg7YzYEZv2uxWTQbav1ELPw+GDh G/LQi0gVVnlWJw+deo7WY95sduvlGHDFxI1xBsRNIvUeAX5d1Ft4N6GSQhVnlJSU4bmrw LKZx+IlRcLrGeEH3NPBi1wbHu8YBrK/lfl4oJAgBQhdIMcitEG3JIJTki4RyhYw6E7Q== 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=mlkBMcGh; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (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 04E4C606A32F for ; Tue, 1 Dec 2026 07:57:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 04E4C606A32F 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=mlkBMcGh Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-386ab9ab619so17167869eec.1 for ; Mon, 30 Nov 2026 23:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796111870; x=1796716670; 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=F0q34GV9sHhzsI6E0/kbhK2TNBd1c6tP6TioH6xbS5M=; b=mlkBMcGhQqSZScYnxIPsg0BIUYtttnEzdlnI2v4+vKuZsrDDT7KBUkKplm/rNfq5+h qytulbG+IwqcxQ/nfops2RXENQcrXkCulecYd7k6czZ1RuePRzHFQcAIu2JpdKYgwjQ7 AWQ+U5STvEM0vWSC6A3OuKT+o6fUuyfoDx8sWn7eV2aAorHfj5Mz3IdUgZWcBXBETXMk tG5huxASFa9OlEehGlV24ZsoqNJyF1zVIp4UMGpmX8DVdatc6jVemBkRz8iUXX8hgUf+ 9NSLjFXM+O6G3u76s4/cQ3/YfE9YaR5mRV874sRiQ/2yjOJeoCJd2KjR+p3l4cx+BX7G jd1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796111870; x=1796716670; 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=F0q34GV9sHhzsI6E0/kbhK2TNBd1c6tP6TioH6xbS5M=; b=bOGvW/2uHF4NFFZE6XaNeTyvACuh0RCOfW7oapBuQPXlaCl3yTtCu9gTvh7WwCmKLY dj9OvXgg69t63dUF5qSekSq8ee6Yvl+JC03VwXJkXpo/E4RcZXDRbNV9QfDXSJtqIoT2 5SQVuB8+v0Y0NmL0qFyJ8kl3dsW0OAG69bKMH+gPSMVpzFoxEM8ZwrsIWy+1YrbbmYa2 t3BvFsDy8wUb0j2HboTVh24g1tqUdgKuiC1RTfFnpE3S3qUK8kmIYBSMtXhrVIBEa5YS Fc7OrneSIrzQ8EPEGQoAqOouRZHUjyexmJuVWNn3i8Ou6YZ1jipDGCiD+y1ZM0zAK2nY w1jA== X-Forwarded-Encrypted: i=1; AL+hErHg5MXnc9TgxKoc5Dq7/ZZTQOSyB7n2C6wTyYlIIlfhZbgQGtK62cz89dTCizIhw89B944=@vger.kernel.org X-Gm-Message-State: APuU4Z8mefO+SvIqtGjNhN0q5cE63Jh0Oqp4EX2OOrToprdeafwWjbo5 CbXDhdCTIGykYY5RjkA8KWTokrzk4mWON987f4CPVYK4QiVsFzXHF2D4M8i4OrQNBgA= X-Gm-Gg: AZFdTZcRrlfkCQeVMM04JXaKpRCMUG81bZ0AWLQI1GkCOaLlIJTZTHJBj2DEHWomBK6 3IiiCAt1U/kJpaj1cNCGfXuj3DFqbZhC7vLQ/U+9qr3pMA/RbyTsuBcUx5aQNXul0DhHHbR0+mZ TUFKA162CipxQFfea4XJZaCHOwF+uDDMRcyJDM1CrmjlEKsWsOOlMu9WK3fSiqPOYT3M1/cSgFx 5IDqhjsL58Q0aVJUolp5OpUpZyhxsA+X656XOtKokyAhtZNfFFCSdXTGZNxyc5XqmAXNM5w0Bvr BWiFHSff6RoXno1fBnYxVUcvQ8hJXlEkBWhHd1RokrZWtpNcw96JRNCQTrEHT2CMWs2/750uZne X740Sw50N7xcXHFVT96rt595OaeRqtVfb569vbhDpVPZF5oVZMv2sJ9h6faSuNuGy5SzrJuvjVd cDIry7JsJbZ5wYk/5Dc2IxD3u6ZdZnt6g0shwG01BYcqBoMGi6b6aqL9sL9iyDjz7Jhxgw+gp06 4k/bzYNaUgeMzCPq4g0fhKZDvTWaJa2TmQhwHIGO4Qadu4ar46EWCCEl4OSTwU+/z11h2ez1RXQ BMwibZU+Szs43eZfT1neV2f0Hg75AJ3wPgnDnyM4KUWzxWOjyY9AHuCuHc3wGqXNIZHG9oKBTOZ FV1rLby0B8vKWhtFHb1RbIFrehmcvgLxVKmyQ36T418x/wbVl7CyYWei7K8TfAHxuE3kDkiVg X-Received: by 2002:a05:7301:4d11:b0:386:c666:ec45 with SMTP id 5a478bee46e88-386c666eeb2mr19177290eec.12.1796111870048; Mon, 30 Nov 2026 23:57:50 -0800 (PST) Received: from localhost.localdomain ([38.114.108.154]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385666e7f59sm112046693eec.6.2026.11.30.23.57.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Nov 2026 23:57:49 -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 v4 2/2] xsk: fill in header offsets for TX checksum offload Date: Tue, 1 Dec 2026 15:57:31 +0800 Message-ID: <20261201075731.36746-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261201075731.36746-1-kerneljasonxing@gmail.com> References: <20261201075731.36746-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. It is checked against the L3 header length found in the frame, and the L4 protocol has to be TCP or UDP with a matching csum_offset, 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 the previous commit ("net: reset the mac header in __dev_direct_xmit()"). A frame whose L2 header cannot be parsed, whose L3 type is not IPv4 or IPv6, whose csum_start does not match the L3 header length, or whose L4 protocol and csum_offset disagree 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 # depends on "net: reset the mac header in __dev_direct_xmit()" Suggested-by: Maciej Fijalkowski Signed-off-by: Jason Xing --- net/xdp/xsk.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index 52d538160e0a..608b76cc0dd5 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -11,8 +11,14 @@ #define pr_fmt(fmt) "AF_XDP: %s: " fmt, __func__ +#include +#include #include #include +#include +#include +#include +#include #include #include #include @@ -1025,12 +1031,77 @@ 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 csum_start, l4_proto; + 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 0; + + proto = eth->h_proto; + if (eth_type_vlan(proto)) { + proto = __vlan_get_protocol(skb, proto, &nhoff); + if (unlikely(!proto)) + return 0; + } + + csum_start = skb_checksum_start_offset(skb); + + switch (proto) { + case htons(ETH_P_IP): { + struct iphdr ip_buf, *iph; + + iph = skb_header_pointer(skb, nhoff, sizeof(*iph), &ip_buf); + if (!iph || iph->version != 4 || iph->ihl < 5 || + csum_start != nhoff + iph->ihl * 4) + return 0; + l4_proto = iph->protocol; + break; + } + case htons(ETH_P_IPV6): { + struct ipv6hdr ip6_buf, *ip6h; + + ip6h = skb_header_pointer(skb, nhoff, sizeof(*ip6h), &ip6_buf); + if (!ip6h || ip6h->version != 6 || + csum_start != nhoff + (int)sizeof(*ip6h)) + return 0; + l4_proto = ip6h->nexthdr; + break; + } + default: + return 0; + } + + switch (l4_proto) { + case IPPROTO_TCP: + if (skb->csum_offset != offsetof(struct tcphdr, check)) + return 0; + break; + case IPPROTO_UDP: + if (skb->csum_offset != offsetof(struct udphdr, check)) + return 0; + break; + default: + return 0; + } + + skb->protocol = eth->h_proto; + skb_set_network_header(skb, nhoff); + skb_set_transport_header(skb, csum_start); + return 0; } @@ -1281,7 +1352,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