Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp140029rdb; Mon, 15 Jan 2024 15:35:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9X/LOrbBRDcHoqVIz4ENfehEZ1zjSye7dkd+uOvvN/uZRQT2iWxg/M3oGRqt0ojca4BzG X-Received: by 2002:a17:907:7284:b0:a2c:d8cd:e541 with SMTP id dt4-20020a170907728400b00a2cd8cde541mr1784254ejc.108.1705361704623; Mon, 15 Jan 2024 15:35:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705361704; cv=none; d=google.com; s=arc-20160816; b=d7oiYjD5UV1Z+Guoq2cDo6UH1j0orjTRnEKt3drVd+jfgq/SbMeIyGwkcckqTTpCS9 duwvIN13yuvowBS9CZvGbj/RfeoHrfynEGV9qh+Oz6OF/48BTMEU8FaqV3oOk7BYk4Mx cBvNpidi+jUf5MVQ5ryN63smKH0ZPRo+UQwydA9PGGS2VjKPqhjZnhnVEVurCzFfzN44 0X2+pn1x2h5udQ6Bz2caxN4FMYvwX6r+lQwC40n6qOnWsQGme+TdFoBbv/DZgcIa2AR7 1/6K25+INaGy2J/WexDW6FcF3Uw6q0mCxKD7o3X5pmNwoy4sPCKNxwTlylJgn+lVh+0V LOvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FXjcP2MQZynEt79x9jqAfZ+0P3gF2TQYEkdlkQOqjLI=; fh=oHyE/62z6RPE+0LSDVE0jWAI6hUfkfKy7qTShiQbhhg=; b=wUvoRjS2qtrhDrMqzSaU52dMrwjmv53eD+NK3rg199yQb77Eo/0oQ7Bg2tmia7uxia L9rI904PmYIRdCCSD1BjmtOyHukJ9EvrWIAyVxiP0VAePOHQfHOuqshk+Bug8S00XOwd EcLS99KHYKOwhbUHYFWSN7qT99gxtn7OffAEY0PEullxzF0THBsGp/u0LN3Ny2N08TJd H8LslxBG/GiQhXXe8aFzcgrOfb3mmv3a1xhYw087XytehRBCQrZe+KBcez6v/okGqRlv RpgLv7rdtSwuHXhJO94OiKLXtkLsNC5RP5UTz/OgvYuO0UjKpiIyEusUDruizHB+2gMC 3eEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=etzXy+6M; spf=pass (google.com: domain of linux-kernel+bounces-26565-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26565-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id le1-20020a170907170100b00a28b0d88854si3921834ejc.621.2024.01.15.15.35.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 15:35:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26565-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=etzXy+6M; spf=pass (google.com: domain of linux-kernel+bounces-26565-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26565-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 119C41F2309C for ; Mon, 15 Jan 2024 23:35:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 28A4F1BF3E; Mon, 15 Jan 2024 23:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="etzXy+6M" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A5F11B807; Mon, 15 Jan 2024 23:26:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92446C433C7; Mon, 15 Jan 2024 23:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705361198; bh=1KyW0Tw/bA+tT4A9gYmSZ7V0b8vbkPmKvnhkEXoNVVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=etzXy+6M4HRGG1x2i7hXc9q4diu9crAV0Srq6iEwIaOrMd73cZYSwR77Ohy9IN5Pq klydOizg/Yr7adMrhF9JMui3n5yPaf1RE3SNUvoGnLfdDFns38lxPQkGlVdgSzvkal eiPPV+/H+PoZ9PibvDEXlY/5q0V6B7p59FP89XzMCLd7SUKKOi1N6ktrUUx6H5XL8v l+VmC1/hJLUmdZNwTQLJavwcyfgil36hljIqsMED4JFpn5YQqVWrlINrj7EFUYqff3 G9yMy2Esx9v3DtgQdvgPypLcgUle7h5nzeFuVQWgVnCK9CSVHyJA4w4DnMuzcFOaAe WkeTNUkwpD+og== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jun'ichi Nomura , Derek Barbosa , Ingo Molnar , Kees Cook , Linus Torvalds , "Paul E . McKenney" , Andy Lutomirski , "H. Peter Anvin" , Peter Zijlstra , Sasha Levin , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, kirill.shutemov@linux.intel.com, rppt@kernel.org, ardb@kernel.org, nikunj@amd.com, thomas.lendacky@amd.com Subject: [PATCH AUTOSEL 6.1 09/14] x86/boot: Ignore NMIs during very early boot Date: Mon, 15 Jan 2024 18:25:43 -0500 Message-ID: <20240115232611.209265-9-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115232611.209265-1-sashal@kernel.org> References: <20240115232611.209265-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.73 Content-Transfer-Encoding: 8bit From: Jun'ichi Nomura [ Upstream commit 78a509fba9c9b1fcb77f95b7c6be30da3d24823a ] 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 Signed-off-by: Sasha Levin --- 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 b4155273df89..d34222816c9f 100644 --- a/arch/x86/boot/compressed/ident_map_64.c +++ b/arch/x86/boot/compressed/ident_map_64.c @@ -393,3 +393,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 3cdf94b41456..d100284bbef4 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 22890e199f5b..4d03c8562f63 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 20118fb7c53b..a49d9219c06e 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -190,6 +190,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); -- 2.43.0