On Thu, Dec 3, 2026 at 8:05 PM Björn Töpel <bjo…@kernel.org> wrote:
>
> Jason Xing <kern…@gmail.com> 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. 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/arKm…@boxer/
> >
> > Fixes: 48eb03dd2630 ("xsk: Add TX timestamp and TX checksum offload support")
> > Cc: stab…@vger.kernel.org # depends on "net: reset the mac header in __dev_direct_xmit()"
> > Suggested-by: Maciej Fijalkowski <maci…@intel.com>
> > Signed-off-by: Jason Xing <kern…@gmail.com>
>
> Thanks, Jason! The skb path is... tricky. :-)
>
> Reviewed-by: Björn Töpel <bjo…@kernel.org>
Thanks for the review :)