Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1086001ybc; Tue, 12 Nov 2019 14:06:48 -0800 (PST) X-Google-Smtp-Source: APXvYqzJz4m/kI6ugzPGMtyIaNf1ukouD3JNAwFjPia0MlGhUSESWvwAedxQMfPKXBZdq7/n02Zq X-Received: by 2002:a50:ac3c:: with SMTP id v57mr34869039edc.300.1573596408680; Tue, 12 Nov 2019 14:06:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573596408; cv=none; d=google.com; s=arc-20160816; b=JlivXiqideONcnw6UURnzm3kpCU4wAEyrC1rEoEc5dWkz9sNqIgceMTVkHS3U69U2K MCRiRyMkjzXLzS3ZIc1nfpgFtMnRKWj3Uj6ny3tVNb195nBhssKVoSuSuykMe1XAoNwI EcV0Ld5ae2O9m7cLiR/Y8xSqQMw/wnsijaq3lIRECsHF8F4/43dshORySAMlnkk6fpve zkIeUMBHm+ri3k9er2sPMfGmhIzMe9Dp7Y8bGm92bciX0aRl1JrWzmCgXA+0WP6FlR1Y qvJqlwfLEaNk1L9l3FqvRfvOSdllJJJDhmKX+q5Dr1FEuXm87wSJ9iIrzSxBYRPDj2SD fVgQ== 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=I1Pi6yOs/csYC6W72VeZEeFbZQ4f19IItGzOeKWk0k4=; b=s3H2bRkD84M7lheZroxfOaRlgvNgtPbERdVR2MtPLhhoObGa7iWCGUeoaKzlDd4Vdv Jwzz49aPMGWfb2aq4GYYICKqDlrOA/a5c/GFqhKbWufLMOGj/00ds9ldrDO3UAAUDLYK L6s3XvbUqEDZvg0mTqpTmgY3RL9T/VzNKLYD31m+a1o4xKSrGa8uA//3PzlCTjd7Otac Iv3UOG5orACaIzCzpx9H7TNhuJRQPmf9xKd0OcCDE3MTKsQS6Aet9jRuDjkmDg4rmzfL X0mR6CvPKw3WbuY0mQFnWXUb/5wtT3Nc2OsUcM0wPbJs8X+Bu51mk2Ulb6x431mWV8NI 70UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pXARKt5T; 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 o5si896485ejn.123.2019.11.12.14.06.24; Tue, 12 Nov 2019 14:06:48 -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=pXARKt5T; 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 S1726973AbfKLWFl (ORCPT + 99 others); Tue, 12 Nov 2019 17:05:41 -0500 Received: from mail-ot1-f53.google.com ([209.85.210.53]:37140 "EHLO mail-ot1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbfKLWFl (ORCPT ); Tue, 12 Nov 2019 17:05:41 -0500 Received: by mail-ot1-f53.google.com with SMTP id d5so15772691otp.4 for ; Tue, 12 Nov 2019 14:05:41 -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=I1Pi6yOs/csYC6W72VeZEeFbZQ4f19IItGzOeKWk0k4=; b=pXARKt5T5Od7Y0qUkyoivMClA/o8lhR5dXBj2Fm/AC9pN9O7ok3a3Msm21JGwY60qX k4Eb3Sp0neG3JV3ruaQCVID3R+nN3u3mfPk/OhsCxZtu6jzzN4HgHgZonTFrZ+CGEd7A XZrp3NoJYL7RV2S21otE67mgwDFaFGZ7QVYOE/71MK+OLX9rK3ZJwculoQaR02oggnwK 16NZRugVc3dzaPCD0zWW7/zXRkIAEA4rHojuloW4UeREDiJBBtB7Z7w00wqet2rnKdWB ovpcg9YkG55nvec27JjiclWiYbUda+AMDzzh+z3pfT/IA610wqb+Z00AOmmJx7787y4X X5RQ== 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=I1Pi6yOs/csYC6W72VeZEeFbZQ4f19IItGzOeKWk0k4=; b=OCpxOvGzHvJRcFghh6FcGNAAFNkwIXZdvbSC6INhmWExzfn7qc6shQl3jjGJ3Fq2iI E3brP/Jq4x7MdramIpK6SVsgvoGBUbzxr6dkVEzh553wZGMIuFZpA3ZsADGMIJTrde6l P5SGt9ufO9QlFCbJerf0X0fFbYhrKRw9cHitnLxp2hOFKn1D5+TueVsGqs+rmsOmr71f JJd0cEmiQxN8jLGC+PixfcsyuNUK1OkwdQqSXNLLeL4Vjbf2vJiJWDaqbf8Rd6J2hN/0 J08zclbie6xePHAbIAf2sFFjmqsd51OSo9CdepEjIR6DRKRkk8Jx6NlbIF065lyoSuvq X3uw== X-Gm-Message-State: APjAAAXbxs1aKiGuFCiAALlWwrR7pAIYvgkYIulmmv/EVXxdUZr7iUT6 Al1VwjVDlKjRXMQjEy5lRqulGpaxXSUGHXeqb0YkNA== X-Received: by 2002:a9d:82e:: with SMTP id 43mr23431901oty.23.1573596340012; Tue, 12 Nov 2019 14:05:40 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Marco Elver Date: Tue, 12 Nov 2019 23:05:27 +0100 Message-ID: Subject: Re: KCSAN: data-race in __alloc_file / __alloc_file To: Linus Torvalds Cc: Alan Stern , Eric Dumazet , Eric Dumazet , syzbot , linux-fsdevel , Linux Kernel Mailing List , syzkaller-bugs , Al Viro , 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 Tue, 12 Nov 2019 at 22:13, Linus Torvalds wrote: > > On Tue, Nov 12, 2019 at 12:58 PM Linus Torvalds > wrote: > > > > Honestly, my preferred model would have been to just add a comment, > > and have the reporting tool know to then just ignore it. So something > > like > > > > + // Benign data-race on min_flt > > tsk->min_flt++; > > perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, address); > > > > for the case that Eric mentioned - the tool would trigger on > > "data-race", and the rest of the comment could/should be for humans. > > Without making the code uglier, but giving the potential for a nice > > leghibl.e explanation instead of a completely illegible "let's > > randomly use WRITE_ONCE() here" or something like that. > > Hmm. Looking at the practicality of this, it actually doesn't look > *too* horrible. > > I note that at least clang already has a "--blacklist" ability. I > didn't find a list of complete syntax for that, and it looks like it > might be just "whole functions" or "whole source files", but maybe the > clang people would be willing to add "file and line ranges" to the > blacklists? > > Then you could generate the blacklist with that trivial grep before > you start the build, and -fsanitize=thread would automatically simply > not look at those lines. > > For a simple first case, maybe the rule could be that the comment has > to be on the line. A bit less legible for humans, but it could be > > - tsk->min_flt++; > + // Benign race min_flt - statistics only > + tsk->min_flt++; // data-race > > instead. > > Wouldn't that be a much better annotation than having to add code? Thanks for the suggestion. Right now I can't say what the most reliable way to do this for KCSAN is. Doing this through the compiler doesn't seem possible today, but is something to look into. An alternative is to preprocess the code based on comments somehow. How many variations of such comments could exist? If it's only one or two, as a counter suggestion, would a macro not be more reliable? A macro would provide a uniform way to document intent, but could otherwise be a no-op. The tool would have no problems understanding the macro. For example "APPROX(tsk->min_flt++)" or something else that documents that the computation can be approximate e.g. in the presence of races. Thanks, -- Marco