Re: [PATCH 10/17] btrfs: add assert_spin_locked() for attach_extent_buffer_page()

Nikolay Borisov
2020-09-11T11:35:51Z

On 8.09.20 г. 10:52 ч., Qu Wenruo wrote:
> When calling attach_extent_buffer_page(), either we're attaching
> anonymous pages, called from btrfs_clone_extent_buffer().
>
> Or we're attaching btree_inode pages, called from alloc_extent_buffer().
>
> For the later case, we should have page->mapping->private_lock hold to
> avoid race modifying page->private.
>
> Add assert_spin_locked() if we're calling from alloc_extent_buffer().
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com> but see one nit below.
> ---
> fs/btrfs/extent_io.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 1cb41dab7a1d..81e43d99feda 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -3096,6 +3096,9 @@ static int submit_extent_page(unsigned int opf,
> static void attach_extent_buffer_page(struct extent_buffer *eb,
> struct page *page)
> {
> + if (page->mapping)
> + assert_spin_locked(&page->mapping->private_lock);

nit: In addition to the changelog I'd rather have a comment explaining
where the distinction we make : So something like:

"Only pages allocated through alloc_extent_buffer will have their
mapping set"

> +
> if (!PagePrivate(page))
> attach_page_private(page, eb);
> else
>