Subject: Re: [PATCH net-next v2 1/2] net_tstamp: add SCM_TS_OPT_ID to provide OPT_ID in control message

From: Vadim Fedorenko <[email-masked]>
Date: Mon, 2 Sep 2024 20:35:26 +0100

On 02/09/2024 19:38, Simon Horman wrote:
> On Mon, Sep 02, 2024 at 06:09:35AM -0700, Vadim Fedorenko wrote:
>> SOF_TIMESTAMPING_OPT_ID socket option flag gives a way to correlate TX
>> timestamps and packets sent via socket. Unfortunately, there is no way
>> to reliably predict socket timestamp ID value in case of error returned
>> by sendmsg. For UDP sockets it's impossible because of lockless
>> nature of UDP transmit, several threads may send packets in parallel. In
>> case of RAW sockets MSG_MORE option makes things complicated. More
>> details are in the conversation [1].
>> This patch adds new control message type to give user-space
>> software an opportunity to control the mapping between packets and
>> values by providing ID with each sendmsg. This works fine for UDP
>> sockets only, and explicit check is added to control message parser.
>>
>> [1] https://lore.kernel.org/netdev/[email-masked]/
>>
>> Signed-off-by: Vadim Fedorenko <[email-masked]>
> 
> ...
> 
>> diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
> 
> ...
> 
>> @@ -1543,10 +1546,15 @@ static int __ip6_append_data(struct sock *sk,
>>   			flags &= ~MSG_SPLICE_PAGES;
>>   	}
>>   
>> -	hold_tskey = cork->tx_flags & SKBTX_ANY_TSTAMP &&
>> -		     READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_OPT_ID;
>> -	if (hold_tskey)
>> -		tskey = atomic_inc_return(&sk->sk_tskey) - 1;
>> +	if (cork->tx_flags & SKBTX_ANY_TSTAMP &&
>> +	    READ_ONCE(sk->sk_tsflags) & SOF_TIMESTAMPING_OPT_ID) {
>> +		if (cork->flags & IPCORK_TS_OPT_ID) {
>> +			tskey = cork->ts_opt_id;
>> +		} else {
>> +			tskey = atomic_inc_return(&sk->sk_tskey) - 1;
>> +			hold_tskey = true;
> 
> Hi Vadim,
> 
> I think that hold_tskey also needs to be assigned a value in
> the cases where wither of the if conditions above are false.

Hi Simon!

Yes, you are right. I should probably init it with false to avoid
'else' statement.

Thanks,
Vadim

> Flagged by Smatch.
> 
>> +		}
>> +	}
>>   
>>   	/*
>>   	 * Let's try using as much space as possible.
>