Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1647498rwb; Sat, 19 Nov 2022 00:32:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/b3b15wEYKFeyCOuEZ8tpXku61f2SXP3hxOgqIBOtDaz/XHjbcUOV4uUgUBagQK/dbUBW X-Received: by 2002:a17:903:1311:b0:189:1e5:8422 with SMTP id iy17-20020a170903131100b0018901e58422mr3235247plb.17.1668846765275; Sat, 19 Nov 2022 00:32:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668846765; cv=none; d=google.com; s=arc-20160816; b=t9I8a6rJMWTKr5ehbjtoFByfer3ucFfhRHrk0aNqIt8eXQ0vdoR05tPQ4+kY6Vviih qApa1QMNj8ca0n0+70DavRgXfgci0tXPlapOxhaG4ValAaxyu5fhV4ZFcEhF9QdGzzN7 2WlOPDUAkGuWH3XPlPEeNYpO5K7+yWYjc4hzm9yCTB+pUyNdDO0+rX+HKjvP05KuhepT z39fLsfybLX6OqKrbNG/7toP9hsCdYACdpGDczVjQRGKDj5KDemjqHL0pUkR33NLpxfy NT5UQ16IKtIOOp3/8PzVPjitlhOwY+LIGGzIDMtgK1DDYiGEyWJXtmKTbkbuL1N7Z0dP 1/+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=HZT09dwWD5fIaFMw5MiqU60lisIB0ejJz2T/HMt9VF4=; b=RMbGKVHjA1BslJYtglEGwe2B8dbCFKCIF65QpE3Ff2vcAOvUWHCfNfZ19VdULL7b8k LAgIktyxwDYkUi4H5wNW3a9Z8rV+Tcp6jo02fWodkaa47f+PjJ434YdMJH35mKXJwhSx kgV7RDgSQvPq8+QqonxpKzCp9Eg046AHr/dpRP92zHvO6XXojDhnfOIB9Dre/I792XqK yrUr+UMvTcfaUS//fgIo+Q93d+/m6lkoIAAzMpZkOjd2OCnXJuQmxMUX+rM31nlbYacP j+36wKfrGB8g6iszcp36w5OEn1dOGZU0AHpObujZS4c+oNtbUrqmzwOxIa65SrrbrnpM DGXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=SHtU6YYN; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a63cc50000000b00476d7732344si5800358pgi.741.2022.11.19.00.32.33; Sat, 19 Nov 2022 00:32:45 -0800 (PST) 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=@google.com header.s=20210112 header.b=SHtU6YYN; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232651AbiKSINY (ORCPT + 91 others); Sat, 19 Nov 2022 03:13:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232098AbiKSINK (ORCPT ); Sat, 19 Nov 2022 03:13:10 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BF327EBDC for ; Sat, 19 Nov 2022 00:13:09 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id h16-20020a170902f55000b001871b770a83so5419673plf.9 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=hR3FCuvDHaZ/1Nmw2QUsr1MKhlGQTGiYM+gFtKaiIqq0cwLeOQgGj6q1s+uElxsj9J /yekw3gccQNGoyPUhuBdiNKikcIOhZPh2sfXCM5wQNqZSPoWtPFpOhsoFTujIej6xTK7 wtqgNsJxmV50ANLNq/DdDzMJ8wC907rubcVB8KvPNI5RNUergX4nxtAWlQMyDYCluO6I fFdqVp8Ht7++yTc4Ru/LgFge4g3VnJi1dZqIV3Hk8q17mFAmGagz1e+p/YUwMaRmuowB kXOvjsckdWmUr4orbrVt7Tl1Z9yKezsOcClUNWOs3y+2QOQSD9xQxHrZwpfYG5aneW7c Xwlw== X-Gm-Message-State: ANoB5pmAWcJ64MXw5Zp++5n5FU74o0mBCe5ahuW95Jw8Xas1qVSgQX9p cqef0LPf5NQ5QV8CcQFv52tcxIV9eS7+zg== 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 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 --- 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"); -- 2.38.1.584.g0f3c55d4c2-goog