From patchwork Fri Nov 25 08:43:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 13055608 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 21628C4332F for ; Fri, 25 Nov 2022 08:43:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0D026B0075; Fri, 25 Nov 2022 03:43:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ABDD66B007B; Fri, 25 Nov 2022 03:43:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AC366B007D; Fri, 25 Nov 2022 03:43:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8D5A16B0075 for ; Fri, 25 Nov 2022 03:43:26 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 59BB640294 for ; Fri, 25 Nov 2022 08:43:26 +0000 (UTC) X-FDA: 80171325612.01.CC9DDE4 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf08.hostedemail.com (Postfix) with ESMTP id E9EEA16000F for ; Fri, 25 Nov 2022 08:43:24 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id c1-20020a170902d48100b0018723580343so3136782plg.15 for ; Fri, 25 Nov 2022 00:43:24 -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=dkxFkrOpjQGLbrLmIP0+FclGqPGzevJvZOLievBv8dk=; b=kqgbzNKEz/EBdl30RURuDttaaXxDeC30LnNegyGkFZc9kDj5JRKrZbbcEP9pwVxxZN G9XRyB4jJukMFOoeTGeBeQ3CnM0EbzUy0iVy1MuX2Azm+2w3BQ9adRyL9kvkdnoRUBgI X6bKvh5wnfqjPenjD+9aZ4sKilQcc3HfOGFYHURPQ69pGtxzEdI0XKeB9kAYdbFzp7Bg iV3xmvTGIdnYEq9akRm0/9IGUCEtjMcs+FCtU+t6i2Mn7bMXvKRnkKAJSxnin4lI09Y7 1pZbQEDt8j+6a4aF/rIVEb1uQE3DhbYONBvJrOsxEcU1VcYGwGBsoyKH/GlpFeZvG8ID eajQ== 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=dkxFkrOpjQGLbrLmIP0+FclGqPGzevJvZOLievBv8dk=; b=q5MAol79F/UXemCHwOIxQQWBJA5+rfH2S+lEVA59J8acqKreAWTKgX3tlP+2kUxXKB qSTKslkZaXpYFqlfcfrmiCOHgu/8SMzxgbuTUEbPHA8ogI/ltk2dlEYlSiv2r3bWcgqq t/3+DDvp727t+0frbDoIEm2fH3zT5aNm1rsQsLJStzPp7kjAUEKpAR8Ns2P/ZgkoWBdx XGj5YjenDjMq8WL7rjda0xp51JItxJ8VZKZeM3cXHcCsznRmk9Lt9yKbCXgjRGgqh3nM Sie2QFu2b4+FrCJ5cpKGIsH6IIRTticrDbk3O/qVh8xMDmXqM3lu/gDpJm7IEzqjSPfW TVHg== X-Gm-Message-State: ANoB5pk+4xL+OtzP7RaXHPvWsDbJ1ZOcD2ZzHJrTEU8xryDS5xPxV5Yf PlqlcWqRrNLS1quiVZZqg/yrfwhsZmNWXg== X-Google-Smtp-Source: AA0mqf7RiYkevlcRuG6Fr8tnCwq1XAC9tTw8xXaio9yL/yIb9hcwf34Ri5nG0oPQNQBwzo8q3vRzqDIvG97ZmA== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a17:90b:3809:b0:20a:c64c:ae80 with SMTP id mq9-20020a17090b380900b0020ac64cae80mr28596107pjb.12.1669365803760; Fri, 25 Nov 2022 00:43:23 -0800 (PST) Date: Fri, 25 Nov 2022 16:43:06 +0800 In-Reply-To: <20221125084306.1063074-1-davidgow@google.com> Mime-Version: 1.0 References: <20221125084306.1063074-1-davidgow@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221125084306.1063074-3-davidgow@google.com> Subject: [PATCH v4 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=1669365805; a=rsa-sha256; cv=none; b=0vIMh02rfY/gY97Ns+9uLTzaFSK+Z0otIewavWlp9lYoGq+sxQvwfEJDYTYwkGD7qzrWkv jb/YfUSTR6HF0wBRwDdhGy36rTU7PiSr0aISCy19NPH9ZSzLW6hWw6dhUncrGWpajgNgM3 DJPCJl4ZT7ygfNBqXXZmaGDT2J+0eVM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kqgbzNKE; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3K4CAYwgKCFAvsD0vy6Ey66y3w.u64305CF-442Dsu2.69y@flex--davidgow.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3K4CAYwgKCFAvsD0vy6Ey66y3w.u64305CF-442Dsu2.69y@flex--davidgow.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669365805; 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=dkxFkrOpjQGLbrLmIP0+FclGqPGzevJvZOLievBv8dk=; b=Ma7SNTID4HC5udffLghRQSe5iI6880MQSJVBEDgshonUeJ9hMF4IKZex0al3/+lDSOvUui nCU/+0I/gdaSpXRf/RfTacoz6FWs1NRforrf28G6HasCmLfyIU1tmJfnI8KZBztyFTqEjP Xprsm7zmGkaj0SpI07ep60/NU6l5aF0= X-Rspamd-Queue-Id: E9EEA16000F X-Stat-Signature: ugpaufy1peedmqj4p7s5io1ouk8ij6jn X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kqgbzNKE; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3K4CAYwgKCFAvsD0vy6Ey66y3w.u64305CF-442Dsu2.69y@flex--davidgow.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3K4CAYwgKCFAvsD0vy6Ey66y3w.u64305CF-442Dsu2.69y@flex--davidgow.bounces.google.com X-Rspamd-Server: rspam09 X-HE-Tag: 1669365804-540034 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> Reviewed-by: Kees Cook --- 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 v3: https://lore.kernel.org/linux-kselftest/20221119081252.3864249-3-davidgow@google.com/ - Add Hyeonggon's Acked-by. 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");