• Toshi Kani's avatar
    mm/memory_hotplug.c: check start_pfn in test_pages_in_a_zone() · deb88a2a
    Toshi Kani authored
    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
    bdee237c ("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
    5f0f2887 ("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 bdee237c ("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.comSigned-off-by: default avatarToshi 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>
    Cc: <stable@vger.kernel.org>	[4.4+]
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    deb88a2a
memory_hotplug.c 54.7 KB