Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2857222ybx; Fri, 8 Nov 2019 10:19:22 -0800 (PST) X-Google-Smtp-Source: APXvYqyUE6nxNEzKyxaRHTX/BdYD+lZ/7N4zrgRuVtkjBPekE8t8Qu/bSO8K3tfBO1MbF1UiQr82 X-Received: by 2002:a50:b6f8:: with SMTP id f53mr11826800ede.29.1573237162812; Fri, 08 Nov 2019 10:19:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573237162; cv=none; d=google.com; s=arc-20160816; b=I0MkHkxvt8pA+YKxMlCGRito9VtYRSQww6R4wkmMWlhaklx/Xlix5TIO9Q677JOcgf rzoJUGLAw0QPKOIJuqTZfYvGGH/XV3TR68UdEdLz8vaG5UBGvlc5tOambgyBnypvus4f s4W2c2Bhb/oyKAhqK0CfmLNenq8aF8XOqDJBpFh2aBPJC5ReeuRCbD4+x35iGICGu+b0 b+Mpo+1yasgANYfbu6Gv9mF7A3mUAaoViZ5TzcQKXPxI+gKTh47uTbdCZCembgFo/Dh6 xkGTsaz3+TUXnLbDiHQfR3weN/nKfB7aHP/XQf3KGk395Jn4ZQbp/4GD+bhowV1i9Hhg Xn8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5tUkPEobvq0D1LVe3HBgFyeSBazbNDJmhpV7AqtazYk=; b=kS41yqMkiRy2oc+qYHS5mwRMd8sxPq9xirMxE80IKICxC1WpzJ8ZzVfn0lpXZJH+sK ot3l8sW0f5nqeOWWS+qyD8/5N0aBcKpL2X91vqEmrh5/CyKpWtSziHudncqkiYfE1H0B X4IaaqQLZYYAlgqM7IQVAODUmrnUrC5gzFFKvr7kBGwM+yQ7AUskp3UjVAOmzD2HMf/s iIxs6Na0Ee8IEGFZaAGYr1Be+JgVjQDYcsKgrQsT1hXNHrsxHatoJZkjrg2/y7+zqwao 4I30PRwCI2sOWrqYFnMgGR3u/JC1fiYBQgkM/wQR3Tt8zcf3ksoTvpn2F//A5PWmRrD/ Lcww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eOjJlMG+; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h5si5084689edj.25.2019.11.08.10.18.59; Fri, 08 Nov 2019 10:19:22 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=eOjJlMG+; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729075AbfKHSQL (ORCPT + 99 others); Fri, 8 Nov 2019 13:16:11 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:41576 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728235AbfKHSQL (ORCPT ); Fri, 8 Nov 2019 13:16:11 -0500 Received: by mail-oi1-f193.google.com with SMTP id e9so6040077oif.8 for ; Fri, 08 Nov 2019 10:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5tUkPEobvq0D1LVe3HBgFyeSBazbNDJmhpV7AqtazYk=; b=eOjJlMG++cIiJCf+41ocgxmN10k5xlvB3wJ0CksO002FTLGIfa1fJAK3O6Jkuvb+fx PoYCLNW6D9YGSl/MRBgAgccJM9ZYaMcSWBKOR7v209fCgig2SLt9Ica4sc8EHdCSh8XH Ux1kOwoLofwMYcXkC1qfLwNF+V8nJ+gsHx/B6VSj99yDTpBiHFF7QN7BQjdI0F/qpINc 9OuIsii0Utk16W6qPPnOPqVSFO9J2+ryFGyMIdT+r6lw0e2eERLZDQDBX+lKlXDdfOG5 5aoWOUYIE9AeSKenvkd6IZDEUieVABlwMtLu3qTnx16lM/SXZWP7UC29idEKMbV/UIQM LPug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5tUkPEobvq0D1LVe3HBgFyeSBazbNDJmhpV7AqtazYk=; b=TBNMc6e4knf2XEgt9AzMx/UFr2JaVGzo6QTZbaDL6DeKE3+GXrGLtYeakjl9ATB6FO uEPrhj3d/SrxXYfZRXy0qtktDfR3fmM9yy0k89rCaWc8qpF/zTZFFZCXIxoYt/iiuJRX 4Z+PXG83UwfpLux7SKaUYYiUHcpPfCI/rrm5aspJLpCagkrVK1mfHFGVYLamiXIecFDE 2qZimB5lrIduecHcwhH9HztF17Oy09xkp8puncDbngbu1DJLttExHhyQjFf2F0J/eGnV +faEYMpnYjfFceQUzLL2FC15tBwTefkozBzVPiovUtjwLJmvBZa49W7kwGFSXeeSxv+B kgKw== X-Gm-Message-State: APjAAAWJSBv+yjIqF+uM1FO/mtGUwwmZNU5tda2bpddMZWaTUAEkbn2U lCOHq/GC+pK7f6AzWu0ga9urAJPrGPNGOEwRGW+3Kw== X-Received: by 2002:aca:fc0d:: with SMTP id a13mr10989363oii.83.1573236969814; Fri, 08 Nov 2019 10:16:09 -0800 (PST) MIME-Version: 1.0 References: <000000000000c422a80596d595ee@google.com> <6bddae34-93df-6820-0390-ac18dcbf0927@gmail.com> In-Reply-To: From: Marco Elver Date: Fri, 8 Nov 2019 19:15:58 +0100 Message-ID: Subject: Re: KCSAN: data-race in __alloc_file / __alloc_file To: Linus Torvalds Cc: Eric Dumazet , Eric Dumazet , syzbot , linux-fsdevel , Linux Kernel Mailing List , syzkaller-bugs , Al Viro , Alan Stern , Andrea Parri , "Paul E. McKenney" , LKMM Maintainers -- Akira Yokosawa Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 8 Nov 2019 at 19:05, Linus Torvalds wrote: > > On Fri, Nov 8, 2019 at 9:53 AM Eric Dumazet wrote: > > > > I personally like WRITE_ONCE() since it adds zero overhead on generated code, > > and is the facto accessor we used for many years (before KCSAN was conceived) > > So I generally prefer WRITE_ONCE() over adding "volatile" to random > data structure members. > > Because volatile *does* have potentially absolutely horrendous > overhead on generated code. It just happens to be ok for the simple > case of writing once to a variable. > > In fact, you bring that up yourself in your next email when you ask > for "ADD_ONCE()". Exactly because gcc generates absolutely horrendous > garbage for volatiles, for no actual good reason. Gcc *could* generate > a single add-to-memory instruction. But no, that's not at all what gcc > does. > > So for the kernel, we've generally had the rule to avoid 'volatile' > data structures as much as humanly possible, because it actually does > something much worse than it could do, and the source code _looks_ > simple when the volatile is hidden in the data structures. > > Which is why we have READ_ONCE/WRITE_ONCE - it puts the volatile in > the code, and makes it clear not only what is going on, but also the > impact it has on code generation. > > But at the same time, I don't love WRITE_ONCE() when it's not actually > about writing once. It might be better to have another way to show > "this variable is a flag that we set to a single value". Even if maybe > the implementation is then the same (ie we use a 'volatile' assignment > to make KCSAN happy). (+some LKMM folks, in case I missed something on what the LKMM defines as data race.) KCSAN does not use volatile to distinguish accesses. Right now READ_ONCE, WRITE_ONCE, atomic bitops, atomic_t (+ some arch specific primitives) are treated as marked atomic operations. The goal is to cover all primitives that the LKMM declares as marked/atomic. A data race is then detected for concurrent conflicting accesses where at least one is plain unmarked. In the end the LKMM should decide what KCSAN determines as a data race. As far as I can tell, none of the reported data races so far are false positives in that sense. Many thanks, -- Marco