From nobody Tue Dec 16 08:51:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA748C32771 for ; Mon, 26 Sep 2022 11:04:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237218AbiIZLEw (ORCPT ); Mon, 26 Sep 2022 07:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237356AbiIZLDy (ORCPT ); Mon, 26 Sep 2022 07:03:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA416958E; Mon, 26 Sep 2022 03:32:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9793860CA3; Mon, 26 Sep 2022 10:31:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D933C433C1; Mon, 26 Sep 2022 10:31:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188279; bh=eJ+fDbbzA19SGMmU8INWJvoyHaXEcrggf1UMvpYzvDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QXafxHQspj1iy4sCDw6Kl3mxt7XeIPlIyewHKwf+32MJccZEkdsOVL5sLUg7BF5Bc Hc5LBwLj/TMavknqCGm2UTieYVztIVrzS61tCqgMYwITCHMMld/xU+ZIzBq9lTdj7I 8zBeRrPpUoIQNmGa2nUm4riyfemSzUgpJYncLYVk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 099/141] wireguard: ratelimiter: disable timings test by default Date: Mon, 26 Sep 2022 12:12:05 +0200 Message-Id: <20220926100758.018280750@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100754.639112000@linuxfoundation.org> References: <20220926100754.639112000@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jason A. Donenfeld [ 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 Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/wireguard/selftest/ratelimiter.c | 25 ++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireguard/selftest/ratelimiter.c b/drivers/net/wir= eguard/selftest/ratelimiter.c index ba87d294604f..d4bb40a695ab 100644 --- a/drivers/net/wireguard/selftest/ratelimiter.c +++ b/drivers/net/wireguard/selftest/ratelimiter.c @@ -6,29 +6,28 @@ #ifdef DEBUG =20 #include -#include =20 static const struct { bool result; - u64 nsec_to_sleep_before; + unsigned int msec_to_sleep_before; } expected_results[] __initconst =3D { [0 ... PACKETS_BURSTABLE - 1] =3D { true, 0 }, [PACKETS_BURSTABLE] =3D { false, 0 }, - [PACKETS_BURSTABLE + 1] =3D { true, NSEC_PER_SEC / PACKETS_PER_SECOND }, + [PACKETS_BURSTABLE + 1] =3D { true, MSEC_PER_SEC / PACKETS_PER_SECOND }, [PACKETS_BURSTABLE + 2] =3D { false, 0 }, - [PACKETS_BURSTABLE + 3] =3D { true, (NSEC_PER_SEC / PACKETS_PER_SECOND) *= 2 }, + [PACKETS_BURSTABLE + 3] =3D { true, (MSEC_PER_SEC / PACKETS_PER_SECOND) *= 2 }, [PACKETS_BURSTABLE + 4] =3D { true, 0 }, [PACKETS_BURSTABLE + 5] =3D { false, 0 } }; =20 static __init unsigned int maximum_jiffies_at_index(int index) { - u64 total_nsecs =3D 2 * NSEC_PER_SEC / PACKETS_PER_SECOND / 3; + unsigned int total_msecs =3D 2 * MSEC_PER_SEC / PACKETS_PER_SECOND / 3; int i; =20 for (i =3D 0; i <=3D index; ++i) - total_nsecs +=3D expected_results[i].nsec_to_sleep_before; - return nsecs_to_jiffies(total_nsecs); + total_msecs +=3D expected_results[i].msec_to_sleep_before; + return msecs_to_jiffies(total_msecs); } =20 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, str= uct iphdr *hdr4, loop_start_time =3D jiffies; =20 for (i =3D 0; i < ARRAY_SIZE(expected_results); ++i) { - if (expected_results[i].nsec_to_sleep_before) { - ktime_t timeout =3D 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_BOO= TTIME); - } + if (expected_results[i].msec_to_sleep_before) + msleep(expected_results[i].msec_to_sleep_before); =20 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; =20 - BUILD_BUG_ON(NSEC_PER_SEC % PACKETS_PER_SECOND !=3D 0); + BUILD_BUG_ON(MSEC_PER_SEC % PACKETS_PER_SECOND !=3D 0); =20 if (wg_ratelimiter_init()) goto out; @@ -172,7 +167,7 @@ bool __init wg_ratelimiter_selftest(void) ++test; #endif =20 - for (trials =3D TRIALS_BEFORE_GIVING_UP;;) { + for (trials =3D TRIALS_BEFORE_GIVING_UP; IS_ENABLED(DEBUG_RATELIMITER_TIM= INGS);) { int test_count =3D 0, ret; =20 ret =3D timings_test(skb4, hdr4, skb6, hdr6, &test_count); --=20 2.35.1