Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp597295pxk; Thu, 1 Oct 2020 09:40:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+YEjzTGzHwE6+59buh9Sz5oPZGDy1zfUETYz0HgSqAi0Yk1upmTVEhubJzKpDDtvxh+Dm X-Received: by 2002:a05:6402:3193:: with SMTP id di19mr9008963edb.211.1601570442219; Thu, 01 Oct 2020 09:40:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601570442; cv=none; d=google.com; s=arc-20160816; b=rpdArGIL3mkkP7FumxdKT5+Ik3CmUs/aOlSrJvSC6CE169fFjdpa1e/CvfHoPZQVJf Eufy490W+IprGF5HKi1RwFNHTcOnV6w+8GVOBT1eCgHMHXO0IhjfHlUSrGGKqtpSg5Zp AInhyVdnMIz+5pZL6ImwtfPmRYfJwltHM2YyPUX4CIEZjBiCNkitFzLxI2EG0O8MwAvn TL0cXTILe8ISblIrK0qsj/wGqEyiBA7ECSTklEii93w62YqSGOrJG5t37o3DMnp5ls8R 3pccmtnlP5VoYajF223GlXRvc0AX3BeWdQ2fDaTEfDtDztsP9JWRAwhJ17nI1XMAqes9 GZKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=f5yEjMr17+UdfcdBFXM8q8XgWR5nGcOSBxaHT8QTNg0=; b=YqqmCA7VjpoJeWyBfaomKlSlejny8par3KPY+SpOa27wDlSMnMCtWo7/7AX5uRKXyL +ddzG7qWxIRteagrxskL6EDiJ0U4zn8SM+hyGq8+GAkL/IbljacSGdttUM3vV98CiSCg xSV34LGAnA7xh+P4kNFnGJUm8NlU4qnttBGEqB1wOSMqboJW/fpizDH4HXCW+DtLTXwp v0Zwm95f1x9CaJ+rre7WG4r9hbaRELzNwatkQBVGvahaPTLh0PTTluCm9RTykCV2Q7uj ++ZE69adxHSJNL2NrrHLPF1j4s80FVW+NdKOsPntFSMKbrjWe3GqlXBcvLTCTieXEYaT jPGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si3705194edt.600.2020.10.01.09.40.16; Thu, 01 Oct 2020 09:40:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732104AbgJAQhE (ORCPT + 99 others); Thu, 1 Oct 2020 12:37:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731917AbgJAQhD (ORCPT ); Thu, 1 Oct 2020 12:37:03 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF433C0613D0; Thu, 1 Oct 2020 09:37:03 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kO1ZW-009vym-B9; Thu, 01 Oct 2020 16:36:46 +0000 Date: Thu, 1 Oct 2020 17:36:46 +0100 From: Al Viro To: Alan Stern Cc: "Paul E. McKenney" , parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, dlustig@nvidia.com, joel@joelfernandes.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: Litmus test for question from Al Viro Message-ID: <20201001163646.GG3421308@ZenIV.linux.org.uk> References: <20201001045116.GA5014@paulmck-ThinkPad-P72> <20201001161529.GA251468@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201001161529.GA251468@rowland.harvard.edu> Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 01, 2020 at 12:15:29PM -0400, Alan Stern wrote: > > CPU1: > > to_free = NULL > > spin_lock(&LOCK) > > if (!smp_load_acquire(&V->B)) > > to_free = V > > V->A = 0 > > spin_unlock(&LOCK) > > kfree(to_free) > > > > CPU2: > > to_free = V; > > if (READ_ONCE(V->A)) { > > spin_lock(&LOCK) > > if (V->A) > > to_free = NULL > > smp_store_release(&V->B, 0); > > spin_unlock(&LOCK) > > } > > kfree(to_free); > > 1) is it guaranteed that V will be freed exactly once and that > > no accesses to *V will happen after freeing it? > > 2) do we need smp_store_release() there? I.e. will anything > > break if it's replaced with plain V->B = 0? > > Here are my answers to Al's questions: > > 1) It is guaranteed that V will be freed exactly once. It is not > guaranteed that no accesses to *V will occur after it is freed, because > the test contains a data race. CPU1's plain "V->A = 0" write races with > CPU2's READ_ONCE; What will that READ_ONCE() yield in that case? If it's non-zero, we should be fine - we won't get to kfree() until after we are done with the spinlock. And if it's zero... What will CPU1 do with *V accesses _after_ it has issued the store to V->A? Confused... > if the plain write were replaced with > "WRITE_ONCE(V->A, 0)" then the guarantee would hold. Equally well, > CPU1's smp_load_acquire could be replaced with a plain read while the > plain write is replaced with smp_store_release. Er... Do you mean the write to ->A on CPU1?