devm_memremap_pages: fix vmem_altmap lifetime + alignment handling
authorDan Williams <dan.j.williams@intel.com>
Sat, 30 Jan 2016 05:48:34 +0000 (21:48 -0800)
committerDan Williams <dan.j.williams@intel.com>
Sat, 30 Jan 2016 05:54:04 +0000 (21:54 -0800)
commiteb7d78c9e7f6418932bd5fbee45eb46d5ab05002
tree394076599244a296f4f5b57c3e1e5fabbd40cf8f
parent45eb570a0db3391c88cba04510a20fe7e4125497
devm_memremap_pages: fix vmem_altmap lifetime + alignment handling

to_vmem_altmap() needs to return valid results until
arch_remove_memory() completes.  It also needs to be valid for any pfn
in a section regardless of whether that pfn maps to data.  This escape
was a result of a bug in the unit test.

The signature of this bug is that free_pagetable() fails to retrieve a
vmem_altmap and goes off into the weeds:

 BUG: unable to handle kernel NULL pointer dereference at           (null)
 IP: [<ffffffff811d2629>] get_pfnblock_flags_mask+0x49/0x60
 [..]
 Call Trace:
  [<ffffffff811d3477>] free_hot_cold_page+0x97/0x1d0
  [<ffffffff811d367a>] __free_pages+0x2a/0x40
  [<ffffffff8191e669>] free_pagetable+0x8c/0xd4
  [<ffffffff8191ef4e>] remove_pagetable+0x37a/0x808
  [<ffffffff8191b210>] vmemmap_free+0x10/0x20

Fixes: 4b94ffdc4163 ("x86, mm: introduce vmem_altmap to augment vmemmap_populate()")
Cc: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
kernel/memremap.c