Skip to content

Commit 0fcc3ab

Browse files
committed
Merge branch 'libnvdimm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm fixes from Dan Williams: "Incremental fixes and a small feature addition on top of the main libnvdimm 4.12 pull request: - Geert noticed that tinyconfig was bloated by BLOCK selecting DAX. The size regression is fixed by moving all dax helpers into the dax-core and only specifying "select DAX" for FS_DAX and dax-capable drivers. He also asked for clarification of the NR_DEV_DAX config option which, on closer look, does not need to be a config option at all. Mike also throws in a DEV_DAX_PMEM fixup for good measure. - Ben's attention to detail on -stable patch submissions caught a case where the recent fixes to arch_copy_from_iter_pmem() missed a condition where we strand dirty data in the cache. This is tagged for -stable and will also be included in the rework of the pmem api to a proposed {memcpy,copy_user}_flushcache() interface for 4.13. - Vishal adds a feature that missed the initial pull due to pending review feedback. It allows the kernel to clear media errors when initializing a BTT (atomic sector update driver) instance on a pmem namespace. - Ross noticed that the dax_device + dax_operations conversion broke __dax_zero_page_range(). The nvdimm unit tests fail to check this path, but xfstests immediately trips over it. No excuse for missing this before submitting the 4.12 pull request. These all pass the nvdimm unit tests and an xfstests spot check. The set has received a build success notification from the kbuild robot" * 'libnvdimm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: filesystem-dax: fix broken __dax_zero_page_range() conversion libnvdimm, btt: ensure that initializing metadata clears poison libnvdimm: add an atomic vs process context flag to rw_bytes x86, pmem: Fix cache flushing for iovec write < 8 bytes device-dax: kill NR_DEV_DAX block, dax: move "select DAX" from BLOCK to FS_DAX device-dax: Tell kbuild DEV_DAX_PMEM depends on DEV_DAX
2 parents deac842 + e84b83b commit 0fcc3ab

File tree

19 files changed

+208
-136
lines changed

19 files changed

+208
-136
lines changed

