Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp837313rwo; Wed, 2 Aug 2023 05:09:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlEIENuX36an129w73vE4+KmmEQRZkptuYSQN1oa+XhY7kYBMk/7aWENjNsy6iIBd4mqka6V X-Received: by 2002:a17:902:ecd0:b0:1bb:fcb9:f85 with SMTP id a16-20020a170902ecd000b001bbfcb90f85mr16185746plh.32.1690978139692; Wed, 02 Aug 2023 05:08:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690978139; cv=none; d=google.com; s=arc-20160816; b=DsoRhvKLnv7rTKE8COy4a1YVzs8mpjXMO9pBoTnUguJ62iiPJbkRV85SyLhcc7BIe4 8SnMP+BeReZx/ooqmdgMon8l1RYvpH5k/5N8nXU7ptkScNp4oeeu3SaxKIBNBi0/ppTd NCOWOlloecx0dsCiMASQO6Cv7Aq2tSjSLrwNEtL/UxM26tH/opo2ZF8PlZb5+stZa9CC I7ko7/iix2Zh8EzYWTmn9L1XOvb9KRE4TzqAK6NyWiWQTazOI/ngr8bmhGh+6e73GQFz Ko3IjF+KjohiUJaED2il29KUylex157CvUGqLkChfQEV4Y4fEL7uG12xGvrToDIX2zMT w7dg== 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=KworwVT2v0HpqXoPWJdJcjW+bA4KcReILTYRuVf21jU=; fh=O9JPtEgoXN20WvvffwC9vht4C9mlV4cjm0SKbEbqoG0=; b=lNuv6vokbnp+10KkhD5f9ShYnYXVD48rlDjjOkWUOtSQay/6LiW8BQmDpXru9CVxDl BmgHSx6/+vnnpPY9i6heS/U42jLPJwFSxqw7XIEMmDc71xalv5E/tyFANId8z+hbAP6q Yylva4Qh2zPBlU4IeHzjU6a3NwH4J2YEgSdIdZ4SFhI0LsvKkg0fmkcbvkpJYsSG3CzI HveZu9ECxtQpoWv51CSyJR1MFwPBL8hndqR0Hhbhz4g1esGQi0FfXRbF4JwmrwaSr/pb 8SQFrr7tNo+h39fQZDPH3Z8gMcOiEfem/+er1VEVLA5i/hJ4NR9nCjlXVhwoOHY10c/E i17g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="p/BKVW6r"; 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 e5-20020a17090301c500b001bb3316f71dsi10930000plh.481.2023.08.02.05.08.40; Wed, 02 Aug 2023 05:08:59 -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="p/BKVW6r"; 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 S233393AbjHBKVP (ORCPT + 99 others); Wed, 2 Aug 2023 06:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233212AbjHBKVF (ORCPT ); Wed, 2 Aug 2023 06:21:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EB952690 for ; Wed, 2 Aug 2023 03:21:02 -0700 (PDT) Message-ID: <20230802101932.819070039@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690971661; 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=KworwVT2v0HpqXoPWJdJcjW+bA4KcReILTYRuVf21jU=; b=p/BKVW6rK2byUO6m6m7keMSO0k6eLcnu+ZVZBAHzwkKkaL3qYNTYBJ3+Xxld6PSFMKwvC3 qWoIjVCE/RY+re/+YUeII8FzRmk2USFYEDcsuoKIo5uXntaTtsq0pFwQzAuJJTkf+ahj7N sBWrYiOuOBsMuCgOjldGH8LtQG1rG/rq/BmFbxGfLXukoH3wm3ei11leQHzIazrDaRU0ez 9F8IdQFefXVgyY4kXQ8W1GMKwal2cCr1teVVwuc8ZLrqlZgn4EtyA821Y3F/1wRqACVv29 7MxNifWr6s8J2FMrTtQxmneu2XfyDhkV0JnXusQ81t/1KIyLZeGPs/1BYxnMyA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690971661; 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=KworwVT2v0HpqXoPWJdJcjW+bA4KcReILTYRuVf21jU=; b=gmJPpEGfssLMz9LV7H2vKKjNS/3GGIo7SH/jpzhq9puu8MBthGCUE3NrNk5AhkEU6AGch8 PCOsmBFyD+08lYBw== 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 02/40] x86/apic: Fake primary thread mask for XEN/PV References: <20230802101635.459108805@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Wed, 2 Aug 2023 12:21:01 +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 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_hot-plug_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. 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 --- 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;