Re: [syzbot] [btrfs?] WARNING in btrfs_issue_discard

From: David Sterba
Date: Mon Jan 15 2024 - 14:16:32 EST


On Mon, Jan 15, 2024 at 09:22:19AM -0800, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 3e7aeb78ab01 Merge tag 'net-next-6.8' of git://git.kernel...
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=13f61d33e80000
> kernel config: https://syzkaller.appspot.com/x/.config?x=8e557b1c0a57d2c0
> dashboard link: https://syzkaller.appspot.com/bug?extid=4a4f1eba14eb5c3417d1
> compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16bdfc0be80000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=177f3c83e80000
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/4c8a9f091067/disk-3e7aeb78.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/8cb663b518a5/vmlinux-3e7aeb78.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/bc6d189cfcf3/bzImage-3e7aeb78.xz
> mounted in repro #1: https://storage.googleapis.com/syzbot-assets/e37fd964ba01/mount_0.gz
> mounted in repro #2: https://storage.googleapis.com/syzbot-assets/174ce0bdbd5e/mount_4.gz
>
> The issue was bisected to:
>
> commit 2b9ac22b12a266eb4fec246a07b504dd4983b16b
> Author: Kristian Klausen <kristian@xxxxxxxxxx>
> Date: Fri Jun 18 11:51:57 2021 +0000
>
> loop: Fix missing discard support when using LOOP_CONFIGURE

This only adds proper discard support to loop device so it makes the
problem visible.

> bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=111924a5e80000
> final oops: https://syzkaller.appspot.com/x/report.txt?x=131924a5e80000
> console output: https://syzkaller.appspot.com/x/log.txt?x=151924a5e80000
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+4a4f1eba14eb5c3417d1@xxxxxxxxxxxxxxxxxxxxxxxxx
> Fixes: 2b9ac22b12a2 ("loop: Fix missing discard support when using LOOP_CONFIGURE")
>
> ------------[ cut here ]------------
> WARNING: CPU: 0 PID: 5071 at fs/btrfs/extent-tree.c:1263 btrfs_issue_discard+0x5ba/0x5e0 fs/btrfs/extent-tree.c:1263

1256 static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len,
1257 u64 *discarded_bytes)
1258 {
1259 int j, ret = 0;
1260 u64 bytes_left, end;
1261 u64 aligned_start = ALIGN(start, 1 << SECTOR_SHIFT);
1262
1263 if (WARN_ON(start != aligned_start)) {
^^^^

1264 len -= aligned_start - start;
1265 len = round_down(len, 1 << SECTOR_SHIFT);
1266 start = aligned_start;
1267 }

The alignment check was added in 4d89d377bbb0 ("btrfs: btrfs_issue_discard
ensure offset/length are aligned to sector boundaries"), with the
WARN_ON. It seems that syzbot is testing unaligned discard requests,
which is probably ok but the warning is excessive as there's a fallback.