]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ext4: return to starting transaction in ext4_dax_huge_fault()
authorJan Kara <jack@suse.cz>
Fri, 12 May 2017 22:46:54 +0000 (15:46 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 12 May 2017 22:57:16 +0000 (15:57 -0700)
DAX will return to locking exceptional entry before mapping blocks for a
page fault to fix possible races with concurrent writes.  To avoid lock
inversion between exceptional entry lock and transaction start, start
the transaction already in ext4_dax_huge_fault().

Fixes: 724fa8d602970d4e05b4c04731e1b5812eecc65c
Link: http://lkml.kernel.org/r/20170510085419.27601-4-jack@suse.cz
Signed-off-by: Jan Kara <jack@suse.cz>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ext4/file.c

index cefa9835f275d9b062ae9b13765ea743edb53f64..831fd6beebf01bfa65c1c4a3ae505ed84bd35526 100644 (file)
@@ -257,6 +257,7 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf,
                enum page_entry_size pe_size)
 {
        int result;
+       handle_t *handle = NULL;
        struct inode *inode = file_inode(vmf->vma->vm_file);
        struct super_block *sb = inode->i_sb;
        bool write = vmf->flags & FAULT_FLAG_WRITE;
@@ -264,12 +265,24 @@ static int ext4_dax_huge_fault(struct vm_fault *vmf,
        if (write) {
                sb_start_pagefault(sb);
                file_update_time(vmf->vma->vm_file);
+               down_read(&EXT4_I(inode)->i_mmap_sem);
+               handle = ext4_journal_start_sb(sb, EXT4_HT_WRITE_PAGE,
+                                              EXT4_DATA_TRANS_BLOCKS(sb));
+       } else {
+               down_read(&EXT4_I(inode)->i_mmap_sem);
        }
-       down_read(&EXT4_I(inode)->i_mmap_sem);
-       result = dax_iomap_fault(vmf, pe_size, &ext4_iomap_ops);
-       up_read(&EXT4_I(inode)->i_mmap_sem);
-       if (write)
+       if (!IS_ERR(handle))
+               result = dax_iomap_fault(vmf, pe_size, &ext4_iomap_ops);
+       else
+               result = VM_FAULT_SIGBUS;
+       if (write) {
+               if (!IS_ERR(handle))
+                       ext4_journal_stop(handle);
+               up_read(&EXT4_I(inode)->i_mmap_sem);
                sb_end_pagefault(sb);
+       } else {
+               up_read(&EXT4_I(inode)->i_mmap_sem);
+       }
 
        return result;
 }