From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: paulmck <paulmck@linux.ibm.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Jann Horn <jannh@google.com>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
linux-api <linux-api@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Andrea Parri <parri.andrea@gmail.com>,
Andrew Hunter <ahh@google.com>, Andy Lutomirski <luto@kernel.org>,
Avi Kivity <avi@scylladb.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Boqun Feng <boqun.feng@gmail.com>,
Dave Watson <davejwatson@fb.com>, David Sehr <sehr@google.com>,
Greg Hackmann <ghackmann@google.com>,
"H. Peter Anvin" <hpa@zytor.com>,
maged michael <maged.michael@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Paul Mackerras <paulus@samba.org>,
"Russell King, ARM Linux" <linux@armlinux.org.uk>,
Will Deacon <will.deacon@arm.com>,
stable <stable@vger.kernel.org>
Subject: Re: [RFC PATCH] Fix: membarrier: racy access to p->mm in membarrier_global_expedited()
Date: Mon, 28 Jan 2019 16:07:26 -0500 (EST) [thread overview]
Message-ID: <231707440.2765.1548709646123.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <20190128204611.GB4240@linux.ibm.com>
----- On Jan 28, 2019, at 3:46 PM, paulmck paulmck@linux.ibm.com wrote:
> On Mon, Jan 28, 2019 at 12:27:03PM -0800, Linus Torvalds wrote:
>> On Mon, Jan 28, 2019 at 10:27 AM Mathieu Desnoyers
>> <mathieu.desnoyers@efficios.com> wrote:
>> >
>> > Jann Horn identified a racy access to p->mm in the global expedited
>> > command of the membarrier system call.
>> >
>> > The suggested fix is to hold the task_lock() around the accesses to
>> > p->mm and to the mm_struct membarrier_state field to guarantee the
>> > existence of the mm_struct.
>>
>> Hmm. I think this is right. You shouldn't access another threads mm
>> pointer without proper locking.
>>
>> That said, we *could* make the mm_cachep be SLAB_TYPESAFE_BY_RCU,
>> which would allow speculatively reading data off the mm pointer under
>> RCU. It might not be the *right* mm if somebody just did an exit, but
>> for things like this it shouldn't matter.
>
> That sounds much simpler and more effective than the contention-reduction
> approach that I suggested. ;-)
I'd be tempted to stick to the locking approach for a fix, and implement
Linus' type-safe mm_cachep idea if anyone complains about the overhead
of membarrier GLOBAL_EXPEDITED (and submit for a future merge window).
I tested the KASAN splat reproducer from Jann locally, and confirmed that
my patch fixes the issue it reproduces.
Please let me know if the task_lock() approach is OK as a fix for now.
I'm also awaiting a Tested-by from Jann before submitting this for real.
Thanks,
Mathieu
>
> Thanx, Paul
>
>> But if this is the only case that might care, it sounds like just
>> doing the proper locking is the right approach.
>>
>> Linus
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2019-01-28 21:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-28 18:26 [RFC PATCH] Fix: membarrier: racy access to p->mm in membarrier_global_expedited() Mathieu Desnoyers
2019-01-28 20:27 ` Linus Torvalds
2019-01-28 20:46 ` Paul E. McKenney
2019-01-28 21:07 ` Mathieu Desnoyers [this message]
2019-01-28 21:26 ` Paul E. McKenney
2019-01-28 21:33 ` Jann Horn
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=231707440.2765.1548709646123.JavaMail.zimbra@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=ahh@google.com \
--cc=avi@scylladb.com \
--cc=benh@kernel.crashing.org \
--cc=boqun.feng@gmail.com \
--cc=davejwatson@fb.com \
--cc=ghackmann@google.com \
--cc=hpa@zytor.com \
--cc=jannh@google.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=luto@kernel.org \
--cc=maged.michael@gmail.com \
--cc=mingo@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=parri.andrea@gmail.com \
--cc=paulmck@linux.ibm.com \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=sehr@google.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.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