Skip to contentSkip to conversation

libnvdimm: add to_{nvdimm,nd_region}_dev()

RFC In review Oliver O'Halloran 4 participants 10 messages Jun 27, 2017 – Jul 11, 2017 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC 1/4 libnvdimm: add to_{nvdimm,nd_region}_dev()

struct device contains the ->of_node pointer so that devices can be assoicated with the device-tree node that created them on DT platforms. libnvdimm hides the struct device for regions and nvdimm devices inside of an opaque structure so this patch adds accessors for each to allow the of_nvdimm driver to set the of_node pointer.

---
 drivers/nvdimm/dimm_devs.c   | 6 ++++++
 drivers/nvdimm/region_devs.c | 6 ++++++
 include/linux/libnvdimm.h    | 2 ++
 3 files changed, 14 insertions(+)
drivers/nvdimm/dimm_devs.c +6 -0
index f0d1b7e5de01..cbddac011181 100644
@@ -227,6 +227,12 @@ struct nvdimm *to_nvdimm(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(to_nvdimm);
 
+struct device *to_nvdimm_dev(struct nvdimm *nvdimm)
+{
+	return &nvdimm->dev;
+}
+EXPORT_SYMBOL_GPL(to_nvdimm_dev);
+
 struct nvdimm *nd_blk_region_to_dimm(struct nd_blk_region *ndbr)
 {
 	struct nd_region *nd_region = &ndbr->nd_region;
drivers/nvdimm/region_devs.c +6 -0
index cbaab4210c39..6c3988135fd5 100644
@@ -182,6 +182,12 @@ struct nd_region *to_nd_region(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(to_nd_region);
 
+struct device *to_nd_region_dev(struct nd_region *region)
+{
+	return &region->dev;
+}
+EXPORT_SYMBOL_GPL(to_nd_region_dev);
+
 struct nd_blk_region *to_nd_blk_region(struct device *dev)
 {
 	struct nd_region *nd_region = to_nd_region(dev);
include/linux/libnvdimm.h +2 -0
index 550761477005..10fbc523ff95 100644
@@ -139,6 +139,8 @@ struct nd_region *to_nd_region(struct device *dev);
 struct nd_blk_region *to_nd_blk_region(struct device *dev);
 struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus);
 struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus);
+struct device *to_nvdimm_dev(struct nvdimm *nvdimm);
+struct device *to_nd_region_dev(struct nd_region *region);
 const char *nvdimm_name(struct nvdimm *nvdimm);
 struct kobject *nvdimm_kobj(struct nvdimm *nvdimm);
 unsigned long nvdimm_cmd_mask(struct nvdimm *nvdimm);
Signature · 6 lines
2.9.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#2 lore raw

RFC 2/4 libnvdimm: Add a device-tree interface

In reply to a message not in the archive

A fairly bare-bones set of device-tree bindings so libnvdimm can be used on powerpc and other, less cool, device-tree based platforms.

---
The current bindings are essentially this:

nonvolatile-memory {
	compatible = "nonvolatile-memory", "special-memory";
	ranges;

	region@0 {
		compatible = "nvdimm,byte-addressable";
		reg = <0x0 0x1000>;
	};

	region@1000 {
		compatible = "nvdimm,byte-addressable";
		reg = <0x1000 0x1000>;
	};
};

To handle interleave sets, etc the plan was the add an extra property with the interleave stride and a "mapping" property with <&DIMM, dimm-start-offset> tuples for each dimm in the interleave set. Block MMIO regions can be added with a different compatible type, but I'm not too concerned with them for now.

Does this sound reasonable? Is there anything this scheme would make difficult?

---
 drivers/nvdimm/Kconfig     |  10 +++
 drivers/nvdimm/Makefile    |   1 +
 drivers/nvdimm/of_nvdimm.c | 209 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/nvdimm/of_nvdimm.c
drivers/nvdimm/Kconfig +10 -0
index 5bdd499b5f4f..72d147b55596 100644
@@ -102,4 +102,14 @@ config NVDIMM_DAX
 
 	  Select Y if unsure
 
+config OF_NVDIMM
+	tristate "Device-tree support for NVDIMMs"
+	depends on OF
+	default LIBNVDIMM
+	help
+	  Allows byte addressable persistent memory regions to be described in the
+	  device-tree.
+
+	  Select Y if unsure.
+
 endif
drivers/nvdimm/Makefile +1 -0
index 909554c3f955..622961f4849d 100644
@@ -3,6 +3,7 @@ obj-$(CONFIG_BLK_DEV_PMEM) += nd_pmem.o
 obj-$(CONFIG_ND_BTT) += nd_btt.o
 obj-$(CONFIG_ND_BLK) += nd_blk.o
 obj-$(CONFIG_X86_PMEM_LEGACY) += nd_e820.o
+obj-$(CONFIG_OF_NVDIMM) += of_nvdimm.o
 
 nd_pmem-y := pmem.o
 
drivers/nvdimm/of_nvdimm.c new file +209 -0

209 lines not on this page · raw message

Signature · 6 lines
2.9.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#6 lore raw

RFC 3/4 powerpc: Add pmem API support

In reply to Oliver O'Halloran

Adds powerpc64 implementations of:

memcpy_flushcache()
arch_wb_cache_pmem()
arch_invalidate_pmem()

Which form the architecture-specific portition of the persistent memory API. These functions provide cache-management primitives for the DAX drivers and libNVDIMM.

---
This should go on to of the ZONE_DEVICE patches. If you want a full tree there's one here that's based on next-20170626 with Dan's libnvdimm-pending branch merged in: https://github.com/oohal/linux/tree/ppc-nvdimm-4.13

---
 arch/powerpc/Kconfig            |  1 +
 arch/powerpc/include/asm/pmem.h | 42 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 arch/powerpc/include/asm/pmem.h
arch/powerpc/Kconfig +1 -0
index 4526c9ba09b6..f551f3a26130 100644
@@ -127,6 +127,7 @@ config PPC
 	select ARCH_HAS_ELF_RANDOMIZE
 	select ARCH_HAS_FORTIFY_SOURCE
 	select ARCH_HAS_GCOV_PROFILE_ALL
+	select ARCH_HAS_PMEM_API                if PPC64
 	select ARCH_HAS_SCALED_CPUTIME		if VIRT_CPU_ACCOUNTING_NATIVE
 	select ARCH_HAS_SG_CHAIN
 	select ARCH_HAS_TICK_BROADCAST		if GENERIC_CLOCKEVENTS_BROADCAST
arch/powerpc/include/asm/pmem.h new file +42 -0

42 lines not on this page · raw message

Signature · 6 lines
2.9.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#8 lore raw

RFC 4/4 powerpc/powernv: Create platform devs for nvdimm buses

In reply to Oliver O'Halloran

Scan the devicetree for nonvolatile-memory buses and instantiate a platform device for them.

---
 arch/powerpc/platforms/powernv/opal.c | 3 +++
 1 file changed, 3 insertions(+)
arch/powerpc/platforms/powernv/opal.c +3 -0
index 59684b4af4d1..bd3ed78f6f04 100644
@@ -775,6 +775,9 @@ static int __init opal_init(void)
 	/* Create i2c platform devices */
 	opal_pdev_init("ibm,opal-i2c");
 
+	/* Handle non-volatile memory devices */
+	opal_pdev_init("nonvolatile-memory");
+
 	/* Setup a heatbeat thread if requested by OPAL */
 	opal_init_heartbeat();
 
Signature · 6 lines
2.9.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#4 lore raw

Re: [RFC 2/4] libnvdimm: Add a device-tree interface

In reply to a message not in the archive

Hi,

Quoted 2 lines · Oliver O'Halloran

A fairly bare-bones set of device-tree bindings so libnvdimm can be used on powerpc and other, less cool, device-tree based platforms.

;)

Quoted 5 lines

---
The current bindings are essentially this:

Quoted 14 lines
nonvolatile-memory {
	compatible = "nonvolatile-memory", "special-memory";
	ranges;

	region@0 {
		compatible = "nvdimm,byte-addressable";
		reg = <0x0 0x1000>;
	};

	region@1000 {
		compatible = "nvdimm,byte-addressable";
		reg = <0x1000 0x1000>;
	};
};

This needs to have a proper binding document under Documentation/devicetree/bindings/. Something like the reserved-memory bdings would be a good template.

If we want thet "nvdimm" vendor-prefix, that'll have to be reserved, too (see Documentation/devicetree/bindings/vendor-prefixes.txt).

What is "special-memory"? What other memory types would be described here?

What exacctly does "nvdimm,byte-addressable" imply? I suspect that you also expect such memory to be compatible with mappings using (some) cacheable attributes?

Perhaps the byte-addressable property should be a boolean property on the region, rather than part of the compatible string.

Quoted 5 lines

To handle interleave sets, etc the plan was the add an extra property with the interleave stride and a "mapping" property with <&DIMM, dimm-start-offset> tuples for each dimm in the interleave set. Block MMIO regions can be added with a different compatible type, but I'm not too concerned with them for now.

Sorry, I'm not too familiar with nonvolatile memory. What are interleave sets?

What are block MMIO regions?

Is there any documentation one can refer to for any of this?

[...]

drivers/nvdimm/of_nvdimm.c line 194

Quoted 5 lines
drivers/nvdimm/of_nvdimm.c new file +5 -0
+static const struct of_device_id of_nvdimm_bus_match[] = {
+	{ .compatible = "nonvolatile-memory" },
+	{ .compatible = "special-memory" },
+	{ },
+};

Why both? Is the driver handling other "special-memory"?

Thanks,
Mark.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#5 lore raw

Re: [RFC 2/4] libnvdimm: Add a device-tree interface

Hi Mark,

Thanks for the review and sorry, I really should have added more context. I was originally just going to send this to the linux-nvdimm list, but I figured the wider device-tree community might be interested too.

Preamble:

Non-volatile DIMMs (nvdimms) are otherwise normal DDR DIMMs that are based on some kind of non-volatile memory with DRAM-like performance (i.e. not flash). The best known example would probably be Intel's 3D XPoint technology, but there are a few others around. The non-volatile aspect makes them useful as storage devices and being part of the memory space allows the backing storage to be exposed to userspace via mmap() provided the kernel supports it. The mmap() trick is enabled by the kernel supporting "direct access" aka DAX.

With that out of the way...

Quoted 28 lines · Mark Rutland

Hi,

Quoted 2 lines · Oliver O'Halloran

A fairly bare-bones set of device-tree bindings so libnvdimm can be used on powerpc and other, less cool, device-tree based platforms.

;)

