[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAL3q7H5p4vmBs-ES08dkY7z4sjE_k3970CkJRAjiy0MhpXjYWw@mail.gmail.com>
Date: Sat, 31 Aug 2024 11:55:53 +0100
From: Filipe Manana <fdmanana@...nel.org>
To: Lizhi Xu <lizhi.xu@...driver.com>
Cc: syzbot+4704b3cc972bd76024f1@...kaller.appspotmail.com, clm@...com,
dsterba@...e.com, josef@...icpanda.com, linux-btrfs@...r.kernel.org,
linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com
Subject: Re: [PATCH] btrfs: Add assert or condition
On Sat, Aug 31, 2024 at 1:36 AM Lizhi Xu <lizhi.xu@...driver.com> wrote:
>
> When the value of fsync_skip_inode_lock is true, i_mmap_lock is used,
> so add it or condition in the ASSERT.
>
> Reported-and-tested-by: syzbot+4704b3cc972bd76024f1@...kaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=4704b3cc972bd76024f1
> Signed-off-by: Lizhi Xu <lizhi.xu@...driver.com>
> ---
> fs/btrfs/ordered-data.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
> index 82a68394a89c..d0187e1fb941 100644
> --- a/fs/btrfs/ordered-data.c
> +++ b/fs/btrfs/ordered-data.c
> @@ -1015,7 +1015,8 @@ void btrfs_get_ordered_extents_for_logging(struct btrfs_inode *inode,
> {
> struct rb_node *n;
>
> - ASSERT(inode_is_locked(&inode->vfs_inode));
> + ASSERT(inode_is_locked(&inode->vfs_inode) ||
> + rwsem_is_locked(&inode->i_mmap_lock));
This definitely fixes the syzbot report, in the sense the assertion
won't fail anymore.
But it's wrong, very, very, very, very wrong.
The inode must be locked during the course of the fsync, that's why
the assertion is there.
Why do you think it's ok to not have the inode locked?
Have you done any analysis about that?
You mention "fsync_skip_inode_lock is true" in the changelog, but have
you checked where and why it's set to true?
Where we set it to true, at btrfs_direct_write(), there's a comment
which explains it's to avoid a deadlock on the inode lock at
btrfs_sync_file().
This is a perfect example of trying a patch not only without having
any idea how the code works but also being very lazy,
as there's a very explicit comment in the code about why the variable
is set to true, and even much more detailed in the
change log of the commit that introduced it.
And btw, there's already a patch to fix this issue:
https://lore.kernel.org/linux-btrfs/717029440fe379747b9548a9c91eb7801bc5a813.1724972507.git.fdmanana@suse.com/
>
> spin_lock_irq(&inode->ordered_tree_lock);
> for (n = rb_first(&inode->ordered_tree); n; n = rb_next(n)) {
> --
> 2.43.0
>
>
Powered by blists - more mailing lists