From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C452FC4332F for ; Fri, 2 Dec 2022 00:53:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0DB86B0072; Thu, 1 Dec 2022 19:53:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CBD376B0073; Thu, 1 Dec 2022 19:53:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5D7B6B0074; Thu, 1 Dec 2022 19:53:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A6D416B0072 for ; Thu, 1 Dec 2022 19:53:10 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 79A0FAB150 for ; Fri, 2 Dec 2022 00:53:10 +0000 (UTC) X-FDA: 80195542140.05.D28569B Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf17.hostedemail.com (Postfix) with ESMTP id 2F00140002 for ; Fri, 2 Dec 2022 00:53:09 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bVgUeTsr; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf17.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.49 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669942390; a=rsa-sha256; cv=none; b=UtvPcdncZoprXRcN9oyzLcJw6T4NUQx1vJnsH9uinQvz3PgYN3748mBSsWF7fTE53fTuw0 LD1a/+Iby1XRk2VMbXY4g9UO3DLc2avaUYy5KV8NRJlwR6D4xMTs/xjCBjj7cgd1B9IacI rc4qug5EVo5cQRn6l9xNdnOtT2zS7sU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bVgUeTsr; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf17.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.49 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669942390; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XyBUNma2/pYbDUwd0AEpCfAW8UmvTyVIMQbvVCIhkjM=; b=ShLM8TxVu05ahVfEMFPRT6MGOynlGG2w4TqCR19z6IiM3/N3vpJUIhh5IIrU3YHTVawf74 sNjjPGsoP25Q9tMtnMRR9SB51C4oxo9Nb7zh+khv+S/IZgiQzOziObpHKUzczfuhbiErLM 5UuXfzhR77T1EDg5WtEHgVn9cJz1A4w= Received: by mail-pj1-f49.google.com with SMTP id cm20so3474209pjb.1 for ; Thu, 01 Dec 2022 16:53:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XyBUNma2/pYbDUwd0AEpCfAW8UmvTyVIMQbvVCIhkjM=; b=bVgUeTsrg8bzGvV93UtCv9XNcvszgWb7QAtIdDr7Me2tepgdsPs2kw+4W0Ika1rn3X dXkgt53D7jkEl0t6LV+LV8A6bjJdYd4q9LxE3xMmUp/ElJdVnmMkT+HbVKl+BcJQrYBP 22wTub10PuwV0PKzdO/bFm+2lWgIWrEIiH/fQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XyBUNma2/pYbDUwd0AEpCfAW8UmvTyVIMQbvVCIhkjM=; b=pv8VdPTea4TBKRi0XjKfPWMb9UtYzPgKQHO4J4bfWBZrB1bIBgSjkwpUiCfoxz+Ius aTV++JDs1WOYbfzTtpWJQNfQfLcRRktgAW2b4tGCk7bG2EvtBjAjPGBfAMGzFXWQjc7F 5CDV5PifiYsGdNfQFJocd7Z3cpvm/GrVZhnhZ0U3nM7PNQlZBjzkkycKe89OcXH9r2r2 XamvuR2UttouqARITs8mmjnklwudTeewvHK4qhoCl4lYLhIVXI0cdLm+OHCCwdqPhIdR MYZuTttn+JGCa1DwBWBB5DSGx4EurozkfETOXFYkxCPnEMiHvye1dGNyWEfnkTPcQLuY CVuA== X-Gm-Message-State: ANoB5pkmUBef7j3HlLrCMDYnPpQiAt9zd2tQknbkGp402Vm2KwifIoWq WH+EBoA+3JIR4XF7cFVfqc84FA== X-Google-Smtp-Source: AA0mqf5kY7K6H1Eeevu9SIZH52BCxqvw1zVXLhAShSeJAlQdO1Y5eaWkEBpwalGdUhJ9r/q94Gifsw== X-Received: by 2002:a17:902:a514:b0:189:97c3:6382 with SMTP id s20-20020a170902a51400b0018997c36382mr18353098plq.168.1669942388918; Thu, 01 Dec 2022 16:53:08 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h9-20020a628309000000b00574de4a2fbasm3808867pfe.196.2022.12.01.16.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 16:53:07 -0800 (PST) Date: Thu, 1 Dec 2022 16:53:06 -0800 From: Kees Cook To: David Gow Cc: Brendan Higgins , Daniel Latypov , Shuah Khan , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v4 1/3] kunit: Provide a static key to check if KUnit is actively running tests Message-ID: <202212011652.4E8CB40@keescook> References: <20221125084306.1063074-1-davidgow@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221125084306.1063074-1-davidgow@google.com> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2F00140002 X-Stat-Signature: zca1g1gy8odzjp1hnj8w5e96f9wxkqrm X-Spamd-Result: default: False [0.60 / 9.00]; SORBS_IRL_BL(3.00)[209.85.216.49:from]; BAYES_HAM(-3.00)[100.00%]; MID_RHS_NOT_FQDN(0.50)[]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; DKIM_TRACE(0.00)[chromium.org:+]; DMARC_POLICY_ALLOW(0.00)[chromium.org,none]; RCPT_COUNT_SEVEN(0.00)[9]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; R_DKIM_ALLOW(0.00)[chromium.org:s=google]; ARC_NA(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspam-User: X-HE-Tag: 1669942389-693308 X-Bogosity: Ham, tests=bogofilter, spamicity=0.001000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Nov 25, 2022 at 04:43:04PM +0800, David Gow wrote: > KUnit does a few expensive things when enabled. This hasn't been a > problem because KUnit was only enabled on test kernels, but with a few > people enabling (but not _using_) KUnit on production systems, we need a > runtime way of handling this. > > Provide a 'kunit_running' static key (defaulting to false), which allows > us to hide any KUnit code behind a static branch. This should reduce the > performance impact (on other code) of having KUnit enabled to a single > NOP when no tests are running. > > Note that, while it looks unintuitive, tests always run entirely within > __kunit_test_suites_init(), so it's safe to decrement the static key at > the end of this function, rather than in __kunit_test_suites_exit(), > which is only there to clean up results in debugfs. > > Signed-off-by: David Gow > Reviewed-by: Daniel Latypov > --- > This should be a no-op (other than a possible performance improvement) > functionality-wise, and lays the groundwork for a more optimised static > stub implementation. > > The remaining patches in the series add a kunit_get_current_test() > function which is a more friendly and performant wrapper around > current->kunit_test, and use this in the slub test. They also improve > the documentation a bit. > > If there are no objections, we'll take the whole series via the KUnit > tree. > > Changes since v3: > https://lore.kernel.org/linux-kselftest/20221119081252.3864249-1-davidgow@google.com/ > - Use DECLARE_STATIC_KEY_FALSE() -- thanks Daniel! > > No changes since v2: > https://lore.kernel.org/all/20221025071907.1251820-1-davidgow@google.com/ > > Changes since v1: > https://lore.kernel.org/linux-kselftest/20221021072854.333010-1-davidgow@google.com/ > - No changes in this patch. > - Patch 2/3 is reworked, patch 3/3 is new. > > --- > include/kunit/test.h | 4 ++++ > lib/kunit/test.c | 6 ++++++ > 2 files changed, 10 insertions(+) > > diff --git a/include/kunit/test.h b/include/kunit/test.h > index 4666a4d199ea..87ea90576b50 100644 > --- a/include/kunit/test.h > +++ b/include/kunit/test.h > @@ -16,6 +16,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -27,6 +28,9 @@ > > #include > > +/* Static key: true if any KUnit tests are currently running */ > +DECLARE_STATIC_KEY_FALSE(kunit_running); > + > struct kunit; > > /* Size of log associated with test. */ > diff --git a/lib/kunit/test.c b/lib/kunit/test.c > index 1c9d8d962d67..87a5d795843b 100644 > --- a/lib/kunit/test.c > +++ b/lib/kunit/test.c > @@ -20,6 +20,8 @@ > #include "string-stream.h" > #include "try-catch-impl.h" > > +DEFINE_STATIC_KEY_FALSE(kunit_running); > + > #if IS_BUILTIN(CONFIG_KUNIT) > /* > * Fail the current test and print an error message to the log. > @@ -615,10 +617,14 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_ > return 0; > } > > + static_branch_inc(&kunit_running); Is it expected there will be multiple tests running? (I was expecting "static_branch_enable"). > + > for (i = 0; i < num_suites; i++) { > kunit_init_suite(suites[i]); > kunit_run_tests(suites[i]); > } > + > + static_branch_dec(&kunit_running); > return 0; > } > EXPORT_SYMBOL_GPL(__kunit_test_suites_init); > -- > 2.38.1.584.g0f3c55d4c2-goog > Regardless: Reviewed-by: Kees Cook -- Kees Cook