Message ID | 20230814085112.149440843@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2623799vqi; Mon, 14 Aug 2023 02:31:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQbjnYdux/TIbaCkJuqOS89IK0UDSmBrWV1dn3CGmTvoXV6u3H/CFlRz2/aIQK25JoA0ZQ X-Received: by 2002:a05:6871:80e:b0:1a9:c186:398d with SMTP id q14-20020a056871080e00b001a9c186398dmr10889669oap.21.1692005481532; Mon, 14 Aug 2023 02:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692005481; cv=none; d=google.com; s=arc-20160816; b=yaZKH0xV2SCtWZhe0ZRCDqHtct2Jy0u+LOvoS/wPWsypMV5tL7FGAXVBPZKb5JxWEk HKovBaSookwIiZoAmdQXPKV1g6l2JM3sCfv7etsKJi5AkTRnELgDDsog1iKiCMBg1v5p lcTPs2ZgguzsQSqb8llkiGqWHV2kp3TqLz4TnFZGfU8k+ToJt/6ttVbWWFA5BqQXqttV ABbdjdcvWQiASvQaCu7mvCikVsBIl06gceIwNR1kDIJ+uXz/uSEmMtdff+LQUVZamu7I nWa9HdB/DeyrpsoNtDpHndPl2TBaWugW9NBvQ8L1fMyBT0zsBWXpyp/7b/CYQlk7tNTm y4Yw== 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=6UGrI6Ud/CP8ZpSU60c+UMBZEwkl8meNMyIq7OTHrBs=; fh=vmKIJtcbtoHWhyuxI4oEq8r1SWZ2V9Rrbp1Orw2DxqA=; b=I3OI2aejfpMIfFjNZBc2/c4aGIaX/h+EYc/qYz17p99VFUPVEyjuNN+giQcE18I4r0 OdGusStPq6Xdnw2GWdm8BpgQRHayX5KvUydbbCVZP2ulbO5FjdrNSpx7KU6zJIcDhSBB AmYWI6OqJgqYBTeV9VIfltmnrSHMlEbaNwxo8mPekvV3lb9J4VJs+YX4x5R6bL7FDIKj DksyVHxwcIfvmUq9umNWjAseISIaXOyvl3FRGNX95TOSEZ7lbeTcfITd12SAZNuJgkHe yuYjcmsQ09tHIk7I983rI3yUAB0hQturvtA0Uo4o1BlMp5n+5r7DbOmGytwOU74QuWJU 84Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yTHN50q6; 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 b11-20020a17090a5a0b00b0026b365096e5si4276246pjd.53.2023.08.14.02.31.08; Mon, 14 Aug 2023 02:31:21 -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=yTHN50q6; 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 S231706AbjHNIyP (ORCPT <rfc822;274620705z@gmail.com> + 99 others); Mon, 14 Aug 2023 04:54:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233903AbjHNIxk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 14 Aug 2023 04:53:40 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02B9510B for <linux-kernel@vger.kernel.org>; Mon, 14 Aug 2023 01:53:39 -0700 (PDT) Message-ID: <20230814085112.149440843@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692003217; 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=6UGrI6Ud/CP8ZpSU60c+UMBZEwkl8meNMyIq7OTHrBs=; b=yTHN50q6gw0TeW2JhLr5EqrwCsNqHtUNcjNCaChaRFf3868X+WpFzyrj1ntNrkbMdrM1Sx fCAI60MXnkNEZDVFIY2cHwlVrEtfK0WsBjKG3u5xEpNTnXT8pa0AxwpHguEjhKxl4iE90E MuJ/TYLaY7CJa47VAI/9yX5MmPG9oLoxfQ/W4l4PBhPuVo1i6JwX7MN61ywcs8pDq5BNT3 rvHC3oJhqYp5/x0esPaG5Zz/UZZgMB0FrFAEKEqfrVD6bboaKAWyuEGBLe6bkzqMGoN3nk sJBJ/pjAMdR800oeL68LJ5T3jnoHLHvMrTH/DpxypgJFvotRUWtFw+cTveWV8A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692003217; 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=6UGrI6Ud/CP8ZpSU60c+UMBZEwkl8meNMyIq7OTHrBs=; b=CSra9bkYm4iOU76EFCNZ2F5vFF1p77f0ata+h48tURjAYnnZbLVh0imDi0EQlK4DTIn6ke nqDkgp2R0Roda+Dg== 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>, Pu Wen <puwen@hygon.cn>, Qiuxu Zhuo <qiuxu.zhuo@intel.com>, Sohil Mehta <sohil.mehta@intel.com> Subject: [patch V4 02/41] cpu/SMT: Make SMT control more robust against enumeration failures References: <20230814085006.593997112@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 14 Aug 2023 10:53:37 +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 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: 1774196340188250600 X-GMAIL-MSGID: 1774196340188250600 |
Series |
x86/cpu: Rework the topology evaluation
|
|
Commit Message
Thomas Gleixner
Aug. 14, 2023, 8:53 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. Rename it to cpu_bootable() while at it as that makes it more clear what the function is about. 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> Tested-by: Juergen Gross <jgross@suse.com> Tested-by: Sohil Mehta <sohil.mehta@intel.com> Tested-by: Michael Kelley <mikelley@microsoft.com> --- V2: Rename cpu_smt_allowed() - Borislav --- kernel/cpu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
Comments
On Tue, Aug 15 2023 at 14:15, Dave Hansen wrote: > On 8/14/23 01:53, Thomas Gleixner wrote: >> -static inline bool cpu_smt_allowed(unsigned int cpu) >> +static inline bool cpu_bootable(unsigned int cpu) >> { >> if (cpu_smt_control == CPU_SMT_ENABLED) >> return true; >> >> + if (cpu_smt_control == CPU_SMT_NOT_SUPPORTED) >> + return true; > > I found this new pair of if()'s rather counterintuitive to read. > > The first one reads like: > > "If SMT is not supported, the CPU is always bootable" > > but "supported" could easily mean CONFIG_SMP==n (which is actually > covered in the next case). Would this be better named: > > CPU_SMT_NOT_ENUMERATED > or > CPU_SMT_NOT_DETECTED > > ? Yes, no, maybe. I rather keep them as is because the strings which are exposed via sysfs cannot be changed and are matching. > /* Every CPU is bootable on non-SMT systems: */ > if (cpu_smt_control == CPU_SMT_NOT_DETECTED) > return true; > > For the next one: > >> + if (cpu_smt_control == CPU_SMT_NOT_IMPLEMENTED) >> + return true; > > This reads a bit like "SMT is not implemented" rather than "SMT controls > are not implemented". Maybe a comment would help: > > /* All CPUs are bootable if controls are not implemented: */ Sure.
--- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -625,11 +625,17 @@ static int __init smt_cmdline_disable(ch } early_param("nosmt", smt_cmdline_disable); -static inline bool cpu_smt_allowed(unsigned int cpu) +static inline bool cpu_bootable(unsigned int cpu) { 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; @@ -660,7 +666,7 @@ static inline const struct cpumask *cpuh return cpu_primary_thread_mask; } #else -static inline bool cpu_smt_allowed(unsigned int cpu) { return true; } +static inline bool cpu_bootable(unsigned int cpu) { return true; } static inline bool cpuhp_smt_aware(void) { return false; } static inline const struct cpumask *cpuhp_get_primary_thread_mask(void) { @@ -768,10 +774,10 @@ static int bringup_wait_for_ap_online(un * 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; } @@ -1699,7 +1705,7 @@ static int cpu_up(unsigned int cpu, enum err = -EBUSY; goto out; } - if (!cpu_smt_allowed(cpu)) { + if (!cpu_bootable(cpu)) { err = -EPERM; goto out; }