Skip to contentSkip to conversation

nvdimm: allow exposing RAM as libnvdimm DIMMs

PATCH Superseded Mike Rapoport 2 participants 6 messages Oct 15, 2025 – Oct 23, 2025 libnvdimm: non-volatile memory device

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover nvdimm: allow exposing RAM as libnvdimm DIMMs

From: "Mike Rapoport (Microsoft)" <[email protected]>

Hi,

It's not uncommon that libnvdimm/dax/ndctl are used with normal volatile memory for a whole bunch of $reasons.

Probably the most common usecase is to back VMs memory with fsdax/devdax, but there are others as well when there's a requirement to manage memory separately from the kernel.

The existing mechanisms to expose normal ram as "persistent", such as memmap=x!y on x86 or dummy pmem-region device tree nodes on DT systems lack flexibility to dynamically partition a single region without rebooting the system and sometimes even updating the system firmware. Also, to create several DAX devices with different properties it's necessary to repeat the memmap= command line option or add several pmem-region nodes to the DT.

I propose a new ramdax driver that will create a DIMM device on E820_TYPE_PRAM/pmem-region and that will allow partitioning that device dynamically. The label area is kept in the end of that region and managed by the driver.

v2 changes:
* Change the way driver is bound to a device, following Dan's suggestion. Instead of forcing mutual exclusion of ramdax and nr_e820/of-pmem at build time, rely on 'driver_override' attribute to allow binding ramdax driver to e820_pmem/pmem-region devices.
* Fix build warning reported by kbuild

v1: https://lore.kernel.org/all/[email protected]
* fix offset calculations in ramdax_{get,set}_config_data
* use a magic constant instead of a random number as nd_set->cookie*

RFC: https://lore.kernel.org/all/[email protected]

Mike Rapoport (Microsoft) (1):
nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices

 drivers/nvdimm/Kconfig  |  17 +++
 drivers/nvdimm/Makefile |   1 +
 drivers/nvdimm/ramdax.c | 272 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 290 insertions(+)
 create mode 100644 drivers/nvdimm/ramdax.c

base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787 --
2.50.1

#1 lore raw

PATCH v2 1/1 nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices

From: "Mike Rapoport (Microsoft)" <[email protected]>

There are use cases, for example virtual machine hosts, that create "persistent" memory regions using memmap= option on x86 or dummy pmem-region device tree nodes on DT based systems.

Both these options are inflexible because they create static regions and the layout of the "persistent" memory cannot be adjusted without reboot and sometimes they even require firmware update.

Add a ramdax driver that allows creation of DIMM devices on top of E820_TYPE_PRAM regions and devicetree pmem-region nodes.

The DIMMs support label space management on the "device" and provide a flexible way to access RAM using fsdax and devdax.

---
 drivers/nvdimm/Kconfig  |  17 +++
 drivers/nvdimm/Makefile |   1 +
 drivers/nvdimm/ramdax.c | 272 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 290 insertions(+)
 create mode 100644 drivers/nvdimm/ramdax.c
drivers/nvdimm/Kconfig +17 -0
index fde3e17c836c..9ac96a7cd773 100644
@@ -97,6 +97,23 @@ config OF_PMEM
 
 	  Select Y if unsure.
 
+config RAMDAX
+	tristate "Support persistent memory interfaces on RAM carveouts"
+	depends on OF || X86
+	select X86_PMEM_LEGACY_DEVICE
+	default LIBNVDIMM
+	help
+	  Allows creation of DAX devices on RAM carveouts.
+
+	  Memory ranges that are manually specified by the
+	  'memmap=nn[KMG]!ss[KMG]' kernel command line or defined by dummy
+	  pmem-region device tree nodes would be managed by this driver as DIMM
+	  devices with support for dynamic layout of namespaces.
+	  The driver can be bound to e820_pmem or pmem-region platform
+	  devices using 'driver_override' device attribute.
+
+	  Select N if unsure.
+
 config NVDIMM_KEYS
 	def_bool y
 	depends on ENCRYPTED_KEYS
drivers/nvdimm/Makefile +1 -0
index ba0296dca9db..8c268814936c 100644
@@ -5,6 +5,7 @@ obj-$(CONFIG_ND_BTT) += nd_btt.o
 obj-$(CONFIG_X86_PMEM_LEGACY) += nd_e820.o
 obj-$(CONFIG_OF_PMEM) += of_pmem.o
 obj-$(CONFIG_VIRTIO_PMEM) += virtio_pmem.o nd_virtio.o
