From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C874FFA372A for ; Wed, 16 Oct 2019 10:07:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8132420650 for ; Wed, 16 Oct 2019 10:07:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IzhRqtVY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8132420650 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2D1398E000A; Wed, 16 Oct 2019 06:07:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2825C8E0001; Wed, 16 Oct 2019 06:07:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 170518E000A; Wed, 16 Oct 2019 06:07:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id E5BDA8E0001 for ; Wed, 16 Oct 2019 06:07:04 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 372878016BBC for ; Wed, 16 Oct 2019 10:07:04 +0000 (UTC) X-FDA: 76049219568.28.bike47_3dab901193d0e X-HE-Tag: bike47_3dab901193d0e X-Filterd-Recvd-Size: 8326 Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Wed, 16 Oct 2019 10:07:03 +0000 (UTC) Received: by mail-oi1-f195.google.com with SMTP id i16so19547791oie.4 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=dPUF9uKGc25nIJys9PMThD75XedYSS0yJLcjEl1QlXc0F1RmaR1WtiiajZS1zgKW/q WUl1M/9W93j8POA6jyqEklyX4ZaNx4bEgkQKfde5njq2gKWXiK9AmA2ANF2peOsazhO0 APRfqFpDVljy4HCvnXzEqH8coGH6OpS6EqOxJip95ZnZrWToNkdC1uWkg+QhceE5KQHy Rg3z4d/JNlDEEjqcvP3wZ62lqivoQMvgzy/raPd3aV91/4JIqSytHkJxTlEUY+0nhHou 8xsdUYaqR0z5lhB1Z/uL8Iagpo13VfDCvdogCjMqXELW0fPE3jqTbiUKCt0wxB5KQOXE 3xlg== X-Gm-Message-State: APjAAAWsMCgDy6StYDbKYGqPuK5dk9piU3XsvCH15blRMWLRhYkBovrN d6FzPhAjeve6K7KdTyacNFo14TJ1BojeIhq+6G+Odg== X-Google-Smtp-Source: APXvYqxWEIV0fVIrxNzDqgv+Do5nMi6aRtYEMsJW2Y12BL+F4CpGAX7l1gYylp2IQRBYF8VTmXy4feTlqfHWT/7/2sQ= 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" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); > [...]