From patchwork Wed Aug 2 10:20:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 129754 Return-Path: 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 + 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 ); 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 ; 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 To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Michael Kelley , Wei Liu Subject: [patch V3 01/40] cpu/SMT: Make SMT control more robust against enumeration failures References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773113497983168292 X-GMAIL-MSGID: 1773113497983168292 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 Signed-off-by: Thomas Gleixner --- 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 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;