Skip to content
  • Qian Cai's avatar
    mm/page_owner: don't access uninitialized memmaps when reading /proc/pagetypeinfo · de68b45d
    Qian Cai authored
    Uninitialized memmaps contain garbage and in the worst case trigger kernel
    BUGs, especially with CONFIG_PAGE_POISONING.  They should not get touched.
    
    For example, when not onlining a memory block that is spanned by a zone
    and reading /proc/pagetypeinfo with CONFIG_DEBUG_VM_PGFLAGS and
    CONFIG_PAGE_POISONING, we can trigger a kernel BUG:
    
    :/# echo 1 > /sys/devices/system/memory/memory40/online
    :/# echo 1 > /sys/devices/system/memory/memory42/online
    :/# cat /proc/pagetypeinfo > test.file
      [   42.489856] page:fffff2c585200000 is uninitialized and poisoned
      [   42.489861] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
      [   42.492235] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
      [   42.493501] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
      [   42.494533] There is not page extension available.
      [   42.495358] ------------[ cut here ]------------
      [   42.496163] kernel BUG at include/linux/mm.h:1107!
      [   42.497069] invalid opcode: 0000 [#1] SMP NOPTI
    
    Please note that this change does not affect ZONE_DEVICE, because
    pagetypeinfo_showmixedcount_print() is called from
    mm/vmstat.c:pagetypeinfo_showmixedcount() only for populated zones, and
    ZONE_DEVICE is never populated (zone->present_pages always 0).
    
    [david@redhat.com: move check to outer loop, add comment, rephrase description]
    Link: http://lkml.kernel.org/r/20191011140638.8160-1-david@redhat.com
    Fixes: f1dd2cd1 ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e8
    
    
    Signed-off-by: default avatarQian Cai <cai@lca.pw>
    Signed-off-by: default avatarDavid Hildenbrand <david@redhat.com>
    Acked-by: default avatarMichal Hocko <mhocko@suse.com>
    Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
    Cc: Miles Chen <miles.chen@mediatek.com>
    Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
    Cc: Qian Cai <cai@lca.pw>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: <stable@vger.kernel.org>	[4.13+]
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
    de68b45d