+obj-$(CONFIG_RAMDAX) += ramdax.o
 
 nd_pmem-y := pmem.o
 
drivers/nvdimm/ramdax.c new file +272 -0

272 lines not on this page · raw message

Signature · 1 line
2.50.1
Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2 1/1] nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices

Quoted 29 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

There are use cases, for example virtual machine hosts, that create "persistent" memory regions using memmap= option on x86 or dummy pmem-region device tree nodes on DT based systems.

Both these options are inflexible because they create static regions and the layout of the "persistent" memory cannot be adjusted without reboot and sometimes they even require firmware update.

Add a ramdax driver that allows creation of DIMM devices on top of E820_TYPE_PRAM regions and devicetree pmem-region nodes.

The DIMMs support label space management on the "device" and provide a flexible way to access RAM using fsdax and devdax.

---
 drivers/nvdimm/Kconfig  |  17 +++
 drivers/nvdimm/Makefile |   1 +
 drivers/nvdimm/ramdax.c | 272 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 290 insertions(+)
 create mode 100644 drivers/nvdimm/ramdax.c
drivers/nvdimm/Kconfig +0 -0
index fde3e17c836c..9ac96a7cd773 100644

drivers/nvdimm/Kconfig config OF_PMEM · line 102

Quoted 6 lines
drivers/nvdimm/Kconfig +3 -0
@@ -97,6 +97,23 @@ config OF_PMEM
 
 	  Select Y if unsure.
 
+config RAMDAX
+	tristate "Support persistent memory interfaces on RAM carveouts"
+	depends on OF || X86

I see no compile time dependency for CONFIG_OF. The one call to dev_of_node() looks like it still builds in the CONFIG_OF=n case. For CONFIG_X86 the situation is different because the kernel needs infrastructure to build the device.

So maybe change the dependency to drop OF and make it:

depends on X86_PMEM_LEGACY if X86

drivers/nvdimm/Kconfig config OF_PMEM · line 103

Quoted 1 line
drivers/nvdimm/Kconfig +1 -0
+	select X86_PMEM_LEGACY_DEVICE

...and drop this select.

drivers/nvdimm/Kconfig config OF_PMEM · line 113

Quoted 10 lines
drivers/nvdimm/Kconfig +10 -0
+	default LIBNVDIMM
+	help
+	  Allows creation of DAX devices on RAM carveouts.
+
+	  Memory ranges that are manually specified by the
+	  'memmap=nn[KMG]!ss[KMG]' kernel command line or defined by dummy
+	  pmem-region device tree nodes would be managed by this driver as DIMM
+	  devices with support for dynamic layout of namespaces.
+	  The driver can be bound to e820_pmem or pmem-region platform
+	  devices using 'driver_override' device attribute.

Maybe some notes for details like:

* 128K stolen at the end of the memmap range
* supports 509 namespaces (see 'ndctl create-namespace --help')
* must be force bound via driver_override

[..]

