Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pmem: add wb_cache_pmem() to the PMEM API

__arch_wb_cache_pmem() was already an internal implementation detail of
the x86 PMEM API, but this functionality needs to be exported as part of
the general PMEM API to handle the fsync/msync case for DAX mmaps.

One thing worth noting is that we really do want this to be part of the
PMEM API as opposed to a stand-alone function like clflush_cache_range()
because of ordering restrictions. By having wb_cache_pmem() as part of
the PMEM API we can leave it unordered, call it multiple times to write
back large amounts of memory, and then order the multiple calls with a
single wmb_pmem().

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: "J. Bruce Fields" <bfields@fieldses.org>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jan Kara <jack@suse.com>
Cc: Jeff Layton <jlayton@poochiereds.net>
Cc: Matthew Wilcox <willy@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Matthew Wilcox <matthew.r.wilcox@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ross Zwisler and committed by
Linus Torvalds
3f4a2670 de14b9cb

+27 -6
+6 -5
arch/x86/include/asm/pmem.h
··· 67 67 } 68 68 69 69 /** 70 - * __arch_wb_cache_pmem - write back a cache range with CLWB 70 + * arch_wb_cache_pmem - write back a cache range with CLWB 71 71 * @vaddr: virtual start address 72 72 * @size: number of bytes to write back 73 73 * 74 74 * Write back a cache range using the CLWB (cache line write back) 75 75 * instruction. This function requires explicit ordering with an 76 - * arch_wmb_pmem() call. This API is internal to the x86 PMEM implementation. 76 + * arch_wmb_pmem() call. 77 77 */ 78 - static inline void __arch_wb_cache_pmem(void *vaddr, size_t size) 78 + static inline void arch_wb_cache_pmem(void __pmem *addr, size_t size) 79 79 { 80 80 u16 x86_clflush_size = boot_cpu_data.x86_clflush_size; 81 81 unsigned long clflush_mask = x86_clflush_size - 1; 82 + void *vaddr = (void __force *)addr; 82 83 void *vend = vaddr + size; 83 84 void *p; 84 85 ··· 116 115 len = copy_from_iter_nocache(vaddr, bytes, i); 117 116 118 117 if (__iter_needs_pmem_wb(i)) 119 - __arch_wb_cache_pmem(vaddr, bytes); 118 + arch_wb_cache_pmem(addr, bytes); 120 119 121 120 return len; 122 121 } ··· 134 133 void *vaddr = (void __force *)addr; 135 134 136 135 memset(vaddr, 0, size); 137 - __arch_wb_cache_pmem(vaddr, size); 136 + arch_wb_cache_pmem(addr, size); 138 137 } 139 138 140 139 static inline bool __arch_has_wmb_pmem(void)
+21 -1
include/linux/pmem.h
··· 53 53 { 54 54 BUG(); 55 55 } 56 + 57 + static inline void arch_wb_cache_pmem(void __pmem *addr, size_t size) 58 + { 59 + BUG(); 60 + } 56 61 #endif 57 62 58 63 /* 59 64 * Architectures that define ARCH_HAS_PMEM_API must provide 60 65 * implementations for arch_memcpy_to_pmem(), arch_wmb_pmem(), 61 - * arch_copy_from_iter_pmem(), arch_clear_pmem() and arch_has_wmb_pmem(). 66 + * arch_copy_from_iter_pmem(), arch_clear_pmem(), arch_wb_cache_pmem() 67 + * and arch_has_wmb_pmem(). 62 68 */ 63 69 static inline void memcpy_from_pmem(void *dst, void __pmem const *src, size_t size) 64 70 { ··· 183 177 arch_clear_pmem(addr, size); 184 178 else 185 179 default_clear_pmem(addr, size); 180 + } 181 + 182 + /** 183 + * wb_cache_pmem - write back processor cache for PMEM memory range 184 + * @addr: virtual start address 185 + * @size: number of bytes to write back 186 + * 187 + * Write back the processor cache range starting at 'addr' for 'size' bytes. 188 + * This function requires explicit ordering with a wmb_pmem() call. 189 + */ 190 + static inline void wb_cache_pmem(void __pmem *addr, size_t size) 191 + { 192 + if (arch_has_pmem_api()) 193 + arch_wb_cache_pmem(addr, size); 186 194 } 187 195 #endif /* __PMEM_H__ */