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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3A68C433EF for ; Tue, 12 Jul 2022 14:18:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233560AbiGLOSU (ORCPT ); Tue, 12 Jul 2022 10:18:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233282AbiGLORv (ORCPT ); Tue, 12 Jul 2022 10:17:51 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9600AB1861 for ; Tue, 12 Jul 2022 07:17:50 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-3137316bb69so82209297b3.10 for ; Tue, 12 Jul 2022 07:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rAqtnQvHicJEwVtFwBWlT2ImbHkxNKwCydMf49aDhZw=; b=aiMgzeBmgUZ/65gwB7z3OTtsJK0m68bYi/4uF0m2lufr7mlmeVAZPQ0CgoETjNHwN9 OR5ql/M5renBykTr5vdYLobTW0XAP/UTlosdoJx2ANZqwzs8BK3tQGb/yRGemqhOPTB5 iK99Fjwli6AAsLPKMn8lRm5+/LpczLnXvRM5mdBg7X8PI1Rb0wb3vtXNmwxva/MoP8Y9 f0pMS7Ab2OR6Rz5JjkDq0qesIKRAysU1yuWv5n+e039Y8V30n/O9aqVLUMKQNiHTpAvR iguPu8aE/PvAAvswibB+IxoRaR7YpLvASj0kcPA4lDVbjhZ/A8OlDVlXCq4Uy6Acnz0a GKhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rAqtnQvHicJEwVtFwBWlT2ImbHkxNKwCydMf49aDhZw=; b=Nt2rNEOcf8BGlao9bWCGJWa9OST/8Boc7sCMyxs0ZoNQRxLR+t5AY1kuy39ZU1vRx3 7+hxNWm+sOHdNUvq7J7gyut6ODEAeYPiNnPgu1bDyjzn1sR+i/PPoONA/2i3cw5ly0Kw DElATl4vHN1vBoc6TPLsReFB+pneur7aPPW83LVvHMMdi2sRNGbmITzVMElib8qp8pug Wklp47HcTg3zOnxqEbUFSFFgOrqu+eDbpYb4mHbdCzBmdsG7oyXyB4swGxxdzu+WRZL4 SS19I/EopHkhArENpAulFw5TIN2RuKbPKHqU8f6UE4HA86QmH382QAqT0e18noGIzSWM ew+Q== X-Gm-Message-State: AJIora9WYeLvEZJGc/D1K2LttFTRaRYvgiWJnwfB8zYhQIgC4aHR+Qhh d9OIO7OMrwQhhZmI0Z6ldZNBGpnmDLXCOwJAnvn2Lw== X-Google-Smtp-Source: AGRyM1tKjPPwFYnKg+0p6eGc1mlWK6G9zJMRPDOrTPORWMifQA9yBH9S1buboNSiyORVrmetN+LzTUSEuucVV4I4Qr8= X-Received: by 2002:a81:98d:0:b0:31c:921c:9783 with SMTP id 135-20020a81098d000000b0031c921c9783mr25429483ywj.316.1657635469677; Tue, 12 Jul 2022 07:17:49 -0700 (PDT) MIME-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> <20220701142310.2188015-8-glider@google.com> In-Reply-To: <20220701142310.2188015-8-glider@google.com> From: Marco Elver Date: Tue, 12 Jul 2022 16:17:14 +0200 Message-ID: Subject: Re: [PATCH v4 07/45] kmsan: introduce __no_sanitize_memory and __no_kmsan_checks To: Alexander Potapenko Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 1 Jul 2022 at 16:23, Alexander Potapenko wrote: > > __no_sanitize_memory is a function attribute that instructs KMSAN to > skip a function during instrumentation. This is needed to e.g. implement > the noinstr functions. > > __no_kmsan_checks is a function attribute that makes KMSAN > ignore the uninitialized values coming from the function's > inputs, and initialize the function's outputs. > > Functions marked with this attribute can't be inlined into functions > not marked with it, and vice versa. This behavior is overridden by > __always_inline. > > __SANITIZE_MEMORY__ is a macro that's defined iff the file is > instrumented with KMSAN. This is not the same as CONFIG_KMSAN, which is > defined for every file. > > Signed-off-by: Alexander Potapenko Reviewed-by: Marco Elver > --- > Link: https://linux-review.googlesource.com/id/I004ff0360c918d3cd8b18767ddd1381c6d3281be > --- > include/linux/compiler-clang.h | 23 +++++++++++++++++++++++ > include/linux/compiler-gcc.h | 6 ++++++ > 2 files changed, 29 insertions(+) > > diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h > index c84fec767445d..4fa0cc4cbd2c8 100644 > --- a/include/linux/compiler-clang.h > +++ b/include/linux/compiler-clang.h > @@ -51,6 +51,29 @@ > #define __no_sanitize_undefined > #endif > > +#if __has_feature(memory_sanitizer) > +#define __SANITIZE_MEMORY__ > +/* > + * Unlike other sanitizers, KMSAN still inserts code into functions marked with > + * no_sanitize("kernel-memory"). Using disable_sanitizer_instrumentation > + * provides the behavior consistent with other __no_sanitize_ attributes, > + * guaranteeing that __no_sanitize_memory functions remain uninstrumented. > + */ > +#define __no_sanitize_memory __disable_sanitizer_instrumentation > + > +/* > + * The __no_kmsan_checks attribute ensures that a function does not produce > + * false positive reports by: > + * - initializing all local variables and memory stores in this function; > + * - skipping all shadow checks; > + * - passing initialized arguments to this function's callees. > + */ > +#define __no_kmsan_checks __attribute__((no_sanitize("kernel-memory"))) > +#else > +#define __no_sanitize_memory > +#define __no_kmsan_checks > +#endif > + > /* > * Support for __has_feature(coverage_sanitizer) was added in Clang 13 together > * with no_sanitize("coverage"). Prior versions of Clang support coverage > diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h > index a0c55eeaeaf16..63eb90eddad77 100644 > --- a/include/linux/compiler-gcc.h > +++ b/include/linux/compiler-gcc.h > @@ -125,6 +125,12 @@ > #define __SANITIZE_ADDRESS__ > #endif > > +/* > + * GCC does not support KMSAN. > + */ > +#define __no_sanitize_memory > +#define __no_kmsan_checks > + > /* > * Turn individual warnings and errors on and off locally, depending > * on version. > -- > 2.37.0.rc0.161.g10f37bed90-goog >