From: Dan Williams <dan.j.williams@intel.com>
To: axboe@fb.com
Cc: jack@suse.cz, linux-nvdimm@ml01.01.org, david@fromorbit.com,
linux-kernel@vger.kernel.org, hch@lst.de,
Jeff Moyer <jmoyer@redhat.com>, Jan Kara <jack@suse.com>,
ross.zwisler@linux.intel.com,
kbuild test robot <fengguang.wu@intel.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH v3 12/15] block: enable dax for raw block devices
Date: Sun, 01 Nov 2015 23:30:47 -0500 [thread overview]
Message-ID: <20151102043047.6610.59544.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <20151102042941.6610.27784.stgit@dwillia2-desk3.amr.corp.intel.com>
If an application wants exclusive access to all of the persistent memory
provided by an NVDIMM namespace it can use this raw-block-dax facility
to forgo establishing a filesystem. This capability is targeted
primarily to hypervisors wanting to provision persistent memory for
guests. It can be disabled / enabled dynamically via the new BLKDAXSET
ioctl.
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Reviewed-by: Jan Kara <jack@suse.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
block/ioctl.c | 43 ++++++++++++++++++++++
fs/block_dev.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++-
include/linux/fs.h | 3 ++
include/uapi/linux/fs.h | 2 +
4 files changed, 137 insertions(+), 1 deletion(-)
diff --git a/block/ioctl.c b/block/ioctl.c
index 8061eba42887..205d57612fbd 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -295,6 +295,35 @@ static inline int is_unrecognized_ioctl(int ret)
ret == -ENOIOCTLCMD;
}
+#ifdef CONFIG_FS_DAX
+static int blkdev_set_dax(struct block_device *bdev, int n)
+{
+ struct gendisk *disk = bdev->bd_disk;
+ int rc = 0;
+
+ if (n)
+ n = S_DAX;
+
+ if (n && !disk->fops->direct_access)
+ return -ENOTTY;
+
+ mutex_lock(&bdev->bd_inode->i_mutex);
+ if (bdev->bd_map_count == 0)
+ inode_set_flags(bdev->bd_inode, n, S_DAX);
+ else
+ rc = -EBUSY;
+ mutex_unlock(&bdev->bd_inode->i_mutex);
+ return rc;
+}
+#else
+static int blkdev_set_dax(struct block_device *bdev, int n)
+{
+ if (n)
+ return -ENOTTY;
+ return 0;
+}
+#endif
+
/*
* always keep this in sync with compat_blkdev_ioctl()
*/
@@ -449,6 +478,20 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
case BLKTRACETEARDOWN:
ret = blk_trace_ioctl(bdev, cmd, (char __user *) arg);
break;
+ case BLKDAXSET:
+ if (!capable(CAP_SYS_ADMIN))
+ return -EACCES;
+
+ if (get_user(n, (int __user *)(arg)))
+ return -EFAULT;
+ n = !!n;
+ if (n == !!(bdev->bd_inode->i_flags & S_DAX))
+ return 0;
+
+ return blkdev_set_dax(bdev, n);
+ case BLKDAXGET:
+ return put_int(arg, !!(bdev->bd_inode->i_flags & S_DAX));
+ break;
default:
ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
}
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 29cd1eb0765d..13ce6d0ff7f6 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1687,13 +1687,101 @@ static const struct address_space_operations def_blk_aops = {
.is_dirty_writeback = buffer_check_dirty_writeback,
};
+#ifdef CONFIG_FS_DAX
+/*
+ * In the raw block case we do not need to contend with truncation nor
+ * unwritten file extents. Without those concerns there is no need for
+ * additional locking beyond the mmap_sem context that these routines
+ * are already executing under.
+ *
+ * Note, there is no protection if the block device is dynamically
+ * resized (partition grow/shrink) during a fault. A stable block device
+ * size is already not enforced in the blkdev_direct_IO path.
+ *
+ * For DAX, it is the responsibility of the block device driver to
+ * ensure the whole-disk device size is stable while requests are in
+ * flight.
+ *
+ * Finally, unlike the filemap_page_mkwrite() case there is no
+ * filesystem superblock to sync against freezing. We still include a
+ * pfn_mkwrite callback for dax drivers to receive write fault
+ * notifications.
+ */
+static int blkdev_dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+ return __dax_fault(vma, vmf, blkdev_get_block, NULL);
+}
+
+static int blkdev_dax_pmd_fault(struct vm_area_struct *vma, unsigned long addr,
+ pmd_t *pmd, unsigned int flags)
+{
+ return __dax_pmd_fault(vma, addr, pmd, flags, blkdev_get_block, NULL);
+}
+
+static void blkdev_vm_open(struct vm_area_struct *vma)
+{
+ struct inode *bd_inode = bdev_file_inode(vma->vm_file);
+ struct block_device *bdev = I_BDEV(bd_inode);
+
+ mutex_lock(&bd_inode->i_mutex);
+ bdev->bd_map_count++;
+ mutex_unlock(&bd_inode->i_mutex);
+}
+
+static void blkdev_vm_close(struct vm_area_struct *vma)
+{
+ struct inode *bd_inode = bdev_file_inode(vma->vm_file);
+ struct block_device *bdev = I_BDEV(bd_inode);
+
+ mutex_lock(&bd_inode->i_mutex);
+ bdev->bd_map_count--;
+ mutex_unlock(&bd_inode->i_mutex);
+}
+
+static const struct vm_operations_struct blkdev_dax_vm_ops = {
+ .open = blkdev_vm_open,
+ .close = blkdev_vm_close,
+ .fault = blkdev_dax_fault,
+ .pmd_fault = blkdev_dax_pmd_fault,
+ .pfn_mkwrite = blkdev_dax_fault,
+};
+
+static const struct vm_operations_struct blkdev_default_vm_ops = {
+ .open = blkdev_vm_open,
+ .close = blkdev_vm_close,
+ .fault = filemap_fault,
+ .map_pages = filemap_map_pages,
+};
+
+static int blkdev_mmap(struct file *file, struct vm_area_struct *vma)
+{
+ struct inode *bd_inode = bdev_file_inode(file);
+ struct block_device *bdev = I_BDEV(bd_inode);
+
+ file_accessed(file);
+ mutex_lock(&bd_inode->i_mutex);
+ bdev->bd_map_count++;
+ if (IS_DAX(bd_inode)) {
+ vma->vm_ops = &blkdev_dax_vm_ops;
+ vma->vm_flags |= VM_MIXEDMAP | VM_HUGEPAGE;
+ } else {
+ vma->vm_ops = &blkdev_default_vm_ops;
+ }
+ mutex_unlock(&bd_inode->i_mutex);
+
+ return 0;
+}
+#else
+#define blkdev_mmap generic_file_mmap
+#endif
+
const struct file_operations def_blk_fops = {
.open = blkdev_open,
.release = blkdev_close,
.llseek = block_llseek,
.read_iter = blkdev_read_iter,
.write_iter = blkdev_write_iter,
- .mmap = generic_file_mmap,
+ .mmap = blkdev_mmap,
.fsync = blkdev_fsync,
.unlocked_ioctl = block_ioctl,
#ifdef CONFIG_COMPAT
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 72d8a844c692..8fb2d4b848bf 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -482,6 +482,9 @@ struct block_device {
int bd_fsfreeze_count;
/* Mutex for freeze */
struct mutex bd_fsfreeze_mutex;
+#ifdef CONFIG_FS_DAX
+ int bd_map_count;
+#endif
};
/*
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 9b964a5920af..cc2f0fdae707 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -152,6 +152,8 @@ struct inodes_stat_t {
#define BLKSECDISCARD _IO(0x12,125)
#define BLKROTATIONAL _IO(0x12,126)
#define BLKZEROOUT _IO(0x12,127)
+#define BLKDAXSET _IO(0x12,128)
+#define BLKDAXGET _IO(0x12,129)
#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
#define FIBMAP _IO(0x00,1) /* bmap access */
next prev parent reply other threads:[~2015-11-02 4:37 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-02 4:29 [PATCH v3 00/15] block, dax updates for 4.4 Dan Williams
2015-11-02 4:29 ` [PATCH v3 01/15] pmem, dax: clean up clear_pmem() Dan Williams
2015-11-02 4:29 ` [PATCH v3 02/15] dax: increase granularity of dax_clear_blocks() operations Dan Williams
2015-11-03 0:51 ` Dave Chinner
2015-11-03 3:27 ` Dan Williams
2015-11-03 4:48 ` Dave Chinner
2015-11-03 5:31 ` Dan Williams
2015-11-03 5:52 ` Dave Chinner
2015-11-03 7:24 ` Dan Williams
2015-11-03 16:21 ` Jan Kara
2015-11-03 17:57 ` Ross Zwisler
2015-11-03 20:59 ` Dave Chinner
2015-11-02 4:29 ` [PATCH v3 03/15] block, dax: fix lifetime of in-kernel dax mappings with dax_map_atomic() Dan Williams
2015-11-03 19:01 ` Ross Zwisler
2015-11-03 19:09 ` Jeff Moyer
2015-11-03 22:50 ` Dan Williams
2016-01-18 10:42 ` Geert Uytterhoeven
2015-11-02 4:30 ` [PATCH v3 04/15] libnvdimm, pmem: move request_queue allocation earlier in probe Dan Williams
2015-11-03 19:15 ` Ross Zwisler
2015-11-02 4:30 ` [PATCH v3 05/15] libnvdimm, pmem: fix size trim in pmem_direct_access() Dan Williams
2015-11-03 19:32 ` Ross Zwisler
2015-11-03 21:39 ` Dan Williams
2015-11-02 4:30 ` [PATCH v3 06/15] um: kill pfn_t Dan Williams
2015-11-02 4:30 ` [PATCH v3 07/15] kvm: rename pfn_t to kvm_pfn_t Dan Williams
2015-11-02 4:30 ` [PATCH v3 08/15] mm, dax, pmem: introduce pfn_t Dan Williams
2015-11-02 16:30 ` Joe Perches
2015-11-02 4:30 ` [PATCH v3 09/15] block: notify queue death confirmation Dan Williams
2015-11-02 4:30 ` [PATCH v3 10/15] dax, pmem: introduce zone_device_revoke() and devm_memunmap_pages() Dan Williams
2015-11-02 4:30 ` [PATCH v3 11/15] block: introduce bdev_file_inode() Dan Williams
2015-11-02 4:30 ` Dan Williams [this message]
2015-11-02 4:30 ` [PATCH v3 13/15] block, dax: make dax mappings opt-in by default Dan Williams
2015-11-03 0:32 ` Dave Chinner
2015-11-03 7:35 ` Dan Williams
2015-11-03 20:20 ` Dave Chinner
2015-11-03 23:04 ` Dan Williams
2015-11-04 19:23 ` Dan Williams
2015-11-02 4:30 ` [PATCH v3 14/15] dax: dirty extent notification Dan Williams
2015-11-03 1:16 ` Dave Chinner
2015-11-03 4:56 ` Dan Williams
2015-11-03 5:40 ` Dave Chinner
2015-11-03 7:20 ` Dan Williams
2015-11-03 20:51 ` Dave Chinner
2015-11-03 21:19 ` Dan Williams
2015-11-03 21:37 ` Ross Zwisler
2015-11-03 21:43 ` Dan Williams
2015-11-03 21:18 ` Ross Zwisler
2015-11-03 21:34 ` Dan Williams
2015-11-02 4:31 ` [PATCH v3 15/15] pmem: blkdev_issue_flush support Dan Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151102043047.6610.59544.stgit@dwillia2-desk3.amr.corp.intel.com \
--to=dan.j.williams@intel.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@fb.com \
--cc=david@fromorbit.com \
--cc=fengguang.wu@intel.com \
--cc=hch@lst.de \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=jmoyer@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@ml01.01.org \
--cc=ross.zwisler@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).