From patchwork Fri Nov 22 11:26:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11257913 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 A8F786C1 for ; Fri, 22 Nov 2019 11:27:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 685C920721 for ; Fri, 22 Nov 2019 11:27:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PefGYHlb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 685C920721 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 DE2FC6B04F5; Fri, 22 Nov 2019 06:27:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D93116B04F7; Fri, 22 Nov 2019 06:27:55 -0500 (EST) 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 CAC0B6B04F8; Fri, 22 Nov 2019 06:27:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id AB2816B04F5 for ; Fri, 22 Nov 2019 06:27:55 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 7829C2C84 for ; Fri, 22 Nov 2019 11:27:55 +0000 (UTC) X-FDA: 76183688910.20.run61_ae763629191d X-Spam-Summary: 2,0,0,4a4219de726450da,d41d8cd98f00b204,3ocbxxqykcbo6b834h6ee6b4.2ecb8dkn-ccal02a.eh6@flex--glider.bounces.google.com,:axboe@kernel.dk:luto@kernel.org:vegard.nossum@oracle.com:dvyukov@google.com::glider@google.com:viro@zeniv.linux.org.uk:adilger.kernel@dilger.ca:akpm@linux-foundation.org:andreyknvl@google.com:aryabinin@virtuozzo.com:ard.biesheuvel@linaro.org:arnd@arndb.de:hch@infradead.org:hch@lst.de:darrick.wong@oracle.com:davem@davemloft.net:dmitry.torokhov@gmail.com:ebiggers@google.com:edumazet@google.com:ericvh@gmail.com:gregkh@linuxfoundation.org:harry.wentland@amd.com:herbert@gondor.apana.org.au:iii@linux.ibm.com:mingo@elte.hu:jasowang@redhat.com:m.szyprowski@samsung.com:elver@google.com:mark.rutland@arm.com:martin.petersen@oracle.com:schwidefsky@de.ibm.com:willy@infradead.org:mst@redhat.com:monstr@monstr.eu:pmladek@suse.com:cai@lca.pw:rdunlap@infradead.org:robin.murphy@arm.com:sergey.senozhatsky@gmail.com:rostedt@goodmis.org:tiwai@suse.com:tytso@mit.edu :tglx@li X-HE-Tag: run61_ae763629191d X-Filterd-Recvd-Size: 6990 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Nov 2019 11:27:54 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id q12so3774410wrr.3 for ; Fri, 22 Nov 2019 03:27:54 -0800 (PST) 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=kGtSL7NS7n26rUCNxYnNP906Anov59021UHpuibfPQ0=; b=PefGYHlb1Euv/MrIudcl80KGhFsxlB5kbZPO7AS4rD8YmygslhR68ObjaxWSyd9A1a d/dhdMmVbSijdvr0N5X42YG0zS0jMGYus+sfOyooG0vQZUOagJmhOjgKq8LNcGLJZugh A+/9YwUsG9ax6Y4bT5rZEfj8KB753XoYMzMM5ES2JD+UsCXh2hmH0mIoMj5dLjsaMGCA NGWyPYVOueQ1epM5ToeyOtt28y+WdSntevmYsr5MzleqfDa2pjQWJ3maSV5T1nngHhgT WvpWXWHwjCARFjXxbpd1NyuySE4p4UeXP94AGy7hF0Fr7BtaJH6NWAt4F8wMip1R5ULe jUvA== 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=kGtSL7NS7n26rUCNxYnNP906Anov59021UHpuibfPQ0=; b=C4c5kotFwtiZCFeSfLdEKTPzLsqmSAVCgBRmr6yQ9KIddffjS8EYKtqt8DOOZJijdy I6oHcdPhdvUUo2EP7zVTgnj3tpo8ZK1dk3kjr+sXSBjQKgYWlPmVaEmrXE95Qc3MPisQ 740ZqYbA2nQLKgaIDDfr/J3Tu8nvqN7E6a/mxT4VebiJ54eL1Ly8NtZeInwaxrAkQfXq TgYZvFT89qLm/CfzVIsi2uDVxaWEZX8aVOW9/PuN8ZyMoxV0Y4yvkNuzB6lmpIpSZPiq Yv1+oF7j/u0q1N50LRbokHnr5EZHSktF/veJwG1Aq1rjY68QOi6eMeLZDe2qjnBl7B0Y nJlw== X-Gm-Message-State: APjAAAWa6uQN81jEBj+Wx/2IIqsEqC4fypWs+551RCKar/pEfxTTe2Z9 mV/hCAb6FHao2Gu6u90EwQK++ERHCRM= X-Google-Smtp-Source: APXvYqyciDDRTB+KDvso+1+q8JSkGrKEvs6RYc7kNN+QQokiAy2dOBnQn5t1McVjLu1CNyxheZWhE+QPQEg= X-Received: by 2002:a5d:4a8f:: with SMTP id o15mr8412205wrq.50.1574422073526; Fri, 22 Nov 2019 03:27:53 -0800 (PST) Date: Fri, 22 Nov 2019 12:26:13 +0100 In-Reply-To: <20191122112621.204798-1-glider@google.com> Message-Id: <20191122112621.204798-29-glider@google.com> Mime-Version: 1.0 References: <20191122112621.204798-1-glider@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog Subject: [PATCH RFC v3 28/36] kmsan: enable KMSAN builds From: glider@google.com To: Jens Axboe , Andy Lutomirski , Vegard Nossum , Dmitry Vyukov , linux-mm@kvack.org Cc: glider@google.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, akpm@linux-foundation.org, andreyknvl@google.com, aryabinin@virtuozzo.com, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@infradead.org, hch@lst.de, darrick.wong@oracle.com, davem@davemloft.net, dmitry.torokhov@gmail.com, ebiggers@google.com, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, iii@linux.ibm.com, mingo@elte.hu, jasowang@redhat.com, m.szyprowski@samsung.com, elver@google.com, mark.rutland@arm.com, martin.petersen@oracle.com, schwidefsky@de.ibm.com, willy@infradead.org, mst@redhat.com, monstr@monstr.eu, pmladek@suse.com, cai@lca.pw, rdunlap@infradead.org, robin.murphy@arm.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, gor@linux.ibm.com, wsa@the-dreams.de 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: Make KMSAN usable by adding the necessary Makefile bits and calling KMSAN initialization routines (kmsan_initialize_shadow() and kmsan_initialize()) from init/main.c Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Jens Axboe Cc: Andy Lutomirski Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: linux-mm@kvack.org --- This patch was previously called "kmsan: Changing existing files to enable KMSAN builds". Logically unrelated parts of it were split away. Change-Id: I37e0b7f2d2f2b0aeac5753ff9d6b411485fc374e --- Makefile | 3 ++- init/main.c | 3 +++ mm/Makefile | 1 + scripts/Makefile.lib | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 79be70bf2899..181ae2dac415 100644 --- a/Makefile +++ b/Makefile @@ -478,7 +478,7 @@ export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE -export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN +export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN CFLAGS_KMSAN export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL @@ -898,6 +898,7 @@ KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none) endif include scripts/Makefile.kasan +include scripts/Makefile.kmsan include scripts/Makefile.extrawarn include scripts/Makefile.ubsan diff --git a/init/main.c b/init/main.c index 91f6ebb30ef0..afcca2a38348 100644 --- a/init/main.c +++ b/init/main.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -554,6 +555,7 @@ static void __init mm_init(void) */ page_ext_init_flatmem(); report_meminit(); + kmsan_initialize_shadow(); mem_init(); kmem_cache_init(); kmemleak_init(); @@ -625,6 +627,7 @@ asmlinkage __visible void __init start_kernel(void) sort_main_extable(); trap_init(); mm_init(); + kmsan_initialize(); ftrace_init(); diff --git a/mm/Makefile b/mm/Makefile index d996846697ef..419e6e02dfaf 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -71,6 +71,7 @@ obj-$(CONFIG_PAGE_POISONING) += page_poison.o obj-$(CONFIG_SLAB) += slab.o obj-$(CONFIG_SLUB) += slub.o obj-$(CONFIG_KASAN) += kasan/ +obj-$(CONFIG_KMSAN) += kmsan/ obj-$(CONFIG_FAILSLAB) += failslab.o obj-$(CONFIG_MEMORY_HOTPLUG) += memory_hotplug.o obj-$(CONFIG_MEMTEST) += memtest.o diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 179d55af5852..f9f38f7c1cd4 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -140,6 +140,12 @@ _c_flags += $(if $(patsubst n%,, \ $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) endif +ifeq ($(CONFIG_KMSAN),y) +_c_flags += $(if $(patsubst n%,, \ + $(KMSAN_SANITIZE_$(basetarget).o)$(KMSAN_SANITIZE)y), \ + $(CFLAGS_KMSAN)) +endif + ifeq ($(CONFIG_UBSAN),y) _c_flags += $(if $(patsubst n%,, \ $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \