From patchwork Mon Aug 14 08:53:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 135330 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2654161vqi; Mon, 14 Aug 2023 03:44:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEc2RVuohuOuwIOgoZdZY27ZJul3ysqqRuFhpG1HpRuYDqroNAoqqZapl0auOVMSiMO+49D X-Received: by 2002:a05:6402:750:b0:523:437b:44ff with SMTP id p16-20020a056402075000b00523437b44ffmr7147011edy.12.1692009858041; Mon, 14 Aug 2023 03:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692009858; cv=none; d=google.com; s=arc-20160816; b=eNXPDTB5WmzE6Gbr+T39sIpjBnRv/6LecheTDRagW/keFipo0kMacBCIuIqeKdJBjc AFsNUrqdUJPzVcD0RApnWU5HbZheH6qaNKMtanIrRuXVICOaF9aVB8jI94QQYrOLUvYR npu43FA/9Ly6P7mL+mUihcsU2sWgkmxj42loeinF0SeufXxAJO9B3/shpGW4ATicRdVc Ik8gnZi01/lPPNEOuXi4pSB4SsKxhQkUBZDrLPFnbXM2Nj1iocNGQCYKX5AqfQeBVxyd eivCU0mskCjmhJi1ikjmkByb1rTSk3TvQ+VYNcdlh/FMJuqwVtkpL73fQUHpAebw+2KN r/0A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r25-20020aa7c159000000b005224e403e96si4931299edp.196.2023.08.14.03.43.53; Mon, 14 Aug 2023 03:44:18 -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 S235053AbjHNIyR (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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774200928393752650 X-GMAIL-MSGID: 1774200928393752650 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;