Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2458946rdg; Mon, 14 Aug 2023 03:20:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPs/eCB5lzLe6pd2EbXUYcUiaCTr7VRqZseASFAt6MwQmpe+/mMXOyAxfN4V4NrsdCFD93 X-Received: by 2002:a05:6a00:1995:b0:680:d00c:b164 with SMTP id d21-20020a056a00199500b00680d00cb164mr12229759pfl.34.1692008401874; Mon, 14 Aug 2023 03:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692008401; cv=none; d=google.com; s=arc-20160816; b=aQ76euqKOj8Qtwj3ZU6JrUvAhUxZ3AYbIgkwEwYv4FfQ7PiifZgfSwoxpLN5vbygbp d/PJF35hE7RFszcurvivFqoL8vCfzwtFz75+NZEdPjcUVk+pMrwXLmhhkRt4hRDaH9G3 Dvsw2thaNYNUs9e2d/NIvuxT/MthusByT1dYWEYhkq2B4VRD0+dAQHCnosixV7LNJkzA JB1eKPUW+1mvuZhOhKasXsCn3Wy1TV5xmArqgtf7XfCV+NrAIX+9ZagTy+MwuT7BH3fI kyQTTWwZx97MAM/Zy1A3o0nm059/OrHbbINeugA12lZAoEBS7GaB7p0Jo8BHkKDKtbu4 YwzA== 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=nD+LWCUPb/nY7KWkB0c0EJXdbBh6K+dG9PjIdqnGrPA=; fh=vmKIJtcbtoHWhyuxI4oEq8r1SWZ2V9Rrbp1Orw2DxqA=; b=fAtDtdn1dff/tNg1YWeUP7TYm6AHW+O4SKuP0XsAhaAecmCX3dwKDILIeIp3usp/5h nXViPiwwsTxm4QyqJPCtYKUezcNgNWRzh2rj2cors9fSZBIrwPhnaTD+ekXK1XZVvVg5 +odlUdRuPXxqKCDZ5IABRCUU3LztPdDJlHSrBac8Jqj2NackXVsiKtoDTBu8eiqzlm68 QGW13ujOyge22RvRXAn1F1HUkWgu3V9NHa5W9vN+RrkRCUIbGkSVdNQmqWrj9kqtVPwW gxStoYGH03JNwYyLFtsJQqq0cesEoC2npLz60lP6IpjaduQ7vu+q+7C/uF7Kn0X6g+Tc Pagg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fwo2FxuO; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a056a00238300b0068254b9108bsi7977801pfc.71.2023.08.14.03.19.49; Mon, 14 Aug 2023 03:20:01 -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=fwo2FxuO; 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 S235050AbjHNIyR (ORCPT + 99 others); Mon, 14 Aug 2023 04:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234152AbjHNIxl (ORCPT ); Mon, 14 Aug 2023 04:53:41 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D6F791 for ; Mon, 14 Aug 2023 01:53:40 -0700 (PDT) Message-ID: <20230814085112.210011520@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692003219; 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=nD+LWCUPb/nY7KWkB0c0EJXdbBh6K+dG9PjIdqnGrPA=; b=fwo2FxuOhXijXLvaxBnbfpYmO0XxJ7IcIxOP4BSUjxKhdOLTmT7Hvbr83tk+xjmxpvbvja AM9fLIyk2jEQm83V1S8l3R+HnAp0S44GSy96xPgTI3vtiKC+aw2qo0JRXzJAM8wvnzfJOS A8twcLryRivqwqhGmM3ylvhb6WEDcC2aAXXQb9FbuW63Zu18J4Czv0u/0qAXK6iJc/78jr KlbJl69SPZXkUmmlxGjDu50K6p6wY5EqFVHaqAL0aLzWH9fALWF65uvzPb8KLP0hTbdtvf S6mqW9w6iDTjaqrCNHTfSoDpGliO8KTKQ+vterldyDyF7pzUMSh40yf5ye7cMg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692003219; 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=nD+LWCUPb/nY7KWkB0c0EJXdbBh6K+dG9PjIdqnGrPA=; b=t8JymdvPNdMVI2B8H+PMItAhyODMNSdTb+Djmm04FJALZMrOw7aker1SCA2kr2MwYXYm6h MBXX/2urs0a6GbDQ== 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 03/41] x86/apic: Fake primary thread mask for XEN/PV References: <20230814085006.593997112@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Mon, 14 Aug 2023 10:53:38 +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 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 --- V2: Fixup changelog - Borislav --- arch/x86/kernel/apic/apic.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- 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_threa { 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;