Commit 712cd386fdc983d318fecf302a2a9cb8e9de90c9
Committed by
Linus Torvalds
1 parent
b9d5ab2562
Exists in
master
and in
20 other branches
mm/memory_hotplug.c: update start_pfn in zone and pg_data when spanned_pages == 0.
If we hot-remove memory only and leave the cpus alive, the corresponding node will not be removed. But the node_start_pfn and node_spanned_pages in pg_data will be reset to 0. In this case, when we hot-add the memory back next time, the node_start_pfn will always be 0 because no pfn is less than 0. After that, if we hot-remove the memory again, it will cause kernel panic in function find_biggest_section_pfn() when it tries to scan all the pfns. The zone will also have the same problem. This patch sets start_pfn to the start_pfn of the section being added when spanned_pages of the zone or pg_data is 0. ---How to reproduce--- 1. hot-add a container with some memory and cpus; 2. hot-remove the container's memory, and leave cpus there; 3. hot-add these memory again; 4. hot-remove them again; then, the kernel will panic. ---Call trace--- BUG: unable to handle kernel paging request at 00000fff82a8cc38 IP: [<ffffffff811c0d55>] find_biggest_section_pfn+0xe5/0x180 ...... Call Trace: [<ffffffff811c1124>] __remove_zone+0x184/0x1b0 [<ffffffff811c11dc>] __remove_section+0x8c/0xb0 [<ffffffff811c12e7>] __remove_pages+0xe7/0x120 [<ffffffff81654f7c>] arch_remove_memory+0x2c/0x80 [<ffffffff81655bb6>] remove_memory+0x56/0x90 [<ffffffff813da0c8>] acpi_memory_device_remove_memory+0x48/0x73 [<ffffffff813da55a>] acpi_memory_device_notify+0x153/0x274 [<ffffffff813b6786>] acpi_ev_notify_dispatch+0x41/0x5f [<ffffffff813a3867>] acpi_os_execute_deferred+0x27/0x34 [<ffffffff81090589>] process_one_work+0x219/0x680 [<ffffffff810923be>] worker_thread+0x12e/0x320 [<ffffffff81098396>] kthread+0xc6/0xd0 [<ffffffff8167c7c4>] kernel_thread_helper+0x4/0x10 ...... ---[ end trace 96d845dbf33fee11 ]--- Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: Wen Congyang <wency@cn.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 2 additions and 2 deletions Side-by-side Diff
mm/memory_hotplug.c
... | ... | @@ -205,7 +205,7 @@ |
205 | 205 | zone_span_writelock(zone); |
206 | 206 | |
207 | 207 | old_zone_end_pfn = zone->zone_start_pfn + zone->spanned_pages; |
208 | - if (start_pfn < zone->zone_start_pfn) | |
208 | + if (!zone->spanned_pages || start_pfn < zone->zone_start_pfn) | |
209 | 209 | zone->zone_start_pfn = start_pfn; |
210 | 210 | |
211 | 211 | zone->spanned_pages = max(old_zone_end_pfn, end_pfn) - |
... | ... | @@ -220,7 +220,7 @@ |
220 | 220 | unsigned long old_pgdat_end_pfn = |
221 | 221 | pgdat->node_start_pfn + pgdat->node_spanned_pages; |
222 | 222 | |
223 | - if (start_pfn < pgdat->node_start_pfn) | |
223 | + if (!pgdat->node_spanned_pages || start_pfn < pgdat->node_start_pfn) | |
224 | 224 | pgdat->node_start_pfn = start_pfn; |
225 | 225 | |
226 | 226 | pgdat->node_spanned_pages = max(old_pgdat_end_pfn, end_pfn) - |