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: 628731 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BDC2C4321E for ; Fri, 25 Nov 2022 08:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbiKYInh (ORCPT ); Fri, 25 Nov 2022 03:43:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbiKYIn1 (ORCPT ); Fri, 25 Nov 2022 03:43:27 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84BC721E2D for ; Fri, 25 Nov 2022 00:43:24 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id my9-20020a17090b4c8900b002130d29fd7cso5163639pjb.7 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=2abhKLDlLIKIc+DsqvKKwRcjJ39dISkN9spYu528BpEqhXPvkdV64azfDvYklZMwe+ Ri6NVKucnTQWQQazajLEMbNhhtF8O5gYySrNd7zI1A7ttBy71mWIatBBEHtaKbKDw3j8 RZqMm57kLrZTbiLXkyFg0E4kqjAj7nmrYW/cZfLjjSOykmbhUfuFiWh6zZb9pInacMff gO9kmS/fA7xIwxQUKFVcsJ3TwEnQUC651r9Kke0+Oa7GCJHHSOKCbm5qNhZKjBcFgVW4 zH+xw2+bTbcplvsy9qZ9tIOpGP2PVuZkHbhSP0IEUuUakJCVAzpxVbKdF1vNtW2HyEMe bDdA== X-Gm-Message-State: ANoB5pnYIC2lYgeRvYOE5l8zqeOctvwC99zjuDvXB+JXJp/h0Nwn+IUT XHKnGiHq57dH9MgAinfM1sEXkOBwOJKJaA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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 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");