Skip to content

Commit b6ffe9b

Browse files
committed
Merge tag 'libnvdimm-for-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm updates from Dan Williams: "libnvdimm updates for the latest ACPI and UEFI specifications. This pull request also includes new 'struct dax_operations' enabling to undo the abuse of copy_user_nocache() for copy operations to pmem. The dax work originally missed 4.12 to address concerns raised by Al. Summary: - Introduce the _flushcache() family of memory copy helpers and use them for persistent memory write operations on x86. The _flushcache() semantic indicates that the cache is either bypassed for the copy operation (movnt) or any lines dirtied by the copy operation are written back (clwb, clflushopt, or clflush). - Extend dax_operations with ->copy_from_iter() and ->flush() operations. These operations and other infrastructure updates allow all persistent memory specific dax functionality to be pushed into libnvdimm and the pmem driver directly. It also allows dax-specific sysfs attributes to be linked to a host device, for example: /sys/block/pmem0/dax/write_cache - Add support for the new NVDIMM platform/firmware mechanisms introduced in ACPI 6.2 and UEFI 2.7. This support includes the v1.2 namespace label format, extensions to the address-range-scrub command set, new error injection commands, and a new BTT (block-translation-table) layout. These updates support inter-OS and pre-OS compatibility. - Fix a longstanding memory corruption bug in nfit_test. - Make the pmem and nvdimm-region 'badblocks' sysfs files poll(2) capable. - Miscellaneous fixes and small updates across libnvdimm and the nfit driver. Acknowledgements that came after the branch was pushed: commit 6aa734a ("libnvdimm, region, pmem: fix 'badblocks' sysfs_get_dirent() reference lifetime") was reviewed by Toshi Kani <toshi.kani@hpe.com>" * tag 'libnvdimm-for-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: (42 commits) libnvdimm, namespace: record 'lbasize' for pmem namespaces acpi/nfit: Issue Start ARS to retrieve existing records libnvdimm: New ACPI 6.2 DSM functions acpi, nfit: Show bus_dsm_mask in sysfs libnvdimm, acpi, nfit: Add bus level dsm mask for pass thru. acpi, nfit: Enable DSM pass thru for root functions. libnvdimm: passthru functions clear to send libnvdimm, btt: convert some info messages to warn/err libnvdimm, region, pmem: fix 'badblocks' sysfs_get_dirent() reference lifetime libnvdimm: fix the clear-error check in nsio_rw_bytes libnvdimm, btt: fix btt_rw_page not returning errors acpi, nfit: quiet invalid block-aperture-region warnings libnvdimm, btt: BTT updates for UEFI 2.7 format acpi, nfit: constify *_attribute_group libnvdimm, pmem: disable dax flushing when pmem is fronting a volatile region libnvdimm, pmem, dax: export a cache control attribute dax: convert to bitmask for flags dax: remove default copy_from_iter fallback libnvdimm, nfit: enable support for volatile ranges libnvdimm, pmem: fix persistence warning ...
2 parents 9f45efb + 9d92573 commit b6ffe9b

47 files changed

