Re: [PATCH] net: optimize cmpxchg in ip_idents_reserve

From: Shaokun Zhang
Date: Sat Jan 18 2020 - 22:46:41 EST


Hi Peter,

On 2020/1/17 20:32, Peter Zijlstra wrote:
> On Fri, Jan 17, 2020 at 02:54:03PM +0800, Shaokun Zhang wrote:
>> So how about this? ;-)
>>
>> delta = prandom_u32_max(now - old);
>>
>> +#ifdef CONFIG_UBSAN
>> /* Do not use atomic_add_return() as it makes UBSAN unhappy */
>> + old = (u32)atomic_read(p_id);
>> do {
>> - old = (u32)atomic_read(p_id);
>> new = old + delta + segs;
>> - } while (atomic_cmpxchg(p_id, old, new) != old);
>> + } while (!atomic_try_cmpxchg(p_id, &old, new));
>> +#else
>> + new = atomic_add_return(segs + delta, p_id);
>> +#endif
>
> That's crazy, just accept that UBSAN is taking bonghits and ignore it.
> Use atomic_add_return() unconditionally.

We have used the atomic_add_return[1], but it makes the UBSAN unhappy followed
by the comment.
It seems that Eric also agreed to do it if some comments are added. I will do
it later.

Thanks,
Shaokun

[1] https://lkml.org/lkml/2019/7/26/217

>
> .
>