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

Configure Feed

Select the types of activity you want to include in your feed.

at 4d8e74ad4585672489da6145b3328d415f50db82 325 lines 10 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_DAX_H 3#define _LINUX_DAX_H 4 5#include <linux/fs.h> 6#include <linux/mm.h> 7#include <linux/radix-tree.h> 8 9typedef unsigned long dax_entry_t; 10 11struct dax_device; 12struct gendisk; 13struct iomap_ops; 14struct iomap_iter; 15struct iomap; 16 17enum dax_access_mode { 18 DAX_ACCESS, 19 DAX_RECOVERY_WRITE, 20}; 21 22struct dax_operations { 23 /* 24 * direct_access: translate a device-relative 25 * logical-page-offset into an absolute physical pfn. Return the 26 * number of pages available for DAX at that pfn. 27 */ 28 long (*direct_access)(struct dax_device *, pgoff_t, long, 29 enum dax_access_mode, void **, unsigned long *); 30 /* zero_page_range: required operation. Zero page range */ 31 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t); 32 /* 33 * recovery_write: recover a poisoned range by DAX device driver 34 * capable of clearing poison. 35 */ 36 size_t (*recovery_write)(struct dax_device *dax_dev, pgoff_t pgoff, 37 void *addr, size_t bytes, struct iov_iter *iter); 38}; 39 40struct dax_holder_operations { 41 /* 42 * notify_failure - notify memory failure into inner holder device 43 * @dax_dev: the dax device which contains the holder 44 * @offset: offset on this dax device where memory failure occurs 45 * @len: length of this memory failure event 46 * @flags: action flags for memory failure handler 47 */ 48 int (*notify_failure)(struct dax_device *dax_dev, u64 offset, 49 u64 len, int mf_flags); 50}; 51 52#if IS_ENABLED(CONFIG_DAX) 53struct dax_device *alloc_dax(void *private, const struct dax_operations *ops); 54void *dax_holder(struct dax_device *dax_dev); 55void put_dax(struct dax_device *dax_dev); 56void kill_dax(struct dax_device *dax_dev); 57struct dax_device *dax_dev_get(dev_t devt); 58void dax_write_cache(struct dax_device *dax_dev, bool wc); 59bool dax_write_cache_enabled(struct dax_device *dax_dev); 60bool dax_synchronous(struct dax_device *dax_dev); 61void set_dax_nocache(struct dax_device *dax_dev); 62void set_dax_nomc(struct dax_device *dax_dev); 63void set_dax_synchronous(struct dax_device *dax_dev); 64size_t dax_recovery_write(struct dax_device *dax_dev, pgoff_t pgoff, 65 void *addr, size_t bytes, struct iov_iter *i); 66/* 67 * Check if given mapping is supported by the file / underlying device. 68 */ 69static inline bool daxdev_mapping_supported(const struct vm_area_desc *desc, 70 const struct inode *inode, 71 struct dax_device *dax_dev) 72{ 73 if (!vma_desc_test(desc, VMA_SYNC_BIT)) 74 return true; 75 if (!IS_DAX(inode)) 76 return false; 77 return dax_synchronous(dax_dev); 78} 79#else 80static inline void *dax_holder(struct dax_device *dax_dev) 81{ 82 return NULL; 83} 84static inline struct dax_device *alloc_dax(void *private, 85 const struct dax_operations *ops) 86{ 87 return ERR_PTR(-EOPNOTSUPP); 88} 89static inline void put_dax(struct dax_device *dax_dev) 90{ 91} 92static inline void kill_dax(struct dax_device *dax_dev) 93{ 94} 95static inline void dax_write_cache(struct dax_device *dax_dev, bool wc) 96{ 97} 98static inline bool dax_write_cache_enabled(struct dax_device *dax_dev) 99{ 100 return false; 101} 102static inline bool dax_synchronous(struct dax_device *dax_dev) 103{ 104 return true; 105} 106static inline void set_dax_nocache(struct dax_device *dax_dev) 107{ 108} 109static inline void set_dax_nomc(struct dax_device *dax_dev) 110{ 111} 112static inline void set_dax_synchronous(struct dax_device *dax_dev) 113{ 114} 115static inline bool daxdev_mapping_supported(const struct vm_area_desc *desc, 116 const struct inode *inode, 117 struct dax_device *dax_dev) 118{ 119 return !vma_desc_test(desc, VMA_SYNC_BIT); 120} 121static inline size_t dax_recovery_write(struct dax_device *dax_dev, 122 pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i) 123{ 124 return 0; 125} 126#endif 127 128struct writeback_control; 129#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX) 130int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk); 131void dax_remove_host(struct gendisk *disk); 132struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev, u64 *start_off, 133 void *holder, const struct dax_holder_operations *ops); 134#else 135static inline int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk) 136{ 137 return 0; 138} 139static inline void dax_remove_host(struct gendisk *disk) 140{ 141} 142static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev, 143 u64 *start_off, void *holder, 144 const struct dax_holder_operations *ops) 145{ 146 return NULL; 147} 148#endif /* CONFIG_BLOCK && CONFIG_FS_DAX */ 149 150#if IS_ENABLED(CONFIG_FS_DAX) 151void fs_put_dax(struct dax_device *dax_dev, void *holder); 152int fs_dax_get(struct dax_device *dax_dev, void *holder, 153 const struct dax_holder_operations *hops); 154int dax_writeback_mapping_range(struct address_space *mapping, 155 struct dax_device *dax_dev, struct writeback_control *wbc); 156int dax_folio_reset_order(struct folio *folio); 157 158struct page *dax_layout_busy_page(struct address_space *mapping); 159struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end); 160dax_entry_t dax_lock_folio(struct folio *folio); 161void dax_unlock_folio(struct folio *folio, dax_entry_t cookie); 162dax_entry_t dax_lock_mapping_entry(struct address_space *mapping, 163 unsigned long index, struct page **page); 164void dax_unlock_mapping_entry(struct address_space *mapping, 165 unsigned long index, dax_entry_t cookie); 166#else 167static inline void fs_put_dax(struct dax_device *dax_dev, void *holder) 168{ 169} 170 171static inline int fs_dax_get(struct dax_device *dax_dev, void *holder, 172 const struct dax_holder_operations *hops) 173{ 174 return -EOPNOTSUPP; 175} 176static inline struct page *dax_layout_busy_page(struct address_space *mapping) 177{ 178 return NULL; 179} 180 181static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages) 182{ 183 return NULL; 184} 185 186static inline int dax_writeback_mapping_range(struct address_space *mapping, 187 struct dax_device *dax_dev, struct writeback_control *wbc) 188{ 189 return -EOPNOTSUPP; 190} 191 192static inline dax_entry_t dax_lock_folio(struct folio *folio) 193{ 194 if (IS_DAX(folio->mapping->host)) 195 return ~0UL; 196 return 0; 197} 198 199static inline void dax_unlock_folio(struct folio *folio, dax_entry_t cookie) 200{ 201} 202 203static inline dax_entry_t dax_lock_mapping_entry(struct address_space *mapping, 204 unsigned long index, struct page **page) 205{ 206 return 0; 207} 208 209static inline void dax_unlock_mapping_entry(struct address_space *mapping, 210 unsigned long index, dax_entry_t cookie) 211{ 212} 213#endif 214 215int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, 216 const struct iomap_ops *ops); 217int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, 218 const struct iomap_ops *ops); 219int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, 220 const struct iomap_ops *ops); 221 222static inline bool dax_page_is_idle(struct page *page) 223{ 224 return page && page_ref_count(page) == 0; 225} 226 227#if IS_ENABLED(CONFIG_DAX) 228int dax_read_lock(void); 229void dax_read_unlock(int id); 230#else 231static inline int dax_read_lock(void) 232{ 233 return 0; 234} 235 236static inline void dax_read_unlock(int id) 237{ 238} 239#endif /* CONFIG_DAX */ 240 241#if !IS_ENABLED(CONFIG_FS_DAX) 242static inline int __must_check dax_break_layout(struct inode *inode, 243 loff_t start, loff_t end, void (cb)(struct inode *)) 244{ 245 return 0; 246} 247 248static inline void dax_break_layout_final(struct inode *inode) 249{ 250} 251#endif 252 253bool dax_alive(struct dax_device *dax_dev); 254void *dax_get_private(struct dax_device *dax_dev); 255int dax_set_ops(struct dax_device *dax_dev, const struct dax_operations *ops); 256long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages, 257 enum dax_access_mode mode, void **kaddr, unsigned long *pfn); 258size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, 259 size_t bytes, struct iov_iter *i); 260size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, 261 size_t bytes, struct iov_iter *i); 262int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, 263 size_t nr_pages); 264int dax_holder_notify_failure(struct dax_device *dax_dev, u64 off, u64 len, 265 int mf_flags); 266void dax_flush(struct dax_device *dax_dev, void *addr, size_t size); 267 268ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, 269 const struct iomap_ops *ops); 270vm_fault_t dax_iomap_fault(struct vm_fault *vmf, unsigned int order, 271 unsigned long *pfnp, int *errp, 272 const struct iomap_ops *ops); 273vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, 274 unsigned int order, unsigned long pfn); 275int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index); 276void dax_delete_mapping_range(struct address_space *mapping, 277 loff_t start, loff_t end); 278int dax_invalidate_mapping_entry_sync(struct address_space *mapping, 279 pgoff_t index); 280int __must_check dax_break_layout(struct inode *inode, loff_t start, 281 loff_t end, void (cb)(struct inode *)); 282static inline int __must_check dax_break_layout_inode(struct inode *inode, 283 void (cb)(struct inode *)) 284{ 285 return dax_break_layout(inode, 0, LLONG_MAX, cb); 286} 287void dax_break_layout_final(struct inode *inode); 288int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff, 289 struct inode *dest, loff_t destoff, 290 loff_t len, bool *is_same, 291 const struct iomap_ops *ops); 292int dax_remap_file_range_prep(struct file *file_in, loff_t pos_in, 293 struct file *file_out, loff_t pos_out, 294 loff_t *len, unsigned int remap_flags, 295 const struct iomap_ops *ops); 296static inline bool dax_mapping(struct address_space *mapping) 297{ 298 return mapping->host && IS_DAX(mapping->host); 299} 300 301/* 302 * Due to dax's memory and block duo personalities, hwpoison reporting 303 * takes into consideration which personality is presently visible. 304 * When dax acts like a block device, such as in block IO, an encounter of 305 * dax hwpoison is reported as -EIO. 306 * When dax acts like memory, such as in page fault, a detection of hwpoison 307 * is reported as -EHWPOISON which leads to VM_FAULT_HWPOISON. 308 */ 309static inline int dax_mem2blk_err(int err) 310{ 311 return (err == -EHWPOISON) ? -EIO : err; 312} 313 314#ifdef CONFIG_DEV_DAX_HMEM_DEVICES 315void hmem_register_resource(int target_nid, struct resource *r); 316#else 317static inline void hmem_register_resource(int target_nid, struct resource *r) 318{ 319} 320#endif 321 322typedef int (*walk_hmem_fn)(struct device *dev, int target_nid, 323 const struct resource *res); 324int walk_hmem_resources(struct device *dev, walk_hmem_fn fn); 325#endif