linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Filipe Manana <fdmanana@kernel.org>
To: Alex Lyakas <alex@zadara.com>
Cc: linux-btrfs <linux-btrfs@vger.kernel.org>,
	Filipe Manana <fdmanana@suse.com>
Subject: Re: [PATCH 2/2] Btrfs: fix unprotected deletion from pending_chunks list
Date: Mon, 21 Jan 2019 20:05:47 +0000	[thread overview]
Message-ID: <CAL3q7H7G7PzkPG7ukSBXFR+7q9AK_PryW=T5DNFNnMpiojnA4A@mail.gmail.com> (raw)
In-Reply-To: <CAOcd+r3U9x20gAsrOtDC1pd1qO-Zy_QiWrmQysvKjbLJOUDH_A@mail.gmail.com>

On Mon, Jan 21, 2019 at 7:07 PM Alex Lyakas <alex@zadara.com> wrote:
>
> Hi Filipe,
>
> On Tue, Dec 2, 2014 at 8:08 PM Filipe Manana <fdmanana@suse.com> wrote:
> >
> > On block group remove if the corresponding extent map was on the
> > transaction->pending_chunks list, we were deleting the extent map
> > from that list, through remove_extent_mapping(), without any
> > synchronization with chunk allocation (which iterates that list
> > and adds new elements to it). Fix this by ensure that this is done
> > while the chunk mutex is held, since that's the mutex that protects
> > the list in the chunk allocation code path.
> >
> > This applies on top (depends on) of my previous patch titled:
> > "Btrfs: fix race between fs trimming and block group remove/allocation"
> >
> > But the issue in fact was already present before that change, it only
> > became easier to hit after Josef's 3.18 patch that added automatic
> > removal of empty block groups.
> >
> > Signed-off-by: Filipe Manana <fdmanana@suse.com>
> > ---
> >  fs/btrfs/extent-tree.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> > index 17d429d..a7b81b4 100644
> > --- a/fs/btrfs/extent-tree.c
> > +++ b/fs/btrfs/extent-tree.c
> > @@ -9524,19 +9524,25 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
> >                 list_move_tail(&em->list, &root->fs_info->pinned_chunks);
> >         }
> >         spin_unlock(&block_group->lock);
> > -       unlock_chunks(root);
> >
> >         if (remove_em) {
> >                 struct extent_map_tree *em_tree;
> >
> >                 em_tree = &root->fs_info->mapping_tree.map_tree;
> >                 write_lock(&em_tree->lock);
> > +               /*
> > +                * The em might be in the pending_chunks list, so make sure the
> > +                * chunk mutex is locked, since remove_extent_mapping() will
> > +                * delete us from that list.
> > +                */
> >                 remove_extent_mapping(em_tree, em);
> >                 write_unlock(&em_tree->lock);
> If the "em" was in pending_chunks, it will be deleted from that list
> by "remove_extent_mapping". But it looks like in this case we also
> need to drop the extra ref on "em", which was held by pending_chunks
> list. I don't see it being done anywhere else. So we should check
> before the remove_extent_mapping() call whether "em" was in
> pending_chunks, and, if yes, drop the extra ref?

This was part of a large patch set that fixed multiple issues with
automatic removal of block groups.
Dropping the extent map reference was done on another patch of that patch set:

commit 495e64f4fe0363bc79fa0dfb41c271787e01b5c3
Author: Filipe Manana <fdmanana@suse.com>
Date:   Tue Dec 2 18:07:30 2014 +0000

    Btrfs: fix fs mapping extent map leak

Over 4 years ago....

>
> Thanks,
> Alex.
>
>
> >                 /* once for the tree */
> >                 free_extent_map(em);
> >         }
> >
> > +       unlock_chunks(root);
> > +
> >         btrfs_put_block_group(block_group);
> >         btrfs_put_block_group(block_group);
> >
> > --
> > 2.1.3
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2019-01-21 20:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-02 18:07 [PATCH 2/2] Btrfs: fix unprotected deletion from pending_chunks list Filipe Manana
2019-01-21 19:07 ` Alex Lyakas
2019-01-21 20:05   ` Filipe Manana [this message]
2019-01-22 10:41     ` Alex Lyakas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAL3q7H7G7PzkPG7ukSBXFR+7q9AK_PryW=T5DNFNnMpiojnA4A@mail.gmail.com' \
    --to=fdmanana@kernel.org \
    --cc=alex@zadara.com \
    --cc=fdmanana@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).