From patchwork Tue Oct 25 07:19:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 10550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp859912wru; Tue, 25 Oct 2022 00:33:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM66/G+/ikp+tqtJEQLz0Na5IwziiqLzW0Wos1tMx8QokvSGpPcsena0jA0kkzq6YGjdmq9d X-Received: by 2002:a17:903:40cb:b0:17f:6e08:6eac with SMTP id t11-20020a17090340cb00b0017f6e086eacmr37531102pld.80.1666683229724; Tue, 25 Oct 2022 00:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666683229; cv=none; d=google.com; s=arc-20160816; b=s2RO5Y7LYyzTIi1NotHAIb5kUNHCLs3A33aGXnz9nDt07WaO68eTtqWR6RByXtcG6N IFfDQJVMpDDnCRgpLKRvVQ3NOkb3SKaRGLV530bvKG3KrqadJrmmKoKjnmv2FseG1+UN ptPUECcctnpDqkdzTKiC9nsqksCMxvYAXb0pJgyC118TcFXGloo+PLxSUQcP2GjHz+6v 61WoAzIkRFYqg1am3L/+Qt5gBfGhMteRK9RRJY86v8Z9WiVXTZEM9F6FiudNY+1hzh2m unmAspevxVSF3Y6cSxDRH84S9HyQd79pKHc3FdF2MudHJ5qljuZ5rbOmCVt68C5mp0r6 n/sg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a170902d88d00b001868ef35f09si2198858plz.258.2022.10.25.00.33.36; Tue, 25 Oct 2022 00:33:49 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747644034753459694?= X-GMAIL-MSGID: =?utf-8?q?1747644034753459694?= 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. 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;