• Dan Williams's avatar
    x86, memremap: fix altmap accounting at free · a7e6c701
    Dan Williams authored
    Commit 24b6d416 "mm: pass the vmem_altmap to vmemmap_free" converted
    the vmemmap_free() path to pass the altmap argument all the way through
    the call chain rather than looking it up based on the page.
    Unfortunately that ends up over freeing altmap allocated pages in some
    cases since free_pagetable() is used to free both memmap space and pte
    space, where only the memmap stored in huge pages uses altmap
    allocations.
    
    Given that altmap allocations for memmap space are special cased in
    vmemmap_populate_hugepages() add a symmetric / special case
    free_hugepage_table() to handle altmap freeing, and cleanup the unneeded
    passing of altmap to leaf functions that do not require it.
    
    Without this change the sanity check accounting in
    devm_memremap_pages_release() will throw a warning with the following
    signature.
    
     nd_pmem pfn10.1: devm_memremap_pages_release: failed to free all reserved pages
     WARNING: CPU: 44 PID: 3539 at kernel/memremap.c:310 devm_memremap_pages_release+0x1c7/0x220
     CPU: 44 PID: 3539 Comm: ndctl Tainted: G             L   4.16.0-rc1-linux-stable #7
     RIP: 0010:devm_memremap_pages_release+0x1c7/0x220
     [..]
     Call Trace:
      release_nodes+0x225/0x270
      device_release_driver_internal+0x15d/0x210
      bus_remove_device+0xe2/0x160
      device_del+0x130/0x310
      ? klist_release+0x56/0x100
      ? nd_region_notify+0xc0/0xc0 [libnvdimm]
      device_unregister+0x16/0x60
    
    This was missed in testing since not all configurations will trigger
    this warning.
    
    Fixes: 24b6d416 ("mm: pass the vmem_altmap to vmemmap_free")
    Reported-by: default avatarJane Chu <jane.chu@oracle.com>
    Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
    a7e6c701
init_64.c 37.2 KB