Quoted 5 lines

---
The current bindings are essentially this:

Quoted 14 lines
nonvolatile-memory {
      compatible = "nonvolatile-memory", "special-memory";
      ranges;

      region@0 {
              compatible = "nvdimm,byte-addressable";
              reg = <0x0 0x1000>;
      };

      region@1000 {
              compatible = "nvdimm,byte-addressable";
              reg = <0x1000 0x1000>;
      };
};
Quoted 6 lines

This needs to have a proper binding document under Documentation/devicetree/bindings/. Something like the reserved-memory bdings would be a good template.

If we want thet "nvdimm" vendor-prefix, that'll have to be reserved, too (see Documentation/devicetree/bindings/vendor-prefixes.txt).

It's on my TODO list, I just wanted to get some comments on the overall approach before doing the rest of the grunt work.

Quoted 7 lines

What is "special-memory"? What other memory types would be described here?

What exacctly does "nvdimm,byte-addressable" imply? I suspect that you also expect such memory to be compatible with mappings using (some) cacheable attributes?

I think it's always been assumed that nvdimm memory can be treated as cacheable system memory for all intents and purposes. It might be useful to be able to override it on a per-bus or per-region basis though.

Quoted 3 lines

Perhaps the byte-addressable property should be a boolean property on the region, rather than part of the compatible string.

