[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <99dba217-ba1b-424c-8d04-5b3f1ef78d5f@suse.com>
Date: Tue, 19 Mar 2024 06:32:12 +1030
From: Qu Wenruo <wqu@...e.com>
To: Tavian Barnes <tavianator@...ianator.com>, linux-btrfs@...r.kernel.org
Cc: Chris Mason <clm@...com>, Josef Bacik <josef@...icpanda.com>,
David Sterba <dsterba@...e.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] btrfs: WARN if EXTENT_BUFFER_UPTODATE is set while
reading
在 2024/3/19 00:26, Tavian Barnes 写道:
> We recently tracked down a race condition that triggered a read for an
> extent buffer with EXTENT_BUFFER_UPTODATE already set. While this read
> was in progress, other concurrent readers would see the UPTODATE bit and
> return early as if the read was already complete, making accesses to the
> extent buffer conflict with the read operation that was overwriting it.
>
> Add a WARN_ON() to end_bbio_meta_read() for this situation to make
> similar races easier to spot in the future.
>
> Signed-off-by: Tavian Barnes <tavianator@...ianator.com>
Reviewed-by: Qu Wenruo <wqu@...e.com>
Thanks,
Qu
> ---
> fs/btrfs/extent_io.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 46173dcfde4f..0024ea20bfc4 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -4285,6 +4285,13 @@ static void end_bbio_meta_read(struct btrfs_bio *bbio)
> struct folio_iter fi;
> u32 bio_offset = 0;
>
> + /*
> + * If the extent buffer is marked UPTODATE before the read operation
> + * completes, other calls to read_extent_buffer_pages() will return
> + * early without waiting for the read to finish, causing data races.
> + */
> + WARN_ON(test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags));
> +
> eb->read_mirror = bbio->mirror_num;
>
> if (uptodate &&
Powered by blists - more mailing lists