From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4122D116F1 for ; Fri, 28 Nov 2025 03:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=G3gPrOC7MauvGRj4YbxCiDaSAJrqi5DShDaS5sFXKjg=; b=qLdX9auWzAOCcAkaYPIqkGqQgh 9a61Dc1D9UAApaEguLQmSXlnDta0+Kplbzg7Tv4zVO5ZNOxoRT1SS4OUokPpPiw8Eah5SkUZyj6Y1 WQsOcrwGkMObRxhMmSpfuFlnSutI4BxsJdh3JuI+o8dRfDnZov3h53FbDYnLdBTaihppQ09CH9uzw cDRa4bWGNWaXrYKfEQPRIA2kWwB6lqLSiCagmWagBO5qDV3ethXmER4VY2d0exb6odVeSXPqLKOyX aeOim75N0T9fV6l2PQUgsQgZP3/V70HYWkVWsaDpJ6sHqcd1VtHymh/qvPdjq23ErOTPLiM+Z7gNY rkbrzBMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vOpFC-0000000HWYO-0oIV; Fri, 28 Nov 2025 03:34:02 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vOpF8-0000000HWXI-3WS8 for kexec@lists.infradead.org; Fri, 28 Nov 2025 03:34:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764300837; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G3gPrOC7MauvGRj4YbxCiDaSAJrqi5DShDaS5sFXKjg=; b=HcBLVzaQ7LU+pS/W9VCUD5Yo/tQmye62QiFK7yEgDbUJskZTkUbePEF5vtw8caYr2JINvw rxFL48jisQCsouaYfDU45jMzO0Zx9pDFz/27BB/UL5smaRUe+GoXOTXUXVDtO9nDQuPRIO lgpcD70mA5EJBHzI58cAOMr6E8FSK4I= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-346-uEumHcseO-e49imQKWSn1w-1; Thu, 27 Nov 2025 22:33:55 -0500 X-MC-Unique: uEumHcseO-e49imQKWSn1w-1 X-Mimecast-MFC-AGG-ID: uEumHcseO-e49imQKWSn1w_1764300833 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 657891956088; Fri, 28 Nov 2025 03:33:52 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.7]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A23FA19560B0; Fri, 28 Nov 2025 03:33:44 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, andreyknvl@gmail.com, glider@google.com, dvyukov@google.com, vincenzo.frascino@arm.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, elver@google.com, sj@kernel.org, lorenzo.stoakes@oracle.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He Subject: [PATCH v4 02/12] mm/kasan: move kasan= code to common place Date: Fri, 28 Nov 2025 11:33:10 +0800 Message-ID: <20251128033320.1349620-3-bhe@redhat.com> In-Reply-To: <20251128033320.1349620-1-bhe@redhat.com> References: <20251128033320.1349620-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251127_193359_937897_C5846DA1 X-CRM114-Status: GOOD ( 14.43 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org This allows generic and sw_tags to be set in kernel cmdline too. When at it, rename 'kasan_arg' to 'kasan_arg_disabled' as a bool variable. And expose 'kasan_flag_enabled' to kasan common place too. This is prepared for later adding kernel parameter kasan=on|off for all three kasan modes. Signed-off-by: Baoquan He --- include/linux/kasan-enabled.h | 4 +++- mm/kasan/common.c | 20 ++++++++++++++++++-- mm/kasan/hw_tags.c | 28 ++-------------------------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/include/linux/kasan-enabled.h b/include/linux/kasan-enabled.h index 9eca967d8526..b05ec6329fbe 100644 --- a/include/linux/kasan-enabled.h +++ b/include/linux/kasan-enabled.h @@ -4,13 +4,15 @@ #include -#if defined(CONFIG_ARCH_DEFER_KASAN) || defined(CONFIG_KASAN_HW_TAGS) +extern bool kasan_arg_disabled; + /* * Global runtime flag for KASAN modes that need runtime control. * Used by ARCH_DEFER_KASAN architectures and HW_TAGS mode. */ DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); +#if defined(CONFIG_ARCH_DEFER_KASAN) || defined(CONFIG_KASAN_HW_TAGS) /* * Runtime control for shadow memory initialization or HW_TAGS mode. * Uses static key for architectures that need deferred KASAN or HW_TAGS. diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 1d27f1bd260b..ac14956986ee 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -32,14 +32,30 @@ #include "kasan.h" #include "../slab.h" -#if defined(CONFIG_ARCH_DEFER_KASAN) || defined(CONFIG_KASAN_HW_TAGS) /* * Definition of the unified static key declared in kasan-enabled.h. * This provides consistent runtime enable/disable across KASAN modes. */ DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled); EXPORT_SYMBOL_GPL(kasan_flag_enabled); -#endif + +bool kasan_arg_disabled __ro_after_init; +/* kasan=off/on */ +static int __init early_kasan_flag(char *arg) +{ + if (!arg) + return -EINVAL; + + if (!strcmp(arg, "off")) + kasan_arg_disabled = true; + else if (!strcmp(arg, "on")) + kasan_arg_disabled = false; + else + return -EINVAL; + + return 0; +} +early_param("kasan", early_kasan_flag); struct slab *kasan_addr_to_slab(const void *addr) { diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 1c373cc4b3fa..709c91abc1b1 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -22,12 +22,6 @@ #include "kasan.h" -enum kasan_arg { - KASAN_ARG_DEFAULT, - KASAN_ARG_OFF, - KASAN_ARG_ON, -}; - enum kasan_arg_mode { KASAN_ARG_MODE_DEFAULT, KASAN_ARG_MODE_SYNC, @@ -41,7 +35,6 @@ enum kasan_arg_vmalloc { KASAN_ARG_VMALLOC_ON, }; -static enum kasan_arg kasan_arg __ro_after_init; static enum kasan_arg_mode kasan_arg_mode __ro_after_init; static enum kasan_arg_vmalloc kasan_arg_vmalloc __initdata; @@ -81,23 +74,6 @@ unsigned int kasan_page_alloc_sample_order = PAGE_ALLOC_SAMPLE_ORDER_DEFAULT; DEFINE_PER_CPU(long, kasan_page_alloc_skip); -/* kasan=off/on */ -static int __init early_kasan_flag(char *arg) -{ - if (!arg) - return -EINVAL; - - if (!strcmp(arg, "off")) - kasan_arg = KASAN_ARG_OFF; - else if (!strcmp(arg, "on")) - kasan_arg = KASAN_ARG_ON; - else - return -EINVAL; - - return 0; -} -early_param("kasan", early_kasan_flag); - /* kasan.mode=sync/async/asymm */ static int __init early_kasan_mode(char *arg) { @@ -222,7 +198,7 @@ void kasan_init_hw_tags_cpu(void) * When this function is called, kasan_flag_enabled is not yet * set by kasan_init_hw_tags(). Thus, check kasan_arg instead. */ - if (kasan_arg == KASAN_ARG_OFF) + if (kasan_arg_disabled) return; /* @@ -240,7 +216,7 @@ void __init kasan_init_hw_tags(void) return; /* If KASAN is disabled via command line, don't initialize it. */ - if (kasan_arg == KASAN_ARG_OFF) + if (kasan_arg_disabled) return; switch (kasan_arg_mode) { -- 2.41.0