From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755170AbbIRP50 (ORCPT ); Fri, 18 Sep 2015 11:57:26 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:52488 "EHLO e39.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754425AbbIRP5W (ORCPT ); Fri, 18 Sep 2015 11:57:22 -0400 X-Helo: d03dlp02.boulder.ibm.com X-MailFrom: paulmck@linux.vnet.ibm.com X-RcptTo: linux-kernel@vger.kernel.org Date: Fri, 18 Sep 2015 08:57:13 -0700 From: "Paul E. McKenney" To: Will Deacon Cc: Dmitry Vyukov , Peter Zijlstra , Oleg Nesterov , "ebiederm@xmission.com" , Al Viro , Andrew Morton , Ingo Molnar , "mhocko@suse.cz" , LKML , "ktsan@googlegroups.com" , Kostya Serebryany , Andrey Konovalov , Alexander Potapenko , Hans Boehm Subject: Re: [PATCH] kernel: fix data race in put_pid Message-ID: <20150918155713.GN4029@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <1442496268-47803-1-git-send-email-dvyukov@google.com> <20150917160837.GA26050@redhat.com> <20150917174456.GA30178@redhat.com> <20150917180919.GA32116@redhat.com> <20150918085156.GS3816@twins.programming.kicks-ass.net> <20150918092820.GA27377@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150918092820.GA27377@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15091815-0033-0000-0000-000005EFCDE2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 18, 2015 at 10:28:20AM +0100, Will Deacon wrote: > On Fri, Sep 18, 2015 at 10:06:46AM +0100, Dmitry Vyukov wrote: > > On Fri, Sep 18, 2015 at 10:51 AM, Peter Zijlstra wrote: > > > As an alternative patch, could we not do: > > > > > > void put_pid(struct pid *pid) > > > { > > > struct pid_namespace *ns; > > > > > > if (!pid) > > > return; > > > > > > ns = pid->numbers[pid->level].ns; > > > if ((atomic_read(&pid->count) == 1) || > > > atomic_dec_and_test(&pid->count)) { > > > > > > + smp_read_barrier_depends(); /* ctrl-dep */ > > > > > > kmem_cache_free(ns->pid_cachep, pid); > > > put_pid_ns(ns); > > > } > > > } > > > > > > That would upgrade the atomic_read() path to a full READ_ONCE_CTRL(), > > > and thereby avoid any of the kmem_cache_free() stores from leaking out. > > > And its free, except on Alpha. Whereas the atomic_read_acquire() will > > > generate a full memory barrier on whole bunch of archs. > > > > > > What you propose makes sense. > > > > +Will, Paul > > > > Can we have something along the lines of: > > > > #define atomic_read_ctrl(v) READ_ONCE_CTRL(&(v)->counter) > > Funnily enough, I had this exact same discussion off-list yesterday > afternoon, since I wrote some code relying on a ctrl dependency from > an atomic_read to an atomic_xchg_relaxed. > > So I guess I'm for the addition, but at the same time, could we make > atomic_read and atomic_set generic too? If we have some places that could use it, by all means let's add it! Thanx, Paul