Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7315870ybp; Wed, 16 Oct 2019 07:04:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0Gia5HK9i66JnUFOCnfznlULKNgxbXaLmdv+R89GCrqNSoY3aUtFfs/Xv3o0mZsjY31/s X-Received: by 2002:a05:600c:34b:: with SMTP id u11mr3635625wmd.176.1571234667223; Wed, 16 Oct 2019 07:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571234667; cv=none; d=google.com; s=arc-20160816; b=CLVcErqR40v4M4TfubIZ9BuGueO4mdDLsQiixUQ5CvvQkDSq/O14qCtHE+tyOqo0rC rDBzAeHPydqpjwoNQCZy6JQ5W9uw8UiyrEvEaCaYTl61ZUKBbo+cS/T5/KPhTbHXBM3t iHNm4rFdVIKofT+aOq9pjzUZUR5ICextV335tGQpgi2u9k7huQytPW1GNo5ttGQ+VnB9 OSm1nm/PkxV4YvLhSNlknhPCC4atmJL3eJ1UxabCObwscR010KG3yiR1rF1vypmDq7+e wK3ERY1zEvyYiBx1+zFUv5OIeX5gcRkGoGBVaSJ8q/AvNfxoTktnV+/Kv4a5HiR/HAs+ rrSQ== 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=qMLDRlP6KAQbJ6EBR+tTwOR/BZha8QBB781yjh9f+vI=; b=lH3uWHgHcGsOAkzyNzw6HiMkCNIxuZwmJvmbkjmgFvu1zTduYUj+7sbMQHSXs4IH+o uQSpVR+HYoX8rcpUGMuOTp8jS/u4wPEK0hFp0TKPAnx0y1Tq+PatsA6YdiHkSb7TDTrA 8yJhYx8b9ho6cIKpWJuVf8uDCjjo5YYRoyYUqbQg7ez/q3R94aRqR3e9aEH2AMDLVSXl /nNyDJAnpug4BdN7SLnXWnyTqh4S50kIlL8OiFThh8lAl8SGSrzR2aJt88gdCWcxlGs0 /FVjVHlAH8nEsj3gr38BgglwU3vUoUIOd2g3IvAfKQkUT0SXV+uaBE1Cdx02zP7JC1bl w+EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IzhRqtVY; 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 g38si17670679edg.127.2019.10.16.07.04.02; Wed, 16 Oct 2019 07:04:27 -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=IzhRqtVY; 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 S2390348AbfJPKHE (ORCPT + 99 others); Wed, 16 Oct 2019 06:07:04 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:46031 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390164AbfJPKHE (ORCPT ); Wed, 16 Oct 2019 06:07:04 -0400 Received: by mail-oi1-f193.google.com with SMTP id o205so19506721oib.12 for ; Wed, 16 Oct 2019 03:07:03 -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=qMLDRlP6KAQbJ6EBR+tTwOR/BZha8QBB781yjh9f+vI=; b=IzhRqtVYSIrQOWk8qCQYn4/rTOnHC2BhU7+kR7WbjbeLrfwEgkriTH0i/iiLXUxE6w 9TY1zEHAxm9LWqj9U9FKFNFpJPksG+o5jpTnwf0AH9L9qx4EjTfEmYZspBAwyoYTq58y 2XoJim6PnzA8V5rkbEZ+1gHJd/d8E1TT3mVou1qLNPGV59Oh4Lp8AGHQC6TqedqA1I80 mFPnDoRcUI6zhCDUTpoHxhcuDdKJAMAQgwv1O9N/6gP1uqvOtZZc24tKklN7heCOtCLw AGLWDPjGICR0HouGNZzMf7ZxOX6YjI/TIY2ddPvOeO7bcqUGL2vcWzGzn9/wEQ98UyfN oZxQ== 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=qMLDRlP6KAQbJ6EBR+tTwOR/BZha8QBB781yjh9f+vI=; b=ra6TvNlY5ogSPQ3WSLEjrNr1WRRop0fGFKTJ4tNFnEOoW7nv80OgUuYqod5QiJAYYx +4lvKCLLAY1ddoijW7wVfC6jOkoScoP2alIQFg8zs1jRdiv+0yvQFPhWwGzzH24i63E5 Z+vkX1Wnkd7oLe2mqKJJAyeDgfB3jyGHxfc+q5eXl8Tewr7g/Qvdhy5wrpJ6+gf1EYF6 UJhFIjY+/3QNoa/s0czlcLtT8e2xuQgaLqRiCz5ScLjuPjNexfpVt6SQhEY+TaR71k71 heEdjZpUPjLBGWxOggN7nvZVvWd0CV9rKClHhEmaiRgP4YQCjnV+WcdbVJAg3vG8ruot yJTw== X-Gm-Message-State: APjAAAW+4OAJ87CpuwINZmy9/f7UIffhUuSb1y6z20ob3/ulur+cyT4U 0wPeirXrNyJrz4kbAITcFGX7cH//teeRNNfchk2X3g== X-Received: by 2002:aca:f492:: with SMTP id s140mr2789533oih.83.1571220422532; Wed, 16 Oct 2019 03:07:02 -0700 (PDT) MIME-Version: 1.0 References: <20191016083959.186860-1-elver@google.com> <20191016083959.186860-2-elver@google.com> <20191016094234.GB2701514@tardis> In-Reply-To: <20191016094234.GB2701514@tardis> From: Marco Elver Date: Wed, 16 Oct 2019 12:06:51 +0200 Message-ID: Subject: Re: [PATCH 1/8] kcsan: Add Kernel Concurrency Sanitizer infrastructure To: Boqun Feng Cc: LKMM Maintainers -- Akira Yokosawa , Alan Stern , Alexander Potapenko , Andrea Parri , Andrey Konovalov , Andy Lutomirski , ard.biesheuvel@linaro.org, Arnd Bergmann , Borislav Petkov , Daniel Axtens , Daniel Lustig , dave.hansen@linux.intel.com, dhowells@redhat.com, Dmitry Vyukov , "H. Peter Anvin" , Ingo Molnar , Jade Alglave , Joel Fernandes , Jonathan Corbet , Josh Poimboeuf , Luc Maranget , Mark Rutland , Nicholas Piggin , "Paul E. McKenney" , Peter Zijlstra , Thomas Gleixner , Will Deacon , kasan-dev , linux-arch , "open list:DOCUMENTATION" , linux-efi@vger.kernel.org, linux-kbuild@vger.kernel.org, LKML , Linux Memory Management List , "the arch/x86 maintainers" 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 Wed, 16 Oct 2019 at 11:42, Boqun Feng wrote: > > Hi Marco, > > On Wed, Oct 16, 2019 at 10:39:52AM +0200, Marco Elver wrote: > [...] > > --- /dev/null > > +++ b/kernel/kcsan/kcsan.c > > @@ -0,0 +1,81 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > + > > +/* > > + * The Kernel Concurrency Sanitizer (KCSAN) infrastructure. For more info please > > + * see Documentation/dev-tools/kcsan.rst. > > + */ > > + > > +#include > > + > > +#include "kcsan.h" > > + > > +/* > > + * Concurrency Sanitizer uses the same instrumentation as Thread Sanitizer. > > Is there any documentation on the instrumentation? Like a complete list > for all instrumentation functions plus a description of where the > compiler will use those functions. Yes, the names of the below functions > are straightforward, but an accurate doc on the instrumentation will > cerntainly help people review KCSAN. As far as I'm aware neither GCC nor Clang have documentation on the emitted instrumentation that we could reference (other than look into the compiler passes). However it is as straightforward as it seems: the compiler emits instrumentation calls for all loads and stores that the compiler generates; inline asm is not instrumented. I will add a comment to that effect for v2. Thanks, -- Marco > Regards, > Boqun > > > + */ > > + > > +#define DEFINE_TSAN_READ_WRITE(size) \ > > + void __tsan_read##size(void *ptr) \ > > + { \ > > + __kcsan_check_access(ptr, size, false); \ > > + } \ > > + EXPORT_SYMBOL(__tsan_read##size); \ > > + void __tsan_write##size(void *ptr) \ > > + { \ > > + __kcsan_check_access(ptr, size, true); \ > > + } \ > > + EXPORT_SYMBOL(__tsan_write##size) > > + > > +DEFINE_TSAN_READ_WRITE(1); > > +DEFINE_TSAN_READ_WRITE(2); > > +DEFINE_TSAN_READ_WRITE(4); > > +DEFINE_TSAN_READ_WRITE(8); > > +DEFINE_TSAN_READ_WRITE(16); > > + > > +/* > > + * Not all supported compiler versions distinguish aligned/unaligned accesses, > > + * but e.g. recent versions of Clang do. > > + */ > > +#define DEFINE_TSAN_UNALIGNED_READ_WRITE(size) \ > > + void __tsan_unaligned_read##size(void *ptr) \ > > + { \ > > + __kcsan_check_access(ptr, size, false); \ > > + } \ > > + EXPORT_SYMBOL(__tsan_unaligned_read##size); \ > > + void __tsan_unaligned_write##size(void *ptr) \ > > + { \ > > + __kcsan_check_access(ptr, size, true); \ > > + } \ > > + EXPORT_SYMBOL(__tsan_unaligned_write##size) > > + > > +DEFINE_TSAN_UNALIGNED_READ_WRITE(2); > > +DEFINE_TSAN_UNALIGNED_READ_WRITE(4); > > +DEFINE_TSAN_UNALIGNED_READ_WRITE(8); > > +DEFINE_TSAN_UNALIGNED_READ_WRITE(16); > > + > > +void __tsan_read_range(void *ptr, size_t size) > > +{ > > + __kcsan_check_access(ptr, size, false); > > +} > > +EXPORT_SYMBOL(__tsan_read_range); > > + > > +void __tsan_write_range(void *ptr, size_t size) > > +{ > > + __kcsan_check_access(ptr, size, true); > > +} > > +EXPORT_SYMBOL(__tsan_write_range); > > + > > +/* > > + * The below are not required KCSAN, but can still be emitted by the compiler. > > + */ > > +void __tsan_func_entry(void *call_pc) > > +{ > > +} > > +EXPORT_SYMBOL(__tsan_func_entry); > > +void __tsan_func_exit(void) > > +{ > > +} > > +EXPORT_SYMBOL(__tsan_func_exit); > > +void __tsan_init(void) > > +{ > > +} > > +EXPORT_SYMBOL(__tsan_init); > [...]