See below.

Quoted 8 lines
Quoted 5 lines

To handle interleave sets, etc the plan was the add an extra property with the interleave stride and a "mapping" property with <&DIMM, dimm-start-offset> tuples for each dimm in the interleave set. Block MMIO regions can be added with a different compatible type, but I'm not too concerned with them for now.

Sorry, I'm not too familiar with nonvolatile memory. What are interleave sets?

An interleave set refers to a group of DIMMs which share a physical address range. The addresses in the range are assigned to different backing DIMMs to improve performance. E.g

Addr 0 to Addr 127 are on DIMM0, Addr 127 to 255 are on DIMM1, Addr 256 to 384 are on DIMM0, etc, etc

software needs to be aware of the interleave pattern so it can localise memory errors to a specific DIMM.

Quoted 2 lines

What are block MMIO regions?

NVDIMMs come in two flavours: byte addressable and block aperture. The byte addressable type can be treated as conventional memory while the block aperture type are essentially an MMIO block device. Their contents are accessed via the MMIO window rather than being presented to the system as RAM so they don't have any of the features that make NVDIMMs interesting. It would be nice if we could punt them into a different driver, unfortunately ACPI allows storage on one DIMM to be partitioned into byte addressable and block regions and libnvdimm provides the management interface for both. Dan Williams, who maintains libnvdimm and the ACPI interface to it, would be a better person to ask about the finer details.

Quoted 2 lines

Is there any documentation one can refer to for any of this?

Documentation/nvdimm/nvdimm.txt has a fairly detailed overview of how libnvdimm operates. The short version is that libnvdimm provides a "nvdimm_bus" container for "regions" and "dimms." Regions are chunks of memory and come in the block or byte types mentioned above, while DIMMs refer to the physical devices. A firmware specific driver converts the firmware's hardware description into a set of DIMMs, a set of regions, and a set of relationships between the two.

