linux-stable/drivers/nvdimm
Dan Williams ec5471c92f mm, devm_memremap_pages: fix shutdown handling
commit a95c90f1e2 upstream.

The last step before devm_memremap_pages() returns success is to allocate
a release action, devm_memremap_pages_release(), to tear the entire setup
down.  However, the result from devm_add_action() is not checked.

Checking the error from devm_add_action() is not enough.  The api
currently relies on the fact that the percpu_ref it is using is killed by
the time the devm_memremap_pages_release() is run.  Rather than continue
this awkward situation, offload the responsibility of killing the
percpu_ref to devm_memremap_pages_release() directly.  This allows
devm_memremap_pages() to do the right thing relative to init failures and
shutdown.

Without this change we could fail to register the teardown of
devm_memremap_pages().  The likelihood of hitting this failure is tiny as
small memory allocations almost always succeed.  However, the impact of
the failure is large given any future reconfiguration, or disable/enable,
of an nvdimm namespace will fail forever as subsequent calls to
devm_memremap_pages() will fail to setup the pgmap_radix since there will
be stale entries for the physical address range.

An argument could be made to require that the ->kill() operation be set in
the @pgmap arg rather than passed in separately.  However, it helps code
readability, tracking the lifetime of a given instance, to be able to grep
the kill routine directly at the devm_memremap_pages() call site.

Link: http://lkml.kernel.org/r/154275558526.76910.7535251937849268605.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Fixes: e8d5134833 ("memremap: change devm_memremap_pages interface...")
Reviewed-by: "Jérôme Glisse" <jglisse@redhat.com>
Reported-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-13 09:51:04 +01:00
..
badrange.c libnvdimm, badrange: remove a WARN for list_empty 2017-11-02 10:42:30 -07:00
blk.c for-4.17/block-20180402 2018-04-05 14:27:02 -07:00
btt.c block: make bdev_ops->rw_page() take a REQ_OP instead of bool 2018-07-18 08:44:14 -06:00
btt.h libnvdimm, btt: Fix an incompatibility in the log layout 2017-12-21 14:59:27 -08:00
btt_devs.c libnvdimm: remove redundant __func__ in dev_dbg 2018-03-06 08:44:17 -08:00
bus.c libnvdimm: Hold reference on parent while scheduling async init 2018-11-13 11:08:42 -08:00
claim.c libnvdimm, pmem: Fix memcpy_mcsafe() return code handling in nsio_rw_bytes() 2018-06-28 18:21:30 -07:00
core.c libnvdimm: remove redundant __func__ in dev_dbg 2018-03-06 08:44:17 -08:00
dax_devs.c libnvdimm: remove redundant __func__ in dev_dbg 2018-03-06 08:44:17 -08:00
dimm.c libnvdimm: Introduce locked DIMM capacity support 2018-07-14 10:27:00 -07:00
dimm_devs.c libnvdimm: Use max contiguous area for namespace size 2018-07-25 14:11:09 -07:00
e820.c libnvdimm, e820: Register all pmem resources 2018-06-02 17:05:43 -07:00
Kconfig Revert "libnvdimm, of_pmem: workaround OF_NUMA=n build error" 2018-04-19 15:10:56 -07:00
label.c libnvdimm, label: change nvdimm_num_label_slots per UEFI 2.7 2018-03-15 13:59:57 -07:00
label.h libnvdimm, label: change min label storage size per UEFI 2.7 2018-03-15 10:44:32 -07:00
Makefile libnvdimm: Add device-tree based driver 2018-04-07 07:53:23 -07:00
namespace_devs.c libnvdimm: Use max contiguous area for namespace size 2018-07-25 14:11:09 -07:00
nd-core.h libnvdimm, pfn: Pad pfn namespaces relative to other regions 2018-12-13 09:16:22 +01:00
nd.h libnvdimm-for-4.19_misc 2018-08-25 18:13:10 -07:00
of_pmem.c libnvdimm, of_pmem: use dev_to_node() instead of of_node_to_nid() 2018-04-19 15:07:10 -07:00
pfn.h libnvdimm, dax: autodetect support 2016-05-20 22:02:57 -07:00
pfn_devs.c libnvdimm, pfn: Pad pfn namespaces relative to other regions 2018-12-13 09:16:22 +01:00
pmem.c mm, devm_memremap_pages: fix shutdown handling 2019-01-13 09:51:04 +01:00
pmem.h libnvdimm, pmem: Restore page attributes when clearing errors 2018-08-20 09:22:45 -07:00
region.c libnvdimm, region: quiet region probe 2018-04-07 07:47:10 -07:00
region_devs.c libnvdimm, pfn: Pad pfn namespaces relative to other regions 2018-12-13 09:16:22 +01:00