Lines changed: 1504 additions & 460 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎MAINTAINERS‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7680,9 +7680,7 @@ M: Ross Zwisler <ross.zwisler@linux.intel.com>
76807680
L: linux-nvdimm@lists.01.org
76817681
Q: https://patchwork.kernel.org/project/linux-nvdimm/list/
76827682
S: Supported
7683-
F: drivers/nvdimm/pmem.c
7684-
F: include/linux/pmem.h
7685-
F: arch/*/include/asm/pmem.h
7683+
F: drivers/nvdimm/pmem*
76867684

76877685
LIGHTNVM PLATFORM SUPPORT
76887686
M: Matias Bjorling <mb@lightnvm.io>

‎arch/powerpc/sysdev/axonram.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <linux/of_device.h>
4646
#include <linux/of_platform.h>
4747
#include <linux/pfn_t.h>
48+
#include <linux/uio.h>
4849

4950
#include <asm/page.h>
5051
#include <asm/prom.h>
@@ -163,8 +164,15 @@ axon_ram_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pa
163164
return __axon_ram_direct_access(bank, pgoff, nr_pages, kaddr, pfn);
164165
}
165166

167+
static size_t axon_ram_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff,
168+
void *addr, size_t bytes, struct iov_iter *i)
169+
{
170+
return copy_from_iter(addr, bytes, i);
171+
}
172+
166173
static const struct dax_operations axon_ram_dax_ops = {
167174
.direct_access = axon_ram_dax_direct_access,
175+
.copy_from_iter = axon_ram_copy_from_iter,
168176
};
169177

170178
/**

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ config X86
5454
select ARCH_HAS_KCOV if X86_64
5555
select ARCH_HAS_MMIO_FLUSH
5656
select ARCH_HAS_PMEM_API if X86_64
57+
select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64
5758
select ARCH_HAS_SET_MEMORY
5859
select ARCH_HAS_SG_CHAIN
5960
select ARCH_HAS_STRICT_KERNEL_RWX

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

Lines changed: 0 additions & 136 deletions
This file was deleted.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ memcpy_mcsafe(void *dst, const void *src, size_t cnt)
109109
return 0;
110110
}
111111

112+
#ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE
113+
#define __HAVE_ARCH_MEMCPY_FLUSHCACHE 1
114+
void memcpy_flushcache(void *dst, const void *src, size_t cnt);
115+
#endif
116+
112117
#endif /* __KERNEL__ */
113118

114119
#endif /* _ASM_X86_STRING_64_H */

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ unsigned long raw_copy_in_user(void __user *dst, const void __user *src, unsigne
171171
extern long __copy_user_nocache(void *dst, const void __user *src,
172172
unsigned size, int zerorest);
173173

174+
extern long __copy_user_flushcache(void *dst, const void __user *src, unsigned size);
175+
extern void memcpy_page_flushcache(char *to, struct page *page, size_t offset,
176+
size_t len);
177+
174178
static inline int
175179
__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
176180
unsigned size)
@@ -179,6 +183,13 @@ __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
179183
return __copy_user_nocache(dst, src, size, 0);
180184
}
181185

186+
static inline int
187+
__copy_from_user_flushcache(void *dst, const void __user *src, unsigned size)
188+
{
189+
kasan_check_write(dst, size);
190+
return __copy_user_flushcache(dst, src, size);
191+
}
192+
182193
unsigned long
183194
copy_user_handle_tail(char *to, char *from, unsigned len);
184195

‎arch/x86/lib/usercopy_64.c‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
#include <linux/export.h>
99
#include <linux/uaccess.h>
10+
#include <linux/highmem.h>
1011

