linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fusionio.com>
To: Zach Brown <zab@zabbo.net>
Cc: Josef Bacik <JBacik@fusionio.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH] Btrfs: fix freeing delayed ref head while still holding its mutex
Date: Thu, 31 Jan 2013 11:23:57 -0500	[thread overview]
Message-ID: <20130131162357.GN3660@localhost.localdomain> (raw)
In-Reply-To: <20130130221635.GV14246@lenny.home.zabbo.net>

On Wed, Jan 30, 2013 at 03:16:35PM -0700, Zach Brown wrote:
> On Wed, Jan 30, 2013 at 04:06:18PM -0500, Josef Bacik wrote:
> > I hit this error when reproducing a bug that would end in a transaction
> > abort.  We take the delayed ref head's mutex to keep anybody from processing
> > it while we're destroying it, but we fail to drop the mutex before we carry
> > on and free the damned thing.  Fix this by doing the remove logic for the
> > head ourselves and unlock the mutex, that way we can avoid use after free's
> > or hung tasks waiting on that mutex to come back so they know the delayed
> > ref completed.  Thanks,
> > 
> 
> > +			ref->in_tree = 0;
> > +			rb_erase(&ref->rb_node, &delayed_refs->root);
> > +			delayed_refs->num_entries--;
> > +			mutex_unlock(&head->mutex);
> > +		} else {
> > +			ref->in_tree = 0;
> > +			rb_erase(&ref->rb_node, &delayed_refs->root);
> > +			delayed_refs->num_entries--;
> 
> Do you really need to duplicate the removal under the mutex?  Isn't all
> that protected by the delayed_refs->lock?
> 
> Isn't it enough to just add the mutex_unlock()?
> 

Yeah I could re-arrange I guess, either way it's not pretty but I guess not
duplicating stuff is better.  Thanks,

Josef

      reply	other threads:[~2013-01-31 16:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-30 21:06 [PATCH] Btrfs: fix freeing delayed ref head while still holding its mutex Josef Bacik
2013-01-30 22:16 ` Zach Brown
2013-01-31 16:23   ` Josef Bacik [this message]

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=20130131162357.GN3660@localhost.localdomain \
    --to=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=zab@zabbo.net \
    /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).