Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1761196pxk; Fri, 2 Oct 2020 19:38:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw85NQDETDS+Jsoke1Hl1WCZo725YLAyMPlp3G1LoGTJqQhKUoK/fZSjIXhSwBlGLQDuTLi X-Received: by 2002:a05:6402:1503:: with SMTP id f3mr6086236edw.307.1601692733789; Fri, 02 Oct 2020 19:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601692733; cv=none; d=google.com; s=arc-20160816; b=gNtHGIbji9eN16MhcXLkQNXfPgYeKa4HvQ8wWMBRn6u7jZdTK0yBL3pKkvqRLnMg78 f0w5gGOv89RlRoXX+5CnhFok1236dGamve2mNS/aHuOt7uEBj3+ZUR/VA6jLAYwGLsw1 p4lGsL4RPH2th1KHcorlR1Mz0jJzqRCQvM7lEexGrH8DQ0E1YW3FyFB0aSHenV7zUiJO O5jsleljG8ivESPRIAV5/zgxhc0HzNZ8TG46PaA0nmJwSuRYtHwtU3JqKK6mk/YPLDgw GkCIXmgXW2QFWv3nHXVte4y6ijNmceQ4FaIq/b5CgPUiTyEAOOec7+HVL3pGZixDg1rO Tv2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=qMmWF6ubbtV92w199K+3UInTe5FQZJe6gLAHz49PtPo=; b=Px0ZFs+A12YQUZgghdHSoukfsj9+i4ODvpTlMf1lRz/+mIwcCM1TCWJUaiAnJjMbt5 N4cFBpPFpt3qU/WpffZaYk41JF3/QRywsy+/pdyGCkA3dXuyux3BsnrvB+gg6BNVzPLC lbJYf0HVZ94NYm/haZtEwNTkjLucnpuemZBomSCiBprSZ6OctHZSd8cwm6mEvw7DDHT3 XXKFryk3MKTdcE1YV4zidHwNL+F06uf/drv9OwDVxJLAcY4koHLFQkb5jHnaXmuQtY65 AKgd6B5Z4HbKylfV6S6eWoIIdPQNfdGbx9wf9wIV7YSsM4UMQ1KzCzCckPrwlVBpjhel F35A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jonmasters-org.20150623.gappssmtp.com header.s=20150623 header.b=hgtENHPH; 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 j4si2282726eds.475.2020.10.02.19.38.31; Fri, 02 Oct 2020 19:38:53 -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=@jonmasters-org.20150623.gappssmtp.com header.s=20150623 header.b=hgtENHPH; 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 S1725834AbgJCCgT (ORCPT + 99 others); Fri, 2 Oct 2020 22:36:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbgJCCgS (ORCPT ); Fri, 2 Oct 2020 22:36:18 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F575C0613D0 for ; Fri, 2 Oct 2020 19:36:18 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id 19so4396653qtp.1 for ; Fri, 02 Oct 2020 19:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jonmasters-org.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qMmWF6ubbtV92w199K+3UInTe5FQZJe6gLAHz49PtPo=; b=hgtENHPHkh6zTxcjGbJwuue7p57lIA8ne9nOJ1+/l6pP7Zcl6TJqSOv28eF1SDxvGc LOSH4nWYb2h9hSO6fPFS6g5rasN7bByaO6G6K/ZGw3XJQWFk5ZANfVTE37q0qHuqy/YM vJH/YrYTz/ixZ+s7ijdactefIJ6fuHxMpSNTquWRLOrOEzKv2kL/+vhcVd2RV+i6FeiL oECIQD3M8o7VPBRt3Gllq7t90m9lvSoIIGIedLW4bA344IvlxIiURTPfpMrl5CbO5o7t X7ecq/K9tunmN2mighMN2KPioNXZuQ5mbE30U60dZVYQOI/rQ59lLQBuHkKd2v0gUi3O CjpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=qMmWF6ubbtV92w199K+3UInTe5FQZJe6gLAHz49PtPo=; b=q9kks5aL54cSgt6t7XQAxRx5y7kZ+F1jSmQB/Uj/Y4Phs4H1XdBQIWmDgtp7QozAP4 D4BWLzY7zICkj+WBCuNPm1QUBN1T1MyooquspKjPhU9pC1jf4X3UHWxEa36GNhwZv7Qk v11igBc1zGGiSTwEyG9r7++0wQ0FZK/HO9x8Iu7um6I12dJbOgEQvtRqgiqoAHbTR5hn fb3bEH0wHZYgKYKeDwbkn+OhPw4sD885sz5HWnutSM3XxYII4TnZTSheGpuFNzIaglUk 0JECp3J89ZHHnlbnIBVf0dXH8K0x+HkJMaF4BMtW0AceEO5ePpbzrZPeuSPECrdpkw8U nCvQ== X-Gm-Message-State: AOAM530wgMT4YOy8B5L07RfO2zncbKLsBXr6irq+/C1e65TPBgoLn5Rh DZaoHlElViu/IraQblBMc9HvuDxn+kswuu3Yino= X-Received: by 2002:ac8:3fd4:: with SMTP id v20mr5104744qtk.210.1601692577156; Fri, 02 Oct 2020 19:36:17 -0700 (PDT) Received: from independence.bos.jonmasters.org (Boston.jonmasters.org. [50.195.43.97]) by smtp.gmail.com with ESMTPSA id e1sm2547440qtb.0.2020.10.02.19.36.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Oct 2020 19:36:16 -0700 (PDT) Subject: Re: Litmus test for question from Al Viro To: Alan Stern , "Paul E. McKenney" Cc: 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 References: <20201001045116.GA5014@paulmck-ThinkPad-P72> <20201001161529.GA251468@rowland.harvard.edu> From: Jon Masters Organization: World Organi{s,z}ation of Broken Dreams Message-ID: <17935342-e927-284c-9a2b-ca75dd2398ad@jonmasters.org> Date: Fri, 2 Oct 2020 22:35:45 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20201001161529.GA251468@rowland.harvard.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Jon. -- Computer Architect