Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kasan: disable memory hotplug

Currently memory hotplug won't work with KASan. As we don't have shadow
for hotplugged memory, kernel will crash on the first access to it. To
make this work we will need to allocate shadow for new memory.

At some future point proper memory hotplug support will be implemented.
Until then, print a warning at startup and disable memory hot-add.

Signed-off-by: Andrey Ryabinin <a.ryabinin@samsung.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Konstantin Serebryany <kcc@google.com>
Cc: Dmitry Chernenkov <dmitryc@google.com>
Signed-off-by: Andrey Konovalov <adech.fo@gmail.com>
Cc: Yuri Gribov <tetra2005@gmail.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andrey Ryabinin and committed by
Linus Torvalds
786a8959 0b24becc

+21
+21
mm/kasan/kasan.c
··· 20 20 #include <linux/init.h> 21 21 #include <linux/kernel.h> 22 22 #include <linux/memblock.h> 23 + #include <linux/memory.h> 23 24 #include <linux/mm.h> 24 25 #include <linux/printk.h> 25 26 #include <linux/sched.h> ··· 301 300 /* to shut up compiler complaints */ 302 301 void __asan_handle_no_return(void) {} 303 302 EXPORT_SYMBOL(__asan_handle_no_return); 303 + 304 + #ifdef CONFIG_MEMORY_HOTPLUG 305 + static int kasan_mem_notifier(struct notifier_block *nb, 306 + unsigned long action, void *data) 307 + { 308 + return (action == MEM_GOING_ONLINE) ? NOTIFY_BAD : NOTIFY_OK; 309 + } 310 + 311 + static int __init kasan_memhotplug_init(void) 312 + { 313 + pr_err("WARNING: KASan doesn't support memory hot-add\n"); 314 + pr_err("Memory hot-add will be disabled\n"); 315 + 316 + hotplug_memory_notifier(kasan_mem_notifier, 0); 317 + 318 + return 0; 319 + } 320 + 321 + module_init(kasan_memhotplug_init); 322 + #endif