@@ -3694,6 +3694,7 @@ int btree_readahead_hook(struct extent_buffer *eb, int err);
/* dax.c */
ssize_t btrfs_file_dax_read(struct kiocb *iocb, struct iov_iter *to);
ssize_t btrfs_file_dax_write(struct kiocb *iocb, struct iov_iter *from);
+vm_fault_t btrfs_dax_fault(struct vm_fault *vmf);
#endif /* CONFIG_FS_DAX */
static inline int is_fstree(u64 rootid)
@@ -190,5 +190,48 @@ ssize_t btrfs_file_dax_write(struct kiocb *iocb, struct iov_iter *from)
count - done, true);
extent_changeset_free(data_reserved);
return done ? done : ret;
+}
+
+/* As copied from dax_iomap_pte_fault() */
+vm_fault_t btrfs_dax_fault(struct vm_fault *vmf)
+{
+ pfn_t pfn;
+ struct address_space *mapping = vmf->vma->vm_file->f_mapping;
+ XA_STATE(xas, &mapping->i_pages, vmf->pgoff);
+ struct inode *inode = mapping->host;
+ loff_t pos = (loff_t)vmf->pgoff << PAGE_SHIFT;
+ void *entry = NULL;
+ vm_fault_t ret = 0;
+
+ if (pos > i_size_read(inode)) {
+ ret = VM_FAULT_SIGBUS;
+ goto out;
+ }
+ entry = grab_mapping_entry(&xas, mapping, 0);
+ if (IS_ERR(entry)) {
+ ret = dax_fault_return(PTR_ERR(entry));
+ goto out;
+ }
+
+ if (!vmf->cow_page) {
+ sector_t sector;
+ struct extent_map *em;
+ em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, pos, PAGE_SIZE, 0);
+ if (em->block_start == EXTENT_MAP_HOLE) {
+ ret = dax_load_hole(&xas, mapping, entry, vmf);
+ goto out;
+ }
+ sector = ((get_start_sect(em->bdev) << 9) +
+ (em->block_start + (pos - em->start))) >> 9;
+ ret = dax_pfn(fs_dax_get_by_bdev(em->bdev), em->bdev, sector, PAGE_SIZE, &pfn);
+ if (ret)
+ goto out;
+ dax_insert_entry(&xas, mapping, vmf, entry, pfn, 0, false);
+ ret = vmf_insert_mixed(vmf->vma, vmf->address, pfn);
+ }
+out:
+ if (entry)
+ dax_unlock_entry(&xas, entry);
+ return ret;
}
@@ -2227,8 +2227,18 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
return ret > 0 ? -EIO : ret;
}
+static vm_fault_t btrfs_fault(struct vm_fault *vmf)
+{
+ struct inode *inode = vmf->vma->vm_file->f_mapping->host;
+#ifdef CONFIG_FS_DAX
+ if (IS_DAX(inode))
+ return btrfs_dax_fault(vmf);
+#endif
+ return filemap_fault(vmf);
+}
+
static const struct vm_operations_struct btrfs_file_vm_ops = {
- .fault = filemap_fault,
+ .fault = btrfs_fault,
.map_pages = filemap_map_pages,
.page_mkwrite = btrfs_page_mkwrite,
};