arch/x86/include/asm/pmem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static inline size_t arch_copy_from_iter_pmem(void *addr, size_t bytes,
9898

9999
if (bytes < 8) {
100100
if (!IS_ALIGNED(dest, 4) || (bytes != 4))
101-
arch_wb_cache_pmem(addr, 1);
101+
arch_wb_cache_pmem(addr, bytes);
102102
} else {
103103
if (!IS_ALIGNED(dest, 8)) {
104104
dest = ALIGN(dest, boot_cpu_data.x86_clflush_size);

block/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ menuconfig BLOCK
66
default y
77
select SBITMAP
88
select SRCU
9-
select DAX
109
help
1110
Provide block layer support for the kernel.
1211

drivers/dax/Kconfig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ config DEV_DAX
1919

2020
config DEV_DAX_PMEM
2121
tristate "PMEM DAX: direct access to persistent memory"
22-
depends on LIBNVDIMM && NVDIMM_DAX
22+
depends on LIBNVDIMM && NVDIMM_DAX && DEV_DAX
2323
default DEV_DAX
2424
help
2525
Support raw access to persistent memory. Note that this
@@ -28,9 +28,4 @@ config DEV_DAX_PMEM
2828

2929
Say Y if unsure
3030

31-
config NR_DEV_DAX
32-
int "Maximum number of Device-DAX instances"
33-
default 32768
34-
range 256 2147483647
35-
3631
endif

drivers/dax/super.c

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
#include <linux/module.h>
1515
#include <linux/mount.h>
1616
#include <linux/magic.h>
17+
#include <linux/genhd.h>
1718
#include <linux/cdev.h>
1819
#include <linux/hash.h>
1920
#include <linux/slab.h>
2021
#include <linux/dax.h>
2122
#include <linux/fs.h>
2223

23-
static int nr_dax = CONFIG_NR_DEV_DAX;
24-
module_param(nr_dax, int, S_IRUGO);
25-
MODULE_PARM_DESC(nr_dax, "max number of dax device instances");
26-
2724
static dev_t dax_devt;
2825
DEFINE_STATIC_SRCU(dax_srcu);
2926
static struct vfsmount *dax_mnt;
@@ -47,6 +44,75 @@ void dax_read_unlock(int id)
4744
}
4845
EXPORT_SYMBOL_GPL(dax_read_unlock);
4946

47+
int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size,
48+
pgoff_t *pgoff)
49+
{
50+
phys_addr_t phys_off = (get_start_sect(bdev) + sector) * 512;
51+
52+
if (pgoff)
53+
*pgoff = PHYS_PFN(phys_off);
54+
if (phys_off % PAGE_SIZE || size % PAGE_SIZE)
55+
return -EINVAL;
56+
return 0;
57+
}
58+
EXPORT_SYMBOL(bdev_dax_pgoff);
59+
60+
/**
61+
* __bdev_dax_supported() - Check if the device supports dax for filesystem
62+
* @sb: The superblock of the device
63+
* @blocksize: The block size of the device
64+
*
65+
* This is a library function for filesystems to check if the block device
66+
* can be mounted with dax option.
67+
*
68+
* Return: negative errno if unsupported, 0 if supported.
69+
*/
70+
int __bdev_dax_supported(struct super_block *sb, int blocksize)
71+
{
72+
struct block_device *bdev = sb->s_bdev;
73+
struct dax_device *dax_dev;
74+
pgoff_t pgoff;
75+
int err, id;
76+
void *kaddr;
77+
pfn_t pfn;
78+
long len;
79+
80+
if (blocksize != PAGE_SIZE) {
81+
pr_err("VFS (%s): error: unsupported blocksize for dax\n",
82+
sb->s_id);
83+
return -EINVAL;
84+
}
85+
86+
err = bdev_dax_pgoff(bdev, 0, PAGE_SIZE, &pgoff);
87+
if (err) {
88+
pr_err("VFS (%s): error: unaligned partition for dax\n",
89+
sb->s_id);
90+
return err;
91+
}
92+
93+
dax_dev = dax_get_by_host(bdev->bd_disk->disk_name);
94+
if (!dax_dev) {
95+
pr_err("VFS (%s): error: device does not support dax\n",
96+
sb->s_id);
97+
return -EOPNOTSUPP;
98+
}
99+
100+
id = dax_read_lock();
101+
len = dax_direct_access(dax_dev, pgoff, 1, &kaddr, &pfn);
102+
dax_read_unlock(id);
103+
104+
put_dax(dax_dev);
105+
106+
if (len < 1) {
107+
pr_err("VFS (%s): error: dax access failed (%ld)",
108+
sb->s_id, len);
109+
return len < 0 ? len : -EIO;
110+
}
111+
112+
return 0;
113+
}
114+
EXPORT_SYMBOL_GPL(__bdev_dax_supported);
115+
50116
/**
51117
* struct dax_device - anchor object for dax services
52118
* @inode: core vfs
@@ -261,7 +327,7 @@ struct dax_device *alloc_dax(void *private, const char *__host,
261327
if (__host && !host)
262328
return NULL;
263329

264-
minor = ida_simple_get(&dax_minor_ida, 0, nr_dax, GFP_KERNEL);
330+
minor = ida_simple_get(&dax_minor_ida, 0, MINORMASK+1, GFP_KERNEL);
265331
if (minor < 0)
266332
goto err_minor;
267333

@@ -405,16 +471,15 @@ static int __init dax_fs_init(void)
405471
if (rc)
406472
return rc;
407473

408-
nr_dax = max(nr_dax, 256);
409-
rc = alloc_chrdev_region(&dax_devt, 0, nr_dax, "dax");
474+
rc = alloc_chrdev_region(&dax_devt, 0, MINORMASK+1, "dax");
410475
if (rc)
411476
__dax_fs_exit();
412477
return rc;
413478
}
414479

415480
static void __exit dax_fs_exit(void)
416481
{
417-
unregister_chrdev_region(dax_devt, nr_dax);
482+
unregister_chrdev_region(dax_devt, MINORMASK+1);
418483
ida_destroy(&dax_minor_ida);
419484
__dax_fs_exit();
420485
}

drivers/nvdimm/blk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ static blk_qc_t nd_blk_make_request(struct request_queue *q, struct bio *bio)
218218
}
219219

220220
static int nsblk_rw_bytes(struct nd_namespace_common *ndns,
221-
resource_size_t offset, void *iobuf, size_t n, int rw)
221+
resource_size_t offset, void *iobuf, size_t n, int rw,
222+
unsigned long flags)
222223
{
223224
struct nd_namespace_blk *nsblk = to_nd_namespace_blk(&ndns->dev);
224225
struct nd_blk_region *ndbr = to_ndbr(nsblk);

0 commit comments

Comments
 (0)