lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2aa5377f-23ea-44b4-a45c-7df1acb39cf0@gmail.com>
Date: Fri, 30 May 2025 19:44:05 +0100
From: Pavel Begunkov <asml.silence@...il.com>
To: Stanislav Fomichev <stfomichev@...il.com>
Cc: io-uring@...r.kernel.org, Vadim Fedorenko <vadim.fedorenko@...ux.dev>,
 netdev@...r.kernel.org, Eric Dumazet <edumazet@...gle.com>,
 Kuniyuki Iwashima <kuniyu@...zon.com>, Paolo Abeni <pabeni@...hat.com>,
 Willem de Bruijn <willemb@...gle.com>, "David S . Miller"
 <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>,
 Richard Cochran <richardcochran@...il.com>
Subject: Re: [PATCH 1/5] net: timestamp: add helper returning skb's tx tstamp

On 5/30/25 19:30, Stanislav Fomichev wrote:
> On 05/30, Stanislav Fomichev wrote:
>> On 05/30, Pavel Begunkov wrote:
>>> Add a helper function skb_get_tx_timestamp() that returns a tx timestamp
>>> associated with an skb from an queue queue.
>>>
>>> Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
>>> ---
>>>   include/net/sock.h |  4 ++++
>>>   net/socket.c       | 49 ++++++++++++++++++++++++++++++++++++++++++++++
>>>   2 files changed, 53 insertions(+)
>>>
>>> diff --git a/include/net/sock.h b/include/net/sock.h
>>> index 92e7c1aae3cc..b0493e82b6e3 100644
>>> --- a/include/net/sock.h
>>> +++ b/include/net/sock.h
>>> @@ -2677,6 +2677,10 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
>>>   void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
>>>   			     struct sk_buff *skb);
>>>   
>>> +bool skb_has_tx_timestamp(struct sk_buff *skb, struct sock *sk);
>>> +bool skb_get_tx_timestamp(struct sk_buff *skb, struct sock *sk,
>>> +			  struct timespec64 *ts);
>>> +
>>>   static inline void
>>>   sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
>>>   {
>>> diff --git a/net/socket.c b/net/socket.c
>>> index 9a0e720f0859..d1dc8ab28e46 100644
>>> --- a/net/socket.c
>>> +++ b/net/socket.c
>>> @@ -843,6 +843,55 @@ static void put_ts_pktinfo(struct msghdr *msg, struct sk_buff *skb,
>>>   		 sizeof(ts_pktinfo), &ts_pktinfo);
>>>   }
>>>   
>>> +bool skb_has_tx_timestamp(struct sk_buff *skb, struct sock *sk)
>>> +{
>>> +	u32 tsflags = READ_ONCE(sk->sk_tsflags);
>>> +	struct sock_exterr_skb *serr = SKB_EXT_ERR(skb);
>>> +
>>> +	if (serr->ee.ee_errno != ENOMSG ||
>>> +	   serr->ee.ee_origin != SO_EE_ORIGIN_TIMESTAMPING)
>>> +		return false;
>>> +
>>> +	/* software time stamp available and wanted */
>>> +	if ((tsflags & SOF_TIMESTAMPING_SOFTWARE) && skb->tstamp)
>>> +		return true;
>>> +	/* hardware time stamps available and wanted */
>>> +	return (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
>>> +		skb_hwtstamps(skb)->hwtstamp;
>>> +}
>>> +
>>> +bool skb_get_tx_timestamp(struct sk_buff *skb, struct sock *sk,
>>> +			  struct timespec64 *ts)
>>> +{
>>> +	u32 tsflags = READ_ONCE(sk->sk_tsflags);
>>> +	bool false_tstamp = false;
>>> +	ktime_t hwtstamp;
>>> +	int if_index = 0;
>>> +
>>
>> [..]
>>
>>> +	if (sock_flag(sk, SOCK_RCVTSTAMP) && skb->tstamp == 0) {
>>> +		__net_timestamp(skb);
>>> +		false_tstamp = true;
>>> +	}
>>
>> The place it was copy-pasted from (__sock_recv_timestamp) has a comment
>> about a race between packet rx and enabling the timestamp. Does the same
>> race happen here? Worth keeping the comment?

I can add the comment

> Or maybe you don't need this case at all? Since you're skipping the
> tstamp == 0 cases anyway down below... Pass 'false' to skb_is_swtx_tstamp
> instead?

__net_timestamp updates skb->tstamp, so I couldn't prove it's fine to
omit just from looking at code. But I don't know all intricacies of
timestamping, would be great someone knows a way to simplify it further.

-- 
Pavel Begunkov


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