From a5f32c14829c2cf52ffe8a2c25fd5e089c254d9c Mon Sep 17 00:00:00 2001 From: xuanzhuo Date: Mon, 13 Apr 2020 19:48:55 +0800 Subject: [PATCH 0869/2944] alinux: Revert "net: get rid of an signed integer overflow in ip_idents_reserve()" fix #24463023 This reverts commit adb03115f4590baa280ddc440a8eff08a6be0cb7. Related Links: https://lkml.org/lkml/2019/7/24/243 https://lore.kernel.org/lkml/b0160f4b-b996-b0ee-405a-3d5f1866272e@gmail.com/ https://lore.kernel.org/lkml/20181101172739.GA3196@hirez.programming.kicks-ass.net/ test methods: 1. add dummy net dev. "ip link add pps_dummy0 type dummy" 2. set the dummy dev with addr 10.10.10.1 3. send numerous udp packets to 10.10.10.2(fake addr) by dummy dev test command: sockperf tp -m 14 -t 20 --mps=max -i 10.10.10.2 -p 11111 By default, the ip_idents_reserve function will be called to distribute the identities of the identities in the ip layer without the DF flag. Use this method to stress test this function. After testing under vm, after the concurrent CPU exceeds 12, the old patch pps will no longer rise. The data for concurrent CPU 32 is as follows: test without atomic_add_return: 11:32:10 AM pps_dummy0 0.00 8008897.00 0.00 437986.55 0.00 0.00 0.00 11:32:11 AM pps_dummy0 0.00 7992910.00 0.00 437112.27 0.00 0.00 0.00 11:32:12 AM pps_dummy0 0.00 7982553.00 0.00 436545.87 0.00 0.00 0.00 11:32:13 AM pps_dummy0 0.00 7977757.00 0.00 436283.59 0.00 0.00 0.00 11:32:14 AM pps_dummy0 0.00 7968355.00 0.00 435769.41 0.00 0.00 0.00 test with atomic_add_return: 11:33:20 AM pps_dummy0 0.00 16024069.00 0.00 876316.27 0.00 0.00 0.00 11:33:21 AM pps_dummy0 0.00 16024252.00 0.00 876326.28 0.00 0.00 0.00 11:33:22 AM pps_dummy0 0.00 16021639.00 0.00 876183.38 0.00 0.00 0.00 11:33:23 AM pps_dummy0 0.00 16018738.00 0.00 876024.73 0.00 0.00 0.00 11:33:24 AM pps_dummy0 0.00 16022333.00 0.00 876221.34 0.00 0.00 0.00 11:33:25 AM pps_dummy0 0.00 16028147.00 0.00 876539.29 0.00 0.00 0.00 Signed-off-by: xuanzhuo Acked-by: Dust Li --- net/ipv4/route.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 69127f6..4ede4fc3 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -483,18 +483,12 @@ u32 ip_idents_reserve(u32 hash, int segs) atomic_t *p_id = ip_idents + hash % IP_IDENTS_SZ; u32 old = READ_ONCE(*p_tstamp); u32 now = (u32)jiffies; - u32 new, delta = 0; + u32 delta = 0; if (old != now && cmpxchg(p_tstamp, old, now) == old) delta = prandom_u32_max(now - old); - /* Do not use atomic_add_return() as it makes UBSAN unhappy */ - do { - old = (u32)atomic_read(p_id); - new = old + delta + segs; - } while (atomic_cmpxchg(p_id, old, new) != old); - - return new - segs; + return atomic_add_return(segs + delta, p_id) - segs; } EXPORT_SYMBOL(ip_idents_reserve); -- 1.8.3.1