From: Filipe Manana <fdmanana@suse.com>
To: "Holger Hoffstätte" <holger.hoffstaette@googlemail.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: fix race when reusing stale extent buffers that leads to BUG_ON
Date: Fri, 24 Apr 2015 17:08:56 +0100 [thread overview]
Message-ID: <553A6A98.4070309@suse.com> (raw)
In-Reply-To: <pan.2015.04.23.13.53.22@googlemail.com>
On 04/23/2015 02:53 PM, Holger Hoffstätte wrote:
> On Thu, 23 Apr 2015 14:43:40 +0100, Filipe Manana wrote:
>
>> I don't think a lock followed by unlock without nothing in between (be
>> it a spinlock, mutex, or any other kind of lock) will be seen by the
>> compiler as a nop. Pretty sure I've seen this pattern being done in the
>
> No, I didn't say they would - that would be wrong. I just found it odd,
> that's all.
For reference, you have plenty of example in the kernel source tree:
$ find . -name '*.c' | xargs pcregrep --line-offsets -nrM '^\s*spin_lock.*\n^\s*spin_unlock'
(...)
./fs/ext4/balloc.c:644:0,68
(...)
./mm/truncate.c:458:0,51
(...)
$ cat ./fs/ext4/balloc.c | head -646 | tail -4
if (!(*errp) && (flags & EXT4_MB_DELALLOC_RESERVED)) {
spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
dquot_alloc_block_nofail(inode,
$ cat ./mm/truncate.c | head -460 | tail -9
/*
* As truncation uses a lockless tree lookup, cycle
* the tree lock to make sure any ongoing tree
* modification that does not see AS_EXITING is
* completed before starting the final truncate.
*/
spin_lock_irq(&mapping->tree_lock);
spin_unlock_irq(&mapping->tree_lock);
>
>> kernel and in many other places as mechanism to wait for something.
>
> I also completely forgot that spinlocks disable preemption, since
> otherwise nothing would really work. That's the real reason why
> any of this works. Well, that and the refcount==2 thing.
>
> Cool! Thanks!
> Holger
>
> --
> 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
>
next prev parent reply other threads:[~2015-04-24 16:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-23 10:28 [PATCH] Btrfs: fix race when reusing stale extent buffers that leads to BUG_ON Filipe Manana
2015-04-23 12:16 ` Holger Hoffstätte
2015-04-23 12:34 ` Filipe Manana
2015-04-23 13:22 ` Holger Hoffstätte
2015-04-23 13:43 ` Filipe Manana
2015-04-23 13:53 ` Holger Hoffstätte
2015-04-24 16:08 ` Filipe Manana [this message]
2015-05-12 13:04 ` David Sterba
2015-05-07 16:19 ` David Sterba
2015-05-07 19:30 ` Chris Mason
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=553A6A98.4070309@suse.com \
--to=fdmanana@suse.com \
--cc=holger.hoffstaette@googlemail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.