Skip to contentSkip to conversation

kasan: fix memory notifier handling

PATCH Superseded David Hildenbrand 1 participant 4 messages May 22, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover kasan: fix memory notifier handling

If onlining of pages fails, we don't properly free up memory. Also, the memory hotplug notifier is not registered early enough, still failing on certain setups where memory is detected, added and onlined early.

David Hildenbrand (2):
kasan: free allocated shadow memory on MEM_CANCEL_OFFLINE
kasan: fix memory hotplug during boot

 mm/kasan/kasan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.0
#1 lore raw

PATCH 1/2 kasan: free allocated shadow memory on MEM_CANCEL_OFFLINE

We have to free memory again when we cancel onlining, otherwise a later onlining attempt will fail.

---
 mm/kasan/kasan.c | 1 +
 1 file changed, 1 insertion(+)
mm/kasan/kasan.c +1 -0
index 135ce2838c89..8baefe1a674b 100644
@@ -867,6 +867,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
 		kmemleak_ignore(ret);
 		return NOTIFY_OK;
 	}
+	case MEM_CANCEL_OFFLINE:
 	case MEM_OFFLINE: {
 		struct vm_struct *vm;
 
Signature · 1 line
2.17.0
#2 lore raw

Re: [PATCH v1 1/2] kasan: free allocated shadow memory on MEM_CANCEL_OFFLINE

Quoted 13 lines · David Hildenbrand

We have to free memory again when we cancel onlining, otherwise a later onlining attempt will fail.

---
 mm/kasan/kasan.c | 1 +
 1 file changed, 1 insertion(+)
mm/kasan/kasan.c +0 -0
index 135ce2838c89..8baefe1a674b 100644

mm/kasan/kasan.c static int __meminit kasan_mem_notifier(struct notifier_block *nb, · line 870

Quoted 4 lines
mm/kasan/kasan.c +1 -0
@@ -867,6 +867,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
 		kmemleak_ignore(ret);
 		return NOTIFY_OK;
 	}
+	case MEM_CANCEL_OFFLINE:

Typo, MEM_CANCEL_ONLINE

Quoted 4 lines
mm/kasan/kasan.c +0 -0
 	case MEM_OFFLINE: {
 		struct vm_struct *vm;
 
Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

PATCH 2/2 kasan: fix memory hotplug during boot

In reply to David Hildenbrand

Using module_init() is wrong. E.g. ACPI adds and onlines memory before our memory notifier gets registered.

This makes sure that ACPI memory detected during boot up will not result in a kernel crash.

Easily reproducable with QEMU, just specify a DIMM when starting up.

---
 mm/kasan/kasan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kasan/kasan.c +1 -1
index 8baefe1a674b..04b60d2b607c 100644
@@ -892,5 +892,5 @@ static int __init kasan_memhotplug_init(void)
 	return 0;
 }
 
-module_init(kasan_memhotplug_init);
+core_initcall(kasan_memhotplug_init);
 #endif
Signature · 1 line
2.17.0