All of lore.kernel.org
 help / color / mirror / Atom feed
* Kernel BUG with loongarch and CONFIG_KFENCE and CONFIG_DEBUG_SG
@ 2024-03-27 19:11 Guenter Roeck
  2024-03-27 19:33 ` Xi Ruoyao
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2024-03-27 19:11 UTC (permalink / raw)
  To: loongarch
  Cc: Huacai Chen, WANG Xuerui, Alexander Potapenko, Marco Elver,
	Dmitry Vyukov, kasan-dev

Hi,

when enabling both CONFIG_KFENCE and CONFIG_DEBUG_SG, I get the following
backtraces when running loongarch images in qemu.

[    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.

I have only seen this if CONFIG_DEBUG_SG is enabled because sg_set_buf()
otherwise does not call virt_addr_valid(), but I found that many memory
allocation calls return addresses above vm_map_base, making this a
potential problem when running loongarch images with CONFIG_KFENCE enabled
whenever some code calls virt_addr_valid().

I don't know how to solve the problem, but I did notice that virt_to_page()
does handle situations with addr >= vm_map_base. Maybe a similar solution
would be possible for virt_addr_valid().

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-29 16:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27 19:11 Kernel BUG with loongarch and CONFIG_KFENCE and CONFIG_DEBUG_SG Guenter Roeck
2024-03-27 19:33 ` Xi Ruoyao
2024-03-27 23:38   ` Guenter Roeck
2024-03-29  2:17     ` Huacai Chen
2024-03-29 16:32       ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.