Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1789140ybj; Sun, 22 Sep 2019 11:59:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlUk9gEGODewgVkHcMmrYy8ytKf0Sm3FsMVdnzeCg13V3Bz2lA7xEB1Z6Lz8NkSN/oUX8L X-Received: by 2002:a05:6402:65a:: with SMTP id u26mr33003172edx.86.1569178766700; Sun, 22 Sep 2019 11:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569178766; cv=none; d=google.com; s=arc-20160816; b=a1VjxooJrUa5dP60KOHpTj0Px3W1QaBsta/FAoQY2R3xQwr5qh03L2f5eGgOcJ7fgX GmJhUuXAfA0YLEkgx4c7QOKY+xWCvIe2AEbkhBD9gKXs5/nEoTF/UaGx7JEETOiJGszM M8CAhtBJ9teVquxqmrSV3DgFgCwcWUPZgxHu14csxMZ9VgndYbugZDzSdX71pKhcgp13 qW0zqVCs+OMQ7caRReS4YIp3YcV2MTOXKTVp5fvEl6haeTPiijEIiLXuU47ttq3vzq+3 6oUMKD2puzGVS7eWT5ACIXnF4dnLpGb6J6xrrp9F2s9MISojMaHKOelUebIv/1sneV4e aT8w== 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=eTz6yzxiFyHtcxZo7L97GNHOGY6QY7O6TNCJQilZlzU=; b=qnqXiCvD9eDWAQvhgKSX4gOevzW/BdsTcueuPhtyZqOzN4G/8YRXH9x3LxoiETYORa CArH1md0maZhIdCH4cM7/S5fsdzKlUNE8RXbiPse5Ji5N3ZA60ZagDGf+HUeiGeTH3ld SV3cucVrcq+1bLF5U4Qwv8eMC2c9EIDimm4O2MiQV51qejYHkuVfF9B7LJtpECQifCFk Xgsq3FqGRdwEHxshFG3hSzCZInagp4ifjWUHo/v7Mg4spPKZOdXVGcWc4Nf2Tj6Z6k2t cJjO+pYa9TAFZILme523HGBIGbXPo4vaCpwmH3/FoEw/2WpumLgHmoAP0Od0L2KehkfR NaQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UEgIQlBP; 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 f2si3881628ejk.25.2019.09.22.11.59.02; Sun, 22 Sep 2019 11:59:26 -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=@google.com header.s=20161025 header.b=UEgIQlBP; 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 S2404904AbfITRvR (ORCPT + 99 others); Fri, 20 Sep 2019 13:51:17 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:34674 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390680AbfITRvR (ORCPT ); Fri, 20 Sep 2019 13:51:17 -0400 Received: by mail-oi1-f195.google.com with SMTP id 83so2497599oii.1 for ; Fri, 20 Sep 2019 10:51:16 -0700 (PDT) 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=eTz6yzxiFyHtcxZo7L97GNHOGY6QY7O6TNCJQilZlzU=; b=UEgIQlBPZuG/x9jdC25TMCOjdIAuit0OtbKI7LeWZhf1jNcX4Cf+LAPC2zklx2jgsf +iD2KDdjo+PxvIJIzga/BJoFr9y/LMIo/xvCU4ugOa6fxl1SR1B3E8TSdtLiKNxkgGHP XLPwyhT7PGr9M3J9Q29Yd4iDC/zmEtoidcEkMSHsu6gNcT1s8+lLWT2yhpyFXe5Kd5VQ pCnH9461L0/WDksxLcZTDgw17k1m4YQQfAuzKFuKsM8NVgGWU7vI+XKu1dic8mLIYkCU 5Esdvda1jsAPFD1gXQdWDBxJq/TDRW/lIXM5OGS0Mqw2Ynd7o9NQtvIuXVmuPtTllS2j xPbQ== 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=eTz6yzxiFyHtcxZo7L97GNHOGY6QY7O6TNCJQilZlzU=; b=EOXT8vmrCZQK8URUAzAugZ0GQmsXE8huYjJvpzzkOqoHkUfe2QsgcvrAeUPuYa9f23 988NU8j/ueMd1wdoJPp+lxTjSrR/gyvu+GBNRloB4yu+9bETY7ydn4KdalRkfA19ftwz nQXETZWgv/2cT7k93l48dW7BpNJuB4TtONJPX3DJbWXg2dKZdPzeSbIlvO/D7ZtMIot1 dS2bfN4gW50EhAucnFUkyEUcDuOup4YhNpEjqTpU7AVmSGkzoDeG+Ykk1MQYeQcz9gLC t1uNFt9eMxctyNR0krxRtMwCpt12MhmIZm4Ijh1q34/aG736TRK3hI5nJdkjz/k25LI7 Mhmw== X-Gm-Message-State: APjAAAXrAmOEuaDuLv2CozvijNxeH2ItJyzhNF/gQioNc4KCu0cm2V2S zAq9Fhy0Ik6p8WDKXvtHtBBHFaF9z5K1KZtLozY7g7msIACrv6w4 X-Received: by 2002:aca:5510:: with SMTP id j16mr4095393oib.121.1569001876015; Fri, 20 Sep 2019 10:51:16 -0700 (PDT) MIME-Version: 1.0 References: <20190920163123.GC55224@lakrids.cambridge.arm.com> In-Reply-To: From: Marco Elver Date: Fri, 20 Sep 2019 19:51:04 +0200 Message-ID: Subject: Re: Kernel Concurrency Sanitizer (KCSAN) To: Dmitry Vyukov Cc: Mark Rutland , kasan-dev , LKML , Andrey Konovalov , Alexander Potapenko , "Paul E. McKenney" , Paul Turner , Daniel Axtens , Anatol Pomazau , Will Deacon , Andrea Parri , Alan Stern , LKMM Maintainers -- Akira Yokosawa , Nicholas Piggin , Boqun Feng , Daniel Lustig , Jade Alglave , Luc Maranget 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, 20 Sep 2019 at 18:47, Dmitry Vyukov wrote: > > On Fri, Sep 20, 2019 at 6:31 PM Mark Rutland wrote: > > > > 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/kcsan.rst) > > > > Nice! > > > > BTW kcsan_atomic_next() is missing a stub definition in > > when !CONFIG_KCSAN: > > > > https://github.com/google/ktsan/commit/a22a093a0f0d0b582c82cdbac4f133a3f61d207c#diff-19d7c475b4b92aab8ba440415ab786ec > > > > ... and I think the kcsan_{begin,end}_atomic() stubs need to be static > > inline too. Thanks for catching, fixed and pushed. Feel free to rebase your arm64 branch. > > It looks like this is easy enough to enable on arm64, with the only real > > special case being secondary_start_kernel() which we might want to > > refactor to allow some portions to be instrumented. > > > > I pushed the trivial patches I needed to get arm64 booting to my arm64/kcsan > > branch: > > > > git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git arm64/kcsan Cool, thanks for testing! > > We have some interesting splats at boot time in stop_machine, which > > don't seem to have been hit/fixed on x86 yet in the kcsan-with-fixes > > branch, e.g. > > > > [ 0.237939] ================================================================== > > [ 0.239431] BUG: KCSAN: data-race in multi_cpu_stop+0xa8/0x198 and set_state+0x80/0xb0 > > [ 0.241189] > > [ 0.241606] write to 0xffff00001003bd00 of 4 bytes by task 24 on cpu 3: > > [ 0.243435] set_state+0x80/0xb0 > > [ 0.244328] multi_cpu_stop+0x16c/0x198 > > [ 0.245406] cpu_stopper_thread+0x170/0x298 > > [ 0.246565] smpboot_thread_fn+0x40c/0x560 > > [ 0.247696] kthread+0x1a8/0x1b0 > > [ 0.248586] ret_from_fork+0x10/0x18 > > [ 0.249589] > > [ 0.250006] read to 0xffff00001003bd00 of 4 bytes by task 14 on cpu 1: > > [ 0.251804] multi_cpu_stop+0xa8/0x198 > > [ 0.252851] cpu_stopper_thread+0x170/0x298 > > [ 0.254008] smpboot_thread_fn+0x40c/0x560 > > [ 0.255135] kthread+0x1a8/0x1b0 > > [ 0.256027] ret_from_fork+0x10/0x18 > > [ 0.257036] > > [ 0.257449] Reported by Kernel Concurrency Sanitizer on: > > [ 0.258918] CPU: 1 PID: 14 Comm: migration/1 Not tainted 5.3.0-00007-g67ab35a199f4-dirty #3 > > [ 0.261241] Hardware name: linux,dummy-virt (DT) > > [ 0.262517] ==================================================================> Thanks, the fixes in -with-fixes were ones I only encountered with Syzkaller, where I disable KCSAN during boot. I've just added a fix for this race and pushed to kcsan-with-fixes. > > > 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 > > > > > > 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). > > > > > > 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/). > > > > I think the big risk here is drive-by "fixes" masking the warnings > > rather than fixing the actual issue. It's easy for people to suppress a > > warning with {READ,WRITE}_ONCE(), so they're liable to do that even the > > resulting race isn't benign. > > > > I don't have a clue how to prevent that, though. > > I think this is mostly orthogonal problem. E.g. for some syzbot bugs I > see fixes that also try to simply "shut up" the immediate > manifestation with whatever means, e.g. sprinkling some slinlocks. So > (1) it's not unique to atomics, (2) presence of READ/WRITE_ONCE will > make the reader aware of the fact that this runs concurrently with > something else, and then they may ask themselves why this runs > concurrently with something when the object is supposed to be private > to the thread, and then maybe they re-fix it properly. Whereas if it's > completely unmarked, nobody will even notice that this code accesses > the object concurrently with other code. So even if READ/WRITE_ONCE > was a wrong fix, it's still better to have it rather than not.