From patchwork Fri Oct 20 11:37:47 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: 156042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp991224vqb; Fri, 20 Oct 2023 04:39:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBYqq084EG18kRyxMni68HfFGfzp2nNDfrKs7f1dpLqAVR7rt2KnyjMr7JrzkIE5buuRbx X-Received: by 2002:a17:90b:b13:b0:27d:5174:442f with SMTP id bf19-20020a17090b0b1300b0027d5174442fmr1497861pjb.6.1697801976938; Fri, 20 Oct 2023 04:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697801976; cv=none; d=google.com; s=arc-20160816; b=jQ0/z2pwW7+enmaK3MF/3SJVceF5ZazBN80ItR8FqxYOgNSsnIur+ih8sm+GKN8htC ifKLq6bLxHNxL3DQ45o/TI2pKBSPnJGJPm0I+qorCmgSV6iHlMpokQ7SmgYHU+oTRutE 3lyyYr7+8MF8aS5yy6Jfd5s3W9ZQl3B8G/6F4OSHPrH9hLOK1QSInBF6nw17aI1DKgsE B5eOU+dPIAqfEpN8Febmh1PkhCC3xK7XBh9JB8+YMWs7r0LsURuyTG2NUhHLD6VwXd3q l//6phC5MX64XoWpMDq3hVNG0zQvZZFPbFyxUa1rvUOYD0hkeeGIC+R8iF380NJ6GdaB lsKg== 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:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=4eVwspwx/gJa3p7Ks+jUERl5JNrYXamLdYfyAZWNAns=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=TJSCB+vugiRG29eUyQGNAPcaGfZ3eg6FBhYY5AM0hb/sVSdG1iqkDlLiH2j1+egPl5 FdaAiWTFb/3ylw95jCZhI3J/EzqN/jG0NA+mKCfGZw8up1mMUrWIDUBL1JGn5m5FBnlO qnEh6Kx7Lj0PSdtvnqIHtHp6DO92gd7zA4Vy7r17W+QLj4izt80Zw1mSt3YfT2Oz3Hsn 0A4HZvl8geo+bD3ndbdLQ8oUKQ+gS/1qDeh3JikRAErxJCEhf5tFhd4ULaOxcBVlZDK7 kxRdCGqNi1asrFzOyDfHkWprhJDMka6cqJi8jPKWNwgK0lHTHpIVAGuznmHRD6kvZ0Gu frog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4kCtOIsK; dkim=neutral (no key) header.i=@linutronix.de header.b=Rn6Ldcyh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id z20-20020a17090ab11400b0027d4684804dsi1611966pjq.122.2023.10.20.04.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=4kCtOIsK; dkim=neutral (no key) header.i=@linutronix.de header.b=Rn6Ldcyh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 7134583FC398; Fri, 20 Oct 2023 04:39:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377147AbjJTLjD (ORCPT + 25 others); Fri, 20 Oct 2023 07:39:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377012AbjJTLic (ORCPT ); Fri, 20 Oct 2023 07:38:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7D4F199D; Fri, 20 Oct 2023 04:37:49 -0700 (PDT) Date: Fri, 20 Oct 2023 11:37:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801867; 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=4eVwspwx/gJa3p7Ks+jUERl5JNrYXamLdYfyAZWNAns=; b=4kCtOIsKXKknWDVEX6Xn4r5E7BeUKQg3G/R1wSsr6Bx0dfBy1ssbKFt7R1m8Ehgm9pT+mF zZDuuHqUcMr+CgfMqMxcH95po7Xxmuvpze+teXLQ/qsxQdRfsjPs63Z6JgBv1xss/uPadf VYGZMcPESqB5nt9On5TCMTpliZVyH07zrJ6/JdBMXSgHS5Cct7qwJyNQTQB6ZZM3cYKNMk /u5u0xD14H3vyQluvxh5h3edBkRD4lZj+oxjhe2TDS60zZ9ODm1OxCB3ZUTVhTzdRJ5zFT xM7+yxaDAraFYi9hEQIRdj+uBEm/BOGEWoYXJZptvVAVvG8hXXMbTWbtnl79xA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801867; 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=4eVwspwx/gJa3p7Ks+jUERl5JNrYXamLdYfyAZWNAns=; b=Rn6LdcyhDXl/4Ou/WnZ/k+dxa6KmdxxUSW5VV1SBSXiUME2XA05sB881yRmzwfB1qlYjQN 6jdCYLZx7gtpNtCA== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/microcode] x86/apic: Provide apic_force_nmi_on_cpu() Cc: Thomas Gleixner , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231002115903.603100036@linutronix.de> References: <20231002115903.603100036@linutronix.de> MIME-Version: 1.0 Message-ID: <169780186713.3135.17624325755924889790.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 04:39:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778647093604779153 X-GMAIL-MSGID: 1780274405692632039 The following commit has been merged into the x86/microcode branch of tip: Commit-ID: ea8ef7118d201c0a9d24f25c00f4c36efb2216e3 Gitweb: https://git.kernel.org/tip/ea8ef7118d201c0a9d24f25c00f4c36efb2216e3 Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 14:00:07 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 19 Oct 2023 16:00:37 +02:00 x86/apic: Provide apic_force_nmi_on_cpu() When SMT siblings are soft-offlined and parked in one of the play_dead() variants they still react on NMI, which is problematic on affected Intel CPUs. The default play_dead() variant uses MWAIT on modern CPUs, which is not guaranteed to be safe when updated concurrently. Right now late loading is prevented when not all SMT siblings are online, but as they still react on NMI, it is possible to bring them out of their park position into a trivial rendezvous handler. Provide a function which allows to do that. I does sanity checks whether the target is in the cpus_booted_once_mask and whether the APIC driver supports it. Mark X2APIC and XAPIC as capable, but exclude 32bit and the UV and NUMACHIP variants as that needs feedback from the relevant experts. Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20231002115903.603100036@linutronix.de --- arch/x86/include/asm/apic.h | 5 ++++- arch/x86/kernel/apic/apic_flat_64.c | 2 ++ arch/x86/kernel/apic/ipi.c | 8 ++++++++ arch/x86/kernel/apic/x2apic_cluster.c | 1 + arch/x86/kernel/apic/x2apic_phys.c | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 5af4ec1..17f2f28 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -276,7 +276,8 @@ struct apic { u32 disable_esr : 1, dest_mode_logical : 1, - x2apic_set_max_apicid : 1; + x2apic_set_max_apicid : 1, + nmi_to_offline_cpu : 1; u32 (*calc_dest_apicid)(unsigned int cpu); @@ -542,6 +543,8 @@ extern bool default_check_apicid_used(physid_mask_t *map, int apicid); extern void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap); extern int default_cpu_present_to_apicid(int mps_cpu); +void apic_send_nmi_to_offline_cpu(unsigned int cpu); + #else /* CONFIG_X86_LOCAL_APIC */ static inline unsigned int read_apic_id(void) { return 0; } diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c index 032a84e..cd16228 100644 --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -103,6 +103,7 @@ static struct apic apic_flat __ro_after_init = { .send_IPI_allbutself = default_send_IPI_allbutself, .send_IPI_all = default_send_IPI_all, .send_IPI_self = default_send_IPI_self, + .nmi_to_offline_cpu = true, .read = native_apic_mem_read, .write = native_apic_mem_write, @@ -175,6 +176,7 @@ static struct apic apic_physflat __ro_after_init = { .send_IPI_allbutself = default_send_IPI_allbutself, .send_IPI_all = default_send_IPI_all, .send_IPI_self = default_send_IPI_self, + .nmi_to_offline_cpu = true, .read = native_apic_mem_read, .write = native_apic_mem_write, diff --git a/arch/x86/kernel/apic/ipi.c b/arch/x86/kernel/apic/ipi.c index a44ba72..edad86f 100644 --- a/arch/x86/kernel/apic/ipi.c +++ b/arch/x86/kernel/apic/ipi.c @@ -97,6 +97,14 @@ sendmask: __apic_send_IPI_mask(mask, CALL_FUNCTION_VECTOR); } +void apic_send_nmi_to_offline_cpu(unsigned int cpu) +{ + if (WARN_ON_ONCE(!apic->nmi_to_offline_cpu)) + return; + if (WARN_ON_ONCE(!cpumask_test_cpu(cpu, &cpus_booted_once_mask))) + return; + apic->send_IPI(cpu, NMI_VECTOR); +} #endif /* CONFIG_SMP */ static inline int __prepare_ICR2(unsigned int mask) diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c index affbff6..a830608 100644 --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -251,6 +251,7 @@ static struct apic apic_x2apic_cluster __ro_after_init = { .send_IPI_allbutself = x2apic_send_IPI_allbutself, .send_IPI_all = x2apic_send_IPI_all, .send_IPI_self = x2apic_send_IPI_self, + .nmi_to_offline_cpu = true, .read = native_apic_msr_read, .write = native_apic_msr_write, diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c index 788cdb4..c8ac1b1 100644 --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -166,6 +166,7 @@ static struct apic apic_x2apic_phys __ro_after_init = { .send_IPI_allbutself = x2apic_send_IPI_allbutself, .send_IPI_all = x2apic_send_IPI_all, .send_IPI_self = x2apic_send_IPI_self, + .nmi_to_offline_cpu = true, .read = native_apic_msr_read, .write = native_apic_msr_write,