Skip to content

Commit 7d3bf61

Browse files
committed
Merge tag 'libnvdimm-for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm updates from Dan Williams: "This adds a user for the new 'bytes-remaining' updates to memcpy_mcsafe() that you already received through Ingo via the x86-dax- for-linus pull. Not included here, but still targeting this cycle, is support for handling memory media errors (poison) consumed via userspace dax mappings. Summary: - DAX broke a fundamental assumption of truncate of file mapped pages. The truncate path assumed that it is safe to disconnect a pinned page from a file and let the filesystem reclaim the physical block. With DAX the page is equivalent to the filesystem block. Introduce dax_layout_busy_page() to enable filesystems to wait for pinned DAX pages to be released. Without this wait a filesystem could allocate blocks under active device-DMA to a new file. - DAX arranges for the block layer to be bypassed and uses dax_direct_access() + copy_to_iter() to satisfy read(2) calls. However, the memcpy_mcsafe() facility is available through the pmem block driver. In order to safely handle media errors, via the DAX block-layer bypass, introduce copy_to_iter_mcsafe(). - Fix cache management policy relative to the ACPI NFIT Platform Capabilities Structure to properly elide cache flushes when they are not necessary. The table indicates whether CPU caches are power-fail protected. Clarify that a deep flush is always performed on REQ_{FUA,PREFLUSH} requests" * tag 'libnvdimm-for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: (21 commits) dax: Use dax_write_cache* helpers libnvdimm, pmem: Do not flush power-fail protected CPU caches libnvdimm, pmem: Unconditionally deep flush on *sync libnvdimm, pmem: Complete REQ_FLUSH => REQ_PREFLUSH acpi, nfit: Remove ecc_unit_size dax: dax_insert_mapping_entry always succeeds libnvdimm, e820: Register all pmem resources libnvdimm: Debug probe times linvdimm, pmem: Preserve read-only setting for pmem devices x86, nfit_test: Add unit test for memcpy_mcsafe() pmem: Switch to copy_to_iter_mcsafe() dax: Report bytes remaining in dax_iomap_actor() dax: Introduce a ->copy_to_iter dax operation uio, lib: Fix CONFIG_ARCH_HAS_UACCESS_MCSAFE compilation xfs, dax: introduce xfs_break_dax_layouts() xfs: prepare xfs_break_layouts() for another layout type xfs: prepare xfs_break_layouts() to be called with XFS_MMAPLOCK_EXCL mm, fs, dax: handle layout changes to pinned dax mappings mm: fix __gup_device_huge vs unmap mm: introduce MEMORY_DEVICE_FS_DAX and CONFIG_DEV_PAGEMAP_OPS ...
2 parents a381884 + 930218a commit 7d3bf61

40 files changed

Lines changed: 924 additions & 379 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
What: /sys/bus/nd/devices/regionX/nfit/ecc_unit_size
2+
Date: Aug, 2017
3+
KernelVersion: v4.14 (Removed v4.18)
4+
Contact: linux-nvdimm@lists.01.org
5+
Description:
6+
(RO) Size of a write request to a DIMM that will not incur a
7+
read-modify-write cycle at the memory controller.
8+
9+
When the nfit driver initializes it runs an ARS (Address Range
10+
Scrub) operation across every pmem range. Part of that process
11+
involves determining the ARS capabilities of a given address
12+
range. One of the capabilities that is reported is the 'Clear
13+
Uncorrectable Error Range Length Unit Size' (see: ACPI 6.2
14+
section 9.20.7.4 Function Index 1 - Query ARS Capabilities).
15+
This property indicates the boundary at which the NVDIMM may
16+
need to perform read-modify-write cycles to maintain ECC (Error
17+
Correcting Code) blocks.

‎Documentation/ABI/testing/sysfs-bus-nfit‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,3 @@ Description:
212212
range. Used by NVDIMM Region Mapping Structure to uniquely refer
213213
to this structure. Value of 0 is reserved and not used as an
214214
index.
215-
216-
217-
What: /sys/bus/nd/devices/regionX/nfit/ecc_unit_size
218-
Date: Aug, 2017
219-
KernelVersion: v4.14
220-
Contact: linux-nvdimm@lists.01.org
221-
Description:
222-
(RO) Size of a write request to a DIMM that will not incur a
223-
read-modify-write cycle at the memory controller.
224-
225-
When the nfit driver initializes it runs an ARS (Address Range
226-
Scrub) operation across every pmem range. Part of that process
227-
involves determining the ARS capabilities of a given address
228-
range. One of the capabilities that is reported is the 'Clear
229-
Uncorrectable Error Range Length Unit Size' (see: ACPI 6.2
230-
section 9.20.7.4 Function Index 1 - Query ARS Capabilities).
231-
This property indicates the boundary at which the NVDIMM may
232-
need to perform read-modify-write cycles to maintain ECC (Error
233-
Correcting Code) blocks.

