Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6251997ybx; Mon, 11 Nov 2019 06:22:11 -0800 (PST) X-Google-Smtp-Source: APXvYqzCxQnogapNJcJ1GNbOZPQ8eJa8x6Qw5h/Vy6lBPj70s+y8Ulrd17qXnEgKN8JRy8ailug1 X-Received: by 2002:aa7:d0ce:: with SMTP id u14mr25975741edo.225.1573482131754; Mon, 11 Nov 2019 06:22:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573482131; cv=none; d=google.com; s=arc-20160816; b=z/u4pIbeF/U9zuWRkRdCUodLrRI1sgF9zmFnhAKKiQwAhaJiFcCM6iV2VA1UAv6n9g hWWm3NS3Pz7FggUDsN3VDmD5YYpkgidugojbNFOlDaw6Npd/7GfvXUeWm+3S4bMuTY3d QSgimcsvN4vnYH5uVcebC5Zu73m0iQwlpbnNJ/rlXNY+FkuzTXRCQiAspQX/qRXMKS8j gB/YPdqb0F71uzjhJyOZ+KMkKV5kWlDSKe/GCrlq/1PChThb+Sd/2LtxmsImL59VQNx4 2Ov9CiCKb9Piua2y6XRnTsD97SN2gKhMNAUSSYsZCrvv6blu9ejnLlYDPJEdaTpomZCj c7NQ== 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=h0W1n0b934oa9x92tev635siFZCltGl2D+xamCm39z0=; b=uRWlr0H/b8KIt1bqB5k8leh7LcK+oFrJUDPefPP9fmg2udhwEMGEBCCmjvvwKtkC3n EZjBEWs5KZ3TEgnlnhHCV4gReMIyyyLz2RIC4DXu7ZKvAcfAwLRJMmHbD+naWa9nD7yj 4wUXAO2QzV9gAPYYevtxV6hHowp4lDNvT6k7T7Gj2k8+QgFkA6baeojTU5gC5Lpz0eZE 4mwXdL3r3KBwBv5o5LEHyK9E93US36DuPR9cbzn51KawJ6T4Q3tR6AwIUMi+MDcN0a0J Du05YIWC+Fpyqoj89PJxSFP4g+a5jZu4/LpKKVPVZbBzJjtTqdlZvQadZIeImUyk+uVe 7Y6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dwlafrN5; 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 m20si9189532ejx.33.2019.11.11.06.21.46; Mon, 11 Nov 2019 06:22:11 -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=dwlafrN5; 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 S1726994AbfKKOSH (ORCPT + 99 others); Mon, 11 Nov 2019 09:18:07 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:44225 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726834AbfKKOSH (ORCPT ); Mon, 11 Nov 2019 09:18:07 -0500 Received: by mail-ot1-f65.google.com with SMTP id c19so11297671otr.11 for ; Mon, 11 Nov 2019 06:18:06 -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=h0W1n0b934oa9x92tev635siFZCltGl2D+xamCm39z0=; b=dwlafrN5wf9ZIU+8HnaHXgZxiE2WQoT2x13HIzNXh13AVC2z3WLTG/MDiHDkrI9DLI HtQNz8QlSzy6fLSGhikfiPTKLrcsgsN9aGBQShDYal54qTdyehcCHU2vWo/9MjyZUuad oj22/sOn27ZMo4QbsiE1ldiPe95t4pY5hCRyAoI3IaepW5H3a7dXwX0aolfiFAVR4M+I SEtyClMYBDLUyznNvnNoQDY9NQT+NXdQPZo6OB6N/UshLDbhAwwuW2zX+zZKj2C5nGbG bNY6gOTRehHoOIDsL8aWekzTNutrCox1p1heqVt36+Y/jUV6fXtDPfKfnhS6uSzqI/XL w84g== 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=h0W1n0b934oa9x92tev635siFZCltGl2D+xamCm39z0=; b=IHcq537AFUmkCifs6wb16zwof0SZnIyPrjrRRG12wzhPur6WNhydM28/tiY9Dkz0tl KHkW/f0MRqKbijjMmMNhOkjc58Ueo61GwAipvILTSk+EBK0woJA3K4oNfoVvu+ajhcty Ug5bfT7OKBJX2CO/F6e8PuzD/Bx7KgdSW6PSMbV2Hdw/x/7P8qt7M/8VTQr9TV2jdEBA 7eUdBeQvNcqtPl8///73jSppMSVdPTdkYaJf0ghPZ7EmnnGPb6rI3k1Uhv5MvGD1215Z BdZBVmLlZPfdQnqI4CIGz65cVOq1gmoalW7Q9Vh68V3gxC4o7js29cTlNm5TVufPoxFx 4PnQ== X-Gm-Message-State: APjAAAVYcey2z06Zlz+vYkaMODJ2m2w70HwgrZh5FYti/lueoOxRGZkC jqyHM9MaEHzBNSotdAxRRm3ii4qNWwDoBwVpPML1eA== X-Received: by 2002:a9d:7308:: with SMTP id e8mr22346700otk.17.1573481884676; Mon, 11 Nov 2019 06:18:04 -0800 (PST) MIME-Version: 1.0 References: <20191110204442.GA2865@paulmck-ThinkPad-P72> In-Reply-To: <20191110204442.GA2865@paulmck-ThinkPad-P72> From: Marco Elver Date: Mon, 11 Nov 2019 15:17:51 +0100 Message-ID: Subject: Re: KCSAN: data-race in __alloc_file / __alloc_file To: "Paul E. McKenney" Cc: Linus Torvalds , Alan Stern , Eric Dumazet , Eric Dumazet , syzbot , linux-fsdevel , Linux Kernel Mailing List , syzkaller-bugs , Al Viro , Andrea Parri , 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 Sun, 10 Nov 2019 at 21:44, Paul E. McKenney wrote: > > On Sun, Nov 10, 2019 at 11:20:53AM -0800, Linus Torvalds wrote: > > On Sun, Nov 10, 2019 at 11:12 AM Linus Torvalds > > wrote: > > > > > > And this is where WRITE_IDEMPOTENT would make a possible difference. > > > In particular, if we make the optimization to do the "read and only > > > write if changed" > > > > It might be useful for checking too. IOW, something like KCSAN could > > actually check that if a field has an idempotent write to it, all > > writes always have the same value. > > > > Again, there's the issue with lifetime. > > > > Part of that is "initialization is different". Those writes would not > > be marked idempotent, of course, and they'd write another value. > > > > There's also the issue of lifetime at the _end_ of the use, of course. > > There _are_ interesting data races at the end of the lifetime, both > > reads and writes. > > > > In particular, if it's a sticky flag, in order for there to not be any > > races, all the writes have to happen with a refcount held, and the > > final read has to happen after the final refcount is dropped (and the > > refcounts have to have atomicity and ordering, of course). I'm not > > sure how easy something like that is model in KSAN. Maybe it already > > does things like that for all the other refcount stuff we do. > > > > But the lifetime can be problematic for other reasons too - in this > > particular case we have a union for that sticky flag (which is used > > under the refcount), and then when the final refcount is released we > > read that value (thus no data race) but because of the union we will > > now start using that field with *different* data. It becomes that RCU > > list head instead. > > > > That kind of "it used to be a sticky flag, but now the lifetime of the > > flag is over, and it's something entirely different" might be a > > nightmare for something like KCSAN. It sounds complicated to check > > for, but I have no idea what KCSAN really considers complicated or > > not. > > But will "one size fits all" be practical and useful? > > For my code, I would be happy to accept a significant "false positive" > rate to get even a probabilistic warning of other-task accesses to some > of RCU's fields. Even if the accesses were perfect from a functional > viewpoint, they could be problematic from a performance and scalability > viewpoint. And for something like RCU, real bugs, even those that are > very improbable, need to be fixed. > > But other code (and thus other developers and maintainers) are going to > have different needs. For all I know, some might have good reasons to > exclude their code from KCSAN analysis entirely. > > Would it make sense for KCSAN to have per-file/subsystem/whatever flags > specifying the depth of the analysis? Just to answer this: we already have this, and disable certain files already. So it's an option if required. Just need maintainers to add KCSAN_SANITIZE := n, or KCSAN_SANITIZE_file.o := n to Makefiles, and KCSAN will simply ignore those. FWIW we now also have a config option to "ignore repeated writes with the same value". It may be a little overaggressive/imprecise in filtering data races, but anything else like the super precise analysis involving tracking lifetimes and values (and whatever else the rules would require) is simply too complex. So, the current solution will avoid reporting cases like the original report here (__alloc_file), but at the cost of maybe being a little imprecise. It's probably a reasonable trade-off, given that we have too many data races to deal with on syzbot anyway. Thanks, -- Marco