On Mon, Sep 21, 2020 at 09:43:42AM -0500, Goldwyn Rodrigues wrote: > From: Goldwyn Rodrigues <rgoldwyn@xxxxxxxx> > > iomap complete routine can deadlock with btrfs_fallocate because of the > call to generic_write_sync(). > > P0 P1 > inode_lock() fallocate(FALLOC_FL_ZERO_RANGE) > __iomap_dio_rw() inode_lock() > <block> > <submits IO> > <completes IO> > inode_unlock() > <gets inode_lock()> > inode_dio_wait() > iomap_dio_complete() > generic_write_sync() > btrfs_file_fsync() > inode_lock() > <deadlock> > > inode_dio_end() is used to notify the end of DIO data in order > to synchronize with truncate. Call inode_dio_end() before calling > generic_write_sync(), so filesystems can lock i_rwsem during a sync. Looks good: Reviewed-by: Christoph Hellwig <hch@xxxxxx> You might want to mention in the commit log that this matches the sequence in the old fs/direct-io.c implementation.