From patchwork Fri Aug 26 15:07:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12956206 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E5A0ECAAA3 for ; Fri, 26 Aug 2022 15:09:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A22794000E; Fri, 26 Aug 2022 11:09:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32B8F940007; Fri, 26 Aug 2022 11:09:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17E3A94000E; Fri, 26 Aug 2022 11:09:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 07A45940007 for ; Fri, 26 Aug 2022 11:09:47 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DDE011A0EBA for ; Fri, 26 Aug 2022 15:09:46 +0000 (UTC) X-FDA: 79842078372.29.CAC5E0F Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf26.hostedemail.com (Postfix) with ESMTP id 90E4E140038 for ; Fri, 26 Aug 2022 15:09:46 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id sb14-20020a1709076d8e00b0073d48a10e10so726503ejc.16 for ; Fri, 26 Aug 2022 08:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc; bh=TL1IO7xzXsHa87B/8VTzh6zaFcPyOOUQBNZupLxKBzY=; b=HmM0VO6gyAfILflJdnMgQCrJGnTi5XVkH3YSfQa6Ep7rg4UjuRksDwsSKfdFWywrKQ X82KrgKGqPOH7W1Y085jaYB8hH48o1UO09SOdX25urL9IS+XrJIM0Ssl/7EKgVgUGuxb suAFkuoPLhsCY3yiCTAbiGImLbwkQ5FdkgDFrYP2s7UE16Wpzs+b87M7ywZwNSRcm9YT cGnqAcNCOOLNxnkJmTHzwJPrKl7dQaDEoIofp21fLLf8UCuU8TSnY933jziAvQ7zwjo3 /ax/hZi6c/lKBcQc7+qabk0byKdenq8IrwbzMmcRBwdyqFxWLtVcbbN3QqtnjPKNbk+n t0fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc; bh=TL1IO7xzXsHa87B/8VTzh6zaFcPyOOUQBNZupLxKBzY=; b=mFnHjkHYlN060+5Ct+pdftRP21pdooLVqEuQZjXLJBJdKhg2/ySzjTwMVwFFSKoZ4p UYTAqYX1hrXzO4fctCKG3OJKf/67Wv054HPk5I466sCzsCC6HwJVKqVR/OfxqSm48OeH 2EZiGa3LNi+23ctwq+fN5ypfXB7Bsk0XyRxtJYyAvUt/qrMLwvM4NiFUebmcfxvBfAVW wc0IzFNo6LpPaNJlvx6S1UHQzet7Yk2riJy/IRbKT5Q2SKBjDJYBQhIn1rdWKINS40wH 0nE1arCEexD042UR5vsaxfomYMqdXdbLUlOSKqPm7jYN6fvaStx3FOV1HL7/T5XCf1j+ dMhA== X-Gm-Message-State: ACgBeo1OpkkjmNv86BBFlJfBnJYoE0EAWlEkQgEMqMHGgoG49qSRu9el jb08EJgjrcNdkeYCXof+h0rKgslJMj8= X-Google-Smtp-Source: AA6agR76x5AzTzEwn7EdrRuhdUjJW6rIUhqvD9uYbbBW+SigP/bQyvCEvWgW5kLb9e6YBzYDFPgy1GTjMDc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a50:fe91:0:b0:43d:c97d:1b93 with SMTP id d17-20020a50fe91000000b0043dc97d1b93mr7390732edt.67.1661526585272; Fri, 26 Aug 2022 08:09:45 -0700 (PDT) Date: Fri, 26 Aug 2022 17:07:56 +0200 In-Reply-To: <20220826150807.723137-1-glider@google.com> Mime-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826150807.723137-34-glider@google.com> Subject: [PATCH v5 33/44] x86: kmsan: disable instrumentation of unsupported code From: Alexander Potapenko To: glider@google.com 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 , Marco Elver , 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661526586; a=rsa-sha256; cv=none; b=pDpYOEKPfrgFTW0jLrG3ReNbmgFfRgXlq/3DQPh9NpRxbZLT6srFzPF5p8yMJAAEBF3jtn xcHTifMAYKHTvgp5sxfEkjYeK6EanVz+ObRpDyWZZgM3Tgv/zBqiI8TNm8g6uHD5mZLFE8 Oa1fH/M6OZJd2HdUq2X2zHFdmDO/mk0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=HmM0VO6g; spf=pass (imf26.hostedemail.com: domain of 3OeIIYwYKCEAinkfgtiqqing.eqonkpwz-oomxcem.qti@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3OeIIYwYKCEAinkfgtiqqing.eqonkpwz-oomxcem.qti@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661526586; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TL1IO7xzXsHa87B/8VTzh6zaFcPyOOUQBNZupLxKBzY=; b=SHbf2Cgo75KRA+keYRd3LnKRyNqujN5zZSSGNJzVrAfzvgjSTN9wiYnu1/LFbrYtEmMjD8 MTPbEFzl0L4eYLmeY68xnAtdXce/mbobblMJCCZfu4Ci58qES1Ymc7s4mk26z6y32HHVma 3ro317aV22R/D3sxTS4gqymExJasmk0= X-Stat-Signature: 7n36tria1ke9hn69shop7zfq7nprh88q X-Rspamd-Queue-Id: 90E4E140038 X-Rspam-User: X-Rspamd-Server: rspam06 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=HmM0VO6g; spf=pass (imf26.hostedemail.com: domain of 3OeIIYwYKCEAinkfgtiqqing.eqonkpwz-oomxcem.qti@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3OeIIYwYKCEAinkfgtiqqing.eqonkpwz-oomxcem.qti@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1661526586-868748 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: Instrumenting some files with KMSAN will result in kernel being unable to link, boot or crashing at runtime for various reasons (e.g. infinite recursion caused by instrumentation hooks calling instrumented code again). Completely omit KMSAN instrumentation in the following places: - arch/x86/boot and arch/x86/realmode/rm, as KMSAN doesn't work for i386; - arch/x86/entry/vdso, which isn't linked with KMSAN runtime; - three files in arch/x86/kernel - boot problems; - arch/x86/mm/cpu_entry_area.c - recursion. Signed-off-by: Alexander Potapenko --- v2: -- moved the patch earlier in the series so that KMSAN can compile -- split off the non-x86 part into a separate patch v3: -- added a comment to lib/Makefile v5: -- removed a comment belonging to another patch Link: https://linux-review.googlesource.com/id/Id5e5c4a9f9d53c24a35ebb633b814c414628d81b --- arch/x86/boot/Makefile | 1 + arch/x86/boot/compressed/Makefile | 1 + arch/x86/entry/vdso/Makefile | 3 +++ arch/x86/kernel/Makefile | 2 ++ arch/x86/kernel/cpu/Makefile | 1 + arch/x86/mm/Makefile | 2 ++ arch/x86/realmode/rm/Makefile | 1 + 7 files changed, 11 insertions(+) diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile index ffec8bb01ba8c..9860ca5979f8a 100644 --- a/arch/x86/boot/Makefile +++ b/arch/x86/boot/Makefile @@ -12,6 +12,7 @@ # Sanitizer runtimes are unavailable and cannot be linked for early boot code. KASAN_SANITIZE := n KCSAN_SANITIZE := n +KMSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y # Kernel does not boot with kcov instrumentation here. diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 35ce1a64068b7..3a261abb6d158 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -20,6 +20,7 @@ # Sanitizer runtimes are unavailable and cannot be linked for early boot code. KASAN_SANITIZE := n KCSAN_SANITIZE := n +KMSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index 12f6c4d714cd6..ce4eb7e44e5b8 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -11,6 +11,9 @@ include $(srctree)/lib/vdso/Makefile # Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE := n +KMSAN_SANITIZE_vclock_gettime.o := n +KMSAN_SANITIZE_vgetcpu.o := n + UBSAN_SANITIZE := n KCSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index a20a5ebfacd73..ac564c5d7b1f0 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -33,6 +33,8 @@ KASAN_SANITIZE_sev.o := n # With some compiler versions the generated code results in boot hangs, caused # by several compilation units. To be safe, disable all instrumentation. KCSAN_SANITIZE := n +KMSAN_SANITIZE_head$(BITS).o := n +KMSAN_SANITIZE_nmi.o := n # If instrumentation of this dir is enabled, boot hangs during first second. # Probably could be more selective here, but note that files related to irqs, diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 9661e3e802be5..f10a921ee7565 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -12,6 +12,7 @@ endif # If these files are instrumented, boot hangs during the first second. KCOV_INSTRUMENT_common.o := n KCOV_INSTRUMENT_perf_event.o := n +KMSAN_SANITIZE_common.o := n # As above, instrumenting secondary CPU boot code causes boot hangs. KCSAN_SANITIZE_common.o := n diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index f8220fd2c169a..39c0700c9955c 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile @@ -12,6 +12,8 @@ KASAN_SANITIZE_mem_encrypt_identity.o := n # Disable KCSAN entirely, because otherwise we get warnings that some functions # reference __initdata sections. KCSAN_SANITIZE := n +# Avoid recursion by not calling KMSAN hooks for CEA code. +KMSAN_SANITIZE_cpu_entry_area.o := n ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_mem_encrypt.o = -pg diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile index 83f1b6a56449f..f614009d3e4e2 100644 --- a/arch/x86/realmode/rm/Makefile +++ b/arch/x86/realmode/rm/Makefile @@ -10,6 +10,7 @@ # Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE := n KCSAN_SANITIZE := n +KMSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.