Skip to content

Commit 786a895

Browse files
aryabinintorvalds
authored andcommitted
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>
1 parent 0b24bec commit 786a895

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

mm/kasan/kasan.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/init.h>
2121
#include <linux/kernel.h>
2222
#include <linux/memblock.h>
23+
#include <linux/memory.h>
2324
#include <linux/mm.h>
2425
#include <linux/printk.h>
2526
#include <linux/sched.h>
@@ -300,3 +301,23 @@ EXPORT_SYMBOL(__asan_storeN_noabort);
300301
/* to shut up compiler complaints */
301302
void __asan_handle_no_return(void) {}
302303
EXPORT_SYMBOL(__asan_handle_no_return);
304+
305+
#ifdef CONFIG_MEMORY_HOTPLUG
306+
static int kasan_mem_notifier(struct notifier_block *nb,
307+
unsigned long action, void *data)
308+
{
309+
return (action == MEM_GOING_ONLINE) ? NOTIFY_BAD : NOTIFY_OK;
310+
}
311+
312+
static int __init kasan_memhotplug_init(void)
313+
{
314+
pr_err("WARNING: KASan doesn't support memory hot-add\n");
315+
pr_err("Memory hot-add will be disabled\n");
316+
317+
hotplug_memory_notifier(kasan_mem_notifier, 0);
318+
319+
return 0;
320+
}
321+
322+
module_init(kasan_memhotplug_init);
323+
#endif

0 commit comments

Comments
 (0)