Re: [PATCH net v3 1/2] xsk: defer software checksum until the skb is complete

From
Jason Xing <hidden>
Date
2026-10-30 02:30:40
Also in
bpf, lkml, stable
Reply to
Rongzheng Wang, 2026-10-28
On Wed, Oct 28, 2026 at 10:50 AM Rongzheng Wang [off-list ref] wrote:
When XDP_UMEM_TX_SW_CSUM is used with multi-buffer TX, xsk_skb_metadata()
calls skb_checksum_help() while only the first descriptor has been added to
the skb. The checksum therefore covers just the first fragment, and
skb_checksum_help() sets ip_summed to CHECKSUM_NONE, so the remaining
fragments are never included in the checksum.

Move the software checksum calculation to the point where the last
descriptor has been added to the skb.

On a checksum failure the packet is now dropped instead of being returned
to the application for a retry. This path is not reachable with the
existing metadata validation, but the behavior change is intentional.

Fixes: 11614723af26 ("xsk: Add option to calculate TX checksum in SW")
Cc: <redacted>
Signed-off-by: Rongzheng Wang <redacted>
Reviewed-by: Jason Xing <redacted>
quoted hunk ↗ jump to hunk
---
 net/xdp/xsk.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 33475b180ea6..aa6b010192ad 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -1011,14 +1011,6 @@ static int xsk_skb_metadata(struct sk_buff *skb, void *buffer,
                skb->csum_start = hr + csum_start;
                skb->csum_offset = csum_offset;
                skb->ip_summed = CHECKSUM_PARTIAL;
-
-               if (unlikely(pool->tx_sw_csum)) {
-                       int err;
-
-                       err = skb_checksum_help(skb);
-                       if (err)
-                               return err;
-               }
        }

        if (flags & XDP_TXMD_FLAGS_LAUNCH_TIME)
@@ -1030,6 +1022,15 @@ 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)
+{
+       if (unlikely(pool->tx_sw_csum &&
+                    skb->ip_summed == CHECKSUM_PARTIAL))
+               return skb_checksum_help(skb);
+
+       return 0;
+}
+
 static struct sk_buff *xsk_build_skb_zerocopy(struct xdp_sock *xs,
                                              struct xdp_desc *desc)
 {
@@ -1275,6 +1276,12 @@ static int __xsk_generic_xmit(struct sock *sk)
                if (xp_mb_desc(&desc)) {
                        xs->skb = skb;
                        continue;
nit: since we have 'continue' here.
+               } else {
How about removing the 'else' branch to avoid unnecessary indentation?

Thanks,
Jason
+                       err = xsk_skb_sw_csum(skb, xs->pool);
+                       if (unlikely(err)) {
+                               xsk_drop_skb(skb);
+                               goto out;
+                       }
                }

                err = __dev_direct_xmit(skb, xs->queue_id);
--
2.39.5 (Apple Git-154)
Thread (9 messages) 9 messages, 4 authors, last reply 5d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help