Skip to contentSkip to conversation

iopmem : A block device for PCIe memory

PATCH In review Stephen Bates 7 participants 25 messages Oct 18, 2016 – Nov 6, 2016

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

cover iopmem : A block device for PCIe memory

This patch follows from an RFC we did earlier this year [1]. This patchset applies cleanly to v4.9-rc1.

Updates since RFC
-----------------
Rebased.
Included the iopmem driver in the submission.

History
-------

There have been several attempts to upstream patchsets that enable DMAs between PCIe peers. These include Peer-Direct [2] and DMA-Buf style patches [3]. None have been successful to date. Haggai Eran gives a nice overview of the prior art in this space in his cover letter [3].

Motivation and Use Cases
------------------------

PCIe IO devices are getting faster. It is not uncommon now to find PCIe network and storage devices that can generate and consume several GB/s. Almost always these devices have either a high performance DMA engine, a number of exposed PCIe BARs or both.

Until this patch, any high-performance transfer of information between two PICe devices has required the use of a staging buffer in system memory. With this patch the bandwidth to system memory is not compromised when high-throughput transfers occurs between PCIe devices. This means that more system memory bandwidth is available to the CPU cores for data processing and manipulation. In addition, in systems where the two PCIe devices reside behind a PCIe switch the datapath avoids the CPU entirely.

Consumers
---------

We provide a PCIe device driver in an accompanying patch that can be used to map any PCIe BAR into a DAX capable block device. For non-persistent BARs this simply serves as an alternative to using system memory bounce buffers. For persistent BARs this can serve as an additional storage device in the system.

Testing and Performance
-----------------------

We have done a moderate about of testing of this patch on a QEMU environment and on real hardware. On real hardware we have observed peer-to-peer writes of up to 4GB/s and reads of up to 1.2 GB/s. In both cases these numbers are limitations of our consumer hardware. In addition, we have observed that the CPU DRAM bandwidth is not impacted when using IOPMEM which is not the case when a traditional path through system memory is taken.

For more information on the testing and performance results see the GitHub site [4].

Known Issues
------------

1. Address Translation. Suggestions have been made that in certain architectures and topologies the dma_addr_t passed to the DMA master in a peer-2-peer transfer will not correctly route to the IO memory intended. However in our testing to date we have not seen this to be an issue, even in systems with IOMMUs and PCIe switches. It is our understanding that an IOMMU only maps system memory and would not interfere with device memory regions. (It certainly has no opportunity to do so if the transfer gets routed through a switch).

2. Memory Segment Spacing. This patch has the same limitations that ZONE_DEVICE does in that memory regions must be spaces at least SECTION_SIZE bytes part. On x86 this is 128MB and there are cases where BARs can be placed closer together than this. Thus ZONE_DEVICE would not be usable on neighboring BARs. For our purposes, this is not an issue as we'd only be looking at enabling a single BAR in a given PCIe device. More exotic use cases may have problems with this.

3. Coherency Issues. When IOMEM is written from both the CPU and a PCIe peer there is potential for coherency issues and for writes to occur out of order. This is something that users of this feature need to be cognizant of. Though really, this isn't much different than the existing situation with things like RDMA: if userspace sets up an MR for remote use, they need to be careful about using that memory region themselves.

4. Architecture. Currently this patch is applicable only to x86_64 architectures. The same is true for much of the code pertaining to PMEM and ZONE_DEVICE. It is hoped that the work will be extended to other ARCH over time.

References
----------
[1] https://patchwork.kernel.org/patch/8583221/
[2] http://comments.gmane.org/gmane.linux.drivers.rdma/21849
[3] http://www.spinics.net/lists/linux-rdma/msg38748.html
[4] https://github.com/sbates130272/zone-device

Logan Gunthorpe (1):
memremap.c : Add support for ZONE_DEVICE IO memory with struct pages.

Stephen Bates (2):
iopmem : Add a block device driver for PCIe attached IO memory. iopmem : Add documentation for iopmem driver

 Documentation/blockdev/00-INDEX   |   2 +
 Documentation/blockdev/iopmem.txt |  62 +++++++
 MAINTAINERS                       |   7 +
 drivers/block/Kconfig             |  27 ++++
 drivers/block/Makefile            |   1 +
 drivers/block/iopmem.c            | 333 ++++++++++++++++++++++++++++++++++++++
 drivers/dax/pmem.c                |   4 +-
 drivers/nvdimm/pmem.c             |   4 +-
 include/linux/memremap.h          |   5 +-
 kernel/memremap.c                 |  80 ++++++++-
 tools/testing/nvdimm/test/iomap.c |   3 +-
 11 files changed, 518 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/blockdev/iopmem.txt
 create mode 100644 drivers/block/iopmem.c

--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

PATCH 1/3 memremap.c : Add support for ZONE_DEVICE IO memory with struct pages.

From: Logan Gunthorpe <[email protected]>

We build on recent work that adds memory regions owned by a device driver (ZONE_DEVICE) [1] and to add struct page support for these new regions of memory [2].

1. Add an extra flags argument into dev_memremap_pages to take in a MEMREMAP_XX argument. We update the existing calls to this function to reflect the change.

2. For completeness, we add MEMREMAP_WT support to the memremap; however we have no actual need for this functionality.

3. We add the static functions, add_zone_device_pages and remove_zone_device pages. These are similar to arch_add_memory except they don't create the memory mapping. We don't believe these need to be made arch specific, but are open to other opinions.

4. dev_memremap_pages and devm_memremap_pages_release are updated to treat IO memory slightly differently. For IO memory we use a combination of the appropriate io_remap function and the zone_device pages functions created above. A flags variable and kaddr pointer are added to struct page_mem to facilitate this for the release function. We also set up the page attribute tables for the mapped region correctly based on the desired mapping.

[1] https://lists.01.org/pipermail/linux-nvdimm/2015-August/001810.html
[2] https://lists.01.org/pipermail/linux-nvdimm/2015-October/002387.html

---
 drivers/dax/pmem.c                |  4 +-
 drivers/nvdimm/pmem.c             |  4 +-
 include/linux/memremap.h          |  5 ++-
 kernel/memremap.c                 | 80 +++++++++++++++++++++++++++++++++++++--
 tools/testing/nvdimm/test/iomap.c |  3 +-
 5 files changed, 86 insertions(+), 10 deletions(-)
drivers/dax/pmem.c +3 -1
index 9630d88..58ac456 100644
@@ -14,6 +14,7 @@
 #include <linux/memremap.h>
 #include <linux/module.h>
 #include <linux/pfn_t.h>
+#include <linux/pmem.h>
 #include "../nvdimm/pfn.h"
 #include "../nvdimm/nd.h"
 #include "dax.h"
@@ -108,7 +109,8 @@ static int dax_pmem_probe(struct device *dev)
 	if (rc)
 		return rc;
 
-	addr = devm_memremap_pages(dev, &res, &dax_pmem->ref, altmap);
+	addr = devm_memremap_pages(dev, &res, &dax_pmem->ref, altmap,
+							ARCH_MEMREMAP_PMEM);
 	if (IS_ERR(addr))
 		return PTR_ERR(addr);
 