On top of that, regions are partitioned into "namespaces" which are then exported to userspace as either a block device (with PAGE_SIZE blocks) or as a "DAX device." In the block device case a filesystem is used to manage the storage and provided the filesystem supports FS_DAX and is mounted with -o dax, mmap() calls will map the backing memory directly rather than buffering IO in the page cache. DAX devices can be mmap()ed to access the backing storage directly so all the management issues can be punted to userspace.

Quoted 10 lines

[...]

drivers/nvdimm/of_nvdimm.c line 194

Quoted 5 lines
drivers/nvdimm/of_nvdimm.c new file +5 -0
+static const struct of_device_id of_nvdimm_bus_match[] = {
+     { .compatible = "nonvolatile-memory" },
+     { .compatible = "special-memory" },
+     { },
+};

Why both? Is the driver handling other "special-memory"?

This is one of the things I was hoping the community could help decide. "nonvolatile-memory" is probably a more accurate description of the for the current usage, but the functionality does have other uses. The interface might be useful for exposing any kind memory with special characteristics, like high-bandwidth memory or memory on a coherent accelerator.

Thanks,
Oliver
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#9 lore raw
In reply to Oliver O'Halloran
Quoted 5 lines · Oliver O'Halloran

struct device contains the ->of_node pointer so that devices can be assoicated with the device-tree node that created them on DT platforms. libnvdimm hides the struct device for regions and nvdimm devices inside of an opaque structure so this patch adds accessors for each to allow the of_nvdimm driver to set the of_node pointer.

I'd rather go the other way and pass in the of_node to the bus and dimm registration routines. It's a generic property of the device so we should handle it like other generic device properties that get set at initialization time like 'attr_groups' in nvdimm_bus_descriptor, or a new parameter to nvdimm_create().
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#7 lore raw

Re: [RFC 3/4] powerpc: Add pmem API support

In reply to Oliver O'Halloran
Quoted 10 lines · Oliver O'Halloran

Adds powerpc64 implementations of:

memcpy_flushcache()
arch_wb_cache_pmem()
arch_invalidate_pmem()

Which form the architecture-specific portition of the persistent memory API. These functions provide cache-management primitives for the DAX drivers and libNVDIMM.

Ok, now that we have commit 0aed55af8834 "x86, uaccess: introduce copy_from_iter_flushcache for pmem / cache-bypass operations" upstream that changes the model for how an architecture advertises pmem-specific cache management routines. CONFIG_ARCH_HAS_PMEM_API causes the pmem driver to try to link to these helpers rather than dummy fallbacks:

arch_wb_cache_pmem
arch_invalidate_pmem

....and CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE indicates that the arch has all the needed "flushcache" apis:

__copy_from_user_flushcache
memcpy_page_flushcache
memcpy_flushcache
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#10 lore raw
In reply to Dan Williams
Quoted 7 lines · Dan Williams
Quoted 5 lines · Oliver O'Halloran

struct device contains the ->of_node pointer so that devices can be assoicated with the device-tree node that created them on DT platforms. libnvdimm hides the struct device for regions and nvdimm devices inside of an opaque structure so this patch adds accessors for each to allow the of_nvdimm driver to set the of_node pointer.

Quoted 5 lines

I'd rather go the other way and pass in the of_node to the bus and dimm registration routines. It's a generic property of the device so we should handle it like other generic device properties that get set at initialization time like 'attr_groups' in nvdimm_bus_descriptor, or a new parameter to nvdimm_create().

Sure. I just figured it would be preferable to keep firmware specific details inside the firmware driver rather than adding #ifdef CONFIG_OF around the place. Do you have any objections to making nvdimm_create() take a descriptor structure rather than adding a parameter?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#11 lore raw
Quoted 14 lines · Oliver
Quoted 7 lines · Dan Williams
Quoted 5 lines · Oliver O'Halloran

struct device contains the ->of_node pointer so that devices can be assoicated with the device-tree node that created them on DT platforms. libnvdimm hides the struct device for regions and nvdimm devices inside of an opaque structure so this patch adds accessors for each to allow the of_nvdimm driver to set the of_node pointer.

Quoted 5 lines

I'd rather go the other way and pass in the of_node to the bus and dimm registration routines. It's a generic property of the device so we should handle it like other generic device properties that get set at initialization time like 'attr_groups' in nvdimm_bus_descriptor, or a new parameter to nvdimm_create().

Quoted 4 lines

Sure. I just figured it would be preferable to keep firmware specific details inside the firmware driver rather than adding #ifdef CONFIG_OF around the place. Do you have any objections to making nvdimm_create() take a descriptor structure rather than adding a parameter?

I don't see why we need "#ifdef CONFIG_OF". It's just a "struct of_node *" pointer that can be forward declared as "struct of_node;" we don't need the full definition.

Yes, I'm fine with converting nvdimm_create() to a take a descriptor,
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm