Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2456496ybc; Wed, 13 Nov 2019 14:51:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwB4p4GHGb5HUAWf98/aIUuT4mSNeIltmWs3KKyfXps/i0ZrdT+E5iYCHFw+wdnRVbGsSwW X-Received: by 2002:a05:6402:4c5:: with SMTP id n5mr6615899edw.157.1573685493555; Wed, 13 Nov 2019 14:51:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573685493; cv=none; d=google.com; s=arc-20160816; b=UCmPL8VLaX+KrHgf/GFhOEKUfmRfvfA7VEkaTHuOw3MxWU6jILN76RuvuZqHxE6DFj Kl/4O1fqIbwNUJrxcTnjNgZUibEMgBVggrGT0m5ZYcUXyT3+CYym3zGr05MTjuEQDl/W Cu+yIfx2JVii+dRNANxR7tjKcLQXJxesgLLoOWQJTQtN1TYquwqRZmMlDyt96lTIN700 h56x86C/tP8ZfEtLoU5JRvxxmKkzlP0X11JrNm170U6C9nd4B3m4d58mM9VDQQn8pFBP DfJJJCfNArg4HbMelx8d/BSoWijuMo+6WH5xBD4wCJlz8w41+m14GhMan0i9efe92RPA Zb1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lZTpS2joYk+fUmESBGaQbCu+yB8VwBrfz0zrdA9q1TQ=; b=swUL4gv5lRZ0RFQLUAJVpuTSlN3fOaPevKWoHqPLb300c1gyvXhr4ALTr6T+ujVlYv tDX+ElL8G6/sUcm15rT3iGKewg1CJFcZlwq9Vkmcbfn980kUPL029o2nYL50VI+BXVaC bICMJCwY5YkiH11jGT/Hg7H8I21FGKuZ9mNS//E0tvqmTaHamG50FSj7McwswD4LCYm3 sHXK5bq70PywY44DCYfrB1YgplylGvQZ7DjBmiZgUTygUIL/0/KmGIgFelc6ujPSIyT4 n5VQx/YxiZhnTkng4E36EXNWmo5ULPc8w9sAP7GsZGg1F6ziyFRaKgynj2PdxwBqkver K69g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=BzjIduan; 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 n2si2236859ejx.38.2019.11.13.14.51.09; Wed, 13 Nov 2019 14:51:33 -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=BzjIduan; 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 S1726528AbfKMWsR (ORCPT + 99 others); Wed, 13 Nov 2019 17:48:17 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:35185 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbfKMWsR (ORCPT ); Wed, 13 Nov 2019 17:48:17 -0500 Received: by mail-wr1-f66.google.com with SMTP id s5so4288639wrw.2 for ; Wed, 13 Nov 2019 14:48:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=lZTpS2joYk+fUmESBGaQbCu+yB8VwBrfz0zrdA9q1TQ=; b=BzjIduangPFvAzZWgR203MjIM7WWi0HEh94XzWGlBunGkjxbJV1Zb2XDd0K0Q5XjiG ImPnXGqv6nIpyOuNTdvhk8IXCAF96XveyxUFVxTlMHJZzhL2jGsSPcMWFb3i+uFgnoY4 PES0M9eDn+cmqL+60VQQsXI3NArqGkEfkq4gY9q0HsYCWuLwSIUOGmSf4B2iY5awX7Z3 mWacf2zQyuAFyeVaYr1cnmKKDmGfJ6ZoV0zjlZHzV/TyDl2LK9ev5EIfC1dCGDv2FZc+ PWH/mh8PT+a84SywJNRMstDzBKvK70cxyXhjK1fbiUp/1yXBPISA494u9cOq8B9BOOct UdXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=lZTpS2joYk+fUmESBGaQbCu+yB8VwBrfz0zrdA9q1TQ=; b=KzLaNfXkhGQTBk3lIn3xKZwFfKTGjFmFZIdyT1rjMPseRge0GFutUeoPkBIMU+dj1a EgWK/Kk2tg6AfLwvYwYtMMcEOFN7Zk+W8xPWOdDCxpueFxnGdNsu3AmqT7AxVddpuaey GBypTMPEwqkIG+wcT2wpteeypwiVFeNwaDM78Z0so5mWe5IqvJbHg0MJ8SVxhRuZszHG Vq4PQUdNi7LupEHg03IR0MjTnrLXURORtNuI1dIkN/BX0RSy6HUz8rr1w9Y5SALLFA5M tPaGhfV9IDwRtBLt/4/agKdj7WlfeU83ICmx8BEGyJTwgkZTToN5slnhxQYXAbTk/8pj d7Sg== X-Gm-Message-State: APjAAAXz3rvJ+qBs7Rrk7VlUpfBiZHKrtcRVk4hKJwJhbTjyUSM3/G/w VzMi93GIQOEgL3Q8bB5n9n2c9w== X-Received: by 2002:a5d:6a4c:: with SMTP id t12mr5444884wrw.141.1573685294877; Wed, 13 Nov 2019 14:48:14 -0800 (PST) Received: from google.com ([100.105.32.75]) by smtp.gmail.com with ESMTPSA id v9sm4447145wrs.95.2019.11.13.14.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 14:48:13 -0800 (PST) Date: Wed, 13 Nov 2019 23:48:08 +0100 From: Marco Elver To: Alan Stern Cc: Linus Torvalds , Eric Dumazet , Alexei Starovoitov , 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 Message-ID: <20191113224808.GA3960@google.com> References: <20191113213336.GA20665@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 13 Nov 2019, Alan Stern wrote: > On Wed, 13 Nov 2019, Marco Elver wrote: > > > An expression works fine. The below patch would work with KCSAN, and all > > your above examples work. > > > > Re name: would it make sense to more directly convey the intent? I.e. > > "this expression can race, and it's fine that the result is approximate > > if it does"? > > > > My vote would go to something like 'smp_lossy' or 'lossy_race' -- but > > don't have a strong preference, and would also be fine with 'data_race'. > > Whatever is most legible. Comments? > > Lossiness isn't really relevant. Things like sticky writes work > perfectly well with data races; they don't lose anything. > > My preference would be for "data_race" or something very similar > ("racy"? "race_ok"?). That's the whole point -- we know the > operation can be part of a data race and we don't care. Makes sense. Let's stick with 'data_race' then. As Linus pointed out this won't yet work for void types and if-statements. How frequent would that use be? Should it even be encouraged? I'll add this as a patch for the next version of the KCSAN patch series. Thanks, -- Marco diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 0b6506b9dd11..a97f323b61e3 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -308,6 +308,26 @@ unsigned long read_word_at_a_time(const void *addr) __u.__val; \ }) +#include + +/* + * data_race: macro to document that accesses in an expression may conflict with + * other concurrent accesses resulting in data races, but the resulting + * behaviour is deemed safe regardless. + * + * This macro *does not* affect normal code generation, but is a hint to tooling + * that data races here are intentional. + */ +#define data_race(expr) \ + ({ \ + typeof(({ expr; })) __val; \ + kcsan_nestable_atomic_begin(); \ + __val = ({ expr; }); \ + kcsan_nestable_atomic_end(); \ + __val; \ + }) +#else + #endif /* __KERNEL__ */ /*