Message ID | 20221019085747.3810920-1-davidgow@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp223502wrs; Wed, 19 Oct 2022 02:37:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5cd0dnYC9I+oOiUqRx9hHmOuXZo9jeo/4878ncgK6LEeqku0xjgZD4dXvDTHsAdHjgLNOA X-Received: by 2002:a05:6402:501a:b0:457:f093:cadb with SMTP id p26-20020a056402501a00b00457f093cadbmr6447972eda.143.1666172260808; Wed, 19 Oct 2022 02:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172260; cv=none; d=google.com; s=arc-20160816; b=z/pOXHhfQXR5venPe/6bQOI8oyZ5pMs0YMXmVtS0YCe+LIUb57X/K4PwJ5M5xAsRP8 3vrJndJBoAeNwsatWD0ReIL709+wYAW5QvAlEhaIYxWxLjMOf71J8B1L35JLy8BcoTUs tImLxa/k8Wth4zrHiwuWxjSXxMBWDvqvipCiCUwR1SvPahg8rvyqUR9LRVwtOn+egxgq 94CDvg9TGCb7mPTRvg0DnAfGLhCuBr2oCO73QmjPq3yfIns1w5hEwZqo6Re4du5oKb/S 617NwUAkaM+bxosjSbRPfmUG6s8vfXHMcnPfxZmNrBxx1KPYvbH8CR3aUYUJ55L5CTXu b1ZA== 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:mime-version:date :dkim-signature; bh=c8o2xpxs+RS4/DEwLn7pAvuoJ6D9DUOeVpcYY5/eGtA=; b=C6tYqHMzv8pdsMunbFq7L85sw3J7EaKU3RQjBesIH5TRPdj/Q92mCHypHHmM8oVCn2 2ymLz4N7Qi4lnSz+XXJE9sCOJWpObyzNLrg142/mI/8JJFOmoYbiwwsr80UvgPZiAkqX yPnEzmVhCXnWrzxQq60kq/fBj5mMBwW7zjlbgL/VVydXcgmqUqymf27c3MBOiKqaGBrF sDTujLd9DxpzFvw0cV6JWH9sWfQ1Guz/buVasLh9pVDK/R/It04hELngq70/OhRqbUDh jj35w34Q8zPeb8AJHSzIW9guTmBcojciGhqXSBjsuEXkvVRJcKTWTt2gd+HjENB0HEtC ZPTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=F3mCd7yV; 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 sa26-20020a1709076d1a00b007879bb73291si15479969ejc.807.2022.10.19.02.37.15; Wed, 19 Oct 2022 02:37:40 -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=F3mCd7yV; 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 S233394AbiJSJVO (ORCPT <rfc822;samuel.l.nystrom@gmail.com> + 99 others); Wed, 19 Oct 2022 05:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233669AbiJSJTw (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Oct 2022 05:19:52 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F85EB99 for <linux-kernel@vger.kernel.org>; Wed, 19 Oct 2022 02:09:26 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id d8-20020a25bc48000000b00680651cf051so15818763ybk.23 for <linux-kernel@vger.kernel.org>; Wed, 19 Oct 2022 02:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=c8o2xpxs+RS4/DEwLn7pAvuoJ6D9DUOeVpcYY5/eGtA=; b=F3mCd7yVd6lajsXX9epZlyUhkZrObRrxUMfGiDU0t6D3kwut7jdOK48H9qisPJA51i iCFAgxhoDJ42r43DvCgSDpgRrDgBlZwkZiz9AvDDHafW26hQs7uFA7qq7gl2HMUYFMFh CJOvcCKALlG4Mb4yyUedGPXUcMBOVqk5axA7oa5stpx5N7sCDK8+x07ahaNooWVSaWAr 2hJszbCIw4bNpft71Fa8Y6HfVUbPc+EN8nwVCLXVKpm3h+Lj+1iowwoXC6+ELpTQP1If CgV0yFgCoKdepX6w9owj7SUjb6ksCbz0LynTefYVRRooUpBOFdVUlTNNtBKVbjbf+uDr P2Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=c8o2xpxs+RS4/DEwLn7pAvuoJ6D9DUOeVpcYY5/eGtA=; b=Ccp/Vu1eZ21cZ/5PGmMr0nzHozZXERVQACaYHIOXHM1MjQQjk5nr7pKPagxzj4mzq+ r1Nu4U9Jd1PJv5jSKUpKGzdqLm9wAgWWl1LXcPK+F35Wtb3HYOi7RpJmvjAGugQwuoLh MNJoAA7Z3Mi7C0mAKqqo9zZZ0QNGbbeUy5c7XZnY9lVrxOu1mnXmlnHKwendJ5i4HfoL yFY26ZvzmgkNXDD0MfzggziJROqV8m80E2Rm+/99815sgVD5zUM0El1nUvGyNPIPawU/ 3gq/LJOPeawP8nRLAMXOaIRRDOpCPHCMsLkFYqBlRTfejnBCTKJ+lAptoAxvEwZfdWSd chUg== X-Gm-Message-State: ACrzQf00c2q8/5y551RHipnkAZ9Fl7ZGKvLVz46hBtvEOd9rQy3tiGTw 0/t3JuMi9oIkrMBG4F4Xyo6EPMb7Jr3U9g== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a0d:db52:0:b0:357:94ca:f32c with SMTP id d79-20020a0ddb52000000b0035794caf32cmr5703668ywe.25.1666169883452; Wed, 19 Oct 2022 01:58:03 -0700 (PDT) Date: Wed, 19 Oct 2022 16:57:48 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221019085747.3810920-1-davidgow@google.com> Subject: [PATCH] kasan: Enable KUnit integration whenever CONFIG_KUNIT is enabled From: David Gow <davidgow@google.com> To: Andrey Konovalov <andreyknvl@google.com>, Alexander Potapenko <glider@google.com>, Andrey Ryabinin <ryabinin.a.a@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Andrew Morton <akpm@linux-foundation.org> Cc: David Gow <davidgow@google.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Daniel Latypov <dlatypov@google.com>, Brendan Higgins <brendanhiggins@google.com>, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com 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=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747108244365019124?= X-GMAIL-MSGID: =?utf-8?q?1747108244365019124?= |
Series |
kasan: Enable KUnit integration whenever CONFIG_KUNIT is enabled
|
|
Commit Message
David Gow
Oct. 19, 2022, 8:57 a.m. UTC
Enable the KASAN/KUnit integration even when the KASAN tests are
disabled, as it's useful for testing other things under KASAN.
Essentially, this reverts commit 49d9977ac909 ("kasan: check CONFIG_KASAN_KUNIT_TEST instead of CONFIG_KUNIT").
To mitigate the performance impact slightly, add a likely() to the check
for a currently running test.
There's more we can do for performance if/when it becomes more of a
problem, such as only enabling the "expect a KASAN failure" support wif
the KASAN tests are enabled, or putting the whole thing behind a "kunit
tests are running" static branch (which I do plan to do eventually).
Fixes: 49d9977ac909 ("kasan: check CONFIG_KASAN_KUNIT_TEST instead of CONFIG_KUNIT")
Signed-off-by: David Gow <davidgow@google.com>
---
Basically, hiding the KASAN/KUnit integration broke being able to just
pass --kconfig_add CONFIG_KASAN=y to kunit_tool to enable KASAN
integration. We didn't notice this, because usually
CONFIG_KUNIT_ALL_TESTS is enabled, which in turn enables
CONFIG_KASAN_KUNIT_TEST. However, using a separate .kunitconfig might
result in failures being missed.
Take, for example:
./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_KASAN=y \
--kunitconfig drivers/gpu/drm/tests
This should run the drm tests with KASAN enabled, but even if there's a
KASAN failure (such as the one fixed by [1]), kunit_tool will report
success.
[1]: https://lore.kernel.org/dri-devel/20221019073239.3779180-1-davidgow@google.com/
---
mm/kasan/kasan.h | 2 +-
mm/kasan/report.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
Comments
On Wed, Oct 19, 2022 at 10:58 AM 'David Gow' via kasan-dev <kasan-dev@googlegroups.com> wrote: > > Enable the KASAN/KUnit integration even when the KASAN tests are > disabled, as it's useful for testing other things under KASAN. > Essentially, this reverts commit 49d9977ac909 ("kasan: check CONFIG_KASAN_KUNIT_TEST instead of CONFIG_KUNIT"). > > To mitigate the performance impact slightly, add a likely() to the check > for a currently running test. > > There's more we can do for performance if/when it becomes more of a > problem, such as only enabling the "expect a KASAN failure" support wif > the KASAN tests are enabled, or putting the whole thing behind a "kunit > tests are running" static branch (which I do plan to do eventually). > > Fixes: 49d9977ac909 ("kasan: check CONFIG_KASAN_KUNIT_TEST instead of CONFIG_KUNIT") > Signed-off-by: David Gow <davidgow@google.com> > --- > > Basically, hiding the KASAN/KUnit integration broke being able to just > pass --kconfig_add CONFIG_KASAN=y to kunit_tool to enable KASAN > integration. We didn't notice this, because usually > CONFIG_KUNIT_ALL_TESTS is enabled, which in turn enables > CONFIG_KASAN_KUNIT_TEST. However, using a separate .kunitconfig might > result in failures being missed. > > Take, for example: > ./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_KASAN=y \ > --kunitconfig drivers/gpu/drm/tests > > This should run the drm tests with KASAN enabled, but even if there's a > KASAN failure (such as the one fixed by [1]), kunit_tool will report > success. Hi David, How does KUnit detect a KASAN failure for other tests than the KASAN ones? I thought this was only implemented for KASAN tests. At least, I don't see any code querying kunit_kasan_status outside of KASAN tests. I'm currently switching KASAN tests from using KUnit resources to console tracepoints [1], and those patches will be in conflict with yours. Thanks! [1] https://lore.kernel.org/linux-mm/ebf96ea600050f00ed567e80505ae8f242633640.1666113393.git.andreyknvl@google.com/
On Wed, Oct 19, 2022 at 10:18 PM Andrey Konovalov <andreyknvl@gmail.com> wrote: > > On Wed, Oct 19, 2022 at 10:58 AM 'David Gow' via kasan-dev > <kasan-dev@googlegroups.com> wrote: > > > > Enable the KASAN/KUnit integration even when the KASAN tests are > > disabled, as it's useful for testing other things under KASAN. > > Essentially, this reverts commit 49d9977ac909 ("kasan: check CONFIG_KASAN_KUNIT_TEST instead of CONFIG_KUNIT"). > > > > To mitigate the performance impact slightly, add a likely() to the check > > for a currently running test. > > > > There's more we can do for performance if/when it becomes more of a > > problem, such as only enabling the "expect a KASAN failure" support wif > > the KASAN tests are enabled, or putting the whole thing behind a "kunit > > tests are running" static branch (which I do plan to do eventually). > > > > Fixes: 49d9977ac909 ("kasan: check CONFIG_KASAN_KUNIT_TEST instead of CONFIG_KUNIT") > > Signed-off-by: David Gow <davidgow@google.com> > > --- > > > > Basically, hiding the KASAN/KUnit integration broke being able to just > > pass --kconfig_add CONFIG_KASAN=y to kunit_tool to enable KASAN > > integration. We didn't notice this, because usually > > CONFIG_KUNIT_ALL_TESTS is enabled, which in turn enables > > CONFIG_KASAN_KUNIT_TEST. However, using a separate .kunitconfig might > > result in failures being missed. > > > > Take, for example: > > ./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_KASAN=y \ > > --kunitconfig drivers/gpu/drm/tests > > > > This should run the drm tests with KASAN enabled, but even if there's a > > KASAN failure (such as the one fixed by [1]), kunit_tool will report > > success. > > Hi David, > > How does KUnit detect a KASAN failure for other tests than the KASAN > ones? I thought this was only implemented for KASAN tests. At least, I > don't see any code querying kunit_kasan_status outside of KASAN tests. Yeah, there aren't any other tests which set up a "kasan_status" resource to expect specific failures, but we still want the fallback call to kunit_set_failure() so that any test which causes a KASAN report will fail: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/kasan/report.c#n130 > I'm currently switching KASAN tests from using KUnit resources to > console tracepoints [1], and those patches will be in conflict with > yours. Ah, sorry -- I'd seen these go past, and totally forgot about them! I think all we really want to keep is the ability to fail tests if a KASAN report occurs. The tricky bit is then disabling that for the KASAN tests, so that they can have "expected" failures. -- David
On Wed, Oct 19, 2022 at 5:06 PM David Gow <davidgow@google.com> wrote: > > > How does KUnit detect a KASAN failure for other tests than the KASAN > > ones? I thought this was only implemented for KASAN tests. At least, I > > don't see any code querying kunit_kasan_status outside of KASAN tests. > > Yeah, there aren't any other tests which set up a "kasan_status" > resource to expect specific failures, but we still want the fallback > call to kunit_set_failure() so that any test which causes a KASAN > report will fail: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/kasan/report.c#n130 Ah, right. Thanks for the explanation! > > I'm currently switching KASAN tests from using KUnit resources to > > console tracepoints [1], and those patches will be in conflict with > > yours. > > Ah, sorry -- I'd seen these go past, and totally forgot about them! I > think all we really want to keep is the ability to fail tests if a > KASAN report occurs. The tricky bit is then disabling that for the > KASAN tests, so that they can have "expected" failures. I wonder what's the best solution to support this, assuming KASAN tests are switched to using tracepoints... I guess we could still keep the per-task KUnit flag, and only use it for non-KASAN tests. However, they will still suffer from the same issue tracepoints solve for KASAN tests: if a bug is triggered in a context other than the current task, the test will succeed.
On Thu, Oct 20, 2022 at 3:48 AM Andrey Konovalov <andreyknvl@gmail.com> wrote: > > On Wed, Oct 19, 2022 at 5:06 PM David Gow <davidgow@google.com> wrote: > > > > > How does KUnit detect a KASAN failure for other tests than the KASAN > > > ones? I thought this was only implemented for KASAN tests. At least, I > > > don't see any code querying kunit_kasan_status outside of KASAN tests. > > > > Yeah, there aren't any other tests which set up a "kasan_status" > > resource to expect specific failures, but we still want the fallback > > call to kunit_set_failure() so that any test which causes a KASAN > > report will fail: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/kasan/report.c#n130 > > Ah, right. Thanks for the explanation! > > > > I'm currently switching KASAN tests from using KUnit resources to > > > console tracepoints [1], and those patches will be in conflict with > > > yours. > > > > Ah, sorry -- I'd seen these go past, and totally forgot about them! I > > think all we really want to keep is the ability to fail tests if a > > KASAN report occurs. The tricky bit is then disabling that for the > > KASAN tests, so that they can have "expected" failures. > > I wonder what's the best solution to support this, assuming KASAN > tests are switched to using tracepoints... I guess we could still keep > the per-task KUnit flag, and only use it for non-KASAN tests. However, > they will still suffer from the same issue tracepoints solve for KASAN > tests: if a bug is triggered in a context other than the current task, > the test will succeed. Yeah: I'm not sure what the perfect solution here is. Ideally, we'd have some good way to get the current test, which would work even in workqueues, rcu, etc. This affects more than just KASAN: there are quite a few different places where getting "the current test" is important. One option is just to use a global: we don't support running multiple simultaneous KUnit tests at all, at the moment. But, equally, it increases the possibility of false-positives if something non-test related needs to access the test structure. This is probably not too much of a problem for KASAN, but the function redirection features we're working on benefit quite a bit from those redirections not being enabled outside of the test. Thus far, we've just sort-of accepted that these don't work with tests which push work to other tasks, but it is sub-optimal. And even if KASAN moves to tracepoints, this problem doesn't totally go away, as you still need some way to know you're in the KASAN test to disable the "fail-test-on-KASAN-report" behaviour. I guess that could be some global flag triggered from the suite_init / suite_exit for the KASAN test, though. Cheers, -- David
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index abbcc1b0eec5..afacef14c7f4 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -261,7 +261,7 @@ struct kasan_stack_ring { #endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ -#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) +#if IS_ENABLED(CONFIG_KUNIT) /* Used in KUnit-compatible KASAN tests. */ struct kunit_kasan_status { bool report_found; diff --git a/mm/kasan/report.c b/mm/kasan/report.c index df3602062bfd..efa063b9d093 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -114,7 +114,7 @@ EXPORT_SYMBOL_GPL(kasan_restore_multi_shot); #endif -#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) +#if IS_ENABLED(CONFIG_KUNIT) static void update_kunit_status(bool sync) { struct kunit *test; @@ -122,7 +122,7 @@ static void update_kunit_status(bool sync) struct kunit_kasan_status *status; test = current->kunit_test; - if (!test) + if (likely(!test)) return; resource = kunit_find_named_resource(test, "kasan_status");