Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp482109rdb; Tue, 23 Jan 2024 05:50:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3EqV/sxO5JD7Ijt+aKrPZVNTr/t7zhG0z6WcSnDrNq1UbWoCqGY+zFKn/wwJNme3Th7+4 X-Received: by 2002:a05:6a20:7495:b0:19c:48f1:42a1 with SMTP id p21-20020a056a20749500b0019c48f142a1mr2772373pzd.87.1706017842366; Tue, 23 Jan 2024 05:50:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706017842; cv=pass; d=google.com; s=arc-20160816; b=tfTT1LWvYU8k6iUJ97S85qx3d3G9UvO5qVfkT1xvQpMNIUbTYwgFTPCW1G8oQePeE/ d0koQdIUH0jfnkicW+N80JOxf9819ezmJv4Q2qVygXvwE0C0W2abKGAhydwxIH9V5NpL S7kuMLR3bQ665a8aplPNfREGqBIFIMqg7+LR0K6hFVfaGkG1LXyiG1cy1nB3V3g8BA4g shvt7st0/Vv0z8IepBc4Cozh8fG13I/VhuqN0yblafo6ofC7e2bEiTgg7kyRkXum+EAd qK1FeFeQ22HyJlBKS44NudnAMXRC/dW1iC/l7ALusGCJtSwN1MXjzHu+W3Pzcvrc936l Ix6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=QYkqZUVDy5aQy4fykCVti4/iE4yQ4r5vOJDLBJD/A5w=; fh=Te0fDPJ/sd+7p881M6fa/oF213lBbJvGdEFWr/TLqNA=; b=SNKaiRvCQenoOrmBthPm3xH+SPe5J+ChvlJv0pyR8ZP2CDYSm6uefPLxjmI8iJPrcB oi8qV4v4cozqTpfBs0EGTDQY8h7VsuZu+F4kGkWrljX6Z6Hh+XnmQAawIS1ywluks7wo 4KmhhUgODfa8YDSJh47JFCTvo9EY4QE4VFWe/RUWGKgIovSwwhHr3xNeTj7AQah76L36 5NGrccm9xMEI3AUndrFLgAMbw8P2kSliv9aH/JgBFEEY9ISo7fvFMxde3YBjROIiyqLj zuSvDJ58vIcgPE7HNsaYnVfVZo9qv7tN8qOtsRVy8NFiEtKHF+KAHhnXdCFUH5R+q4Ul qFdg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CxiWdZRE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-35362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35362-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n2-20020aa78a42000000b006dd7ce8857bsi795777pfa.138.2024.01.23.05.50.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 05:50:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-35362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=CxiWdZRE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-35362-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-35362-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B5218B262A4 for ; Tue, 23 Jan 2024 13:21:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6487565BA5; Tue, 23 Jan 2024 13:11:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CxiWdZRE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="za8UYb25" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FB60657B9 for ; Tue, 23 Jan 2024 13:11:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015484; cv=none; b=ThodwtvzZlPTXqdraaly+DEj8Y9w9uCxaYVJvoPAxIsdZwTFH3LkgwMvp4hVB8Odf7qaBGt+LxB8PR2Nz66yDrHZFsaT5vWgHwNiLj7bXHuNqKMzstTeyr1FNbguhVY98aBx8w3do9Tirjm6JwG52OBjc5/IkoHVNjP77qoqIjM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015484; c=relaxed/simple; bh=VSTRfyPlCXvwknOkQvjqc/Ec8ov0aPVQqZEK9a+yUk4=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=DpKCVhsLYQUY+G1z+0bcwIpQAhNzPnYxMKT1V57Qut2QMPm/tnKyLVzatRPbqD6N8P40fUPnDX7PSOzhFu7xMAKI2/OVQhuddvAOc82A2QrR/gtZwM1Ura4h7CtnpL2JljsdqNWOxZw+2J8x4D/k9wFxWZHRCK6ulkHRwBZZDKU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CxiWdZRE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=za8UYb25; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240118123649.625929494@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015481; 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=QYkqZUVDy5aQy4fykCVti4/iE4yQ4r5vOJDLBJD/A5w=; b=CxiWdZREYvOTlpdW8W6JWefLqwwJPIdIur97a133OCb3dMiITTC9ZzV4hUcbN0wnxEfpwN D/ZKRNN3hsOBdqFKvpE8gSNG7WwWpo26YwKJUoVlg+MxmDxjdioE3tI1FCkLTFnCM4t1cB pCfw8toMovYObQe12Oc22l1yxlsPUyGEbgMi79BtPhuVZa/KGZRzk7/ezskw3r/AUeKeuY 4/lnF+IoHMczWYqDXUOpXb7uA85ZYvLB2Nuh6e4vIZ5BnqCCQ8tc9Jt/QWyUkgPwOYwKoU 947pmmuktBHeYF0OcoTPHsb9F9AywqDpSZm8TfvK1uNIp2wC3g9t/StJaZo+Nw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015481; 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=QYkqZUVDy5aQy4fykCVti4/iE4yQ4r5vOJDLBJD/A5w=; b=za8UYb25giBOnlzfvqR01F18iYPIbIHbBiUR+mAI01Ic6ELUBj/K06f7yKM4udv0Eza08x waB0Af9Qxei89hDg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Huang Rui , Juergen Gross , Dimitri Sivanich , Sohil Mehta , K Prateek Nayak , Kan Liang , Zhang Rui , "Paul E. McKenney" , Feng Tang , Andy Shevchenko , Michael Kelley , "Peter Zijlstra (Intel)" Subject: [patch v2 19/30] x86/xen/smp_pv: Count number of vCPUs early References: <20240118123127.055361964@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Date: Tue, 23 Jan 2024 14:11:20 +0100 (CET) From: Thomas Gleixner XEN/PV has a completely broken vCPU enumeration scheme, which just works by chance and provides zero topology information. Each vCPU ends up being a single core package. Dom0 provides MADT which can be used for topology information, but that table is the unmodified host table, which means that there can be more CPUs registered than the number of vCPUs XEN provides for the dom0 guest. DomU does not have ACPI and both rely on counting the possible vCPUs via an hypercall. To prepare for using CPUID topology information either via MADT or via fake APIC IDs count the number of possible CPUs during early boot and adjust nr_cpu_ids() accordingly. Signed-off-by: Thomas Gleixner --- arch/x86/xen/enlighten_pv.c | 3 +++ arch/x86/xen/smp.h | 2 ++ arch/x86/xen/smp_pv.c | 14 ++++++++++++++ 3 files changed, 19 insertions(+) --- --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -200,6 +200,9 @@ static void __init xen_pv_init_platform( xen_set_mtrr_data(); else mtrr_overwrite_state(NULL, 0, MTRR_TYPE_WRBACK); + + /* Adjust nr_cpu_ids before "enumeration" happens */ + xen_smp_count_cpus(); } static void __init xen_pv_guest_late_init(void) --- a/arch/x86/xen/smp.h +++ b/arch/x86/xen/smp.h @@ -19,6 +19,7 @@ extern void xen_smp_intr_free(unsigned i int xen_smp_intr_init_pv(unsigned int cpu); void xen_smp_intr_free_pv(unsigned int cpu); +void xen_smp_count_cpus(void); void xen_smp_cpus_done(unsigned int max_cpus); void xen_smp_send_reschedule(int cpu); @@ -44,6 +45,7 @@ static inline int xen_smp_intr_init_pv(u return 0; } static inline void xen_smp_intr_free_pv(unsigned int cpu) {} +static inline void xen_smp_count_cpus(void) { } #endif /* CONFIG_SMP */ #endif --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -411,6 +411,20 @@ static irqreturn_t xen_irq_work_interrup return IRQ_HANDLED; } +void __init xen_smp_count_cpus(void) +{ + unsigned int cpus; + + for (cpus = 0; cpus < nr_cpu_ids; cpus++) { + if (HYPERVISOR_vcpu_op(VCPUOP_is_up, cpus, NULL) < 0) + break; + } + + pr_info("Xen PV: Detected %u vCPUS\n", cpus); + if (cpus < nr_cpu_ids) + set_nr_cpu_ids(cpus); +} + static const struct smp_ops xen_smp_ops __initconst = { .smp_prepare_boot_cpu = xen_pv_smp_prepare_boot_cpu, .smp_prepare_cpus = xen_pv_smp_prepare_cpus,