aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memory_hotplug.c
diff options
context:
space:
mode:
authorToshi Kani <toshi.kani@hpe.com>2017-02-03 16:13:23 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-02-03 17:13:19 -0500
commita96dfddbcc04336bbed50dc2b24823e45e09e80c (patch)
tree0a6501e0d11cb978a46d8d3753dd449e57a97717 /mm/memory_hotplug.c
parentdeb88a2a19e85842d79ba96b05031739ec327ff4 (diff)
base/memory, hotplug: fix a kernel oops in show_valid_zones()
Reading a sysfs "memoryN/valid_zones" file leads to the following oops when the first page of a range is not backed by struct page. show_valid_zones() assumes that 'start_pfn' is always valid for page_zone(). BUG: unable to handle kernel paging request at ffffea017a000000 IP: show_valid_zones+0x6f/0x160 This issue may happen on x86-64 systems with 64GiB or more memory since their memory block size is bumped up to 2GiB. [1] An example of such systems is desribed below. 0x3240000000 is only aligned by 1GiB and this memory block starts from 0x3200000000, which is not backed by struct page. BIOS-e820: [mem 0x0000003240000000-0x000000603fffffff] usable Since test_pages_in_a_zone() already checks holes, fix this issue by extending this function to return 'valid_start' and 'valid_end' for a given range. show_valid_zones() then proceeds with the valid range. [1] 'Commit bdee237c0343 ("x86: mm: Use 2GB memory block size on large-memory x86-64 systems")' Link: http://lkml.kernel.org/r/20170127222149.30893-3-toshi.kani@hpe.com Signed-off-by: Toshi Kani <toshi.kani@hpe.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Zhang Zhen <zhenzhang.zhang@huawei.com> Cc: Reza Arbab <arbab@linux.vnet.ibm.com> Cc: David Rientjes <rientjes@google.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: <stable@vger.kernel.org> [4.4+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memory_hotplug.c')
-rw-r--r--mm/memory_hotplug.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 1218f73890b6..b8c11e063ff0 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1484,10 +1484,13 @@ bool is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
1484 1484
1485/* 1485/*
1486 * Confirm all pages in a range [start, end) belong to the same zone. 1486 * Confirm all pages in a range [start, end) belong to the same zone.
1487 * When true, return its valid [start, end).
1487 */ 1488 */
1488int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn) 1489int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn,
1490 unsigned long *valid_start, unsigned long *valid_end)
1489{ 1491{
1490 unsigned long pfn, sec_end_pfn; 1492 unsigned long pfn, sec_end_pfn;
1493 unsigned long start, end;
1491 struct zone *zone = NULL; 1494 struct zone *zone = NULL;
1492 struct page *page; 1495 struct page *page;
1493 int i; 1496 int i;
@@ -1509,14 +1512,20 @@ int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn)
1509 page = pfn_to_page(pfn + i); 1512 page = pfn_to_page(pfn + i);
1510 if (zone && page_zone(page) != zone) 1513 if (zone && page_zone(page) != zone)
1511 return 0; 1514 return 0;
1515 if (!zone)
1516 start = pfn + i;
1512 zone = page_zone(page); 1517 zone = page_zone(page);
1518 end = pfn + MAX_ORDER_NR_PAGES;
1513 } 1519 }
1514 } 1520 }
1515 1521
1516 if (zone) 1522 if (zone) {
1523 *valid_start = start;
1524 *valid_end = end;
1517 return 1; 1525 return 1;
1518 else 1526 } else {
1519 return 0; 1527 return 0;
1528 }
1520} 1529}
1521 1530
1522/* 1531/*
@@ -1843,6 +1852,7 @@ static int __ref __offline_pages(unsigned long start_pfn,
1843 long offlined_pages; 1852 long offlined_pages;
1844 int ret, drain, retry_max, node; 1853 int ret, drain, retry_max, node;
1845 unsigned long flags; 1854 unsigned long flags;
1855 unsigned long valid_start, valid_end;
1846 struct zone *zone; 1856 struct zone *zone;
1847 struct memory_notify arg; 1857 struct memory_notify arg;
1848 1858
@@ -1853,10 +1863,10 @@ static int __ref __offline_pages(unsigned long start_pfn,
1853 return -EINVAL; 1863 return -EINVAL;
1854 /* This makes hotplug much easier...and readable. 1864 /* This makes hotplug much easier...and readable.
1855 we assume this for now. .*/ 1865 we assume this for now. .*/
1856 if (!test_pages_in_a_zone(start_pfn, end_pfn)) 1866 if (!test_pages_in_a_zone(start_pfn, end_pfn, &valid_start, &valid_end))
1857 return -EINVAL; 1867 return -EINVAL;
1858 1868
1859 zone = page_zone(pfn_to_page(start_pfn)); 1869 zone = page_zone(pfn_to_page(valid_start));
1860 node = zone_to_nid(zone); 1870 node = zone_to_nid(zone);
1861 nr_pages = end_pfn - start_pfn; 1871 nr_pages = end_pfn - start_pfn;
1862 1872