From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9718F1F0089C; Mon, 30 Nov 2026 19:53:15 +0000 (UTC) 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== From: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= To: Jason Xing , willemb@google.com, magnus.karlsson@intel.com, maciej.fijalkowski@intel.com, sdf@fomichev.me, 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: Re: [PATCH net v3 2/2] xsk: fill in header offsets for TX checksum offload In-Reply-To: <20261129111056.11124-3-kerneljasonxing@gmail.com> References: <20261129111056.11124-1-kerneljasonxing@gmail.com> <20261129111056.11124-3-kerneljasonxing@gmail.com> Date: Mon, 30 Nov 2026 20:53:12 +0100 Message-ID: <87tskyyu3b.fsf@all.your.base.are.belong.to.us> 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-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Jason Xing 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 suppo= rt") > 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 @@ >=20=20 > #define pr_fmt(fmt) "AF_XDP: %s: " fmt, __func__ >=20=20 > +#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; > } >=20=20 > -static int xsk_skb_sw_csum(struct sk_buff *skb, struct xsk_buff_pool *po= ol) > +static int xsk_skb_csum(struct sk_buff *skb, struct xsk_buff_pool *pool) > { > - if (unlikely(pool->tx_sw_csum && > - skb->ip_summed =3D=3D CHECKSUM_PARTIAL)) > + struct ethhdr eth_buf, *eth; > + int nhoff =3D ETH_HLEN; > + unsigned int l3_min; > + __be16 proto; > + > + if (unlikely(skb->ip_summed !=3D CHECKSUM_PARTIAL)) > + return 0; > + > + if (unlikely(pool->tx_sw_csum)) > return skb_checksum_help(skb); >=20=20 > + if (unlikely(skb->dev->type !=3D ARPHRD_ETHER)) > + return 0; > + > + eth =3D skb_header_pointer(skb, 0, sizeof(*eth), ð_buf); > + if (unlikely(!eth)) > + return 0; > + > + proto =3D eth->h_proto; > + if (eth_type_vlan(proto)) { > + proto =3D __vlan_get_protocol(skb, proto, &nhoff); > + if (unlikely(!proto)) > + return 0; > + } > + > + switch (proto) { > + case htons(ETH_P_IP): > + l3_min =3D sizeof(struct iphdr); > + break; > + case htons(ETH_P_IPV6): > + l3_min =3D sizeof(struct ipv6hdr); > + break; > + default: > + return 0; > + } > + > + if (unlikely(skb_checksum_start_offset(skb) < nhoff + l3_min)) > + return 0; > + > + skb->protocol =3D 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=C3=B6rn