Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757414AbbDVNzU (ORCPT ); Wed, 22 Apr 2015 09:55:20 -0400 Received: from mail-ie0-f176.google.com ([209.85.223.176]:35986 "EHLO mail-ie0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756623AbbDVNzR (ORCPT ); Wed, 22 Apr 2015 09:55:17 -0400 Message-ID: <1429710915.18561.72.camel@edumazet-glaptop2.roam.corp.google.com> Subject: Re: [RFC PATCH] fs: use a sequence counter instead of file_lock in fd_install From: Eric Dumazet To: Mateusz Guzik Cc: Al Viro , Andrew Morton , "Paul E. McKenney" , Yann Droneaud , Konstantin Khlebnikov , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 22 Apr 2015 06:55:15 -0700 In-Reply-To: <20150422133149.GA10455@mguzik> References: <20150417230252.GE889@ZenIV.linux.org.uk> <20150420130633.GA2513@mguzik> <20150420134326.GC2513@mguzik> <20150420151054.GD2513@mguzik> <1429550126.7346.268.camel@edumazet-glaptop2.roam.corp.google.com> <1429562991.7346.290.camel@edumazet-glaptop2.roam.corp.google.com> <1429639543.7346.329.camel@edumazet-glaptop2.roam.corp.google.com> <20150421200624.GA16097@mguzik> <20150421201201.GB16097@mguzik> <1429650413.18561.10.camel@edumazet-glaptop2.roam.corp.google.com> <20150422133149.GA10455@mguzik> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2080 Lines: 59 On Wed, 2015-04-22 at 15:31 +0200, Mateusz Guzik wrote: > On Tue, Apr 21, 2015 at 02:06:53PM -0700, Eric Dumazet wrote: > > On Tue, 2015-04-21 at 22:12 +0200, Mateusz Guzik wrote: > > > > > in dup_fd: > > > for (i = open_files; i != 0; i--) { > > > struct file *f = *old_fds++; > > > if (f) { > > > get_file(f); > > > > > > > I see no new requirement here. f is either NULL or not. > > multi threaded programs never had a guarantee dup_fd() would catch a non > > NULL pointer here. > > > > It's not about seeing NULL f or not, but using the right address for > dereference. > > If I read memory-barriers.txt right (see 'DATA DEPENDENCY BARRIERS'), it > is possible that cpus like alpha will see a non-NULL pointer and then > proceed to dereference *the old* (here: NULL) value. > > Hence I suspect this needs smp_read_barrier_depends (along with > ACCESS_ONCE). > > Other consumers (e.g. procfs code) use rcu_dereference macro which does > ends up using lockless_dereference macro, which in turn does: > #define lockless_dereference(p) \ > ({ \ > typeof(p) _________p1 = ACCESS_ONCE(p); \ > smp_read_barrier_depends(); /* Dependency order vs. p > above. */ \ > (_________p1); \ > }) > > That said memory barriers are not exactly my strong suit, but I do > believe my suspicion here is justified enough to ask someone with solid > memory barrier-fu to comment. Again, your comment has nothing to do with the patch. If there is old data, it only can be a NULL. And it is fine, case was _already_ handled. It can not be an 'old' file pointer, because close() takes the spinlock. spin_unlock() contains a write memory barrier, so the NULL pointer put by close() would have been committed to memory. This works also on alpha cpus. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/