Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: handle layout changes to pinned DAX mappings

Follow the lead of xfs_break_dax_layouts() and add synchronization between
operations in ext4 which remove blocks from an inode (hole punch, truncate
down, etc.) and pages which are pinned due to DAX DMA operations.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>

authored by

Ross Zwisler and committed by
Theodore Ts'o
430657b6 cdbf8897

+68
+1
fs/ext4/ext4.h
··· 2459 2459 extern int ext4_inode_attach_jinode(struct inode *inode); 2460 2460 extern int ext4_can_truncate(struct inode *inode); 2461 2461 extern int ext4_truncate(struct inode *); 2462 + extern int ext4_break_layouts(struct inode *); 2462 2463 extern int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length); 2463 2464 extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks); 2464 2465 extern void ext4_set_inode_flags(struct inode *);
+17
fs/ext4/extents.c
··· 4826 4826 * released from page cache. 4827 4827 */ 4828 4828 down_write(&EXT4_I(inode)->i_mmap_sem); 4829 + 4830 + ret = ext4_break_layouts(inode); 4831 + if (ret) { 4832 + up_write(&EXT4_I(inode)->i_mmap_sem); 4833 + goto out_mutex; 4834 + } 4835 + 4829 4836 ret = ext4_update_disksize_before_punch(inode, offset, len); 4830 4837 if (ret) { 4831 4838 up_write(&EXT4_I(inode)->i_mmap_sem); ··· 5506 5499 * page cache. 5507 5500 */ 5508 5501 down_write(&EXT4_I(inode)->i_mmap_sem); 5502 + 5503 + ret = ext4_break_layouts(inode); 5504 + if (ret) 5505 + goto out_mmap; 5506 + 5509 5507 /* 5510 5508 * Need to round down offset to be aligned with page size boundary 5511 5509 * for page size > block size. ··· 5659 5647 * page cache. 5660 5648 */ 5661 5649 down_write(&EXT4_I(inode)->i_mmap_sem); 5650 + 5651 + ret = ext4_break_layouts(inode); 5652 + if (ret) 5653 + goto out_mmap; 5654 + 5662 5655 /* 5663 5656 * Need to round down to align start offset to page size boundary 5664 5657 * for page size > block size.
+46
fs/ext4/inode.c
··· 4191 4191 return 0; 4192 4192 } 4193 4193 4194 + static void ext4_wait_dax_page(struct ext4_inode_info *ei, bool *did_unlock) 4195 + { 4196 + *did_unlock = true; 4197 + up_write(&ei->i_mmap_sem); 4198 + schedule(); 4199 + down_write(&ei->i_mmap_sem); 4200 + } 4201 + 4202 + int ext4_break_layouts(struct inode *inode) 4203 + { 4204 + struct ext4_inode_info *ei = EXT4_I(inode); 4205 + struct page *page; 4206 + bool retry; 4207 + int error; 4208 + 4209 + if (WARN_ON_ONCE(!rwsem_is_locked(&ei->i_mmap_sem))) 4210 + return -EINVAL; 4211 + 4212 + do { 4213 + retry = false; 4214 + page = dax_layout_busy_page(inode->i_mapping); 4215 + if (!page) 4216 + return 0; 4217 + 4218 + error = ___wait_var_event(&page->_refcount, 4219 + atomic_read(&page->_refcount) == 1, 4220 + TASK_INTERRUPTIBLE, 0, 0, 4221 + ext4_wait_dax_page(ei, &retry)); 4222 + } while (error == 0 && retry); 4223 + 4224 + return error; 4225 + } 4226 + 4194 4227 /* 4195 4228 * ext4_punch_hole: punches a hole in a file by releasing the blocks 4196 4229 * associated with the given offset and length ··· 4297 4264 * page cache. 4298 4265 */ 4299 4266 down_write(&EXT4_I(inode)->i_mmap_sem); 4267 + 4268 + ret = ext4_break_layouts(inode); 4269 + if (ret) 4270 + goto out_dio; 4271 + 4300 4272 first_block_offset = round_up(offset, sb->s_blocksize); 4301 4273 last_block_offset = round_down((offset + length), sb->s_blocksize) - 1; 4302 4274 ··· 5591 5553 ext4_wait_for_tail_page_commit(inode); 5592 5554 } 5593 5555 down_write(&EXT4_I(inode)->i_mmap_sem); 5556 + 5557 + rc = ext4_break_layouts(inode); 5558 + if (rc) { 5559 + up_write(&EXT4_I(inode)->i_mmap_sem); 5560 + error = rc; 5561 + goto err_out; 5562 + } 5563 + 5594 5564 /* 5595 5565 * Truncate pagecache after we've waited for commit 5596 5566 * in data=journal mode to make pages freeable.
+4
fs/ext4/truncate.h
··· 11 11 */ 12 12 static inline void ext4_truncate_failed_write(struct inode *inode) 13 13 { 14 + /* 15 + * We don't need to call ext4_break_layouts() because the blocks we 16 + * are truncating were never visible to userspace. 17 + */ 14 18 down_write(&EXT4_I(inode)->i_mmap_sem); 15 19 truncate_inode_pages(inode->i_mapping, inode->i_size); 16 20 ext4_truncate(inode);