]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
mm/devm_memremap_pages: fix final page put race
authorDan Williams <dan.j.williams@intel.com>
Thu, 13 Jun 2019 22:56:33 +0000 (15:56 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 14 Jun 2019 03:34:56 +0000 (17:34 -1000)
commit50f44ee7248ad2f7984ef081974a6ecd09724b3e
treeab753d9044434c94c8e6d70ead68173c2af339f6
parent1570175abd164b32ea1cc677f9dfd2dc6bd093f5
mm/devm_memremap_pages: fix final page put race

Logan noticed that devm_memremap_pages_release() kills the percpu_ref
drops all the page references that were acquired at init and then
immediately proceeds to unplug, arch_remove_memory(), the backing pages
for the pagemap.  If for some reason device shutdown actually collides
with a busy / elevated-ref-count page then arch_remove_memory() should
be deferred until after that reference is dropped.

As it stands the "wait for last page ref drop" happens *after*
devm_memremap_pages_release() returns, which is obviously too late and
can lead to crashes.

Fix this situation by assigning the responsibility to wait for the
percpu_ref to go idle to devm_memremap_pages() with a new ->cleanup()
callback.  Implement the new cleanup callback for all
devm_memremap_pages() users: pmem, devdax, hmm, and p2pdma.

Link: http://lkml.kernel.org/r/155727339156.292046.5432007428235387859.stgit@dwillia2-desk3.amr.corp.intel.com
Fixes: 41e94a851304 ("add devm_memremap_pages")
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reported-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: "Jérôme Glisse" <jglisse@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/dax/device.c
drivers/nvdimm/pmem.c
drivers/pci/p2pdma.c
include/linux/memremap.h
kernel/memremap.c
mm/hmm.c
tools/testing/nvdimm/test/iomap.c