diff options
authorDan Williams <>2019-08-08 14:43:49 -0700
committerDan Williams <>2019-08-09 14:16:15 -0700
commit06282373ff57a2b82621be4f84f981e1b0a4eb28 (patch)
parentd75996dd022b6d83bd14af59b2775b1aa639e4b9 (diff)
mm/memremap: Fix reuse of pgmap instances with internal references
Currently, attempts to shutdown and re-enable a device-dax instance trigger: Missing reference count teardown definition WARNING: CPU: 37 PID: 1608 at mm/memremap.c:211 devm_memremap_pages+0x234/0x850 [..] RIP: 0010:devm_memremap_pages+0x234/0x850 [..] Call Trace: dev_dax_probe+0x66/0x190 [device_dax] really_probe+0xef/0x390 driver_probe_device+0xb4/0x100 device_driver_attach+0x4f/0x60 Given that the setup path initializes pgmap->ref, arrange for it to be also torn down so devm_memremap_pages() is ready to be called again and not be mistaken for the 3rd-party per-cpu-ref case. Fixes: 24917f6b1041 ("memremap: provide an optional internal refcount in struct dev_pagemap") Reported-by: Fan Du <> Tested-by: Vishal Verma <> Cc: Andrew Morton <> Cc: Christoph Hellwig <> Cc: Ira Weiny <> Cc: Jason Gunthorpe <> Reviewed-by: Christoph Hellwig <> Link: Signed-off-by: Dan Williams <>
1 files changed, 6 insertions, 0 deletions
diff --git a/mm/memremap.c b/mm/memremap.c
index 6ee03a816d67..86432650f829 100644
--- a/mm/memremap.c
+++ b/mm/memremap.c
@@ -91,6 +91,12 @@ static void dev_pagemap_cleanup(struct dev_pagemap *pgmap)
+ /*
+ * Undo the pgmap ref assignment for the internal case as the
+ * caller may re-enable the same pgmap.
+ */
+ if (pgmap->ref == &pgmap->internal_ref)
+ pgmap->ref = NULL;
static void devm_memremap_pages_release(void *data)