Skip to contentSkip to conversation

net-timestamp: support TCP GSO case for a few missing flags

PATCH Superseded Jason Xing 2 participants 6 messages Feb 28, 2025 – Mar 3, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jason Xing

author
#0 lore raw

PATCH 1/1 net-timestamp: support TCP GSO case for a few missing flags

When I read through the TSO codes, I found out that we probably miss initializing the tx_flags of last seg when TSO is turned off, which means at the following points no more timestamp (for this last one) will be generated. There are three flags to be handled in this patch:
1. SKBTX_HW_TSTAMP
2. SKBTX_HW_TSTAMP_USE_CYCLES
3. SKBTX_BPF

This patch initializes the tx_flags to SKBTX_ANY_TSTAMP like what the UDP GSO does. But flag like SKBTX_SCHED_TSTAMP is not useful and will not be used in the remaining path since the skb has already passed the QDisc layer.

---
 net/ipv4/tcp_offload.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
net/ipv4/tcp_offload.c +7 -4
index 2308665b51c5..886582002425 100644
@@ -13,12 +13,15 @@
 #include <net/tcp.h>
 #include <net/protocol.h>
 
-static void tcp_gso_tstamp(struct sk_buff *skb, unsigned int ts_seq,
+static void tcp_gso_tstamp(struct sk_buff *skb, struct sk_buff *gso_skb,
 			   unsigned int seq, unsigned int mss)
 {
+	u32 flags = skb_shinfo(gso_skb)->tx_flags & SKBTX_ANY_TSTAMP;
+	u32 ts_seq = skb_shinfo(gso_skb)->tskey;
+
 	while (skb) {
 		if (before(ts_seq, seq + mss)) {
-			skb_shinfo(skb)->tx_flags |= SKBTX_SW_TSTAMP;
+			skb_shinfo(skb)->tx_flags |= flags;
 			skb_shinfo(skb)->tskey = ts_seq;
 			return;
 		}
@@ -193,8 +196,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
 	th = tcp_hdr(skb);
 	seq = ntohl(th->seq);
 
-	if (unlikely(skb_shinfo(gso_skb)->tx_flags & SKBTX_SW_TSTAMP))
-		tcp_gso_tstamp(segs, skb_shinfo(gso_skb)->tskey, seq, mss);
+	if (unlikely(skb_shinfo(gso_skb)->tx_flags & (SKBTX_ANY_TSTAMP)))
+		tcp_gso_tstamp(segs, gso_skb, seq, mss);
 
 	newcheck = ~csum_fold(csum_add(csum_unfold(th->check), delta));
 
Signature · 1 line
2.43.5
#1 lore raw
Quoted 3 lines · Jason Xing

When I read through the TSO codes, I found out that we probably miss initializing the tx_flags of last seg when TSO is turned off,

When falling back onto TCP GSO. Good catch.

This is a fix, so should target net?

Quoted 5 lines

which means at the following points no more timestamp (for this last one) will be generated. There are three flags to be handled in this patch:
1. SKBTX_HW_TSTAMP
2. SKBTX_HW_TSTAMP_USE_CYCLES

Nit: this no longer exists

(But it will affect the upcoming completion timestamp.)

Quoted 6 lines

3. SKBTX_BPF

This patch initializes the tx_flags to SKBTX_ANY_TSTAMP like what the UDP GSO does. But flag like SKBTX_SCHED_TSTAMP is not useful and will not be used in the remaining path since the skb has already passed the QDisc layer.

Unless multiple layers of qdiscs (e.g., bonding or tunneling) and GSO is applied on the first layer, and SKBTX_SW_TSTAMP is not requested. But SCHED without SW is an unlikely configuration

Probably best to just drop this.

Quoted 29 lines
---
 net/ipv4/tcp_offload.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
net/ipv4/tcp_offload.c +5 -2
index 2308665b51c5..886582002425 100644
@@ -13,12 +13,15 @@
 #include <net/tcp.h>
 #include <net/protocol.h>
 
-static void tcp_gso_tstamp(struct sk_buff *skb, unsigned int ts_seq,
+static void tcp_gso_tstamp(struct sk_buff *skb, struct sk_buff *gso_skb,
 			   unsigned int seq, unsigned int mss)
 {
+	u32 flags = skb_shinfo(gso_skb)->tx_flags & SKBTX_ANY_TSTAMP;
+	u32 ts_seq = skb_shinfo(gso_skb)->tskey;
+
 	while (skb) {
 		if (before(ts_seq, seq + mss)) {
-			skb_shinfo(skb)->tx_flags |= SKBTX_SW_TSTAMP;
+			skb_shinfo(skb)->tx_flags |= flags;
 			skb_shinfo(skb)->tskey = ts_seq;
 			return;
 		}

net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 199

Quoted 6 lines
net/ipv4/tcp_offload.c +1 -2
@@ -193,8 +196,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
 	th = tcp_hdr(skb);
 	seq = ntohl(th->seq);
 
-	if (unlikely(skb_shinfo(gso_skb)->tx_flags & SKBTX_SW_TSTAMP))
-		tcp_gso_tstamp(segs, skb_shinfo(gso_skb)->tskey, seq, mss);
+	if (unlikely(skb_shinfo(gso_skb)->tx_flags & (SKBTX_ANY_TSTAMP)))

no need for the extra parentheses

Quoted 7 lines
net/ipv4/tcp_offload.c +1 -0
+		tcp_gso_tstamp(segs, gso_skb, seq, mss);
 
 	newcheck = ~csum_fold(csum_add(csum_unfold(th->check), delta));
 
Signature · 1 line
2.43.5
author
#2 lore raw
Quoted 9 lines · Willem de Bruijn
Quoted 3 lines · Jason Xing

When I read through the TSO codes, I found out that we probably miss initializing the tx_flags of last seg when TSO is turned off,

When falling back onto TCP GSO. Good catch.

This is a fix, so should target net?

After seeing your comment below, I'm not sure if the next version targets the net branch because SKBTX_BPF flag is not in the net branch.

If target net-net tree, I would add the following:

Fixes 6b98ec7e882af ("bpf: Add BPF_SOCK_OPS_TSTAMP_SCHED_CB callback")
Fixes 4ed2d765dfacc ("net-timestamp: TCP timestamping")
Quoted 8 lines
Quoted 6 lines

which means at the following points no more timestamp (for this last one) will be generated. There are three flags to be handled in this patch:
1. SKBTX_HW_TSTAMP
2. SKBTX_HW_TSTAMP_USE_CYCLES

Nit: this no longer exists

Right, I wrote on the old branch, sorry.

Quoted 10 lines

(But it will affect the upcoming completion timestamp.)

Quoted 6 lines

3. SKBTX_BPF

This patch initializes the tx_flags to SKBTX_ANY_TSTAMP like what the UDP GSO does. But flag like SKBTX_SCHED_TSTAMP is not useful and will not be used in the remaining path since the skb has already passed the QDisc layer.

Quoted 4 lines

Unless multiple layers of qdiscs (e.g., bonding or tunneling) and GSO is applied on the first layer, and SKBTX_SW_TSTAMP is not requested. But SCHED without SW is an unlikely configuration Probably best to just drop this.

Got it. I will remove this description.

Quoted 33 lines
Quoted 33 lines
---
 net/ipv4/tcp_offload.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
net/ipv4/tcp_offload.c +5 -2
index 2308665b51c5..886582002425 100644
@@ -13,12 +13,15 @@
 #include <net/tcp.h>
 #include <net/protocol.h>
 
-static void tcp_gso_tstamp(struct sk_buff *skb, unsigned int ts_seq,
+static void tcp_gso_tstamp(struct sk_buff *skb, struct sk_buff *gso_skb,
                         unsigned int seq, unsigned int mss)
 {
+     u32 flags = skb_shinfo(gso_skb)->tx_flags & SKBTX_ANY_TSTAMP;
+     u32 ts_seq = skb_shinfo(gso_skb)->tskey;
+
      while (skb) {
              if (before(ts_seq, seq + mss)) {
-                     skb_shinfo(skb)->tx_flags |= SKBTX_SW_TSTAMP;
+                     skb_shinfo(skb)->tx_flags |= flags;
                      skb_shinfo(skb)->tskey = ts_seq;
                      return;
              }
@@ -193,8 +196,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
      th = tcp_hdr(skb);
      seq = ntohl(th->seq);
 
Quoted 5 lines

net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 199

Quoted 3 lines
net/ipv4/tcp_offload.c +1 -2
-     if (unlikely(skb_shinfo(gso_skb)->tx_flags & SKBTX_SW_TSTAMP))
-             tcp_gso_tstamp(segs, skb_shinfo(gso_skb)->tskey, seq, mss);
+     if (unlikely(skb_shinfo(gso_skb)->tx_flags & (SKBTX_ANY_TSTAMP)))

no need for the extra parentheses

Will correct it.

Thank for the review,
Jason

Quoted 10 lines
Quoted 8 lines
net/ipv4/tcp_offload.c +1 -1
+             tcp_gso_tstamp(segs, gso_skb, seq, mss);
 
      newcheck = ~csum_fold(csum_add(csum_unfold(th->check), delta));
 
--

2.43.5

#3 lore raw
Quoted 8 lines · Jason Xing
Quoted 6 lines · Willem de Bruijn
Quoted 3 lines · Jason Xing

When I read through the TSO codes, I found out that we probably miss initializing the tx_flags of last seg when TSO is turned off,

Quoted 6 lines
Quoted 3 lines

When falling back onto TCP GSO. Good catch.

This is a fix, so should target net?

After seeing your comment below, I'm not sure if the next version targets the net branch because SKBTX_BPF flag is not in the net branch.

HWTSTAMP is sufficient reason

Quoted 3 lines

If target net-net tree, I would add the following:

Fixes 6b98ec7e882af ("bpf: Add BPF_SOCK_OPS_TSTAMP_SCHED_CB callback")
Fixes 4ed2d765dfacc ("net-timestamp: TCP timestamping")

Please only add one Fixes tag. In this case 4ed2d765dfacc

author
#4 lore raw
Quoted 10 lines · Willem de Bruijn
Quoted 8 lines · Jason Xing
Quoted 6 lines · Willem de Bruijn
Quoted 3 lines · Jason Xing

When I read through the TSO codes, I found out that we probably miss initializing the tx_flags of last seg when TSO is turned off,

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

When falling back onto TCP GSO. Good catch.

This is a fix, so should target net?

After seeing your comment below, I'm not sure if the next version targets the net branch because SKBTX_BPF flag is not in the net branch.

HWTSTAMP is sufficient reason

Got it.

Quoted 6 lines
Quoted 4 lines

If target net-net tree, I would add the following:

Fixes 6b98ec7e882af ("bpf: Add BPF_SOCK_OPS_TSTAMP_SCHED_CB callback")
Fixes 4ed2d765dfacc ("net-timestamp: TCP timestamping")

Please only add one Fixes tag. In this case 4ed2d765dfacc

Okay, I will do it as you said.

Sorry to ask one more thing: should I mention SKBTX_BPF in the commit message like "...SKBTX_BPF for now is only net-next material, but it can be fixed by this patch as well"? I'm not sure if it's allowed to say like that since we target the net branch.

Thanks,
Jason

#5 lore raw
Quoted 28 lines · Jason Xing
Quoted 10 lines · Willem de Bruijn
Quoted 8 lines · Jason Xing
Quoted 6 lines · Willem de Bruijn
Quoted 3 lines · Jason Xing

When I read through the TSO codes, I found out that we probably miss initializing the tx_flags of last seg when TSO is turned off,

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

When falling back onto TCP GSO. Good catch.

This is a fix, so should target net?

After seeing your comment below, I'm not sure if the next version targets the net branch because SKBTX_BPF flag is not in the net branch.

HWTSTAMP is sufficient reason

Got it.

Quoted 5 lines
Quoted 4 lines

If target net-net tree, I would add the following:

Fixes 6b98ec7e882af ("bpf: Add BPF_SOCK_OPS_TSTAMP_SCHED_CB callback")
Fixes 4ed2d765dfacc ("net-timestamp: TCP timestamping")
Quoted 8 lines
Quoted 1 line

Please only add one Fixes tag. In this case 4ed2d765dfacc

Okay, I will do it as you said.

Sorry to ask one more thing: should I mention SKBTX_BPF in the commit message like "...SKBTX_BPF for now is only net-next material, but it can be fixed by this patch as well"? I'm not sure if it's allowed to say like that since we target the net branch.

Absolutely fine. That is relevant information.