‎arch/x86/Kconfig.debug‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ config EARLY_PRINTK_USB_XDBC
7272
You should normally say N here, unless you want to debug early
7373
crashes or need a very simple printk logging facility.
7474

75+
config MCSAFE_TEST
76+
def_bool n
77+
7578
config X86_PTDUMP_CORE
7679
def_bool n
7780

‎arch/x86/include/asm/mcsafe_test.h‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _MCSAFE_TEST_H_
3+
#define _MCSAFE_TEST_H_
4+
5+
#ifndef __ASSEMBLY__
6+
#ifdef CONFIG_MCSAFE_TEST
7+
extern unsigned long mcsafe_test_src;
8+
extern unsigned long mcsafe_test_dst;
9+
10+
static inline void mcsafe_inject_src(void *addr)
11+
{
12+
if (addr)
13+
mcsafe_test_src = (unsigned long) addr;
14+
else
15+
mcsafe_test_src = ~0UL;
16+
}
17+
18+
static inline void mcsafe_inject_dst(void *addr)
19+
{
20+
if (addr)
21+
mcsafe_test_dst = (unsigned long) addr;
22+
else
23+
mcsafe_test_dst = ~0UL;
24+
}
25+
#else /* CONFIG_MCSAFE_TEST */
26+
static inline void mcsafe_inject_src(void *addr)
27+
{
28+
}
29+
30+
static inline void mcsafe_inject_dst(void *addr)
31+
{
32+
}
33+
#endif /* CONFIG_MCSAFE_TEST */
34+
35+
#else /* __ASSEMBLY__ */
36+
#include <asm/export.h>
37+
38+
#ifdef CONFIG_MCSAFE_TEST
39+
.macro MCSAFE_TEST_CTL
40+
.pushsection .data
41+
.align 8
42+
.globl mcsafe_test_src
43+
mcsafe_test_src:
44+
.quad 0
45+
EXPORT_SYMBOL_GPL(mcsafe_test_src)
46+
.globl mcsafe_test_dst
47+
mcsafe_test_dst:
48+
.quad 0
49+
EXPORT_SYMBOL_GPL(mcsafe_test_dst)
50+
.popsection
51+
.endm
52+
53+
.macro MCSAFE_TEST_SRC reg count target
54+
leaq \count(\reg), %r9
55+
cmp mcsafe_test_src, %r9
56+
ja \target
57+
.endm
58+
59+
.macro MCSAFE_TEST_DST reg count target
60+
leaq \count(\reg), %r9
61+
cmp mcsafe_test_dst, %r9
62+
ja \target
63+
.endm
64+
#else
65+
.macro MCSAFE_TEST_CTL
66+
.endm
67+
68+
.macro MCSAFE_TEST_SRC reg count target
69+
.endm
70+
71+
.macro MCSAFE_TEST_DST reg count target
72+
.endm
73+
#endif /* CONFIG_MCSAFE_TEST */
74+
#endif /* __ASSEMBLY__ */
75+
#endif /* _MCSAFE_TEST_H_ */

‎arch/x86/lib/memcpy_64.S‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/linkage.h>
44
#include <asm/errno.h>
55
#include <asm/cpufeatures.h>
6+
#include <asm/mcsafe_test.h>
67
#include <asm/alternative-asm.h>
78
#include <asm/export.h>
89

@@ -183,6 +184,9 @@ ENTRY(memcpy_orig)
183184
ENDPROC(memcpy_orig)
184185

