* [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
@ 2026-09-24 15:25 Jason Xing
2026-09-29 23:53 ` Jakub Kicinski
2026-09-30 21:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 9+ messages in thread
From: Jason Xing @ 2026-09-24 15:25 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 of the last skb to
the new skb, matching tcp_try_coalesce()/tcp_add_backlog().
Note that the has_rxtstamp flag can still be inherited through
the cb memcpy from an skb that contributes no bytes (fully covered
skb left in the ofo tree by the tcp_ooo_try_coalesce() ->
coalesce_done path), so set TCP_SKB_CB(nskb)->has_rxtstamp to false
which makes the new block the only place setting it.
Fixes: 98aaa913b4ed ("tcp: Extend SOF_TIMESTAMPING_RX_SOFTWARE to TCP recvmsg")
Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
---
V3
Link: https://lore.kernel.org/all/20260917132742.87117-1-kerneljasonxing@gmail.com/
1. revise the commit message with more accurate description (Eric)
2. fix a corner case (where a skb can contribute no bytes if OOO happens)
spotted by AI and Eric
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 | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 92bc60716f33..f58954ddecee 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -5834,6 +5834,7 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
break;
memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
+ TCP_SKB_CB(nskb)->has_rxtstamp = false;
skb_copy_decrypted(nskb, skb);
TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(nskb)->end_seq = start;
if (list)
@@ -5854,6 +5855,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.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
2026-09-24 15:25 [PATCH v3 net] tcp: preserve timestamps across receive queue collapse Jason Xing
@ 2026-09-29 23:53 ` Jakub Kicinski
2026-09-29 23:54 ` Jakub Kicinski
2026-09-30 21:00 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2026-09-29 23:53 UTC (permalink / raw)
To: edumazet; +Cc: Jason Xing, davem, pabeni, horms, willemb, kuniyu, netdev
On Thu, 24 Sep 2026 23:25:29 +0800 Jason Xing wrote:
> 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 of the last skb to
> the new skb, matching tcp_try_coalesce()/tcp_add_backlog().
>
> Note that the has_rxtstamp flag can still be inherited through
> the cb memcpy from an skb that contributes no bytes (fully covered
> skb left in the ofo tree by the tcp_ooo_try_coalesce() ->
> coalesce_done path), so set TCP_SKB_CB(nskb)->has_rxtstamp to false
> which makes the new block the only place setting it.
>
> Fixes: 98aaa913b4ed ("tcp: Extend SOF_TIMESTAMPING_RX_SOFTWARE to TCP recvmsg")
> Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
> ---
> V3
> Link: https://lore.kernel.org/all/20260917132742.87117-1-kerneljasonxing@gmail.com/
> 1. revise the commit message with more accurate description (Eric)
> 2. fix a corner case (where a skb can contribute no bytes if OOO happens)
> spotted by AI and Eric
Looks good now, Eric?
https://lore.kernel.org/all/20260924152529.5689-1-kerneljasonxing@gmail.com/
(Jason, please see net for the up-to-date email addr for Eric)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
2026-09-29 23:53 ` Jakub Kicinski
@ 2026-09-29 23:54 ` Jakub Kicinski
2026-09-30 1:53 ` Jason Xing
0 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2026-09-29 23:54 UTC (permalink / raw)
To: edumazet; +Cc: Jason Xing, davem, pabeni, horms, willemb, kuniyu, netdev
On Tue, 29 Sep 2026 16:53:18 -0700 Jakub Kicinski wrote:
> On Thu, 24 Sep 2026 23:25:29 +0800 Jason Xing wrote:
> > 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 of the last skb to
> > the new skb, matching tcp_try_coalesce()/tcp_add_backlog().
> >
> > Note that the has_rxtstamp flag can still be inherited through
> > the cb memcpy from an skb that contributes no bytes (fully covered
> > skb left in the ofo tree by the tcp_ooo_try_coalesce() ->
> > coalesce_done path), so set TCP_SKB_CB(nskb)->has_rxtstamp to false
> > which makes the new block the only place setting it.
> >
> > Fixes: 98aaa913b4ed ("tcp: Extend SOF_TIMESTAMPING_RX_SOFTWARE to TCP recvmsg")
> > Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
> > ---
> > V3
> > Link: https://lore.kernel.org/all/20260917132742.87117-1-kerneljasonxing@gmail.com/
> > 1. revise the commit message with more accurate description (Eric)
> > 2. fix a corner case (where a skb can contribute no bytes if OOO happens)
> > spotted by AI and Eric
>
> Looks good now, Eric?
> https://lore.kernel.org/all/20260924152529.5689-1-kerneljasonxing@gmail.com/
>
> (Jason, please see net for the up-to-date email addr for Eric)
I meant to also say - I'm leaning towards net-next on this one.
Please LMK if you disagree
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
2026-09-29 23:54 ` Jakub Kicinski
@ 2026-09-30 1:53 ` Jason Xing
2026-09-30 1:56 ` Jason Xing
2026-09-30 2:19 ` Jakub Kicinski
0 siblings, 2 replies; 9+ messages in thread
From: Jason Xing @ 2026-09-30 1:53 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: edumazet, davem, pabeni, horms, willemb, kuniyu, netdev
On Wed, Sep 30, 2026 at 7:54 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Tue, 29 Sep 2026 16:53:18 -0700 Jakub Kicinski wrote:
> > On Thu, 24 Sep 2026 23:25:29 +0800 Jason Xing wrote:
> > > 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 of the last skb to
> > > the new skb, matching tcp_try_coalesce()/tcp_add_backlog().
> > >
> > > Note that the has_rxtstamp flag can still be inherited through
> > > the cb memcpy from an skb that contributes no bytes (fully covered
> > > skb left in the ofo tree by the tcp_ooo_try_coalesce() ->
> > > coalesce_done path), so set TCP_SKB_CB(nskb)->has_rxtstamp to false
> > > which makes the new block the only place setting it.
> > >
> > > Fixes: 98aaa913b4ed ("tcp: Extend SOF_TIMESTAMPING_RX_SOFTWARE to TCP recvmsg")
> > > Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
> > > ---
> > > V3
> > > Link: https://lore.kernel.org/all/20260917132742.87117-1-kerneljasonxing@gmail.com/
> > > 1. revise the commit message with more accurate description (Eric)
> > > 2. fix a corner case (where a skb can contribute no bytes if OOO happens)
> > > spotted by AI and Eric
> >
> > Looks good now, Eric?
> > https://lore.kernel.org/all/20260924152529.5689-1-kerneljasonxing@gmail.com/
> >
> > (Jason, please see net for the up-to-date email addr for Eric)
Will do.
>
> I meant to also say - I'm leaning towards net-next on this one.
> Please LMK if you disagree
I'm okay with net-next. Seems like I need to repost.
Thanks,
Jason
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
2026-09-30 1:53 ` Jason Xing
@ 2026-09-30 1:56 ` Jason Xing
2026-09-30 2:19 ` Jakub Kicinski
1 sibling, 0 replies; 9+ messages in thread
From: Jason Xing @ 2026-09-30 1:56 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: edumazet, davem, pabeni, horms, willemb, kuniyu, netdev
On Wed, Sep 30, 2026 at 9:53 AM Jason Xing <kerneljasonxing@gmail.com> wrote:
>
> On Wed, Sep 30, 2026 at 7:54 AM Jakub Kicinski <kuba@kernel.org> wrote:
> >
> > On Tue, 29 Sep 2026 16:53:18 -0700 Jakub Kicinski wrote:
> > > On Thu, 24 Sep 2026 23:25:29 +0800 Jason Xing wrote:
> > > > 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 of the last skb to
> > > > the new skb, matching tcp_try_coalesce()/tcp_add_backlog().
> > > >
> > > > Note that the has_rxtstamp flag can still be inherited through
> > > > the cb memcpy from an skb that contributes no bytes (fully covered
> > > > skb left in the ofo tree by the tcp_ooo_try_coalesce() ->
> > > > coalesce_done path), so set TCP_SKB_CB(nskb)->has_rxtstamp to false
> > > > which makes the new block the only place setting it.
> > > >
> > > > Fixes: 98aaa913b4ed ("tcp: Extend SOF_TIMESTAMPING_RX_SOFTWARE to TCP recvmsg")
> > > > Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
> > > > ---
> > > > V3
> > > > Link: https://lore.kernel.org/all/20260917132742.87117-1-kerneljasonxing@gmail.com/
> > > > 1. revise the commit message with more accurate description (Eric)
> > > > 2. fix a corner case (where a skb can contribute no bytes if OOO happens)
> > > > spotted by AI and Eric
> > >
> > > Looks good now, Eric?
> > > https://lore.kernel.org/all/20260924152529.5689-1-kerneljasonxing@gmail.com/
> > >
> > > (Jason, please see net for the up-to-date email addr for Eric)
>
> Will do.
>
> >
> > I meant to also say - I'm leaning towards net-next on this one.
> > Please LMK if you disagree
>
> I'm okay with net-next. Seems like I need to repost.
And it also seems unnecessary to carry the Fixes tag in V4, but I will
mention this commit in the message.
Thanks,
Jason
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
2026-09-30 1:53 ` Jason Xing
2026-09-30 1:56 ` Jason Xing
@ 2026-09-30 2:19 ` Jakub Kicinski
2026-09-30 6:35 ` Eric Dumazet
1 sibling, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2026-09-30 2:19 UTC (permalink / raw)
To: Jason Xing; +Cc: edumazet, davem, pabeni, horms, willemb, kuniyu, netdev
On Wed, 30 Sep 2026 09:53:11 +0800 Jason Xing wrote:
> > I meant to also say - I'm leaning towards net-next on this one.
> > Please LMK if you disagree
>
> I'm okay with net-next. Seems like I need to repost.
No need to repost.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
2026-09-30 2:19 ` Jakub Kicinski
@ 2026-09-30 6:35 ` Eric Dumazet
2026-09-30 6:37 ` Eric Dumazet
0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2026-09-30 6:35 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: Jason Xing, davem, pabeni, horms, willemb, kuniyu, netdev
On Wed, Sep 30, 2026 at 4:19 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 30 Sep 2026 09:53:11 +0800 Jason Xing wrote:
> > > I meant to also say - I'm leaning towards net-next on this one.
> > > Please LMK if you disagree
> >
> > I'm okay with net-next. Seems like I need to repost.
>
> No need to repost.
Sorry for missing this v2, LGTM, thanks!
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
2026-09-30 6:35 ` Eric Dumazet
@ 2026-09-30 6:37 ` Eric Dumazet
0 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2026-09-30 6:37 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: Jason Xing, davem, pabeni, horms, willemb, kuniyu, netdev
On Wed, Sep 30, 2026 at 8:35 AM Eric Dumazet <edumazet@kernel.org> wrote:
> Sorry for missing this v2, LGTM, thanks!
Well this was V3, and net-next is fine by me.
>
> Reviewed-by: Eric Dumazet <edumazet@kernel.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 net] tcp: preserve timestamps across receive queue collapse
2026-09-24 15:25 [PATCH v3 net] tcp: preserve timestamps across receive queue collapse Jason Xing
2026-09-29 23:53 ` Jakub Kicinski
@ 2026-09-30 21:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-30 21:00 UTC (permalink / raw)
To: Jason Xing; +Cc: davem, edumazet, kuba, pabeni, horms, willemb, kuniyu, netdev
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 24 Sep 2026 23:25:29 +0800 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [v3,net] tcp: preserve timestamps across receive queue collapse
https://git.kernel.org/netdev/net-next/c/1a924ab28fb5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-09-30 21:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-24 15:25 [PATCH v3 net] tcp: preserve timestamps across receive queue collapse Jason Xing
2026-09-29 23:53 ` Jakub Kicinski
2026-09-29 23:54 ` Jakub Kicinski
2026-09-30 1:53 ` Jason Xing
2026-09-30 1:56 ` Jason Xing
2026-09-30 2:19 ` Jakub Kicinski
2026-09-30 6:35 ` Eric Dumazet
2026-09-30 6:37 ` Eric Dumazet
2026-09-30 21:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox