Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2439746rdg; Mon, 14 Aug 2023 02:31:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElfMIA1Dn1cTSaYI29Unei2W1t2jKIl8Zuw7w63oXMbRv0k2N4lqUMzJyWverpipNgZk8I X-Received: by 2002:a17:907:7758:b0:99c:f6f7:1796 with SMTP id kx24-20020a170907775800b0099cf6f71796mr7717935ejc.42.1692005517474; Mon, 14 Aug 2023 02:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692005517; cv=none; d=google.com; s=arc-20160816; b=jTso8s7JWpY1DK5LQj72DsrkymEUnWf98J83OEYsUqYLs8KFqciBda5ZSPQAwk/T3V neJwy7Dx2TXvedSYK/th+FjeQvSLZH7+X9+IMygr4ZRJQ1tooc8YVGpFCjCHvkwFvXDG zM8+arVu+HNsHJX/DpewNGtnvFH1Cb2etmLyzmi1ub17N+PT2xHbYr8QkkbepAxvTNKd OcDmjsVzeBS2WhOY/jwx0GNklVHUisjgi7MejVUbvha7ZxHFpO9jYnI50ziy7dIZIR1A j2+Kuba+yac/tJi2b9R7JX/ExSvS70qPayDxZQ2WKNYkPGKJmoZ0J7QKQSyGkKH+xkI6 LcsQ== 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 header.s=2020e header.b=CSra9bkY; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14-20020a1709064d8e00b00992e22a640csi7100837eju.547.2023.08.14.02.31.33; Mon, 14 Aug 2023 02:31:57 -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 header.s=2020e header.b=CSra9bkY; 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 S235018AbjHNIyO (ORCPT + 99 others); Mon, 14 Aug 2023 04:54:14 -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 ); 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 ; 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 To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Michael Kelley , Wei Liu , Pu Wen , Qiuxu Zhuo , Sohil Mehta 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- V2: Rename cpu_smt_allowed() - Borislav --- kernel/cpu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) --- 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; }