From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from www2881.sakura.ne.jp (www2881.sakura.ne.jp [49.212.198.91]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76C1B3C0607 for ; Wed, 29 Apr 2026 09:16:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=49.212.198.91 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777454211; cv=none; b=TqE0OVL+24vZ/C/+pDixwLf62h90UIMcmu8YnFGENBBMi3+UeBwEu8PYFfNGogn8hC1ldPbI7gUKlpGpaXffCjsLgiGvPB+p3ce6XkDm1ykNf7V6LIRrbbAQZvsaOzQUd5R7+GVi1Lgri0dYurYOpuJPArYOpw3PBeIHAMxBPbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777454211; c=relaxed/simple; bh=jooEF0Q2ODBHr+EeWZk3cn58gUgpPnmfj/zlBZ4xAes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GCT+pwDVGN0l/hc1RfL902MMSLE5wJY+Avt1oqkh20wlC6IOxslwC0WJsFaVAlzhmvB9NRke8CePN1v6HZVSpoi81TpH7KjcTAMayUDurZU27rge1aQ00gC0U/NJJP5gEEtCo6xE5DRjav0BuxUR1t8VMSKhPr/mtXFBwGLyb8g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=enjuk.jp; spf=pass smtp.mailfrom=enjuk.jp; dkim=pass (2048-bit key) header.d=enjuk.jp header.i=@enjuk.jp header.b=rQEhSziT; arc=none smtp.client-ip=49.212.198.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=enjuk.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=enjuk.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=enjuk.jp header.i=@enjuk.jp header.b="rQEhSziT" Received: from ms-a2 (197.87.13.160.dy.iij4u.or.jp [160.13.87.197]) (authenticated bits=0) by www2881.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 63T9Gl79043858 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 29 Apr 2026 18:16:47 +0900 (JST) (envelope-from kohei@enjuk.jp) DKIM-Signature: a=rsa-sha256; bh=VNsqaO4VKM8duP7X8u8FBpIkMOKyeVk0AVzZrcnvqQk=; c=relaxed/relaxed; d=enjuk.jp; h=From:Message-ID:To:Subject:Date; s=rs20251215; t=1777454208; v=1; b=rQEhSziTaV0FBpgEarw4ucX8bjV0NzKD6QXkBZ5aqUTVRatvlFm0OtMQc44rgxUJ 0qPPxlKIL+tX1tAbZHE0CyWNZeijJUmKb1/4PGO01THNbf7tSzRn8dnE29JjzbEE J8KOn0wM4y8IDRxwCvrYoyNB61hwQ6+XgV+MaRfLTqltIPfqSF3SgfIXeLdKOkBw hMxHM45BCjQ4QHIQ2gB6BHsQPIG9ah5a4XP6j1PW6rs58UMGp1ZvmpfAR8noozkT jHHNHh7HfEhsdgjNG/p8z054cAMN0CzvpdGWCVNnDwDgZ3C+XTLweTmQT1NTrg0v kgU2YZZPMvtWSmLryHzKVA== From: Kohei Enju To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Kuniyuki Iwashima , Willem de Bruijn , David Ahern , Neal Cardwell , Gerhard Engleder , Jonathan Lemon , Richard Cochran , Kohei Enju Subject: [PATCH net v1 3/3] tcp: use skb_get_hwtstamp() for hardware timestamps Date: Wed, 29 Apr 2026 09:16:19 +0000 Message-ID: <20260429091632.26509-4-kohei@enjuk.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260429091632.26509-1-kohei@enjuk.jp> References: <20260429091632.26509-1-kohei@enjuk.jp> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Additionally, recognize SKBTX_HW_TSTAMP_NETDEV as indicating a receive timestamp is present. 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 --- 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