Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2891006pxk; Sun, 4 Oct 2020 16:36:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiNx/ftdq5r44/hvkANSgSKJeSGtZQNFOXuya+/WwufXdnyR6FoR+oHtDOi2lVzXnvncAB X-Received: by 2002:a17:906:8283:: with SMTP id h3mr8855358ejx.492.1601854581767; Sun, 04 Oct 2020 16:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601854581; cv=none; d=google.com; s=arc-20160816; b=AZXE6NCbwP8bihpk3MDuicRpArfjmzQzuWAHN7jEY9Y1bl1DnEmG/+KwQeBdassDTA nMYV3cgv1b1rEwnHsz/N0NWDl5FXqHvlvZF8fCGBbIrs7CO2XTbruH3jQI/IoI6iwXYh USJ4imzsbXDBhl2wUdI8Ng6MbK9ZDl9wJWi5fWnz9Tm3pR52W7CxKpdUsPmDwx5afzkO m6/JX3vcksTxXF2FvE8h7BGDHfiMcRGP5MVWZrnUXV7XbdNu+BR59Jjl23wqM3vbNER3 LxE1Y3a3bNd30KyNpP8/JkucsTzmgBQ4vuPxSnqOVJ3YbzlAuPMNJ3EcIq21xXID8QlC JXnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Qe4U9fRDkGBZfhe4wJsrmMlBcmJ8GeTX0aXS9RrPEac=; b=VYAaGwzQxQw30/k5HPpLluTuF6oruQQky+EF+IM872eIzMJ1RBDLFatjpIFypDQJJi ZzchhBbD655qPlJIRCgCyPaOr99nvD1EJjs9jsS0b2mcnElcjc6ujkDNRuUtheMp/FxI KL3FX+lvkqVjHtzGzplfeC8277Y9z10+C/s4mpydtSgEEQRZE1pHUjJ9R14BwKKPfSh0 3usCrgIvfZ7GJpKC0d75SoEemAJHKt3zJk6oBhWh5zsZYiGqSWSlxEZ7vC3f4nDs0T6k 8tX+x9paSD/UOnbE+zCvuFdcbf5Q/Aap0qe2tK1NEvDw+MxxGuy0zmLa0YTxlqKTxMfV ciYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="t2teay/J"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dc4si5798737ejb.526.2020.10.04.16.35.58; Sun, 04 Oct 2020 16:36:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b="t2teay/J"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725865AbgJDXc3 (ORCPT + 99 others); Sun, 4 Oct 2020 19:32:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:36970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbgJDXc2 (ORCPT ); Sun, 4 Oct 2020 19:32:28 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-104-11.bvtn.or.frontiernet.net [50.39.104.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0B2B2206B6; Sun, 4 Oct 2020 23:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601854348; bh=YzpcxYAFA+eJp0cl8hwcxcJi+D+5TLeTPsAXUn92KwY=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=t2teay/JnQ5b19qQc0wEnqJMTZHhT/onkMM/QrCtYWDQE/9PoM6eOIpF5vAwMUlRd 8Qi+lDP65X0DEbOm/D1CH8C7ZIeqIH85VLnsmwYPI5pHl1y2dETJdCnqun4WwvDr19 kL8/uAyH2U5PBJmU9hSez81fpWJHtTviQ5/GK33M= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id C614035225F2; Sun, 4 Oct 2020 16:32:27 -0700 (PDT) Date: Sun, 4 Oct 2020 16:32:27 -0700 From: "Paul E. McKenney" To: Jon Masters Cc: Alan Stern , 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, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: Litmus test for question from Al Viro Message-ID: <20201004233227.GQ29330@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20201001045116.GA5014@paulmck-ThinkPad-P72> <20201001161529.GA251468@rowland.harvard.edu> <17935342-e927-284c-9a2b-ca75dd2398ad@jonmasters.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <17935342-e927-284c-9a2b-ca75dd2398ad@jonmasters.org> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 02, 2020 at 10:35:45PM -0400, Jon Masters wrote: > On 10/1/20 12:15 PM, Alan Stern wrote: > > On Wed, Sep 30, 2020 at 09:51:16PM -0700, Paul E. McKenney wrote: > > > Hello! > > > > > > Al Viro posted the following query: > > > > > > ------------------------------------------------------------------------ > > > > > > fun question regarding barriers, if you have time for that > > > V->A = V->B = 1; > > > > > > 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; 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. > > > > 2) The smp_store_release in CPU2 is not needed. Replacing it with a > > plain V->B = 0 will not break anything. > > This was my interpretation also. I made the mistake of reading this right > before trying to go to bed the other night and ended up tweeting at Paul > that I'd regret it if he gave me scary dreams. Thought about it and read > your write up and it is still exactly how I see it. Should I have added a "read at your own risk" disclaimer? ;-) Thanx, Paul