Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4493873ybv; Tue, 25 Feb 2020 21:29:40 -0800 (PST) X-Google-Smtp-Source: APXvYqz3WBMTQazdDPYOqr/uYL5D2hULjR4ge6XL3w1YGnb/B3PDyfyVK7ZypNWdMvAv3kbfCm0v X-Received: by 2002:aca:ab52:: with SMTP id u79mr1659765oie.145.1582694979884; Tue, 25 Feb 2020 21:29:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582694979; cv=none; d=google.com; s=arc-20160816; b=HljwSAdA7UfYt+MSUY0aTvEVO5q5VD0cjqhW2weeDIzf2Do4zAhZFzyvCxO0Ge98N0 r3cJzp/gXKkvNKxrKt3WZzKImRfOZaxMD8Wkj0xaMrKhqLKD25HlVTDBUiTqXxBAZLs/ Q7Ae9NRTLkQvk7Bb7zqhOOjOk4z8owTXGN/HphDytFCQagffApv+DlknIAS+eW1AtOih o1V/fhEsecRZB1y5AbKGdPB4zg1+LD5wbYEoiPD+X/cUOzWpIWaYL3MKMT0aSsUP+eH4 611nmy9sIMCj/IhnjUuQR2bPq2yktCfk2jcKMGjmTY2BoQmhRBwZ8XYJiFydmt54qn8l McVw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=pIKtXWs08QHcgpjYpSrZMJZhZRwieXlUPb5L4pm59Ns=; b=dscanHss1T1Rzc2TUqVNdolDeHjjNQD/XxgnQ0ldvOcOTfmPsvqij97peJK++5vs72 F3nzA0H+MRtp2EjrMnQgkbzcSjxHZXxeNWmY6DMQxIIOolL6pbUMPXniiBEjzAYW22G1 wnPQcpxWYnIHpF4uTrhArJIQtnsEMmRgLJwODS8+eKK88Gs0ng/wxGmgIqTPjVYyIJw1 lPtgapjfSkpjDfgyYpBTxz8OKxzakSboyEUbYLMgtNad32/Cm8379dz9mSPaXq8Jq4md d4vCXHTUsFvJj8o5clncP6786wQPK7YwOe7ToLwYNeLoYaBrjuUj8CEdZlb0ygUAwWDF mjrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mFeHjgEf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si692695otp.310.2020.02.25.21.29.28; Tue, 25 Feb 2020 21:29:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mFeHjgEf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726948AbgBZF3C (ORCPT + 99 others); Wed, 26 Feb 2020 00:29:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:33542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbgBZF3C (ORCPT ); Wed, 26 Feb 2020 00:29:02 -0500 Received: from [192.168.0.217] (c-67-180-165-146.hsd1.ca.comcast.net [67.180.165.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 25C4C21927; Wed, 26 Feb 2020 05:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582694941; bh=7EZlyJmfitwu9cl72s933JiTNqw/gi+6NG4TRgo4WRE=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=mFeHjgEfkA7pOt7jfFCg5L8mtHjs+k/GwAC0YTe/YMbPlM6xs8nk5DwfglUYqtaBX DGKrhZbXoBF5M3sOjnsPaapdshJIQsDRgIMQs2GSp/YZAvr+1DfsEehDWrZIjlYjEN xQxZ2xvc/FUDtccjB03rf+4xH0yDfV5bGvG9Db3s= Subject: Re: [patch 02/10] x86/mce: Disable tracing and kprobes on do_machine_check() To: Frederic Weisbecker , Thomas Gleixner Cc: LKML , x86@kernel.org, Steven Rostedt , Brian Gerst , Juergen Gross , Paolo Bonzini , Arnd Bergmann References: <20200225213636.689276920@linutronix.de> <20200225220216.315548935@linutronix.de> <20200226011349.GH9599@lenoir> From: Andy Lutomirski Message-ID: Date: Tue, 25 Feb 2020 21:29:00 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200226011349.GH9599@lenoir> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/25/20 5:13 PM, Frederic Weisbecker wrote: > On Tue, Feb 25, 2020 at 10:36:38PM +0100, Thomas Gleixner wrote: >> From: Andy Lutomirski >> >> do_machine_check() can be raised in almost any context including the most >> fragile ones. Prevent kprobes and tracing. >> >> Signed-off-by: Andy Lutomirski >> Signed-off-by: Thomas Gleixner >> --- >> arch/x86/include/asm/traps.h | 3 --- >> arch/x86/kernel/cpu/mce/core.c | 12 ++++++++++-- >> 2 files changed, 10 insertions(+), 5 deletions(-) >> >> --- a/arch/x86/include/asm/traps.h >> +++ b/arch/x86/include/asm/traps.h >> @@ -88,9 +88,6 @@ dotraplinkage void do_page_fault(struct >> dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code); >> dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code); >> dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code); >> -#ifdef CONFIG_X86_MCE >> -dotraplinkage void do_machine_check(struct pt_regs *regs, long error_code); >> -#endif >> dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code); >> #ifdef CONFIG_X86_32 >> dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code); >> --- a/arch/x86/kernel/cpu/mce/core.c >> +++ b/arch/x86/kernel/cpu/mce/core.c >> @@ -1213,8 +1213,14 @@ static void __mc_scan_banks(struct mce * >> * On Intel systems this is entered on all CPUs in parallel through >> * MCE broadcast. However some CPUs might be broken beyond repair, >> * so be always careful when synchronizing with others. >> + * >> + * Tracing and kprobes are disabled: if we interrupted a kernel context >> + * with IF=1, we need to minimize stack usage. There are also recursion >> + * issues: if the machine check was due to a failure of the memory >> + * backing the user stack, tracing that reads the user stack will cause >> + * potentially infinite recursion. >> */ >> -void do_machine_check(struct pt_regs *regs, long error_code) >> +void notrace do_machine_check(struct pt_regs *regs, long error_code) >> { >> DECLARE_BITMAP(valid_banks, MAX_NR_BANKS); >> DECLARE_BITMAP(toclear, MAX_NR_BANKS); >> @@ -1360,6 +1366,7 @@ void do_machine_check(struct pt_regs *re >> ist_exit(regs); >> } >> EXPORT_SYMBOL_GPL(do_machine_check); >> +NOKPROBE_SYMBOL(do_machine_check); > > That won't protect all the function called by do_machine_check(), right? > There are lots of them. > It at least means we can survive to run actual C code in do_machine_check(), which lets us try to mitigate this issue further. PeterZ has patches for that, and maybe this series fixes it later on. (I'm reading in order!)