From patchwork Thu Sep 5 07:17:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13791827 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A2B219306B; Thu, 5 Sep 2024 07:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725520678; cv=none; b=Ip7DJeJL50VAO6zwIRULZKVqUvoeg5/NNly+rRWXUuQ06qNmpHvbqbNGYXctCEUBPn0vvIddL03OTpxhQIIkHtVPmFGfR8BAUt+DxWbVjig+7XXpzde423W0y1K5sFDdjPgeeiArBbulPjuYJGmaQmNmOC7XgQUKt8NNzFT/aZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725520678; c=relaxed/simple; bh=pm18LzKuf7Pe/TqQlkff7gRCifSAML3mIMou2tvYhtg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nfHDd8YtLdRU4Pq8oij1r8PRo02ytyCK9/JzadzAJ/SknDKpcQMYMJm1DH3a6BCCuebKnw6P61O06XInBV2SR9JH77zC2J3OD/YPQSEHQWAdXXbF3HfuD2t3iqnKBGXmMu8zGet2kmESVUqF1RRnoNcumG8b4JSNYRddQsSv7Y0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HbHlXroJ; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HbHlXroJ" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7d4f6d8c1eeso360101a12.1; Thu, 05 Sep 2024 00:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725520676; x=1726125476; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r2o2hbaaXm5/I0Rt4fzNJUxwimu3WCgjAFqRCFnWp90=; b=HbHlXroJ5YesjTJuXzLS+8kO5FARwVM4PNkyl1EUn1gJsMev2bAhqSyeYudzc2Sq6I LrIp+qJTj7vbtiCDdXy43iJuZvOKAsMYuS0ekzJJSVYxbU+iq1gaE0DyPlSQEfEe2o4v +bRhQpSOFau9NtPRwAPF5h0k/I1D7bepx89CSGbQ3XhL/7S+ViEsL/3FxlCxo/SPsW+Z Ni0aW6cAfInsIeXH4U7VYAO+XqmZbDHsihhdX6jlg2EK0eaRbyN6bRldWvVsQlH0jrjJ XsX1PAHDW1KL4ht8zwyPiJHRztA2Cv+/THpRF49K3Az6ala1f1xT7Cj9eGXrW1+8JgNZ 8eqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725520676; x=1726125476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r2o2hbaaXm5/I0Rt4fzNJUxwimu3WCgjAFqRCFnWp90=; b=Z0/OBnuZgOmbwpSspEcTzAQYs72VOthDpVRKSeZZeAv8j1Jy4JB2VYU1yzF6p/VWpE /T4JONyIARoUfkqkMiFfc5oeoYVN1kdyYZmx3q1c4Wji9416ljP3YiZqAc/SdBSlF0wF I1LE8YUuuJ8RUGQQZ41qMsIDEm/fJukMni4WuLXaNMpnEAZX5bvsXtcZGFnt3w2PNkbq GBd0Mt6W7lbvrrR5SBc1HMToVUDkW9B0R6oQp4sg9TgHljXWv/w0qTQxUFoyTV667sPc QJNpMqO+2lfrXEZywAigGND7tCMdaNCG2HNeYtjFskwsKkaILJztqr+AGEgDsxgDzrxp 1IGQ== X-Forwarded-Encrypted: i=1; AJvYcCUnO8/D3nv4jeeyBBVIdajmWqcDBBm+0EcnDML0N/yH27ryNuaswFr2p4596OnDawazNeHvMoc=@vger.kernel.org X-Gm-Message-State: AOJu0YzBpTlq6Gr460NVhY8GTVjx74bzucpBon93Jps6Gptn57BoAUJm 8lPfvFZ/cXnJvK0RD08SJriMoxB8KQSty3glsY7/YtApIgNHZj8C X-Google-Smtp-Source: AGHT+IF3P19sPUd0ouuwNRSN9DiPnMWG75Vzki1Vpej8NwUZMf3dRz+Aacb9hECi2eUzY0s1F+RbsA== X-Received: by 2002:a17:902:e804:b0:1fc:568d:5f05 with SMTP id d9443c01a7336-205472c61acmr190174145ad.8.1725520676022; Thu, 05 Sep 2024 00:17:56 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.24]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae913b19sm22929425ad.61.2024.09.05.00.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 00:17:55 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, shuah@kernel.org, willemb@google.com Cc: linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v4 1/4] net-timestamp: filter out report when setting SOF_TIMESTAMPING_SOFTWARE Date: Thu, 5 Sep 2024 15:17:34 +0800 Message-Id: <20240905071738.3725-2-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240905071738.3725-1-kerneljasonxing@gmail.com> References: <20240905071738.3725-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jason Xing introduce a new flag SOF_TIMESTAMPING_OPT_RX_FILTER in the receive path. User can set it with SOF_TIMESTAMPING_SOFTWARE to filter out rx software timestamp report, especially after a process turns on netstamp_needed_key which can time stamp every incoming skb. Previously, we found out if an application starts first which turns on netstamp_needed_key, then another one only passing SOF_TIMESTAMPING_SOFTWARE could also get rx timestamp. Now we handle this case by introducing this new flag without breaking users. Quoting Willem to explain why we need the flag: "why a process would want to request software timestamp reporting, but not receive software timestamp generation. The only use I see is when the application does request SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_TX_SOFTWARE." In this way, we have two kinds of combination: 1. setting SOF_TIMESTAMPING_SOFTWARE|SOF_TIMESTAMPING_RX_SOFTWARE, it will surely allow users to get the rx software timestamp report. 2. setting SOF_TIMESTAMPING_SOFTWARE|SOF_TIMESTAMPING_OPT_RX_FILTER while the skb is timestamped, it will stop reporting the rx software timestamp. Another thing about errqueue in this patch I have a few words to say: In this case, we need to handle the egress path carefully, or else reporting the tx timestamp will fail. Egress path and ingress path will finally call sock_recv_timestamp(). We have to distinguish them. Errqueue is a good indicator to reflect the flow direction. Suggested-by: Willem de Bruijn Reviewed-by: Willem de Bruijn Signed-off-by: Jason Xing --- v4 Link: https://lore.kernel.org/all/20240830153751.86895-2-kerneljasonxing@gmail.com/ 1. revise the commit message and doc (Willem) 2. simplify the test statement (Jakub) 3. add Willem's reviewed-by tag (Willem) v3 1. Willem suggested this alternative way to solve the issue, so I added his Suggested-by tag here. Thanks! --- Documentation/networking/timestamping.rst | 12 ++++++++++++ include/uapi/linux/net_tstamp.h | 3 ++- net/core/sock.c | 4 ++++ net/ethtool/common.c | 1 + net/ipv4/tcp.c | 6 ++++-- net/socket.c | 4 +++- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Documentation/networking/timestamping.rst b/Documentation/networking/timestamping.rst index 5e93cd71f99f..37ead02be3b1 100644 --- a/Documentation/networking/timestamping.rst +++ b/Documentation/networking/timestamping.rst @@ -266,6 +266,18 @@ SOF_TIMESTAMPING_OPT_TX_SWHW: two separate messages will be looped to the socket's error queue, each containing just one timestamp. +SOF_TIMESTAMPING_OPT_RX_FILTER: + Used in the receive software timestamp. Enabling the flag along with + SOF_TIMESTAMPING_SOFTWARE will not report the rx timestamp to the + userspace so that it can filter out the case where one process starts + first which turns on netstamp_needed_key through setting generation + flags like SOF_TIMESTAMPING_RX_SOFTWARE, then another one only passing + SOF_TIMESTAMPING_SOFTWARE report flag could also get the rx timestamp. + + SOF_TIMESTAMPING_OPT_RX_FILTER prevents the application from being + influenced by others and let the application choose whether to report + the timestamp in the receive path or not. + New applications are encouraged to pass SOF_TIMESTAMPING_OPT_ID to disambiguate timestamps and SOF_TIMESTAMPING_OPT_TSONLY to operate regardless of the setting of sysctl net.core.tstamp_allow_data. diff --git a/include/uapi/linux/net_tstamp.h b/include/uapi/linux/net_tstamp.h index a2c66b3d7f0f..858339d1c1c4 100644 --- a/include/uapi/linux/net_tstamp.h +++ b/include/uapi/linux/net_tstamp.h @@ -32,8 +32,9 @@ enum { SOF_TIMESTAMPING_OPT_TX_SWHW = (1<<14), SOF_TIMESTAMPING_BIND_PHC = (1 << 15), SOF_TIMESTAMPING_OPT_ID_TCP = (1 << 16), + SOF_TIMESTAMPING_OPT_RX_FILTER = (1 << 17), - SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_ID_TCP, + SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_RX_FILTER, SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) | SOF_TIMESTAMPING_LAST }; diff --git a/net/core/sock.c b/net/core/sock.c index 468b1239606c..6a93344e21cf 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -908,6 +908,10 @@ int sock_set_timestamping(struct sock *sk, int optname, !(val & SOF_TIMESTAMPING_OPT_ID)) return -EINVAL; + if (val & SOF_TIMESTAMPING_RX_SOFTWARE && + val & SOF_TIMESTAMPING_OPT_RX_FILTER) + return -EINVAL; + if (val & SOF_TIMESTAMPING_OPT_ID && !(sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID)) { if (sk_is_tcp(sk)) { diff --git a/net/ethtool/common.c b/net/ethtool/common.c index 781834ef57c3..6c245e59bbc1 100644 --- a/net/ethtool/common.c +++ b/net/ethtool/common.c @@ -427,6 +427,7 @@ const char sof_timestamping_names[][ETH_GSTRING_LEN] = { [const_ilog2(SOF_TIMESTAMPING_OPT_TX_SWHW)] = "option-tx-swhw", [const_ilog2(SOF_TIMESTAMPING_BIND_PHC)] = "bind-phc", [const_ilog2(SOF_TIMESTAMPING_OPT_ID_TCP)] = "option-id-tcp", + [const_ilog2(SOF_TIMESTAMPING_OPT_RX_FILTER)] = "option-rx-filter", }; static_assert(ARRAY_SIZE(sof_timestamping_names) == __SOF_TIMESTAMPING_CNT); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 8a5680b4e786..a0c57c8b77bd 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,15 @@ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, } } - if (READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_SOFTWARE) + if (tsflags & SOF_TIMESTAMPING_SOFTWARE && + !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER)) 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}; diff --git a/net/socket.c b/net/socket.c index fcbdd5bc47ac..f8609d649ed3 100644 --- a/net/socket.c +++ b/net/socket.c @@ -946,7 +946,9 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, memset(&tss, 0, sizeof(tss)); tsflags = READ_ONCE(sk->sk_tsflags); - if ((tsflags & SOF_TIMESTAMPING_SOFTWARE) && + if ((tsflags & SOF_TIMESTAMPING_SOFTWARE && + (skb_is_err_queue(skb) || + !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER))) && ktime_to_timespec64_cond(skb->tstamp, tss.ts + 0)) empty = 0; if (shhwtstamps && From patchwork Thu Sep 5 07:17:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13791828 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0498119309E; Thu, 5 Sep 2024 07:17:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725520681; cv=none; b=a1vn5acZvMvZ5YCJcO+edLifHMHb9WXHB7TfHcGbQy8eUU/5OajV4bIyVJqRjbSASGNSRoWBHB78nFlkF6z0sGewysqfTMa2ObN0aVfNy7dn24cuZDbVg/ij+2ajRGdi8HbynlO3fkonSR9OfXWanEPGTGU4fGRDcejHNGoDL1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725520681; c=relaxed/simple; bh=qjn4bYpnc3sdB2QTbr7U3+e4e+QlFCoBLwCKFutGSVE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yb9wwchRtKavg+h84q14b4sYIvP6xKwOA8lCImXo0JatmymVesvXtVCEAOKoDxvc0itnwS4ziX1DhMR+bc5H7Urm4CZSTymhaQYAuPaSDkkk8HEaGsTyDBAgejW63DTAwf2SYU96jeO1zVm1ZCGhwuw8GjXx7rW0a0aqOHZQmj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=U4nZNeru; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U4nZNeru" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-205722ba00cso4512025ad.0; Thu, 05 Sep 2024 00:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725520679; x=1726125479; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jP3RiSVA2PzoQSWjpyM3hUS+f8SmsdBGbkZ90Q8ikY0=; b=U4nZNeru592GjvnP2oAh5Xzxvf/bpfdf5DAkRxT8soksrVHj7CRPgZtoryiC29bnmi dCpCf2iV/2Kgn2D5Ju+ByxUaoasl+FvWwdwCH23U3eT7mWnFCC84EfO7X8uQRg0j8RHA 1VDVe0oyfYh7E6H0Ng/N6FXS9HwUQi+P/10R7E4xrlOxYALXX0EwULwpitIdSC8RH0Jr xZGzrTJ/9wrj3ZeuRTWhFhjnCiy07YkzJizWN4hN1kaJGKoVyC7D8dyohkbCRCkM9kzR Y+erZJ7YYN9sIqcgjs+vsUDg0PesN6yOI6HXo4hYSFlHz7iAStrGFbzGVGl9hcvdnL3J 7nmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725520679; x=1726125479; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jP3RiSVA2PzoQSWjpyM3hUS+f8SmsdBGbkZ90Q8ikY0=; b=qxw49t/ncdU7hVFZ9lAQgTdSo/dCyliJ41QAuEg+AgMTjLwGH0tf0IEU8tRSdD/kYI C+YiZ/ZPOfCsA5xpp6HxkxFDwHUfJFuDIPu/S2FhDB0kwyjedGKNRwCJVI5obGjy5HlX P7R+d3JUjAg5DqGo0uovZF5C3M/kKuUfQttewnOsaUj2/NCYoOsvM2Yre0q6f/f02lRj NkqsRbieK29f8uaO+zftmJpURIfI7c/AvEyFhgZl56djE8D4Ucb3M3IbmwW04SrjqfKU ELJIkJfGEuIZo4v8K1R50ZLJgKtrEitjYqsTJHuTF4WNH09o6QyxSTbUsK5vrFS0CIDR 804g== X-Forwarded-Encrypted: i=1; AJvYcCV/q3uZv8nTDZw+1l0AAc1jrr9bYLgDDILJeeJxEzij0nqweE76ElosWSi9s7r91Rk8zrFkdo4=@vger.kernel.org X-Gm-Message-State: AOJu0Yype0n+99i0ZV/AV/aIvCXMTIuzliLlm5Qsz9tU9DJ0/pltVW1q 5Culew3n3F6oCyolDzHMAp9bgBMXksNtahcQxrrftBw18HGAf5TcpzGApX33gnw= X-Google-Smtp-Source: AGHT+IGpTNYT3PgXESdKWr8uWYHWixR/xmlPHfz5UsODqIeJ+yKPOCbBCML/deqDNf8frtm7lFiacg== X-Received: by 2002:a17:902:ce85:b0:205:9112:efee with SMTP id d9443c01a7336-2059112f162mr111327415ad.21.1725520679034; Thu, 05 Sep 2024 00:17:59 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.24]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae913b19sm22929425ad.61.2024.09.05.00.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 00:17:58 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, shuah@kernel.org, willemb@google.com Cc: linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v4 2/4] net-timestamp: correct the use of SOF_TIMESTAMPING_RAW_HARDWARE Date: Thu, 5 Sep 2024 15:17:35 +0800 Message-Id: <20240905071738.3725-3-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240905071738.3725-1-kerneljasonxing@gmail.com> References: <20240905071738.3725-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jason Xing SOF_TIMESTAMPING_RAW_HARDWARE is a report flag which passes the timestamps generated by either SOF_TIMESTAMPING_TX_HARDWARE or SOF_TIMESTAMPING_RX_HARDWARE to the userspace all the time. So let us revise the doc here. Suggested-by: Willem de Bruijn Signed-off-by: Jason Xing Reviewed-by: Willem de Bruijn --- Link: https://lore.kernel.org/all/66d8c21d3042a_163d93294cb@willemb.c.googlers.com.notmuch/ --- Documentation/networking/timestamping.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/timestamping.rst b/Documentation/networking/timestamping.rst index 37ead02be3b1..ac57d9de2f11 100644 --- a/Documentation/networking/timestamping.rst +++ b/Documentation/networking/timestamping.rst @@ -158,7 +158,8 @@ SOF_TIMESTAMPING_SYS_HARDWARE: SOF_TIMESTAMPING_RAW_HARDWARE: Report hardware timestamps as generated by - SOF_TIMESTAMPING_TX_HARDWARE when available. + SOF_TIMESTAMPING_TX_HARDWARE or SOF_TIMESTAMPING_RX_HARDWARE + when available. 1.3.3 Timestamp Options From patchwork Thu Sep 5 07:17:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13791829 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD42719309E; Thu, 5 Sep 2024 07:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725520684; cv=none; b=R2L3qv0qOQr8NqUk3iOsXpbLN6Zqf7LZL2e/Qrt3ZPH06+ZcrsC8LJHYU6ebDSOWGrEG0jJWvPJ1eT/xxV0jBRno+F13L/BB8bwRKQe0zdM1sa9dE9BX12BBtFeloiBVjVchIxPVIosyYVTOdzX/koYpvXU/Bmq5hm5EAialx/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725520684; c=relaxed/simple; bh=e5eurefDLwBpTLCJOcGL3UM1sOupQSYqKp6w3ch8OjA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YFTY9zJFu066A/S1z1A98bLAC/czBmqpJue014TjZj1mCBCqif4JjY1GVTTsP9ZombTT6jg6UsCD8wFdY4coc9nX0Oz8c9ftSxHjg4DL+EyiVbkiiaPuCAVN5TtoydKdnKwy+cPyRfc/IVhU1pZDjKUIwsPL8lO1ONanXjPAN5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=B3t8QCWZ; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B3t8QCWZ" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-714226888dfso365181b3a.1; Thu, 05 Sep 2024 00:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725520682; x=1726125482; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UjT0OS+OKNHcBBxpm+XNUrjLujslH+p3LNsUZFLQoW8=; b=B3t8QCWZjs8UUZ1H6u91xH9YKXfmZ732m1NFHEegVYlElL2e+dt7K4GYPh2TLWGNyK gwn88VwGBBVURhGMktBCXJtJrvaLF3cYoKI3ElBcidJnodNI2oalNgklvlsrnFbT9sBl +QbHNjejEYpwElxSBM+FJfgcSBqHL+UTaK6oy40N9g9gF8TKuobvnMknTFIRwEYsaMnk ySz8FjkN+eocez+rAX/+Ftn1KyBZxBLEj2HvXm9PCyL32aIsHccDNjV5iBj99ee5AEaU ivZ1UgjgIhRSHfol0Yb5RgpGSHeQ6p9tCTdpa8yELYk+gqDgS1KNxnW7Ry850JzITAOx BBGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725520682; x=1726125482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UjT0OS+OKNHcBBxpm+XNUrjLujslH+p3LNsUZFLQoW8=; b=Nf6W9HFjr8f0mhPsRVDIsCAdfBEHlRyfhTEfOCVBkI8fM7vpmBwmTW3srYbEAsr9vJ r5PgaEm80roEmCKPfrr2AkTui4Z+1qOm7JlVTOsJrAPPkCw61DZfYyoONoXKxdf9t+so it++9YZdvG1VfKnUZFdpWnTIamz5Qec9daMMXJaujIoeUSMJJRk2Fc0nJ3mmt/N5I/K7 Clu6t9xLfX7ewCOhKRAWaFhinzJMiH56XR7daQ6nbVe3RSDh1iD8S0H85nK+D8dJ5TN8 2nb2ANdhx3XwARtkQPq04oNbKFPjOgA3Nsjejjc8uj/+F7raEJHZmoNIcGr/04SsIllN 7tzw== X-Forwarded-Encrypted: i=1; AJvYcCW99gWhbNQY2hS83unDyKcmrtHcvux6CpoTOl5101y+J4q3EzPsElfWjqxoidPi6gCQY/wtC9M=@vger.kernel.org X-Gm-Message-State: AOJu0YyiFI56eqg714YUyzknZaFAZ+y+RBoD4Tm8qE8Cq1N4vKT8zGZA CD9BsKlbhb+dlPrfTE6f6bBfO/nmWoAZVgJpBwgPwaz5Bd8TwQ9b X-Google-Smtp-Source: AGHT+IH2AyA8kWz7CrbTl/ZEYI/tNCmZX+hDCLZw6KsewAB6lN5rO8IFQigMHVIFo+pB214du9i4tg== X-Received: by 2002:a05:6a21:3a87:b0:1ce:db9e:6ea0 with SMTP id adf61e73a8af0-1cedb9e6f70mr15656388637.19.1725520682108; Thu, 05 Sep 2024 00:18:02 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.24]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae913b19sm22929425ad.61.2024.09.05.00.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 00:18:01 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, shuah@kernel.org, willemb@google.com Cc: linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v4 3/4] net-timestamp: extend SOF_TIMESTAMPING_OPT_RX_FILTER for hardware use Date: Thu, 5 Sep 2024 15:17:36 +0800 Message-Id: <20240905071738.3725-4-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240905071738.3725-1-kerneljasonxing@gmail.com> References: <20240905071738.3725-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jason Xing In the previous patch, we found things could happen in the rx software timestamp. Here, we also noticed that, for rx hardware timestamp case, it could happen when one process enables the rx hardware timestamp generating flag first, then another process only setting SOF_TIMESTAMPING_RAW_HARDWARE report flag can still get the hardware timestamp. In this patch, we extend the OPT_RX_FILTER flag to filter out the above case for hardware use. Suggested-by: Jakub Kicinski Signed-off-by: Jason Xing --- Link: https://lore.kernel.org/all/20240903121940.6390b958@kernel.org/ --- Documentation/networking/timestamping.rst | 15 +++++++++------ net/core/sock.c | 5 +++-- net/ipv4/tcp.c | 3 ++- net/socket.c | 3 ++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Documentation/networking/timestamping.rst b/Documentation/networking/timestamping.rst index ac57d9de2f11..55e79ea71f3e 100644 --- a/Documentation/networking/timestamping.rst +++ b/Documentation/networking/timestamping.rst @@ -268,12 +268,15 @@ SOF_TIMESTAMPING_OPT_TX_SWHW: each containing just one timestamp. SOF_TIMESTAMPING_OPT_RX_FILTER: - Used in the receive software timestamp. Enabling the flag along with - SOF_TIMESTAMPING_SOFTWARE will not report the rx timestamp to the - userspace so that it can filter out the case where one process starts - first which turns on netstamp_needed_key through setting generation - flags like SOF_TIMESTAMPING_RX_SOFTWARE, then another one only passing - SOF_TIMESTAMPING_SOFTWARE report flag could also get the rx timestamp. + Used in the receive software/hardware timestamp. Enabling the flag + along with SOF_TIMESTAMPING_SOFTWARE/SOF_TIMESTAMPING_RAW_HARDWARE + will not report the rx timestamp to the userspace so that it can + filter out the cases where 1) one process starts first which turns + on netstamp_needed_key through setting generation flags like + SOF_TIMESTAMPING_RX_SOFTWARE, or 2) similarly one process enables + generating the hardware timestamp already, then another one only + passing SOF_TIMESTAMPING_SOFTWARE report flag could also get the + rx timestamp. SOF_TIMESTAMPING_OPT_RX_FILTER prevents the application from being influenced by others and let the application choose whether to report diff --git a/net/core/sock.c b/net/core/sock.c index 6a93344e21cf..dc4a43cfff59 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -908,8 +908,9 @@ int sock_set_timestamping(struct sock *sk, int optname, !(val & SOF_TIMESTAMPING_OPT_ID)) return -EINVAL; - if (val & SOF_TIMESTAMPING_RX_SOFTWARE && - val & SOF_TIMESTAMPING_OPT_RX_FILTER) + if (val & SOF_TIMESTAMPING_OPT_RX_FILTER && + (val & SOF_TIMESTAMPING_RX_SOFTWARE || + val & SOF_TIMESTAMPING_RX_HARDWARE)) return -EINVAL; if (val & SOF_TIMESTAMPING_OPT_ID && diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index a0c57c8b77bd..23f0722aa801 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2283,7 +2283,8 @@ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk, } if (tss->ts[2].tv_sec || tss->ts[2].tv_nsec) { - if (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) + if (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE && + !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER)) has_timestamping = true; else tss->ts[2] = (struct timespec64) {0}; diff --git a/net/socket.c b/net/socket.c index f8609d649ed3..bfbae2069fbb 100644 --- a/net/socket.c +++ b/net/socket.c @@ -952,7 +952,8 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, ktime_to_timespec64_cond(skb->tstamp, tss.ts + 0)) empty = 0; if (shhwtstamps && - (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) && + (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE && + !(tsflags & SOF_TIMESTAMPING_OPT_RX_FILTER)) && !skb_is_swtx_tstamp(skb, false_tstamp)) { if_index = 0; if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP_NETDEV) From patchwork Thu Sep 5 07:17:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Xing X-Patchwork-Id: 13791830 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B91B8193075; Thu, 5 Sep 2024 07:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725520687; cv=none; b=OHhi9WCRJhVAQWA7ufg8gsVcIXqMlt5YWyfMvGDo17nLb6f51hFfCvGeSkVi8Le3WbvqBvPxF7dIv2Ug8izfuSXxDl/szC+a8uOVjUU+W7VLLsR7MGv2zwW61ReN6tNO0rsDYZcv4DYpIatehs1V+XAkpzq8KUCH03IIUuw+OaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725520687; c=relaxed/simple; bh=QnK91DuJeGoRFoqM9GpuoJH5kC8osPkheLOM+tzeYmw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K12YIx1A0vy4hA6I5/Bb2nvoMeWcZENxRaUMMqYQUw2bBtqm1v3X/Sym+6lhSML0JBBSbZ/Cq7W+3EhwfP4sgiptiL+WPB+OPzOlkqM8pYkyqAnc9+CaGKfHHy92cshOXqvEt+AzTCrneThXN7DxWbFOe3ndAHpdM7HWuIpqDmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LBnL9IaC; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LBnL9IaC" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2054feabfc3so4676095ad.1; Thu, 05 Sep 2024 00:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725520685; x=1726125485; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3nOX2YMvtf/OrIDC6qncA+oTCXoL26pma70Wab3JtoU=; b=LBnL9IaCw80Su8YdDjNqPpmGN5fhojg4YsLen6mQqQw3l7/+SopMvRbk665ZBJYNlj gSYh8prZYrOmbUy9szRqHYSbXMvIbdZtJmjqP+hJ8Tt4VDX093Yu77oOE7Hq37c0+3xk Rxg3bL+QnpnMPIAyN+QhLMVmpU0c1SjFfgaMZWxQtlEngLuURh5pbo1gvr6ppwx1Qgix qtDuIVhpVgOpSlFOgGgH5/Ym/P2b46yLzzEkaJdYlEduyU813VxEWGwt+hsFXQeLGllj vgZjXtZm3A1XLj+dBN1Igr7XG5cJ5VS+ScjaBievlQigHtDcOC4fIJmIEkOO+GQVi6Kp nlMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725520685; x=1726125485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3nOX2YMvtf/OrIDC6qncA+oTCXoL26pma70Wab3JtoU=; b=YR/n6uIquAuIgHSKrdq3S4y9vdwggvOO8vo+ScM9hIE6Vh5nUYQ+J+PTu6cOFVsexC Eze33tBNzkdkAgslxUHbvf4U6DPofAGFR8Gn7PDya1Szb75WCMheZcni+09uk482VXyH 8aL311JHgYEcLv8mTaCPMlHDzEySIjwt9IornEFjyvm+nIRiiIe+BjtqA7csPPMW8Ymj GSxrS2hcetuxiHnCmnRo+LZnNtiGqjyqTvCwmR/R9ZQyBMRCE+9qRdlsBjC4J23ZWPYe b3Ieh/FqKyVCmBaEjYHXHlRw2MwN56Zl9Bl6G8BD5ed29Dnvxnkm2G9NJM+fwOpog++M tiVw== X-Forwarded-Encrypted: i=1; AJvYcCUZ+3ISfaljsR13xljxasSwKqeIkcXcVbykTlZsCArQH/VafDQVs24NhA4OHH6hN/w46yNR2dc=@vger.kernel.org X-Gm-Message-State: AOJu0YzwjgT/9/YssLRhhawrpO9uuXx94fm4JVw08ntQOqNr1uWRj4aq L/eke55ISoeaa8HgUlF7j+yz4KV3DDlHU0dz+ztisKoETTfj+7bO X-Google-Smtp-Source: AGHT+IGfKXNaQsFQrovWzbgLjoQs7RD65xHlqTQBOlsXCiB0U+VGNJNZGDu709if11WU3Y08pXCw3A== X-Received: by 2002:a17:902:e74e:b0:206:bbaa:84e7 with SMTP id d9443c01a7336-206bbaa92afmr53884455ad.40.1725520685001; Thu, 05 Sep 2024 00:18:05 -0700 (PDT) Received: from KERNELXING-MB0.tencent.com ([43.132.141.24]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae913b19sm22929425ad.61.2024.09.05.00.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 00:18:04 -0700 (PDT) From: Jason Xing To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, willemdebruijn.kernel@gmail.com, shuah@kernel.org, willemb@google.com Cc: linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Jason Xing Subject: [PATCH net-next v4 4/4] rxtimestamp.c: add the test for SOF_TIMESTAMPING_OPT_RX_FILTER Date: Thu, 5 Sep 2024 15:17:37 +0800 Message-Id: <20240905071738.3725-5-kerneljasonxing@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240905071738.3725-1-kerneljasonxing@gmail.com> References: <20240905071738.3725-1-kerneljasonxing@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jason Xing Test when we use SOF_TIMESTAMPING_OPT_RX_FILTER with software or hardware report flag. The expected result is no rx timestamp report. Reviewed-by: Willem de Bruijn Signed-off-by: Jason Xing --- tools/testing/selftests/net/rxtimestamp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/testing/selftests/net/rxtimestamp.c b/tools/testing/selftests/net/rxtimestamp.c index 9eb42570294d..9760abdb6e05 100644 --- a/tools/testing/selftests/net/rxtimestamp.c +++ b/tools/testing/selftests/net/rxtimestamp.c @@ -57,6 +57,7 @@ static struct sof_flag sof_flags[] = { SOF_FLAG(SOF_TIMESTAMPING_SOFTWARE), SOF_FLAG(SOF_TIMESTAMPING_RX_SOFTWARE), SOF_FLAG(SOF_TIMESTAMPING_RX_HARDWARE), + SOF_FLAG(SOF_TIMESTAMPING_OPT_RX_FILTER), }; static struct socket_type socket_types[] = { @@ -97,6 +98,16 @@ static struct test_case test_cases[] = { | SOF_TIMESTAMPING_RX_HARDWARE }, {} }, + { + { .so_timestamping = SOF_TIMESTAMPING_RAW_HARDWARE + | SOF_TIMESTAMPING_OPT_RX_FILTER }, + {} + }, + { + { .so_timestamping = SOF_TIMESTAMPING_SOFTWARE + | SOF_TIMESTAMPING_OPT_RX_FILTER }, + {} + }, { { .so_timestamping = SOF_TIMESTAMPING_SOFTWARE | SOF_TIMESTAMPING_RX_SOFTWARE },