Message ID | 4481393496a9dfe99c9432193407ebdaa27d0753.1583789410.git.osandov@fb.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: read repair/direct I/O improvements | expand |
On 3/9/20 5:32 PM, Omar Sandoval wrote: > From: Omar Sandoval <osandov@fb.com> > > If we submit orig_bio in btrfs_submit_direct_hook(), we never increment > pending_bios. Then, if btrfs_submit_dio_bio() fails, we decrement > pending_bios to -1, and we never complete orig_bio. Fix it by > initializing pending_bios to 1 instead of incrementing later. > > Fixing this exposes another bug: we put orig_bio prematurely and then > put it again from end_io. Fix it by not putting orig_bio. > > After this change, pending_bios is really more of a reference count, but > I'll leave that cleanup separate to keep the fix small. > > Fixes: e65e15355429 ("btrfs: fix panic caused by direct IO") > Signed-off-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Thanks, Josef
On 9.03.20 г. 23:32 ч., Omar Sandoval wrote: > From: Omar Sandoval <osandov@fb.com> > > If we submit orig_bio in btrfs_submit_direct_hook(), we never increment > pending_bios. Then, if btrfs_submit_dio_bio() fails, we decrement > pending_bios to -1, and we never complete orig_bio. Fix it by > initializing pending_bios to 1 instead of incrementing later. nit: I'd rephrase this paragraph to put the emphasis on when this could happen, which is when the write falls entirely within a chunk's stripe (i.e doesn't span 64k region in case of having a block group with a profile different than SINGLE) or doesn't span a chunk in case of a profile different than SINGLE. > > Fixing this exposes another bug: we put orig_bio prematurely and then > put it again from end_io. Fix it by not putting orig_bio. > > After this change, pending_bios is really more of a reference count, but > I'll leave that cleanup separate to keep the fix small. > > Fixes: e65e15355429 ("btrfs: fix panic caused by direct IO") > Signed-off-by: Omar Sandoval <osandov@fb.com> The changes look good, I just wonder why didn't this trip earlier... Reviewed-by: Nikolay Borisov <nborisov@suse.com>
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8a3bc19d83ff..d48a2010f24a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7948,7 +7948,6 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip) /* bio split */ ASSERT(geom.len <= INT_MAX); - atomic_inc(&dip->pending_bios); do { clone_len = min_t(int, submit_len, geom.len); @@ -7998,7 +7997,8 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip) if (!status) return 0; - bio_put(bio); + if (bio != orig_bio) + bio_put(bio); out_err: dip->errors = 1; /* @@ -8039,7 +8039,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode, bio->bi_private = dip; dip->orig_bio = bio; dip->dio_bio = dio_bio; - atomic_set(&dip->pending_bios, 0); + atomic_set(&dip->pending_bios, 1); io_bio = btrfs_io_bio(bio); io_bio->logical = file_offset;