nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/18] dax: fix dma vs truncate/hole-punch
@ 2017-12-24  0:56 Dan Williams
  2017-12-24  0:56 ` [PATCH v4 01/18] mm, dax: introduce pfn_t_special() Dan Williams
                   ` (18 more replies)
  0 siblings, 19 replies; 66+ messages in thread
From: Dan Williams @ 2017-12-24  0:56 UTC (permalink / raw)
  To: akpm
  Cc: Michal Hocko, jack, Peter Zijlstra, Benjamin Herrenschmidt,
	Dave Hansen, Heiko Carstens, Andreas Dilger, hch, Matthew Wilcox,
	Michael Ellerman, Ingo Molnar, Martin Schwidefsky, linux-ext4,
	Dave Chinner, linux-nvdimm, Jérôme Glisse,
	Alexander Viro, Gerald Schaefer, Theodore Ts'o,
	Darrick J. Wong, linux-xfs, Jan Kara, linux-fsdevel,
	Paul Mackerras, Kirill A. Shutemov

Changes since v3 [1]:
* Kill the i_daxdma_lock, and do not impose any new locking constraints
  on filesystem implementations (Dave)

* Reuse the existing i_mmap_lock for synchronizing against
  get_user_pages() by unmapping and causing punch-hole/truncate to
  re-fault the page before get_user_pages() can elevate the page reference
  count (Jan)

* Create a dax-specifc address_space_operations instance for each
  filesystem. This allows page->mapping to be set for dax pages. (Jan).

* Change the ext4 and ext2 policy of 'mount -o dax' vs a device that
  does not support dax. This converts any environments that may have
  been using 'page-less' dax back to using page cache.

* Rename wait_on_devmap_idle() to wait_on_atomic_one(), a generic
  facility for waiting for an atomic counter to reach a value of '1'.

[1]: https://lwn.net/Articles/737273/

---

Background:

get_user_pages() pins file backed memory pages for access by dma
devices. However, it only pins the memory pages not the page-to-file
offset association. If a file is truncated the pages are mapped out of
the file and dma may continue indefinitely into a page that is owned by
a device driver. This breaks coherency of the file vs dma, but the
assumption is that if userspace wants the file-space truncated it does
not matter what data is inbound from the device, it is not relevant
anymore. The only expectation is that dma can safely continue while the
filesystem reallocates the block(s).

Problem:

This expectation that dma can safely continue while the filesystem
changes the block map is broken by dax. With dax the target dma page
*is* the filesystem block. The model of leaving the page pinned for dma,
but truncating the file block out of the file, means that the filesytem
is free to reallocate a block under active dma to another file and now
the expected data-incoherency situation has turned into active
data-corruption.

Solution:

Defer all filesystem operations (fallocate(), truncate()) on a dax mode
file while any page/block in the file is under active dma. This solution
assumes that dma is transient. Cases where dma operations are known to
not be transient, like RDMA, have been explicitly disabled via
commits like 5f1d43de5416 "IB/core: disable memory registration of
filesystem-dax vmas".

The dax_flush_dma() routine is called by filesystems with a lock held
against mm faults (i_mmap_lock). It then invalidates all mappings to
trigger any subsequent get_user_pages() to block on i_mmap_lock. Finally
it scans/rescans all pages in the mapping until it observes all pages
idle.

So far this solution only targets xfs since it already implements
xfs_break_layouts in all the locations that would need this
synchronization. It applies on top of the vmem_altmap / dev_pagemap
reworks from Christoph.

---

