From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Kohei Enju <kohei@enjuk.jp>, netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Kuniyuki Iwashima <kuniyu@google.com>,
Willem de Bruijn <willemb@google.com>,
David Ahern <dsahern@kernel.org>,
Neal Cardwell <ncardwell@google.com>,
Gerhard Engleder <gerhard@engleder-embedded.com>,
Jonathan Lemon <jonathan.lemon@gmail.com>,
Richard Cochran <richardcochran@gmail.com>,
Kohei Enju <kohei@enjuk.jp>
Subject: Re: [PATCH net v1 3/3] tcp: use skb_get_hwtstamp() for hardware timestamps
Date: Wed, 29 Apr 2026 17:09:07 -0400 [thread overview]
Message-ID: <willemdebruijn.kernel.2345608a210cc@gmail.com> (raw)
In-Reply-To: <20260429091632.26509-4-kohei@enjuk.jp>
Kohei Enju wrote:
> Since commit 97dc7cd92ac6 ("ptp: Support late timestamp determination"),
> skb_shared_hwtstamps may contain netdev_data instead of hwtstamp. TCP
> receive timestamping can then interpret the stored value as a ktime_t
> and report bogus hardware timestamps to userspace.
>
> Use skb_get_hwtstamp() instead of reading hwtstamp directly, so TCP
> sockets follow the same hardware timestamp resolution path as the socket
> layer. When coalescing SKBs, resolve late timestamps before copying them
> to the merged skb.
Why? Does this preclude supporting SOF_TIMESTAMPING_BIND_PHC for such
sockets at a later time?
It is just as easy to coalesce the cookie as the htwtstamp.
That also avoids the need to mask out SKBTX_HW_TSTAMP_NETDEV.
> Additionally, recognize SKBTX_HW_TSTAMP_NETDEV as
> indicating a receive timestamp is present.
What is the reason for this extra condition?
> Note that skb_get_hwtstamp() is called with cycles == false, since TCP
> hasn't honored SOF_TIMESTAMPING_BIND_PHC so far, and this patch doesn't
> change that behavior.
>
> Fixes: 97dc7cd92ac6 ("ptp: Support late timestamp determination")
> Signed-off-by: Kohei Enju <kohei@enjuk.jp>
> ---
> include/net/tcp.h | 2 +-
> net/ipv4/tcp_input.c | 3 ++-
> net/ipv4/tcp_ipv4.c | 6 ++++--
> net/ipv6/tcp_ipv6.c | 3 ++-
> 4 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index ecbadcb3a744..7b5fcee97079 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -524,7 +524,7 @@ tcp_update_recv_tstamps(struct sk_buff *skb,
> struct scm_timestamping_internal *tss)
> {
> tss->ts[0] = skb->tstamp;
> - tss->ts[2] = skb_hwtstamps(skb)->hwtstamp;
> + tss->ts[2] = skb_get_hwtstamp(skb, false, NULL);
> }
>
> void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk,
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index d5c9e65d9760..9fd473559b58 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -5237,7 +5237,8 @@ static bool tcp_try_coalesce(struct sock *sk,
> if (TCP_SKB_CB(from)->has_rxtstamp) {
> TCP_SKB_CB(to)->has_rxtstamp = true;
> to->tstamp = from->tstamp;
> - skb_hwtstamps(to)->hwtstamp = skb_hwtstamps(from)->hwtstamp;
> + skb_hwtstamps(to)->hwtstamp = skb_get_hwtstamp(from, false, NULL);
> + skb_shinfo(to)->tx_flags &= ~SKBTX_HW_TSTAMP_NETDEV;
> }
>
> return true;
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index 8fc24c3743c5..c35d82317764 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -1993,7 +1993,8 @@ enum skb_drop_reason tcp_add_backlog(struct sock *sk, struct sk_buff *skb)
> if (TCP_SKB_CB(skb)->has_rxtstamp) {
> TCP_SKB_CB(tail)->has_rxtstamp = true;
> tail->tstamp = skb->tstamp;
> - skb_hwtstamps(tail)->hwtstamp = skb_hwtstamps(skb)->hwtstamp;
> + skb_hwtstamps(tail)->hwtstamp = skb_get_hwtstamp(skb, false, NULL);
> + skb_shinfo(tail)->tx_flags &= ~SKBTX_HW_TSTAMP_NETDEV;
> }
>
> /* Not as strict as GRO. We only need to carry mss max value */
> @@ -2062,7 +2063,8 @@ static void tcp_v4_fill_cb(struct sk_buff *skb, const struct iphdr *iph,
> TCP_SKB_CB(skb)->ip_dsfield = ipv4_get_dsfield(iph);
> TCP_SKB_CB(skb)->sacked = 0;
> TCP_SKB_CB(skb)->has_rxtstamp =
> - skb->tstamp || skb_hwtstamps(skb)->hwtstamp;
> + skb->tstamp || skb_hwtstamps(skb)->hwtstamp ||
> + (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP_NETDEV);
> }
>
> /*
> diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
> index 2c3f7a739709..3361ed7f94de 100644
> --- a/net/ipv6/tcp_ipv6.c
> +++ b/net/ipv6/tcp_ipv6.c
> @@ -1704,7 +1704,8 @@ static void tcp_v6_fill_cb(struct sk_buff *skb, const struct ipv6hdr *hdr,
> TCP_SKB_CB(skb)->ip_dsfield = ipv6_get_dsfield(hdr);
> TCP_SKB_CB(skb)->sacked = 0;
> TCP_SKB_CB(skb)->has_rxtstamp =
> - skb->tstamp || skb_hwtstamps(skb)->hwtstamp;
> + skb->tstamp || skb_hwtstamps(skb)->hwtstamp ||
> + (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP_NETDEV);
> }
>
> INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-04-29 21:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 9:16 [PATCH net v1 0/3] af_packet/tcp: fix late hardware timestamp handling Kohei Enju
2026-04-29 9:16 ` [PATCH net v1 1/3] net: introduce helper to resolve hardware timestamps from skb Kohei Enju
2026-04-29 21:04 ` Willem de Bruijn
2026-04-30 4:50 ` Kohei Enju
2026-05-01 20:25 ` Gerhard Engleder
2026-04-29 9:16 ` [PATCH net v1 2/3] af_packet: use skb_get_hwtstamp() for hardware timestamps Kohei Enju
2026-04-29 9:16 ` [PATCH net v1 3/3] tcp: " Kohei Enju
2026-04-29 21:09 ` Willem de Bruijn [this message]
2026-04-30 5:07 ` Kohei Enju
2026-04-30 6:09 ` Eric Dumazet
2026-04-30 6:52 ` Kohei Enju
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=willemdebruijn.kernel.2345608a210cc@gmail.com \
--to=willemdebruijn.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=gerhard@engleder-embedded.com \
--cc=horms@kernel.org \
--cc=jonathan.lemon@gmail.com \
--cc=kohei@enjuk.jp \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox