@@ -1980,8 +1980,24 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
goto out;
}
+static vm_fault_t btrfs_fault(struct vm_fault *vmf)
+{
+ struct extent_state *cached_state = NULL;
+ struct inode *inode = file_inode(vmf->vma->vm_file);
+ struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
+ u64 page_start = vmf->pgoff;
+ u64 page_end = page_start + PAGE_SIZE - 1;
+ vm_fault_t ret;
+
+ lock_extent(io_tree, page_start, page_end, &cached_state);
+ ret = filemap_fault(vmf);
+ unlock_extent(io_tree, page_start, page_end, &cached_state);
+
+ return ret;
+}
+
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,
};
@@ -8530,7 +8530,6 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
struct page *page = vmf->page;
struct inode *inode = file_inode(vmf->vma->vm_file);
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
- struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
struct btrfs_ordered_extent *ordered;
struct extent_state *cached_state = NULL;
struct extent_changeset *data_reserved = NULL;
@@ -8585,11 +8584,9 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
}
wait_on_page_writeback(page);
- lock_extent(io_tree, page_start, page_end, &cached_state);
ret2 = set_page_extent_mapped(page);
if (ret2 < 0) {
ret = vmf_error(ret2);
- unlock_extent(io_tree, page_start, page_end, &cached_state);
goto out_unlock;
}
@@ -8600,7 +8597,6 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
ordered = btrfs_lookup_ordered_range(BTRFS_I(inode), page_start,
PAGE_SIZE);
if (ordered) {
- unlock_extent(io_tree, page_start, page_end, &cached_state);
unlock_page(page);
up_read(&BTRFS_I(inode)->i_mmap_lock);
btrfs_start_ordered_extent(ordered, 1);
@@ -8633,7 +8629,6 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
ret2 = btrfs_set_extent_delalloc(BTRFS_I(inode), page_start, end, 0,
&cached_state);
if (ret2) {
- unlock_extent(io_tree, page_start, page_end, &cached_state);
ret = VM_FAULT_SIGBUS;
goto out_unlock;
}
@@ -8653,7 +8648,6 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
btrfs_set_inode_last_sub_trans(BTRFS_I(inode));
- unlock_extent(io_tree, page_start, page_end, &cached_state);
up_read(&BTRFS_I(inode)->i_mmap_lock);
btrfs_delalloc_release_extents(BTRFS_I(inode), PAGE_SIZE);
As a part of locking extents before pages, lock entire memfault region while servicing faults. Remove extent locking from page_mkwrite(), since it is part of the fault. Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> --- fs/btrfs/file.c | 18 +++++++++++++++++- fs/btrfs/inode.c | 6 ------ 2 files changed, 17 insertions(+), 7 deletions(-)