0001
0002 #ifndef _LINUX_DAX_H
0003 #define _LINUX_DAX_H
0004
0005 #include <linux/fs.h>
0006 #include <linux/mm.h>
0007 #include <linux/radix-tree.h>
0008
0009 typedef unsigned long dax_entry_t;
0010
0011 struct dax_device;
0012 struct gendisk;
0013 struct iomap_ops;
0014 struct iomap_iter;
0015 struct iomap;
0016
0017 enum dax_access_mode {
0018 DAX_ACCESS,
0019 DAX_RECOVERY_WRITE,
0020 };
0021
0022 struct dax_operations {
0023
0024
0025
0026
0027
0028 long (*direct_access)(struct dax_device *, pgoff_t, long,
0029 enum dax_access_mode, void **, pfn_t *);
0030
0031
0032
0033
0034 bool (*dax_supported)(struct dax_device *, struct block_device *, int,
0035 sector_t, sector_t);
0036
0037 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
0038
0039
0040
0041
0042 size_t (*recovery_write)(struct dax_device *dax_dev, pgoff_t pgoff,
0043 void *addr, size_t bytes, struct iov_iter *iter);
0044 };
0045
0046 struct dax_holder_operations {
0047
0048
0049
0050
0051
0052
0053
0054 int (*notify_failure)(struct dax_device *dax_dev, u64 offset,
0055 u64 len, int mf_flags);
0056 };
0057
0058 #if IS_ENABLED(CONFIG_DAX)
0059 struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
0060 void *dax_holder(struct dax_device *dax_dev);
0061 void put_dax(struct dax_device *dax_dev);
0062 void kill_dax(struct dax_device *dax_dev);
0063 void dax_write_cache(struct dax_device *dax_dev, bool wc);
0064 bool dax_write_cache_enabled(struct dax_device *dax_dev);
0065 bool dax_synchronous(struct dax_device *dax_dev);
0066 void set_dax_synchronous(struct dax_device *dax_dev);
0067 size_t dax_recovery_write(struct dax_device *dax_dev, pgoff_t pgoff,
0068 void *addr, size_t bytes, struct iov_iter *i);
0069
0070
0071
0072 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
0073 struct dax_device *dax_dev)
0074 {
0075 if (!(vma->vm_flags & VM_SYNC))
0076 return true;
0077 if (!IS_DAX(file_inode(vma->vm_file)))
0078 return false;
0079 return dax_synchronous(dax_dev);
0080 }
0081 #else
0082 static inline void *dax_holder(struct dax_device *dax_dev)
0083 {
0084 return NULL;
0085 }
0086 static inline struct dax_device *alloc_dax(void *private,
0087 const struct dax_operations *ops)
0088 {
0089
0090
0091
0092
0093 return NULL;
0094 }
0095 static inline void put_dax(struct dax_device *dax_dev)
0096 {
0097 }
0098 static inline void kill_dax(struct dax_device *dax_dev)
0099 {
0100 }
0101 static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
0102 {
0103 }
0104 static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
0105 {
0106 return false;
0107 }
0108 static inline bool dax_synchronous(struct dax_device *dax_dev)
0109 {
0110 return true;
0111 }
0112 static inline void set_dax_synchronous(struct dax_device *dax_dev)
0113 {
0114 }
0115 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
0116 struct dax_device *dax_dev)
0117 {
0118 return !(vma->vm_flags & VM_SYNC);
0119 }
0120 static inline size_t dax_recovery_write(struct dax_device *dax_dev,
0121 pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i)
0122 {
0123 return 0;
0124 }
0125 #endif
0126
0127 void set_dax_nocache(struct dax_device *dax_dev);
0128 void set_dax_nomc(struct dax_device *dax_dev);
0129
0130 struct writeback_control;
0131 #if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
0132 int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk);
0133 void dax_remove_host(struct gendisk *disk);
0134 struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev, u64 *start_off,
0135 void *holder, const struct dax_holder_operations *ops);
0136 void fs_put_dax(struct dax_device *dax_dev, void *holder);
0137 #else
0138 static inline int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk)
0139 {
0140 return 0;
0141 }
0142 static inline void dax_remove_host(struct gendisk *disk)
0143 {
0144 }
0145 static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
0146 u64 *start_off, void *holder,
0147 const struct dax_holder_operations *ops)
0148 {
0149 return NULL;
0150 }
0151 static inline void fs_put_dax(struct dax_device *dax_dev, void *holder)
0152 {
0153 }
0154 #endif
0155
0156 #if IS_ENABLED(CONFIG_FS_DAX)
0157 int dax_writeback_mapping_range(struct address_space *mapping,
0158 struct dax_device *dax_dev, struct writeback_control *wbc);
0159
0160 struct page *dax_layout_busy_page(struct address_space *mapping);
0161 struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
0162 dax_entry_t dax_lock_page(struct page *page);
0163 void dax_unlock_page(struct page *page, dax_entry_t cookie);
0164 dax_entry_t dax_lock_mapping_entry(struct address_space *mapping,
0165 unsigned long index, struct page **page);
0166 void dax_unlock_mapping_entry(struct address_space *mapping,
0167 unsigned long index, dax_entry_t cookie);
0168 #else
0169 static inline struct page *dax_layout_busy_page(struct address_space *mapping)
0170 {
0171 return NULL;
0172 }
0173
0174 static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages)
0175 {
0176 return NULL;
0177 }
0178
0179 static inline int dax_writeback_mapping_range(struct address_space *mapping,
0180 struct dax_device *dax_dev, struct writeback_control *wbc)
0181 {
0182 return -EOPNOTSUPP;
0183 }
0184
0185 static inline dax_entry_t dax_lock_page(struct page *page)
0186 {
0187 if (IS_DAX(page->mapping->host))
0188 return ~0UL;
0189 return 0;
0190 }
0191
0192 static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
0193 {
0194 }
0195
0196 static inline dax_entry_t dax_lock_mapping_entry(struct address_space *mapping,
0197 unsigned long index, struct page **page)
0198 {
0199 return 0;
0200 }
0201
0202 static inline void dax_unlock_mapping_entry(struct address_space *mapping,
0203 unsigned long index, dax_entry_t cookie)
0204 {
0205 }
0206 #endif
0207
0208 int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
0209 const struct iomap_ops *ops);
0210 int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
0211 const struct iomap_ops *ops);
0212
0213 #if IS_ENABLED(CONFIG_DAX)
0214 int dax_read_lock(void);
0215 void dax_read_unlock(int id);
0216 #else
0217 static inline int dax_read_lock(void)
0218 {
0219 return 0;
0220 }
0221
0222 static inline void dax_read_unlock(int id)
0223 {
0224 }
0225 #endif
0226 bool dax_alive(struct dax_device *dax_dev);
0227 void *dax_get_private(struct dax_device *dax_dev);
0228 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
0229 enum dax_access_mode mode, void **kaddr, pfn_t *pfn);
0230 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
0231 size_t bytes, struct iov_iter *i);
0232 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
0233 size_t bytes, struct iov_iter *i);
0234 int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
0235 size_t nr_pages);
0236 int dax_holder_notify_failure(struct dax_device *dax_dev, u64 off, u64 len,
0237 int mf_flags);
0238 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
0239
0240 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
0241 const struct iomap_ops *ops);
0242 vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
0243 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
0244 vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
0245 enum page_entry_size pe_size, pfn_t pfn);
0246 int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
0247 int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
0248 pgoff_t index);
0249 int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
0250 struct inode *dest, loff_t destoff,
0251 loff_t len, bool *is_same,
0252 const struct iomap_ops *ops);
0253 int dax_remap_file_range_prep(struct file *file_in, loff_t pos_in,
0254 struct file *file_out, loff_t pos_out,
0255 loff_t *len, unsigned int remap_flags,
0256 const struct iomap_ops *ops);
0257 static inline bool dax_mapping(struct address_space *mapping)
0258 {
0259 return mapping->host && IS_DAX(mapping->host);
0260 }
0261
0262 #ifdef CONFIG_DEV_DAX_HMEM_DEVICES
0263 void hmem_register_device(int target_nid, struct resource *r);
0264 #else
0265 static inline void hmem_register_device(int target_nid, struct resource *r)
0266 {
0267 }
0268 #endif
0269
0270 #endif