From patchwork Wed Oct 19 08:57:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gow X-Patchwork-Id: 13011487 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D76BAC4332F for ; Wed, 19 Oct 2022 08:58:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 242F76B0072; Wed, 19 Oct 2022 04:58:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F32D6B0073; Wed, 19 Oct 2022 04:58:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BB796B0074; Wed, 19 Oct 2022 04:58:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EEA536B0072 for ; Wed, 19 Oct 2022 04:58:04 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A9BAC80188 for ; Wed, 19 Oct 2022 08:58:04 +0000 (UTC) X-FDA: 80037096888.03.905A9AB Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf10.hostedemail.com (Postfix) with ESMTP id 58CBAC0020 for ; Wed, 19 Oct 2022 08:58:04 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id o4-20020a258d84000000b006bcfc1aafbdso15672492ybl.14 for ; Wed, 19 Oct 2022 01:58:04 -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=QIT63Y1sJS2lRd8txIY/kvxvSj9YYXiX280bsCSCxbCS9gqEz4b+sOt7Scz1H34mqP zrJPyaNqRYOevHgEHslb2tVbIA4r0h7/sBZfom/QVeC4lvcgnquwNmu362w1s1FhhCFA HcTmjpumGyPE4RO+gqB8RI0q/RZzro7TJI8JMbFu1DGw7PByH+EBDpauhK0en+uFB20U cMSl5GtHZxQP0ldJQzmNARwHMhGaJO234eQ36oWgdOZgklNv8LxCkLZjqbWVxj0flZzp 4BV/Ai8ZO0OkM+8H0Yp78GgInfJ7sq1DHVZJcEyTZDCSBIqUV3QRm7om24heAnYx0fzg 5RnQ== X-Gm-Message-State: ACrzQf2fr6uZHmJvW/8CLryXMnfS2B8KeyI1RiMTFLfvpyMwh76JH94C kBp59mmW9UrgGg/R8yFOJKQng673PbBBpQ== X-Google-Smtp-Source: AMsMyM5VOZZdASm5LNMbolLRFDxxLsXPcEV4v6v1/18NPIwxSshF2mz0iRTuqjx/f9yBzqJejifAb3wMZ6mTdw== 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 To: Andrey Konovalov , Alexander Potapenko , Andrey Ryabinin , Dmitry Vyukov , Andrew Morton Cc: David Gow , Vincenzo Frascino , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Daniel Latypov , Brendan Higgins , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=F3mCd7yV; spf=pass (imf10.hostedemail.com: domain of 3G7xPYwgKCPIXUpcXaiqaiiafY.Wigfchor-ggepUWe.ila@flex--davidgow.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3G7xPYwgKCPIXUpcXaiqaiiafY.Wigfchor-ggepUWe.ila@flex--davidgow.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666169884; a=rsa-sha256; cv=none; b=uw8spx8J15hVtV7koCHtObJtkOGZrV8TiBtaN8VdbLlNkdF2/l4Xwcl1s86fAUVCPRQqbN 2+Vs/U9RmclnBPohB/AtQvKYOhJAHPG+CTJ+39g5mge4zN+T9aErSSOrIEHoL3kOONqZaV oysoYYHogggkdISnAYwQbxpsHVztoRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666169884; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=c8o2xpxs+RS4/DEwLn7pAvuoJ6D9DUOeVpcYY5/eGtA=; b=MgegtsEN7BPlFnnN5s+IeSgOCr3fewuouuVgkvPvmsC7xA3xM7uFc3wJivh8eS3m8TDO3l iGDABZbLsVU+TAc2HZBDJ9bRgcmcdr1eCqQRtveWkYtOca1fukjkps55a+Bo9aQJ/0PV/D un3NPOIJOuejJzZlxv4SqgVdam99ORQ= X-Stat-Signature: 7hmihj51c3q4rgyfirfafp5f168fsouy X-Rspamd-Queue-Id: 58CBAC0020 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=F3mCd7yV; spf=pass (imf10.hostedemail.com: domain of 3G7xPYwgKCPIXUpcXaiqaiiafY.Wigfchor-ggepUWe.ila@flex--davidgow.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3G7xPYwgKCPIXUpcXaiqaiiafY.Wigfchor-ggepUWe.ila@flex--davidgow.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1666169884-669564 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- 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(-) 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");