aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToshi Kani <toshi.kani@hpe.com>2017-02-03 16:13:20 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-02-09 02:08:27 -0500
commit72f7419610c838abc5e3fde87835a5581e8e368c (patch)
tree65897b5b302ef1badd9c6ce0986f50d34053e399
parent9e255997c2e169ba4bca92e6f84324581b28abbe (diff)
mm/memory_hotplug.c: check start_pfn in test_pages_in_a_zone()
commit deb88a2a19e85842d79ba96b05031739ec327ff4 upstream. Patch series "fix a kernel oops when reading sysfs valid_zones", v2. A sysfs memory file is created for each 2GiB memory block on x86-64 when the system has 64GiB or more memory. [1] When the start address of a memory block is not backed by struct page, i.e. a memory range is not aligned by 2GiB, reading its 'valid_zones' attribute file leads to a kernel oops. This issue was observed on multiple x86-64 systems with more than 64GiB of memory. This patch-set fixes this issue. Patch 1 first fixes an issue in test_pages_in_a_zone(), which does not test the start section. Patch 2 then fixes the kernel oops by extending test_pages_in_a_zone() to return valid [start, end). Note for stable kernels: The memory block size change was made by commit bdee237c0343 ("x86: mm: Use 2GB memory block size on large-memory x86-64 systems"), which was accepted to 3.9. However, this patch-set depends on (and fixes) the change to test_pages_in_a_zone() made by commit 5f0f2887f4de ("mm/memory_hotplug.c: check for missing sections in test_pages_in_a_zone()"), which was accepted to 4.4. So, I recommend that we backport it up to 4.4. [1] 'Commit bdee237c0343 ("x86: mm: Use 2GB memory block size on large-memory x86-64 systems")' This patch (of 2): test_pages_in_a_zone() does not check 'start_pfn' when it is aligned by section since 'sec_end_pfn' is set equal to 'pfn'. Since this function is called for testing the range of a sysfs memory file, 'start_pfn' is always aligned by section. Fix it by properly setting 'sec_end_pfn' to the next section pfn. Also make sure that this function returns 1 only when the range belongs to a zone. Link: http://lkml.kernel.org/r/20170127222149.30893-2-toshi.kani@hpe.com Signed-off-by: Toshi Kani <toshi.kani@hpe.com> Cc: Andrew Banman <abanman@sgi.com> Cc: Reza Arbab <arbab@linux.vnet.ibm.com> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--mm/memory_hotplug.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index c3a8141ac788..3a330d7cae69 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1483,7 +1483,7 @@ bool is_mem_section_removable(unsigned long start_pfn, unsigned long nr_pages)
1483} 1483}
1484 1484
1485/* 1485/*
1486 * Confirm all pages in a range [start, end) is belongs to the same zone. 1486 * Confirm all pages in a range [start, end) belong to the same zone.
1487 */ 1487 */
1488int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn) 1488int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn)
1489{ 1489{
@@ -1491,9 +1491,9 @@ int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn)
1491 struct zone *zone = NULL; 1491 struct zone *zone = NULL;
1492 struct page *page; 1492 struct page *page;
1493 int i; 1493 int i;
1494 for (pfn = start_pfn, sec_end_pfn = SECTION_ALIGN_UP(start_pfn); 1494 for (pfn = start_pfn, sec_end_pfn = SECTION_ALIGN_UP(start_pfn + 1);
1495 pfn < end_pfn; 1495 pfn < end_pfn;
1496 pfn = sec_end_pfn + 1, sec_end_pfn += PAGES_PER_SECTION) { 1496 pfn = sec_end_pfn, sec_end_pfn += PAGES_PER_SECTION) {
1497 /* Make sure the memory section is present first */ 1497 /* Make sure the memory section is present first */
1498 if (!present_section_nr(pfn_to_section_nr(pfn))) 1498 if (!present_section_nr(pfn_to_section_nr(pfn)))
1499 continue; 1499 continue;
@@ -1512,7 +1512,11 @@ int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn)
1512 zone = page_zone(page); 1512 zone = page_zone(page);
1513 } 1513 }
1514 } 1514 }
1515 return 1; 1515
1516 if (zone)
1517 return 1;
1518 else
1519 return 0;
1516} 1520}
1517 1521
1518/* 1522/*