Dan Williams (18):
      mm, dax: introduce pfn_t_special()
      ext4: auto disable dax instead of failing mount
      ext2: auto disable dax instead of failing mount
      dax: require 'struct page' by default for filesystem dax
      dax: stop using VM_MIXEDMAP for dax
      dax: stop using VM_HUGEPAGE for dax
      dax: store pfns in the radix
      tools/testing/nvdimm: add 'bio_delay' mechanism
      mm, dax: enable filesystems to trigger dev_pagemap ->page_free callbacks
      mm, dev_pagemap: introduce CONFIG_DEV_PAGEMAP_OPS
      fs, dax: introduce DEFINE_FSDAX_AOPS
      xfs: use DEFINE_FSDAX_AOPS
      ext4: use DEFINE_FSDAX_AOPS
      ext2: use DEFINE_FSDAX_AOPS
      mm, fs, dax: use page->mapping to warn if dma collides with truncate
      wait_bit: introduce {wait_on,wake_up}_atomic_one
      mm, fs, dax: dax_flush_dma, handle dma vs block-map-change collisions
      xfs, dax: wire up dax_flush_dma support via a new xfs_sync_dma helper


 arch/powerpc/platforms/Kconfig        |    1 
 arch/powerpc/sysdev/axonram.c         |    2 
 drivers/dax/device.c                  |    1 
 drivers/dax/super.c                   |  100 ++++++++++-
 drivers/nvdimm/pmem.c                 |    3 
 drivers/s390/block/Kconfig            |    1 
 drivers/s390/block/dcssblk.c          |    3 
 fs/Kconfig                            |    8 +
 fs/dax.c                              |  295 ++++++++++++++++++++++++++++-----
 fs/ext2/ext2.h                        |    1 
 fs/ext2/file.c                        |    1 
 fs/ext2/inode.c                       |   23 ++-
 fs/ext2/namei.c                       |   18 --
 fs/ext2/super.c                       |   13 +
 fs/ext4/file.c                        |    1 
 fs/ext4/inode.c                       |    6 +
 fs/ext4/super.c                       |   15 +-
 fs/xfs/Makefile                       |    3 
 fs/xfs/xfs_aops.c                     |    2 
 fs/xfs/xfs_aops.h                     |    1 
 fs/xfs/xfs_dma.c                      |   81 +++++++++
 fs/xfs/xfs_dma.h                      |   24 +++
 fs/xfs/xfs_file.c                     |    8 -
 fs/xfs/xfs_ioctl.c                    |    7 -
 fs/xfs/xfs_iops.c                     |   12 +
 fs/xfs/xfs_super.c                    |   20 +-
 include/linux/dax.h                   |   70 +++++++-
 include/linux/memremap.h              |   28 +--
 include/linux/mm.h                    |   62 +++++--
 include/linux/pfn_t.h                 |   13 +
 include/linux/vma.h                   |   23 +++
 include/linux/wait_bit.h              |   13 +
 kernel/memremap.c                     |   30 +++
 kernel/sched/wait_bit.c               |   59 ++++++-
 mm/Kconfig                            |    5 +
 mm/gup.c                              |    5 +
 mm/hmm.c                              |   13 -
 mm/huge_memory.c                      |    6 -
 mm/ksm.c                              |    3 
 mm/madvise.c                          |    2 
 mm/memory.c                           |   22 ++
 mm/migrate.c                          |    3 
 mm/mlock.c                            |    5 -
 mm/mmap.c                             |    8 -
 mm/swap.c                             |    3 
 tools/testing/nvdimm/Kbuild           |    1 
 tools/testing/nvdimm/test/iomap.c     |   62 +++++++
 tools/testing/nvdimm/test/nfit.c      |   34 ++++
 tools/testing/nvdimm/test/nfit_test.h |    1 
 49 files changed, 918 insertions(+), 203 deletions(-)
 create mode 100644 fs/xfs/xfs_dma.c
 create mode 100644 fs/xfs/xfs_dma.h
 create mode 100644 include/linux/vma.h
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2018-03-09 17:20 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-24  0:56 [PATCH v4 00/18] dax: fix dma vs truncate/hole-punch Dan Williams
2017-12-24  0:56 ` [PATCH v4 01/18] mm, dax: introduce pfn_t_special() Dan Williams
2018-01-04  8:16   ` Christoph Hellwig
2017-12-24  0:56 ` [PATCH v4 02/18] ext4: auto disable dax instead of failing mount Dan Williams
2018-01-03 14:20   ` Jan Kara
2017-12-24  0:56 ` [PATCH v4 03/18] ext2: " Dan Williams
2018-01-03 14:21   ` Jan Kara
2017-12-24  0:56 ` [PATCH v4 04/18] dax: require 'struct page' by default for filesystem dax Dan Williams
2018-01-03 15:29   ` Jan Kara
2018-01-04  8:16   ` Christoph Hellwig
2018-01-08 11:58   ` Gerald Schaefer
2017-12-24  0:56 ` [PATCH v4 05/18] dax: stop using VM_MIXEDMAP for dax Dan Williams
2018-01-03 15:27   ` Jan Kara
2017-12-24  0:56 ` [PATCH v4 06/18] dax: stop using VM_HUGEPAGE " Dan Williams
2017-12-24  0:56 ` [PATCH v4 07/18] dax: store pfns in the radix Dan Williams
2017-12-27  0:17   ` Ross Zwisler
2018-01-02 20:15     ` Dan Williams
2018-01-03 15:39   ` Jan Kara
2017-12-24  0:56 ` [PATCH v4 08/18] tools/testing/nvdimm: add 'bio_delay' mechanism Dan Williams
2017-12-27 18:08   ` Ross Zwisler
2018-01-02 20:35     ` Dan Williams
2018-01-02 21:44   ` Dave Chinner
2018-01-02 21:51     ` Dan Williams
2018-01-03 15:46       ` Jan Kara
2018-01-03 20:37         ` Jeff Moyer
2017-12-24  0:56 ` [PATCH v4 09/18] mm, dax: enable filesystems to trigger dev_pagemap ->page_free callbacks Dan Williams
2018-01-04  8:20   ` Christoph Hellwig
2017-12-24  0:56 ` [PATCH v4 10/18] mm, dev_pagemap: introduce CONFIG_DEV_PAGEMAP_OPS Dan Williams
2018-01-04  8:25   ` Christoph Hellwig
2017-12-24  0:56 ` [PATCH v4 11/18] fs, dax: introduce DEFINE_FSDAX_AOPS Dan Williams
2017-12-27  5:29   ` Matthew Wilcox
2018-01-02 20:21     ` Dan Williams
2018-01-03 16:05       ` Jan Kara
2018-01-04  8:27         ` Christoph Hellwig
2018-01-02 21:41   ` Dave Chinner
2017-12-24  0:57 ` [PATCH v4 12/18] xfs: use DEFINE_FSDAX_AOPS Dan Williams
2018-01-02 21:15   ` Darrick J. Wong
2018-01-02 21:40     ` Dan Williams
2018-01-03 16:09       ` Jan Kara
2018-01-04  8:28   ` Christoph Hellwig
2017-12-24  0:57 ` [PATCH v4 13/18] ext4: " Dan Williams
2018-01-04  8:29   ` Christoph Hellwig
2017-12-24  0:57 ` [PATCH v4 14/18] ext2: " Dan Williams
2018-01-04  8:29   ` Christoph Hellwig
2017-12-24  0:57 ` [PATCH v4 15/18] mm, fs, dax: use page->mapping to warn if dma collides with truncate Dan Williams
2018-01-04  8:30   ` Christoph Hellwig
2018-01-04  9:39   ` Jan Kara
2017-12-24  0:57 ` [PATCH v4 16/18] wait_bit: introduce {wait_on,wake_up}_atomic_one Dan Williams
2018-01-04  8:30   ` Christoph Hellwig
2017-12-24  0:57 ` [PATCH v4 17/18] mm, fs, dax: dax_flush_dma, handle dma vs block-map-change collisions Dan Williams
2018-01-04  8:31   ` Christoph Hellwig
2018-01-04 11:12   ` Jan Kara
2018-01-07 21:58     ` Dan Williams
2018-01-08 13:50       ` Jan Kara
2018-03-08 17:02         ` Dan Williams
2018-03-09 12:56           ` Jan Kara
2018-03-09 16:15             ` Dan Williams
2018-03-09 17:26               ` Dan Williams
2017-12-24  0:57 ` [PATCH v4 18/18] xfs, dax: wire up dax_flush_dma support via a new xfs_sync_dma helper Dan Williams
2018-01-02 21:07   ` Darrick J. Wong
2018-01-02 23:00   ` Dave Chinner
2018-01-03  2:21     ` Dan Williams
2018-01-03  7:51       ` Dave Chinner
2018-01-04  8:34         ` Christoph Hellwig
2018-01-04  8:33     ` Christoph Hellwig
2018-01-04  8:17 ` [PATCH v4 00/18] dax: fix dma vs truncate/hole-punch Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).