From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795950677; b=Jc1PnBRZreQkweRrb/94l1wahunpuL+fw+/vyvbMIIpP1AjcEFUsz1t0QErZ89jAmriy R0cG2E3sLHbX8luFhex+QJOh8Zcrp3Io7tUjrYIFp59TNoWGggArpLsFJHzLipMi1A9lP Cxkkg1mEQuzL/Zc0a9s0az48dtl4l8XbpVaWJ5fCROpgpGl4rB7qUr2MUGJVLOkpqffpu H6CjNLZTEti/Qx1h+V7fY6xIL6gA9YeW1W2P6yemU2mrjsAXdLhmM0VfTgI1fEyRnqOqE GFiLPPScZdoiiKpmdvCudwPvDs1I0YlSIP6lfjFMEqaPdpg+P5q/sXM47k/5AON/PDg== 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=BDM5aFp9mPEaBqgTDBmcAGkCaKNOZVlbZU814rc2rBIBquQJ3T/nOB2+8lCbibEPTBOt IJxCO2V5E3Nl7q0ovfxlwL0DcjKD+Hd4911Y4JdJefwweG6xJmakJ6Fd6Ycl/PSfjDIJy AWxeDXGxe/N4bHhhCqvkaj7h2hr3zK1SH0ZsbQYtqDbq06wASqP86IE1DUukIwGtgJNnq 47xQYX5lNXNUm9Wg200MVSkejySwEKSfs81QQM1uKB51S6Fr5pk5VoVxaWxYmL6aJGiOs Dwzv92liEFxDChd2tkgfXkHOy5ROnpjCkkCWSJ2IrtJZg8iMkUIHqjZmKtXT+lgu2tQ== 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.178 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (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 E6256606A329 for ; Sun, 29 Nov 2026 11:11:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E6256606A329 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-f178.google.com with SMTP id 5a478bee46e88-385d8a00598so15900766eec.1 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=wKXyKA+RhaFcM7JEvpmIk/pNB354iJJ+ogEn5/bKUXS/wrlAjdYTCtNzh84gvSJS9a LzdO9YaCi7u9ZEfEgonLFxcywS1gdCLbI7b5mtFwRhjVausq0WnXj9b4JhUmPaUApx7n H0I3HHOs2xK7hHr+2b98MpvN7L5FoOy7DcKmF9saNT975L7CXL6iiucOHiTTkjO3TqKX PbQk/VCwYpJSJjaV9C4zAeENUfmTeOxao+Y0VyO5dzrfTD5jCX53sIFvY4sAoyOiZOWg y7B7KjvwllWKdyC5wQoEbzZQTmJ7km3SfpqK4OERSskxH0JJ7JcvZwfDG2LcSPcpB+G4 xdxw== X-Forwarded-Encrypted: i=1; AL+hErF1DYhekBjFFArhCitnYiyyrCU3LHakCe+62EUKQOq1BHtF2NV3BKH8FNpr2mboZCOQb9hkSwI=@vger.kernel.org X-Gm-Message-State: APuU4Z8xiRZcLtqYguDSZVh04K9j5gcJirz4EpSy+lNVUKz1bIokisaz OMYZkq3/ZNHP2PGnEH2BjOD7QIn0qivJcjgyntPxzOBY3Vgf7ZFlkTrk X-Gm-Gg: AZFdTZcLPoIZbs+XZxDfKF0IO0ogxQsyaocfOqO4gixkFEU2LrLqzKsDtetTD2NtUBs z6PUziECITU2guzW94PxdnMtzfgiSmdbbAS2yb7KVvDB2hiV90lvroFBTuFOb0rv2jjyHDc1Cwp BcfR6RED7o6F6Yx3kZn3Z3nQODZlGxP2EuD8C63AuhGcySTU/bjDQ5u8rd4hbpBFUen19+BD+4G QeMypsP3Ml5dwLilq/RuK/mBOqQ0w0whyFXy4Deve7JuBpgxJQQ6YBArons8D9jinxfUmk6P7n5 x0NJtqeyYTVQhVJh2oqCCvME4PU2tj0CIHldiUeelbjen9R9rhS7kZqOziQzvA0UeWnJgQDFafK oE9kkPNey6XaPpVBUiwczBwwlRSWjq/VNdfD14BDqNL+BZpD8X4TPdCXlG8Ob+uoF0rKwQYxZLe 7l8B2lzPFHwT2QyWzhCA+6k/iCriW/A3pSwx3JneSh59cEoo29ysFuBHJRsSF8R7D8YuQ2GkFFy GAjlaoBRML/le9ElbOzvFrfNya0v8P07kXQY2HGxhLbVYZEBcbQVzdM/HdMYcJe8YgfK4WU6P3N KmCouJ4J6ooxHXSa9DLPU43JKbbwCJQUWnHqsByrEHExihkIg8WvPNPCNza8S1ug7inkQ3roj2+ X1eyy+lR3YMFwfQKVfuCLU1Afoc3NY3CwCA4iDG19U853OwXdt1Vmd0mJGotAfdiIEOCzCP0E 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: stable@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