Right now, only static dax regions have a valid @pgmap pointer in its struct dev_dax. Dynamic dax case however, do not. In preparation for device-dax compound devmap support, make sure that dev_dax pgmap field is set after it has been allocated and initialized. dynamic dax device have the @pgmap is allocated at probe() and it's managed by devm (contrast to static dax region which a pgmap is provided and dax core kfrees it). So in addition to ensure a valid @pgmap, clear the pgmap when the dynamic dax device is released to avoid the same pgmap ranges to be re-requested across multiple region device reconfigs. Suggested-by: Dan Williams <dan.j.williams@xxxxxxxxx> Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx> --- drivers/dax/bus.c | 8 ++++++++ drivers/dax/device.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 6cc4da4c713d..49dbff9ba609 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -363,6 +363,14 @@ void kill_dev_dax(struct dev_dax *dev_dax) kill_dax(dax_dev); unmap_mapping_range(inode->i_mapping, 0, 0, 1); + + /* + * Dynamic dax region have the pgmap allocated via dev_kzalloc() + * and thus freed by devm. Clear the pgmap to not have stale pgmap + * ranges on probe() from previous reconfigurations of region devices. + */ + if (!is_static(dev_dax->region)) + dev_dax->pgmap = NULL; } EXPORT_SYMBOL_GPL(kill_dev_dax); diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 0b82159b3564..6e348b5f9d45 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -426,6 +426,8 @@ int dev_dax_probe(struct dev_dax *dev_dax) } pgmap->type = MEMORY_DEVICE_GENERIC; + dev_dax->pgmap = pgmap; + addr = devm_memremap_pages(dev, pgmap); if (IS_ERR(addr)) return PTR_ERR(addr); -- 2.17.1