• Mikhail Zaslonko's avatar
    memory_hotplug: fix kernel_panic on offline page processing · 4e8346d0
    Mikhail Zaslonko authored
    Within show_valid_zones() the function test_pages_in_a_zone() should be
    called for online memory blocks only.
    
    Otherwise it might lead to the VM_BUG_ON due to uninitialized struct
    pages (when CONFIG_DEBUG_VM_PGFLAGS kernel option is set):
    
     page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
     ------------[ cut here ]------------
     Call Trace:
     ([<000000000038f91e>] test_pages_in_a_zone+0xe6/0x168)
      [<0000000000923472>] show_valid_zones+0x5a/0x1a8
      [<0000000000900284>] dev_attr_show+0x3c/0x78
      [<000000000046f6f0>] sysfs_kf_seq_show+0xd0/0x150
      [<00000000003ef662>] seq_read+0x212/0x4b8
      [<00000000003bf202>] __vfs_read+0x3a/0x178
      [<00000000003bf3ca>] vfs_read+0x8a/0x148
      [<00000000003bfa3a>] ksys_read+0x62/0xb8
      [<0000000000bc2220>] system_call+0xdc/0x2d8
    
    That VM_BUG_ON was triggered by the page poisoning introduced in
    mm/sparse.c with the git commit d0dc12e8 ("mm/memory_hotplug:
    optimize memory hotplug").
    
    With the same commit the new 'nid' field has been added to the struct
    memory_block in order to store and later on derive the node id for
    offline pages (instead of accessing struct page which might be
    uninitialized).  But one reference to nid in show_valid_zones() function
    has been overlooked.  Fixed with current commit.  Also, nr_pages will
    not be used any more after test_pages_in_a_zone() call, do not update
    it.
    
    Link: http://lkml.kernel.org/r/20180828090539.41491-1-zaslonko@linux.ibm.com
    Fixes: d0dc12e8 ("mm/memory_hotplug: optimize memory hotplug")
    Signed-off-by: default avatarMikhail Zaslonko <zaslonko@linux.ibm.com>
    Acked-by: default avatarMichal Hocko <mhocko@suse.com>
    Reviewed-by: default avatarPavel Tatashin <pavel.tatashin@microsoft.com>
    Cc: <stable@vger.kernel.org>	[4.17+]
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    4e8346d0
memory.c 20.5 KB