From patchwork Sat Nov 19 08:12:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 13049640 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 1EE27C43219 for ; Sat, 19 Nov 2022 08:13:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DDBC6B0074; Sat, 19 Nov 2022 03:13:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 965E76B0075; Sat, 19 Nov 2022 03:13:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DFAE6B0078; Sat, 19 Nov 2022 03:13:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6F5C06B0074 for ; Sat, 19 Nov 2022 03:13:10 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 44173A0CB8 for ; Sat, 19 Nov 2022 08:13:10 +0000 (UTC) X-FDA: 80149476540.19.4605816 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf30.hostedemail.com (Postfix) with ESMTP id E0C2F80004 for ; Sat, 19 Nov 2022 08:13:09 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id m1-20020a170902db0100b00188eec2726cso5463354plx.18 for ; Sat, 19 Nov 2022 00:13:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=HZT09dwWD5fIaFMw5MiqU60lisIB0ejJz2T/HMt9VF4=; b=SHtU6YYNKAEepXdm5HbRFnuAyJFQdgO+1wedLhMpRsszD6ADUFWgk+3Dk2eyg23L4C zABv2VQZoq1xk7m9WvhdFXtEOjqkkRv7G5nWIow9W96ux/+b98E53LvWytC2S4a6h04r zB4vTdApfRXZH7pB+ZryafnleYvVDTkZGvhF74jyYCJAm2CuHpmFMED7k0JsoYO/yiTs ad0L59iP04zGlyxAB7bv/LMHHuEgs7zBVIQDhZWBX89Lj4G42i/ICeB0VmRucNP1g2An 1t2Tfm6nmhgKRrF4oWPqvjeR2y4x9QOOTpjql3bpcBMpiyRGomB6M2x+txB9lOy5kc1+ MRfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HZT09dwWD5fIaFMw5MiqU60lisIB0ejJz2T/HMt9VF4=; b=MRTY0MOiwaWwc+dtziXgstA7NWJyvwMNmwPQZVyHMLKPxugzBZEKa50ow2xebcSWvN +Uq2sCDLmIkjH4iRio5K/2U6TIEUc3UwZFIIbmCM8uN40HdU6RiwpYOJbQKsxCGbZ1Je nep8R+sw8PwAJYXrEgthbpawzVzMF2suLol33O6NqRMOPx/lVDYIQI1Y3p80ZO5Grcop AZEKmel5hfFEu7vP9vYKfT6og2Uv+LlPIEQU3M1SgkTI7zb5MXJ1tS1FtquDErlqpK7p lAe+m/z/1cz07UvcGH96SDh3a392CaqzVVk3CNs0IlQT7EASTbrc9U92obPNvBAQRxmW pSTQ== X-Gm-Message-State: ANoB5pldbpV/g5ukClEo44tKqlAzAaS87Ivwt7maEeXf9I+rwTK1oYzd xECt1OZFFkC50xTbANLPG+gJYpMDHEYJjA== X-Google-Smtp-Source: AA0mqf6d0TFeFJe2lky/Uxlh+yxajwOJpZKYlUcAsY4hA8k+GJ+0dKXuSI5wzfJrQ5yVpEF7+GNMYaRxd/NUbA== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:aa7:9f9c:0:b0:53e:81ab:9419 with SMTP id z28-20020aa79f9c000000b0053e81ab9419mr11494527pfr.15.1668845588834; Sat, 19 Nov 2022 00:13:08 -0800 (PST) Date: Sat, 19 Nov 2022 16:12:52 +0800 In-Reply-To: <20221119081252.3864249-1-davidgow@google.com> Mime-Version: 1.0 References: <20221119081252.3864249-1-davidgow@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221119081252.3864249-3-davidgow@google.com> Subject: [PATCH v3 3/3] mm: slub: test: Use the kunit_get_current_test() function From: David Gow To: Brendan Higgins , Daniel Latypov , Shuah Khan Cc: David Gow , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , linux-doc@vger.kernel.org, linux-mm@kvack.org, Oliver Glitta , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Christoph Lameter , Vlastimil Babka , David Rientjes , Andrew Morton ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668845589; a=rsa-sha256; cv=none; b=oNk1UoAGs/yjK2GiDJW2nz2vMDMTKObob7dl93CEMhlpuERKCM63MZXiHz3hFo3UppnW2s 76hhlQRWx/R1tCkaD1ca8aDV9+4o5uBD8wbk3VD+p5xtNdL4r5vkCtqJAkPAUXaFrKlUpo +SF5WSEEybAS0G1Jb1VjuHijfeZ52Tg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=SHtU6YYN; spf=pass (imf30.hostedemail.com: domain of 3FJB4YwgKCDkYVqdYbjrbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--davidgow.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3FJB4YwgKCDkYVqdYbjrbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--davidgow.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668845589; 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=HZT09dwWD5fIaFMw5MiqU60lisIB0ejJz2T/HMt9VF4=; b=rjIVyKkt0a4nasoofIQ7HgG1SAKGE1rnX+WjlXXGprEJzHlny4PRQgd6kwdmYssfembT26 4yjrzinliJv1B60POYikQ584k+jsiqc1x8alWnjZwbzpPlAMPMXgN5OwNtIluN1V959noq kKUT0wC6HE7vfQsPS8sTe4JbYnT/dR0= Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=SHtU6YYN; spf=pass (imf30.hostedemail.com: domain of 3FJB4YwgKCDkYVqdYbjrbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--davidgow.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3FJB4YwgKCDkYVqdYbjrbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--davidgow.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E0C2F80004 X-Rspam-User: X-Stat-Signature: fxawwj1pp7hkrih53zcdcun3wr361osm X-HE-Tag: 1668845589-165292 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: Use the newly-added function kunit_get_current_test() instead of accessing current->kunit_test directly. This function uses a static key to return more quickly when KUnit is enabled, but no tests are actively running. There should therefore be a negligible performance impact to enabling the slub KUnit tests. Other than the performance improvement, this should be a no-op. Cc: Oliver Glitta Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Christoph Lameter Cc: Vlastimil Babka Cc: David Rientjes Cc: Andrew Morton Signed-off-by: David Gow Acked-by: Vlastimil Babka Acked-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- This is intended as an example use of the new function. Other users (such as KASAN) will be updated separately, as there would otherwise be conflicts. We'll take this whole series via the kselftest/kunit tree. Changes since v2: https://lore.kernel.org/all/20221025071907.1251820-3-davidgow@google.com/ - Get rid of a redundant 'likely' (Thanks Vlastimil Babka) - Use current->kunit_test directly when we already know a test is running. (Thanks Vlastimil Babka) - Add Vlastimil's Acked-by. There was no v1 of this patch. v1 of the series can be found here: https://lore.kernel.org/linux-kselftest/20221021072854.333010-1-davidgow@google.com/T/#u Cheers, -- David --- lib/slub_kunit.c | 1 + mm/slub.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c index 7a0564d7cb7a..8fd19c8301ad 100644 --- a/lib/slub_kunit.c +++ b/lib/slub_kunit.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include diff --git a/mm/slub.c b/mm/slub.c index 157527d7101b..1887996cb703 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -603,7 +604,7 @@ static bool slab_add_kunit_errors(void) { struct kunit_resource *resource; - if (likely(!current->kunit_test)) + if (!kunit_get_current_test()) return false; resource = kunit_find_named_resource(current->kunit_test, "slab_errors");