]> git.itanic.dy.fi Git - linux-stable/commitdiff
wireguard: ratelimiter: disable timings test by default
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 16 Sep 2022 14:37:38 +0000 (15:37 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Sep 2022 09:32:17 +0000 (11:32 +0200)
[ Upstream commit 684dec3cf45da2b0848298efae4adf3b2aeafeda ]

A previous commit tried to make the ratelimiter timings test more
reliable but in the process made it less reliable on other
configurations. This is an impossible problem to solve without
increasingly ridiculous heuristics. And it's not even a problem that
actually needs to be solved in any comprehensive way, since this is only
ever used during development. So just cordon this off with a DEBUG_
ifdef, just like we do for the trie's randomized tests, so it can be
enabled while hacking on the code, and otherwise disabled in CI. In the
process we also revert 151c8e499f47.

Fixes: 151c8e499f47 ("wireguard: ratelimiter: use hrtimer in selftest")
Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/wireguard/selftest/ratelimiter.c

index ba87d294604fe436e9a672dce65a37139a7a32bf..d4bb40a695ab6785968babc1060a8b1010651e8b 100644 (file)
@@ -6,29 +6,28 @@
 #ifdef DEBUG
 
 #include <linux/jiffies.h>
 #ifdef DEBUG
 
 #include <linux/jiffies.h>
-#include <linux/hrtimer.h>
 
 static const struct {
        bool result;
 
 static const struct {
        bool result;
-       u64 nsec_to_sleep_before;
+       unsigned int msec_to_sleep_before;
 } expected_results[] __initconst = {
        [0 ... PACKETS_BURSTABLE - 1] = { true, 0 },
        [PACKETS_BURSTABLE] = { false, 0 },
 } expected_results[] __initconst = {
        [0 ... PACKETS_BURSTABLE - 1] = { true, 0 },
        [PACKETS_BURSTABLE] = { false, 0 },
-       [PACKETS_BURSTABLE + 1] = { true, NSEC_PER_SEC / PACKETS_PER_SECOND },
+       [PACKETS_BURSTABLE + 1] = { true, MSEC_PER_SEC / PACKETS_PER_SECOND },
        [PACKETS_BURSTABLE + 2] = { false, 0 },
        [PACKETS_BURSTABLE + 2] = { false, 0 },
-       [PACKETS_BURSTABLE + 3] = { true, (NSEC_PER_SEC / PACKETS_PER_SECOND) * 2 },
+       [PACKETS_BURSTABLE + 3] = { true, (MSEC_PER_SEC / PACKETS_PER_SECOND) * 2 },
        [PACKETS_BURSTABLE + 4] = { true, 0 },
        [PACKETS_BURSTABLE + 5] = { false, 0 }
 };
 
 static __init unsigned int maximum_jiffies_at_index(int index)
 {
        [PACKETS_BURSTABLE + 4] = { true, 0 },
        [PACKETS_BURSTABLE + 5] = { false, 0 }
 };
 
 static __init unsigned int maximum_jiffies_at_index(int index)
 {
-       u64 total_nsecs = 2 * NSEC_PER_SEC / PACKETS_PER_SECOND / 3;
+       unsigned int total_msecs = 2 * MSEC_PER_SEC / PACKETS_PER_SECOND / 3;
        int i;
 
        for (i = 0; i <= index; ++i)
        int i;
 
        for (i = 0; i <= index; ++i)
-               total_nsecs += expected_results[i].nsec_to_sleep_before;
-       return nsecs_to_jiffies(total_nsecs);
+               total_msecs += expected_results[i].msec_to_sleep_before;
+       return msecs_to_jiffies(total_msecs);
 }
 
 static __init int timings_test(struct sk_buff *skb4, struct iphdr *hdr4,
 }
 
 static __init int timings_test(struct sk_buff *skb4, struct iphdr *hdr4,
@@ -43,12 +42,8 @@ static __init int timings_test(struct sk_buff *skb4, struct iphdr *hdr4,
        loop_start_time = jiffies;
 
        for (i = 0; i < ARRAY_SIZE(expected_results); ++i) {
        loop_start_time = jiffies;
 
        for (i = 0; i < ARRAY_SIZE(expected_results); ++i) {
-               if (expected_results[i].nsec_to_sleep_before) {
-                       ktime_t timeout = ktime_add(ktime_add_ns(ktime_get_coarse_boottime(), TICK_NSEC * 4 / 3),
-                                                   ns_to_ktime(expected_results[i].nsec_to_sleep_before));
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_hrtimeout_range_clock(&timeout, 0, HRTIMER_MODE_ABS, CLOCK_BOOTTIME);
-               }
+               if (expected_results[i].msec_to_sleep_before)
+                       msleep(expected_results[i].msec_to_sleep_before);
 
                if (time_is_before_jiffies(loop_start_time +
                                           maximum_jiffies_at_index(i)))
 
                if (time_is_before_jiffies(loop_start_time +
                                           maximum_jiffies_at_index(i)))
@@ -132,7 +127,7 @@ bool __init wg_ratelimiter_selftest(void)
        if (IS_ENABLED(CONFIG_KASAN) || IS_ENABLED(CONFIG_UBSAN))
                return true;
 
        if (IS_ENABLED(CONFIG_KASAN) || IS_ENABLED(CONFIG_UBSAN))
                return true;
 
-       BUILD_BUG_ON(NSEC_PER_SEC % PACKETS_PER_SECOND != 0);
+       BUILD_BUG_ON(MSEC_PER_SEC % PACKETS_PER_SECOND != 0);
 
        if (wg_ratelimiter_init())
                goto out;
 
        if (wg_ratelimiter_init())
                goto out;
@@ -172,7 +167,7 @@ bool __init wg_ratelimiter_selftest(void)
        ++test;
 #endif
 
        ++test;
 #endif
 
-       for (trials = TRIALS_BEFORE_GIVING_UP;;) {
+       for (trials = TRIALS_BEFORE_GIVING_UP; IS_ENABLED(DEBUG_RATELIMITER_TIMINGS);) {
                int test_count = 0, ret;
 
                ret = timings_test(skb4, hdr4, skb6, hdr6, &test_count);
                int test_count = 0, ret;
 
                ret = timings_test(skb4, hdr4, skb6, hdr6, &test_count);