From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5EB32853FD for ; Wed, 20 Aug 2025 05:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668128; cv=none; b=FOZ9K+uDeAHHg1NH+arapJxcLRULbZUFgPo4rivK0m3qJn0dnLeSqnKEc+2BcQVAG1jUkkGijpQOPrNgibfZj82H1WhRdKkNcb0HMgNN3TUqu0PwP3zP6hUqGwmSmcqCpKzjvBUq9FMwzzET3/8VnWfyejRqIOEL78d1czkmktA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668128; c=relaxed/simple; bh=8jk0i++LAnDk3WELsHB9+3LcJrHqFyRw/1w+tpO9zNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=JMZ5Yc0cdbDxd6ysl2MsOkJx9PqYVQBYVCcyK0TUM/4MV/w8WwsFyrk3WDhXSWo8U0W3TZH6HexfZqfXgWUP5F+szZnfXq8Mh20lRpfptTOWzahZ2Zcck60P/cgvpYu0JIogdwThrl7pJQ0Uiggr24YSMcHDlm6btda5ZZqXN/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Evg/cT82; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Evg/cT82" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668125; 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=nAFiQLTxZfWIjT2BgzBfUHBH1TsYFyFlhKTQvwrw4NE=; b=Evg/cT82UOS/g4LoLlWfxz2EVeDJiR8rQXpf6PKYvn+D7xxeRkKU4wYPj+1auf0+5K0uio DdiMBTTxlr415Cf44j0dadeZUAjFI8hmOYKyOjNss6wS9Xvg0u0ERhF/YdPQnJDxdhLJTm Fz4TsgrOxFhW56kzm7QEWYNF1EiWyIM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-185-SZJqQwM0MQieMhFfhK9-vw-1; Wed, 20 Aug 2025 01:35:22 -0400 X-MC-Unique: SZJqQwM0MQieMhFfhK9-vw-1 X-Mimecast-MFC-AGG-ID: SZJqQwM0MQieMhFfhK9-vw_1755668120 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B55A11800357; Wed, 20 Aug 2025 05:35:19 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1D33719560B6; Wed, 20 Aug 2025 05:35:11 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He Subject: [PATCH v3 01/12] mm/kasan: add conditional checks in functions to return directly if kasan is disabled Date: Wed, 20 Aug 2025 13:34:48 +0800 Message-ID: <20250820053459.164825-2-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" The current code only does the check if kasan is disabled for hw_tags mode. Here add the conditional checks for functional functions of generic mode and sw_tags mode. This is prepared for later adding kernel parameter kasan=3Don|off for all kasan modes. Signed-off-by: Baoquan He --- mm/kasan/generic.c | 20 ++++++++++++++++++-- mm/kasan/init.c | 6 ++++++ mm/kasan/quarantine.c | 3 +++ mm/kasan/report.c | 4 +++- mm/kasan/shadow.c | 23 ++++++++++++++++++++++- mm/kasan/sw_tags.c | 3 +++ 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index d54e89f8c3e7..8daea5892754 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -165,6 +165,9 @@ static __always_inline bool check_region_inline(const v= oid *addr, size_t size, bool write, unsigned long ret_ip) { + if (!kasan_enabled()) + return true; + if (!kasan_arch_is_ready()) return true; =20 @@ -203,12 +206,13 @@ bool kasan_byte_accessible(const void *addr) =20 void kasan_cache_shrink(struct kmem_cache *cache) { - kasan_quarantine_remove_cache(cache); + if (kasan_enabled()) + kasan_quarantine_remove_cache(cache); } =20 void kasan_cache_shutdown(struct kmem_cache *cache) { - if (!__kmem_cache_empty(cache)) + if (kasan_enabled() && !__kmem_cache_empty(cache)) kasan_quarantine_remove_cache(cache); } =20 @@ -228,6 +232,9 @@ void __asan_register_globals(void *ptr, ssize_t size) int i; struct kasan_global *globals =3D ptr; =20 + if (!kasan_enabled()) + return; + for (i =3D 0; i < size; i++) register_global(&globals[i]); } @@ -358,6 +365,9 @@ void kasan_cache_create(struct kmem_cache *cache, unsig= ned int *size, unsigned int rem_free_meta_size; unsigned int orig_alloc_meta_offset; =20 + if (!kasan_enabled()) + return; + if (!kasan_requires_meta()) return; =20 @@ -510,6 +520,9 @@ size_t kasan_metadata_size(struct kmem_cache *cache, bo= ol in_object) { struct kasan_cache *info =3D &cache->kasan_info; =20 + if (!kasan_enabled()) + return 0; + if (!kasan_requires_meta()) return 0; =20 @@ -535,6 +548,9 @@ void kasan_record_aux_stack(void *addr) struct kasan_alloc_meta *alloc_meta; void *object; =20 + if (!kasan_enabled()) + return; + if (is_kfence_address(addr) || !slab) return; =20 diff --git a/mm/kasan/init.c b/mm/kasan/init.c index ced6b29fcf76..43d95f329675 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -449,6 +449,9 @@ void kasan_remove_zero_shadow(void *start, unsigned lon= g size) unsigned long addr, end, next; pgd_t *pgd; =20 + if (!kasan_enabled()) + return; + addr =3D (unsigned long)kasan_mem_to_shadow(start); end =3D addr + (size >> KASAN_SHADOW_SCALE_SHIFT); =20 @@ -484,6 +487,9 @@ int kasan_add_zero_shadow(void *start, unsigned long si= ze) int ret; void *shadow_start, *shadow_end; =20 + if (!kasan_enabled()) + return 0; + shadow_start =3D kasan_mem_to_shadow(start); shadow_end =3D shadow_start + (size >> KASAN_SHADOW_SCALE_SHIFT); =20 diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 6958aa713c67..a6dc2c3d8a15 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -405,6 +405,9 @@ static int __init kasan_cpu_quarantine_init(void) { int ret =3D 0; =20 + if (!kasan_enabled()) + return 0; + ret =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mm/kasan:online", kasan_cpu_online, kasan_cpu_offline); if (ret < 0) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 62c01b4527eb..884357fa74ed 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -576,7 +576,9 @@ bool kasan_report(const void *addr, size_t size, bool i= s_write, unsigned long irq_flags; struct kasan_report_info info; =20 - if (unlikely(report_suppressed_sw()) || unlikely(!report_enabled())) { + if (unlikely(report_suppressed_sw()) || + unlikely(!report_enabled()) || + !kasan_enabled()) { ret =3D false; goto out; } diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index d2c70cd2afb1..637f2d02d2a3 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -125,6 +125,9 @@ void kasan_poison(const void *addr, size_t size, u8 val= ue, bool init) { void *shadow_start, *shadow_end; =20 + if (!kasan_enabled()) + return; + if (!kasan_arch_is_ready()) return; =20 @@ -150,6 +153,9 @@ EXPORT_SYMBOL_GPL(kasan_poison); #ifdef CONFIG_KASAN_GENERIC void kasan_poison_last_granule(const void *addr, size_t size) { + if (!kasan_enabled()) + return; + if (!kasan_arch_is_ready()) return; =20 @@ -164,6 +170,8 @@ void kasan_unpoison(const void *addr, size_t size, bool= init) { u8 tag =3D get_tag(addr); =20 + if (!kasan_enabled()) + return; /* * Perform shadow offset calculation based on untagged address, as * some of the callers (e.g. kasan_unpoison_new_object) pass tagged @@ -277,7 +285,8 @@ static int __meminit kasan_mem_notifier(struct notifier= _block *nb, =20 static int __init kasan_memhotplug_init(void) { - hotplug_memory_notifier(kasan_mem_notifier, DEFAULT_CALLBACK_PRI); + if (kasan_enabled()) + hotplug_memory_notifier(kasan_mem_notifier, DEFAULT_CALLBACK_PRI); =20 return 0; } @@ -390,6 +399,9 @@ int kasan_populate_vmalloc(unsigned long addr, unsigned= long size) unsigned long shadow_start, shadow_end; int ret; =20 + if (!kasan_enabled()) + return 0; + if (!kasan_arch_is_ready()) return 0; =20 @@ -560,6 +572,9 @@ void kasan_release_vmalloc(unsigned long start, unsigne= d long end, unsigned long region_start, region_end; unsigned long size; =20 + if (!kasan_enabled()) + return; + if (!kasan_arch_is_ready()) return; =20 @@ -655,6 +670,9 @@ int kasan_alloc_module_shadow(void *addr, size_t size, = gfp_t gfp_mask) size_t shadow_size; unsigned long shadow_start; =20 + if (!kasan_enabled()) + return 0; + shadow_start =3D (unsigned long)kasan_mem_to_shadow(addr); scaled_size =3D (size + KASAN_GRANULE_SIZE - 1) >> KASAN_SHADOW_SCALE_SHIFT; @@ -691,6 +709,9 @@ int kasan_alloc_module_shadow(void *addr, size_t size, = gfp_t gfp_mask) =20 void kasan_free_module_shadow(const struct vm_struct *vm) { + if (!kasan_enabled()) + return; + if (IS_ENABLED(CONFIG_UML)) return; =20 diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index b9382b5b6a37..01f19bc4a326 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -78,6 +78,9 @@ bool kasan_check_range(const void *addr, size_t size, boo= l write, u8 *shadow_first, *shadow_last, *shadow; void *untagged_addr; =20 + if (!kasan_enabled()) + return true; + if (unlikely(size =3D=3D 0)) return true; =20 --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6209229A31D for ; Wed, 20 Aug 2025 05:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668138; cv=none; b=fXA1E0ldJddc3Ju/q1MkKUTnhx0CfEAbUAe9Q9APEjwFBNxyig3EnT0Fb9XgpSSNT5La1NHgq0XFbp0DjbzNLwnEN5QpykeDYRh7DGL8Q/1n/IjeagzfklYkGThECaJNvc1bI/1K6Kadwwla1B7wV25CsPoJFaK/filDBHiUFVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668138; c=relaxed/simple; bh=h6m1ZsJcKFolp9C+2kbISmGQqzGwk5a/sU+SlCjFBEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=KA8SmCaPtoI+tYuY8YkDo52ETUOclZB6VZw/m1Gb3rVHXZhWySgR6zlJb1C5zughl2+AYulFpZ4en4bCJqXm+4n0N7cgGoWqPHJZzjzQocyUaz2Pi2ReyY/M9U0Uw2yml6vQpWXZLhuNhNaXKHuzH2ti5AgCjQsuz+/XsXdsyQw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HG6f2u37; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HG6f2u37" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668135; 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=oEDfd5YwQwP//qNNRp60/4j9gVHcNuQdiFWm+KANNic=; b=HG6f2u37ZuywLlwjAbvwmKYvoP7hZldHshs4axxaYtrtww1dW+GVnUuYblqSpkfkqcPMwb 4fJWrUphWXziQLQ6dQ0WvQSoa8a70B3BepkC21yVnCvwKN7+OpIhbtvEIM0LbyLnB7yCsG +CXoXN6PWq6RWDXhBSJorCi5982tSH8= Received: from mx-prod-mc-01.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-210-apjXEsCbN2uozEJ6S1Khlg-1; Wed, 20 Aug 2025 01:35:31 -0400 X-MC-Unique: apjXEsCbN2uozEJ6S1Khlg-1 X-Mimecast-MFC-AGG-ID: apjXEsCbN2uozEJ6S1Khlg_1755668129 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D44CC1954203; Wed, 20 Aug 2025 05:35:28 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9B85D19560B0; Wed, 20 Aug 2025 05:35:20 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He Subject: [PATCH v3 02/12] mm/kasan: move kasan= code to common place Date: Wed, 20 Aug 2025 13:34:49 +0800 Message-ID: <20250820053459.164825-3-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" 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=3Don|off for all kasan modes. Signed-off-by: Baoquan He --- include/linux/kasan-enabled.h | 4 +++- mm/kasan/common.c | 25 +++++++++++++++++++++++++ mm/kasan/hw_tags.c | 35 ++--------------------------------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/include/linux/kasan-enabled.h b/include/linux/kasan-enabled.h index 6f612d69ea0c..32f2d19f599f 100644 --- a/include/linux/kasan-enabled.h +++ b/include/linux/kasan-enabled.h @@ -4,10 +4,12 @@ =20 #include =20 -#ifdef CONFIG_KASAN_HW_TAGS +extern bool kasan_arg_disabled; =20 DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); =20 +#ifdef CONFIG_KASAN_HW_TAGS + static __always_inline bool kasan_enabled(void) { return static_branch_likely(&kasan_flag_enabled); diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 9142964ab9c9..69a848f2a8aa 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -32,6 +32,31 @@ #include "kasan.h" #include "../slab.h" =20 +/* + * Whether KASAN is enabled at all. + * The value remains false until KASAN is initialized. + */ +DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled); +EXPORT_SYMBOL(kasan_flag_enabled); + +bool kasan_arg_disabled __ro_after_init; +/* kasan=3Doff/on */ +static int __init early_kasan_flag(char *arg) +{ + if (!arg) + return -EINVAL; + + if (!strcmp(arg, "off")) + kasan_arg_disabled =3D true; + else if (!strcmp(arg, "on")) + kasan_arg_disabled =3D false; + else + return -EINVAL; + + return 0; +} +early_param("kasan", early_kasan_flag); + struct slab *kasan_addr_to_slab(const void *addr) { if (virt_addr_valid(addr)) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 9a6927394b54..377e9c285a74 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -22,12 +22,6 @@ =20 #include "kasan.h" =20 -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,17 +35,9 @@ enum kasan_arg_vmalloc { KASAN_ARG_VMALLOC_ON, }; =20 -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; =20 -/* - * Whether KASAN is enabled at all. - * The value remains false until KASAN is initialized by kasan_init_hw_tag= s(). - */ -DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled); -EXPORT_SYMBOL(kasan_flag_enabled); - /* * Whether the selected mode is synchronous, asynchronous, or asymmetric. * Defaults to KASAN_MODE_SYNC. @@ -85,23 +71,6 @@ unsigned int kasan_page_alloc_sample_order =3D PAGE_ALLO= C_SAMPLE_ORDER_DEFAULT; =20 DEFINE_PER_CPU(long, kasan_page_alloc_skip); =20 -/* kasan=3Doff/on */ -static int __init early_kasan_flag(char *arg) -{ - if (!arg) - return -EINVAL; - - if (!strcmp(arg, "off")) - kasan_arg =3D KASAN_ARG_OFF; - else if (!strcmp(arg, "on")) - kasan_arg =3D KASAN_ARG_ON; - else - return -EINVAL; - - return 0; -} -early_param("kasan", early_kasan_flag); - /* kasan.mode=3Dsync/async/asymm */ static int __init early_kasan_mode(char *arg) { @@ -209,7 +178,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 =3D=3D KASAN_ARG_OFF) + if (kasan_arg_disabled) return; =20 /* @@ -227,7 +196,7 @@ void __init kasan_init_hw_tags(void) return; =20 /* If KASAN is disabled via command line, don't initialize it. */ - if (kasan_arg =3D=3D KASAN_ARG_OFF) + if (kasan_arg_disabled) return; =20 switch (kasan_arg_mode) { --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B8DD29ACFC for ; Wed, 20 Aug 2025 05:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668150; cv=none; b=nUXNB3UqMlPmJLlKyO6Kw/iDk9u1rYyIylmtNcJwwtWk+7auXjKU1UFsbQIYpzRmftZOa5Bf30dxtMRoDBrztuqnAe6vJOLf+8t9gMUqa56Lwq7QRERvlqtn5CH61HfWRtpzNRZjbh8q8D4/GRGJXvY91Xhjevqyl99U2Cf3nvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668150; c=relaxed/simple; bh=YgopKzfR0IJfsyEXF1E1nafRos8bsFb6WfDl5GYGKuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=PI4G89sSOhBhYaR+XExpkCiInirjvrO7mMaaRGLU9FOYVy7/kV26sY2LVQrWlN1GHMjOEIcJ6P05Imx+y6jD9sOtLeFDN/3h5ROtmpFqZCDctVUKm+2SIRxXsGIlfo8EZS635Qkc/Ji/vOk9rVjv3VtMECaqJn+4WKlRPs5botM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bjW5uPIB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bjW5uPIB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668147; 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=lC7gxKLfCffY1/zE+RJo3yBumyZwu5V9Ft7avRiVVTY=; b=bjW5uPIBiR4bX9pUlJOHPjh899t6QWLhLkO5+zw1cw/qucaeVegZSV6kAl1+8pK/0TJCcz Jr0QZXScOkJLvdQfiQu+MqXCtATPRfJolw1HdeaJn2D6ioY5M5kIv5qGtcgXXHvVDw3pst ZGJ6loTk8YWJ/SoMlejhRx0UzHXX66g= Received: from mx-prod-mc-01.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-265-6LzTzuBZPxSmLJLuVYPWIw-1; Wed, 20 Aug 2025 01:35:41 -0400 X-MC-Unique: 6LzTzuBZPxSmLJLuVYPWIw-1 X-Mimecast-MFC-AGG-ID: 6LzTzuBZPxSmLJLuVYPWIw_1755668139 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4AE39195422A; Wed, 20 Aug 2025 05:35:39 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9FD9E19560B0; Wed, 20 Aug 2025 05:35:29 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He Subject: [PATCH v3 03/12] mm/kasan/sw_tags: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:50 +0800 Message-ID: <20250820053459.164825-4-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" And also add code to enable kasan_flag_enabled, this is for later usage. Signed-off-by: Baoquan He --- mm/kasan/sw_tags.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index 01f19bc4a326..dd963ba4d143 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -40,11 +40,17 @@ void __init kasan_init_sw_tags(void) { int cpu; =20 + if (kasan_arg_disabled) + return; + for_each_possible_cpu(cpu) per_cpu(prng_state, cpu) =3D (u32)get_cycles(); =20 kasan_init_tags(); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + pr_info("KernelAddressSanitizer initialized (sw-tags, stacktrace=3D%s)\n", str_on_off(kasan_stack_collection_enabled())); } --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 946592BE632 for ; Wed, 20 Aug 2025 05:35:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668157; cv=none; b=GKzgurV+W87LBBIj0tTiU3vKhXB9IFAT76vws/gVxpGQXE2gfpviAgGIWqC18Xi00WKLD73mLssQD/sMEiSOWvo276hLrZ+/jMZ5Q21qYdab5dRY+o9L8jvozUYY8CHT1WkIOXJ+99lmlHhGHWJMroy3R9GG32xaMU2iJ75oP+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668157; c=relaxed/simple; bh=YqqkOZ2kEmobvVTDdFZuoNOpAwq1Fr8M4BEbVdpauFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=b5HTdUp7qN1GjjsGONWz/4I5ZMuva/IzZ6HPtrxqvx5IAQp5GV6ElNWmQ2JZUfzD4TuFEO4VRiUH9jTFZKqzEwz/yFfi8ncmwKwd67sEBK1yPywrTRC8c5EoPR7+5EHN12uC3YKmaTvcB9UPm/enPzfpwEdnpX193AUUtQuPR1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=isoIv17x; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="isoIv17x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668154; 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=1F98A6khDpxH5CCRtSbMqyknw7kFB7aw/3wgsldUGho=; b=isoIv17xBrqPe+YSqST2wTcyWWWcSP+un5a24FoBgk+BlcyEzIChik135ubmZVGRGYHKOr dullsN+2CgJZP3ZTY33G8xMDDmToVd/MTGY4tgtfCaJebL0jZnD+p2c63CmyhwA3B8TTn/ joA2bY5Kzm2u/Ztuiupymz2Mz6pmPx8= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-xEr3pfhWP_q7Ci4sKv6iNA-1; Wed, 20 Aug 2025 01:35:51 -0400 X-MC-Unique: xEr3pfhWP_q7Ci4sKv6iNA-1 X-Mimecast-MFC-AGG-ID: xEr3pfhWP_q7Ci4sKv6iNA_1755668149 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AFD7918004A7; Wed, 20 Aug 2025 05:35:48 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 178F519560B0; Wed, 20 Aug 2025 05:35:39 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He , linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 04/12] arch/arm: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:51 +0800 Message-ID: <20250820053459.164825-5-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" And also add code to enable kasan_flag_enabled, this is for later usage. Here call jump_label_init() early in setup_arch() so that later kasan_init() can enable static key kasan_flag_enabled. Put jump_label_init() beofre parse_early_param() as other architectures do. Signed-off-by: Baoquan He Cc: linux-arm-kernel@lists.infradead.org --- arch/arm/kernel/setup.c | 6 ++++++ arch/arm/mm/kasan_init.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 0bfd66c7ada0..453a47a4c715 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -1135,6 +1135,12 @@ void __init setup_arch(char **cmdline_p) early_fixmap_init(); early_ioremap_init(); =20 + /* + * Initialise the static keys early as they may be enabled by the + * kasan_init() or early parameters. + */ + jump_label_init(); + parse_early_param(); =20 #ifdef CONFIG_MMU diff --git a/arch/arm/mm/kasan_init.c b/arch/arm/mm/kasan_init.c index 111d4f703136..c764e1b9c9c5 100644 --- a/arch/arm/mm/kasan_init.c +++ b/arch/arm/mm/kasan_init.c @@ -212,6 +212,8 @@ void __init kasan_init(void) phys_addr_t pa_start, pa_end; u64 i; =20 + if (kasan_arg_disabled) + return; /* * We are going to perform proper setup of shadow memory. * @@ -300,6 +302,10 @@ void __init kasan_init(void) local_flush_tlb_all(); =20 memset(kasan_early_shadow_page, 0, PAGE_SIZE); + + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + pr_info("Kernel address sanitizer initialized\n"); init_task.kasan_depth =3D 0; } --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E46C4280312 for ; Wed, 20 Aug 2025 05:36:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668168; cv=none; b=WTwFjYY2gzY7DhSH+4UWSHiGfPNNazPza1GQbTOnGnxuCPdJesGJK1/jkWl0fa26nQgXEhvSDi1yeE5cq/K/ik1qjed+ozdOAgDN0itnSZ5mmIkiLDlrSXl4DhgjL0YrTOWgqTMC9/Zp5i24A2THrqvpc1gkLbdci4o9uiccNM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668168; c=relaxed/simple; bh=Ha4cG8e+lmVLPwK0pubt1aRx8Xy2hVzAOdLAnVjJZs0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=j1hJ4Tc7NcxJcdiHllpdyaGY+KI3JOleG+HSu1zWOcnHgsjWOdMqkqp2JlXKC7NjwfvBOkBEsNjpfZhLSsykSFuOqq88HLwaASNjBdCMfBjsMmMxYQMY2bHg+YvCwT5fleHr5Z7kMO7EFnHhaPMkfkbP4wxRW9Qt/pNQb3AvBWI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NQpyXpXI; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NQpyXpXI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668166; 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=oS87V1n70KnlvoMP4fCQ/ERdyh1R0fC3CtG4IQhVRyE=; b=NQpyXpXIuo4gb+nLrA2gyx7cMKaPDfOW1K5Q3Bj+aVUXS7VwtZufAU3y512QD6/A9vYpoV Ike1vEw5Gyw9orKdqwbywFiYUQLMwLClCg6nUHqBYHqf2IgWkdVcbvzyT0YOZF5anmNQrf PGsa+yP5M6okFdJdyrVmBkG0YK/i2tY= 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-547-NwZMdlajPhyC9_mbi6VafA-1; Wed, 20 Aug 2025 01:36:00 -0400 X-MC-Unique: NwZMdlajPhyC9_mbi6VafA-1 X-Mimecast-MFC-AGG-ID: NwZMdlajPhyC9_mbi6VafA_1755668158 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 84A5019775AF; Wed, 20 Aug 2025 05:35:58 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2B42719560B2; Wed, 20 Aug 2025 05:35:49 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He , linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 05/12] arch/arm64: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:52 +0800 Message-ID: <20250820053459.164825-6-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" And also add code to enable kasan_flag_enabled, this is for later usage. And also need skip kasan_populate_early_vm_area_shadow() if kasan is disabled. Signed-off-by: Baoquan He Cc: linux-arm-kernel@lists.infradead.org --- arch/arm64/mm/kasan_init.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index d541ce45daeb..0e4ffe3f5d0e 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -384,6 +384,9 @@ void __init kasan_populate_early_vm_area_shadow(void *s= tart, unsigned long size) { unsigned long shadow_start, shadow_end; =20 + if (!kasan_enabled()) + return; + if (!is_vmalloc_or_module_addr(start)) return; =20 @@ -397,6 +400,9 @@ void __init kasan_populate_early_vm_area_shadow(void *s= tart, unsigned long size) =20 void __init kasan_init(void) { + if (kasan_arg_disabled) + return; + kasan_init_shadow(); kasan_init_depth(); #if defined(CONFIG_KASAN_GENERIC) @@ -405,6 +411,7 @@ void __init kasan_init(void) * Software and Hardware Tag-Based modes still require * kasan_init_sw_tags() and kasan_init_hw_tags() correspondingly. */ + static_branch_enable(&kasan_flag_enabled); pr_info("KernelAddressSanitizer initialized (generic)\n"); #endif } --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B6132853FD for ; Wed, 20 Aug 2025 05:36:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668177; cv=none; b=gdZbKzvyPn3TzkcvjZVO6OC0UYkYVsaeA2jmeafUPBPzrfR8FBg6N4uiJALz+eHiFSrR+8G8+nzfPgAll4ZAoBx8GEFcmDSY3MyY8DkfSTAxXGXnCY+DplUlD/Qr8CvblS6m9C3IbSc5eBtzfkabKRyyMbxf0J/a6546Fbfp42E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668177; c=relaxed/simple; bh=qK2KiUugJNUUcLC7trMBab+1oibPnFRPbNs9ZqggVBk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=AJNEh7hVT0SPT3PJ+Tw1JtNiS1wqIVOkM2/suRSNtFuXQ/jb5qFQkkCGfrw7c/qzgwjetlatxjSTaYI2bob09z/BtB/rJc+JR0jdrQjh4dzb1/uV+yAnD02BdAqlhE13V1WhQE9g9FqpmSFvKXDKrIdZ3QnQ79ILq1cvBHsb10w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=N9/RCAk+; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="N9/RCAk+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668175; 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=HIvq87a0AAq2d23Q/rNsSw9xnqrtCb4IHcYwpyhrt5Y=; b=N9/RCAk+81Pg9Ni1O+xoqWU6FAiZ6Xj5ksNq5TKbnDeMyLp7WcYeyV1JltsUrs27o3dRCw QDoBkIdfWrRpLbKviVndppGFDnQSYXc91THZi+LsLRj4FCp4lChYMYbmC7PhXxYKmM7m6z br2DcGN66LB0lIrBJUBTR/SC8BCANnc= Received: from mx-prod-mc-03.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-661-P3sGgTDEOVKL3Cw8VTzXMw-1; Wed, 20 Aug 2025 01:36:09 -0400 X-MC-Unique: P3sGgTDEOVKL3Cw8VTzXMw-1 X-Mimecast-MFC-AGG-ID: P3sGgTDEOVKL3Cw8VTzXMw_1755668167 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5E17F195605A; Wed, 20 Aug 2025 05:36:07 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 661C219560B0; Wed, 20 Aug 2025 05:35:58 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He , loongarch@lists.linux.dev Subject: [PATCH v3 06/12] arch/loongarch: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:53 +0800 Message-ID: <20250820053459.164825-7-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" And also add code to enable kasan_flag_enabled, this is for later usage. Signed-off-by: Baoquan He Cc: loongarch@lists.linux.dev --- arch/loongarch/mm/kasan_init.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/loongarch/mm/kasan_init.c b/arch/loongarch/mm/kasan_init.c index d2681272d8f0..0c32eee6910f 100644 --- a/arch/loongarch/mm/kasan_init.c +++ b/arch/loongarch/mm/kasan_init.c @@ -267,6 +267,8 @@ void __init kasan_init(void) u64 i; phys_addr_t pa_start, pa_end; =20 + if (kasan_arg_disabled) + return; /* * If PGDIR_SIZE is too large for cpu_vabits, KASAN_SHADOW_END will * overflow UINTPTR_MAX and then looks like a user space address. @@ -327,6 +329,9 @@ void __init kasan_init(void) csr_write64(__pa_symbol(swapper_pg_dir), LOONGARCH_CSR_PGDH); local_flush_tlb_all(); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + /* At this point kasan is fully initialized. Enable error messages */ init_task.kasan_depth =3D 0; pr_info("KernelAddressSanitizer initialized.\n"); --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF61429CB57 for ; Wed, 20 Aug 2025 05:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668187; cv=none; b=ENZnVAoBmIWizouqFp4Vb/N5psO0pCEDH3nS4ZOVS72X7R3u++d9l3FQUlFF1RrGV0fdP0B4B9PgyzW0ZNYB+gFc4OoxXsWz/iw2xI7hAnoDE5U9uTkDxHvTJDAw0kOtISMZOKTfrL7YHasyy1tX4ugfq9X9m4vrLDvE023mKQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668187; c=relaxed/simple; bh=/MdD+V0VX+trwP/NryjRZw851pjrj5UmxzyJv35uL5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=FgCDzt6yUc953D3IK/2nEAlw2VP3SQfQhVpe4JTm/czSQIJUhZ7c+sUitU9EGXKQUBzCcULSHyiiqrEaFvJSNqgSKccNxDnFgOCEhRxc6GNqfG8kUdyZey2cz5036edPtNMS4OGmqtxTzsbtoaL0k1jDIJrY5VRL1CactiultaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SfHxbELZ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SfHxbELZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668184; 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=ffaqmFj6s7jEE3FagcYbQXUNvNizOaxd5L//WV57Tuw=; b=SfHxbELZ1oI6J5SdQ35iEFUObuOIO2zde8J+z1raq2DhBRwF5OjiBmDJHXV/zFEDFVCW9V YIWy7kSkBjAZ+fjbzyClmF3pziF9i16a7ivnCgs1d6vRBTDIS5o84eQY9V/OxBph3cWf/0 tiG5JZyiKTQspmFPQK0ueBq970PSrKU= 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-176-ljSlvNsWPGC2J3sVaEdsMA-1; Wed, 20 Aug 2025 01:36:18 -0400 X-MC-Unique: ljSlvNsWPGC2J3sVaEdsMA-1 X-Mimecast-MFC-AGG-ID: ljSlvNsWPGC2J3sVaEdsMA_1755668176 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 0057919775E8; Wed, 20 Aug 2025 05:36:16 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0B83A19560B0; Wed, 20 Aug 2025 05:36:07 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He , linuxppc-dev@lists.ozlabs.org Subject: [PATCH v3 07/12] arch/powerpc: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:54 +0800 Message-ID: <20250820053459.164825-8-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" This includes 32bit, book3s/64 and book3e/64. And also add code to enable kasan_flag_enabled, this is for later usage. Signed-off-by: Baoquan He Cc: linuxppc-dev@lists.ozlabs.org --- arch/powerpc/mm/kasan/init_32.c | 8 +++++++- arch/powerpc/mm/kasan/init_book3e_64.c | 6 ++++++ arch/powerpc/mm/kasan/init_book3s_64.c | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/kasan/init_32.c b/arch/powerpc/mm/kasan/init_3= 2.c index 03666d790a53..b0c465f3fbf5 100644 --- a/arch/powerpc/mm/kasan/init_32.c +++ b/arch/powerpc/mm/kasan/init_32.c @@ -141,6 +141,9 @@ void __init kasan_init(void) u64 i; int ret; =20 + if (kasan_arg_disabled) + return; + for_each_mem_range(i, &base, &end) { phys_addr_t top =3D min(end, total_lowmem); =20 @@ -163,6 +166,9 @@ void __init kasan_init(void) =20 clear_page(kasan_early_shadow_page); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + /* At this point kasan is fully initialized. Enable error messages */ init_task.kasan_depth =3D 0; pr_info("KASAN init done\n"); @@ -170,7 +176,7 @@ void __init kasan_init(void) =20 void __init kasan_late_init(void) { - if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) + if (IS_ENABLED(CONFIG_KASAN_VMALLOC) && kasan_enabled()) kasan_unmap_early_shadow_vmalloc(); } =20 diff --git a/arch/powerpc/mm/kasan/init_book3e_64.c b/arch/powerpc/mm/kasan= /init_book3e_64.c index 60c78aac0f63..1e1c10467a2b 100644 --- a/arch/powerpc/mm/kasan/init_book3e_64.c +++ b/arch/powerpc/mm/kasan/init_book3e_64.c @@ -111,6 +111,9 @@ void __init kasan_init(void) u64 i; pte_t zero_pte =3D pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KER= NEL_RO); =20 + if (kasan_arg_disabled) + return; + for_each_mem_range(i, &start, &end) kasan_init_phys_region(phys_to_virt(start), phys_to_virt(end)); =20 @@ -125,6 +128,9 @@ void __init kasan_init(void) =20 memset(kasan_early_shadow_page, 0, PAGE_SIZE); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + /* Enable error messages */ init_task.kasan_depth =3D 0; pr_info("KASAN init done\n"); diff --git a/arch/powerpc/mm/kasan/init_book3s_64.c b/arch/powerpc/mm/kasan= /init_book3s_64.c index 7d959544c077..9c5cf2354c8b 100644 --- a/arch/powerpc/mm/kasan/init_book3s_64.c +++ b/arch/powerpc/mm/kasan/init_book3s_64.c @@ -56,6 +56,9 @@ void __init kasan_init(void) u64 i; pte_t zero_pte =3D pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KER= NEL); =20 + if (kasan_arg_disabled) + return; + if (!early_radix_enabled()) { pr_warn("KASAN not enabled as it requires radix!"); return; @@ -94,6 +97,9 @@ void __init kasan_init(void) =20 static_branch_inc(&powerpc_kasan_enabled_key); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + /* Enable error messages */ init_task.kasan_depth =3D 0; pr_info("KASAN init done\n"); --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CE6B2BE64B for ; Wed, 20 Aug 2025 05:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668192; cv=none; b=W5aH/Yw566W4LwX6nuqr5ZrgAhGjMI6KQwhbmT9RBbbj6VZxOu4U9BdXOn6NDzkP/VNuXVYgknX8omc7QkZW002E4X7/4PFDF29piXoPzyXIJaAF/XVEnnwd/N5fbx0lmggHDwATauFDVPGKgM6EZbF6lgntmNd7rxpFQQ40Qfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668192; c=relaxed/simple; bh=gYiU5A/v6zbeCWs7ZpFf9UtZ6dZnOyxtmXOSFCiTKCY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=mr5ubOeH3QAaQViRXDpZgNqKq9wqXchkkBRiyQCDYCxmCWfzBEPkPrIMPhCVxD+T5YniPyM9urpOSXNL6pqKne7FT05Rg28+mRACQ15egSi0hBIFmDElZiZavLTN6JYnr/Yc+uK6baN5DbLRlvvBTO7jRhcxsqeyjX4KnEdufj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iZRQ1GFv; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iZRQ1GFv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668189; 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=tSX6B0M/ECg+25VESJMFTz+rvOMGoiNHgeaxc9XIWxk=; b=iZRQ1GFvSFaxsS6L7RJsee2/sO+AdhyB0xjWdzDT07+BWOuzplNqDKTfiLOVIuGbL1728u N/BPwsvvVZNNq/P7j/AZmWUNCBSolClFYsfk/nFMxy/GweBVbfq/TaHSSjLiFwZR8OZE2d 48yNOmIP056PJLhyRES8Mr5RQlHoox8= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-92-GaD0GWmKPR2v39dZ-bWOUA-1; Wed, 20 Aug 2025 01:36:27 -0400 X-MC-Unique: GaD0GWmKPR2v39dZ-bWOUA-1 X-Mimecast-MFC-AGG-ID: GaD0GWmKPR2v39dZ-bWOUA_1755668184 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A6107180047F; Wed, 20 Aug 2025 05:36:24 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BF69119560B0; Wed, 20 Aug 2025 05:36:16 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He , linux-riscv@lists.infradead.org Subject: [PATCH v3 08/12] arch/riscv: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:55 +0800 Message-ID: <20250820053459.164825-9-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" And also add code to enable kasan_flag_enabled, this is for later usage. Signed-off-by: Baoquan He Cc: linux-riscv@lists.infradead.org --- arch/riscv/mm/kasan_init.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c index 41c635d6aca4..ac3ac227c765 100644 --- a/arch/riscv/mm/kasan_init.c +++ b/arch/riscv/mm/kasan_init.c @@ -485,6 +485,9 @@ void __init kasan_init(void) phys_addr_t p_start, p_end; u64 i; =20 + if (kasan_arg_disabled) + return; + create_tmp_mapping(); csr_write(CSR_SATP, PFN_DOWN(__pa(tmp_pg_dir)) | satp_mode); =20 @@ -531,6 +534,9 @@ void __init kasan_init(void) memset(kasan_early_shadow_page, KASAN_SHADOW_INIT, PAGE_SIZE); init_task.kasan_depth =3D 0; =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + csr_write(CSR_SATP, PFN_DOWN(__pa(swapper_pg_dir)) | satp_mode); local_flush_tlb_all(); } --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD4952BDC33 for ; Wed, 20 Aug 2025 05:36:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668203; cv=none; b=afyGGW5rrieSGUsDvYD8lUVT9NLMW76b7EMW/Z9BtITFikF+hwqSHA5Xe8zVNdTRFnhBNr5yPoUl4vIPoaSxJuZIyYNgXBs8FiJh2GQUpnAfjG1TY7b9DtzqFy9UWz/YK7bUZlQRUES20Y2NYpKBLJ/EiChbcRMWQ47o1x35kVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668203; c=relaxed/simple; bh=x7/e/H3t3Nz+bdN9Mynvya1xVS6El/mgPHYB1LdAHec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=QvqQIfL83+YD1sLHPsH7123h+8vOasv5O/0glEPZ69EIvY6rBudGfPQXOHmfspbI2B9FQcnhVYGsWuBaH5mIyFFtRGQmYUUI4Gtvqx2wxBFxRuK4wP+rFKuYU5oD0DIqEs8HyXq+rfipek28nAfIv+MdaKhaaxuRlGxu/Q5gDfo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gPdTm5lz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gPdTm5lz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668199; 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=iAEMFQ7UJQsp/YRWJnDzAESQXUNpKqSpnHshmUmLX+c=; b=gPdTm5lzBAQ5uEAk45iYhvkef2Z1amasqGVDVuPASqY1lveeNxSjIyvlQ8XMqdpsZA4m7G ZzThMf3YkWO9J4kVx4HX4B21qJor4l6K/9nfUVwwYBz8Yqo9XyxSSCUJ/x/LYH/hz+mtUf mA8rO9Bf9CsAhs7KfxNzkjOqLZjbmik= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-488-ua7zccu4OLWU2rQ3gWmgQw-1; Wed, 20 Aug 2025 01:36:36 -0400 X-MC-Unique: ua7zccu4OLWU2rQ3gWmgQw-1 X-Mimecast-MFC-AGG-ID: ua7zccu4OLWU2rQ3gWmgQw_1755668194 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E7C12180034B; Wed, 20 Aug 2025 05:36:33 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 712EF19560B0; Wed, 20 Aug 2025 05:36:25 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He , x86@kernel.org Subject: [PATCH v3 09/12] arch/x86: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:56 +0800 Message-ID: <20250820053459.164825-10-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" And also add code to enable kasan_flag_enabled, this is for later usage. Signed-off-by: Baoquan He Cc: x86@kernel.org --- arch/x86/mm/kasan_init_64.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c index 0539efd0d216..0f2f9311e9df 100644 --- a/arch/x86/mm/kasan_init_64.c +++ b/arch/x86/mm/kasan_init_64.c @@ -343,6 +343,9 @@ void __init kasan_init(void) unsigned long shadow_cea_begin, shadow_cea_per_cpu_begin, shadow_cea_end; int i; =20 + if (kasan_arg_disabled) + return; + memcpy(early_top_pgt, init_top_pgt, sizeof(early_top_pgt)); =20 /* @@ -450,6 +453,9 @@ void __init kasan_init(void) /* Flush TLBs again to be sure that write protection applied. */ __flush_tlb_all(); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + init_task.kasan_depth =3D 0; pr_info("KernelAddressSanitizer initialized\n"); } --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA3FF2BD582 for ; Wed, 20 Aug 2025 05:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668221; cv=none; b=FsNc2vQZt+eRmKX18d3PkAtod+aV1rwVHN0W/F5ACjGz4m334PR9oF5iLuQ8UAof9xLaA/N1F8ciWmbhNDsDNdHByUzOEd3U2PYTZJJZYskaZecR50NMSIiaD50rbqPspyiuM0UTBEf5stK5HTCHSgpsQCHgJ+AIa1OGLAwfJAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668221; c=relaxed/simple; bh=F/EXbDYN33rSnWuQBnMKU/qdlX588EbU/XQytA5yhPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=TBPx9oHtLrEEA4Jk9/2xhMR7Z/upW4UPAg/82kBf+XXNaSw45leq0cYZh0l1ZErCQwPBqADa2X922TV3kJduZCOF9liZ1itBzf5WGlc/Fge6osjYQCSSwXXO4DQYDNEUd+lkSKP4uFnV2zZssFQ0h/V9yQiXUppClu3wKzX4shI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=W01UszXN; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W01UszXN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668218; 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=VcfWxvd2gMUp9MiHd8sOWfFMV/Om7sFRA8QIIlclSZk=; b=W01UszXNauMN1m1cWZg8+etojgzpa06PXRRfwUZWKBmaZ5ATGrN8D15yHP7YeYcaP9kO5q hK2aoGQCxI7YeHjTA7kOPDWoTTxYwRFwDHFz1RKS9d9ukfdcBz/zixIQjVtTSm98UqQhg6 iHQ+x581MH+syp8YMk2qbSz64xszSJc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-kDHKpYH-PcCG6_xA3bDyRQ-1; Wed, 20 Aug 2025 01:36:50 -0400 X-MC-Unique: kDHKpYH-PcCG6_xA3bDyRQ-1 X-Mimecast-MFC-AGG-ID: kDHKpYH-PcCG6_xA3bDyRQ_1755668205 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 26AEB1800346; Wed, 20 Aug 2025 05:36:45 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B28D119560B0; Wed, 20 Aug 2025 05:36:34 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He , Chris Zankel , Max Filippov Subject: [PATCH v3 10/12] arch/xtensa: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:57 +0800 Message-ID: <20250820053459.164825-11-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" And also add code to enable kasan_flag_enabled, this is for later usage. Here call jump_label_init() early in setup_arch() so that later kasan_init() can enable static key kasan_flag_enabled. Put jump_label_init() beofre parse_early_param() as other architectures do. Signed-off-by: Baoquan He Cc: Chris Zankel Cc: Max Filippov --- arch/xtensa/kernel/setup.c | 1 + arch/xtensa/mm/kasan_init.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c index f72e280363be..aabeb23f41fa 100644 --- a/arch/xtensa/kernel/setup.c +++ b/arch/xtensa/kernel/setup.c @@ -352,6 +352,7 @@ void __init setup_arch(char **cmdline_p) mem_reserve(__pa(_SecondaryResetVector_text_start), __pa(_SecondaryResetVector_text_end)); #endif + jump_label_init(); parse_early_param(); bootmem_init(); kasan_init(); diff --git a/arch/xtensa/mm/kasan_init.c b/arch/xtensa/mm/kasan_init.c index f39c4d83173a..4a7b77f47225 100644 --- a/arch/xtensa/mm/kasan_init.c +++ b/arch/xtensa/mm/kasan_init.c @@ -70,6 +70,9 @@ void __init kasan_init(void) { int i; =20 + if (kasan_arg_disabled) + return; + BUILD_BUG_ON(KASAN_SHADOW_OFFSET !=3D KASAN_SHADOW_START - (KASAN_START_VADDR >> KASAN_SHADOW_SCALE_SHIFT)); BUILD_BUG_ON(VMALLOC_START < KASAN_START_VADDR); @@ -92,6 +95,9 @@ void __init kasan_init(void) local_flush_tlb_all(); memset(kasan_early_shadow_page, 0, PAGE_SIZE); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + /* At this point kasan is fully initialized. Enable error messages. */ current->kasan_depth =3D 0; pr_info("KernelAddressSanitizer initialized\n"); --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B7DA2BCF43 for ; Wed, 20 Aug 2025 05:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668222; cv=none; b=KWhNKBqRZMQ6yqsSdfhWFv+ipDVxcflpjPtC1fUEawn5lzHiuG3FCaK6qs2l1H+9sl/HveMN8euZuEQj5wQPfujsz/Rm/k109wbo41WxERQs2xKZ/cBgwzqGTypsx33ywytj6R63dkM89ScuAKXg0gVp7Ea83jGJdp2R1pMBGtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668222; c=relaxed/simple; bh=3Xdhe4bRu39GQie2dQ0RZhJ0QOGO3XdwESK139d067Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=JdVsUN0LNadVDocA+KkrXjV/oAIVvLkD/cX1UCd9Ug2wM43Ek/eqae/Ag569o1C1ZOh0X6sxjF4zGOWimolUIKU2+rckYZnz8EMba5o8Y9TuPgB/aOmDVgk/ptQF5fvdROrkY4R/moYPqGS9qomoAHiMvqJjMVhm+JjTGoWmK30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HR6ocByz; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HR6ocByz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668220; 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=Z1K+NrhffiuczGQxxvXLPTT8safjMr4ane+44BSMgbw=; b=HR6ocByz7mw4F8A3NwodU+qxiioDXqR8oSQ1Umtfp+E5Vw4+b9dd+ksDTPkrXZacS3kPgL eek0BdaqzpVQwvgyO4Osld6GpNEWupdpH1HfQOgV1y4l+mMtd8kouOkzldsjznPx+RS2y2 jLdMuVBkMC7n9iw4Ic3Gc+M11HObT1M= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-FM4T_kMAMBejUgJcViqkcg-1; Wed, 20 Aug 2025 01:36:56 -0400 X-MC-Unique: FM4T_kMAMBejUgJcViqkcg-1 X-Mimecast-MFC-AGG-ID: FM4T_kMAMBejUgJcViqkcg_1755668214 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 62A951800366; Wed, 20 Aug 2025 05:36:54 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1826D19560B0; Wed, 20 Aug 2025 05:36:45 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He , linux-um@lists.infradead.org Subject: [PATCH v3 11/12] arch/um: don't initialize kasan if it's disabled Date: Wed, 20 Aug 2025 13:34:58 +0800 Message-ID: <20250820053459.164825-12-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" And also add code to enable kasan_flag_enabled, this is for later usage. Since kasan_init() is called before main(), enabling kasan_flag_enabled is done in arch_mm_preinit() which is after jump_label_init() invocation. And also do the kasan_arg_disabled chekcing before kasan_flag_enabled enabling to make sure kernel parameter kasan=3Don|off has been parsed. Signed-off-by: Baoquan He Cc: linux-um@lists.infradead.org --- arch/um/kernel/mem.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 76bec7de81b5..7b7f838274b5 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -58,6 +58,13 @@ static unsigned long brk_end; =20 void __init arch_mm_preinit(void) { + +#ifdef CONFIG_KASAN + /* Safe to call after jump_label_init(). Enables KASAN. */ + if (!kasan_arg_disabled) + static_branch_enable(&kasan_flag_enabled); +#endif + /* clear the zero-page */ memset(empty_zero_page, 0, PAGE_SIZE); =20 --=20 2.41.0 From nobody Sat Oct 4 04:57:30 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9FCF2BEFEE for ; Wed, 20 Aug 2025 05:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668231; cv=none; b=ZBiMei1YUBR/qeUTZILdBJnwOGERo5jGSMXhrlD35X21qeVqReEeQu31+S/eSxtE2nZDFvdlOx2Z70I3wX7+oLcfT3OOFw6QxRuZGk/mVLzvJHVmseZ3WcaqPkk6YCTEWDWfllLmyNbkGCnBx7oNMkdQs880qqn6ID+x49AuPI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755668231; c=relaxed/simple; bh=OUjX53EAHeKwXVNw4pKhXoSWyP1sGMgjRDiEs64lYtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=YZ7Z3jaj6RsCDq4c1qDJCYR/bDmpEsjJIPyuTuCN6NOUlryCRKcSsx9BUMr8XqxdaiKYGRazMXgdjj1TZWApzwDXd0vk9q6/rr5rmVuAQJhFZb0Pr3TYtMZa5ay4uhS5vKVK7lg4ZPZj/qXA3PSUqEG68w3pzU38FXRZv6K4Vxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Sm5nir1T; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Sm5nir1T" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755668228; 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=n2YWNQ1R3q2yuyqJw9ejU5xCE0/f1sakMXwMmNRUMe4=; b=Sm5nir1T/ujZc6uuPgEtOtk9Ch6R7WrsZ/CMjDacOb5FMpRVRx90L8raCa/9sXKYAB3RKK a3ZDze1AD3VkgxaovQPZYmCXHAMP86NESheytU6dw6INm/gsUcAB4k7NvkdxE+cmTIarv1 Of6CWJWl32KTppDTmUCtEURAGUPuJYA= Received: from mx-prod-mc-03.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-590-SD3MvwL6PoWLgsvGYJ6o_w-1; Wed, 20 Aug 2025 01:37:05 -0400 X-MC-Unique: SD3MvwL6PoWLgsvGYJ6o_w-1 X-Mimecast-MFC-AGG-ID: SD3MvwL6PoWLgsvGYJ6o_w_1755668223 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 54F0C1956079; Wed, 20 Aug 2025 05:37:03 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.99]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2ED4819560B0; Wed, 20 Aug 2025 05:36:54 +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, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, christophe.leroy@csgroup.eu, Baoquan He Subject: [PATCH v3 12/12] mm/kasan: make kasan=on|off take effect for all three modes Date: Wed, 20 Aug 2025 13:34:59 +0800 Message-ID: <20250820053459.164825-13-bhe@redhat.com> In-Reply-To: <20250820053459.164825-1-bhe@redhat.com> References: <20250820053459.164825-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Now everything is ready, set kasan=3Doff can disable kasan for all three modes. Signed-off-by: Baoquan He --- include/linux/kasan-enabled.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/linux/kasan-enabled.h b/include/linux/kasan-enabled.h index 32f2d19f599f..21b6233f829c 100644 --- a/include/linux/kasan-enabled.h +++ b/include/linux/kasan-enabled.h @@ -4,34 +4,32 @@ =20 #include =20 +#ifdef CONFIG_KASAN extern bool kasan_arg_disabled; =20 DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); =20 -#ifdef CONFIG_KASAN_HW_TAGS - static __always_inline bool kasan_enabled(void) { return static_branch_likely(&kasan_flag_enabled); } +#else /* CONFIG_KASAN */ +static inline bool kasan_enabled(void) +{ + return false; +} +#endif =20 +#ifdef CONFIG_KASAN_HW_TAGS static inline bool kasan_hw_tags_enabled(void) { return kasan_enabled(); } - #else /* CONFIG_KASAN_HW_TAGS */ - -static inline bool kasan_enabled(void) -{ - return IS_ENABLED(CONFIG_KASAN); -} - static inline bool kasan_hw_tags_enabled(void) { return false; } - #endif /* CONFIG_KASAN_HW_TAGS */ =20 #endif /* LINUX_KASAN_ENABLED_H */ --=20 2.41.0