From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Paul E. McKenney" Subject: Re: [RFC PATCH] Fix: membarrier: racy access to p->mm in membarrier_global_expedited() Date: Mon, 28 Jan 2019 12:46:11 -0800 Message-ID: <20190128204611.GB4240@linux.ibm.com> References: <20190128182636.18420-1-mathieu.desnoyers@efficios.com> Reply-To: paulmck@linux.ibm.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Linus Torvalds Cc: Mathieu Desnoyers , Ingo Molnar , Peter Zijlstra , Linux List Kernel Mailing , Linux API , Jann Horn , Thomas Gleixner , Andrea Parri , Andrew Hunter , Andy Lutomirski , Avi Kivity , Benjamin Herrenschmidt , Boqun Feng , Dave Watson , David Sehr , Greg Hackmann , "H . Peter Anvin" , Maged Michael , Michael Ellerman , Paul Mackerras List-Id: linux-api@vger.kernel.org On Mon, Jan 28, 2019 at 12:27:03PM -0800, Linus Torvalds wrote: > On Mon, Jan 28, 2019 at 10:27 AM Mathieu Desnoyers > 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. ;-) 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 >