Skip to contentSkip to conversation

kasan: fix memory notifier handling

PATCH Applied David Hildenbrand 3 participants 10 messages May 22, 2018 – May 23, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover kasan: fix memory notifier handling

If onlining of pages fails (is canceled), 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.

v1 -> v2:
- s/MEM_CANCEL_OFFLINE/MEM_CANCEL_ONLINE

David Hildenbrand (2):
kasan: free allocated shadow memory on MEM_CANCEL_ONLINE
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 v2 1/2 kasan: free allocated shadow memory on MEM_CANCEL_ONLINE

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..53564229674b 100644
@@ -867,6 +867,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
 		kmemleak_ignore(ret);
 		return NOTIFY_OK;
 	}
+	case MEM_CANCEL_ONLINE:
 	case MEM_OFFLINE: {
 		struct vm_struct *vm;
 
Signature · 1 line
2.17.0
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] kasan: free allocated shadow memory on MEM_CANCEL_ONLINE

Quoted 5 lines · David Hildenbrand

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

---

Fixes fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
Quoted 16 lines
 mm/kasan/kasan.c | 1 +
 1 file changed, 1 insertion(+)
mm/kasan/kasan.c +1 -0
index 135ce2838c89..53564229674b 100644
@@ -867,6 +867,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
 		kmemleak_ignore(ret);
 		return NOTIFY_OK;
 	}
+	case MEM_CANCEL_ONLINE:
 	case MEM_OFFLINE: {
 		struct vm_struct *vm;
 
#3 lore raw

PATCH v2 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 53564229674b..a8b85706e2d6 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
Acked-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot

Quoted 7 lines · 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.

reproducible

Quoted 3 lines

---

Fixes fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
Quoted 15 lines
 mm/kasan/kasan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kasan/kasan.c +1 -1
index 53564229674b..a8b85706e2d6 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
#5 lore raw

Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot

Quoted 11 lines · Andrey Ryabinin
Quoted 7 lines · 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.

Quoted 8 lines

reproducible

Quoted 3 lines

---

Fixes fa69b5989bb0 ("mm/kasan: add support for memory hotplug")

Think this even dates back to:

786a8959912e ("kasan: disable memory hotplug")

Quoted 16 lines
Quoted 16 lines
 mm/kasan/kasan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kasan/kasan.c +1 -1
index 53564229674b..a8b85706e2d6 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 · 3 lines
Thanks,

David / dhildenb
#6 lore raw

Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot

Quoted 17 lines · David Hildenbrand
Quoted 16 lines · Andrey Ryabinin
Quoted 7 lines · 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.

reproducible

Quoted 3 lines

---

Quoted 8 lines
Quoted 3 lines
Fixes fa69b5989bb0 ("mm/kasan: add support for memory hotplug")

Think this even dates back to:

786a8959912e ("kasan: disable memory hotplug")

Indeed.

maintainer
#7 lore raw

Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot

Quoted 24 lines · On Tue, 22 May 2018 22:50:12 +0300 Andrey Ryabinin <[email protected]>…
Quoted 21 lines · David Hildenbrand
Quoted 19 lines · Andrey Ryabinin
Quoted 7 lines · 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.

reproducible

Quoted 3 lines

---

Fixes fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
Quoted 6 lines
Quoted 4 lines

Think this even dates back to:

786a8959912e ("kasan: disable memory hotplug")

Indeed.

Is a backport to -stable justified for either of these patches?

#8 lore raw

Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot

Quoted 26 lines · Andrew Morton
Quoted 24 lines · On Tue, 22 May 2018 22:50:12 +0300 Andrey Ryabinin <[email protected]>…
Quoted 21 lines · David Hildenbrand
Quoted 19 lines · Andrey Ryabinin
Quoted 7 lines · 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.

reproducible

Quoted 3 lines

---

Fixes fa69b5989bb0 ("mm/kasan: add support for memory hotplug")
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Think this even dates back to:

786a8959912e ("kasan: disable memory hotplug")

Indeed.

Is a backport to -stable justified for either of these patches?

I don't see any reasons to not backport these.
The first one fixes failure to online memory, why it shouldn't be fixed in -stable? The second one is fixes boot crash, it's definitely stable material IMO.

#9 lore raw

Re: [PATCH v2 2/2] kasan: fix memory hotplug during boot

Quoted 34 lines · Andrey Ryabinin
Quoted 31 lines · Andrew Morton
Quoted 29 lines · On Tue, 22 May 2018 22:50:12 +0300 Andrey Ryabinin <[email protected]>…
Quoted 25 lines · David Hildenbrand
Quoted 11 lines · Andrey Ryabinin
Quoted 7 lines · 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.

Quoted 8 lines

reproducible

Quoted 3 lines

---

Fixes fa69b5989bb0 ("mm/kasan: add support for memory hotplug")

Think this even dates back to:

786a8959912e ("kasan: disable memory hotplug")

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Indeed.

Is a backport to -stable justified for either of these patches?

I don't see any reasons to not backport these.
The first one fixes failure to online memory, why it shouldn't be fixed in -stable? The second one is fixes boot crash, it's definitely stable material IMO.

Agreed, at least the second one should be cc stable, as I can reproduce it with a simple QEMU command.

Signature · 3 lines
Thanks,

David / dhildenb