Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8014414rwi; Tue, 25 Oct 2022 01:01:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4LnDI6ZeecUNDYAj++0xkOwtUfNIlIGuXEd6+qGVeeTlV6kazJRdtDCILhWlPjz+MrN1sa X-Received: by 2002:a17:907:94c1:b0:792:56d7:2879 with SMTP id dn1-20020a17090794c100b0079256d72879mr26620950ejc.144.1666684879725; Tue, 25 Oct 2022 01:01:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666684879; cv=none; d=google.com; s=arc-20160816; b=kWXS7VfLdWe/c5Jvj7VgF00dQaQt9BYXzh4Az1w3UNwZMDyMsoGSosjBPNUKuEA+ez qVjFKB3plwgubRb/ZLpf2LQjLvGOEuiTnuO9O51UKoIamvfikhNrOnYJ+Gt9Uyz3g3Y7 jPmyzMZqZMkloA8V/GBN0vDhL62MKNKeEIORz9990rv5ZapfMFW6mHvjkfh37GBwo/fg zoPMapTBN6sxu2LJZCoPJBdGrpKUB73YNPR2JevSYlh18kBMOB1bU6ZGMJmYAtI85QPM OgGKR4+/VSmcMF3x2/WY7wDkGhmW5T5KWvhVGQpYE6Mz8otLzrZ+93FSd4ih9gv1Lp6M 2nhg== 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=KA5AmQjfCAbtpdHkGDjwVts9T7CuDkkry+0zPgKF0lM=; b=IgqRhHNYIdIidMr9UV//7GXlV4H8jy4vgs6lrhRybrDvvr+YARFtZjcgl32sqRvndo i9r76SaLsLI13BdOoQBcaOY7heATtby1l0th9jNJbNljqA17V6Ml26tXvfa2JPbqPNwm A333iu1vOEDlykZRYYM1dtHuOhTDjujB3TRtJ7wiHoKzkxanf+L7S6tM40hlQ6iD2C5o Yn9/MyYOZsidnkxgwiV7FdUU1E4pyEGHp9obPLfdOgeyCd4j8vI8gG+SGxiJvePbtFg2 HCONLXVKUJaZzRSTpOCSi9xLc6NaaRvnQ9fa8B2V81ucoSrrlYuNfzBuxNcimfGO7Irf vNDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ho9NvHEq; 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 d25-20020a056402401900b004621e2c473dsi990987eda.354.2022.10.25.01.00.29; Tue, 25 Oct 2022 01:01:19 -0700 (PDT) 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=ho9NvHEq; 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 S231486AbiJYHTs (ORCPT + 99 others); Tue, 25 Oct 2022 03:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231629AbiJYHTd (ORCPT ); Tue, 25 Oct 2022 03:19:33 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5C012BE09 for ; Tue, 25 Oct 2022 00:19:30 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-360a7ff46c3so111050707b3.12 for ; Tue, 25 Oct 2022 00:19:30 -0700 (PDT) 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=KA5AmQjfCAbtpdHkGDjwVts9T7CuDkkry+0zPgKF0lM=; b=ho9NvHEqLfDplAjRx3uXKJiU3DoSROQtKqQ8jRhFd0Ck3bp2UOpw8N9lYdxjatKuYv co/P5Nk6CLcK/+U9EK4lL66rumOXMbWTwndY1+zqeBCGNIjWtMZexvP1r8fzZLGhIbkU URsp7CuLP4czyMYdx7nshdoj5wFvyKDgBctnpRho0U/7PipKMJWU+msjlZHwvoClSw6O EvgkK+rfUfDrf/fynysJgKuFNt/SnjNJ/7x0wc8t7u3GvmcbGHIzDOGamTDQO4RMxpdU hh8nQ1fXv3LVNN0nD4AItp5Or8XNWSODER0ITRmk2Az9YLODBHDSLXNZo3mhj/LYKCQs eyxw== 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=KA5AmQjfCAbtpdHkGDjwVts9T7CuDkkry+0zPgKF0lM=; b=MvJTt1GvyBc5fnPmee/coaae5ECv1CxyLCHGaon7dYwcNa4srNE93k44RQZ+lfkGSF 1GrC7R/P0r/OZCZY4GJcA1rkmRIL6RhEACTqgjyDzcyv5jnDjsZxLHJSjoERXRQ1BMz9 5gxMgSwEjgQscOOOmaSFTCDdPC8k4pLN5rilj4d+kRAkm2fa34evef3kap+neePdy9tJ 2WbX5pUz3dHP65bjztPTV56gpSGxFyUXzMClJqr3KdBpKvlc77ZQ7GRGgxikWZz635Ei 4l9D3ABJvwSExaHiL8zfuLQ0t904LOab3DgKoDlPSD78eLHA9Su7PVZ3ZeS74sAPIRMN BN0A== X-Gm-Message-State: ACrzQf26em5UTwTXzrdPnN2rWEmcFC9BpdkZfDcc6IGIadvBV5x4VmYW 6ZUCeI2r5yF3o7sBrRL2bUEmOBvZlU2J4g== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a81:6907:0:b0:34a:51ce:3b38 with SMTP id e7-20020a816907000000b0034a51ce3b38mr32787158ywc.151.1666682369948; Tue, 25 Oct 2022 00:19:29 -0700 (PDT) Date: Tue, 25 Oct 2022 15:19:07 +0800 In-Reply-To: <20221025071907.1251820-1-davidgow@google.com> Mime-Version: 1.0 References: <20221025071907.1251820-1-davidgow@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221025071907.1251820-3-davidgow@google.com> Subject: [PATCH v2 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 --- 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. Assuming there are no objections, we'll take this whole series via the kselftest/kunit tree. 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 --- lib/slub_kunit.c | 1 + mm/slub.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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..15d10d250ef2 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -603,10 +604,10 @@ static bool slab_add_kunit_errors(void) { struct kunit_resource *resource; - if (likely(!current->kunit_test)) + if (likely(!kunit_get_current_test())) return false; - resource = kunit_find_named_resource(current->kunit_test, "slab_errors"); + resource = kunit_find_named_resource(kunit_get_current_test(), "slab_errors"); if (!resource) return false; -- 2.38.0.135.g90850a2211-goog