Commit b19c98f
btrfs: fix race between balance and cancel/pause
Syzbot reported a panic that looks like this:
assertion failed: fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED, in fs/btrfs/ioctl.c:465
------------[ cut here ]------------
kernel BUG at fs/btrfs/messages.c:259!
RIP: 0010:btrfs_assertfail+0x2c/0x30 fs/btrfs/messages.c:259
Call Trace:
<TASK>
btrfs_exclop_balance fs/btrfs/ioctl.c:465 [inline]
btrfs_ioctl_balance fs/btrfs/ioctl.c:3564 [inline]
btrfs_ioctl+0x531e/0x5b30 fs/btrfs/ioctl.c:4632
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:870 [inline]
__se_sys_ioctl fs/ioctl.c:856 [inline]
__x64_sys_ioctl+0x197/0x210 fs/ioctl.c:856
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
The reproducer is running a balance and a cancel or pause in parallel.
The way balance finishes is a bit wonky, if we were paused we need to
save the balance_ctl in the fs_info, but clear it otherwise and cleanup.
However we rely on the return values being specific errors, or having a
cancel request or no pause request. If balance completes and returns 0,
but we have a pause or cancel request we won't do the appropriate
cleanup, and then the next time we try to start a balance we'll trip
this ASSERT.
The error handling is just wrong here, we always want to clean up,
unless we got -ECANCELLED and we set the appropriate pause flag in the
exclusive op. With this patch the reproducer ran for an hour without
tripping, previously it would trip in less than a few minutes.
Reported-by: syzbot+c0f3acf145cb465426d5@syzkaller.appspotmail.com
CC: stable@vger.kernel.org # 6.1+
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>1 parent 8a4a0b2 commit b19c98f
1 file changed
Lines changed: 4 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4081 | 4081 | | |
4082 | 4082 | | |
4083 | 4083 | | |
4084 | | - | |
4085 | | - | |
4086 | | - | |
4087 | | - | |
4088 | | - | |
4089 | | - | |
4090 | | - | |
4091 | | - | |
4092 | 4084 | | |
4093 | 4085 | | |
4094 | 4086 | | |
| |||
4278 | 4270 | | |
4279 | 4271 | | |
4280 | 4272 | | |
| 4273 | + | |
4281 | 4274 | | |
4282 | 4275 | | |
4283 | 4276 | | |
| |||
4408 | 4401 | | |
4409 | 4402 | | |
4410 | 4403 | | |
| 4404 | + | |
4411 | 4405 | | |
4412 | 4406 | | |
4413 | 4407 | | |
| |||
4436 | 4430 | | |
4437 | 4431 | | |
4438 | 4432 | | |
4439 | | - | |
4440 | | - | |
| 4433 | + | |
| 4434 | + | |
4441 | 4435 | | |
4442 | 4436 | | |
4443 | 4437 | | |
| |||
0 commit comments