From: Jason Xing <kerneljasonxing@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, dsahern@kernel.org, willemb@google.com
Cc: netdev@vger.kernel.org, Jason Xing <kernelxing@tencent.com>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Subject: [PATCH net-next v2 1/2] tcp: make SOF_TIMESTAMPING_RX_SOFTWARE feature per socket
Date: Thu, 29 Aug 2024 00:01:44 +0800 [thread overview]
Message-ID: <20240828160145.68805-2-kerneljasonxing@gmail.com> (raw)
In-Reply-To: <20240828160145.68805-1-kerneljasonxing@gmail.com>
From: Jason Xing <kernelxing@tencent.com>
Normally, if we want to record and print the rx timestamp after
tcp_recvmsg_locked(), we must enable both SOF_TIMESTAMPING_SOFTWARE
and SOF_TIMESTAMPING_RX_SOFTWARE flags, from which we also can notice
through running rxtimestamp binary in selftests (see testcase 7).
However, there is one particular case that fails the selftests with
"./rxtimestamp: Expected swtstamp to not be set." error printing in
testcase 6.
How does it happen? When we keep running a thread starting a socket
and set SOF_TIMESTAMPING_RX_SOFTWARE option first, then running
./rxtimestamp, it will fail. The reason is the former thread
switching on netstamp_needed_key that makes the feature global,
every skb going through netif_receive_skb_list_internal() function
will get a current timestamp in net_timestamp_check(). So the skb
will have timestamp regardless of whether its socket option has
SOF_TIMESTAMPING_RX_SOFTWARE or not.
After this patch, we can pass the selftest and control each socket
as we want when using rx timestamp feature.
Cc: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
net/ipv4/tcp.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 8514257f4ecd..5e88c765b9a1 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2235,6 +2235,7 @@ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk,
struct scm_timestamping_internal *tss)
{
int new_tstamp = sock_flag(sk, SOCK_TSTAMP_NEW);
+ u32 tsflags = READ_ONCE(sk->sk_tsflags);
bool has_timestamping = false;
if (tss->ts[0].tv_sec || tss->ts[0].tv_nsec) {
@@ -2274,14 +2275,20 @@ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk,
}
}
- if (READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_SOFTWARE)
+ /* We have to use the generation flag here to test if we
+ * allow the corresponding application to receive the rx
+ * timestamp. Only using report flag does not hold for
+ * receive timestamping case.
+ */
+ if (tsflags & SOF_TIMESTAMPING_SOFTWARE &&
+ tsflags & SOF_TIMESTAMPING_RX_SOFTWARE)
has_timestamping = true;
else
tss->ts[0] = (struct timespec64) {0};
}
if (tss->ts[2].tv_sec || tss->ts[2].tv_nsec) {
- if (READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_RAW_HARDWARE)
+ if (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE)
has_timestamping = true;
else
tss->ts[2] = (struct timespec64) {0};
--
2.37.3
next prev parent reply other threads:[~2024-08-28 16:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-28 16:01 [PATCH net-next v2 0/2] timestamp: control SOF_TIMESTAMPING_RX_SOFTWARE feature per socket Jason Xing
2024-08-28 16:01 ` Jason Xing [this message]
2024-08-29 14:16 ` [PATCH net-next v2 1/2] tcp: make " Willem de Bruijn
2024-08-29 15:34 ` Jason Xing
2024-08-28 16:01 ` [PATCH net-next v2 2/2] net: " Jason Xing
2024-08-29 10:02 ` Jason Xing
2024-08-29 14:21 ` Willem de Bruijn
2024-08-29 15:38 ` Jason Xing
2024-08-29 19:29 ` Jakub Kicinski
2024-08-30 0:40 ` Jason Xing
2024-08-30 2:14 ` Jakub Kicinski
2024-08-29 14:14 ` [PATCH net-next v2 0/2] timestamp: control " Willem de Bruijn
2024-08-29 15:27 ` Jason Xing
2024-08-29 16:23 ` Willem de Bruijn
2024-08-29 17:45 ` Jason Xing
2024-08-29 18:15 ` Willem de Bruijn
2024-08-29 18:31 ` Jason Xing
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=20240828160145.68805-2-kerneljasonxing@gmail.com \
--to=kerneljasonxing@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kernelxing@tencent.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.