Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp837031rdg; Fri, 13 Oct 2023 02:39:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGzFg4RzmrczkHUEr/mJAlao47miEgct5qmJCZobHDDfRs7n8TT9MNpPJQIz+Rxum9zzQS X-Received: by 2002:a05:6a20:2445:b0:15d:8366:65be with SMTP id t5-20020a056a20244500b0015d836665bemr34815393pzc.9.1697189958690; Fri, 13 Oct 2023 02:39:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697189958; cv=none; d=google.com; s=arc-20160816; b=UGT+ZjQn+BAo+dMsUthrxF25aKNGIjIaFdPdimdXAJdUb9WF4m+rnBAcW5xuPVpi03 1fyzJe607DK+J9AaxwHmEzJcQfzgUS2lGE/EgfzSIMKl3NoCOwj8Ex6eId7wf7SuE3xn RFr6UJh5iI55LiyZMAI9fxAS5XjpQTYecM5y4yITXSZKKIUXE6xWDwsGJfJwrsqaHalm 9nEQz/3xOG3U7uY5fUinYu5CxQXm3HurX62il4vsRZVdrfzBBj4wISqPTnCrTmX2C3R7 e91xXMK90mmH5/HE/qZco2+TsErji4LobnKknuvIrn/YyAyXTUU2tVHYoPoMxKFldOmI cwGg== 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=rCTCPgo8jeqYDUyGPCO49XEL+tzO99RT05N9qxWKWRc=; fh=jyUaMcKccPBGiHulsFQCVYJjDZYW9PU3yBzpCo/OBHs=; b=c35e3x7dRv1V9WWQNswFdBrP63rKYCbgYdKJfZYwRDDs/FyNg1El8yohPNycGs1pVj vc2PzvJx0vILBqHiaYPwng5ECgaverXZ/lDWgZ4rbCXllx32oSPh432iDmVHCJAEgg60 AwmdsjJmagEtHrXFeXAzHfLZCJrfJ/coQyECMJVTEO5tywCGfLGTMxjV8tIxxfXCcsJ/ x0iLGwdT6VK3Ew77cQ0rMJH6/rXLsyR1oacfkeYaPvzawe4Z40n5Jn/5jAZRs7W4IDBE Ise1lrdPzLQJeaRuL28xFY+jetj0pptH1Khxr5jiItmys72UqrLfdjjvb5tBl4yjxGGa 5cUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mm5BdMEV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DvcCmy6X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id z66-20020a633345000000b005ab2cb8fdf8si1061699pgz.779.2023.10.13.02.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 02:39:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mm5BdMEV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=DvcCmy6X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 9057682F7FB7; Fri, 13 Oct 2023 02:39:17 -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 S231293AbjJMJjK (ORCPT + 99 others); Fri, 13 Oct 2023 05:39:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231284AbjJMJiR (ORCPT ); Fri, 13 Oct 2023 05:38:17 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5985EBE; Fri, 13 Oct 2023 02:38:15 -0700 (PDT) Date: Fri, 13 Oct 2023 09:38:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697189893; 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=rCTCPgo8jeqYDUyGPCO49XEL+tzO99RT05N9qxWKWRc=; b=mm5BdMEVZPLvrOLrHF03QnQw5cfeUH3j/SaZoXapSbD4RDOOarP3e7DxQakQMpKzllDbw2 Y1BRiOkPiiRqpmwr3OAmns2GEwg7dsGzdNuDgnNX3FxB7zRV22948SbPG0Pli/5dFdGigV hKrNoQwX/J6Nf7f3/qgLwCCisG9RS6oRYGng6/Vh7ezfgIJz3khBPoosEclrPcJ1E1wSC0 uey8bGa4oCOpfAy3pMFkzWkdxWszb9qzozpKWRE5vrwRxhk5iDNNJxs3kfZg47F6T5bDHn Dcq+XmAvO4ebYJbeI5+b0bWvPUnOFA/J/WgTlNmkUyQgWV/ws81JdCGsb9HL7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697189893; 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=rCTCPgo8jeqYDUyGPCO49XEL+tzO99RT05N9qxWKWRc=; b=DvcCmy6XUtOkXfbQxEn+2tr3mWOOVAf6mBm3vFU2LUg0vNGSxIVAIi5nH14Hyy3dMSEZF3 xlYIScSP+qSbZsBw== 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/core] x86/apic: Fake primary thread mask for XEN/PV Cc: Juergen Gross , Thomas Gleixner , Sohil Mehta , Michael Kelley , "Peter Zijlstra (Intel)" , Zhang Rui , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230814085112.210011520@linutronix.de> References: <20230814085112.210011520@linutronix.de> MIME-Version: 1.0 Message-ID: <169718989311.3135.5099682715244955511.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]); Fri, 13 Oct 2023 02:39:17 -0700 (PDT) The following commit has been merged into the x86/core branch of tip: Commit-ID: 965e05ff8af98c44f9937366715c512000373164 Gitweb: https://git.kernel.org/tip/965e05ff8af98c44f9937366715c512000373164 Author: Thomas Gleixner AuthorDate: Mon, 14 Aug 2023 10:18:28 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 10 Oct 2023 14:38:17 +02:00 x86/apic: Fake primary thread mask for XEN/PV 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 cpu_smt_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 cpu_smt_control is set to CPU_SMT_NOT_SUPPORTED which causes cpu_bootable() to evaluate the unpopulated primary thread mask with the conclusion that all non-boot CPUs are not valid to be plugged. The core code has already been made more robust against this kind of fail, but the primary thread mask really wants to be populated to avoid other issues all over the place. Just fake the mask by pretending that all XEN/PV vCPUs are primary threads, which is consistent because all of XEN/PVs topology is fake or non-existent. Fixes: 6a4d2657e048 ("x86/smp: Provide topology_is_primary_thread()") Fixes: f54d4434c281 ("x86/apic: Provide cpu_primary_thread mask") Reported-by: Juergen Gross Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley Tested-by: Peter Zijlstra (Intel) Tested-by: Zhang Rui Acked-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20230814085112.210011520@linutronix.de --- arch/x86/kernel/apic/apic.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 760adac..3cdf484 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -36,6 +36,8 @@ #include #include +#include + #include #include #include @@ -2344,6 +2346,15 @@ static int __init smp_init_primary_thread_mask(void) { unsigned int cpu; + /* + * XEN/PV provides either none or useless topology information. + * Pretend that all vCPUs are primary threads. + */ + if (xen_pv_domain()) { + cpumask_copy(&__cpu_primary_thread_mask, cpu_possible_mask); + return 0; + } + for (cpu = 0; cpu < nr_logical_cpuids; cpu++) cpu_mark_primary_thread(cpu, cpuid_to_apicid[cpu]); return 0;