From nobody Sat Oct 4 21:00:54 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 38CC5242D94 for ; Tue, 12 Aug 2025 12:50:08 +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=1755003011; cv=none; b=XBMoA26cMsdnliWn4rn1zvQz1fRTRYtldXl0F3LU7Zfmw6JyrHDba4fT3mE+6SgNOILH58k+EAWyBqwgI9RCeGco86biR8PcjQml7YQiwp79FwA8l+5+TBzERShjZHtMxqXx2R/3u2HVHLfcG7W5VRxke6zSKejKCHumwCUkmRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003011; 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=PB62b74mcfluVziImtjxbPjFtUt/Lmv1N1Yu7iyaqVjzShffj2ZxV7nNJfOGFG2A41Jstsued3rz0VafKqiwpmFL1JfbZ4OUzJ5p02OEweRiv75Rq06ENIRbeerdVqPp03JBYsoWImSdMS2SVlPdARMJvEJnabVf8pIcYXB6gqo= 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=WvBDM3Kt; 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="WvBDM3Kt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003008; 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=WvBDM3KtuHvEbvM5WZMnKJ6JyvajikNA2p05vKxrlf9pJeWT64ydALXnv+1ZH+gJ1mC1dI AWvkH2jpo4uA5VYXilAowvCtw/nlq9EJFR2lAqbUt3TBGWstpOTaJc2K9Y9jCVZ4dtn6aT 5SPpYcbfeBs/4rro+mmTcwYkAsjNQXo= 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-21-pCgxLexbPZWoogFBtgeuVQ-1; Tue, 12 Aug 2025 08:50:01 -0400 X-MC-Unique: pCgxLexbPZWoogFBtgeuVQ-1 X-Mimecast-MFC-AGG-ID: pCgxLexbPZWoogFBtgeuVQ_1755002999 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 937D9195605B; Tue, 12 Aug 2025 12:49:59 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A119E300146B; Tue, 12 Aug 2025 12:49:52 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 01/12] mm/kasan: add conditional checks in functions to return directly if kasan is disabled Date: Tue, 12 Aug 2025 20:49:30 +0800 Message-ID: <20250812124941.69508-2-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 21:00:54 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 64D1C261574 for ; Tue, 12 Aug 2025 12:50:14 +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=1755003016; cv=none; b=VedL3Jn+WMdiWqEZdq3LPYLN6EazcD9jsI9U7V7dP0unXpjyKAjw2S+x4ODthlxpis6/OnTXGw8lojuRxTRyZYRURNFMBAueufMNxV6DV97BtETQ2sWCn3GkXiLTaWnQbX9RS85XQvQl06ETlsIAUjXFkwG9uOdd2uSHYYk1he0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003016; 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=qwAtP/qJ1lieEqb1wXnbvxl6qFwbi4LxWEXjoUI0yAUdWUAJxXFOn6nrBbcpmIQi8/4irOmHpDpPbUrmTMbWTusUoVwUjgyAAkKxaAPR28L+l2qp8JV496JxbvdIWrt33eaUXOa6rInu5wmZksGLfPGFosrgToXDt1Ns5BVXO3k= 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=AChmoBPd; 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="AChmoBPd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003013; 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=AChmoBPdc24Cyy0iMFhwibOFtfsnF2e9gayt/IItFGrpeYCy2sM3+6/ykZyyo9thABk2Rs D9kR8Sp/7OjMPscVtMVHvt6cVeQ9kqYNgi5bmyaxiDOx/LCENN0y5BH16Y9hwpy+4COxdw DszeiQrWCmAC1qgG7m0bDw44xYErP3Y= 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-25-pB9e8V-hNSCSigDe8LiZ2g-1; Tue, 12 Aug 2025 08:50:10 -0400 X-MC-Unique: pB9e8V-hNSCSigDe8LiZ2g-1 X-Mimecast-MFC-AGG-ID: pB9e8V-hNSCSigDe8LiZ2g_1755003008 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 8214119560B1; Tue, 12 Aug 2025 12:50:07 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6E97330001A1; Tue, 12 Aug 2025 12:49:59 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 02/12] mm/kasan: move kasan= code to common place Date: Tue, 12 Aug 2025 20:49:31 +0800 Message-ID: <20250812124941.69508-3-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 21:00:54 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 8B85B2586DA for ; Tue, 12 Aug 2025 12:50:23 +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=1755003025; cv=none; b=Wv8nk8mD1S+UHF6eLjLiplU5F9KnJ1bQaQwbBND/dOjNf3zzFI2g45QNEhYw0VGXbgwdyb1PH5R+HI73IcGsx/rTDg9brFXjjtO7sgLLW1IxwLpuoYNrE1FP7wUfL/NfSNvPMmIyPzxTikaTnFbC4TP72+Ynv29XSsotFcG4tBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003025; c=relaxed/simple; bh=YgopKzfR0IJfsyEXF1E1nafRos8bsFb6WfDl5GYGKuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=YB4gpjrZou3LRHOWfGS4ZxqqaF9In0XL1N9ss7u+rRKSZ4cRJqgWAPEi+Nc7Z0411vWQ/wmGSPXJoMNGiENICOLbP2XU3/7WiqOsAUqFCqIGr4p8Gdvvyzy44sd7iwzqfPaDgEF88r+wSYCWtGTAyGhf7+OD05nqxLTEgNVPUq4= 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=R1OCAqUD; 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="R1OCAqUD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003022; 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=R1OCAqUDAX6ChlH1eY+OJRAcKmDOPB0v3Pk9JfuBuNd9wwkze4EV6KaP6Rct8xPxlOVBVj Q775aumDc3M+s6ohCeetcAACs40Kd95kap6kx4ZBHSHAyV1VGAZH8cns82QTT9O3GrPtpP zMMz6XYShHUCHAFrj3j8WlJeTid174Y= 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-121-Ahe-8VyWPdGdPbA0pY0ufQ-1; Tue, 12 Aug 2025 08:50:17 -0400 X-MC-Unique: Ahe-8VyWPdGdPbA0pY0ufQ-1 X-Mimecast-MFC-AGG-ID: Ahe-8VyWPdGdPbA0pY0ufQ_1755003015 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 F3E78195608E; Tue, 12 Aug 2025 12:50:14 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 173963001458; Tue, 12 Aug 2025 12:50:07 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 03/12] mm/kasan/sw_tags: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:32 +0800 Message-ID: <20250812124941.69508-4-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 21:00:54 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 B9C4E2571D7 for ; Tue, 12 Aug 2025 12:50:33 +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=1755003035; cv=none; b=BO6+rcbJdReKR5beyLKTGeGhwlb51I56Dv2ib6LdmKFsI/7pKp0zM/0ueXbDte66wADYULDfUvALHYEdCuiMYxwzSvkZHAHsMCiXWcD9NuTDFZccMy61p4FU1b/5GQ5eMro0jqQSIDdPUBvlUUTXHH1djgYpn+ZCHYZPEe4Tvzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003035; c=relaxed/simple; bh=EKoLFKfDE4OVlIlS/bSiogHROByBDPfoUsBfUqFD6c4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=SxVplZL5T1a4H2t/ri+PpCOAI2C7xu73lM3gTZ3S/nrxclaMkufxZ+cGminXMFsHRBHd29wpdnw/1oHdLCOqm1JuYE/pOJqAScz9exwMnTuumuVwSHOqFXmn2nzrI+bWZTAK2TyJ3uofe6svkcCRJ9oXXXDoMTG6HbOjfPFweqY= 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=OZL7wmTm; 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="OZL7wmTm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003032; 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=xr/w2mK6l802lCxz4VjyI0YPeCChzTlSQ7qvXcEbkU8=; b=OZL7wmTmUr7wQuqiUeKcCzwZwBYPrUZFzc3j25JlXW1FqvCAQbLgT7+1euKFFXENjpDNaI u429XRhd5CUIzwoSYT261FoKbj1AFmKyOG1/JIvyrX2LyETYrhMY7UooXiUArRIFfjzxpy Mb0Htrl0pVmt4tvu5ZaOg0ZChFSRiqc= Received: from mx-prod-mc-02.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-10-XufWQzS-Paee81uzo9E_Ew-1; Tue, 12 Aug 2025 08:50:24 -0400 X-MC-Unique: XufWQzS-Paee81uzo9E_Ew-1 X-Mimecast-MFC-AGG-ID: XufWQzS-Paee81uzo9E_Ew_1755003022 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 24E73195608D; Tue, 12 Aug 2025 12:50:22 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7BD173001458; Tue, 12 Aug 2025 12:50:15 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 04/12] arch/arm: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:33 +0800 Message-ID: <20250812124941.69508-5-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 --- 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 21:00:55 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 5DAF12571D7 for ; Tue, 12 Aug 2025 12:50:39 +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=1755003041; cv=none; b=BYptmIPSQkcZBiWjb+ppBZ5KZTsIstWm1G0hBCrC1cVSFy+xwCQOlNW0p3+BIRFdFWmNtjUeZ1nJdt6Y1igMUo2wX9B22pM6q+pltQ6uftv9qLeTJ6JXGveSUdG4+dAym9KGiKaXqF5s83tnfd36fTHr4ySTyMjKVHW64A/uTt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003041; c=relaxed/simple; bh=684V2Sd3lEmleyXlZL6uzzLUkwfe66EuDnmd4KUxaUU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=DpAlbud43fJC2MkbdzLDvxCX5R3cKdcFVnlVBkxdESCYp/PjSCLV+vDDZZ/vWh2xCf5NtRg8j1CvVVRLJCMT++ySOTDkafBT/wEmdsS/aPTlZZZgP6a01zIarmTPdjqUbUGMOwwvhxp0LLvGsDn/cO8Y9gV5wiwWHfwQaTnvjjo= 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=F+UDNhOU; 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="F+UDNhOU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003039; 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=rmch9LxILHmDSZgEKLxWACfFjV5jmswbcfLkcrWwQo8=; b=F+UDNhOUVjTwuAHAobuTyqBxjNH/0OWzY0T0WrGhBWZR7fbYYgmKFHTzfZbYgAVnY06t+d zZ/odquAFXnkzlaQHMXDU2dyuVRF4eKGiIvNoTlDqoaP+RgI7VC5cOXYV74Dht8tEe/+pj vZmTwLq2Ct8BjY6tVhODs/N7UcdMYl8= 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-57-v2GUSWdCNJ2cbTTT3izsjQ-1; Tue, 12 Aug 2025 08:50:34 -0400 X-MC-Unique: v2GUSWdCNJ2cbTTT3izsjQ-1 X-Mimecast-MFC-AGG-ID: v2GUSWdCNJ2cbTTT3izsjQ_1755003030 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 0D25E19560B5; Tue, 12 Aug 2025 12:50:30 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D92EC3001458; Tue, 12 Aug 2025 12:50:22 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 05/12] arch/arm64: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:34 +0800 Message-ID: <20250812124941.69508-6-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 --- 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 21:00:55 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 29506279782 for ; Tue, 12 Aug 2025 12:50:44 +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=1755003045; cv=none; b=J/OiwIz0UgdJGMDj+iOX+LBfj05W3zIYFuxfY1MMCdot7mTbIIbmeTU+8jM9T2MG6ypReHStRfA+xtOAosBwhOCIUmI0wqzraEcTI2ETtvXr/eSoSUxUAqjEC6aUxeTMf8sabm7xh1vfMTLQZhTFsOQOY3Y64bJz8Za9FsZtGag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003045; c=relaxed/simple; bh=vvF9494mWBjv374UHxuAnnOCwXd4eT9+0GvjFMCZv1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=eefycNVaAYQCNeMYaOLbghtmPYiQ2Y/c44/zD9fNIQ/W84h6EUpAQQtvNkQsH1LCW2wdKseBRwYKWKzVeKSvc6Yga8byRci1Le2qQqzBOwl6T8gXlWAXAn/V6WZabJWfFj/ZmLlplvhZztw1+x1hlt0Lj5M+xIBIkoUgzcsbdyg= 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=X/XdSs8P; 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="X/XdSs8P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003043; 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=QN1Z1dUeks4QygHE7wKCYxkrDkPOGTvp8PG+uI+E7oo=; b=X/XdSs8PTu3ylJyvanUGtztD1FqXURsn1U86/F00/Yes2x9egJL5eqkDSvad4yVdK1n/Op oeWIGDO4qvGzbpVixQSejg51xwpFK5YU+hWhCIYHOXlKw4RCQwY0sbaoXjPwv9kCbXR3Fl 7otrlob90Zu6je9qFRTIMuc8L3JvUUU= 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-620-at2M-5U8MMOmrD3AvQwZ7Q-1; Tue, 12 Aug 2025 08:50:40 -0400 X-MC-Unique: at2M-5U8MMOmrD3AvQwZ7Q-1 X-Mimecast-MFC-AGG-ID: at2M-5U8MMOmrD3AvQwZ7Q_1755003038 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 4CC9C1800773; Tue, 12 Aug 2025 12:50:37 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C2C97300145B; Tue, 12 Aug 2025 12:50:30 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 06/12] arch/loongarch: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:35 +0800 Message-ID: <20250812124941.69508-7-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 --- 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 21:00:55 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 AEE3D258CDF for ; Tue, 12 Aug 2025 12:50:52 +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=1755003054; cv=none; b=Yb0IeqDLFNMkaCFbpSYcwuWZYEGsNimg+ELpBw4rmiPPGkB/ilDz2UgkYnCc+7+LPewSg6sEoYUDvk5CE8qUD2kD+0NYw67bXHnzm7M11v5i58PbWykY766rmMjqISG23JaMexaPvid1egEsvpH2ji89YG5HyJfc7Gon9v2XxFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003054; c=relaxed/simple; bh=bnmrtZpr6JNf7FB8rzp2u6XrM3bDUnV0svmYGEKWX8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=fZ2CXkTYxoTni/e0J8pVdvludI4pp7nHjVMZqfAjmXqj8I0Ma5FTI4YZPDKVdV81lCXUZOEog16nxZQEbYapj1Wkmr89Z8W4dAoWyBH86paCKWNLBq3S8TFQb5HZn7HlZhs75U1AHIUh3Cz/YShcCBrffo2RTNvqa/LzK1JDdiE= 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=WgbGkryD; 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="WgbGkryD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003051; 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=jd0CGLClfWsUYGgm7aK9F7vU1kBgjVrUFDs4V0d+D1M=; b=WgbGkryDlB2olDTpvjbe/nt1Khgf2kfqqy+m5KDHJcPgjHwUzo1vLnnoB1f2YtylCiEwG4 fCCkgqG6hK8RkpxB2hrl1KzqIDK2pVmoTjs4M5UHbn5JuqX8W0pe4Kz04S0uI8m+Ns9Sll NZYdQDmhixhVGUHhRTCuDm0O2j1W9Lw= 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-655-aJnDQK3BP9GHbyaEUfDmJQ-1; Tue, 12 Aug 2025 08:50:46 -0400 X-MC-Unique: aJnDQK3BP9GHbyaEUfDmJQ-1 X-Mimecast-MFC-AGG-ID: aJnDQK3BP9GHbyaEUfDmJQ_1755003044 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 90BF2180047F; Tue, 12 Aug 2025 12:50:44 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 140FC300145D; Tue, 12 Aug 2025 12:50:37 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 07/12] arch/powerpc: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:36 +0800 Message-ID: <20250812124941.69508-8-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 --- 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 21:00:55 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 13250275846 for ; Tue, 12 Aug 2025 12:50:59 +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=1755003061; cv=none; b=gbZZnpE/D0p/axmXhTIDz2JJ8RYv2tJcFvmwhvmGWnglV0RyIXuWFVCTM/Vf6TedxD4f/9D3rxkVU6DFbSxm+OGNuBNFrewOIfutl4OAGSBwa4u9SDMgZsn7gT+mntJQbKc4y+gvNF0S6eEUy5U+bHmU733FMUOR2V2Ks3biQEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003061; c=relaxed/simple; bh=/G5jYkyo+hP74iXawuBhorBrIE3sZvr6FUbDljXw8wM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=suDQYukrvxl0HObIZ+/XGK6QF/wrtqfwuP1bqcnpIPYo7+c9BJFtnIaZaOxw7+2fG2ofLC1YWPkl9nA9d55evwmmuIP6KoLr0ZYCDh2Qh4LaJek6ybdBZiNLtm3AykM8hdeH6bBNMUcsSvTgZ3BMl1m4lIFg7WyBxLQdT0GmYtg= 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=PWJprqUm; 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="PWJprqUm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003059; 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=KrTt3YvXHtYUuoIddMbmkc8QXtgLzrL59sgxurx8fJw=; b=PWJprqUmDyKEFA3o7i4zBF4m3DyuZZuwhHW22GQsMxt26ULwI5d52t9Hv4LbEUnAN+NnGE VtDmVnD2scoWw5CxxVIJBDHCpjEwNz5UtceAPGRG7W2CKJYe/YMz+XwII6tcnUdX5Nogp/ m+tlzIFOXijBtxeb5v4wPxdtdCOYE0c= Received: from mx-prod-mc-02.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-9-IghP0uCBOV-OwVmnG3ieZQ-1; Tue, 12 Aug 2025 08:50:53 -0400 X-MC-Unique: IghP0uCBOV-OwVmnG3ieZQ-1 X-Mimecast-MFC-AGG-ID: IghP0uCBOV-OwVmnG3ieZQ_1755003052 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E143219560A2; Tue, 12 Aug 2025 12:50:51 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4F13630001A1; Tue, 12 Aug 2025 12:50:44 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 08/12] arch/riscv: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:37 +0800 Message-ID: <20250812124941.69508-9-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 --- 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 21:00:55 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 E6FF827605A for ; Tue, 12 Aug 2025 12:51:05 +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=1755003067; cv=none; b=XsjTsV38/Nf8WDkOaEwf3i8LRqpEqhetPOrD6qObpR4fkj/0t3IqQs98UZN6Ymt+q+I7HGbJE5H30CpOKZJv3cJXo59dtAY4HUa6uIqzonHSQS+B11zspo8QVJUkQmtz7b7IYkMOOKPn9uvpQ9aTRSEwB87BZZ3vHNZ38171R1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003067; c=relaxed/simple; bh=tW9LfwmiesUIQ8B3MXDoTo58f31UmD+sTrCG7Yr7V70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=fS8FwZn7T87Lcc1q/QqHMlFkiOnyWhMy3baTmPBMDxVkT0zXHnilo28EHn7e/wPkN3Gd/bf4rZMQUk0Reu4IXmDU2p8GzOgsibTLJEQngbHm+pcmDKY2dpRqTmhq2oGBT7BLWibKLsKk+gNkW29r7JOR3rcZUwCBORIt84ezHrQ= 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=ahtF/NiW; 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="ahtF/NiW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003064; 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=+hQAnfUidTkYrnmu4spIdiJcPf/3EYQSdRJ9OD5/zYQ=; b=ahtF/NiWFcXUNdLnGkIxRxmtMjUkViwSFb0PKP2ArOCZJN1p+s8YsIafsmOVveg/B6Q8ER yropH7bzPG2VJEkppI2w8tpwypgzdK0/1iJ5e0O06uJTRGX6krc5J1BqLnjsW2XSfluTr/ 0GrVw3q36yt3GUlHXPJyh4278Aw7ya4= 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-433-lYRCxuF9OOOH8dMMXILcPA-1; Tue, 12 Aug 2025 08:51:01 -0400 X-MC-Unique: lYRCxuF9OOOH8dMMXILcPA-1 X-Mimecast-MFC-AGG-ID: lYRCxuF9OOOH8dMMXILcPA_1755003059 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 D0B1B18004D4; Tue, 12 Aug 2025 12:50:59 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A33053001458; Tue, 12 Aug 2025 12:50:52 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 09/12] arch/x86: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:38 +0800 Message-ID: <20250812124941.69508-10-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 --- 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 21:00:55 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 7E6C625B1CE for ; Tue, 12 Aug 2025 12:51:16 +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=1755003077; cv=none; b=LWTJejGA3UBOsrcOerWUpggcKTZHOsrJUUNL+OEt4azzRbScNZZxcwn8CkVOWY7l+u2iE98sAKbmqCvdjjss6e6thYL81JakxueZumrddpA6R8Bv4HOZsP+Vq07/tDLS1JmlZysz2YSAILzNEzw7ZHEJRrcescUTIlM+I1bThUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003077; c=relaxed/simple; bh=ouk9z2D8X2Ny1UInnHWhDksgKL9U2oHtFEH6E3neSvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=ia1p0z1KBGX2uiR+laTE0J1NwFKxAKyZrbGbRtTkDFYcHNdjbICzhKSyYn5If8/j5tp5rBkFWxAtkix9rgXDJGqDw6NLHaeVq0hOhv9on5sAk+VlGem9zNwYGuSB/BuFfq62i0OTzlUqM32GDNsUVodj2/18hLzrNzXQM65UlQg= 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=G/XiVgYV; 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="G/XiVgYV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003075; 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=qdpdSshaazL7siJRM8NVIrvzcaBedwi1OmyrckGBBVw=; b=G/XiVgYVwkKt2fQurxiF+q3Ja0ZDj6f1sasy9HHZbbpNDyNgO8QafsCXMf7GYMx3Ct+94y hqrn01WGXrKBhmhBGeS8t6YniOAzVk+zj6L4EkDxOCUCqvWfAYgsBM4NnMZPBeFpdQ0AW1 syYyNMPBMooevTFCp8bu3Wf7X1Eb2Dk= 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-656-3Xj9WACAOs-CFxfowhebOQ-1; Tue, 12 Aug 2025 08:51:09 -0400 X-MC-Unique: 3Xj9WACAOs-CFxfowhebOQ-1 X-Mimecast-MFC-AGG-ID: 3Xj9WACAOs-CFxfowhebOQ_1755003068 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 CEB4C180045C; Tue, 12 Aug 2025 12:51:07 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 441D6300146B; Tue, 12 Aug 2025 12:51:00 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 10/12] arch/xtensa: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:39 +0800 Message-ID: <20250812124941.69508-11-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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 --- 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 21:00:55 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 4817C268C73 for ; Tue, 12 Aug 2025 12:51:24 +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=1755003085; cv=none; b=cUCFZad4XPDm4fqFnxEux39STe1QzlAXmisl9+7b2a/FakFhZDJKHPf0F7TlG/xO1zCxafBGQXZlZwERUEESO+/xdESMp/O8gcJECkhyvM6ooYiuz6dkGKVhJJw0F09hs8WDQlOGPAm+y6cJnYFbGJMYQ5WppetSRjVkaTQFha0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003085; c=relaxed/simple; bh=a6yXnqPO/FQuG+PWl4dLH8XXmB6lxQT2qQpDAHyZpAo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=KK1SIqT9tkPoaGqViF6SAIw6YyXH58reYf5XNXSqTy1yAPW8PNf4uKciMV8Z3W86uyXGYdOF90Da6B3nrNLB+MBsa6Z3X1lWYMu7xs1oBKE0rixJh3ZE+ftppwxzYcH1dJt4jaGfCOHWjkpyT3SU0kyk/hkS9GFn9NDcX0woUqk= 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=dQPzvJNh; 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="dQPzvJNh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003083; 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=UNvwjh3bkLYd7LcWTIY96phbAPIdD7DxmW/f2AxTNdM=; b=dQPzvJNhtCuYVtDztPmnUYhtLcVAk7rDAMTiSwzVPZPtt04jdjvGDs72EPAJnHPbP/0pGA kHGVbNcPuQsgHj2DNxXXZrUbwJ6K9uD31r4uH4GutNG4To7blOrO7dzO1Gxw657beBvZqK je7JZkr6n5rXIqWw1QinyfkawOMxO4o= 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-515-BarAkwZZPNi3t3OI2JjPPg-1; Tue, 12 Aug 2025 08:51:17 -0400 X-MC-Unique: BarAkwZZPNi3t3OI2JjPPg-1 X-Mimecast-MFC-AGG-ID: BarAkwZZPNi3t3OI2JjPPg_1755003075 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 0A2E81800352; Tue, 12 Aug 2025 12:51:15 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8EAE530001A1; Tue, 12 Aug 2025 12:51:08 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 11/12] arch/um: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:40 +0800 Message-ID: <20250812124941.69508-12-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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. Signed-off-by: Baoquan He --- arch/um/kernel/mem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c index 76bec7de81b5..392a23d4ef96 100644 --- a/arch/um/kernel/mem.c +++ b/arch/um/kernel/mem.c @@ -26,6 +26,9 @@ int kasan_um_is_ready; void kasan_init(void) { + + if (kasan_arg_disabled) + return; /* * kasan_map_memory will map all of the required address space and * the host machine will allocate physical memory as necessary. @@ -58,6 +61,9 @@ static unsigned long brk_end; =20 void __init arch_mm_preinit(void) { + /* Safe to call after jump_label_init(). Enables KASAN. */ + static_branch_enable(&kasan_flag_enabled); + /* clear the zero-page */ memset(empty_zero_page, 0, PAGE_SIZE); =20 --=20 2.41.0 From nobody Sat Oct 4 21:00:55 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 5F8AB279347 for ; Tue, 12 Aug 2025 12:51:28 +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=1755003089; cv=none; b=ZukaO+w4b07igsGcFKB2pmEBMPnrbZgA2pYsT0dD/fNrSirCJzNSjBa9t/7llYBUktFnw66CSjPQ2szTPB7tubauwzQj00dlKAqllxnf1VFCuoo1oDunXu351hNxGtGS9MklRKXuuISlyOp9xmQiKIb8mtc7MMv8oJzK+wZAs3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003089; c=relaxed/simple; bh=OUjX53EAHeKwXVNw4pKhXoSWyP1sGMgjRDiEs64lYtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=aJC8MfndIIYk55soDFmdYgxaIBghset77qPzQwLh8A86IYRVGcpC8rUc+CJkRGuKe9SQF7JsfNkP2HjtoA2ECQk7O1WAg5t7fba0zVA7w2ChdieXCn9UyN+39FjM2E1BfpkLPgDmXFdizGGdCNidVLi44g5eRb8a88c4CNeJCe0= 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=ieKYKiqa; 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="ieKYKiqa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003087; 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=ieKYKiqa3MUV5WjEhooXOHvL1OB7Sj7+wAm/GNsotP5/U0s0R9y3287Z/ZMh0+g/To8tSO kPNhg6Pu4y7YzB+Y8O1WNt9zgSFHd5YVfwmWXwep2KwLS9uiHLbMTghMpfqmojPiASIQrT 3EArojPLPyiorcgpAl80SKrX36WUkMg= 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-665-9kKnlE7PMdGWBVGqhx90ng-1; Tue, 12 Aug 2025 08:51:24 -0400 X-MC-Unique: 9kKnlE7PMdGWBVGqhx90ng-1 X-Mimecast-MFC-AGG-ID: 9kKnlE7PMdGWBVGqhx90ng_1755003082 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 3E4DF1800370; Tue, 12 Aug 2025 12:51:22 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BFF7230001A1; Tue, 12 Aug 2025 12:51:15 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.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, Baoquan He Subject: [PATCH v2 12/12] mm/kasan: make kasan=on|off take effect for all three modes Date: Tue, 12 Aug 2025 20:49:41 +0800 Message-ID: <20250812124941.69508-13-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-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.4.1 on 10.30.177.4 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