Message ID | 20230802101932.819070039@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp364198vqx; Wed, 2 Aug 2023 03:52:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlHXwyZczd4WjbCSP5Si8DnykbMnkoqUtHjAzEXcj4eeQWZUgJ/WosDuvsHc0mpUJb8SfZtk X-Received: by 2002:aa7:c419:0:b0:522:36e8:bc88 with SMTP id j25-20020aa7c419000000b0052236e8bc88mr4323859edq.12.1690973556585; Wed, 02 Aug 2023 03:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690973556; cv=none; d=google.com; s=arc-20160816; b=LRft+A2gw/CEgXcvajJNHyh9FqzXdhKZx2hr407m5ALA6/+9SK2ZsS+c8S97h9eOYS wTpOLl/D+pQuOac4biJEh6Gy/eAQgXkDWkFjgdfHle/iHZxDOLCUAh+fpISylUxAFJqP /kzV91gPzdDo1zeSTx1hr1+X8r8trS+DDLHEl6802J5tMfkYivL+Kuy31W3TmcY4WcTA pTeDI+/yeMnwlALFB+hQVM/2Gs46K03pwwl53x7yzP6mgvI1MCmEGHI14ugtzc7OjqNO cpSJoQpTkhJQwXFrN54VrfXbZmtJqqCtl+r0ZFeh02L3znzSecnZ66XddkES1DuQtFtk SOTQ== 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 header.s=2020e; 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 h9-20020aa7de09000000b005223f8d2a2csi9510302edv.441.2023.08.02.03.52.13; Wed, 02 Aug 2023 03:52:36 -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 header.s=2020e; 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 S233413AbjHBKVQ (ORCPT <rfc822;maxi.paulin@gmail.com> + 99 others); Wed, 2 Aug 2023 06:21:16 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <tglx@linutronix.de> To: LKML <linux-kernel@vger.kernel.org> Cc: x86@kernel.org, Tom Lendacky <thomas.lendacky@amd.com>, Andrew Cooper <andrew.cooper3@citrix.com>, Arjan van de Ven <arjan@linux.intel.com>, Huang Rui <ray.huang@amd.com>, Juergen Gross <jgross@suse.com>, Dimitri Sivanich <dimitri.sivanich@hpe.com>, Michael Kelley <mikelley@microsoft.com>, Wei Liu <wei.liu@kernel.org> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773114288076572650 X-GMAIL-MSGID: 1773114288076572650 |
Series |
x86/cpu: Rework the topology evaluation
|
|
Commit Message
Thomas Gleixner
Aug. 2, 2023, 10:21 a.m. UTC
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 <jgross@suse.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/kernel/apic/apic.c | 11 +++++++++++
1 file changed, 11 insertions(+)
Comments
On Wed, Aug 02, 2023 at 12:21:01PM +0200, Thomas Gleixner wrote: > 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 I think this means to say "cpu_smt_control". Committer, pls fix. :-) > 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 Ditto. > 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 <jgross@suse.com> > Signed-off-by: Thomas Gleixner <tglx@linutronix.de> > --- > 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 <linux/smp.h> > #include <linux/mm.h> > > +#include <xen/xen.h> > + > #include <asm/trace/irq_vectors.h> > #include <asm/irq_remapping.h> > #include <asm/pc-conf-reg.h> > @@ -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; > + } Can this be somewhere in the Xen init code instead?
On Fri, Aug 04 2023 at 20:12, Borislav Petkov wrote: >> @@ -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; >> + } > > Can this be somewhere in the Xen init code instead? Not for now. That's all going away with the 3rd installment. But right now it's the right place to be.
--- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -36,6 +36,8 @@ #include <linux/smp.h> #include <linux/mm.h> +#include <xen/xen.h> + #include <asm/trace/irq_vectors.h> #include <asm/irq_remapping.h> #include <asm/pc-conf-reg.h> @@ -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;