Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2955380ybx; Fri, 8 Nov 2019 11:49:40 -0800 (PST) X-Google-Smtp-Source: APXvYqzl+P9XbrDHxZKp9mSRCgMv9ztiZta1GaiKLVc9Q4U3n8MQZyCK1LzUUiWDgtVf0P/72rXb X-Received: by 2002:a17:906:6d8a:: with SMTP id h10mr10574150ejt.224.1573242579959; Fri, 08 Nov 2019 11:49:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573242579; cv=none; d=google.com; s=arc-20160816; b=hQKWmY9aN4YBEsWRO6QY/ya3Oqd7AxeKTAJ5IDybN/1xWwI0LI87eWE4Cy6cjNxS8l WJyl6jHHLiXG2dzhl3ttvmjyn5JZHhnGG8/BVrZX/jxweHrcLcZk67N2Em/E/TOzlaym UztYASkT05j42huoLyDvk65QLfNO3G740cJm4hKGOTEMvu3UwR9s3zZ82+zWksR9iJdO TDsdGGNDvHr4TTjvYtTyJc9EE65BehrY7kxCnGEW1mP+tNFF+Ip4QdWKcFSuEDCxTh/E i7oSZYdigCbibML5YYv/qocB8uaBGPFTh3l2vFy0W4F8niPvQfNtArBDA/oaLrQGfBbE BqqQ== 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=KyD23O5RyQ9n1+J0Rmot/Yfd1nJUcElECbIwZO2sFUA=; b=vKdDP9KEQNrDnLqv0CtHF6AfaVOaSmMnABaX69EyePwmBXMFwc/2VzZcleRCMwZxWo XJjY3LFVezmsSWVtl7Y/uwqKegNpr3kx1+dAWyAPXCMOEPduqcsuOgFAIZzB5n+t7mFG gW2K6j9mpT8mFdOIpMBaPzlDASAVioMYZOgkvnBVqbjTtMWAxlEsZpNet7LkAkXYb6LR sjs0kgZ/Z0KYOh8sGssrgq3gg1HBDJXG5VNgBe0NiXuTZwREvT7XbrsL20Znfyk4y+WF WWqhvyWQY0i9St+Al+oauWzQ3ZJOMkncSM3DpWMeMdRzyTmDLFTxJrvha8jVsQSyMJL4 hLxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=iIBxTZqz; 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 jp18si4235958ejb.318.2019.11.08.11.49.15; Fri, 08 Nov 2019 11:49:39 -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=iIBxTZqz; 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 S1732517AbfKHTsn (ORCPT + 99 others); Fri, 8 Nov 2019 14:48:43 -0500 Received: from mail-vk1-f196.google.com ([209.85.221.196]:33116 "EHLO mail-vk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732164AbfKHTsn (ORCPT ); Fri, 8 Nov 2019 14:48:43 -0500 Received: by mail-vk1-f196.google.com with SMTP id p68so1784842vkd.0 for ; Fri, 08 Nov 2019 11:48:42 -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=KyD23O5RyQ9n1+J0Rmot/Yfd1nJUcElECbIwZO2sFUA=; b=iIBxTZqzi92g6E3Yd+VApnsY9O2aLhrUrjJDyu2FNmtAqJhtKqg9yQPrmivVsiGdep 9j+c77PItW7VOWrAT97M+gBlJcid/7ePvIViaxdRMEBZmSm3METY83Q8oDotAkHlZDM5 JeYJlqDx9lkFGcydbB/Ax0BFXw51MfaSzV/36KFZut4oPml6EHFphPLlvHKaxX2yKtNd 6PgJxUsaA2+dS+/5trHIJJA4OIcWuiUbPDIp8IIKlX1HLpncDNfbL7Tr/fSN1HCA0p3u YgCRctdIF2kayVb1LvN9OpqgemOupYdoxUf61EZQcFvDRCQDWUa3YTDEccRGoHgdUjRo 9W9g== 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=KyD23O5RyQ9n1+J0Rmot/Yfd1nJUcElECbIwZO2sFUA=; b=QTTJ6PHU1LyLJLgR+yFjQAzfsCtVTCZq3wJzC1rbcrfm2GCicVWdnRppgtyOimbvGC K0Fr36ifbodm2YYWOzbv99xi4T52E7R+Efj1T5j2Q5nIQaNY0jDn5oGavEprjzepyJjl qFXKaQheGmPby8e/rDcuGb8PskDgr/YXTiGgxK13Y8LvAZ9uEVv8BEAhGU2uJrxPQSam Pi/QJjIw8GRT11FxD6dY8oK2HuS715xp+Wwai1FfSxkxoBiT76ereGMb/kHZEYb9LaUw sGrCwJ4F2Y/XEP3MPcO909/w99RJ8saXoQt15OPV34f0YqKUSd0jMhuk+gFtDlIaaxBu 5Azg== X-Gm-Message-State: APjAAAUiRkxCTEaOh2ME2KJ/jLUc/8mCgcUMhJmJt8f+XE9i3+Jnp4Nq WTXENMKa0DXvcaHSgy8lhte0UW2cmP/jyczvPX0olg== X-Received: by 2002:a1f:8dc5:: with SMTP id p188mr8815941vkd.13.1573242521478; Fri, 08 Nov 2019 11:48:41 -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 20:48:29 +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:40, Linus Torvalds wrote: > > On Fri, Nov 8, 2019 at 10:16 AM Marco Elver wrote: > > > > 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. > > Ok, so we'd have to do this in terms of ATOMIC_WRITE(). > > One alternative might be KCSAN enhancement, where you notice the > following pattern: > > - a field is initialized before the data structure gets exposed (I > presume KCSAN already must understand about this issue - > initializations are different and not atomic) > > - while the field is live, there are operations that write the same > (let's call it "idempotent") value to the field under certain > circumstances > > - at release time, after all the reference counts are gone, the field > is read for whether that situation happened. I'm assuming KCSAN > already understands about this case too? It's not explicitly aware of initialization or release. We rely on compiler instrumentation for all memory accesses; KCSAN then sets up "watchpoints" for sampled memory accesses, delaying execution, and checking if a concurrent access is observed. We already have an option (currently disabled on syzbot) where KCSAN infers a data race not because another instrumented accesses happened concurrently, but because the data value changed during a watchpoint's lifetime (e.g. due to uninstrumented write, device write etc.). This same approach could be used to ignore "idempotent writes" where we would otherwise report a data race; i.e. if there was a concurrent write, but the data value did not change, do not report the race. I'm happy to add this feature if this should always be ignored. > So it would only be the "idempotent writes" thing that would be > something KCSAN would have to realize do not involve a race - because > it simply doesn't matter if two writes of the same value race against > each other. > > But I guess we could also just do > > #define WRITE_IDEMPOTENT(x,y) WRITE_ONCE(x,y) > > and use that in the kernel to annotate these things. And if we have > that kind of annotation, we could then possibly change it to > > #define WRITE_IDEMPOTENT(x,y) \ > if READ_ONCE(x)!=y WRITE_ONCE(x,y) > > if we have numbers that that actually helps (that macro written to be > intentionally invalid C - it obviously needs statement protection and > protection against evaluating the arguments multiple times etc). > > Linus Thanks, -- Marco