From patchwork Thu Nov 30 08:59:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 171782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp245800vqy; Thu, 30 Nov 2023 00:59:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGN77dJ5m2Jx76HJThu7M7/sLCvJVebMc0IsvxILne0fTllEl4ZTZ9kFUI5Ejp+kjFQd4f X-Received: by 2002:a05:6a21:99a7:b0:18a:b5c3:55db with SMTP id ve39-20020a056a2199a700b0018ab5c355dbmr22967165pzb.50.1701334795975; Thu, 30 Nov 2023 00:59:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701334795; cv=none; d=google.com; s=arc-20160816; b=wWQHIHnuOC8rL/5uwN70rfNRBmFCyd8mkKdhESU5jyDZDK5YRmYWrFfotyq27AHJJ+ PiLmZDLD0RfHQ89hGAR+pyqWryW0aX6zOLEXLWj8p/+RDk2vXn2ipse3iJU5fephPG43 rH/gOJ6FkzI8p3eUvFlO4LCa5TYHj2kIKU6E1XDX0Z8ruM8c2O12DSAXhKqdfvd52l/h hph1A6DMHNq9UEFnSQhkl5TOxhAtf2YvRHraSUzLuhUwAa64nEMuQ1AL6f+76n9lx+Tv 4b5tEVqQzw+Z+bBLe/sTvOdNrMYxpz6hygilihVWcrnQGLFn9wRWtA8kdTVzc2FapRMm DNOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=0LR4zPKXvm7NvzMxgz4J/hjCIAaXCpTlSh1BXJxmOgQ=; fh=8J6Mbr/ZW4FtJ+Ad9zDxwpu05ne7BjQ+QHgXwaRmEO8=; b=bskD/bvrLZOIrKhhBlCmEWEqEipOZPmrwj6F6g0qPkIwj24MxMB+GOtzaCDcZffYq6 gDfcn2/3xEHxBwlQH7EXLaw5NQm+LA3+Be+zT4oijhW7kqaU42pz7P0Nv2eVUmA5pmD6 jsIpNm8MJ/P/2FWNp7NJlpbRwS8RyqB10hJaKD+68OxZtUZabh2Fz3VAID9ugWBzEeT1 BLV9tE0XneuqxS2KpoWqNYBAwUECq8nkR9nZjCnys5bTibFmlwcqEL7NER7XDrV0fnov XFh+8oOFS6cGELHqAcpsVypN9J1zZkj0Ug+VmEgSe1Z/LGR/HQvksQDD5sFeARoxFNnN Ku4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=T0yNg63k; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=tw3Z+1Vd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id y16-20020a656c10000000b0059b79bf220csi852566pgu.662.2023.11.30.00.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 00:59:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=T0yNg63k; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=tw3Z+1Vd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CF70B80CFD19; Thu, 30 Nov 2023 00:59:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231782AbjK3I7n (ORCPT + 99 others); Thu, 30 Nov 2023 03:59:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjK3I7l (ORCPT ); Thu, 30 Nov 2023 03:59:41 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4357BB9; Thu, 30 Nov 2023 00:59:47 -0800 (PST) Date: Thu, 30 Nov 2023 08:59:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701334785; h=from:from:sender:sender:reply-to: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:content-transfer-encoding; bh=0LR4zPKXvm7NvzMxgz4J/hjCIAaXCpTlSh1BXJxmOgQ=; b=T0yNg63kaIh0ySWe9LTnOSW7y0UMEYCrWOuMoUUI8WEXX2Wlk3NagQ99uoGvpt/291Rqq5 yfpU0W3d9cmdun3ZyS+J+zjZ8ItQTUFpNnCBZzmBC71LpeyWV60AaBpjSNke0V3krDjDgI 4v7LaJhJNAaghxP4+1olADtVnmeczaRV/2fqfH28xwEG/RcRWL8eEB2oEXEz93oy2D48Cc LsaSj2yJdjqDmsojsgXiog7kYRvfYe9dBcwoY8UM4GfWmEmBcVV1TDB1p/7oCYGW20QZVn aTfy7Lds82CPRn1Vp9thqjWgUIHTgN6Mu5SEdoul6szbW1KqeUCtZtpvmQJxsw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701334785; h=from:from:sender:sender:reply-to: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:content-transfer-encoding; bh=0LR4zPKXvm7NvzMxgz4J/hjCIAaXCpTlSh1BXJxmOgQ=; b=tw3Z+1VdzkNrS26RMGVO4eBqvdje24+5eodyUIR8Yxf90AjmHUCbrnmkvnKIfr3uogVn1y wwF3+qaUZBRb45Aw== From: "tip-bot2 for Jun'ichi Nomura" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/boot: Ignore NMIs during very early boot Cc: "Jun'ichi Nomura" , Derek Barbosa , Ingo Molnar , Kees Cook , Linus Torvalds , "Paul E. McKenney" , Andy Lutomirski , "H. Peter Anvin" , Peter Zijlstra , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <170133478498.398.5261666675868615202.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 30 Nov 2023 00:59:52 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783978835061552634 X-GMAIL-MSGID: 1783978835061552634 The following commit has been merged into the x86/boot branch of tip: Commit-ID: 78a509fba9c9b1fcb77f95b7c6be30da3d24823a Gitweb: https://git.kernel.org/tip/78a509fba9c9b1fcb77f95b7c6be30da3d24823a Author: Jun'ichi Nomura AuthorDate: Wed, 29 Nov 2023 15:44:49 -05:00 Committer: Ingo Molnar CommitterDate: Thu, 30 Nov 2023 09:55:40 +01:00 x86/boot: Ignore NMIs during very early boot When there are two racing NMIs on x86, the first NMI invokes NMI handler and the 2nd NMI is latched until IRET is executed. If panic on NMI and panic kexec are enabled, the first NMI triggers panic and starts booting the next kernel via kexec. Note that the 2nd NMI is still latched. During the early boot of the next kernel, once an IRET is executed as a result of a page fault, then the 2nd NMI is unlatched and invokes the NMI handler. However, NMI handler is not set up at the early stage of boot, which results in a boot failure. Avoid such problems by setting up a NOP handler for early NMIs. [ mingo: Refined the changelog. ] Signed-off-by: Jun'ichi Nomura Signed-off-by: Derek Barbosa Signed-off-by: Ingo Molnar Cc: Kees Cook Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Andy Lutomirski Cc: "H. Peter Anvin" Cc: Peter Zijlstra --- arch/x86/boot/compressed/ident_map_64.c | 5 +++++ arch/x86/boot/compressed/idt_64.c | 1 + arch/x86/boot/compressed/idt_handlers_64.S | 1 + arch/x86/boot/compressed/misc.h | 1 + 4 files changed, 8 insertions(+) diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c index 473ba59..d040080 100644 --- a/arch/x86/boot/compressed/ident_map_64.c +++ b/arch/x86/boot/compressed/ident_map_64.c @@ -386,3 +386,8 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code) */ kernel_add_identity_map(address, end); } + +void do_boot_nmi_trap(struct pt_regs *regs, unsigned long error_code) +{ + /* Empty handler to ignore NMI during early boot */ +} diff --git a/arch/x86/boot/compressed/idt_64.c b/arch/x86/boot/compressed/idt_64.c index 3cdf94b..d100284 100644 --- a/arch/x86/boot/compressed/idt_64.c +++ b/arch/x86/boot/compressed/idt_64.c @@ -61,6 +61,7 @@ void load_stage2_idt(void) boot_idt_desc.address = (unsigned long)boot_idt; set_idt_entry(X86_TRAP_PF, boot_page_fault); + set_idt_entry(X86_TRAP_NMI, boot_nmi_trap); #ifdef CONFIG_AMD_MEM_ENCRYPT /* diff --git a/arch/x86/boot/compressed/idt_handlers_64.S b/arch/x86/boot/compressed/idt_handlers_64.S index 22890e1..4d03c85 100644 --- a/arch/x86/boot/compressed/idt_handlers_64.S +++ b/arch/x86/boot/compressed/idt_handlers_64.S @@ -70,6 +70,7 @@ SYM_FUNC_END(\name) .code64 EXCEPTION_HANDLER boot_page_fault do_boot_page_fault error_code=1 +EXCEPTION_HANDLER boot_nmi_trap do_boot_nmi_trap error_code=0 #ifdef CONFIG_AMD_MEM_ENCRYPT EXCEPTION_HANDLER boot_stage1_vc do_vc_no_ghcb error_code=1 diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index c0d502b..bc2f0f1 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -196,6 +196,7 @@ static inline void cleanup_exception_handling(void) { } /* IDT Entry Points */ void boot_page_fault(void); +void boot_nmi_trap(void); void boot_stage1_vc(void); void boot_stage2_vc(void);