From patchwork Wed Oct 30 14:22:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11219619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D1978112B for ; Wed, 30 Oct 2019 14:23:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9B76B20656 for ; Wed, 30 Oct 2019 14:23:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KroV8hCy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B76B20656 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 0605A6B0266; Wed, 30 Oct 2019 10:23:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F2B906B0269; Wed, 30 Oct 2019 10:23:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D56096B026A; Wed, 30 Oct 2019 10:23:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id B29596B0266 for ; Wed, 30 Oct 2019 10:23:06 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 5EC026132 for ; Wed, 30 Oct 2019 14:23:06 +0000 (UTC) X-FDA: 76100667972.21.rule92_382864bb1cf07 X-Spam-Summary: 2,0,0,3844b352f5f41132,d41d8cd98f00b204,3yjy5xqykcnsdifabodlldib.9ljifkru-jjhs79h.lod@flex--glider.bounces.google.com,:vegard.nossum@oracle.com:dvyukov@google.com::viro@zeniv.linux.org.uk:akpm@linux-foundation.org:aryabinin@virtuozzo.com:luto@kernel.org:ard.biesheuvel@linaro.org:arnd@arndb.de:hch@lst.de:dmitry.torokhov@gmail.com:edumazet@google.com:ericvh@gmail.com:gregkh@linuxfoundation.org:harry.wentland@amd.com:herbert@gondor.apana.org.au:mingo@elte.hu:axboe@kernel.dk:martin.petersen@oracle.com:schwidefsky@de.ibm.com:mst@redhat.com:monstr@monstr.eu:pmladek@suse.com:sergey.senozhatsky@gmail.com:rostedt@goodmis.org:tiwai@suse.com:tytso@mit.edu:tglx@linutronix.de:wsa@the-dreams.de:gor@linux.ibm.com:iii@linux.ibm.com:mark.rutland@arm.com:willy@infradead.org:rdunlap@infradead.org:andreyknvl@google.com:elver@google.com:glider@google.com,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1541:1593:1594:1711:1730:1747 :1777:17 X-HE-Tag: rule92_382864bb1cf07 X-Filterd-Recvd-Size: 5319 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Oct 2019 14:23:05 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id s3so2207078qkd.6 for ; Wed, 30 Oct 2019 07:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=akfNCofcaplWYSusBCm6RIllOookGu0Nmi5nMbilfDI=; b=KroV8hCy5YvvDtHUgx8njZkV1VcMmzh9xhYv8fymY4CEv7/3v6B+m+FjaT0xVyCdtb 2WtwsEGERBoxS6ONsaN+dHi0TpiGRFlwNEPULn4h+7jsTmgJiN4+zFEjliCPKUQCm8wf xYl8XxX1Ngb+MHHxJnFLWNmH8nIn7oBPaVRqGMjWMdJ+2buJkMQIffAB3hAGkLNQmanm 5mTSfh+zImgIeegNZBxPJw2hs1ZhiQpU0dc/xbuCuNgptsrvSehz83ra4B7IH4j1xUwC PwmxrWjzp7AM6SDrZAD2sTmzq6SfQuXoAkllRQDwgMQarYGLtk6hcL3y0qRLzgU9QsX8 Q0fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=akfNCofcaplWYSusBCm6RIllOookGu0Nmi5nMbilfDI=; b=N8qlse1ZNP4CtA3CQYk+9eprKDgIjZdswmcu8xB1Yhmy2vh1oyB/LwSlz4PdO9PNIs /Rq4bDy+DOdwY3C7dIU5EZH5lxaLNuavurAvDc/PVyGYvqXkjUFpjK6K0s8E8XTzbxEB lgZrgZPOoA5/VJtDil8BEgS9zlIg01aJT6SggcGmCG7/grDXDtlmYVFhr72oSdCOXVn0 +NOI9chYsKJT13pp0137DhQjRQC5y8Par6Jt2uqy7IRJnTViv2HD0Nq1lHjNZdGMICF1 DycXS5EVfsiGuF+w/TEREQ05ovXcfa5Y30F8LXxjC3qrs6I4HH+fPc4W1e8ObnfHuMQC A/Zw== X-Gm-Message-State: APjAAAUtx8KO5xx87bbsV9WtPoyjwl/sF7EsJ1Vcys79lgOTtIBl6Bv4 mdJf5Y2y/swAQ5gRST7+BvHajKicMdo= X-Google-Smtp-Source: APXvYqyLqV3WHpqCjY+K5TwB3sVeBWtRq4al0aD//TqSvfceUEzrB7eOGPFFt+OUfhxDNO9Du9fosiYyVZs= X-Received: by 2002:a05:6214:8c6:: with SMTP id da6mr22415815qvb.1.1572445384776; Wed, 30 Oct 2019 07:23:04 -0700 (PDT) Date: Wed, 30 Oct 2019 15:22:19 +0100 In-Reply-To: <20191030142237.249532-1-glider@google.com> Message-Id: <20191030142237.249532-8-glider@google.com> Mime-Version: 1.0 References: <20191030142237.249532-1-glider@google.com> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog Subject: [PATCH RFC v2 07/25] kmsan: introduce __no_sanitize_memory and __SANITIZE_MEMORY__ From: glider@google.com To: Vegard Nossum , Dmitry Vyukov , linux-mm@kvack.org Cc: viro@zeniv.linux.org.uk, akpm@linux-foundation.org, aryabinin@virtuozzo.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@lst.de, dmitry.torokhov@gmail.com, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, mingo@elte.hu, axboe@kernel.dk, martin.petersen@oracle.com, schwidefsky@de.ibm.com, mst@redhat.com, monstr@monstr.eu, pmladek@suse.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, wsa@the-dreams.de, gor@linux.ibm.com, iii@linux.ibm.com, mark.rutland@arm.com, willy@infradead.org, rdunlap@infradead.org, andreyknvl@google.com, elver@google.com, Alexander Potapenko 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: __no_sanitize_memory 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. __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 To: Alexander Potapenko Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: linux-mm@kvack.org --- Change-Id: I1f1672652c8392f15f7ca8ac26cd4e71f9cc1e4b --- include/linux/compiler-clang.h | 8 ++++++++ include/linux/compiler-gcc.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index 333a6695a918..edba13a069a6 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -24,6 +24,14 @@ #define __no_sanitize_address #endif +/* KMSAN is a Clang-only tool, thus putting the defines here */ +#if __has_feature(memory_sanitizer) +# define __SANITIZE_MEMORY__ +# define __no_sanitize_memory __attribute__((no_sanitize("kernel-memory"))) +#else +# define __no_sanitize_memory +#endif + /* * Not all versions of clang implement the the type-generic versions * of the builtin overflow checkers. Fortunately, clang implements diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index d7ee4c6bad48..e5ebc788dde4 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -145,6 +145,11 @@ #define __no_sanitize_address #endif +/* + * GCC doesn't support KMSAN. + */ +#define __no_sanitize_memory + #if GCC_VERSION >= 50100 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 #endif