Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp737869pxk; Thu, 1 Oct 2020 12:33:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwS+/az+MKXyS4akYQKbjpNyNBvjx8UOJjibZD5/pP/QwH/8YZK4YpbtyVByNs4lQ0Zq+ow X-Received: by 2002:a17:906:1157:: with SMTP id i23mr10198276eja.440.1601580831763; Thu, 01 Oct 2020 12:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601580831; cv=none; d=google.com; s=arc-20160816; b=FyrnDEHHNGu4ZcmS8xqBdVc+5ExW90VN4gDzcLc+DfOn/42kamOdjox4ikZGCwiUsx EGu9qi9/8gnLLAsJuDdgc6Myw4CQL/4+GFzN2Y6kBXMyZUqPgz/CB8keW7Qjy6uXlx/c iVB0rhYyttZ0e6ldQIUB3RITIXCj5GHZIk1NmZzJqCYL5jysz87wkqkdkwzBBqj59zvR b7u/WY2RBnj0Jm/11m12k51thZFS96hkpbUx9OnFXyQwCcT0OmTOnivRviSiEH5pqD2x k5JtkWjWAy5csENf3bvQ4eD0nhhAEymHYDsgVxfHdYZOOmL9Hz4kaQAuCxw/SrM+MWfX 0pwg== 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=C3Lm8NWS1yXN2P2iqK6/82wuNVjX5mEThtNI1ktK6y0=; b=GXpD3w/e8HHKtM6UqK4m3wF2HjHiD6ac6m3GcpXafTaG/tgTntlS0cM03/F4FN/KSL u2Q7N6D7Jwno6d2bn/LlGDVOWNL503DyRaabTKdlQDYONrMLQpsJK/+8bQJANbh5gtTr JS46dcSaIiu7Uf0+62GJWnJYDbTodh1Kzdqa8yC7lKWcx/89RF8Hxdl/idaVCoFoc3je 3FEe2GayGzeVWE19aV2dMPCj65Og9hmXoSXFK+xR2DMavKiBXTPCWilOXh/WEZZj8VEc ZTzsiL1wFMVRx9eJaCZoWiyrHHYzo2Yo1lH3PeMkEP45Fznr/sVIx21o6NYutSnwX2z8 U1UQ== 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 cn3si4693994edb.282.2020.10.01.12.33.27; Thu, 01 Oct 2020 12:33:51 -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 S1730093AbgJATaP (ORCPT + 99 others); Thu, 1 Oct 2020 15:30:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729993AbgJATaP (ORCPT ); Thu, 1 Oct 2020 15:30:15 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F334FC0613D0; Thu, 1 Oct 2020 12:30:14 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kO4H8-00A0dq-BS; Thu, 01 Oct 2020 19:29:58 +0000 Date: Thu, 1 Oct 2020 20:29:58 +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: <20201001192958.GH3421308@ZenIV.linux.org.uk> References: <20201001045116.GA5014@paulmck-ThinkPad-P72> <20201001161529.GA251468@rowland.harvard.edu> <20201001163646.GG3421308@ZenIV.linux.org.uk> <20201001183925.GA259470@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201001183925.GA259470@rowland.harvard.edu> Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 01, 2020 at 02:39:25PM -0400, Alan Stern wrote: > The problem with a plain write is that it isn't guaranteed to be atomic > in any sense. In principle, the compiler could generate code for CPU1 > which would write 0 to V->A more than once. > > Although I strongly doubt that any real compiler would actually do this, > the memory model does allow for it, out of an overabundance of caution. Point... OK, not a problem - actually there will be WRITE_ONCE() for other reasons; the real-life (pseudo-)code is spin_lock(&file->f_lock); to_free = NULL; head = file->f_ep; if (head->first == &epitem->fllink && epitem->fllink.next == NULL) { /* the set will go empty */ file->f_ep = NULL; if (!is_file_epoll(file)) { /* * not embedded into struct eventpoll; we want it * freed unless it's on the check list, in which * case we leave it for reverse path check to free. */ v = container_of(head, struct ep_head, epitems); if (!smp_load_acquire(&v->next)) to_free = v; } } hlist_del_rcu(&epitem->fllink); spin_unlock(file->f_lock); kfree(to_free); and hlist_del_rcu() will use WRITE_ONCE() to store the updated forward links. That goes into ep_remove() and CPU1 side of that thing is the final (set-emptying) call. CPU2 side is the list traversal step in reverse_path_check() and in clear_tfile_check_list(): // under rcu_read_lock() to_free = head; epitem = rcu_dereference(hlist_first_rcu(&head->epitems)); if (epitem) { spin_lock(&epitem->file->f_lock); if (!hlist_empty(&head->epitems)) to_free = NULL; head->next = NULL; spin_unlock(&epitem->file->f_lock); } kfree(to_free);