1112
/*
1213
* Zero Userspace
@@ -73,3 +74,136 @@ copy_user_handle_tail(char *to, char *from, unsigned len)
7374
clac();
7475
return len;
7576
}
77+
78+
#ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE
79+
/**
80+
* clean_cache_range - write back a cache range with CLWB
81+
* @vaddr: virtual start address
82+
* @size: number of bytes to write back
83+
*
84+
* Write back a cache range using the CLWB (cache line write back)
85+
* instruction. Note that @size is internally rounded up to be cache
86+
* line size aligned.
87+
*/
88+
static void clean_cache_range(void *addr, size_t size)
89+
{
90+
u16 x86_clflush_size = boot_cpu_data.x86_clflush_size;
91+
unsigned long clflush_mask = x86_clflush_size - 1;
92+
void *vend = addr + size;
93+
void *p;
94+
95+
for (p = (void *)((unsigned long)addr & ~clflush_mask);
96+
p < vend; p += x86_clflush_size)
97+
clwb(p);
98+
}
99+
100+
void arch_wb_cache_pmem(void *addr, size_t size)
101+
{
102+
clean_cache_range(addr, size);
103+
}
104+
EXPORT_SYMBOL_GPL(arch_wb_cache_pmem);
105+
106+
long __copy_user_flushcache(void *dst, const void __user *src, unsigned size)
107+
{
108+
unsigned long flushed, dest = (unsigned long) dst;
109+
long rc = __copy_user_nocache(dst, src, size, 0);
110+
111+
/*
112+
* __copy_user_nocache() uses non-temporal stores for the bulk
113+
* of the transfer, but we need to manually flush if the
114+
* transfer is unaligned. A cached memory copy is used when
115+
* destination or size is not naturally aligned. That is:
116+
* - Require 8-byte alignment when size is 8 bytes or larger.
117+
* - Require 4-byte alignment when size is 4 bytes.
118+
*/
119+
if (size < 8) {
120+
if (!IS_ALIGNED(dest, 4) || size != 4)
121+
clean_cache_range(dst, 1);
122+
} else {
123+
if (!IS_ALIGNED(dest, 8)) {
124+
dest = ALIGN(dest, boot_cpu_data.x86_clflush_size);
125+
clean_cache_range(dst, 1);
126+
}
127+
128+
flushed = dest - (unsigned long) dst;
129+
if (size > flushed && !IS_ALIGNED(size - flushed, 8))
130+
clean_cache_range(dst + size - 1, 1);
131+
}
132+
133+
return rc;
134+
}
135+
136+
void memcpy_flushcache(void *_dst, const void *_src, size_t size)
137+
{
138+
unsigned long dest = (unsigned long) _dst;
139+
unsigned long source = (unsigned long) _src;
140+
141+
/* cache copy and flush to align dest */
142+
if (!IS_ALIGNED(dest, 8)) {
143+
unsigned len = min_t(unsigned, size, ALIGN(dest, 8) - dest);
144+
145+
memcpy((void *) dest, (void *) source, len);
146+
clean_cache_range((void *) dest, len);
147+
dest += len;
148+
source += len;
149+
size -= len;
150+
if (!size)
151+
return;
152+
}
153+
154+
/* 4x8 movnti loop */
155+
while (size >= 32) {
156+
asm("movq (%0), %%r8\n"
157+
"movq 8(%0), %%r9\n"
158+
"movq 16(%0), %%r10\n"
159+
"movq 24(%0), %%r11\n"
160+
"movnti %%r8, (%1)\n"
161+
"movnti %%r9, 8(%1)\n"
162+
"movnti %%r10, 16(%1)\n"
163+
"movnti %%r11, 24(%1)\n"
164+
:: "r" (source), "r" (dest)
165+
: "memory", "r8", "r9", "r10", "r11");
166+
dest += 32;
167+
source += 32;
168+
size -= 32;
169+
}
170+
171+
/* 1x8 movnti loop */
172+
while (size >= 8) {
173+
asm("movq (%0), %%r8\n"
174+
"movnti %%r8, (%1)\n"
175+
:: "r" (source), "r" (dest)
176+
: "memory", "r8");
177+
dest += 8;
178+
source += 8;
179+
size -= 8;
180+
}
181+
182+
/* 1x4 movnti loop */
183+
while (size >= 4) {
184+
asm("movl (%0), %%r8d\n"
185+
"movnti %%r8d, (%1)\n"
186+
:: "r" (source), "r" (dest)
187+
: "memory", "r8");
188+
dest += 4;
189+
source += 4;
190+
size -= 4;
191+
}
192+
193+
/* cache copy for remaining bytes */
194+
if (size) {
195+
memcpy((void *) dest, (void *) source, size);
196+
clean_cache_range((void *) dest, size);
197+
}
198+
}
199+
EXPORT_SYMBOL_GPL(memcpy_flushcache);
200+
201+
void memcpy_page_flushcache(char *to, struct page *page, size_t offset,
202+
size_t len)
203+
{
204+
char *from = kmap_atomic(page);
205+
206+
memcpy_flushcache(to, from + offset, len);
207+
kunmap_atomic(from);
208+
}
209+
#endif

‎arch/x86/mm/pageattr.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ void clflush_cache_range(void *vaddr, unsigned int size)
150150
}
151151
EXPORT_SYMBOL_GPL(clflush_cache_range);
152152

153+
void arch_invalidate_pmem(void *addr, size_t size)
154+
{
155+
clflush_cache_range(addr, size);
156+
}
157+
EXPORT_SYMBOL_GPL(arch_invalidate_pmem);
158+
153159
static void __cpa_flush_all(void *arg)
154160
{
155161
unsigned long cache = (unsigned long)arg;

0 commit comments

Comments
 (0)