185186
#ifndef CONFIG_UML
187+
188+
MCSAFE_TEST_CTL
189+
186190
/*
187191
* __memcpy_mcsafe - memory copy with machine check exception handling
188192
* Note that we only catch machine checks when reading the source addresses.
@@ -206,6 +210,8 @@ ENTRY(__memcpy_mcsafe)
206210
subl %ecx, %edx
207211
.L_read_leading_bytes:
208212
movb (%rsi), %al
213+
MCSAFE_TEST_SRC %rsi 1 .E_leading_bytes
214+
MCSAFE_TEST_DST %rdi 1 .E_leading_bytes
209215
.L_write_leading_bytes:
210216
movb %al, (%rdi)
211217
incq %rsi
@@ -221,6 +227,8 @@ ENTRY(__memcpy_mcsafe)
221227

222228
.L_read_words:
223229
movq (%rsi), %r8
230+
MCSAFE_TEST_SRC %rsi 8 .E_read_words
231+
MCSAFE_TEST_DST %rdi 8 .E_write_words
224232
.L_write_words:
225233
movq %r8, (%rdi)
226234
addq $8, %rsi
@@ -237,6 +245,8 @@ ENTRY(__memcpy_mcsafe)
237245
movl %edx, %ecx
238246
.L_read_trailing_bytes:
239247
movb (%rsi), %al
248+
MCSAFE_TEST_SRC %rsi 1 .E_trailing_bytes
249+
MCSAFE_TEST_DST %rdi 1 .E_trailing_bytes
240250
.L_write_trailing_bytes:
241251
movb %al, (%rdi)
242252
incq %rsi

‎drivers/acpi/nfit/core.c‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,19 +1978,8 @@ static ssize_t range_index_show(struct device *dev,
19781978
}
19791979
static DEVICE_ATTR_RO(range_index);
19801980

1981-
static ssize_t ecc_unit_size_show(struct device *dev,
1982-
struct device_attribute *attr, char *buf)
1983-
{
1984-
struct nd_region *nd_region = to_nd_region(dev);
1985-
struct nfit_spa *nfit_spa = nd_region_provider_data(nd_region);
1986-
1987-
return sprintf(buf, "%d\n", nfit_spa->clear_err_unit);
1988-
}
1989-
static DEVICE_ATTR_RO(ecc_unit_size);
1990-
19911981
static struct attribute *acpi_nfit_region_attributes[] = {
19921982
&dev_attr_range_index.attr,
1993-
&dev_attr_ecc_unit_size.attr,
19941983
NULL,
19951984
};
19961985

‎drivers/dax/super.c‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev);
8585
bool __bdev_dax_supported(struct block_device *bdev, int blocksize)
8686
{
8787
struct dax_device *dax_dev;
88+
bool dax_enabled = false;
8889
pgoff_t pgoff;
8990
int err, id;
9091
void *kaddr;
@@ -134,14 +135,21 @@ bool __bdev_dax_supported(struct block_device *bdev, int blocksize)
134135
* on being able to do (page_address(pfn_to_page())).
135136
*/
136137
WARN_ON(IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API));
138+
dax_enabled = true;
137139
} else if (pfn_t_devmap(pfn)) {
138-
/* pass */;
139-
} else {
140+
struct dev_pagemap *pgmap;
141+
142+
pgmap = get_dev_pagemap(pfn_t_to_pfn(pfn), NULL);
143+
if (pgmap && pgmap->type == MEMORY_DEVICE_FS_DAX)
144+
dax_enabled = true;
145+
put_dev_pagemap(pgmap);
146+
}
147+
148+
if (!dax_enabled) {
140149
pr_debug("%s: error: dax support not enabled\n",
141150
bdevname(bdev, buf));
142151
return false;
143152
}
144-
145153
return true;
146154
}
147155
EXPORT_SYMBOL_GPL(__bdev_dax_supported);
@@ -182,8 +190,7 @@ static ssize_t write_cache_show(struct device *dev,
182190
if (!dax_dev)
183191
return -ENXIO;
184192

185-
rc = sprintf(buf, "%d\n", !!test_bit(DAXDEV_WRITE_CACHE,
186-
&dax_dev->flags));
193+
rc = sprintf(buf, "%d\n", !!dax_write_cache_enabled(dax_dev));
187194
put_dax(dax_dev);
188195
return rc;
189196
}
@@ -201,10 +208,8 @@ static ssize_t write_cache_store(struct device *dev,
201208

202209
if (rc)
203210
len = rc;
204-
else if (write_cache)
205-
set_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags);
206211
else
207-
clear_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags);
212+
dax_write_cache(dax_dev, write_cache);
208213

209214
put_dax(dax_dev);
210215
return len;
@@ -282,11 +287,21 @@ size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
282287
}
283288
EXPORT_SYMBOL_GPL(dax_copy_from_iter);
284289

