Message ID | 20230802101932.758513086@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp359156vqx; Wed, 2 Aug 2023 03:40:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlHvDQzIyiz9sMgWkZb1jyWjCyXwkIKTNVK0oOPnTBzPoforON4BRUKyu/nYDr3bCzyi5+oW X-Received: by 2002:a17:906:7385:b0:99c:825:6076 with SMTP id f5-20020a170906738500b0099c08256076mr4273473ejl.35.1690972803350; Wed, 02 Aug 2023 03:40:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690972803; cv=none; d=google.com; s=arc-20160816; b=REEt+8e3FQ0FGL71SRfUSFv747pkJR2MmONpojE8wAw8hIANBwcNYbHGzk+ktMVxPs ok45m1lfZb7dNUeMNsOflTw3dO3TjYOMJhOY4jaAJ+XPJ2heFOTLfubmGl99XyreSnoZ ZJF2NFTi6a7bij3PtboubIZH/z/0RR+REECEbk/XHpqkZftjsb2IwmlLJHHsz4ICSqDL k5c2bXZACL3dRq8NM7TwSj8AYu1xD5Zo44Y80ZR1UjUaFLybwW2tIxmT2vMCbesFdE/N GxBlGMeZIdbJ7PjRETY1yR2HYPn6mtJgdKeLS0zskKVFYWB6w5tgHldaAo/b2HtRZ33R 7atQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=ifKZU+jjVp506gXqEzVY99mBfb+xgbx4G16QrL/5KJI=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=P6Ow9XPeMiMMbsIut7+qdTNiOdbrVaxSTKwrbEVpbP/wCFFdp+OBNIEJ/Uo/Zb16FZ aTsBdRf5mHJtrbRl3AE7uLp62zmHfDl7g2Rj2n5ot8xEdL/rMKK2W0l60Yq7FPsRorGa FcdG+Kj9EJm5btsiE532T0sPzMXxYQpzoRwItcHv0yqBUpoRFQQo8ob9t5RLC55AdCUc M4z6O3bwahyGdTd57nkPN7f4jK7pevmbONQi5qvTbkzQo12/6vfwYubTb9+zNz+F8Ohq yJ4ryQdwMFYNenO7ZGpwNLcr8Dv9NxlpDnSCHvWeorsovwyoaSlBTQewDPxtHjgkAn24 RkjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Bgi3c5jI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k17-20020a1709061c1100b0098885a739f2si7529376ejg.657.2023.08.02.03.39.39; Wed, 02 Aug 2023 03:40:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Bgi3c5jI; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233160AbjHBKVM (ORCPT <rfc822;maxi.paulin@gmail.com> + 99 others); Wed, 2 Aug 2023 06:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230456AbjHBKVC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 2 Aug 2023 06:21:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70F5E213D for <linux-kernel@vger.kernel.org>; Wed, 2 Aug 2023 03:21:01 -0700 (PDT) Message-ID: <20230802101932.758513086@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=ifKZU+jjVp506gXqEzVY99mBfb+xgbx4G16QrL/5KJI=; b=Bgi3c5jIXWreNy1JQ1MW9oDkILk7cgZUTKPxAO8T5MMvnv1n/GW3zEjKiDefWH5acpRFJ7 VrXd5+F/maZKCZcWS9+bjE/LZIrlfkO4cVVrURoQpB+h7ofDPfGhCgpA9TpINiLIFzYfll /Qiho4obvDD73/Bu05lzc7Cw/mkNuwwK7+2b8KD97pZ3Fc70chGo/WXvDjvS0ZEtxNO5Tq VCV4xhMUWq9qhAGAjXch0YicemdBAI9QRTfJX8eHkZh6no/IRsIanCUpIvLMEM+zPNkeTk KLDSJbeGvWYnPkeSIGAwkr5WpY8MaZT5Pa69RV19/RrGQOWAS6KYdrUvaOYcIg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=ifKZU+jjVp506gXqEzVY99mBfb+xgbx4G16QrL/5KJI=; b=SbMoLthrNU8kvnS9+wB47EzWogOFxHaYI+rsI/o92tIgkiI6+VdfYFcC/i7ukbdnahT2go Yky/aTE8jn1fIyCw== From: Thomas Gleixner <tglx@linutronix.de> To: LKML <linux-kernel@vger.kernel.org> Cc: x86@kernel.org, Tom Lendacky <thomas.lendacky@amd.com>, Andrew Cooper <andrew.cooper3@citrix.com>, Arjan van de Ven <arjan@linux.intel.com>, Huang Rui <ray.huang@amd.com>, Juergen Gross <jgross@suse.com>, Dimitri Sivanich <dimitri.sivanich@hpe.com>, Michael Kelley <mikelley@microsoft.com>, Wei Liu <wei.liu@kernel.org> Subject: [patch V3 01/40] cpu/SMT: Make SMT control more robust against enumeration failures References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Wed, 2 Aug 2023 12:20:59 +0200 (CEST) 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773113497983168292 X-GMAIL-MSGID: 1773113497983168292 |
Series |
x86/cpu: Rework the topology evaluation
|
|
Commit Message
Thomas Gleixner
Aug. 2, 2023, 10:20 a.m. UTC
The SMT control mechanism got added as speculation attack vector
mitigation. The implemented logic relies on the primary thread mask to
be set up properly.
This turns out to be an issue with XEN/PV guests because their CPU hotplug
mechanics do not enumerate APICs and therefore the mask is never correctly
populated.
This went unnoticed so far because by chance XEN/PV ends up with
smp_num_siblings == 2. So smt_hotplug_control stays at its default value
CPU_SMT_ENABLED and the primary thread mask is never evaluated in the
context of CPU hotplug.
This stopped "working" with the upcoming overhaul of the topology
evaluation which legitimately provides a fake topology for XEN/PV. That
sets smp_num_siblings to 1, which causes the core CPU hot-plug core to
refuse to bring up the APs.
This happens because smt_hotplug_control is set to CPU_SMT_NOT_SUPPORTED
which causes cpu_smt_allowed() to evaluate the unpopulated primary thread
mask with the conclusion that all non-boot CPUs are not valid to be
plugged.
Make cpu_smt_allowed() more robust and take CPU_SMT_NOT_SUPPORTED and
CPU_SMT_NOT_IMPLEMENTED into account.
The primary mask issue on x86 XEN/PV needs to be addressed separately as
there are users outside of the CPU hotplug code too.
Fixes: 05736e4ac13c ("cpu/hotplug: Provide knobs to control SMT")
Reported-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/cpu.c | 6 ++++++
1 file changed, 6 insertions(+)
Comments
On Wed, Aug 02, 2023 at 12:20:59PM +0200, Thomas Gleixner wrote: > kernel/cpu.c | 6 ++++++ > 1 file changed, 6 insertions(+) > --- a/kernel/cpu.c > +++ b/kernel/cpu.c > @@ -630,6 +630,12 @@ static inline bool cpu_smt_allowed(unsig As discussed on IRC, the name and what the function does is kinda conflicting. What it actually queries is whether the CPU can be booted. So something like this ontop I guess: --- diff --git a/kernel/cpu.c b/kernel/cpu.c index f93ce69f7e3d..e4195d5425cb 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -659,7 +659,7 @@ static inline bool cpu_smt_thread_allowed(unsigned int cpu) #endif } -static inline bool cpu_smt_allowed(unsigned int cpu) +static inline bool cpu_bootable(unsigned int cpu) { if (cpu_smt_control == CPU_SMT_ENABLED && cpu_smt_thread_allowed(cpu)) return true; @@ -691,7 +691,7 @@ bool cpu_smt_possible(void) EXPORT_SYMBOL_GPL(cpu_smt_possible); #else -static inline bool cpu_smt_allowed(unsigned int cpu) { return true; } +static inline bool cpu_bootable(unsigned int cpu) { return true; } #endif static inline enum cpuhp_state @@ -794,10 +794,10 @@ static int bringup_wait_for_ap_online(unsigned int cpu) * SMT soft disabling on X86 requires to bring the CPU out of the * BIOS 'wait for SIPI' state in order to set the CR4.MCE bit. The * CPU marked itself as booted_once in notify_cpu_starting() so the - * cpu_smt_allowed() check will now return false if this is not the + * cpu_bootable() check will now return false if this is not the * primary sibling. */ - if (!cpu_smt_allowed(cpu)) + if (!cpu_bootable(cpu)) return -ECANCELED; return 0; } @@ -1725,7 +1725,7 @@ static int cpu_up(unsigned int cpu, enum cpuhp_state target) err = -EBUSY; goto out; } - if (!cpu_smt_allowed(cpu)) { + if (!cpu_bootable(cpu)) { err = -EPERM; goto out; }
On Fri, Aug 04 2023 at 19:50, Borislav Petkov wrote: > On Wed, Aug 02, 2023 at 12:20:59PM +0200, Thomas Gleixner wrote: >> kernel/cpu.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> --- a/kernel/cpu.c >> +++ b/kernel/cpu.c >> @@ -630,6 +630,12 @@ static inline bool cpu_smt_allowed(unsig > > As discussed on IRC, the name and what the function does is kinda > conflicting. > > What it actually queries is whether the CPU can be booted. So something > like this ontop I guess: No objections from my side.
--- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -630,6 +630,12 @@ static inline bool cpu_smt_allowed(unsig if (cpu_smt_control == CPU_SMT_ENABLED) return true; + if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED) + return true; + + if (cpu_smt_control == CPU_SMT_NOT_IMPLEMENTED) + return true; + if (topology_is_primary_thread(cpu)) return true;