linux-stable/arch/loongarch/mm
Huacai Chen 1a629fe4cc LoongArch: Make virt_addr_valid()/__virt_addr_valid() work with KFENCE
When enabling both CONFIG_KFENCE and CONFIG_DEBUG_SG, I get the
following backtraces when running LongArch kernels.

[    2.496257] kernel BUG at include/linux/scatterlist.h:187!
...
[    2.501925] Call Trace:
[    2.501950] [<9000000004ad59c4>] sg_init_one+0xac/0xc0
[    2.502204] [<9000000004a438f8>] do_test_kpp+0x278/0x6e4
[    2.502353] [<9000000004a43dd4>] alg_test_kpp+0x70/0xf4
[    2.502494] [<9000000004a41b48>] alg_test+0x128/0x690
[    2.502631] [<9000000004a3d898>] cryptomgr_test+0x20/0x40
[    2.502775] [<90000000041b4508>] kthread+0x138/0x158
[    2.502912] [<9000000004161c48>] ret_from_kernel_thread+0xc/0xa4

The backtrace is always similar but not exactly the same. It is always
triggered from cryptomgr_test, but not always from the same test.

Analysis shows that with CONFIG_KFENCE active, the address returned from
kmalloc() and friends is not always below vm_map_base. It is allocated
by kfence_alloc() which at least sometimes seems to get its memory from
an address space above vm_map_base. This causes __virt_addr_valid() to
return false for the affected objects.

Let __virt_addr_valid() return 1 for kfence pool addresses, this make
virt_addr_valid()/__virt_addr_valid() work with KFENCE.

Reported-by: Guenter Roeck <linux@roeck-us.net>
Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-04-10 21:08:51 +08:00
..
Makefile LoongArch: Add KASAN (Kernel Address Sanitizer) support 2023-09-06 22:54:16 +08:00
cache.c LoongArch: Remove shm_align_mask and use SHMLBA instead 2023-09-06 22:53:09 +08:00
extable.c LoongArch: BPF: Add BPF exception tables 2022-12-14 08:36:11 +08:00
fault.c LoongArch: Fix some build warnings with W=1 2023-09-20 14:26:28 +08:00
hugetlbpage.c LoongArch: Fix some build warnings with W=1 2023-09-20 14:26:28 +08:00
init.c LoongArch: Replace kmap_atomic() with kmap_local_page() in copy_user_highpage() 2023-10-18 08:42:52 +08:00
ioremap.c LoongArch: Fix some build warnings with W=1 2023-09-20 14:26:28 +08:00
kasan_init.c LoongArch: Fix earlycon parameter if KASAN enabled 2024-02-06 12:32:05 +08:00
maccess.c
mmap.c LoongArch: Make virt_addr_valid()/__virt_addr_valid() work with KFENCE 2024-04-10 21:08:51 +08:00
page.S LoongArch: Replace #include <asm/export.h> with #include <linux/export.h> 2023-08-25 23:40:26 +08:00
pgtable.c LoongArch: Make {virt, phys, page, pfn} translation work with KFENCE 2024-04-10 21:08:51 +08:00
tlb.c LoongArch: Add ORC stack unwinder support 2024-03-11 22:23:47 +08:00
tlbex.S LoongArch: Add ORC stack unwinder support 2024-03-11 22:23:47 +08:00