drivers/nvdimm/pmem.c +2 -2
index 42b3a82..97032a1 100644
@@ -278,7 +278,7 @@ static int pmem_attach_disk(struct device *dev,
 	pmem->pfn_flags = PFN_DEV;
 	if (is_nd_pfn(dev)) {
 		addr = devm_memremap_pages(dev, &pfn_res, &q->q_usage_counter,
-				altmap);
+				altmap, ARCH_MEMREMAP_PMEM);
 		pfn_sb = nd_pfn->pfn_sb;
 		pmem->data_offset = le64_to_cpu(pfn_sb->dataoff);
 		pmem->pfn_pad = resource_size(res) - resource_size(&pfn_res);
@@ -287,7 +287,7 @@ static int pmem_attach_disk(struct device *dev,
 		res->start += pmem->data_offset;
 	} else if (pmem_should_map_pages(dev)) {
 		addr = devm_memremap_pages(dev, &nsio->res,
-				&q->q_usage_counter, NULL);
+				&q->q_usage_counter, NULL, ARCH_MEMREMAP_PMEM);
 		pmem->pfn_flags |= PFN_MAP;
 	} else
 		addr = devm_memremap(dev, pmem->phys_addr,
include/linux/memremap.h +3 -2
index 9341619..fc99283 100644
@@ -51,12 +51,13 @@ struct dev_pagemap {
 
 #ifdef CONFIG_ZONE_DEVICE
 void *devm_memremap_pages(struct device *dev, struct resource *res,
-		struct percpu_ref *ref, struct vmem_altmap *altmap);
+		struct percpu_ref *ref, struct vmem_altmap *altmap,
+		unsigned long flags);
 struct dev_pagemap *find_dev_pagemap(resource_size_t phys);
 #else
 static inline void *devm_memremap_pages(struct device *dev,
 		struct resource *res, struct percpu_ref *ref,
-		struct vmem_altmap *altmap)
+		struct vmem_altmap *altmap, unsigned long flags)
 {
 	/*
 	 * Fail attempts to call devm_memremap_pages() without
kernel/memremap.c +76 -4

140 lines not on this page · raw message

tools/testing/nvdimm/test/iomap.c +2 -1
index 3ccef73..b82fecb 100644
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/pfn_t.h>
+#include <linux/pmem.h>
 #include <linux/acpi.h>
 #include <linux/io.h>
 #include <linux/mm.h>
@@ -109,7 +110,7 @@ void *__wrap_devm_memremap_pages(struct device *dev, struct resource *res,
 
 	if (nfit_res)
 		return nfit_res->buf + offset - nfit_res->res.start;
-	return devm_memremap_pages(dev, res, ref, altmap);
+	return devm_memremap_pages(dev, res, ref, altmap, ARCH_MEMREMAP_PMEM);
 }
 EXPORT_SYMBOL(__wrap_devm_memremap_pages);
 

--
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Re: [PATCH 1/3] memremap.c : Add support for ZONE_DEVICE IO memory with struct pages.

Quoted 18 lines · Stephen Bates

From: Logan Gunthorpe <logang-OTvnGxWRz7hWk0Htik3J/[email protected]>

We build on recent work that adds memory regions owned by a device driver (ZONE_DEVICE) [1] and to add struct page support for these new regions of memory [2].

1. Add an extra flags argument into dev_memremap_pages to take in a MEMREMAP_XX argument. We update the existing calls to this function to reflect the change.

2. For completeness, we add MEMREMAP_WT support to the memremap; however we have no actual need for this functionality.

3. We add the static functions, add_zone_device_pages and remove_zone_device pages. These are similar to arch_add_memory except they don't create the memory mapping. We don't believe these need to be made arch specific, but are open to other opinions.

Quoted 8 lines

4. dev_memremap_pages and devm_memremap_pages_release are updated to treat IO memory slightly differently. For IO memory we use a combination of the appropriate io_remap function and the zone_device pages functions created above. A flags variable and kaddr pointer are added to struct page_mem to facilitate this for the release function. We also set up the page attribute tables for the mapped region correctly based on the desired mapping.

This description says "what" is being done, but not "why".

In the cover letter, "[PATCH 0/3] iopmem : A block device for PCIe memory", it mentions that the lack of I/O coherency is a known issue and users of this functionality need to be cognizant of the pitfalls. If that is the case why do we need support for different cpu mapping types than the default write-back cache setting? It's up to the application to handle cache cpu flushing similar to what we require of device-dax users in the persistent memory case.

#3 lore raw

Re: [PATCH 1/3] memremap.c : Add support for ZONE_DEVICE IO memory with struct pages.

Quoted 28 lines · Dan Williams
Quoted 18 lines · Stephen Bates

From: Logan Gunthorpe <[email protected]>

We build on recent work that adds memory regions owned by a device driver (ZONE_DEVICE) [1] and to add struct page support for these new regions of memory [2].

1. Add an extra flags argument into dev_memremap_pages to take in a MEMREMAP_XX argument. We update the existing calls to this function to reflect the change.

2. For completeness, we add MEMREMAP_WT support to the memremap; however we have no actual need for this functionality.

3. We add the static functions, add_zone_device_pages and remove_zone_device pages. These are similar to arch_add_memory except they don't create the memory mapping. We don't believe these need to be made arch specific, but are open to other opinions.

Quoted 8 lines

4. dev_memremap_pages and devm_memremap_pages_release are updated to treat IO memory slightly differently. For IO memory we use a combination of the appropriate io_remap function and the zone_device pages functions created above. A flags variable and kaddr pointer are added to struct page_mem to facilitate this for the release function. We also set up the page attribute tables for the mapped region correctly based on the desired mapping.

Quoted 1 line

This description says "what" is being done, but not "why".

Hi Dan

We discuss the motivation in the cover letter.

Quoted 8 lines

In the cover letter, "[PATCH 0/3] iopmem : A block device for PCIe memory", it mentions that the lack of I/O coherency is a known issue and users of this functionality need to be cognizant of the pitfalls. If that is the case why do we need support for different cpu mapping types than the default write-back cache setting? It's up to the application to handle cache cpu flushing similar to what we require of device-dax users in the persistent memory case.

Some of the iopmem hardware we have tested has certain alignment restrictions on BAR accesses. At the very least we require write combine mappings for these. We then felt it appropriate to add the other mappings for the sake of completeness.

Cheers

Stephen

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [PATCH 1/3] memremap.c : Add support for ZONE_DEVICE IO memory with struct pages.

Quoted 44 lines · Stephen Bates
Quoted 28 lines · Dan Williams
Quoted 18 lines · Stephen Bates

From: Logan Gunthorpe <logang-OTvnGxWRz7hWk0Htik3J/[email protected]>

We build on recent work that adds memory regions owned by a device driver (ZONE_DEVICE) [1] and to add struct page support for these new regions of memory [2].

1. Add an extra flags argument into dev_memremap_pages to take in a MEMREMAP_XX argument. We update the existing calls to this function to reflect the change.

2. For completeness, we add MEMREMAP_WT support to the memremap; however we have no actual need for this functionality.

3. We add the static functions, add_zone_device_pages and remove_zone_device pages. These are similar to arch_add_memory except they don't create the memory mapping. We don't believe these need to be made arch specific, but are open to other opinions.

Quoted 8 lines

4. dev_memremap_pages and devm_memremap_pages_release are updated to treat IO memory slightly differently. For IO memory we use a combination of the appropriate io_remap function and the zone_device pages functions created above. A flags variable and kaddr pointer are added to struct page_mem to facilitate this for the release function. We also set up the page attribute tables for the mapped region correctly based on the desired mapping.

Quoted 1 line

This description says "what" is being done, but not "why".

Hi Dan

We discuss the motivation in the cover letter.

Quoted 8 lines

In the cover letter, "[PATCH 0/3] iopmem : A block device for PCIe memory", it mentions that the lack of I/O coherency is a known issue and users of this functionality need to be cognizant of the pitfalls. If that is the case why do we need support for different cpu mapping types than the default write-back cache setting? It's up to the application to handle cache cpu flushing similar to what we require of device-dax users in the persistent memory case.

Quoted 4 lines

Some of the iopmem hardware we have tested has certain alignment restrictions on BAR accesses. At the very least we require write combine mappings for these. We then felt it appropriate to add the other mappings for the sake of completeness.

If the device can support write-combine then it can support bursts, so I wonder why it couldn't support read bursts for cache fills...

#5 lore raw

Re: [PATCH 1/3] memremap.c : Add support for ZONE_DEVICE IO memory with struct pages.

Quoted 9 lines · Dan Williams
Quoted 9 lines
Quoted 8 lines

In the cover letter, "[PATCH 0/3] iopmem : A block device for PCIe memory", it mentions that the lack of I/O coherency is a known issue and users of this functionality need to be cognizant of the pitfalls. If that is the case why do we need support for different cpu mapping types than the default write-back cache setting? It's up to the application to handle cache cpu flushing similar to what we require of device-dax users in the persistent memory case.

Quoted 7 lines
Quoted 4 lines

Some of the iopmem hardware we have tested has certain alignment restrictions on BAR accesses. At the very least we require write combine mappings for these. We then felt it appropriate to add the other mappings for the sake of completeness.

If the device can support write-combine then it can support bursts, so I wonder why it couldn't support read bursts for cache fills...

Dan

You make a good point. We did some testing on this and for the HW we have access too we did see that a standard WB mapping worked. Interestly though the local access performance was much slower than for the WC mapping. We also noticed the PAT entries we not marked correctly in the WB case. I am trying to get access to some other HW for more testing.

Grepping for the address of interest:

In WB mode it's:

uncached-minus @ 0x381f80000000-0x381fc0000000

In WC mode it's:

write-combining @ 0x381f80000000-0x381fc0000000

Cheers

Stephen

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

PATCH 2/3 iopmem : Add a block device driver for PCIe attached IO memory.

In reply to Stephen Bates

Add a new block device driver that binds to PCIe devices and turns PCIe BARs into DAX capable block devices.

---
 MAINTAINERS            |   7 ++
 drivers/block/Kconfig  |  27 ++++
 drivers/block/Makefile |   1 +
 drivers/block/iopmem.c | 333 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 368 insertions(+)
 create mode 100644 drivers/block/iopmem.c
MAINTAINERS +7 -0
index 1cd38a7..c379f9d 100644
@@ -6510,6 +6510,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/iommu/
 F:	drivers/iommu/
 
+IOPMEM BLOCK DEVICE DRVIER
+M:	Stephen Bates <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/block/iopmem.c
+F:	Documentation/blockdev/iopmem.txt
+
 IP MASQUERADING
 M:	Juanjo Ciarlante <[email protected]>
 S:	Maintained
drivers/block/Kconfig +27 -0
index 39dd30b..13ae1e7 100644
@@ -537,4 +537,31 @@ config BLK_DEV_RSXX
 	  To compile this driver as a module, choose M here: the
 	  module will be called rsxx.
 
+config BLK_DEV_IOPMEM
+	tristate "Persistent block device backed by PCIe Memory"
+	depends on ZONE_DEVICE
+	default n
+	help
+	  Say Y here if you want to include a generic device driver
+	  that can create a block device from persistent PCIe attached
+	  IO memory.
+
+	  To compile this driver as a module, choose M here: The
+	  module will be called iopmem. A block device will be created
+	  for each PCIe attached device that matches the vendor and
+	  device ID as specified in the module. Alternativel this
+	  driver can be bound to any aribtary PCIe function using the
+	  sysfs bind entry.
+
+	  This block device supports direct access (DAX) file systems
+	  and supports struct page backing for the IO Memory. This
+	  makes the underlying memory suitable for things like RDMA
+	  Memory Regions and Direct IO which is useful for PCIe
+	  peer-to-peer DMA operations.
+
+	  Note that persistent is only assured if the memory on the
+	  PCIe card has some form of power loss protection. This could
+	  be provided via some form of battery, a supercap/NAND combo
+	  or some exciting new persistent memory technology.
+
 endif # BLK_DEV
drivers/block/Makefile +1 -0
index 1e9661e..1f4f69b 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX)	+= mtip32xx/
 obj-$(CONFIG_BLK_DEV_RSXX) += rsxx/
 obj-$(CONFIG_BLK_DEV_NULL_BLK)	+= null_blk.o
 obj-$(CONFIG_ZRAM) += zram/
+obj-$(CONFIG_BLK_DEV_IOPMEM)	+= iopmem.o
 
 skd-y		:= skd_main.o
 swim_mod-y	:= swim.o swim_asm.o
drivers/block/iopmem.c new file +333 -0

333 lines not on this page · raw message

--
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

Re: [PATCH 2/3] iopmem : Add a block device driver for PCIe attached IO memory.

Quoted 1 line

FYI, that address has bounced throught the whole thread for me, replacing it with a known good one for now.

Quoted 4 lines

+ * This driver is heavily based on drivers/block/pmem.c.
+ * Copyright (c) 2014, Intel Corporation.
+ * Copyright (C) 2007 Nick Piggin
+ * Copyright (C) 2007 Novell Inc.

Is there anything left of it actually? I didn't spot anything obvious. Nevermind that we don't have a file with that name anymore :)

drivers/block/iopmem.c line 50

Quoted 4 lines
drivers/block/iopmem.c new file +4 -0
+  /*
+   * We can only access the iopmem device with full 32-bit word
+   * accesses which cannot be gaurantee'd by the regular memcpy
+   */

Odd comment formatting.

Quoted 7 lines
drivers/block/iopmem.c new file +7 -0
+static void memcpy_from_iopmem(void *dst, const void *src, size_t sz)
+{
+	u64 *wdst = dst;
+	const u64 *wsrc = src;
+	u64 tmp;
+
+	while (sz >= sizeof(*wdst)) {

drivers/block/iopmem.c line 68

Quoted 10 lines
drivers/block/iopmem.c new file +10 -0
+		*wdst++ = *wsrc++;
+		sz -= sizeof(*wdst);
+	}
+
+	if (!sz)
+		return;
+
+	tmp = *wsrc;
+	memcpy(wdst, &tmp, sz);
+}

And then we dod a memcpy here anyway. And no volatile whatsover, so the compiler could do anything to it. I defintively feel a bit uneasy about having this in the driver as well. Can we define the exact semantics for this and define it by the system, possibly in an arch specific way?

Quoted 4 lines
drivers/block/iopmem.c new file +4 -0
+static void iopmem_do_bvec(struct iopmem_device *iopmem, struct page *page,
+			   unsigned int len, unsigned int off, bool is_write,
+			   sector_t sector)
+{

drivers/block/iopmem.c line 101

Quoted 10 lines
drivers/block/iopmem.c new file +10 -0
+	phys_addr_t iopmem_off = sector * 512;
+	void *iopmem_addr = iopmem->virt_addr + iopmem_off;
+
+	if (!is_write) {
+		read_iopmem(page, off, iopmem_addr, len);
+		flush_dcache_page(page);
+	} else {
+		flush_dcache_page(page);
+		write_iopmem(iopmem_addr, page, off, len);
+	}

How about moving the address and offset calculation as well as the cache flushing into read_iopmem/write_iopmem and removing this function?

drivers/block/iopmem.c line 113

Quoted 10 lines
drivers/block/iopmem.c new file +10 -0
+static blk_qc_t iopmem_make_request(struct request_queue *q, struct bio *bio)
+{
+	struct iopmem_device *iopmem = q->queuedata;
+	struct bio_vec bvec;
+	struct bvec_iter iter;
+
+	bio_for_each_segment(bvec, bio, iter) {
+		iopmem_do_bvec(iopmem, bvec.bv_page, bvec.bv_len,
+			    bvec.bv_offset, op_is_write(bio_op(bio)),
+			    iter.bi_sector);

op_is_write just checks the data direction. I'd feel much more comfortable with a switch on the op, e.g.

	switch (bio_op(bio))) {
	case REQ_OP_READ:
		bio_for_each_segment(bvec, bio, iter)
			read_iopmem(iopmem, bvec, iter.bi_sector);
		break;
	case REQ_OP_READ:
		bio_for_each_segment(bvec, bio, iter)
			write_iopmem(iopmem, bvec, iter.bi_sector);
	defualt:
		WARN_ON_ONCE(1);
		bio->bi_error = -EIO;
		break;
	}

drivers/block/iopmem.c line 137

Quoted 8 lines
drivers/block/iopmem.c new file +8 -0
+static long iopmem_direct_access(struct block_device *bdev, sector_t sector,
+			       void **kaddr, pfn_t *pfn, long size)
+{
+	struct iopmem_device *iopmem = bdev->bd_queue->queuedata;
+	resource_size_t offset = sector * 512;
+
+	if (!iopmem)
+		return -ENODEV;

I don't think this can ever happen, can it?

Quoted 21 lines
drivers/block/iopmem.c new file +21 -0
+static DEFINE_IDA(iopmem_instance_ida);
+static DEFINE_SPINLOCK(ida_lock);
+
+static int iopmem_set_instance(struct iopmem_device *iopmem)
+{
+	int instance, error;
+
+	do {
+		if (!ida_pre_get(&iopmem_instance_ida, GFP_KERNEL))
+			return -ENODEV;
+
+		spin_lock(&ida_lock);
+		error = ida_get_new(&iopmem_instance_ida, &instance);
+		spin_unlock(&ida_lock);
+
+	} while (error == -EAGAIN);
+
+	if (error)
+		return -ENODEV;
+
+	iopmem->instance = instance;

drivers/block/iopmem.c line 181

Quoted 10 lines
drivers/block/iopmem.c new file +10 -0
+	return 0;
+}
+
+static void iopmem_release_instance(struct iopmem_device *iopmem)
+{
+	spin_lock(&ida_lock);
+	ida_remove(&iopmem_instance_ida, iopmem->instance);
+	spin_unlock(&ida_lock);
+}
+

Just use ida_simple_get/ida_simple_remove instead to take care of the locking and preloading, and get rid of these two functions.

drivers/block/iopmem.c line 188

Quoted 7 lines
drivers/block/iopmem.c new file +7 -0
+static int iopmem_attach_disk(struct iopmem_device *iopmem)
+{
+	struct gendisk *disk;
+	int nid = dev_to_node(iopmem->dev);
+	struct request_queue *q = iopmem->queue;
+
+	blk_queue_write_cache(q, true, true);

You don't handle flush commands or the fua bit in make_request, so this setting seems wrong.

drivers/block/iopmem.c line 227

Quoted 4 lines
drivers/block/iopmem.c new file +4 -0
+	int err = 0;
+	int nid = dev_to_node(&pdev->dev);
+
+	if (pci_enable_device_mem(pdev) < 0) {

propagate the actual error code, please.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

Re: [PATCH 2/3] iopmem : Add a block device driver for PCIe attached IO memory.

Hi Christoph,

Thanks so much for the detailed review of the code! Even though by the sounds of things we will be moving to device dax and most of this is moot. Still, it's great to get some feedback and learn a few things.

I've given some responses below.

Quoted 7 lines · Christoph Hellwig
Quoted 4 lines

+ * This driver is heavily based on drivers/block/pmem.c.
+ * Copyright (c) 2014, Intel Corporation.
+ * Copyright (C) 2007 Nick Piggin
+ * Copyright (C) 2007 Novell Inc.

Is there anything left of it actually? I didn't spot anything obvious. Nevermind that we don't have a file with that name anymore :)

Yes, actually there's still a lot of similarities with the current pmem.c. Though, yes, the path was on oversight. Some of this code is getting pretty old (it started from an out-of-tree version of pmem.c) and we've tried our best to track as many of the changes to the pmem.c as possible. This proved to be difficult. Note: this is now the nvdimm pmem and not the dax pmem (drivers/nvdimm/pmem.c)

Quoted 6 lines

drivers/block/iopmem.c line 50

Quoted 4 lines
drivers/block/iopmem.c new file +4 -0
+  /*
+   * We can only access the iopmem device with full 32-bit word
+   * accesses which cannot be gaurantee'd by the regular memcpy
+   */

Odd comment formatting.

Oops. I'm surprised check_patch didn't pick up on that.

Quoted 16 lines
Quoted 16 lines
drivers/block/iopmem.c new file +15 -0
+static void memcpy_from_iopmem(void *dst, const void *src, size_t sz)
+{
+	u64 *wdst = dst;
+	const u64 *wsrc = src;
+	u64 tmp;
+
+	while (sz >= sizeof(*wdst)) {
+		*wdst++ = *wsrc++;
+		sz -= sizeof(*wdst);
+	}
+
+	if (!sz)
+		return;
+
+	tmp = *wsrc;
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	memcpy(wdst, &tmp, sz);
+}

And then we dod a memcpy here anyway. And no volatile whatsover, so the compiler could do anything to it. I defintively feel a bit uneasy about having this in the driver as well. Can we define the exact semantics for this and define it by the system, possibly in an arch specific way?

Yeah, you're right. We should have reviewed this function a bit more. Anyway, I'd be interested in learning a better approach to forcing a copy from a mapped BAR with larger widths.

Quoted 9 lines
Quoted 9 lines
drivers/block/iopmem.c new file +9 -0
+static void iopmem_do_bvec(struct iopmem_device *iopmem, struct page *page,
+			   unsigned int len, unsigned int off, bool is_write,
+			   sector_t sector)
+{
+	phys_addr_t iopmem_off = sector * 512;
+	void *iopmem_addr = iopmem->virt_addr + iopmem_off;
+
+	if (!is_write) {
+		read_iopmem(page, off, iopmem_addr, len);
Quoted 8 lines

drivers/block/iopmem.c line 101

Quoted 5 lines
drivers/block/iopmem.c new file +5 -0
+		flush_dcache_page(page);
+	} else {
+		flush_dcache_page(page);
+		write_iopmem(iopmem_addr, page, off, len);
+	}

How about moving the address and offset calculation as well as the cache flushing into read_iopmem/write_iopmem and removing this function?

Could do. This was copied from the existing pmem.c and once the bad_pmem stuff was stripped out this function became relatively simple.

Quoted 14 lines

drivers/block/iopmem.c line 113

Quoted 11 lines
drivers/block/iopmem.c new file +10 -0
+static blk_qc_t iopmem_make_request(struct request_queue *q, struct bio *bio)
+{
+	struct iopmem_device *iopmem = q->queuedata;
+	struct bio_vec bvec;
+	struct bvec_iter iter;
+
+	bio_for_each_segment(bvec, bio, iter) {
+		iopmem_do_bvec(iopmem, bvec.bv_page, bvec.bv_len,
+			    bvec.bv_offset, op_is_write(bio_op(bio)),
+			    iter.bi_sector);

op_is_write just checks the data direction. I'd feel much more comfortable with a switch on the op, e.g.

That makes sense. This was also copied from pmem.c, so this same change may make sense there too.

Quoted 10 lines

drivers/block/iopmem.c line 137

Quoted 8 lines
drivers/block/iopmem.c new file +8 -0
+static long iopmem_direct_access(struct block_device *bdev, sector_t sector,
+			       void **kaddr, pfn_t *pfn, long size)
+{
+	struct iopmem_device *iopmem = bdev->bd_queue->queuedata;
+	resource_size_t offset = sector * 512;
+
+	if (!iopmem)
+		return -ENODEV;

I don't think this can ever happen, can it?

Yes, I think now that's the case. This is probably a holdover from a previous version.

Quoted 2 lines

Just use ida_simple_get/ida_simple_remove instead to take care of the locking and preloading, and get rid of these two functions.

Thanks, noted. That would be much better. I never found a simple example of that when I was looking, though I expected there should have been.

Quoted 11 lines

drivers/block/iopmem.c line 188

Quoted 8 lines
drivers/block/iopmem.c new file +7 -0
+static int iopmem_attach_disk(struct iopmem_device *iopmem)
+{
+	struct gendisk *disk;
+	int nid = dev_to_node(iopmem->dev);
+	struct request_queue *q = iopmem->queue;
+
+	blk_queue_write_cache(q, true, true);

You don't handle flush commands or the fua bit in make_request, so this setting seems wrong.

Yup, ok. I'm afraid this is a case of copying without complete comprehension.

Quoted 7 lines

drivers/block/iopmem.c line 227

Quoted 5 lines
drivers/block/iopmem.c new file +4 -0
+	int err = 0;
+	int nid = dev_to_node(&pdev->dev);
+
+	if (pci_enable_device_mem(pdev) < 0) {

propagate the actual error code, please.

Hmm, yup. Not sure why that was missed.

Thanks,

Logan

#9 lore raw

PATCH 3/3 iopmem : Add documentation for iopmem driver

In reply to Stephen Bates

Add documentation for the iopmem PCIe device driver.

---
 Documentation/blockdev/00-INDEX   |  2 ++
 Documentation/blockdev/iopmem.txt | 62 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)
 create mode 100644 Documentation/blockdev/iopmem.txt
Documentation/blockdev/00-INDEX +2 -0
index c08df56..913e500 100644
@@ -8,6 +8,8 @@ cpqarray.txt
 	- info on using Compaq's SMART2 Intelligent Disk Array Controllers.
 floppy.txt
 	- notes and driver options for the floppy disk driver.
+iopmem.txt
+	- info on the iopmem block driver.
 mflash.txt
 	- info on mGine m(g)flash driver for linux.
 nbd.txt
Documentation/blockdev/iopmem.txt new file +62 -0

62 lines not on this page · raw message

--
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#10 lore raw

Re: [PATCH 3/3] iopmem : Add documentation for iopmem driver

I'd say please fold this into the previous patch.

#11 lore raw
In reply to Stephen Bates

[ adding Ashok and David for potential iommu comments ]

Quoted 25 lines · Stephen Bates

This patch follows from an RFC we did earlier this year [1]. This patchset applies cleanly to v4.9-rc1.

Updates since RFC
-----------------
Rebased.
Included the iopmem driver in the submission.

History
-------

There have been several attempts to upstream patchsets that enable DMAs between PCIe peers. These include Peer-Direct [2] and DMA-Buf style patches [3]. None have been successful to date. Haggai Eran gives a nice overview of the prior art in this space in his cover letter [3].

Motivation and Use Cases
------------------------

PCIe IO devices are getting faster. It is not uncommon now to find PCIe network and storage devices that can generate and consume several GB/s. Almost always these devices have either a high performance DMA engine, a number of exposed PCIe BARs or both.

Quoted 8 lines

Until this patch, any high-performance transfer of information between two PICe devices has required the use of a staging buffer in system memory. With this patch the bandwidth to system memory is not compromised when high-throughput transfers occurs between PCIe devices. This means that more system memory bandwidth is available to the CPU cores for data processing and manipulation. In addition, in systems where the two PCIe devices reside behind a PCIe switch the datapath avoids the CPU entirely.

I agree with the motivation and the need for a solution, but I have some questions about this implementation.

Quoted 9 lines

Consumers
---------

We provide a PCIe device driver in an accompanying patch that can be used to map any PCIe BAR into a DAX capable block device. For non-persistent BARs this simply serves as an alternative to using system memory bounce buffers. For persistent BARs this can serve as an additional storage device in the system.

Why block devices? I wonder if iopmem was initially designed back when we were considering enabling DAX for raw block devices. However, that support has since been ripped out / abandoned. You currently need a filesystem on top of a block-device to get DAX operation. Putting xfs or ext4 on top of PCI-E memory mapped range seems awkward if all you want is a way to map the bar for another PCI-E device in the topology.

If you're only using the block-device as a entry-point to create dax-mappings then a device-dax (drivers/dax/) character-device might be a better fit.

Quoted 18 lines

Testing and Performance
-----------------------

We have done a moderate about of testing of this patch on a QEMU environment and on real hardware. On real hardware we have observed peer-to-peer writes of up to 4GB/s and reads of up to 1.2 GB/s. In both cases these numbers are limitations of our consumer hardware. In addition, we have observed that the CPU DRAM bandwidth is not impacted when using IOPMEM which is not the case when a traditional path through system memory is taken.

For more information on the testing and performance results see the GitHub site [4].

Known Issues
------------

Quoted 9 lines

1. Address Translation. Suggestions have been made that in certain architectures and topologies the dma_addr_t passed to the DMA master in a peer-2-peer transfer will not correctly route to the IO memory intended. However in our testing to date we have not seen this to be an issue, even in systems with IOMMUs and PCIe switches. It is our understanding that an IOMMU only maps system memory and would not interfere with device memory regions. (It certainly has no opportunity to do so if the transfer gets routed through a switch).

There may still be platforms where peer-to-peer cycles are routed up through the root bridge and then back down to target device, but we can address that when / if it happens. I wonder if we could (ab)use a software-defined 'pasid' as the requester id for a peer-to-peer mapping that needs address translation.

Quoted 7 lines

2. Memory Segment Spacing. This patch has the same limitations that ZONE_DEVICE does in that memory regions must be spaces at least SECTION_SIZE bytes part. On x86 this is 128MB and there are cases where BARs can be placed closer together than this. Thus ZONE_DEVICE would not be usable on neighboring BARs. For our purposes, this is not an issue as we'd only be looking at enabling a single BAR in a given PCIe device. More exotic use cases may have problems with this.

I'm working on patches for 4.10 to allow mixing multiple devm_memremap_pages() allocations within the same physical section. Hopefully this won't be a problem going forward.

Quoted 7 lines

3. Coherency Issues. When IOMEM is written from both the CPU and a PCIe peer there is potential for coherency issues and for writes to occur out of order. This is something that users of this feature need to be cognizant of. Though really, this isn't much different than the existing situation with things like RDMA: if userspace sets up an MR for remote use, they need to be careful about using that memory region themselves.

We might be able to mitigate this by indicating that the mapping is busy for device-to-device transfers. But you're right we could wait to see how much of a problem this is in practice.

Quoted 13 lines

4. Architecture. Currently this patch is applicable only to x86_64 architectures. The same is true for much of the code pertaining to PMEM and ZONE_DEVICE. It is hoped that the work will be extended to other ARCH over time.

References
----------
[1] https://patchwork.kernel.org/patch/8583221/
[2] http://comments.gmane.org/gmane.linux.drivers.rdma/21849
[3] http://www.spinics.net/lists/linux-rdma/msg38748.html
[4] https://github.com/sbates130272/zone-device

Quoted 2 lines

Logan Gunthorpe (1):
memremap.c : Add support for ZONE_DEVICE IO memory with struct pages.

I haven't yet grokked the motivation for this, but I'll go comment on that separately.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw
Quoted 2 lines · Dan Williams

[ adding Ashok and David for potential iommu comments ]

Hi Dan

Thanks for adding Ashok and David!

Quoted 22 lines

I agree with the motivation and the need for a solution, but I have some questions about this implementation.

Quoted 9 lines

Consumers
---------

We provide a PCIe device driver in an accompanying patch that can be used to map any PCIe BAR into a DAX capable block device. For non-persistent BARs this simply serves as an alternative to using system memory bounce buffers. For persistent BARs this can serve as an additional storage device in the system.

Why block devices? I wonder if iopmem was initially designed back when we were considering enabling DAX for raw block devices. However, that support has since been ripped out / abandoned. You currently need a filesystem on top of a block-device to get DAX operation. Putting xfs or ext4 on top of PCI-E memory mapped range seems awkward if all you want is a way to map the bar for another PCI-E device in the topology.

Quoted 4 lines

If you're only using the block-device as a entry-point to create dax-mappings then a device-dax (drivers/dax/) character-device might be a better fit.

We chose a block device because we felt it was intuitive for users to carve up a memory region but putting a DAX filesystem on it and creating files on that DAX aware FS. It seemed like a convenient way to partition up the region and to be easily able to get the DMA address for the memory backing the device.

That said I would be very keen to get other peoples thoughts on how they would like to see this done. And I know some people have had some reservations about using DAX mounted FS to do this in the past.

Quoted 9 lines
Quoted 8 lines

2. Memory Segment Spacing. This patch has the same limitations that ZONE_DEVICE does in that memory regions must be spaces at least SECTION_SIZE bytes part. On x86 this is 128MB and there are cases where BARs can be placed closer together than this. Thus ZONE_DEVICE would not be usable on neighboring BARs. For our purposes, this is not an issue as we'd only be looking at enabling a single BAR in a given PCIe device. More exotic use cases may have problems with this.

Quoted 4 lines

I'm working on patches for 4.10 to allow mixing multiple devm_memremap_pages() allocations within the same physical section. Hopefully this won't be a problem going forward.

Thanks Dan. Your patches will help address the problem of how to partition a /dev/dax device but they don't help the case then BARs themselves are small, closely spaced and non-segment aligned. However I think most people using iopmem will want to use reasonbly large BARs so I am not sure item 2 is that big of an issue.

Quoted 2 lines

I haven't yet grokked the motivation for this, but I'll go comment on that separately.

Thanks Dan!

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw
Quoted 41 lines · Stephen Bates
Quoted 2 lines · Dan Williams

[ adding Ashok and David for potential iommu comments ]

Hi Dan

Thanks for adding Ashok and David!

Quoted 22 lines

I agree with the motivation and the need for a solution, but I have some questions about this implementation.

Quoted 9 lines

Consumers
---------

We provide a PCIe device driver in an accompanying patch that can be used to map any PCIe BAR into a DAX capable block device. For non-persistent BARs this simply serves as an alternative to using system memory bounce buffers. For persistent BARs this can serve as an additional storage device in the system.

Why block devices? I wonder if iopmem was initially designed back when we were considering enabling DAX for raw block devices. However, that support has since been ripped out / abandoned. You currently need a filesystem on top of a block-device to get DAX operation. Putting xfs or ext4 on top of PCI-E memory mapped range seems awkward if all you want is a way to map the bar for another PCI-E device in the topology.

Quoted 4 lines

If you're only using the block-device as a entry-point to create dax-mappings then a device-dax (drivers/dax/) character-device might be a better fit.

We chose a block device because we felt it was intuitive for users to carve up a memory region but putting a DAX filesystem on it and creating files on that DAX aware FS. It seemed like a convenient way to partition up the region and to be easily able to get the DMA address for the memory backing the device.

Quoted 3 lines

That said I would be very keen to get other peoples thoughts on how they would like to see this done. And I know some people have had some reservations about using DAX mounted FS to do this in the past.

I guess it depends on the expected size of these devices BARs, but I get the sense they may be smaller / more precious such that you wouldn't want to spend capacity on filesystem metadata? For the target use case is it assumed that these device BARs are always backed by non-volatile memory? Otherwise this is a mkfs each boot for a volatile device.

Quoted 14 lines
Quoted 9 lines
Quoted 8 lines

2. Memory Segment Spacing. This patch has the same limitations that ZONE_DEVICE does in that memory regions must be spaces at least SECTION_SIZE bytes part. On x86 this is 128MB and there are cases where BARs can be placed closer together than this. Thus ZONE_DEVICE would not be usable on neighboring BARs. For our purposes, this is not an issue as we'd only be looking at enabling a single BAR in a given PCIe device. More exotic use cases may have problems with this.

Quoted 4 lines

I'm working on patches for 4.10 to allow mixing multiple devm_memremap_pages() allocations within the same physical section. Hopefully this won't be a problem going forward.

Quoted 5 lines

Thanks Dan. Your patches will help address the problem of how to partition a /dev/dax device but they don't help the case then BARs themselves are small, closely spaced and non-segment aligned. However I think most people using iopmem will want to use reasonbly large BARs so I am not sure item 2 is that big of an issue.

I think you might have misunderstood what I'm proposing. The patches I'm working on are separate from a facility to carve up a /dev/dax device. The effort is to allow devm_memremap_pages() to maintain several allocations within the same 128MB section. I need this for persistent memory to handle platforms that mix pmem and system-ram in the same section. I want to be able to map ZONE_DEVICE pages for a portion of a section and be able to remove portions of section that may collide with allocations of a different lifetime.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw
Quoted 16 lines
Quoted 12 lines
Quoted 5 lines

If you're only using the block-device as a entry-point to create dax-mappings then a device-dax (drivers/dax/) character-device might be a better fit.

We chose a block device because we felt it was intuitive for users to carve up a memory region but putting a DAX filesystem on it and creating files on that DAX aware FS. It seemed like a convenient way to partition up the region and to be easily able to get the DMA address for the memory backing the device.

Quoted 3 lines

That said I would be very keen to get other peoples thoughts on how they would like to see this done. And I know some people have had some reservations about using DAX mounted FS to do this in the past.

Quoted 6 lines

I guess it depends on the expected size of these devices BARs, but I get the sense they may be smaller / more precious such that you wouldn't want to spend capacity on filesystem metadata? For the target use case is it assumed that these device BARs are always backed by non-volatile memory? Otherwise this is a mkfs each boot for a volatile device.

Dan

Fair point and this is a concern I share. We are not assuming that all iopmem devices are backed by non-volatile memory so the mkfs recreation comment is valid. All in all I think you are persuading us to take a look at /dev/dax ;-). I will see if anyone else chips in with their thoughts on this.

Quoted 21 lines
Quoted 15 lines
Quoted 10 lines
Quoted 9 lines

2. Memory Segment Spacing. This patch has the same limitations that ZONE_DEVICE does in that memory regions must be spaces at least SECTION_SIZE bytes part. On x86 this is 128MB and there are cases where BARs can be placed closer together than this. Thus ZONE_DEVICE would not be usable on neighboring BARs. For our purposes, this is not an issue as we'd only be looking at enabling a single BAR in a given PCIe device. More exotic use cases may have problems with this.

Quoted 4 lines

I'm working on patches for 4.10 to allow mixing multiple devm_memremap_pages() allocations within the same physical section. Hopefully this won't be a problem going forward.

Quoted 5 lines

Thanks Dan. Your patches will help address the problem of how to partition a /dev/dax device but they don't help the case then BARs themselves are small, closely spaced and non-segment aligned. However I think most people using iopmem will want to use reasonbly large BARs so I am not sure item 2 is that big of an issue.

Quoted 8 lines

I think you might have misunderstood what I'm proposing. The patches I'm working on are separate from a facility to carve up a /dev/dax device. The effort is to allow devm_memremap_pages() to maintain several allocations within the same 128MB section. I need this for persistent memory to handle platforms that mix pmem and system-ram in the same section. I want to be able to map ZONE_DEVICE pages for a portion of a section and be able to remove portions of section that may collide with allocations of a different lifetime.

Oh I did misunderstand. This is very cool and would be useful to us. One more reason to consider moving to /dev/dax in the next spin of this patchset ;-).

Thanks

Stephen

#15 lore raw
In reply to Stephen Bates
Quoted 35 lines · Stephen Bates
Quoted 2 lines · Dan Williams

[ adding Ashok and David for potential iommu comments ]

Hi Dan

Thanks for adding Ashok and David!

Quoted 22 lines

I agree with the motivation and the need for a solution, but I have some questions about this implementation.

Quoted 9 lines

Consumers
---------

We provide a PCIe device driver in an accompanying patch that can be used to map any PCIe BAR into a DAX capable block device. For non-persistent BARs this simply serves as an alternative to using system memory bounce buffers. For persistent BARs this can serve as an additional storage device in the system.

Why block devices? I wonder if iopmem was initially designed back when we were considering enabling DAX for raw block devices. However, that support has since been ripped out / abandoned. You currently need a filesystem on top of a block-device to get DAX operation. Putting xfs or ext4 on top of PCI-E memory mapped range seems awkward if all you want is a way to map the bar for another PCI-E device in the topology.

Quoted 4 lines

If you're only using the block-device as a entry-point to create dax-mappings then a device-dax (drivers/dax/) character-device might be a better fit.

Quoted 5 lines

We chose a block device because we felt it was intuitive for users to carve up a memory region but putting a DAX filesystem on it and creating files on that DAX aware FS. It seemed like a convenient way to partition up the region and to be easily able to get the DMA address for the memory backing the device.

You do realise that local filesystems can silently change the location of file data at any point in time, so there is no such thing as a "stable mapping" of file data to block device addresses in userspace?

If you want remote access to the blocks owned and controlled by a filesystem, then you need to use a filesystem with a remote locking mechanism to allow co-ordinated, coherent access to the data in those blocks. Anything else is just asking for ongoing, unfixable filesystem corruption or data leakage problems (i.e. security issues).

Cheers,

Dave.

Signature · 8 lines
Dave Chinner
[email protected]

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#16 lore raw
Quoted 11 lines · Dave Chinner

You do realise that local filesystems can silently change the location of file data at any point in time, so there is no such thing as a "stable mapping" of file data to block device addresses in userspace?

If you want remote access to the blocks owned and controlled by a filesystem, then you need to use a filesystem with a remote locking mechanism to allow co-ordinated, coherent access to the data in those blocks. Anything else is just asking for ongoing, unfixable filesystem corruption or data leakage problems (i.e. security issues).

And at least for XFS we have such a mechanism :) E.g. I have a prototype of a pNFS layout that uses XFS+DAX to allow clients to do RDMA directly to XFS files, with the same locking mechanism we use for the current block and scsi layout in xfs_pnfs.c.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#17 lore raw
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Dave Chinner

You do realise that local filesystems can silently change the location of file data at any point in time, so there is no such thing as a "stable mapping" of file data to block device addresses in userspace?

If you want remote access to the blocks owned and controlled by a filesystem, then you need to use a filesystem with a remote locking mechanism to allow co-ordinated, coherent access to the data in those blocks. Anything else is just asking for ongoing, unfixable filesystem corruption or data leakage problems (i.e. security issues).

Quoted 4 lines

And at least for XFS we have such a mechanism :) E.g. I have a prototype of a pNFS layout that uses XFS+DAX to allow clients to do RDMA directly to XFS files, with the same locking mechanism we use for the current block and scsi layout in xfs_pnfs.c.

Oh, that's good to know - pNFS over XFS was exactly what I was thinking of when I wrote my earlier reply. A few months ago someone else was trying to use file mappings in userspace for direct remote client access on fabric connected devices. I told them "pNFS on XFS and write an efficient transport for you hardware"....

Now that I know we've got RDMA support for pNFS on XFS in the pipeline, I can just tell them "just write an rdma driver for your hardware" instead. :P

Cheers,

Dave.

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

Hi Dave and Christoph

Quoted 7 lines · Dave Chinner
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Dave Chinner

You do realise that local filesystems can silently change the location of file data at any point in time, so there is no such thing as a "stable mapping" of file data to block device addresses in userspace?

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

If you want remote access to the blocks owned and controlled by a filesystem, then you need to use a filesystem with a remote locking mechanism to allow co-ordinated, coherent access to the data in those blocks. Anything else is just asking for ongoing, unfixable filesystem corruption or data leakage problems (i.e. security issues).

Dave are you saying that even for local mappings of files on a DAX capable system it is possible for the mappings to move on you unless the FS supports locking? Does that not mean DAX on such FS is inherently broken?

Quoted 5 lines
Quoted 4 lines

And at least for XFS we have such a mechanism :) E.g. I have a prototype of a pNFS layout that uses XFS+DAX to allow clients to do RDMA directly to XFS files, with the same locking mechanism we use for the current block and scsi layout in xfs_pnfs.c.

Thanks for fixing this issue on XFS Christoph! I assume this problem continues to exist on the other DAX capable FS?

One more reason to consider a move to /dev/dax I guess ;-)...

Stephen

Quoted 10 lines

Oh, that's good to know - pNFS over XFS was exactly what I was thinking of when I wrote my earlier reply. A few months ago someone else was trying to use file mappings in userspace for direct remote client access on fabric connected devices. I told them "pNFS on XFS and write an efficient transport for you hardware"....

Now that I know we've got RDMA support for pNFS on XFS in the pipeline, I can just tell them "just write an rdma driver for your hardware" instead. :P

Quoted 6 lines

Cheers,

Dave.
--
Dave Chinner
[email protected]

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

#19 lore raw
Quoted 18 lines · Stephen Bates

Hi Dave and Christoph

Quoted 7 lines · Dave Chinner
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Dave Chinner

You do realise that local filesystems can silently change the location of file data at any point in time, so there is no such thing as a "stable mapping" of file data to block device addresses in userspace?

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

If you want remote access to the blocks owned and controlled by a filesystem, then you need to use a filesystem with a remote locking mechanism to allow co-ordinated, coherent access to the data in those blocks. Anything else is just asking for ongoing, unfixable filesystem corruption or data leakage problems (i.e. security issues).

Quoted 3 lines

Dave are you saying that even for local mappings of files on a DAX capable system it is possible for the mappings to move on you unless the FS supports locking?

Yes.

Quoted 2 lines

Does that not mean DAX on such FS is
inherently broken?

No. DAX is accessed through a virtual mapping layer that abstracts the physical location from userspace applications.

Example: think copy-on-write overwrites. It occurs atomically from the perspective of userspace and starts by invalidating any current mappings userspace has of that physical location. The location is changes, the data copied in, and then when the locks are released userspace can fault in a new page table mapping on the next access....

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

And at least for XFS we have such a mechanism :) E.g. I have a prototype of a pNFS layout that uses XFS+DAX to allow clients to do RDMA directly to XFS files, with the same locking mechanism we use for the current block and scsi layout in xfs_pnfs.c.

Thanks for fixing this issue on XFS Christoph! I assume this problem continues to exist on the other DAX capable FS?

Yes, but it they implement the exportfs API that supplies this capability, they'll be able to use pNFS, too.

Quoted 1 line

One more reason to consider a move to /dev/dax I guess ;-)...

That doesn't get rid of the need for sane access control arbitration across all machines that are directly accessing the storage. That's the problem pNFS solves, regardless of whether your direct access target is a filesystem, a block device or object storage...

Cheers,

Dave.

Signature · 6 lines
Dave Chinner
[email protected]
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#20 lore raw
Quoted 13 lines · Dave Chinner
Quoted 5 lines · Stephen Bates

Dave are you saying that even for local mappings of files on a DAX capable system it is possible for the mappings to move on you unless the FS supports locking?

Yes.

Quoted 2 lines

Does that not mean DAX on such FS is
inherently broken?

Quoted 8 lines

No. DAX is accessed through a virtual mapping layer that abstracts the physical location from userspace applications.

Example: think copy-on-write overwrites. It occurs atomically from the perspective of userspace and starts by invalidating any current mappings userspace has of that physical location. The location is changes, the data copied in, and then when the locks are released userspace can fault in a new page table mapping on the next access....

Dave

Thanks for the good input and for correcting some of my DAX misconceptions! We will certainly be taking this into account as we consider v1.

Quoted 12 lines
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

And at least for XFS we have such a mechanism :) E.g. I have a prototype of a pNFS layout that uses XFS+DAX to allow clients to do RDMA directly to XFS files, with the same locking mechanism we use for the current block and scsi layout in xfs_pnfs.c.

Thanks for fixing this issue on XFS Christoph! I assume this problem continues to exist on the other DAX capable FS?

Yes, but it they implement the exportfs API that supplies this capability, they'll be able to use pNFS, too.

Quoted 7 lines
Quoted 2 lines

One more reason to consider a move to /dev/dax I guess ;-)...

