From patchwork Thu Jan 25 18:21:23 2024 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: 192227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp170619dyb; Thu, 25 Jan 2024 10:26:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsgmTtmHQPHdwm7xY30/ndIC8116QcTrE9DDJm2i98TnmKZu6BvToIjPvIFqKh/UPryHp9 X-Received: by 2002:a17:902:ec82:b0:1d8:94b6:65e with SMTP id x2-20020a170902ec8200b001d894b6065emr134447plg.2.1706207196109; Thu, 25 Jan 2024 10:26:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706207196; cv=pass; d=google.com; s=arc-20160816; b=NsX//sJLLbxCDJ61BlSq+fwn80mRlkzLjleAqnSBVgpFaQUhVveaVK8cJhR5Qi2xk5 TxdvXB6etCyId/JIU0megRRKLS/o9aJ+J5/K2CKuaCVcrxrTK6eUhawv3xkLB/aAawsO Mdr4CwKuuw/o5AgJ+HgNLMSxqYw1an4eWLpXrwJKeY3VT8iF1C9fGKbOW39SYVDCiKRP SuVBxC8mUsZQgPpWzwCwuC2LwXwZki/jmOnrVQt4FBCf2RtTFAwiNcc2IzSpxi0ZC3+m gJVYbRWwgUWMlkhg1yKS+rEqRWKEpeG9YD37J5jMeMNTVGX2bp3ytCdQ5q8TAbWtlCAj HX7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=zsxTmJZoA59sY8kUufCOH3e/7llLXUJeKT/WAF1bOjs=; fh=U/Hd0cPmVpmsXI9UC370Q88/l4pozXEkKxB1Pi0MTn0=; b=E4RaUBocqyvfaO8N1xUakv/SNAxiG/JQ/5Y76XerwN9khARcJ5qAnySX4rEDd6BMkP gXQhAzeMx2/JEwkAxlVwVfBuwjmOT+N6iWJLm1hB51xftdFQAkt70HRLQ7rE7Me+jUrI 8SxBKISaxlQQf8b/EHD1YnoIh8sojA6rezGCMKX49LXbAHQabS3oASiALkBqGgqw14fi nWNL2Sn6rPWM7UMNeEEkPcrOucMvhNDjH/AW1hCF22uqSrBRWA3ugzqic8MbEwmSf5gb hlmFLG/Dr4YpgFd8wUn8OuJnv9bnRGj5Ll+7PZ3k26nbftnrrAoNgzVhqbLtgAp12sCa v7fQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rVh6kEfl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-39092-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39092-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l15-20020a170902f68f00b001d4beb54473si762528plg.608.2024.01.25.10.26.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 10:26:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39092-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rVh6kEfl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-39092-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39092-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D6F1A29A076 for ; Thu, 25 Jan 2024 18:26:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7C7813DB9A; Thu, 25 Jan 2024 18:21:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rVh6kEfl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2EC/AIlv" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 90524133994; Thu, 25 Jan 2024 18:21:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706206894; cv=none; b=kxe4jUpvBOPapgy4Yjni6XB5sNLDLQft1RWhTAu1skIxY5SHywYMapAgMrP7eXosVrbx6n0UbCdG3XzkaacrjjJ63vo9zYyeJRt2dD07mfP4NMZJewfzoSKUCTauBqkLVP0r9O5YgGH2j+fG5b454TB0EI0oyCwz2u7cGMHFF9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706206894; c=relaxed/simple; bh=hlKPIQWs+nqz5n/JkEUGsWDTrg6fotPLGd5Uav6GkOs=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=pecoeMAjeQsRZ4Vo5gUCmmrsZxG3sV2Gx1uIXTIyMdMwyjHL3FSJoAq+obKSSI3H1p2mkWMngZUXBmq9JJ8mDsQm03nr3ZYgx/EZHD/lMn70NblWlRZA+cj00emzCVjrvZJ5HqW/pEsskKM/obN5hV7qsFDcwYLOXworsUx+04o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rVh6kEfl; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2EC/AIlv; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Thu, 25 Jan 2024 18:21:23 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706206883; 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: in-reply-to:in-reply-to:references:references; bh=zsxTmJZoA59sY8kUufCOH3e/7llLXUJeKT/WAF1bOjs=; b=rVh6kEflRVGuo1UfLXHnSXXAxpm5GY6iFaDhWgLsCX02gdf/uDdake0LGRB/ViLHnycpLd UT/pJ7LM/oSdG44baau1PcO2mK5R91kbbtBY/VjY2a8zuWMZEK4E9YYLNjmBuP3byC5r6x tph6bEeuRNV6L8zFQMD1DBiIeyf7lWJbcMz2z0Dv/8VomqkzaNA7Gr2CTzs9/Ws9ub7dcD eNDv2112Src4pj/Mnd+U4iYio9KLHqUFF9NR4t7JtuJpQ8Gs1h8f8YswNYVtpcLslLxtIZ 5gU+Xs8xnIgj1vJn3Wmyp2BOsPkJ/CNAF1a/xM7ksL4Tz4HTLUbn7jF8aXKcjA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706206883; 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: in-reply-to:in-reply-to:references:references; bh=zsxTmJZoA59sY8kUufCOH3e/7llLXUJeKT/WAF1bOjs=; b=2EC/AIlvlcI/FVhanLXfgLX036xiaXP9n5WWovyN5oNjY3dM6Rgz5HPFeYayJO8eD7yKgy Gg/6XqBEZ24N/2Ag== From: "tip-bot2 for H. Peter Anvin (Intel)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fred] x86/fred: Add a NMI entry stub for FRED Cc: "H. Peter Anvin (Intel)" , Xin Li , Thomas Gleixner , Shan Kang , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231216063139.25567-1-xin3.li@intel.com> References: <20231216063139.25567-1-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170620688304.398.9423671583132761035.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784440871286428693 X-GMAIL-MSGID: 1789087916406819107 The following commit has been merged into the x86/fred branch of tip: Commit-ID: 994f75798425ca0865b54dcc7bbe13bba5e4cfe4 Gitweb: https://git.kernel.org/tip/994f75798425ca0865b54dcc7bbe13bba5e4cfe4 Author: H. Peter Anvin (Intel) AuthorDate: Fri, 15 Dec 2023 22:31:39 -08:00 Committer: Thomas Gleixner CommitterDate: Thu, 25 Jan 2024 19:10:32 +01:00 x86/fred: Add a NMI entry stub for FRED On a FRED system, NMIs nest both with themselves and faults, transient information is saved into the stack frame, and NMI unblocking only happens when the stack frame indicates that so should happen. Thus, the NMI entry stub for FRED is really quite small... Signed-off-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li Signed-off-by: Thomas Gleixner Tested-by: Shan Kang Link: https://lore.kernel.org/r/20231216063139.25567-1-xin3.li@intel.com --- arch/x86/kernel/nmi.c | 42 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+) diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index 17e955a..3130a66 100644 --- a/arch/x86/kernel/nmi.c +++ b/arch/x86/kernel/nmi.c @@ -35,6 +35,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -651,6 +652,47 @@ void nmi_backtrace_stall_check(const struct cpumask *btp) #endif +#ifdef CONFIG_X86_FRED +/* + * With FRED, CR2/DR6 is pushed to #PF/#DB stack frame during FRED + * event delivery, i.e., there is no problem of transient states. + * And NMI unblocking only happens when the stack frame indicates + * that so should happen. + * + * Thus, the NMI entry stub for FRED is really straightforward and + * as simple as most exception handlers. As such, #DB is allowed + * during NMI handling. + */ +DEFINE_FREDENTRY_NMI(exc_nmi) +{ + irqentry_state_t irq_state; + + if (arch_cpu_is_offline(smp_processor_id())) { + if (microcode_nmi_handler_enabled()) + microcode_offline_nmi_handler(); + return; + } + + /* + * Save CR2 for eventual restore to cover the case where the NMI + * hits the VMENTER/VMEXIT region where guest CR2 is life. This + * prevents guest state corruption in case that the NMI handler + * takes a page fault. + */ + this_cpu_write(nmi_cr2, read_cr2()); + + irq_state = irqentry_nmi_enter(regs); + + inc_irq_stat(__nmi_count); + default_do_nmi(regs); + + irqentry_nmi_exit(regs, irq_state); + + if (unlikely(this_cpu_read(nmi_cr2) != read_cr2())) + write_cr2(this_cpu_read(nmi_cr2)); +} +#endif + void stop_nmi(void) { ignore_nmis++;