Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp767956ybj; Tue, 5 May 2020 07:17:04 -0700 (PDT) X-Google-Smtp-Source: APiQypKh+YgS73VucF974ngUDvNB/VEXH8gXUwYzD265sfZdqeIYhNHKnE+Dr1RhJFTr075zaVT4 X-Received: by 2002:a17:906:5fd2:: with SMTP id k18mr2756774ejv.243.1588688224656; Tue, 05 May 2020 07:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588688224; cv=none; d=google.com; s=arc-20160816; b=S5ze8w0i/maSckNA0Mwdc7GMj5LHCzmsnRONwyxSI3ybbnnsoOXENQ810A9iANk7X8 QBuX76UYv007fByDk815J3KyQd8HHrbrVN832Yw1uuRMzAOBIwcVO3Sbrwb6O90H1tGr iDzlZuiG2aDqFZWsbo1IcldSBHPUMBkAJrfNpxXqayVKVkWEtydC7Kt5hjEAParANxON Es7iSA5s8GSjJiSezUyVz/PJx4c7evwtdedTwrOTep77WoYDanmqtyrFuG6rabZPkiMI dbxW30xQIwAif5Adu14Qw9gn4uhGu2jRL8DBLHWGyFuNqz3nsgDb9mvq78/nulQwFVXO YbQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:subject:cc:to:from:date:user-agent:message-id; bh=i1nLc5EQTOP9wsXMtF+OrZBvg80vQ9c9V4yaMRNpjyg=; b=Bo97LUPs6eSCq0cxGN4geQPKJm4Nd9akgeIPqusKC8eL1ml3gbxjtw/vFVH72UwQ9a 7uvSsF5X5UMuMEtwf35fjqH+VjajHTYqEDk0CRr8XUCrn0ih66t5p/V8oic+tHan/Z4g FQn03l3ADZwg0JzICuhIvw7iBwmfp3JFSWQxnI3mmSSsPbuQ1LWDh9m07z8WpJSmUSCt ctq5boIEBPbBpjbJbDcOFH441O+zd/InamTSHPxxTrR5zH5gnDi7mNoD4yySulZ6rJqY R3v6i2BVTO+oWagkSd8btc3Z475Soo3jO3VSFJPqB/xQo4m7HmDPGtn/s2lTdWLOv3hs sENQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z13si1246463eju.18.2020.05.05.07.16.34; Tue, 05 May 2020 07:17:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729535AbgEEOON (ORCPT + 99 others); Tue, 5 May 2020 10:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729511AbgEEOOI (ORCPT ); Tue, 5 May 2020 10:14:08 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 781BCC061A0F for ; Tue, 5 May 2020 07:14:08 -0700 (PDT) Received: from p5de0bf0b.dip0.t-ipconnect.de ([93.224.191.11] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jVyKU-0000iC-As; Tue, 05 May 2020 16:13:50 +0200 Received: from nanos.tec.linutronix.de (localhost [IPv6:::1]) by nanos.tec.linutronix.de (Postfix) with ESMTP id D42831001F5; Tue, 5 May 2020 16:13:49 +0200 (CEST) Message-Id: <20200505134100.957390899@linutronix.de> User-Agent: quilt/0.65 Date: Tue, 05 May 2020 15:16:31 +0200 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, "Paul E. McKenney" , Andy Lutomirski , Alexandre Chartre , Frederic Weisbecker , Paolo Bonzini , Sean Christopherson , Masami Hiramatsu , Petr Mladek , Steven Rostedt , Joel Fernandes , Boris Ostrovsky , Juergen Gross , Brian Gerst , Mathieu Desnoyers , Josh Poimboeuf , Will Deacon , "Peter Zijlstra (Intel)" Subject: [patch V4 part 1 29/36] x86/mce: Send #MC singal from task work References: <20200505131602.633487962@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra Convert #MC over to using task_work_add(); it will run the same code slightly later, on the return to user path of the same exception. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner Reviewed-by: Frederic Weisbecker --- arch/x86/kernel/cpu/mce/core.c | 56 ++++++++++++++++++++++------------------- include/linux/sched.h | 6 ++++ 2 files changed, 37 insertions(+), 25 deletions(-) --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -1086,23 +1087,6 @@ static void mce_clear_state(unsigned lon } } -static int do_memory_failure(struct mce *m) -{ - int flags = MF_ACTION_REQUIRED; - int ret; - - pr_err("Uncorrected hardware memory error in user-access at %llx", m->addr); - if (!(m->mcgstatus & MCG_STATUS_RIPV)) - flags |= MF_MUST_KILL; - ret = memory_failure(m->addr >> PAGE_SHIFT, flags); - if (ret) - pr_err("Memory error not recovered"); - else - set_mce_nospec(m->addr >> PAGE_SHIFT); - return ret; -} - - /* * Cases where we avoid rendezvous handler timeout: * 1) If this CPU is offline. @@ -1204,6 +1188,29 @@ static void __mc_scan_banks(struct mce * *m = *final; } +static void kill_me_now(struct callback_head *ch) +{ + force_sig(SIGBUS); +} + +static void kill_me_maybe(struct callback_head *cb) +{ + struct task_struct *p = container_of(cb, struct task_struct, mce_kill_me); + int flags = MF_ACTION_REQUIRED; + + pr_err("Uncorrected hardware memory error in user-access at %llx", p->mce_addr); + if (!(p->mce_status & MCG_STATUS_RIPV)) + flags |= MF_MUST_KILL; + + if (!memory_failure(p->mce_addr >> PAGE_SHIFT, flags)) { + set_mce_nospec(p->mce_addr >> PAGE_SHIFT); + return; + } + + pr_err("Memory error not recovered"); + kill_me_now(cb); +} + /* * The actual machine check handler. This only handles real * exceptions when something got corrupted coming in through int 18. @@ -1222,7 +1229,7 @@ static void __mc_scan_banks(struct mce * * backing the user stack, tracing that reads the user stack will cause * potentially infinite recursion. */ -void notrace do_machine_check(struct pt_regs *regs, long error_code) +void noinstr do_machine_check(struct pt_regs *regs, long error_code) { DECLARE_BITMAP(valid_banks, MAX_NR_BANKS); DECLARE_BITMAP(toclear, MAX_NR_BANKS); @@ -1354,13 +1361,13 @@ void notrace do_machine_check(struct pt_ if ((m.cs & 3) == 3) { /* If this triggers there is no way to recover. Die hard. */ BUG_ON(!on_thread_stack() || !user_mode(regs)); - local_irq_enable(); - preempt_enable(); - if (kill_it || do_memory_failure(&m)) - force_sig(SIGBUS); - preempt_disable(); - local_irq_disable(); + current->mce_addr = m.addr; + current->mce_status = m.mcgstatus; + current->mce_kill_me.func = kill_me_maybe; + if (kill_it) + current->mce_kill_me.func = kill_me_now; + task_work_add(current, ¤t->mce_kill_me, true); } else { if (!fixup_exception(regs, X86_TRAP_MC, error_code, 0)) mce_panic("Failed kernel mode recovery", &m, msg); @@ -1370,7 +1377,6 @@ void notrace do_machine_check(struct pt_ ist_exit(regs); } EXPORT_SYMBOL_GPL(do_machine_check); -NOKPROBE_SYMBOL(do_machine_check); #ifndef CONFIG_MEMORY_FAILURE int memory_failure(unsigned long pfn, int flags) --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1290,6 +1290,12 @@ struct task_struct { unsigned long prev_lowest_stack; #endif +#ifdef CONFIG_X86_MCE + u64 mce_addr; + u64 mce_status; + struct callback_head mce_kill_me; +#endif + /* * New fields for task_struct should be added above here, so that * they are included in the randomized portion of task_struct.