Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1860267rdb; Mon, 9 Oct 2023 05:30:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9xAn1nMB8pgLb242A+2FkVqe2SOyQGHYckZfPYvZNP0B8AKH10cM3jywsPOxmAr9vLtZE X-Received: by 2002:a17:902:c254:b0:1c5:c36b:e954 with SMTP id 20-20020a170902c25400b001c5c36be954mr14654372plg.2.1696854607801; Mon, 09 Oct 2023 05:30:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696854607; cv=none; d=google.com; s=arc-20160816; b=gUFUjkNNGhvP0GdQ29zEZjqjlV1kR4neRsCHbE9D8ieEzNvVZLq86DpxXsSZAZ3on4 LTR0FHKPwOqSZC0fvTCn7mz8T3w3wI/mqzIblVh5dkD2wyE+RXKDO4RADpJoUk3vgG26 rPqvMey5I81YxxgRR2ip8maxOMpEJoU/k3Hy0w13JC3v5h6untnH7/CbWs2RnVyf2TV1 n24G9Ve3YK68KsIB5NYsSAqu+Oi2310mOdCcEXXRGSnx3DS0VlxX4sLnliS9mLsitbHV x3MHakNaGJ3FGt4uiT8NrZQxOG16UKVzkoPRlaC9qgIQCFr36A03WOs3m3K/+1KD4y6U URsA== 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=j8zvsCZnS1x6OJAIzodhBWLj1k4ErX1axYKhxTQikMM=; fh=LWlv3U+xZ3+vQt4tlJRIlKl5VzN7iFjjE/bzRmlxKDA=; b=w7bRCqZ1KgZFlg3Bb1o62cfxutvCCT5mmJKQujkABEiEOtZtpLvHzBVvT5vmN/d3rO K/SxppHTFGer5rtqumf8+uwZSn1sMhkHLVVBz3LEH23+gKx5MSHH0LHPX9Tn3e4kH5sv y1nqCpYuSs1+HD1jNJJc5ZkJrexR9ye4bwKqbfgMXq36zXLk0xea1iCsBfoNjP3Jm6Qq Sz4SbvNoiE1NRvs5j8vb0euJ5PmYuqOexhiGa5e3hkf5KyM4AbuLx4iFrRR7gJTddQnI Nt9Ae5qYhPuFheD/5T9HJkBGHP8qstF6utAjwGD9Gy3NgJTC7xTGWdykA4EbQl2dh10j ngtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ef3PLbG0; dkim=neutral (no key) header.i=@linutronix.de header.b=5CkZzJ7C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b10-20020a170903228a00b001c737001bb3si9887201plh.345.2023.10.09.05.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 05:30:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ef3PLbG0; dkim=neutral (no key) header.i=@linutronix.de header.b=5CkZzJ7C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 138898029051; Mon, 9 Oct 2023 05:30:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376419AbjJIM37 (ORCPT + 99 others); Mon, 9 Oct 2023 08:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346530AbjJIM3u (ORCPT ); Mon, 9 Oct 2023 08:29:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 915668F; Mon, 9 Oct 2023 05:29:46 -0700 (PDT) Date: Mon, 09 Oct 2023 12:29:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696854585; 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=j8zvsCZnS1x6OJAIzodhBWLj1k4ErX1axYKhxTQikMM=; b=Ef3PLbG0SBZu0HhynWIq8RgEVI6ZyXQloNWhwkJ3sKWM5ty3vI7psZvF+ApVUlRZosaKGR r9tZgjoU9je+xPDrvvC5rkG+fHx1wH86qsNn54joLHm56v+JTIFOH6VJkGzmkpCY3/yB50 FWi/+8frMFhQwpsRr0fjXbl5Fl3MR+ZQqIdorc8K+F/W9wnpuunoVDxccLAmUmh/b26HzG txWT/bkFqB2X7QpJZIAxtu23KSRiNK6QARokY5rt7fpwB5EeF0nkrh9yyrahG8FvimCkZr cDSY+n+JYxT3KAMC/wEjnfxhjrtN6+Yh3tV3a2K6ungy7G9adIot8fiNUood7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696854585; 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=j8zvsCZnS1x6OJAIzodhBWLj1k4ErX1axYKhxTQikMM=; b=5CkZzJ7CNGZ8MM15ij7JP4e17kb9giobKa11FuS8lqpOlnzSO/5rqySb6PgkITX2jpKLCj nBhV4NmnbkC/wSCQ== 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: <169685458454.3135.4888799859743185915.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 05:30:06 -0700 (PDT) The following commit has been merged into the x86/microcode branch of tip: Commit-ID: 27b28750429ed5ab9c41955976a44c05bd029cfb Gitweb: https://git.kernel.org/tip/27b28750429ed5ab9c41955976a44c05bd029cfb Author: Thomas Gleixner AuthorDate: Mon, 02 Oct 2023 14:00:07 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 06 Oct 2023 15:12:25 +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,