From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754153AbbIROoP (ORCPT ); Fri, 18 Sep 2015 10:44:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58337 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753141AbbIROoN (ORCPT ); Fri, 18 Sep 2015 10:44:13 -0400 Date: Fri, 18 Sep 2015 16:41:15 +0200 From: Oleg Nesterov To: Dmitry Vyukov Cc: Peter Zijlstra , Will Deacon , "ebiederm@xmission.com" , Al Viro , Andrew Morton , Ingo Molnar , Paul McKenney , "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: <20150918144115.GA14155@redhat.com> References: <20150917180919.GA32116@redhat.com> <20150918085156.GS3816@twins.programming.kicks-ass.net> <20150918092820.GA27377@arm.com> <20150918112252.GT3816@twins.programming.kicks-ass.net> <20150918115637.GM3604@twins.programming.kicks-ass.net> <20150918134453.GA11630@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/18, Dmitry Vyukov wrote: > > On Fri, Sep 18, 2015 at 3:44 PM, Oleg Nesterov wrote: > > So I assume that if we have > > > > int X = 0; > > atomic_t Y = ATOMIC_INIT(0); > > > > void w(void) > > { > > X = 1; > > atomic_inc_return(&Y); > > } > > > > then > > > > void r(void) > > { > > if (atomic_read_ctrl(&Y)) > > BUG_ON(X == 0); > > } > > > > should be correct? Why? > > > > If not then I am even more confused. > > This not correct, Good. because I wasn't able to understand why this could work. > // thread 1 > X = 1; > atomic_inc_return(&Y); > > // thread 2 > if (atomic_read_ctrl(&Y)) { > X = 2; > BUG_ON(X == 2); > } Thanks. This makes perfect sense to me. And then I agree, atomic_read_ctrl() in put_pid() should fix the theoretical problem. Perhaps we can add this example to memory-barriers.txt... Although perhaps it already explains/documents this case. I am afraid to open it, it is huge and changes too often so every time it looks like a new document to me ;) Oleg.