Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp179920rdh; Tue, 13 Feb 2024 13:19:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWzrC7ogw7a/UlfEX26kPpvvhNceBvM/vcCWOxTXViTTuysmF2kFcQ+HIjBvcoLI2I7CPaBSVwN37tjMxZyRVX8TXFvDVhHYWBF1e1myg== X-Google-Smtp-Source: AGHT+IECMq7dbPdBEX8oHT4goyeGFqWMcX9dl523KFXXUqTJSlFbOBMSdeo9xb55P+XTP0yEQwsJ X-Received: by 2002:aa7:d7cb:0:b0:561:ceb6:28c2 with SMTP id e11-20020aa7d7cb000000b00561ceb628c2mr502290eds.19.1707859166964; Tue, 13 Feb 2024 13:19:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707859166; cv=pass; d=google.com; s=arc-20160816; b=gAh1YxXPckrsV7zYvv6Vm4qOnR1OPDigWjvKSKJKrQJJrNMATxXkyloD4g6YoM0jXi afQ3kiGDZvctVmQNXVoCl4RvhaWQ1yycUrW9IitqDPh6vhKqQRTYjQcju0XuXVxwlRsx FfSA509uoQwKRArv8hVuQEDRjtX+h8cHTPPKObpD5sWk2h9WCdQ21CYdXFBZqfr2GK22 nROmQulq3zkiAb5gorrlKzdYRKaKmlsJ2ErnE5aGUmb2P79CL2NiYKx3gKtlpIH1Vqbt xlt60alhksip32eZnPwV/9CwyJxFM4UCmlR00fEZqfJIQapHXyrKkFgZ9xn16K3TaSh9 g8dA== 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=l5IIheic7HTdLbtL8FePLNCYvWctux8lTDROKkU5h0g=; fh=nMdSHiRjp9lUghFqzgcB/eGFjeYifEgiKQVWl6BE06Y=; b=HmHGEjGRwVuaqAZNKPAYPaUAwqv4reYYIriqxF9+b00H8UAkdKK78wE8ysbkONH90o vpym2kqgWj0CeV6gZIfGhNi7Umk0xkFA+wfUgdQwV5lu1DtJmJSAlrF0XwOLfUosxHuK FFVjxeLZrpkW6AuvvoOakVghxsnVmQcLLdm3bB9mR11IVvCVh5tQh3wiZjzId0c7n94W KnCoCz3gyMzIlbKd3Us8chpvHtkCSRVYvu4kxxhblf2+sBdsWUqTYKOMoZsfFDRV/PW6 4DKUMotR6accD5VgJpFyCGNe/Nmne5lq8DjqygYu9xVSfddkD3c6pJSQjkne95szOzMi cjKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Wt+Q6owG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=a1Vsgm7b; 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-64304-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64304-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de X-Forwarded-Encrypted: i=2; AJvYcCUeXajR8S1t63TF0MN7ZoEPkd1FKBabXBJKiYtPaf6rWTJRVoSiVjGB2rscCpyP4l8Vk66POKjth8oHcV3364SPfE9gAD3tlH8e/E58Kw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c64-20020a509fc6000000b0056232d59d6asi116594edf.291.2024.02.13.13.19.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:19:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64304-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Wt+Q6owG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=a1Vsgm7b; 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-64304-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64304-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B4D5C1F28476 for ; Tue, 13 Feb 2024 21:19:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D179C8405B; Tue, 13 Feb 2024 21:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Wt+Q6owG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="a1Vsgm7b" 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 86DAE839E7 for ; Tue, 13 Feb 2024 21:06:02 +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=1707858364; cv=none; b=CwtjeUYKI4qNC48koSkRadENcqefIhsZdiVyCRWrc1MksqvYHZHNJ/OwnlhOSkHWkqtLEDLNQUui8tlWt69vqeaj856e2bkMSy21bd160PVk35m/Fdx1+pS89aNJyommLtMU16iqTsQuDbos5/cXZzK6gbRMSjSTjs9GRwc/2fs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707858364; c=relaxed/simple; bh=rLsp+V/ZBSzycpeyYr3sAEzojATjfDc9ZcQACwfYXk0=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=VQDYbK4WdVn4nIESp8wM5SbBPRW7laapD366mrYh5gPs3C7omByM3j/7wR/pj/J4Fdxt55Ba+byGfy4VdfcmPAFxcdrTSMZqijtxtE/D0wcq0hmmBQqQhd3wakjIdKUbZ5HPpnVM1Cp1O++xyfGV/r5as1ajqdz0CWpTFN2dNHU= 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=Wt+Q6owG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=a1Vsgm7b; 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: <20240213210252.571795063@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1707858361; 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=l5IIheic7HTdLbtL8FePLNCYvWctux8lTDROKkU5h0g=; b=Wt+Q6owGWnrNJeI13LNavmxTt5Lzs5ThH/dQXT6qesO4DKSLqgiS3ondhGjNgKOQbCvDgW 9R2GOO5EAsdXU6sSJ+htWRBEmUrGCB/661l3aSPAsEEpCKKyJESlpafzVFP+cGSmVB8bkc 42kYfpgOCQyZ65aXNn24eWvGdmVh708pAxPG7xivimdq00BIo+iv0VJwEIN8EPlJs3KfTT pII6gtnyJR95M5aNNod+zIBJybHtvUj0Z4gdtEQPnXXLSi9zCKzmUa7KMd2CmdMBycl8c/ T1vcJwagFyvVJrB9cilnL4xYqhZO2Ghot1WZ8m60nRit2K8h4+U9Y0Z0rs1LtQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1707858361; 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=l5IIheic7HTdLbtL8FePLNCYvWctux8lTDROKkU5h0g=; b=a1Vsgm7b2KoILqZlz/V01LMAGTu+EopHn2bXvBSK5ls0/E3HO1hQG+Dc294cj3B67tmfnk WaGUvLvojc1mH2DQ== 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 19/30] x86/xen/smp_pv: Count number of vCPUs early References: <20240213205415.307029033@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, 13 Feb 2024 22:06:00 +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,