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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2127FC433F5 for ; Tue, 29 Mar 2022 12:42:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A98E68D0010; Tue, 29 Mar 2022 08:42:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A48108D0007; Tue, 29 Mar 2022 08:42:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90FD58D0010; Tue, 29 Mar 2022 08:42:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 821CB8D0007 for ; Tue, 29 Mar 2022 08:42:37 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 33EAD22E84 for ; Tue, 29 Mar 2022 12:42:35 +0000 (UTC) X-FDA: 79297387512.03.B226DE5 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf14.hostedemail.com (Postfix) with ESMTP id 566FE100004 for ; Tue, 29 Mar 2022 12:42:35 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id f2-20020a50d542000000b00418ed3d95d8so10961923edj.11 for ; Tue, 29 Mar 2022 05:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=SXzoEK+WJk4pacaOPaL1kxqndb2ET/uQVttgxEkML+w=; b=EBgX4Z2SSMT4cCzIkiyvRhgKVrX4GCoNERzYeL3X7WwtwGGVnYOFgUHYNinxWjvjqh kPkONHRo3AKKxZf7R9b/cbfY+0RkKOgrN2sHOaZlXcyZw9J83ocbcq3eROphMcFU1OEF YKJAZFiUIL4gSt2ikNRjoKRlkYyZREXJJz7VZhoC8/sgm/33yNzmvyYsBx61nm/5RFi7 Uan2pjppFHg5+0ZzLB/M100362XN/KNKnBk+E1pryuHawtyJIDPxaGso4I1pLwK0vTOC Sf0uIg6BZNx/aUM8AwFe9jVH9IO3gu9QyjACglxQsPj/loJje/iBcBYgMBagUP0EX/7M jrPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SXzoEK+WJk4pacaOPaL1kxqndb2ET/uQVttgxEkML+w=; b=2O35//W9FQ5IKU/Cbd8r5okkqi03NYvfMAv2voXig4r+y6Ea+wIunHgRXBEhiJ8P9K TspR55Gd5xPj+EMwpvhkdhS4uzCvkZ4/7BjhIZRHlr24OPgvv589pITUzthDkSSnw15O Lc+0Cs5ciOyne5CrNSZCu10q+3K4Cmw4vIS2clXA8vTW6Zo6iPA3mkVnZ+eIRateeRz2 sgJpNcmqbtE+2NlWvDWKQiNAcnBCYLOha3DZtvfT6vq24EWWJOb3ZvQoypM+BT3hZlKn /HD1BSuof9fud/EpiT+uWttp/M3ZpWdA5I4Lt47dUXBfUsPcNnO0QWtr8bN3KD/5WZOc 3Fpw== X-Gm-Message-State: AOAM531Xt9svFBTiBi/KtjHNi/lZImtY42w4IyL5FQVyx+eZ8WD1ftkj DJNQWIdzqpACZMoFdAgzA9GM27TCmx4= X-Google-Smtp-Source: ABdhPJy8fACfQ4jyGr9xF342/z75NoNcLTDY10G+LWoaiStO0hTLZbGlHwL73c3ZjRYtS31XbeKhwJgw3p0= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:36eb:759:798f:98c3]) (user=glider job=sendgmr) by 2002:a17:906:9acd:b0:6e0:b74d:d932 with SMTP id ah13-20020a1709069acd00b006e0b74dd932mr24156373ejc.695.1648557754011; Tue, 29 Mar 2022 05:42:34 -0700 (PDT) Date: Tue, 29 Mar 2022 14:40:16 +0200 In-Reply-To: <20220329124017.737571-1-glider@google.com> Message-Id: <20220329124017.737571-48-glider@google.com> Mime-Version: 1.0 References: <20220329124017.737571-1-glider@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 47/48] x86: kmsan: handle register passing from uninstrumented code From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , 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 , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 566FE100004 X-Stat-Signature: ukzmk1nwgaq9iq411dxg8k83hjjx6938 X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=EBgX4Z2S; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf14.hostedemail.com: domain of 3uv5CYgYKCNsDIFABODLLDIB.9LJIFKRU-JJHS79H.LOD@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3uv5CYgYKCNsDIFABODLLDIB.9LJIFKRU-JJHS79H.LOD@flex--glider.bounces.google.com X-HE-Tag: 1648557755-546371 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: Replace instrumentation_begin() with instrumentation_begin_with_regs() to let KMSAN handle the non-instrumented code and unpoison pt_regs passed from the instrumented part. This is done to reduce the number of false positive reports. Signed-off-by: Alexander Potapenko --- v2: -- this patch was previously called "x86: kmsan: handle register passing from uninstrumented code". Instead of adding KMSAN-specific code to every instrumentation_begin()/instrumentation_end() section, we changed instrumentation_begin() to instrumentation_begin_with_regs() where applicable. Link: https://linux-review.googlesource.com/id/I435ec076cd21752c2f877f5da81f5eced62a2ea4 --- arch/x86/entry/common.c | 3 ++- arch/x86/include/asm/idtentry.h | 10 +++++----- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/kvm.c | 2 +- arch/x86/kernel/nmi.c | 2 +- arch/x86/kernel/sev.c | 4 ++-- arch/x86/kernel/traps.c | 14 +++++++------- arch/x86/mm/fault.c | 2 +- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 6c2826417b337..047d157987859 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -75,7 +76,7 @@ __visible noinstr void do_syscall_64(struct pt_regs *regs, int nr) add_random_kstack_offset(); nr = syscall_enter_from_user_mode(regs, nr); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); if (!do_syscall_x64(regs, nr) && !do_syscall_x32(regs, nr) && nr != -1) { /* Invalid system call, but still a system call. */ diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h index 1345088e99025..f24ff33fc3681 100644 --- a/arch/x86/include/asm/idtentry.h +++ b/arch/x86/include/asm/idtentry.h @@ -51,7 +51,7 @@ __visible noinstr void func(struct pt_regs *regs) \ { \ irqentry_state_t state = irqentry_enter(regs); \ \ - instrumentation_begin(); \ + instrumentation_begin_with_regs(regs); \ __##func (regs); \ instrumentation_end(); \ irqentry_exit(regs, state); \ @@ -98,7 +98,7 @@ __visible noinstr void func(struct pt_regs *regs, \ { \ irqentry_state_t state = irqentry_enter(regs); \ \ - instrumentation_begin(); \ + instrumentation_begin_with_regs(regs); \ __##func (regs, error_code); \ instrumentation_end(); \ irqentry_exit(regs, state); \ @@ -195,7 +195,7 @@ __visible noinstr void func(struct pt_regs *regs, \ irqentry_state_t state = irqentry_enter(regs); \ u32 vector = (u32)(u8)error_code; \ \ - instrumentation_begin(); \ + instrumentation_begin_with_regs(regs); \ kvm_set_cpu_l1tf_flush_l1d(); \ run_irq_on_irqstack_cond(__##func, regs, vector); \ instrumentation_end(); \ @@ -235,7 +235,7 @@ __visible noinstr void func(struct pt_regs *regs) \ { \ irqentry_state_t state = irqentry_enter(regs); \ \ - instrumentation_begin(); \ + instrumentation_begin_with_regs(regs); \ kvm_set_cpu_l1tf_flush_l1d(); \ run_sysvec_on_irqstack_cond(__##func, regs); \ instrumentation_end(); \ @@ -262,7 +262,7 @@ __visible noinstr void func(struct pt_regs *regs) \ { \ irqentry_state_t state = irqentry_enter(regs); \ \ - instrumentation_begin(); \ + instrumentation_begin_with_regs(regs); \ __irq_enter_raw(); \ kvm_set_cpu_l1tf_flush_l1d(); \ __##func (regs); \ diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 5818b837fd4d4..7b8c43d8727cc 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -1355,7 +1355,7 @@ static void queue_task_work(struct mce *m, char *msg, void (*func)(struct callba /* Handle unconfigured int18 (should never happen) */ static noinstr void unexpected_machine_check(struct pt_regs *regs) { - instrumentation_begin(); + instrumentation_begin_with_regs(regs); pr_err("CPU#%d: Unexpected int18 (Machine Check)\n", smp_processor_id()); instrumentation_end(); diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index d77481ecb0d5f..eaed9b412908c 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -249,7 +249,7 @@ noinstr bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token) return false; state = irqentry_enter(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); /* * If the host managed to inject an async #PF into an interrupt diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 4bce802d25fb1..3f987a5dc38c7 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch/x86/kernel/nmi.c @@ -329,7 +329,7 @@ static noinstr void default_do_nmi(struct pt_regs *regs) __this_cpu_write(last_nmi_rip, regs->ip); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); handled = nmi_handle(NMI_LOCAL, regs); __this_cpu_add(nmi_stats.normal, handled); diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index e6d316a01fdd4..9bfc29fc9c983 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1330,7 +1330,7 @@ DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication) irq_state = irqentry_nmi_enter(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); if (!vc_raw_handle_exception(regs, error_code)) { /* Show some debug info */ @@ -1362,7 +1362,7 @@ DEFINE_IDTENTRY_VC_USER(exc_vmm_communication) } irqentry_enter_from_user_mode(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); if (!vc_raw_handle_exception(regs, error_code)) { /* diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 8143693a7ea6e..f08741abc0e5b 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -229,7 +229,7 @@ static noinstr bool handle_bug(struct pt_regs *regs) /* * All lies, just get the WARN/BUG out. */ - instrumentation_begin(); + instrumentation_begin_with_regs(regs); /* * Since we're emulating a CALL with exceptions, restore the interrupt * state to what it was at the exception site. @@ -260,7 +260,7 @@ DEFINE_IDTENTRY_RAW(exc_invalid_op) return; state = irqentry_enter(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); handle_invalid_op(regs); instrumentation_end(); irqentry_exit(regs, state); @@ -414,7 +414,7 @@ DEFINE_IDTENTRY_DF(exc_double_fault) #endif irqentry_nmi_enter(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV); tsk->thread.error_code = error_code; @@ -690,14 +690,14 @@ DEFINE_IDTENTRY_RAW(exc_int3) */ if (user_mode(regs)) { irqentry_enter_from_user_mode(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); do_int3_user(regs); instrumentation_end(); irqentry_exit_to_user_mode(regs); } else { irqentry_state_t irq_state = irqentry_nmi_enter(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); if (!do_int3(regs)) die("int3", regs, 0); instrumentation_end(); @@ -896,7 +896,7 @@ static __always_inline void exc_debug_kernel(struct pt_regs *regs, */ unsigned long dr7 = local_db_save(); irqentry_state_t irq_state = irqentry_nmi_enter(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); /* * If something gets miswired and we end up here for a user mode @@ -975,7 +975,7 @@ static __always_inline void exc_debug_user(struct pt_regs *regs, */ irqentry_enter_from_user_mode(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); /* * Start the virtual/ptrace DR6 value with just the DR_STEP mask diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index f2250a32a10ca..676e394f1af5b 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1557,7 +1557,7 @@ DEFINE_IDTENTRY_RAW_ERRORCODE(exc_page_fault) */ state = irqentry_enter(regs); - instrumentation_begin(); + instrumentation_begin_with_regs(regs); handle_page_fault(regs, error_code, address); instrumentation_end(); -- 2.35.1.1021.g381101b075-goog