Quoted 8 lines
drivers/nvdimm/Kconfig +8 -0
+static int ramdax_probe(struct platform_device *pdev)
+{
+	static struct nvdimm_bus_descriptor nd_desc;
+	struct device *dev = &pdev->dev;
+	struct nvdimm_bus *nvdimm_bus;
+	struct device_node *np;
+	int rc = -ENXIO;
+

drivers/nvdimm/Kconfig config OF_PMEM

Quoted 10 lines
drivers/nvdimm/Kconfig +10 -0
+	nd_desc.provider_name = "ramdax";
+	nd_desc.module = THIS_MODULE;
+	nd_desc.ndctl = ramdax_ctl;
+	nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
+	if (!nvdimm_bus)
+		goto err;
+
+	np = dev_of_node(&pdev->dev);
+	if (np)
+		rc = ramdax_probe_of(pdev, nvdimm_bus, np);

Hmm, I do not see any confirmation that this node is actually a "pmem-region". If you attach the kernel to the wrong device I think you get fireworks that could be avoided with a manual of_match_node() check of the same device_id list as the of_pmem driver.

That still would not require a "depends on OF" given of_match_node() compiles away in the CONFIG_OF=n case.

[..]

This looks good to me. With the above comments addressed you can add:

#3 lore raw

Re: [PATCH v2 1/1] nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices

Quoted 42 lines · On Fri, Oct 17, 2025 at 05:08:11PM -0700, [email protected] wrote:
Quoted 29 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

There are use cases, for example virtual machine hosts, that create "persistent" memory regions using memmap= option on x86 or dummy pmem-region device tree nodes on DT based systems.

Both these options are inflexible because they create static regions and the layout of the "persistent" memory cannot be adjusted without reboot and sometimes they even require firmware update.

Add a ramdax driver that allows creation of DIMM devices on top of E820_TYPE_PRAM regions and devicetree pmem-region nodes.

The DIMMs support label space management on the "device" and provide a flexible way to access RAM using fsdax and devdax.

---
 drivers/nvdimm/Kconfig  |  17 +++
 drivers/nvdimm/Makefile |   1 +
 drivers/nvdimm/ramdax.c | 272 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 290 insertions(+)
 create mode 100644 drivers/nvdimm/ramdax.c
drivers/nvdimm/Kconfig +0 -0
index fde3e17c836c..9ac96a7cd773 100644

drivers/nvdimm/Kconfig config OF_PMEM · line 102

Quoted 6 lines
drivers/nvdimm/Kconfig +3 -0
@@ -97,6 +97,23 @@ config OF_PMEM
 
 	  Select Y if unsure.
 
+config RAMDAX
+	tristate "Support persistent memory interfaces on RAM carveouts"
+	depends on OF || X86

I see no compile time dependency for CONFIG_OF. The one call to dev_of_node() looks like it still builds in the CONFIG_OF=n case. For CONFIG_X86 the situation is different because the kernel needs infrastructure to build the device.

Quoted 3 lines

So maybe change the dependency to drop OF and make it:

depends on X86_PMEM_LEGACY if X86

We can't put if in a depends statement :(
My intention with "depends on OF || X86" was that if it's not really possible to use this driver if it's not X86 or OF because there's nothing to define a platform device for ramdax to bind.

Maybe what we actually need is

select X86_PMEM_LEGACY_DEVICE if X86
default n

so that it could be only explicitly enabled in the configuration and if it is, it will also enable X86_PMEM_LEGACY_DEVICE on x86.
With default set to no it won't be build "accidentailly", but OTOH cloud providers can disable X86_PMEM_LEGACY and enable RAMDAX and distros can build them as modules on x86 and architectures that support OF.

What do you think?

Quoted 17 lines

drivers/nvdimm/Kconfig config OF_PMEM · line 103

Quoted 1 line
drivers/nvdimm/Kconfig +1 -0
+	select X86_PMEM_LEGACY_DEVICE

...and drop this select.

drivers/nvdimm/Kconfig config OF_PMEM · line 113

Quoted 10 lines
drivers/nvdimm/Kconfig +10 -0
+	default LIBNVDIMM
+	help
+	  Allows creation of DAX devices on RAM carveouts.
+
+	  Memory ranges that are manually specified by the
+	  'memmap=nn[KMG]!ss[KMG]' kernel command line or defined by dummy
+	  pmem-region device tree nodes would be managed by this driver as DIMM
+	  devices with support for dynamic layout of namespaces.
+	  The driver can be bound to e820_pmem or pmem-region platform
+	  devices using 'driver_override' device attribute.

Maybe some notes for details like:

Quoted 3 lines

* 128K stolen at the end of the memmap range
* supports 509 namespaces (see 'ndctl create-namespace --help')
* must be force bound via driver_override

Sure.

Quoted 25 lines

[..]

Quoted 8 lines
drivers/nvdimm/Kconfig +8 -0
+static int ramdax_probe(struct platform_device *pdev)
+{
+	static struct nvdimm_bus_descriptor nd_desc;
+	struct device *dev = &pdev->dev;
+	struct nvdimm_bus *nvdimm_bus;
+	struct device_node *np;
+	int rc = -ENXIO;
+

drivers/nvdimm/Kconfig

Quoted 10 lines
drivers/nvdimm/Kconfig +10 -0
+	nd_desc.provider_name = "ramdax";
+	nd_desc.module = THIS_MODULE;
+	nd_desc.ndctl = ramdax_ctl;
+	nvdimm_bus = nvdimm_bus_register(dev, &nd_desc);
+	if (!nvdimm_bus)
+		goto err;
+
+	np = dev_of_node(&pdev->dev);
+	if (np)
+		rc = ramdax_probe_of(pdev, nvdimm_bus, np);

Hmm, I do not see any confirmation that this node is actually a "pmem-region". If you attach the kernel to the wrong device I think you get fireworks that could be avoided with a manual of_match_node() check of the same device_id list as the of_pmem driver.

Quoted 2 lines

That still would not require a "depends on OF" given of_match_node() compiles away in the CONFIG_OF=n case.

With how driver_override is implemented it's possible to get fireworks with any platform device :)

I'll add a manual check for of_match_node() to be on the safer side.

Quoted 5 lines

[..]

This looks good to me. With the above comments addressed you can add:

Signature · 2 lines
Sincerely yours,
Mike.
#4 lore raw

Re: [PATCH v2 1/1] nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices

Mike Rapoport wrote:
[..]

Quoted 9 lines
Quoted 9 lines

drivers/nvdimm/Kconfig config OF_PMEM · line 102

Quoted 3 lines
drivers/nvdimm/Kconfig +3 -0
+config RAMDAX
+	tristate "Support persistent memory interfaces on RAM carveouts"
+	depends on OF || X86

I see no compile time dependency for CONFIG_OF. The one call to dev_of_node() looks like it still builds in the CONFIG_OF=n case. For CONFIG_X86 the situation is different because the kernel needs infrastructure to build the device.

Quoted 5 lines
Quoted 3 lines

So maybe change the dependency to drop OF and make it:

depends on X86_PMEM_LEGACY if X86

We can't put if in a depends statement :(

Ugh, yeah, whoops.

Quoted 14 lines

My intention with "depends on OF || X86" was that if it's not really possible to use this driver if it's not X86 or OF because there's nothing to define a platform device for ramdax to bind.

Maybe what we actually need is

select X86_PMEM_LEGACY_DEVICE if X86
default n
so that it could be only explicitly enabled in the configuration and if it is, it will also enable X86_PMEM_LEGACY_DEVICE on x86.
With default set to no it won't be build "accidentailly", but OTOH cloud providers can disable X86_PMEM_LEGACY and enable RAMDAX and distros can build them as modules on x86 and architectures that support OF.

Quoted 1 line

What do you think?

Perhaps:

    depends on X86_PMEM_LEGACY || OF || COMPILE_TEST

...because it is awkward to select symbols that has dependencies that may be missing, and it shows that this driver has no compile time dependencies on those symbols.

[..]

Quoted 2 lines

With how driver_override is implemented it's possible to get fireworks with any platform device :)

True.

Quoted 1 line

I'll add a manual check for of_match_node() to be on the safer side.

Sounds good.

#5 lore raw

Re: [PATCH v2 1/1] nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices

Quoted 33 lines · On Wed, Oct 22, 2025 at 04:29:23PM -0700, [email protected] wrote:

Mike Rapoport wrote:
[..]

Quoted 9 lines
Quoted 9 lines

drivers/nvdimm/Kconfig config OF_PMEM · line 102

Quoted 3 lines
drivers/nvdimm/Kconfig +3 -0
+config RAMDAX
+	tristate "Support persistent memory interfaces on RAM carveouts"
+	depends on OF || X86

I see no compile time dependency for CONFIG_OF. The one call to dev_of_node() looks like it still builds in the CONFIG_OF=n case. For CONFIG_X86 the situation is different because the kernel needs infrastructure to build the device.

Quoted 5 lines
Quoted 3 lines

So maybe change the dependency to drop OF and make it:

depends on X86_PMEM_LEGACY if X86

We can't put if in a depends statement :(

Ugh, yeah, whoops.

Quoted 14 lines

My intention with "depends on OF || X86" was that if it's not really possible to use this driver if it's not X86 or OF because there's nothing to define a platform device for ramdax to bind.

Maybe what we actually need is

select X86_PMEM_LEGACY_DEVICE if X86
default n
so that it could be only explicitly enabled in the configuration and if it is, it will also enable X86_PMEM_LEGACY_DEVICE on x86.
With default set to no it won't be build "accidentailly", but OTOH cloud providers can disable X86_PMEM_LEGACY and enable RAMDAX and distros can build them as modules on x86 and architectures that support OF.

Quoted 5 lines
Quoted 1 line

What do you think?

Perhaps:

    depends on X86_PMEM_LEGACY || OF || COMPILE_TEST

Works for me :)

Quoted 3 lines

...because it is awkward to select symbols that has dependencies that may be missing, and it shows that this driver has no compile time dependencies on those symbols.

Signature · 2 lines
Sincerely yours,
Mike.