[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20241018040024.1060903-1-chenhuacai@loongson.cn>
Date: Fri, 18 Oct 2024 12:00:24 +0800
From: Huacai Chen <chenhuacai@...ngson.cn>
To: Huacai Chen <chenhuacai@...nel.org>
Cc: loongarch@...ts.linux.dev,
Xuefeng Li <lixuefeng@...ngson.cn>,
Guo Ren <guoren@...nel.org>,
Xuerui Wang <kernel@...0n.name>,
Jiaxun Yang <jiaxun.yang@...goat.com>,
linux-kernel@...r.kernel.org,
loongson-kernel@...ts.loongnix.cn,
Huacai Chen <chenhuacai@...ngson.cn>,
stable@...r.kernel.org,
Kanglong Wang <wangkanglong@...ngson.cn>
Subject: [PATCH] LoongArch: Make KASAN usable for variable cpu_vabits
Currently, KASAN on LoongArch assume the CPU VA bits is 48, which is
true for Loongson-3 series, but not for Loongson-2 series (only 40 or
lower), this patch fix that issue and make KASAN usable for variable
cpu_vabits.
1. Define XRANGE_SHADOW_SHIFT which means valid address length from
VA_BITS to min(cpu_vabits, VA_BITS).
2. In kasan_mem_to_shadow() let DMW addresses which exceed XRANGE_SIZE
to return kasan_early_shadow_page.
Cc: stable@...r.kernel.org
Signed-off-by: Kanglong Wang <wangkanglong@...ngson.cn>
Signed-off-by: Huacai Chen <chenhuacai@...ngson.cn>
---
arch/loongarch/include/asm/kasan.h | 2 +-
arch/loongarch/mm/kasan_init.c | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/include/asm/kasan.h b/arch/loongarch/include/asm/kasan.h
index cd6084f4e153..c6bce5fbff57 100644
--- a/arch/loongarch/include/asm/kasan.h
+++ b/arch/loongarch/include/asm/kasan.h
@@ -16,7 +16,7 @@
#define XRANGE_SHIFT (48)
/* Valid address length */
-#define XRANGE_SHADOW_SHIFT (PGDIR_SHIFT + PAGE_SHIFT - 3)
+#define XRANGE_SHADOW_SHIFT min(cpu_vabits, VA_BITS)
/* Used for taking out the valid address */
#define XRANGE_SHADOW_MASK GENMASK_ULL(XRANGE_SHADOW_SHIFT - 1, 0)
/* One segment whole address space size */
diff --git a/arch/loongarch/mm/kasan_init.c b/arch/loongarch/mm/kasan_init.c
index 427d6b1aec09..e5ecc8c12034 100644
--- a/arch/loongarch/mm/kasan_init.c
+++ b/arch/loongarch/mm/kasan_init.c
@@ -48,6 +48,10 @@ void *kasan_mem_to_shadow(const void *addr)
return (void *)(kasan_early_shadow_page);
maddr &= XRANGE_SHADOW_MASK;
+
+ if (maddr >= XRANGE_SIZE)
+ return (void *)(kasan_early_shadow_page);
+
switch (xrange) {
case XKPRANGE_CC_SEG:
offset = XKPRANGE_CC_SHADOW_OFFSET;
--
2.43.5
Powered by blists - more mailing lists