Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1167686rdb; Fri, 16 Feb 2024 07:18:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWjEeBNI/tqKmS3VPetsuMAGEh1/EVZj5ZTcy1xwYFD8Ep5e3SJ68QByR1ufaJW2rayJsIxBs9hNgAl9w3jy0FYOeeigaXGhddS/m7XkA== X-Google-Smtp-Source: AGHT+IFyc6K7Ws9bUsNMYo4wa3cBJoHBXHwNwWjg0rOyrp7VyA1mPtqXrFbPZJcRnihg7suB1dNy X-Received: by 2002:a05:6a21:3997:b0:1a0:587d:5664 with SMTP id ad23-20020a056a21399700b001a0587d5664mr14403218pzc.15.1708096736664; Fri, 16 Feb 2024 07:18:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708096736; cv=pass; d=google.com; s=arc-20160816; b=bwY1vfBPRZnI/5U4lC90nc75LgxlLBuUFn2GuuEroMsPttAwHeeDCcZfcUX+l+1DfN Yoh9FqKcO4Pz54qORmLMT+xzh+J9MhE7LcYprwYx67vMZ46z/Irsv2ZoiW48Mt6VS1Q/ poj1LPx5Ht8xfeZZYyWmVfBnkXxSpBZ4ey5Lfeo076bEgIN+d8gu5AS77a0S7cwAv8Dk aTMdr3y5tZRfCzw0Q1hsXI8zCfjy/Dd8rR5DpydIpq2k14097qQZZKLyO/pgL98e7vlI jIf2MjSxNBcyBcLqN93xMOkiZWt5BVCiUmYahYnVlNkqmSYadUf7QFlYVkepBdpJVAm8 nYcA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=y5IMW7g7ZBFtpyVUyp9Bmha+mfhhRo2Ei0BOPf5AEqw=; fh=HfXWoIhgCc+vt39DMIJv/Ec0aAKnw0eFA8QxuIQTUoQ=; b=dgqBZ6HpmgndBBFoalE51R5fgeitx4qd7lzgKL6iHzFfKP2wr04Z89wy/gzP+v25L3 iDqw0Vr2T3pUZE9laioNhQa4E99jBlM4DF3iDhkkmUE2es6wh1J3A1eJmxNGbBkbsV6u J0fAHZri4YNt9qyd5hBNjAX8jH3AlWWRwkVhX6ZdkNKLV9O5iSg/aiDid7NNW8nwuZBp c3pVFkvgOqx7lfUaCewJBxkPbcBZFFll1h/pdhRu/vxkOeTPW36N5UtsMhZk7ZnLjdrQ qtiGMih2fHLkny8+Aq3st8hoPJB9N+BiNiUOmeM8afaZW5DAM1i+3y8Rg5yOv1hqQ3Lo 1OiQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Vo48m1nt; 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-68801-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68801-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q2-20020a656a82000000b005dbf22da2c6si30323pgu.61.2024.02.16.07.18.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 07:18:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68801-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Vo48m1nt; 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-68801-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68801-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 5E88828390F for ; Fri, 16 Feb 2024 15:18:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51CA9130E54; Fri, 16 Feb 2024 15:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Vo48m1nt"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jKELYrcR" 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 93BA8130E4A; Fri, 16 Feb 2024 15:16:56 +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=1708096618; cv=none; b=eiwDkOO+OXMF7xhgu/mPaNTx3SsH/+mnkOhnm+NbF3ZO5AM6LB8JD7H4DM8dlklVzr3FdmlNpMyvr0Q0zSiwbJRfu8ku1Yt/pnICctMkWGenFG9K2im9db+cq5RvIN+TGmgR4abAAPId9xLvw5UK+MJnHvAMJ3l58hrZQLRLJyE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708096618; c=relaxed/simple; bh=R+QNnNy1teOxlVVAigZ4Eo5eHtA9VlUU1AokOKMEDms=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=iciacVdpN8MD3XYtwOxbnOCXV4cBxyMt/ERmV3/klUFTkS77aEnmBNl27smzjt27pkKMh1H73zhmug90G/DGfo5LkkWZ7VRbvQqC0LKL1YgnKeP+L0WmZM4QDRJb65r2egPJd7RHyCMh6QaIGoBEaqyp9WXx3Yon2Lk0DVNwf6o= 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=Vo48m1nt; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jKELYrcR; 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 Date: Fri, 16 Feb 2024 15:16:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708096614; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y5IMW7g7ZBFtpyVUyp9Bmha+mfhhRo2Ei0BOPf5AEqw=; b=Vo48m1ntxBAc1Ggz/QIItxNe5VP8efKrdwnKC1TXm5D3bBdpBES08gMAIlglbQqq2nwvws vOvRQD7AU2GbIVnRvd7PuHuuQ2z3nQ+F0uCzlIQuFYbpwHZ5caQa2/CmQ7eFbT1oWSUFxz jh3Hr1Gpk8Ij9oYPXqV/hzgWw29ehhlI0TuB2+0F1C5zS/RgIIBHwjHoq51LmiwkrnwzZe K21B5PwXsQul6tUUl82t5NWQhfKZ10r2ClbzdQdw45QjNbgLhCkqyqT0Hiplf1iOLEf8Qk wHcFIw5F3tO006vn89ZVJvCWXuvR+gyAn0QlQqty7vSExaXo78dsDGKB0tmQ5Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708096614; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y5IMW7g7ZBFtpyVUyp9Bmha+mfhhRo2Ei0BOPf5AEqw=; b=jKELYrcRngTmgTHPo5kAkbosnlfWlqQBoFZRYovnimhaImtxnsc4dB8XoWCaodYNXSXkQ1 EKRriO8yGp2PQkAQ== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/apic] x86/xen/smp_pv: Count number of vCPUs early Cc: Thomas Gleixner , Michael Kelley , Sohil Mehta , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240213210252.571795063@linutronix.de> References: <20240213210252.571795063@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170809661418.398.8946381891178522312.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/apic branch of tip: Commit-ID: c8f808231f1fb63553f90d4b3796cb6804d1e693 Gitweb: https://git.kernel.org/tip/c8f808231f1fb63553f90d4b3796cb6804d1e693 Author: Thomas Gleixner AuthorDate: Tue, 13 Feb 2024 22:06:00 +01:00 Committer: Thomas Gleixner CommitterDate: Thu, 15 Feb 2024 22:07:44 +01:00 x86/xen/smp_pv: Count number of vCPUs early 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 Tested-by: Michael Kelley Tested-by: Sohil Mehta Link: https://lore.kernel.org/r/20240213210252.571795063@linutronix.de --- 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(+) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index aeb33e0..ace2eb0 100644 --- 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(void) 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) diff --git a/arch/x86/xen/smp.h b/arch/x86/xen/smp.h index c20cbb1..b8efdbc 100644 --- a/arch/x86/xen/smp.h +++ b/arch/x86/xen/smp.h @@ -19,6 +19,7 @@ extern void xen_smp_intr_free(unsigned int cpu); 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(unsigned int cpu) 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 diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c index 98849b3..44706f0 100644 --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -411,6 +411,20 @@ static irqreturn_t xen_irq_work_interrupt(int irq, void *dev_id) 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,