From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 3/5] asm-generic/bitops/atomic.h: Rewrite using atomic_fetch_*
Date: Mon, 19 Feb 2018 14:01:43 +0000 [thread overview]
Message-ID: <20180219140142.GD30394@arm.com> (raw)
In-Reply-To: <20180216102100.GB25201@hirez.programming.kicks-ass.net>
Hi Peter,
On Fri, Feb 16, 2018 at 11:21:00AM +0100, Peter Zijlstra wrote:
> On Thu, Feb 15, 2018 at 06:20:49PM +0000, Will Deacon wrote:
> > On Thu, Feb 15, 2018 at 06:08:47PM +0100, Peter Zijlstra wrote:
> > > On Thu, Feb 15, 2018 at 03:29:33PM +0000, Will Deacon wrote:
> > > > +static inline void __clear_bit_unlock(unsigned int nr,
> > > > + volatile unsigned long *p)
> > > > +{
> > > > + unsigned long old;
> > > >
> > > > + p += BIT_WORD(nr);
> > > > + old = READ_ONCE(*p);
> > > > + old &= ~BIT_MASK(nr);
> > > > + smp_store_release(p, old);
> > >
> > > This should be atomic_set_release() I think, for the special case where
> > > atomics are implemented with spinlocks, see the 'fun' case in
> > > Documentation/atomic_t.txt.
> >
> > My understanding of __clear_bit_unlock is that there is guaranteed to be
> > no concurrent accesses to the same word, so why would it matter whether
> > locks are used to implement atomics?
>
>
> commit f75d48644c56a31731d17fa693c8175328957e1d
> Author: Peter Zijlstra <peterz@infradead.org>
> Date: Wed Mar 9 12:40:54 2016 +0100
>
> bitops: Do not default to __clear_bit() for __clear_bit_unlock()
>
> __clear_bit_unlock() is a special little snowflake. While it carries the
> non-atomic '__' prefix, it is specifically documented to pair with
> test_and_set_bit() and therefore should be 'somewhat' atomic.
>
> Therefore the generic implementation of __clear_bit_unlock() cannot use
> the fully non-atomic __clear_bit() as a default.
>
> If an arch is able to do better; is must provide an implementation of
> __clear_bit_unlock() itself.
>
> Specifically, this came up as a result of hackbench livelock'ing in
> slab_lock() on ARC with SMP + SLUB + !LLSC.
>
> The issue was incorrect pairing of atomic ops.
>
> slab_lock() -> bit_spin_lock() -> test_and_set_bit()
> slab_unlock() -> __bit_spin_unlock() -> __clear_bit()
>
> The non serializing __clear_bit() was getting "lost"
>
> 80543b8e: ld_s r2,[r13,0] <--- (A) Finds PG_locked is set
> 80543b90: or r3,r2,1 <--- (B) other core unlocks right here
> 80543b94: st_s r3,[r13,0] <--- (C) sets PG_locked (overwrites unlock)
Ah, so it's problematic for the case where atomics are built using locks.
Got it. I'll err on the side of caution here and have the asm-generic header
(which should be bitops/lock.h not bitops/atomic.h) conditionally define
__clear_bit_unlock as clear_bit_lock unless the architecture has provided
its own implementation.
Thanks,
Will
next prev parent reply other threads:[~2018-02-19 14:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 15:29 [RFC PATCH 0/5] Rewrite asm-generic/bitops/atomic.h and use on arm64 Will Deacon
2018-02-15 15:29 ` [RFC PATCH 1/5] arm64: fpsimd: include <linux/init.h> in fpsimd.h Will Deacon
2018-02-15 15:29 ` [RFC PATCH 2/5] asm-generic: Avoid including linux/kernel.h in asm-generic/bug.h Will Deacon
2018-02-15 15:29 ` [RFC PATCH 3/5] asm-generic/bitops/atomic.h: Rewrite using atomic_fetch_* Will Deacon
2018-02-15 17:08 ` Peter Zijlstra
2018-02-15 18:20 ` Will Deacon
2018-02-16 10:21 ` Peter Zijlstra
2018-02-19 14:01 ` Will Deacon [this message]
2018-02-19 14:04 ` Peter Zijlstra
2018-02-16 10:35 ` Peter Zijlstra
2018-02-16 14:18 ` Peter Zijlstra
2018-02-19 14:01 ` Will Deacon
2018-02-19 14:05 ` Peter Zijlstra
2018-02-15 15:29 ` [RFC PATCH 4/5] arm64: Replace our atomic bitops implementation with asm-generic Will Deacon
2018-02-15 15:29 ` [RFC PATCH 5/5] arm64: bitops: Include <asm-generic/bitops/ext2-atomic-setbit.h> Will Deacon
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=20180219140142.GD30394@arm.com \
--to=will.deacon@arm.com \
--cc=linux-arm-kernel@lists.infradead.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).