That doesn't get rid of the need for sane access control arbitration across all machines that are directly accessing the storage. That's the problem pNFS solves, regardless of whether your direct access target is a filesystem, a block device or object storage...

Fair point. I am still hoping for a bit more discussion on the best choice of user-space interface for this work. If/When that happens we will take it into account when we look at spinning the patchset.

Stephen

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

#21 lore raw
In reply to Christoph Hellwig
Quoted 13 lines
Quoted 6 lines

You do realise that local filesystems can silently change the location of file data at any point in time, so there is no such thing as a "stable mapping" of file data to block device addresses in userspace?

Quoted 6 lines

If you want remote access to the blocks owned and controlled by a filesystem, then you need to use a filesystem with a remote locking mechanism to allow co-ordinated, coherent access to the data in those blocks. Anything else is just asking for ongoing, unfixable filesystem corruption or data leakage problems (i.e. security issues).

Quoted 4 lines

And at least for XFS we have such a mechanism :) E.g. I have a prototype of a pNFS layout that uses XFS+DAX to allow clients to do RDMA directly to XFS files, with the same locking mechanism we use for the current block and scsi layout in xfs_pnfs.c.

Christoph, did you manage to leap to the future and solve the RDMA persistency hole? :)

e.g. what happens with O_DSYNC in this model? Or you did a message exchange for commits?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#22 lore raw
Quoted 5 lines · Sagi Grimberg

