Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp645524ybz; Wed, 15 Apr 2020 15:51:43 -0700 (PDT) X-Google-Smtp-Source: APiQypI6semVtGYcT9stX8xxXb+eVln3csJE0hBFu7FF1ZiqePNcuxGuU7DDJ3kkye6Zk+GHFiw4 X-Received: by 2002:a05:6402:14c1:: with SMTP id f1mr15137065edx.221.1586991102919; Wed, 15 Apr 2020 15:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586991102; cv=none; d=google.com; s=arc-20160816; b=i/Go4oYpa5Zz0ObFOEFNOe4QnYPkiE01XUZsB5Fp2jSSnbJKSC3mB6UthQVkMGZ5GB wbyUvPJ99Mum6uYf2KvxbUs2BM5WZsujShraCeDUEwF//Ue266D1dWQEW4O94611+Kv2 lOOWhkhO+Ffn0B+M7WHXCR88eCOnY25O8xA8LaoqdPdvrJ+i9KVUCcAXH0POF/4tWBJV CtNsbvJq0WMMO/HLbjusINgGyRyCw7oF5GFSFMGpR2N49DZCz2FFsmiau3gqyg+hdvOL O/7buscYI3trE5h+BYJFreuTuqRaF303SSW5flj0hpsHa2YWlMxkAYBiIeoKZEaaZwLJ 1kiw== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=wexxU4vWzroEyqXWtFob6GYxEVb4Nw8MNwbZyLzycmU=; b=e51jROknU9aXwF2ljhp5p+1bQCfLiKFC0Hf8oLVVCdRGs+xpBn/7Q90FD4bW8PPvRq pBhizQY+kMbWmNq1d4jOuGBZof7yMpwaNt/yw2UJcfXhkY1WOpbqKjN35fz3sAWbRQQN krufr8EM8L+xWWupYBVf6UwkX43PFYtpkhHPFGtAiuTyz3nys+6Ad4DqLvEF4hBFKHTS z2la5BgVpMI1v9M5CXw3jQapG0APbk311y9z9OnkGZpI3zpkqXF9fp4uiw7IncxOtLdH KGNK0PZpxPaaCfMhN/dffGkwkpg+gM8kCcrynegyPkc/XEOik62qPt76cMYugkcvU+U/ Jv9w== 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 h10si10989794ejt.278.2020.04.15.15.51.19; Wed, 15 Apr 2020 15:51:42 -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 S2895966AbgDOJvJ (ORCPT + 99 others); Wed, 15 Apr 2020 05:51:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2895900AbgDOJuB (ORCPT ); Wed, 15 Apr 2020 05:50:01 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AAF6C061A0C; Wed, 15 Apr 2020 02:50:01 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jOefz-0005rO-1R; Wed, 15 Apr 2020 11:49:47 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 7ACFF1C0081; Wed, 15 Apr 2020 11:49:46 +0200 (CEST) Date: Wed, 15 Apr 2020 09:49:46 -0000 From: "tip-bot2 for Borislav Petkov" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: ras/core] x86/mce: Fixup exception only for the correct MCEs Cc: Thomas Gleixner , Borislav Petkov , Tony Luck , x86 , LKML In-Reply-To: <20200407163414.18058-10-bp@alien8.de> References: <20200407163414.18058-10-bp@alien8.de> MIME-Version: 1.0 Message-ID: <158694418608.28353.4166689107383983190.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following commit has been merged into the ras/core branch of tip: Commit-ID: 1df73b2131e3b33d518609769636b41ce00212de Gitweb: https://git.kernel.org/tip/1df73b2131e3b33d518609769636b41ce00212de Author: Borislav Petkov AuthorDate: Tue, 07 Apr 2020 13:49:58 +02:00 Committer: Borislav Petkov CommitterDate: Tue, 14 Apr 2020 16:01:49 +02:00 x86/mce: Fixup exception only for the correct MCEs The severity grading code returns IN_KERNEL_RECOV error context for errors which have happened in kernel space but from which the kernel can recover. Whether the recovery can happen is determined by the exception table entry having as handler ex_handler_fault() and which has been declared at build time using _ASM_EXTABLE_FAULT(). IN_KERNEL_RECOV is used in mce_severity_intel() to lookup the corresponding error severity in the severities table. However, the mapping back from error severity to whether the error is IN_KERNEL_RECOV is ambiguous and in the very paranoid case - which might not be possible right now - but be better safe than sorry later, an exception fixup could be attempted for another MCE whose address is in the exception table and has the proper severity. Which would be unfortunate, to say the least. Therefore, mark such MCEs explicitly as MCE_IN_KERNEL_RECOV so that the recovery attempt is done only for them. Document the whole handling, while at it, as it is not trivial. Reported-by: Thomas Gleixner Signed-off-by: Borislav Petkov Tested-by: Tony Luck Link: https://lkml.kernel.org/r/20200407163414.18058-10-bp@alien8.de --- arch/x86/include/asm/mce.h | 1 + arch/x86/kernel/cpu/mce/core.c | 15 +++++++++++++-- arch/x86/kernel/cpu/mce/severity.c | 6 +++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/mce.h b/arch/x86/include/asm/mce.h index 5f04a24..c598aaa 100644 --- a/arch/x86/include/asm/mce.h +++ b/arch/x86/include/asm/mce.h @@ -136,6 +136,7 @@ #define MCE_HANDLED_NFIT BIT_ULL(3) #define MCE_HANDLED_EDAC BIT_ULL(4) #define MCE_HANDLED_MCELOG BIT_ULL(5) +#define MCE_IN_KERNEL_RECOV BIT_ULL(6) /* * This structure contains all data related to the MCE log. Also diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 4efe6c1..02e1f16 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -1331,8 +1331,19 @@ void notrace do_machine_check(struct pt_regs *regs, long error_code) local_irq_disable(); ist_end_non_atomic(); } else { - if (!fixup_exception(regs, X86_TRAP_MC, error_code, 0)) - mce_panic("Failed kernel mode recovery", &m, msg); + /* + * Handle an MCE which has happened in kernel space but from + * which the kernel can recover: ex_has_fault_handler() has + * already verified that the rIP at which the error happened is + * a rIP from which the kernel can recover (by jumping to + * recovery code specified in _ASM_EXTABLE_FAULT()) and the + * corresponding exception handler which would do that is the + * proper one. + */ + if (m.kflags & MCE_IN_KERNEL_RECOV) { + if (!fixup_exception(regs, X86_TRAP_MC, error_code, 0)) + mce_panic("Failed kernel mode recovery", &m, msg); + } } out_ist: diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/severity.c index 87bcdc6..e1da619 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -213,8 +213,12 @@ static int error_context(struct mce *m) { if ((m->cs & 3) == 3) return IN_USER; - if (mc_recoverable(m->mcgstatus) && ex_has_fault_handler(m->ip)) + + if (mc_recoverable(m->mcgstatus) && ex_has_fault_handler(m->ip)) { + m->kflags |= MCE_IN_KERNEL_RECOV; return IN_KERNEL_RECOV; + } + return IN_KERNEL; }