OpenCloudOS-Kernel/arch/sh/mm
David Hildenbrand feee6b2989 mm/memory_hotplug: shrink zones when offlining memory
We currently try to shrink a single zone when removing memory.  We use
the zone of the first page of the memory we are removing.  If that
memmap was never initialized (e.g., memory was never onlined), we will
read garbage and can trigger kernel BUGs (due to a stale pointer):

    BUG: unable to handle page fault for address: 000000000000353d
    #PF: supervisor write access in kernel mode
    #PF: error_code(0x0002) - not-present page
    PGD 0 P4D 0
    Oops: 0002 [#1] SMP PTI
    CPU: 1 PID: 7 Comm: kworker/u8:0 Not tainted 5.3.0-rc5-next-20190820+ #317
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.4
    Workqueue: kacpi_hotplug acpi_hotplug_work_fn
    RIP: 0010:clear_zone_contiguous+0x5/0x10
    Code: 48 89 c6 48 89 c3 e8 2a fe ff ff 48 85 c0 75 cf 5b 5d c3 c6 85 fd 05 00 00 01 5b 5d c3 0f 1f 840
    RSP: 0018:ffffad2400043c98 EFLAGS: 00010246
    RAX: 0000000000000000 RBX: 0000000200000000 RCX: 0000000000000000
    RDX: 0000000000200000 RSI: 0000000000140000 RDI: 0000000000002f40
    RBP: 0000000140000000 R08: 0000000000000000 R09: 0000000000000001
    R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000140000
    R13: 0000000000140000 R14: 0000000000002f40 R15: ffff9e3e7aff3680
    FS:  0000000000000000(0000) GS:ffff9e3e7bb00000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 000000000000353d CR3: 0000000058610000 CR4: 00000000000006e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
     __remove_pages+0x4b/0x640
     arch_remove_memory+0x63/0x8d
     try_remove_memory+0xdb/0x130
     __remove_memory+0xa/0x11
     acpi_memory_device_remove+0x70/0x100
     acpi_bus_trim+0x55/0x90
     acpi_device_hotplug+0x227/0x3a0
     acpi_hotplug_work_fn+0x1a/0x30
     process_one_work+0x221/0x550
     worker_thread+0x50/0x3b0
     kthread+0x105/0x140
     ret_from_fork+0x3a/0x50
    Modules linked in:
    CR2: 000000000000353d

Instead, shrink the zones when offlining memory or when onlining failed.
Introduce and use remove_pfn_range_from_zone(() for that.  We now
properly shrink the zones, even if we have DIMMs whereby

 - Some memory blocks fall into no zone (never onlined)

 - Some memory blocks fall into multiple zones (offlined+re-onlined)

 - Multiple memory blocks that fall into different zones

Drop the zone parameter (with a potential dubious value) from
__remove_pages() and __remove_section().

Link: http://lkml.kernel.org/r/20191006085646.5768-6-david@redhat.com
Fixes: f1dd2cd13c ("mm, memory_hotplug: do not associate hotadded memory to zones until online")	[visible after d0dc12e86b]
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Logan Gunthorpe <logang@deltatee.com>
Cc: <stable@vger.kernel.org>	[5.0+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-04 13:55:08 -08:00
..
Kconfig mm: remove quicklist page table caches 2019-09-24 15:54:09 -07:00
Makefile sh: use the generic get_user_pages_fast code 2019-07-12 11:05:44 -07:00
alignment.c procfs: new helper - PDE_DATA(inode) 2013-04-09 14:13:32 -04:00
asids-debugfs.c sh: no need to check return value of debugfs_create functions 2019-06-03 15:39:40 +02:00
cache-debugfs.c sh: no need to check return value of debugfs_create functions 2019-06-03 15:39:40 +02:00
cache-j2.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 211 2019-05-30 11:29:53 -07:00
cache-sh2.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 211 2019-05-30 11:29:53 -07:00
cache-sh2a.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 211 2019-05-30 11:29:53 -07:00
cache-sh3.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 211 2019-05-30 11:29:53 -07:00
cache-sh4.c mm: fix races between swapoff and flush dcache 2018-04-05 21:36:26 -07:00
cache-sh5.c sh: move inline before return type 2017-07-12 16:26:04 -07:00
cache-sh7705.c mm: fix races between swapoff and flush dcache 2018-04-05 21:36:26 -07:00
cache-shx3.c sh: prefix sh-specific "CCR" and "CCR2" by "SH_" 2014-03-04 07:55:49 -08:00
cache.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 211 2019-05-30 11:29:53 -07:00
consistent.c sh: Use pr_warn instead of pr_warning 2019-10-18 13:52:05 +02:00
extable_32.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
extable_64.c lib/extable.c: use bsearch() library function in search_extable() 2017-07-10 16:32:35 -07:00
fault.c mm, kprobes: generalize and rename notify_page_fault() as kprobe_page_fault() 2019-07-16 19:23:22 -07:00
flush-sh4.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
hugetlbpage.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
init.c mm/memory_hotplug: shrink zones when offlining memory 2020-01-04 13:55:08 -08:00
ioremap.c sh: remove __iounmap 2019-11-11 21:18:19 +01:00
ioremap_fixed.c mm: remove include/linux/bootmem.h 2018-10-31 08:54:16 -07:00
kmap.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 211 2019-05-30 11:29:53 -07:00
mmap.c mm: larger stack guard gap, between vmas 2017-06-19 21:50:20 +08:00
nommu.c mm: consolidate pgtable_cache_init() and pgd_cache_init() 2019-09-24 15:54:09 -07:00
numa.c treewide: add checks for the return value of memblock_alloc*() 2019-03-12 10:04:02 -07:00
pgtable.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
pmb.c sh: no need to check return value of debugfs_create functions 2019-06-03 15:39:40 +02:00
sram.c sh: fix up fallout from system.h disintegration. 2012-03-30 19:29:57 +09:00
tlb-debugfs.c sh: no need to check return value of debugfs_create functions 2019-06-03 15:39:40 +02:00
tlb-pteaex.c Disintegrate asm/system.h for SH 2012-03-28 18:30:03 +01:00
tlb-sh3.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 211 2019-05-30 11:29:53 -07:00
tlb-sh4.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 211 2019-05-30 11:29:53 -07:00
tlb-sh5.c sh: delete __cpuinit usage from all sh files 2013-07-14 19:36:53 -04:00
tlb-urb.c sh: update the TLB replacement counter for entry wiring. 2010-03-26 11:37:16 +09:00
tlbex_32.c sh: Enable shared page fault handler for _32/_64. 2012-05-14 15:33:28 +09:00
tlbex_64.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
tlbflush_32.c sh: Provide a global TLB flush for U/I-TLB clear. 2010-07-02 15:44:09 +09:00
tlbflush_64.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
uncached.c treewide: replace #include <asm/sizes.h> with #include <linux/sizes.h> 2019-05-14 19:52:52 -07:00