Skip to content

Commit a6211ca

Browse files
yuqijin16davem330
authored andcommitted
net: revert "net: get rid of an signed integer overflow in ip_idents_reserve()"
Commit adb0311 ("net: get rid of an signed integer overflow in ip_idents_reserve()") used atomic_cmpxchg to replace "atomic_add_return" inside the function "ip_idents_reserve". The reason was to avoid UBSAN warning. However, this change has caused performance degrade and in GCC-8, fno-strict-overflow is now mapped to -fwrapv -fwrapv-pointer and signed integer overflow is now undefined by default at all optimization levels[1]. Moreover, it was a bug in UBSAN vs -fwrapv /-fno-strict-overflow, so Let's revert it safely. [1] https://gcc.gnu.org/gcc-8/changes.html Suggested-by: Peter Zijlstra <peterz@infradead.org> Suggested-by: Eric Dumazet <edumazet@google.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org> Cc: Jakub Kicinski <kuba@kernel.org> Cc: Jiri Pirko <jiri@resnulli.us> Cc: Arvind Sankar <nivedita@alum.mit.edu> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Eric Dumazet <edumazet@google.com> Cc: Jiong Wang <jiongwang@huawei.com> Signed-off-by: Yuqi Jin <jinyuqi@huawei.com> Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 61d0301 commit a6211ca

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

net/ipv4/route.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,18 +491,16 @@ u32 ip_idents_reserve(u32 hash, int segs)
491491
atomic_t *p_id = ip_idents + hash % IP_IDENTS_SZ;
492492
u32 old = READ_ONCE(*p_tstamp);
493493
u32 now = (u32)jiffies;
494-
u32 new, delta = 0;
494+
u32 delta = 0;
495495

496496
if (old != now && cmpxchg(p_tstamp, old, now) == old)
497497
delta = prandom_u32_max(now - old);
498498

499-
/* Do not use atomic_add_return() as it makes UBSAN unhappy */
500-
do {
501-
old = (u32)atomic_read(p_id);
502-
new = old + delta + segs;
503-
} while (atomic_cmpxchg(p_id, old, new) != old);
504-
505-
return new - segs;
499+
/* If UBSAN reports an error there, please make sure your compiler
500+
* supports -fno-strict-overflow before reporting it that was a bug
501+
* in UBSAN, and it has been fixed in GCC-8.
502+
*/
503+
return atomic_add_return(segs + delta, p_id) - segs;
506504
}
507505
EXPORT_SYMBOL(ip_idents_reserve);
508506

0 commit comments

Comments
 (0)