Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] tcp: preserve timestamps across receive queue collapse
@ 2026-09-17 13:27 Jason Xing
  2026-09-17 14:09 ` Xuanqiang Luo
  2026-09-21 15:34 ` netdev-bot+sashiko
  0 siblings, 2 replies; 5+ messages in thread
From: Jason Xing @ 2026-09-17 13:27 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, horms, willemb, kuniyu; +Cc: netdev, Jason Xing

When tcp_collapse() rebuilds skbs under memory pressure, the copy
process doesn't include the right tstamp and hwtstamp from the
old skb. And memcpy(nskb->cb, skb->cb, ...) copies has_rxtstamp,
but nskb->tstamp and hwtstamps are left at zero, so
tcp_recv_timestamp() ends up emitting no cmsg at all.

In net timestamping case, if such an skb happens to be the last
one consumed in a recvmsg() call, the application receives no RX
timestamp for that call.

Fix this by copying both tstamp and hwtstamp to the new skb right
after the initialization.

Fixes: 98aaa913b4ed ("tcp: Extend SOF_TIMESTAMPING_RX_SOFTWARE to TCP recvmsg")
Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
---
V2
Link: https://lore.kernel.org/all/20260916124153.43457-1-kerneljasonxing@gmail.com/
1. add one sentence in commit log from Eric's reply
2. use the same semantic as tcp_add_backlog which is to sync the
   last skb (Eric)
---
 net/ipv4/tcp_input.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 0f60a1dbf927..81d587654d3d 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -5854,6 +5854,12 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
 				if (skb_copy_bits(skb, offset, skb_put(nskb, size), size))
 					BUG();
 				TCP_SKB_CB(nskb)->end_seq += size;
+				if (TCP_SKB_CB(skb)->has_rxtstamp) {
+					TCP_SKB_CB(nskb)->has_rxtstamp = true;
+					nskb->tstamp = skb->tstamp;
+					skb_hwtstamps(nskb)->hwtstamp =
+						skb_hwtstamps(skb)->hwtstamp;
+				}
 				copy -= size;
 				start += size;
 			}
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-24 14:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 13:27 [PATCH net v2] tcp: preserve timestamps across receive queue collapse Jason Xing
2026-09-17 14:09 ` Xuanqiang Luo
2026-09-21 15:34 ` netdev-bot+sashiko
2026-09-21 15:47   ` Eric Dumazet
2026-09-24 14:33     ` Jason Xing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox