mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Matteo Franchin <Matteo.Franchin@arm.com>,
	Darren Hart <dvhart@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Mike Galbraith <umgwanakikbuti@gmail.com>
Subject: Re: [PATCH] futex: Ensure get_futex_key_refs() always implies a barrier
Date: Mon, 20 Oct 2014 17:00:09 +0100	[thread overview]
Message-ID: <20141020160009.GK23751@e104818-lin.cambridge.arm.com> (raw)
In-Reply-To: <CA+55aFxjFpPWMn=w1orFk3k7-ZaWwFoLsv7y37X5zamd428BsQ@mail.gmail.com>

On Mon, Oct 20, 2014 at 04:32:00PM +0100, Linus Torvalds wrote:
> On Mon, Oct 20, 2014 at 3:49 AM, Catalin Marinas
> <catalin.marinas@arm.com> wrote:
> > Since you mention symmetry, something like below makes the barriers more
> > explicit.
> 
> Borken, for two reasons:
> 
> > diff --git a/kernel/futex.c b/kernel/futex.c
> > index f3a3a071283c..5b9d857d0816 100644
> > --- a/kernel/futex.c
> > +++ b/kernel/futex.c
> > @@ -143,9 +143,7 @@
> >  static inline void futex_get_mm(union futex_key *key)
> >  {
> >         atomic_inc(&key->private.mm->mm_count);
> > -       /*
> > -        * Ensure futex_get_mm() implies a full barrier such that
> > -        * get_futex_key() implies a full barrier. This is relied upon
> > -        * as full barrier (B), see the ordering comment above.
> > -        */
> > -       smp_mb__after_atomic();
> >  }
> 
> So the thing is, this means that we can't take advantage of the fact
> that "atomic_inc" is already an atomic. So this is just a performance
> breakage. But:

OK, I looked at this from an ARM perspective only and it would not make
any difference. But it seems that MIPS makes a distinction between
"before" and "after" barriers with "before" defined as wmb in some
configuration, so the hunk below would break it.

> >  static inline int hb_waiters_pending(struct futex_hash_bucket *hb)
> >  {
> > +       /*
> > +        * Full barrier (B), see the ordering comment above.
> > +        */
> > +       smp_mb__before_atomic();
> >  #ifdef CONFIG_SMP
> >         return atomic_read(&hb->waiters);
> 
> This is just entirely broken.
> 
> "atomic_read()" isn't really an "atomic op" at all. despite the name,
> it's just a read that is basically ACCESS_ONCE.
> 
> So smp_mb__before_atomic() doesn't work for atomic_read(), and the
> code is nonsensical and doesn't work. It would need to be a full
> memory barrier.

Looking at the semantics of smp_mb__*_atomic(), it would indeed have to
be a full smp_mb() here.

-- 
Catalin

  reply	other threads:[~2014-10-20 16:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-17 16:38 Catalin Marinas
2014-10-18  6:54 ` Mike Galbraith
2014-10-18  7:09   ` Mike Galbraith
2014-10-18 15:28   ` Linus Torvalds
2014-10-18 16:15     ` Mike Galbraith
2014-10-18  7:33 ` Davidlohr Bueso
2014-10-18 19:58   ` Davidlohr Bueso
2014-10-18 20:50     ` Linus Torvalds
2014-10-19  2:16       ` Davidlohr Bueso
2014-10-20  9:11         ` Thomas Gleixner
2014-10-20 10:49           ` Catalin Marinas
2014-10-20 15:32             ` Linus Torvalds
2014-10-20 16:00               ` Catalin Marinas [this message]
2014-10-18 19:32 ` Darren Hart
2014-10-18 20:19   ` Davidlohr Bueso
2014-10-18 20:25     ` Darren Hart
2014-10-20 10:15     ` Catalin Marinas
2014-10-24  3:27 ` [PATCH] futex: Mention key referencing differences between shared and private futexes Davidlohr Bueso
2014-10-24  9:11   ` Catalin Marinas
2014-10-26 15:22   ` [tip:locking/urgent] " tip-bot for Davidlohr Bueso

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=20141020160009.GK23751@e104818-lin.cambridge.arm.com \
    --to=catalin.marinas@arm.com \
    --cc=Matteo.Franchin@arm.com \
    --cc=dave@stgolabs.net \
    --cc=dvhart@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=umgwanakikbuti@gmail.com \
    /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

all inboxes | Powered by JetHome®