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 85B4EC4332F for ; Fri, 2 Dec 2022 00:54:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14E976B0072; Thu, 1 Dec 2022 19:54:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 105CE6B0073; Thu, 1 Dec 2022 19:54:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB9636B0074; Thu, 1 Dec 2022 19:54:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D60226B0072 for ; Thu, 1 Dec 2022 19:54:37 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A268BC0545 for ; Fri, 2 Dec 2022 00:54:37 +0000 (UTC) X-FDA: 80195545794.09.2A75E5C Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf25.hostedemail.com (Postfix) with ESMTP id 49B45A0013 for ; Fri, 2 Dec 2022 00:54:37 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=UI50tBxd; spf=pass (imf25.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.169 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669942477; 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=qHYGi4hccRkpXmnqsWHqGlJk0rUF38lHPoxZSO5Qzyc=; b=EY/6Nkm3twxl/rSdrCpR+YW6vUfWcXYMp8jVd4c5nri6mp0ROMT3LYXS72TELhss0LPlpj MLWbYdSsuu4xv5P7VWfyWbwD86ydHRhncIt6hDnoX5Z7KiTvIzYfHP/qa1QkcmKT0b80FV eq4zHRL57WoUlFYo+hj58PTdMsYHsfY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669942477; a=rsa-sha256; cv=none; b=SEqSldox1kM8zuYT8VbJvA+sVi+6JQaQEux1f3qS3fxx+cJKJZgk06IqaM8VErtTLbUB2g +86TVCDC+FtE7bsBKNBjt9Uwe92t0Xk7u/uqLmkKMLcoG3qte6pvqfWZ6SG6bz9beLZcam kFBdzYtk1FoWv9ujx5jDdcGbaOt6agA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=UI50tBxd; spf=pass (imf25.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.169 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org Received: by mail-pf1-f169.google.com with SMTP id c15so3461982pfb.13 for ; Thu, 01 Dec 2022 16:54:37 -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=qHYGi4hccRkpXmnqsWHqGlJk0rUF38lHPoxZSO5Qzyc=; b=UI50tBxdrwYo1AkTLCVtUhVaHYduXtuPzQvN76OM8fbMoTHKPPBlui8rr+gidv1/Yl jEdYfF30QrKfZuxlUubWJlAZEH9B+hvbfIoe6bNjih73getounWssghoDca5FB8eEnsf 2m8LyLwBFFfYR/v303/vtmwg7k2C1Cktsf9Yw= 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=qHYGi4hccRkpXmnqsWHqGlJk0rUF38lHPoxZSO5Qzyc=; b=t23m7NeNf7HPu13Hrv3bb5zZgzCrgeyhHxiL2+9I7p3BvtaaRoirkxOze3eIaenupH qaZjfMeeZeK41YQkU9V5rAU85lQifc1jrlH+aTrkZuAB3Iu+FZ8bQ5CUC3K8RDVeZltL XpDM0FukKwAjb09uhTL+3F5aa1ctaQ9KP/UDxNXpqZjkZSf8z81lfy7u06Wc3/t1gNOY 3FuzM6vQaFiqRvgFZJ8EmW2pLVMvmh/GEgO0IqyCzeGEkqCNjHHHvLmdjySji88tRSkz NFck/Rii0b/Es4+Q68va8CP9JCFJn4ddWwAGgrOwvfqvoRbZK+ewA7ivwLpeez2q1Ugm I4Dg== X-Gm-Message-State: ANoB5pkqNFJvagOlSXI7zODy6lS2aeTnIgBpXewBIdvFN/ZDtL/8wK76 VZskLVJutonNOUUBmn6E0xy+sQ== X-Google-Smtp-Source: AA0mqf5kJfb1ONIrys8W61vNxCK5ToeM9RpLkUWl+1oYBQO7bay6U5spcQ68Ek81GSK/b5VnkHaraA== X-Received: by 2002:a63:4d61:0:b0:477:b1a8:531e with SMTP id n33-20020a634d61000000b00477b1a8531emr41488628pgl.158.1669942476366; Thu, 01 Dec 2022 16:54:36 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id jx24-20020a17090b46d800b00213202d77d9sm3588021pjb.43.2022.12.01.16.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 16:54:35 -0800 (PST) Date: Thu, 1 Dec 2022 16:54:35 -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, Jonathan Corbet , Sadiya Kazi Subject: Re: [PATCH v4 2/3] kunit: Use the static key when retrieving the current test Message-ID: <202212011654.9BB14785@keescook> References: <20221125084306.1063074-1-davidgow@google.com> <20221125084306.1063074-2-davidgow@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221125084306.1063074-2-davidgow@google.com> X-Rspam-User: X-Spamd-Result: default: False [3.60 / 9.00]; SORBS_IRL_BL(3.00)[209.85.210.169:from]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_NO_TLS_LAST(0.10)[]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAYES_HAM(-0.00)[41.41%]; DKIM_TRACE(0.00)[chromium.org:+]; DMARC_POLICY_ALLOW(0.00)[chromium.org,none]; RCPT_COUNT_SEVEN(0.00)[11]; 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-Stat-Signature: j549iu3jwbqzm6kttpzebx5kz375q7nr X-Rspamd-Queue-Id: 49B45A0013 X-Rspamd-Server: rspam05 X-HE-Tag: 1669942477-800566 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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:05PM +0800, David Gow wrote: > In order to detect if a KUnit test is running, and to access its > context, the 'kunit_test' member of the current task_struct is used. > Usually, this is accessed directly or via the kunit_fail_current_task() > function. > > In order to speed up the case where no test is running, add a wrapper, > kunit_get_current_test(), which uses the static key to fail early. > Equally, Speed up kunit_fail_current_test() by using the static key. > > This should make it convenient for code to call this > unconditionally in fakes or error paths, without worrying that this will > slow the code down significantly. > > If CONFIG_KUNIT=n (or m), this compiles away to nothing. If > CONFIG_KUNIT=y, it will compile down to a NOP (on most architectures) if > no KUnit test is currently running. > > Note that kunit_get_current_test() does not work if KUnit is built as a > module. This mirrors the existing restriction on kunit_fail_current_test(). > > Note that the definition of kunit_fail_current_test() still wraps an > empty, inline function if KUnit is not built-in. This is to ensure that > the printf format string __attribute__ will still work. > > Also update the documentation to suggest users use the new > kunit_get_current_test() function, update the example, and to describe > the behaviour when KUnit is disabled better. > > Cc: Jonathan Corbet > Cc: Sadiya Kazi > Signed-off-by: David Gow Reviewed-by: Kees Cook -- Kees Cook