Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp183656ybn; Tue, 24 Sep 2019 20:57:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEwb/RIW+Z4C++661o/yw3eXtGxtVNAWt8W7uYf7L10RItnqrMIrFPv+Y37/WMAMRCe4FE X-Received: by 2002:a1c:cb83:: with SMTP id b125mr4822500wmg.43.1569383825891; Tue, 24 Sep 2019 20:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569383825; cv=none; d=google.com; s=arc-20160816; b=yc5xUTHl0qAlE7iXittcioYcOWHripXPzuP8a3PUO7QzjdVQgkf1pdpqhiwDWz1s49 P3XS6hsxMp0t0HdI16KQZf1tCuHPs1foulyyEtO5DvJyesAPfpiyIR0mzDt3OFzlc8Cs zWcyW80x8hmb2YtY25I+xY7DdJ9M6xFeTB/t4nWFfy2YQ2QfABdljo10Zc4WH3aelAAt snoqCp5LKaXd+AJkgKVQJB+qHtxNZK6tDwoAL/Zq6fyqruKrGb7asrLgxibdhyVdvNMd +i6U8KmcyB8/8E8HBgY5LydR6X1gRnPdlYPtS3iYZtcg32PxZZQ2psL9TEKtfiLxcJYo e2hg== 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=4QM9p6JUL1H2+7ufpY9lHAHlLiqvaNnzuQlbpSFc8tM=; b=AH/IfjwLyOiGfxDmkG1oWzdg8u9Fq8IWWGeZXMW98tcWl44QUUSSsXDJWlD9kPF7y8 jEg1B5sG0NloNIFbGvBWQ7GLe5PSCTMht0Wk9JZm1zQ9JqWi4luFIfUpASL51AYlfyZR IYtBK9zedzyKKgA6mqKzW51K2AFC8nkTypda3hdPqPLyc+zih4UVjqzvC5cMggYnKUBT EoZQ03gxhZHrQhtuu0tnfyGRTbwkPfZSctt8l9ERKf3LXt3Cl7fd/kmZcQutqbAkeHQA XmBCYafp05Eu9uZHKMOWZE0hi/vw5QGVq69ssL15xaSZJAaA8hlA29y817cEskyPvH13 384g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kp6S8U50; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i24si2669594edj.207.2019.09.24.20.56.12; Tue, 24 Sep 2019 20:57:05 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=kp6S8U50; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729157AbfIWEb0 (ORCPT + 99 others); Mon, 23 Sep 2019 00:31:26 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:35435 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726536AbfIWEb0 (ORCPT ); Mon, 23 Sep 2019 00:31:26 -0400 Received: by mail-qk1-f196.google.com with SMTP id w2so14026065qkf.2 for ; Sun, 22 Sep 2019 21:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=4QM9p6JUL1H2+7ufpY9lHAHlLiqvaNnzuQlbpSFc8tM=; b=kp6S8U50H9zQURpbWiVwsIep53fMTjYvYSQ1hH7rsdcVRizx/5hgI1Qg2WKjMdLWXf GNwfNzEITwHot/iLdAn1kdRMmbSv/9d4huyEATB08vNHmt3ayXBLr3NCxWoTqlAeb6E8 3Bgo1CKJjm4lrLM4GSS7TlOUUIm9tDKEnYm2C9xpZGgvbpru+lxyI2YTIrED+Bi6kJTC yeA8lBLRLPJVoBCVrQ1d9J/F23Y60pvapHtF77vcyAjLNdZnFiaSXPbIhp9GhSELNX83 pi1W42HdJTyIQ/61nD4CI3QFycdaT+UanE3kV49bcXrWMkCH7sXRSQEXG4wTl49Vzlqj v9sw== 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=4QM9p6JUL1H2+7ufpY9lHAHlLiqvaNnzuQlbpSFc8tM=; b=RDQ6f1fK5mKGTmEAqApx9QiXrcsWYIQnDeKv7EJ5WGJsh0fYPB2hFLQSopUQ9u3VJg uK1aZKS5KvqSw9SZZNVywl71CoOYmPoHubNvazyMWeA06Vja/8PpRHH3S9FCEEbsyFOX 2Kl+HHorXHRDxujYavxLJpcwZSewYaYNFzc02njznDU6nJsdLed4x91gNO6ZsAYzRZFw 8PQ/s47adz72o5fakr78/dbkRUkI5GiTR2hu6552BHPD0LmzSCgScdoarjpGqiMzErFP xxmdaTGaV4+jz/0xvXgD+3ExEBeIzdr1o9rdjSwU4OdfkrBuDxZXLCDZjqksfmG7g3O+ 5yJg== X-Gm-Message-State: APjAAAXMsgB2zsIQPSFn4afnZ6L+rRJohcINNgfDwoh2DCtO21Ih/64K QoMvx6OtWrQzH6j6Wfmd6V8= X-Received: by 2002:a37:7041:: with SMTP id l62mr15740747qkc.7.1569213085158; Sun, 22 Sep 2019 21:31:25 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id k54sm5680914qtf.28.2019.09.22.21.31.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Sep 2019 21:31:23 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 4D4CE220AA; Mon, 23 Sep 2019 00:31:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 23 Sep 2019 00:31:22 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdejgdekiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujggfsehgtderredtredvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuffhomhgrih hnpehgihhthhhusgdrtghomhdpuhhsvghnihigrdhorhhgpdhlfihnrdhnvghtnecukfhp peeghedrfedvrdduvdekrddutdelnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquh hnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudej jeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrd hnrghmvgenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 20A73D6005E; Mon, 23 Sep 2019 00:31:21 -0400 (EDT) Date: Mon, 23 Sep 2019 12:31:13 +0800 From: Boqun Feng To: Will Deacon Cc: Marco Elver , kasan-dev , LKML , Dmitry Vyukov , Andrey Konovalov , Alexander Potapenko , paulmck@linux.ibm.com, Paul Turner , Daniel Axtens , Anatol Pomazau , Andrea Parri , stern@rowland.harvard.edu, akiyks@gmail.com, npiggin@gmail.com, dlustig@nvidia.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr Subject: Re: Kernel Concurrency Sanitizer (KCSAN) Message-ID: <20190923043113.GA1080@tardis> References: <20190920155420.rxiflqdrpzinncpy@willie-the-truck> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="RnlQjJ0d97Da+TV1" Content-Disposition: inline In-Reply-To: <20190920155420.rxiflqdrpzinncpy@willie-the-truck> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --RnlQjJ0d97Da+TV1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 20, 2019 at 04:54:21PM +0100, Will Deacon wrote: > Hi Marco, >=20 > On Fri, Sep 20, 2019 at 04:18:57PM +0200, Marco Elver wrote: > > We would like to share a new data-race detector for the Linux kernel: > > Kernel Concurrency Sanitizer (KCSAN) -- > > https://github.com/google/ktsan/wiki/KCSAN (Details: > > https://github.com/google/ktsan/blob/kcsan/Documentation/dev-tools/kcsa= n.rst) > >=20 > > To those of you who we mentioned at LPC that we're working on a > > watchpoint-based KTSAN inspired by DataCollider [1], this is it (we > > renamed it to KCSAN to avoid confusion with KTSAN). > > [1] http://usenix.org/legacy/events/osdi10/tech/full_papers/Erickson.pdf >=20 > Oh, spiffy! >=20 > > In the coming weeks we're planning to: > > * Set up a syzkaller instance. > > * Share the dashboard so that you can see the races that are found. > > * Attempt to send fixes for some races upstream (if you find that the > > kcsan-with-fixes branch contains an important fix, please feel free to > > point it out and we'll prioritize that). >=20 > Curious: do you take into account things like alignment and/or access size > when looking at READ_ONCE/WRITE_ONCE? Perhaps you could initially prune > naturally aligned accesses for which __native_word() is true? >=20 > > There are a few open questions: > > * The big one: most of the reported races are due to unmarked > > accesses; prioritization or pruning of races to focus initial efforts > > to fix races might be required. Comments on how best to proceed are > > welcome. We're aware that these are issues that have recently received > > attention in the context of the LKMM > > (https://lwn.net/Articles/793253/). >=20 > This one is tricky. What I think we need to avoid is an onslaught of > patches adding READ_ONCE/WRITE_ONCE without a concrete analysis of the > code being modified. My worry is that Joe Developer is eager to get their > first patch into the kernel, so runs this tool and starts spamming > maintainers with these things to the point that they start ignoring KCSAN > reports altogether because of the time they take up. >=20 > I suppose one thing we could do is to require each new READ_ONCE/WRITE_ON= CE > to have a comment describing the racy access, a bit like we do for memory > barriers. Another possibility would be to use atomic_t more widely if > there is genuine concurrency involved. >=20 Instead of commenting READ_ONCE/WRITE_ONCE()s, how about adding anotations for data fields/variables that might be accessed without holding a lock? Because if all accesses to a variable are protected by proper locks, we mostly don't need to worry about data races caused by not using READ_ONCE/WRITE_ONCE(). Bad things happen when we write to a variable using locks but read it outside a lock critical section for better performance, for example, rcu_node::qsmask. I'm thinking so maybe we can introduce a new annotation similar to __rcu, maybe call it __lockfree ;-) as follow: struct rcu_node { ... unsigned long __lockfree qsmask; ... } , and __lockfree indicates that by design the maintainer of this data structure or variable believe there will be accesses outside lock critical sections. Note that not all accesses to __lockfree field, need to be READ_ONCE/WRITE_ONCE(), if the developer manages to build a complex but working wake/wait state machine so that it could not be accessed in the same time, READ_ONCE()/WRITE_ONCE() is not needed. If we have such an annotation, I think it won't be hard for configuring KCSAN to only examine accesses to variables with this annotation. Also=20 this annotation could help other checkers in the future. If KCSAN (at the least the upstream version) only check accesses with such an anotation, "spamming with KCSAN warnings/fixes" will be the choice of each maintainer ;-)=20 Thoughts? Regards, Boqun > > * How/when to upstream KCSAN? >=20 > Start by posting the patches :) >=20 > Will --RnlQjJ0d97Da+TV1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAl2ISo4ACgkQSXnow7UH +rgHOwf7BLuk59YmfLvND3YZHNAzLM2LGXuNIuOZcWlnUL1nI092bou02ChdTEPo 2VRQ41P95dAA6mGX5oIhExPy8KQ+vCMqnNV8ZMT3L134cqiLU6C+UZIp/9GSFub/ 0c9cvLyiwQo98gVIarEb/HWk5lSye1hlOPgSud3NpE4A11QFWAzRs4LkcVlFnh3g ATihIRCxLr0gPOsi9YQI2mBJjCi9yId+VzTFNbGhKfQVwAMUHZMVbRg15Q/OYe8g 1/c449UasaAZ64z/zlHZisjkD4RCUztekNPdFL1R7zrsaAJtpC5xsPncC6Q8EXL+ +6FT4rcFYJy4vRHy9MFnh/AxSEsXyA== =B1n/ -----END PGP SIGNATURE----- --RnlQjJ0d97Da+TV1--