Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp793980rwb; Mon, 26 Sep 2022 06:04:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wnNqF+1CRMwM2d2SWzX+qX5VUMkwi/6dD9ZFzfROxI7gthSoqh8VOAv+SlECR+2IigG1k X-Received: by 2002:a17:90b:3912:b0:203:c0a0:f582 with SMTP id ob18-20020a17090b391200b00203c0a0f582mr31058438pjb.141.1664197440882; Mon, 26 Sep 2022 06:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197440; cv=none; d=google.com; s=arc-20160816; b=FIlcuKQdhNxIN4XjOa/ga5Y57aNhYi01aJ8EXBE9COdxggLH6gGSvWpLH0o5o3NIEv z89kUQN/Bofy6jE6JtWreSS6gox8De4gOnSlFIw41l6PJCucOgte8yOZxdlc6L+by17S cbBLu7Ae9j6SDWf5xkvXZ7n0c221SkLLOwN5Yq50xLmILhT0fBTbbHNjwGYpLTQHL+a2 SZD56zh0IO8A48XE9/7dfbkFylnFmdU0UE/PW7Ywinl+HEUxNHIWg6k1Lo6upPN1T9hH QmyJ8zUJJ9UiAXp1VMbEdK1K52YCK8bNSSC7bGiuvsiI3kngPeQMllzcwAD1a45eXKAj oc9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gmi48BLWoOlGpiHWdjdbqUOlGjJ67rWEs3NTJmy5XDA=; b=ZE12Fvb3L2MzaK5m+xZjd+uhKoEMAqdDwHXkweO7KJPqtIeXt9uyg8qY5Dup8ujI0W goPdR+QfFUoD2pR0BRi00cq436a/uDl2WIz+hJszFvk4KQxycA8a7KHNdxS+jU8Fx1Y9 /msKiEU3kBJcGjygy4eQ5t+lYLnrPdEUYiuUexMviwEeeMofwO3iMsMPtrpA/s7fIFMf L+/qBFKvUS5G8Gq6nwwtTmtUyCcphvN8TKVRVAMN+pfB88u877l5JZ9vm1Yaqp69mLHO oReNp7yrDfG/oOHt/J2bxfuFvVB5AhOsOevLxdcIak7jAg7zPAsZP0RV+aAUjFURbZmi ixsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Bsndg4uR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a63544e000000b0043447486c84si17283289pgm.875.2022.09.26.06.03.48; Mon, 26 Sep 2022 06:04:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Bsndg4uR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234996AbiIZLUJ (ORCPT + 99 others); Mon, 26 Sep 2022 07:20:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237751AbiIZLSz (ORCPT ); Mon, 26 Sep 2022 07:18:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7D9866A68; Mon, 26 Sep 2022 03:38:27 -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 ams.source.kernel.org (Postfix) with ESMTPS id 53A6DB8091E; Mon, 26 Sep 2022 10:38:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A45AAC433C1; Mon, 26 Sep 2022 10:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188701; bh=eJ+fDbbzA19SGMmU8INWJvoyHaXEcrggf1UMvpYzvDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bsndg4uRPQozWIAewi7lHPeyYVqbUrCMttL8bdKmtW7b9nDSXLVe7wTAX40+fTryO mx0qROSP4nMf6wk7B+NTLK9DSzOxlBaNBNRpG4xAWQLC7h+/3lwYVUFfFwW7sYqKEI 16SfPpKH1+h2h2upA4QYT5qSQbAAWE4vqf5u71CQ= 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.15 094/148] wireguard: ratelimiter: disable timings test by default Date: Mon, 26 Sep 2022 12:12:08 +0200 Message-Id: <20220926100759.612525023@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/wireguard/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 #include -#include 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 }, - [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 + 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) { - 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) - 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, @@ -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) { - 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))) @@ -132,7 +127,7 @@ bool __init wg_ratelimiter_selftest(void) 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; @@ -172,7 +167,7 @@ bool __init wg_ratelimiter_selftest(void) ++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); -- 2.35.1