290+
size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
291+
size_t bytes, struct iov_iter *i)
292+
{
293+
if (!dax_alive(dax_dev))
294+
return 0;
295+
296+
return dax_dev->ops->copy_to_iter(dax_dev, pgoff, addr, bytes, i);
297+
}
298+
EXPORT_SYMBOL_GPL(dax_copy_to_iter);
299+
285300
#ifdef CONFIG_ARCH_HAS_PMEM_API
286301
void arch_wb_cache_pmem(void *addr, size_t size);
287302
void dax_flush(struct dax_device *dax_dev, void *addr, size_t size)
288303
{
289-
if (unlikely(!test_bit(DAXDEV_WRITE_CACHE, &dax_dev->flags)))
304+
if (unlikely(!dax_write_cache_enabled(dax_dev)))
290305
return;
291306

292307
arch_wb_cache_pmem(addr, size);

‎drivers/md/dm-linear.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,24 @@ static size_t linear_dax_copy_from_iter(struct dm_target *ti, pgoff_t pgoff,
185185
return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
186186
}
187187

188+
static size_t linear_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
189+
void *addr, size_t bytes, struct iov_iter *i)
190+
{
191+
struct linear_c *lc = ti->private;
192+
struct block_device *bdev = lc->dev->bdev;
193+
struct dax_device *dax_dev = lc->dev->dax_dev;
194+
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
195+
196+
dev_sector = linear_map_sector(ti, sector);
197+
if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
198+
return 0;
199+
return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
200+
}
201+
188202
#else
189203
#define linear_dax_direct_access NULL
190204
#define linear_dax_copy_from_iter NULL
205+
#define linear_dax_copy_to_iter NULL
191206
#endif
192207

193208
static struct target_type linear_target = {
@@ -204,6 +219,7 @@ static struct target_type linear_target = {
204219
.iterate_devices = linear_iterate_devices,
205220
.direct_access = linear_dax_direct_access,
206221
.dax_copy_from_iter = linear_dax_copy_from_iter,
222+
.dax_copy_to_iter = linear_dax_copy_to_iter,
207223
};
208224

209225
int __init dm_linear_init(void)

‎drivers/md/dm-log-writes.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,23 @@ static size_t log_writes_dax_copy_from_iter(struct dm_target *ti,
962962
dax_copy:
963963
return dax_copy_from_iter(lc->dev->dax_dev, pgoff, addr, bytes, i);
964964
}
965+
966+
static size_t log_writes_dax_copy_to_iter(struct dm_target *ti,
967+
pgoff_t pgoff, void *addr, size_t bytes,
968+
struct iov_iter *i)
969+
{
970+
struct log_writes_c *lc = ti->private;
971+
sector_t sector = pgoff * PAGE_SECTORS;
972+
973+
if (bdev_dax_pgoff(lc->dev->bdev, sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
974+
return 0;
975+
return dax_copy_to_iter(lc->dev->dax_dev, pgoff, addr, bytes, i);
976+
}
977+
965978
#else
966979
#define log_writes_dax_direct_access NULL
967980
#define log_writes_dax_copy_from_iter NULL
981+
#define log_writes_dax_copy_to_iter NULL
968982
#endif
969983

970984
static struct target_type log_writes_target = {
@@ -982,6 +996,7 @@ static struct target_type log_writes_target = {
982996
.io_hints = log_writes_io_hints,
983997
.direct_access = log_writes_dax_direct_access,
984998
.dax_copy_from_iter = log_writes_dax_copy_from_iter,
999+
.dax_copy_to_iter = log_writes_dax_copy_to_iter,
9851000
};
9861001

9871002
static int __init dm_log_writes_init(void)

‎drivers/md/dm-stripe.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,29 @@ static size_t stripe_dax_copy_from_iter(struct dm_target *ti, pgoff_t pgoff,
354354
return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
355355
}
356356

357+
static size_t stripe_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
358+
void *addr, size_t bytes, struct iov_iter *i)
359+
{
360+
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
361+
struct stripe_c *sc = ti->private;
362+
struct dax_device *dax_dev;
363+
struct block_device *bdev;
364+
uint32_t stripe;
365+
366+
stripe_map_sector(sc, sector, &stripe, &dev_sector);
367+
dev_sector += sc->stripe[stripe].physical_start;
368+
dax_dev = sc->stripe[stripe].dev->dax_dev;
369+
bdev = sc->stripe[stripe].dev->bdev;
370+
371+
if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
372+
return 0;
373+
return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
374+
}
375+
357376
#else
358377
#define stripe_dax_direct_access NULL
359378
#define stripe_dax_copy_from_iter NULL
379+
#define stripe_dax_copy_to_iter NULL
360380
#endif
361381

362382
/*
@@ -478,6 +498,7 @@ static struct target_type stripe_target = {
478498
.io_hints = stripe_io_hints,
479499
.direct_access = stripe_dax_direct_access,
480500
.dax_copy_from_iter = stripe_dax_copy_from_iter,
501+
.dax_copy_to_iter = stripe_dax_copy_to_iter,
481502
};
482503

483504
int __init dm_stripe_init(void)

0 commit comments

Comments
 (0)