Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4410237ybx; Sat, 9 Nov 2019 15:11:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyiL5v61lfViIXtvdYLCJ/z9yTUX4e0AADwGx8QHzYkUwKWI1QFnWUpJZQHGK88sLWQkq7W X-Received: by 2002:a50:ac3c:: with SMTP id v57mr17934020edc.300.1573341117468; Sat, 09 Nov 2019 15:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573341117; cv=none; d=google.com; s=arc-20160816; b=02vLtYFPbcQwiDfdlY9Bg4AWVppZYJvB14LgzfDDaLwAS4ICB6tabYynJjBrU7nOLo o3N+Uo4U2TfiFzO40xUXsuYVcxKpxVy64tO1iOloPOBMkmbIqmNDG5FQ1a4pBoNn5E1K UA9L3XvuvtGK3JjurtCdDVdhBXCssM2ETGFISCFp/MdbfZopHAk55b60Yn8RojQetRh5 bLZOjuJL6FoTa1Qu1HgWtFCnB1WuyuA8GJQVIrWDsu0K3BQ5euoW87i9/fX6PqbkoWtc LYpSKykLD4DizyJKRtqMihrc0+9Ra8dckDfx5qU2g6EGcfIx3L82F6YXeg7oZMQRYUgH K2Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=um4HRUhasTfcfAN+MxxCw5aX6r/srqeSknF8VwG3Ac8=; b=wJlyM1KtLDM3CRYyJknfTl7nRyL8XebrH5gHQqBU9giaetcyyb2t8ldgmFBeqYYK3M BygfZ9AEhQbNXV/Qtt7mVLvje5K+5XA7tzaHDKVCN9j9r7PZ0dY6b+v7sr99uc8VdQUD 0heBAlm+mTvWCWXC9pXcjA2r4/N293sKHBL6xvSw2Pcqvk6PBjYpKw7mzSa+Z8XHu30l zdo4DM9GDjsAhXCZDUsEtMgRcswRXlfUT1S36eNsx+I1O10Ko7nPVAgRH6PNFdHeeQnS lEco2worA30K+5fXPs0jxyeHplPbGYa/s+L8awYeyvxo9/zHssE6NrpTlfhnkCZ5nP/m De/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a11si9668474edj.143.2019.11.09.15.11.34; Sat, 09 Nov 2019 15:11:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbfKIXIZ (ORCPT + 99 others); Sat, 9 Nov 2019 18:08:25 -0500 Received: from netrider.rowland.org ([192.131.102.5]:54221 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726591AbfKIXIZ (ORCPT ); Sat, 9 Nov 2019 18:08:25 -0500 Received: (qmail 31724 invoked by uid 500); 9 Nov 2019 18:08:24 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 9 Nov 2019 18:08:24 -0500 Date: Sat, 9 Nov 2019 18:08:24 -0500 (EST) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Linus Torvalds cc: Marco Elver , Eric Dumazet , Eric Dumazet , syzbot , linux-fsdevel , Linux Kernel Mailing List , syzkaller-bugs , Al Viro , Andrea Parri , "Paul E. McKenney" , LKMM Maintainers -- Akira Yokosawa Subject: Re: KCSAN: data-race in __alloc_file / __alloc_file In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 8 Nov 2019, Linus Torvalds wrote: > On Fri, Nov 8, 2019 at 1:57 PM Alan Stern wrote: > > > > Can we please agree to call these writes something other than > > "idempotent"? After all, any write to normal memory is idempotent in > > the sense that doing it twice has the same effect as doing it once > > (ignoring possible races, of course). > > No! > > You're completely missing the point. > > Two writes to normal memory are *not* idempotent if they write > different values. The ordering very much matters, and it's racy and a > tool should complain. What you have written strongly indicates that either you think the word "idempotent" means something different from its actual meaning or else you are misusing the word in a very confusing way. Your text seems to say that two operations are idempotent if they have the same effect. Compare that to the definition from Wikipedia (not the best in the world, perhaps, but adequate for this discussion): Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. For example, writing 5 to x is idempotent because performing that write multiple times will have the same result as performing it only once. Likewise for any write to normal memory. Therefore talking about idempotent writes as somehow being distinct from other writes does not make sense. Nor does it make sense to say "Two writes to normal memory are *not* idempotent if they write different values", because idempotence is a property of individual operations, not of pairs of operations. You should use a different word, because what you mean is different from what "idempotent" actually means. > But the point of WRITE_IDEMPOTENT() is that it *always* writes the > same value, so it doesn't matter if two different writers race on it. > > So it really is about being idempotent. Okay, I agree that I did completely miss the point of what you originally meant. But what you meant wasn't "being idempotent". > > A better name would be "write-if-different" or "write-if-changed" > > No. > > Again, you're totally missing the point. > > It's not about "write-if-different". > > It's about idempotent writes. Assuming you really are talking about writes (presumably in different threads) that store the same value to the same location: Yes, two such writes do not in practice race with each other -- even though they may satisfy the formal definition of a data race. On the other hand, they may each race with other accesses. > But if you do know that all the possible racing writes are idempotent, > then AS A POSSIBLE CACHE OPTIMIZATION, you can then say "only do this > write if somebody else didn't already do it". In fact, you can _always_ perform that possible optimization. Whether it will be worthwhile is a separate matter... > But that's a side effect of being idempotent, not the basic rule! And > it's not necessarily obviously an optimization at all, because the > cacheline may already be dirty, and checking the old value and having > a conditional on it may be much more expensive than just writing the > new value./ Agreed. > The point is that certain writes DO NOT CARE ABOUT ORDERING, because > they may be setting a sticky flag (or stickily clearing a flag, as in > this case). The ordering doesn't matter, because the operation is > idempotent. Ah, here you use the word correctly. > That's what "idempotent" means. You can do it once, or a hundred > times, and the end result is the same (but is different from not doing > it at all). Precisely the point I make above. > And no, not all writes are idempotent. That's just crazy talk. Writes > have values. By "writes have values", do you mean that writes store values? Of course they do. But it is clear from what you wrote just above that all writes _are_ idempotent, because doing a write once or a hundred times will yield the same end result. On a more productive note, do you think we should change the LKMM so that it won't consider two writes to race with each other if they store the same value? Alan Stern