From: Baoquan He <bhe@redhat.com>
To: linux-mm@kvack.org
Cc: snovitoll@gmail.com, ryabinin.a.a@gmail.com,
christophe.leroy@csgroup.eu, hca@linux.ibm.com,
andreyknvl@gmail.com, akpm@linux-foundation.org,
chenhuacai@loongson.cn, davidgow@google.com, glider@google.com,
dvyukov@google.com, alexghiti@rivosinc.com,
kasan-dev@googlegroups.com, loongarch@lists.linux.dev,
linuxppc-dev@lists.ozlabs.org, linux-um@lists.infradead.org,
linux-kernel@vger.kernel.org, agordeev@linux.ibm.com,
Baoquan He <bhe@redhat.com>
Subject: [PATCH 1/4] arch/loongarch: remove kasan_arch_is_ready()
Date: Tue, 12 Aug 2025 21:09:30 +0800 [thread overview]
Message-ID: <20250812130933.71593-2-bhe@redhat.com> (raw)
In-Reply-To: <20250812130933.71593-1-bhe@redhat.com>
From: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
With the help of static key kasan_flag_enabled, kasan_arch_is_ready()
is not needed any more. So reomve the unneeded kasan_arch_is_ready() and
the relevant codes.
Here, move kasan_flag_enabled enabling before populating shadow of
liner mapping regions so that kasan_mem_to_shadow() can function well
just as the old variable 'kasan_early_stage' is located.
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
Signed-off-by: Baoquan He <bhe@redhat.com>
---
arch/loongarch/include/asm/kasan.h | 7 -------
arch/loongarch/mm/kasan_init.c | 10 +++-------
2 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/arch/loongarch/include/asm/kasan.h b/arch/loongarch/include/asm/kasan.h
index 62f139a9c87d..0e50e5b5e056 100644
--- a/arch/loongarch/include/asm/kasan.h
+++ b/arch/loongarch/include/asm/kasan.h
@@ -66,7 +66,6 @@
#define XKPRANGE_WC_SHADOW_OFFSET (KASAN_SHADOW_START + XKPRANGE_WC_KASAN_OFFSET)
#define XKVRANGE_VC_SHADOW_OFFSET (KASAN_SHADOW_START + XKVRANGE_VC_KASAN_OFFSET)
-extern bool kasan_early_stage;
extern unsigned char kasan_early_shadow_page[PAGE_SIZE];
#define kasan_mem_to_shadow kasan_mem_to_shadow
@@ -75,12 +74,6 @@ void *kasan_mem_to_shadow(const void *addr);
#define kasan_shadow_to_mem kasan_shadow_to_mem
const void *kasan_shadow_to_mem(const void *shadow_addr);
-#define kasan_arch_is_ready kasan_arch_is_ready
-static __always_inline bool kasan_arch_is_ready(void)
-{
- return !kasan_early_stage;
-}
-
#define addr_has_metadata addr_has_metadata
static __always_inline bool addr_has_metadata(const void *addr)
{
diff --git a/arch/loongarch/mm/kasan_init.c b/arch/loongarch/mm/kasan_init.c
index 0c32eee6910f..f156cba818e6 100644
--- a/arch/loongarch/mm/kasan_init.c
+++ b/arch/loongarch/mm/kasan_init.c
@@ -40,11 +40,9 @@ static pgd_t kasan_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
#define __pte_none(early, pte) (early ? pte_none(pte) : \
((pte_val(pte) & _PFN_MASK) == (unsigned long)__pa(kasan_early_shadow_page)))
-bool kasan_early_stage = true;
-
void *kasan_mem_to_shadow(const void *addr)
{
- if (!kasan_arch_is_ready()) {
+ if (!kasan_enabled()) {
return (void *)(kasan_early_shadow_page);
} else {
unsigned long maddr = (unsigned long)addr;
@@ -300,7 +298,8 @@ void __init kasan_init(void)
kasan_populate_early_shadow(kasan_mem_to_shadow((void *)VMALLOC_START),
kasan_mem_to_shadow((void *)KFENCE_AREA_END));
- kasan_early_stage = false;
+ /* Enable KASAN here before kasan_mem_to_shadow(). */
+ static_branch_enable(&kasan_flag_enabled);
/* Populate the linear mapping */
for_each_mem_range(i, &pa_start, &pa_end) {
@@ -329,9 +328,6 @@ void __init kasan_init(void)
csr_write64(__pa_symbol(swapper_pg_dir), LOONGARCH_CSR_PGDH);
local_flush_tlb_all();
- /* 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 = 0;
pr_info("KernelAddressSanitizer initialized.\n");
--
2.41.0
next prev parent reply other threads:[~2025-08-12 13:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-12 13:09 [PATCH 0/4] mm/kasan: " Baoquan He
2025-08-12 13:09 ` Baoquan He [this message]
2025-08-12 13:09 ` [PATCH 2/4] arch/powerpc: " Baoquan He
2025-08-12 13:09 ` [PATCH 3/4] arch/um: " Baoquan He
2025-08-12 13:09 ` [PATCH 4/4] mm/kasan: " Baoquan He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250812130933.71593-2-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=alexghiti@rivosinc.com \
--cc=andreyknvl@gmail.com \
--cc=chenhuacai@loongson.cn \
--cc=christophe.leroy@csgroup.eu \
--cc=davidgow@google.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=hca@linux.ibm.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-um@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=ryabinin.a.a@gmail.com \
--cc=snovitoll@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®