From patchwork Fri Feb 16 15:16:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 202161 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp584054dyb; Fri, 16 Feb 2024 07:19:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkON5aOaL37rctBDTSAr/Q5AAV6EMuPgV/2Wj7ZxdhG/IYxLXTAmY1REgTfBuk8+D2OCtoooDIS5zigQyeTFtjDosZMA== X-Google-Smtp-Source: AGHT+IGqRcZVrCtPvZ+K2KdPG6UTm8CPbxANFe+HjRDu1oncs/5KCVwI9ufQIfuugO6cja1yNf9S X-Received: by 2002:aa7:d794:0:b0:564:b68:1854 with SMTP id s20-20020aa7d794000000b005640b681854mr533501edq.17.1708096768108; Fri, 16 Feb 2024 07:19:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708096768; cv=pass; d=google.com; s=arc-20160816; b=lYEDNUuhd9QN7uy9omobxFRBUY/usyzgvSEet6FaL12y4rKbnm5eTkoUUylGjKl3PZ 0CVZC28Rd0I0CIRMsUIcuCezXBTMnrq33ACkHO5NYjGcF9rc0hSRIIeJmLIKpKVgOjF3 92pVe/ZpAL+G4uJZB6YfXG9ML6TaZ9dXBvPPrkWULdwLDZLFSRFnimjT/BDyJFmAoSrH kX3T9eTuuk54QEvxQvA6Cn/Un/546qewuvARQU397cfWlknjgtf0U963gfPvUcQvFUfV j/vDhp9XpQaffVS5EPSh43P+XaOGBKL78/cGYcNP8SJ3TXDwauo8xav+hD+o+yEU3Mlw yE9Q== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68801-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v3-20020a50d583000000b00561a9aaf59dsi48076edi.414.2024.02.16.07.19.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 07:19:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68801-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68801-ouuuleilei=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 B36081F21C6E for ; Fri, 16 Feb 2024 15:19:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70699133412; Fri, 16 Feb 2024 15:17:01 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790820182819879420 X-GMAIL-MSGID: 1791069277039857525 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,