Christoph, did you manage to leap to the future and solve the RDMA persistency hole? :)

e.g. what happens with O_DSYNC in this model? Or you did a message exchange for commits?

Yes, pNFS calls this the layoutcommit. That being said once we get a RDMA commit or flush operation we could easily make the layoutcommit optional for some operations. There already is a precedence for the in the flexfiles layout specification.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#23 lore raw
In reply to Dan Williams
Quoted 8 lines · Dan Williams
Quoted 7 lines · Stephen Bates

1. Address Translation. Suggestions have been made that in certain architectures and topologies the dma_addr_t passed to the DMA master in a peer-2-peer transfer will not correctly route to the IO memory intended. However in our testing to date we have not seen this to be an issue, even in systems with IOMMUs and PCIe switches. It is our understanding that an IOMMU only maps system memory and would not interfere with device memory regions.

I'm not sure that's the case. I think it works because with ZONE_DEVICE, the iommu driver will simply treat a dma_map_page call as any other PFN, and create a mapping as it does for any memory page.

Quoted 2 lines
Quoted 2 lines

(It certainly has no opportunity
to do so if the transfer gets routed through a switch).

It can still go through the IOMMU if you enable ACS upstream forwarding.

Quoted 3 lines

There may still be platforms where peer-to-peer cycles are routed up through the root bridge and then back down to target device, but we can address that when / if it happens.

I agree.

Quoted 3 lines

I wonder if we could (ab)use a
software-defined 'pasid' as the requester id for a peer-to-peer mapping that needs address translation.

Why would you need that? Isn't it enough to map the peer-to-peer addresses correctly in the iommu driver?

Haggai

#24 lore raw

On Wed, Oct 26, 2016 at 1:24 AM, Haggai Eran <haggaie-VPRAkNaXOzVWk0Htik3J/[email protected]> wrote:
[..]

Quoted 6 lines
Quoted 3 lines

I wonder if we could (ab)use a
software-defined 'pasid' as the requester id for a peer-to-peer mapping that needs address translation.

Why would you need that? Isn't it enough to map the peer-to-peer addresses correctly in the iommu driver?

You're right, we might already have enough...

We would just need to audit iommu drivers to undo any assumptions that the page being mapped is always in host memory and apply any bus address translations between source device and target device.