Hi Goldwyn, url: https://github.com/0day-ci/linux/commits/Goldwyn-Rodrigues/BTRFS-DIO-inode-locking-D_SYNC-fix/20200921-224649 base: https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next config: x86_64-randconfig-m001-20200920 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot Reported-by: Dan Carpenter New smatch warnings: fs/btrfs/file.c:2147 btrfs_file_write_iter() error: uninitialized symbol 'err'. Old smatch warnings: fs/btrfs/file.c:2902 btrfs_replace_file_extents() error: uninitialized symbol 'drop_end'. # https://github.com/0day-ci/linux/commit/2e4ab0a0ed53f87e6fe8f369c2bf5d809f455ac4 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Goldwyn-Rodrigues/BTRFS-DIO-inode-locking-D_SYNC-fix/20200921-224649 git checkout 2e4ab0a0ed53f87e6fe8f369c2bf5d809f455ac4 vim +/err +2147 fs/btrfs/file.c b30ac0fc4109701 Al Viro 2014-04-03 2066 static ssize_t btrfs_file_write_iter(struct kiocb *iocb, b30ac0fc4109701 Al Viro 2014-04-03 2067 struct iov_iter *from) d0215f3e5ebb580 Josef Bacik 2011-01-25 2068 { d0215f3e5ebb580 Josef Bacik 2011-01-25 2069 struct file *file = iocb->ki_filp; 496ad9aa8ef4480 Al Viro 2013-01-23 2070 struct inode *inode = file_inode(file); 0b246afa62b0cf5 Jeff Mahoney 2016-06-22 2071 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); d0215f3e5ebb580 Josef Bacik 2011-01-25 2072 struct btrfs_root *root = BTRFS_I(inode)->root; d0215f3e5ebb580 Josef Bacik 2011-01-25 2073 ssize_t num_written = 0; f50cb7aff964599 Omar Sandoval 2019-08-15 2074 const bool sync = iocb->ki_flags & IOCB_DSYNC; 3309dd04cbcd2cd Al Viro 2015-04-09 2075 ssize_t err; ^^^^^^^^^^^ This is never initialized. d0215f3e5ebb580 Josef Bacik 2011-01-25 2076 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2077 /* 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2078 * If BTRFS flips readonly due to some impossible error 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2079 * (fs_info->fs_state now has BTRFS_SUPER_FLAG_ERROR), 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2080 * although we have opened a file as writable, we have 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2081 * to stop this write operation to ensure FS consistency. 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2082 */ 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2083 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2084 return -EROFS; 1b4761d18914c44 Goldwyn Rodrigues 2020-09-21 2085 91f9943e1c7b663 Christoph Hellwig 2017-08-29 2086 if (!(iocb->ki_flags & IOCB_DIRECT) && 91f9943e1c7b663 Christoph Hellwig 2017-08-29 2087 (iocb->ki_flags & IOCB_NOWAIT)) 91f9943e1c7b663 Christoph Hellwig 2017-08-29 2088 return -EOPNOTSUPP; 91f9943e1c7b663 Christoph Hellwig 2017-08-29 2089 b812ce28796f746 Josef Bacik 2012-11-16 2090 if (sync) b812ce28796f746 Josef Bacik 2012-11-16 2091 atomic_inc(&BTRFS_I(inode)->sync_writers); b812ce28796f746 Josef Bacik 2012-11-16 2092 2ba48ce513c4e54 Al Viro 2015-04-09 2093 if (iocb->ki_flags & IOCB_DIRECT) { 09745ff88d93537 Josef Bacik 2020-09-03 2094 /* 09745ff88d93537 Josef Bacik 2020-09-03 2095 * 1. We must always clear IOCB_DSYNC in order to not deadlock 09745ff88d93537 Josef Bacik 2020-09-03 2096 * in iomap, as it calls generic_write_sync() in this case. 09745ff88d93537 Josef Bacik 2020-09-03 2097 * 2. If we are async, we can call iomap_dio_complete() either 09745ff88d93537 Josef Bacik 2020-09-03 2098 * in 09745ff88d93537 Josef Bacik 2020-09-03 2099 * 09745ff88d93537 Josef Bacik 2020-09-03 2100 * 2.1. A worker thread from the last bio completed. In this 09745ff88d93537 Josef Bacik 2020-09-03 2101 * case we need to mark the btrfs_dio_data that it is 09745ff88d93537 Josef Bacik 2020-09-03 2102 * async in order to call generic_write_sync() properly. 09745ff88d93537 Josef Bacik 2020-09-03 2103 * This is handled by setting BTRFS_DIO_SYNC_STUB in the 09745ff88d93537 Josef Bacik 2020-09-03 2104 * current->journal_info. 09745ff88d93537 Josef Bacik 2020-09-03 2105 * 2.2 The submitter context, because all IO completed 09745ff88d93537 Josef Bacik 2020-09-03 2106 * before we exited iomap_dio_rw(). In this case we can 09745ff88d93537 Josef Bacik 2020-09-03 2107 * just re-set the IOCB_DSYNC on the iocb and we'll do 09745ff88d93537 Josef Bacik 2020-09-03 2108 * the sync below. If our ->end_io() gets called and 09745ff88d93537 Josef Bacik 2020-09-03 2109 * current->journal_info is set, then we know we're in 09745ff88d93537 Josef Bacik 2020-09-03 2110 * our current context and we will clear 09745ff88d93537 Josef Bacik 2020-09-03 2111 * current->journal_info to indicate that we need to 09745ff88d93537 Josef Bacik 2020-09-03 2112 * sync below. 09745ff88d93537 Josef Bacik 2020-09-03 2113 */ 09745ff88d93537 Josef Bacik 2020-09-03 2114 if (sync) { 09745ff88d93537 Josef Bacik 2020-09-03 2115 ASSERT(current->journal_info == NULL); 09745ff88d93537 Josef Bacik 2020-09-03 2116 iocb->ki_flags &= ~IOCB_DSYNC; 09745ff88d93537 Josef Bacik 2020-09-03 2117 current->journal_info = BTRFS_DIO_SYNC_STUB; 09745ff88d93537 Josef Bacik 2020-09-03 2118 } d8a13486adc39bc Goldwyn Rodrigues 2020-09-21 2119 num_written = btrfs_direct_write(iocb, from); 09745ff88d93537 Josef Bacik 2020-09-03 2120 09745ff88d93537 Josef Bacik 2020-09-03 2121 /* 09745ff88d93537 Josef Bacik 2020-09-03 2122 * As stated above, we cleared journal_info, so we need to do 09745ff88d93537 Josef Bacik 2020-09-03 2123 * the sync ourselves. 09745ff88d93537 Josef Bacik 2020-09-03 2124 */ 09745ff88d93537 Josef Bacik 2020-09-03 2125 if (sync && current->journal_info == NULL) 09745ff88d93537 Josef Bacik 2020-09-03 2126 iocb->ki_flags |= IOCB_DSYNC; 09745ff88d93537 Josef Bacik 2020-09-03 2127 current->journal_info = NULL; d0215f3e5ebb580 Josef Bacik 2011-01-25 2128 } else { e4af400a9c5081e Goldwyn Rodrigues 2018-06-17 2129 num_written = btrfs_buffered_write(iocb, from); d0215f3e5ebb580 Josef Bacik 2011-01-25 2130 } d0215f3e5ebb580 Josef Bacik 2011-01-25 2131 5a3f23d515a2ebf Chris Mason 2009-03-31 2132 /* 6c760c072403f44 Josef Bacik 2012-11-09 2133 * We also have to set last_sub_trans to the current log transid, 6c760c072403f44 Josef Bacik 2012-11-09 2134 * otherwise subsequent syncs to a file that's been synced in this bb7ab3b92e46da0 Adam Buchbinder 2016-03-04 2135 * transaction will appear to have already occurred. 5a3f23d515a2ebf Chris Mason 2009-03-31 2136 */ 2f2ff0ee5e4303e Filipe Manana 2015-03-20 2137 spin_lock(&BTRFS_I(inode)->lock); 6c760c072403f44 Josef Bacik 2012-11-09 2138 BTRFS_I(inode)->last_sub_trans = root->log_transid; 2f2ff0ee5e4303e Filipe Manana 2015-03-20 2139 spin_unlock(&BTRFS_I(inode)->lock); e259221763a4040 Christoph Hellwig 2016-04-07 2140 if (num_written > 0) e259221763a4040 Christoph Hellwig 2016-04-07 2141 num_written = generic_write_sync(iocb, num_written); 0a3404dcff29a75 Miao Xie 2013-01-28 2142 b812ce28796f746 Josef Bacik 2012-11-16 2143 if (sync) b812ce28796f746 Josef Bacik 2012-11-16 2144 atomic_dec(&BTRFS_I(inode)->sync_writers); 81be057069d906f Goldwyn Rodrigues 2020-09-21 2145 39279cc3d2704cf Chris Mason 2007-06-12 2146 current->backing_dev_info = NULL; 39279cc3d2704cf Chris Mason 2007-06-12 @2147 return num_written ? num_written : err; 39279cc3d2704cf Chris Mason 2007-06-12 2148 } --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org