1 /* SPDX-License-Identifier: GPL-2.0 */
7 #include <linux/radix-tree.h>
9 typedef unsigned long dax_entry_t;
17 enum dax_access_mode {
22 struct dax_operations {
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.
28 long (*direct_access)(struct dax_device *, pgoff_t, long,
29 enum dax_access_mode, void **, pfn_t *);
31 * Validate whether this device is usable as an fsdax backing
34 bool (*dax_supported)(struct dax_device *, struct block_device *, int,
36 /* zero_page_range: required operation. Zero page range */
37 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
39 * recovery_write: recover a poisoned range by DAX device driver
40 * capable of clearing poison.
42 size_t (*recovery_write)(struct dax_device *dax_dev, pgoff_t pgoff,
43 void *addr, size_t bytes, struct iov_iter *iter);
46 struct dax_holder_operations {
48 * notify_failure - notify memory failure into inner holder device
49 * @dax_dev: the dax device which contains the holder
50 * @offset: offset on this dax device where memory failure occurs
51 * @len: length of this memory failure event
52 * @flags: action flags for memory failure handler
54 int (*notify_failure)(struct dax_device *dax_dev, u64 offset,
55 u64 len, int mf_flags);
58 #if IS_ENABLED(CONFIG_DAX)
59 struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
60 void *dax_holder(struct dax_device *dax_dev);
61 void put_dax(struct dax_device *dax_dev);
62 void kill_dax(struct dax_device *dax_dev);
63 void dax_write_cache(struct dax_device *dax_dev, bool wc);
64 bool dax_write_cache_enabled(struct dax_device *dax_dev);
65 bool dax_synchronous(struct dax_device *dax_dev);
66 void set_dax_synchronous(struct dax_device *dax_dev);
67 size_t dax_recovery_write(struct dax_device *dax_dev, pgoff_t pgoff,
68 void *addr, size_t bytes, struct iov_iter *i);
70 * Check if given mapping is supported by the file / underlying device.
72 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
73 struct dax_device *dax_dev)
75 if (!(vma->vm_flags & VM_SYNC))
77 if (!IS_DAX(file_inode(vma->vm_file)))
79 return dax_synchronous(dax_dev);
82 static inline void *dax_holder(struct dax_device *dax_dev)
86 static inline struct dax_device *alloc_dax(void *private,
87 const struct dax_operations *ops)
90 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
91 * NULL is an error or expected.
95 static inline void put_dax(struct dax_device *dax_dev)
98 static inline void kill_dax(struct dax_device *dax_dev)
101 static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
104 static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
108 static inline bool dax_synchronous(struct dax_device *dax_dev)
112 static inline void set_dax_synchronous(struct dax_device *dax_dev)
115 static inline bool daxdev_mapping_supported(struct vm_area_struct *vma,
116 struct dax_device *dax_dev)
118 return !(vma->vm_flags & VM_SYNC);
120 static inline size_t dax_recovery_write(struct dax_device *dax_dev,
121 pgoff_t pgoff, void *addr, size_t bytes, struct iov_iter *i)
127 void set_dax_nocache(struct dax_device *dax_dev);
128 void set_dax_nomc(struct dax_device *dax_dev);
130 struct writeback_control;
131 #if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX)
132 int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk);
133 void dax_remove_host(struct gendisk *disk);
134 struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev, u64 *start_off,
135 void *holder, const struct dax_holder_operations *ops);
136 void fs_put_dax(struct dax_device *dax_dev, void *holder);
138 static inline int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk)
142 static inline void dax_remove_host(struct gendisk *disk)
145 static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev,
146 u64 *start_off, void *holder,
147 const struct dax_holder_operations *ops)
151 static inline void fs_put_dax(struct dax_device *dax_dev, void *holder)
154 #endif /* CONFIG_BLOCK && CONFIG_FS_DAX */
156 #if IS_ENABLED(CONFIG_FS_DAX)
157 int dax_writeback_mapping_range(struct address_space *mapping,
158 struct dax_device *dax_dev, struct writeback_control *wbc);
160 struct page *dax_layout_busy_page(struct address_space *mapping);
161 struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
162 dax_entry_t dax_lock_page(struct page *page);
163 void dax_unlock_page(struct page *page, dax_entry_t cookie);
164 dax_entry_t dax_lock_mapping_entry(struct address_space *mapping,
165 unsigned long index, struct page **page);
166 void dax_unlock_mapping_entry(struct address_space *mapping,
167 unsigned long index, dax_entry_t cookie);
169 static inline struct page *dax_layout_busy_page(struct address_space *mapping)
174 static inline struct page *dax_layout_busy_page_range(struct address_space *mapping, pgoff_t start, pgoff_t nr_pages)
179 static inline int dax_writeback_mapping_range(struct address_space *mapping,
180 struct dax_device *dax_dev, struct writeback_control *wbc)
185 static inline dax_entry_t dax_lock_page(struct page *page)
187 if (IS_DAX(page->mapping->host))
192 static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
196 static inline dax_entry_t dax_lock_mapping_entry(struct address_space *mapping,
197 unsigned long index, struct page **page)
202 static inline void dax_unlock_mapping_entry(struct address_space *mapping,
203 unsigned long index, dax_entry_t cookie)
208 int dax_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
209 const struct iomap_ops *ops);
210 int dax_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
211 const struct iomap_ops *ops);
213 #if IS_ENABLED(CONFIG_DAX)
214 int dax_read_lock(void);
215 void dax_read_unlock(int id);
217 static inline int dax_read_lock(void)
222 static inline void dax_read_unlock(int id)
225 #endif /* CONFIG_DAX */
226 bool dax_alive(struct dax_device *dax_dev);
227 void *dax_get_private(struct dax_device *dax_dev);
228 long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
229 enum dax_access_mode mode, void **kaddr, pfn_t *pfn);
230 size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
231 size_t bytes, struct iov_iter *i);
232 size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
233 size_t bytes, struct iov_iter *i);
234 int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
236 int dax_holder_notify_failure(struct dax_device *dax_dev, u64 off, u64 len,
238 void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
240 ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
241 const struct iomap_ops *ops);
242 vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
243 pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
244 vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
245 enum page_entry_size pe_size, pfn_t pfn);
246 int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
247 int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
249 int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
250 struct inode *dest, loff_t destoff,
251 loff_t len, bool *is_same,
252 const struct iomap_ops *ops);
253 int dax_remap_file_range_prep(struct file *file_in, loff_t pos_in,
254 struct file *file_out, loff_t pos_out,
255 loff_t *len, unsigned int remap_flags,
256 const struct iomap_ops *ops);
257 static inline bool dax_mapping(struct address_space *mapping)
259 return mapping->host && IS_DAX(mapping->host);
262 #ifdef CONFIG_DEV_DAX_HMEM_DEVICES
263 void hmem_register_device(int target_nid, struct resource *r);
265 static inline void hmem_register_device(int target_nid, struct resource *r)