From nobody Fri Dec 19 02:50:56 2025 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 94F9E6167D for ; Tue, 23 Jan 2024 13:10:53 +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=1706015455; cv=none; b=TyFZPwcEuoMtEy6ETVi+qnRJtZpnpt1PRFHPv/9VabZjpNZzJoWvghx34Mzi9CcqQeUvExnq9tQEGJgJ44eA/S0LgeJL7zoyv8BM1oJ5FPlsRejHvXDfXPqZgzO7lr5jAb3nl7pGeNQ7Lp/MDCGqkeDA1aKz6qZq4AzzXP343Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015455; c=relaxed/simple; bh=H8JzuQG1sEOgF2TLbpz/omM2OhnQeRbB3ZTOMANEMTg=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=rY+j+HeIf6jZg0MXFVyRAtVKkJNYSSzjsIl0BpyspSZ/N71elQ1zsiDaDt8x/mxbKsMZA5MSUbbx8d73Vf4ugaS1J4LwJDvIEVRPA4tT5QeiN6YooafAAhWTaNJQjtnXuifzm0WGzKbvGt4sexsE9nOaIOPNSPs4WSY3VpaCBEU= 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=0DdyQPY/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xFGcmW0G; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0DdyQPY/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xFGcmW0G" Message-ID: <20240118123648.602495866@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015451; 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=AnUc38kvL19uRwGNwh2Tl4oOv53yd3EVeT6WSDx/x1s=; b=0DdyQPY/9ac3HBN5zTm5Djkd4OFjxtxGxWJCqhZfbkTAY4ocJxW7pxo3n+OnWjbBQjRIvz b9n19tDI+sVQ5Oc5CQcwHso2W/jSEKx6s6JnHs+rFJXyNvNzDDwuKEs/TE94bni8XpRg4S YVaNR2il8sBen8pMGNEtB9DpGUjPjgkcO4KmIwuSO0/HAuES1mNwNZxmJ22IeqN01LQ/sF 9qwryMW+igsA1BurpwEytXeckOYGVrNML9iT7lDFIfIlLYlqXGxOYOD+jQYHLQGJQQqs6m CCf6CtZQgoOVe5rv1DhB6qtI56Qh/JJ8bu2OuY+aljgB4Wu+O352W8CKBy4Oog== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015451; 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=AnUc38kvL19uRwGNwh2Tl4oOv53yd3EVeT6WSDx/x1s=; b=xFGcmW0GWGXHALEFybbVHsI5HoNE788P3F59C8DB+0fCuA2q34ucaFU1NXZ0rBufsKy8a4 GK4pxZ17ekJgPBCg== 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 01/30] x86/cpu/topology: Move registration out of APIC code 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 Date: Tue, 23 Jan 2024 14:10:50 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The APIC/CPU registration sits in the middle of the APIC code. In fact this is a topology evaluation function and has nothing to do with the inner workings of the local APIC. Move it out into a file which reflects what this is about. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/apic.h | 2=20 arch/x86/kernel/apic/apic.c | 185 ------------------------------------= ----- arch/x86/kernel/cpu/Makefile | 12 +- arch/x86/kernel/cpu/topology.c | 184 ++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 195 insertions(+), 188 deletions(-) create mode 100644 arch/x86/kernel/cpu/topology.c --- --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -171,6 +171,8 @@ extern bool apic_needs_pit(void); =20 extern void apic_send_IPI_allbutself(unsigned int vector); =20 +extern void topology_register_boot_apic(u32 apic_id); + #else /* !CONFIG_X86_LOCAL_APIC */ static inline void lapic_shutdown(void) { } #define local_apic_timer_c2_ok 1 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -68,26 +68,12 @@ =20 #include "local.h" =20 -unsigned int num_processors; - -unsigned disabled_cpus; - /* Processor that is doing the boot up */ u32 boot_cpu_physical_apicid __ro_after_init =3D BAD_APICID; EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid); =20 u8 boot_cpu_apic_version __ro_after_init; =20 -/* Bitmap of physically present CPUs. */ -DECLARE_BITMAP(phys_cpu_present_map, MAX_LOCAL_APIC); - -/* - * Processor to be disabled specified by kernel parameter - * disable_cpu_apicid=3D, mostly used for the kdump 2nd kernel to - * avoid undefined behaviour caused by sending INIT from AP to BSP. - */ -static u32 disabled_cpu_apicid __ro_after_init =3D BAD_APICID; - /* * This variable controls which CPUs receive external NMIs. By default, * external NMIs are delivered only to the BSP. @@ -107,14 +93,6 @@ static inline bool apic_accessible(void) return x2apic_mode || apic_mmio_base; } =20 -/* - * Map cpu index to physical APIC ID - */ -DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_apicid, BAD_APICID); -DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid, CPU_ACPIID_INVALI= D); -EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid); -EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_acpiid); - #ifdef CONFIG_X86_32 /* Local APIC was disabled by the BIOS and enabled by the kernel */ static int enabled_via_apicbase __ro_after_init; @@ -1676,8 +1654,6 @@ void apic_ap_setup(void) end_local_APIC_setup(); } =20 -static __init void cpu_set_boot_apic(void); - static __init void apic_read_boot_cpu_id(bool x2apic) { /* @@ -1692,7 +1668,8 @@ static __init void apic_read_boot_cpu_id boot_cpu_physical_apicid =3D read_apic_id(); boot_cpu_apic_version =3D GET_APIC_VERSION(apic_read(APIC_LVR)); } - cpu_set_boot_apic(); + topology_register_boot_apic(boot_cpu_physical_apicid); + x86_32_probe_bigsmp_early(); } =20 #ifdef CONFIG_X86_X2APIC @@ -2291,155 +2268,6 @@ void disconnect_bsp_APIC(int virt_wire_s apic_write(APIC_LVT1, value); } =20 -/* - * The number of allocated logical CPU IDs. Since logical CPU IDs are allo= cated - * contiguously, it equals to current allocated max logical CPU ID plus 1. - * All allocated CPU IDs should be in the [0, nr_logical_cpuids) range, - * so the maximum of nr_logical_cpuids is nr_cpu_ids. - * - * NOTE: Reserve 0 for BSP. - */ -static int nr_logical_cpuids =3D 1; - -/* - * Used to store mapping between logical CPU IDs and APIC IDs. - */ -u32 cpuid_to_apicid[] =3D { [0 ... NR_CPUS - 1] =3D BAD_APICID, }; - -bool arch_match_cpu_phys_id(int cpu, u64 phys_id) -{ - return phys_id =3D=3D (u64)cpuid_to_apicid[cpu]; -} - -#ifdef CONFIG_SMP -static void cpu_mark_primary_thread(unsigned int cpu, unsigned int apicid) -{ - /* Isolate the SMT bit(s) in the APICID and check for 0 */ - u32 mask =3D (1U << (fls(smp_num_siblings) - 1)) - 1; - - if (smp_num_siblings =3D=3D 1 || !(apicid & mask)) - cpumask_set_cpu(cpu, &__cpu_primary_thread_mask); -} - -/* - * Due to the utter mess of CPUID evaluation smp_num_siblings is not valid - * during early boot. Initialize the primary thread mask before SMP - * bringup. - */ -static int __init smp_init_primary_thread_mask(void) -{ - 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 =3D 0; cpu < nr_logical_cpuids; cpu++) - cpu_mark_primary_thread(cpu, cpuid_to_apicid[cpu]); - return 0; -} -early_initcall(smp_init_primary_thread_mask); -#else -static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int = apicid) { } -#endif - -/* - * Should use this API to allocate logical CPU IDs to keep nr_logical_cpui= ds - * and cpuid_to_apicid[] synchronized. - */ -static int allocate_logical_cpuid(int apicid) -{ - int i; - - /* - * cpuid <-> apicid mapping is persistent, so when a cpu is up, - * check if the kernel has allocated a cpuid for it. - */ - for (i =3D 0; i < nr_logical_cpuids; i++) { - if (cpuid_to_apicid[i] =3D=3D apicid) - return i; - } - - /* Allocate a new cpuid. */ - if (nr_logical_cpuids >=3D nr_cpu_ids) { - WARN_ONCE(1, "APIC: NR_CPUS/possible_cpus limit of %u reached. " - "Processor %d/0x%x and the rest are ignored.\n", - nr_cpu_ids, nr_logical_cpuids, apicid); - return -EINVAL; - } - - cpuid_to_apicid[nr_logical_cpuids] =3D apicid; - return nr_logical_cpuids++; -} - -static void cpu_update_apic(int cpu, u32 apicid) -{ -#if defined(CONFIG_SMP) || defined(CONFIG_X86_64) - early_per_cpu(x86_cpu_to_apicid, cpu) =3D apicid; -#endif - set_cpu_possible(cpu, true); - set_bit(apicid, phys_cpu_present_map); - set_cpu_present(cpu, true); - num_processors++; - - if (system_state !=3D SYSTEM_BOOTING) - cpu_mark_primary_thread(cpu, apicid); -} - -static __init void cpu_set_boot_apic(void) -{ - cpuid_to_apicid[0] =3D boot_cpu_physical_apicid; - cpu_update_apic(0, boot_cpu_physical_apicid); - x86_32_probe_bigsmp_early(); -} - -int generic_processor_info(int apicid) -{ - int cpu, max =3D nr_cpu_ids; - - /* The boot CPU must be set before MADT/MPTABLE parsing happens */ - if (cpuid_to_apicid[0] =3D=3D BAD_APICID) - panic("Boot CPU APIC not registered yet\n"); - - if (apicid =3D=3D boot_cpu_physical_apicid) - return 0; - - if (disabled_cpu_apicid =3D=3D apicid) { - int thiscpu =3D num_processors + disabled_cpus; - - pr_warn("APIC: Disabling requested cpu. Processor %d/0x%x ignored.\n", - thiscpu, apicid); - - disabled_cpus++; - return -ENODEV; - } - - if (num_processors >=3D nr_cpu_ids) { - int thiscpu =3D max + disabled_cpus; - - pr_warn("APIC: NR_CPUS/possible_cpus limit of %i reached. " - "Processor %d/0x%x ignored.\n", max, thiscpu, apicid); - - disabled_cpus++; - return -EINVAL; - } - - cpu =3D allocate_logical_cpuid(apicid); - if (cpu < 0) { - disabled_cpus++; - return -EINVAL; - } - - cpu_update_apic(cpu, apicid); - return cpu; -} - - void __irq_msi_compose_msg(struct irq_cfg *cfg, struct msi_msg *msg, bool dmar) { @@ -2828,15 +2656,6 @@ static int __init lapic_insert_resource( */ late_initcall(lapic_insert_resource); =20 -static int __init apic_set_disabled_cpu_apicid(char *arg) -{ - if (!arg || !get_option(&arg, &disabled_cpu_apicid)) - return -EINVAL; - - return 0; -} -early_param("disable_cpu_apicid", apic_set_disabled_cpu_apicid); - static int __init apic_set_extnmi(char *arg) { if (!arg) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -26,14 +26,16 @@ obj-y +=3D bugs.o obj-y +=3D aperfmperf.o obj-y +=3D cpuid-deps.o obj-y +=3D umwait.o +obj-y +=3D capflags.o powerflags.o =20 -obj-$(CONFIG_PROC_FS) +=3D proc.o -obj-y +=3D capflags.o powerflags.o +obj-$(CONFIG_X86_LOCAL_APIC) +=3D topology.o =20 -obj-$(CONFIG_IA32_FEAT_CTL) +=3D feat_ctl.o +obj-$(CONFIG_PROC_FS) +=3D proc.o + +obj-$(CONFIG_IA32_FEAT_CTL) +=3D feat_ctl.o ifdef CONFIG_CPU_SUP_INTEL -obj-y +=3D intel.o intel_pconfig.o tsx.o -obj-$(CONFIG_PM) +=3D intel_epb.o +obj-y +=3D intel.o intel_pconfig.o tsx.o +obj-$(CONFIG_PM) +=3D intel_epb.o endif obj-$(CONFIG_CPU_SUP_AMD) +=3D amd.o obj-$(CONFIG_CPU_SUP_HYGON) +=3D hygon.o --- /dev/null +++ b/arch/x86/kernel/cpu/topology.c @@ -0,0 +1,184 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include + +#include + +#include +#include +#include + +/* + * Map cpu index to physical APIC ID + */ +DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_apicid, BAD_APICID); +DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid, CPU_ACPIID_INVALI= D); +EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid); +EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_acpiid); + +/* Bitmap of physically present CPUs. */ +DECLARE_BITMAP(phys_cpu_present_map, MAX_LOCAL_APIC) __read_mostly; + +/* Used for CPU number allocation and parallel CPU bringup */ +u32 cpuid_to_apicid[] __read_mostly =3D { [0 ... NR_CPUS - 1] =3D BAD_APIC= ID, }; + +/* + * Processor to be disabled specified by kernel parameter + * disable_cpu_apicid=3D, mostly used for the kdump 2nd kernel to + * avoid undefined behaviour caused by sending INIT from AP to BSP. + */ +static u32 disabled_cpu_apicid __ro_after_init =3D BAD_APICID; + +unsigned int num_processors; +unsigned disabled_cpus; + +/* + * The number of allocated logical CPU IDs. Since logical CPU IDs are allo= cated + * contiguously, it equals to current allocated max logical CPU ID plus 1. + * All allocated CPU IDs should be in the [0, nr_logical_cpuids) range, + * so the maximum of nr_logical_cpuids is nr_cpu_ids. + * + * NOTE: Reserve 0 for BSP. + */ +static int nr_logical_cpuids =3D 1; + +bool arch_match_cpu_phys_id(int cpu, u64 phys_id) +{ + return phys_id =3D=3D (u64)cpuid_to_apicid[cpu]; +} + +#ifdef CONFIG_SMP +static void cpu_mark_primary_thread(unsigned int cpu, unsigned int apicid) +{ + /* Isolate the SMT bit(s) in the APICID and check for 0 */ + u32 mask =3D (1U << (fls(smp_num_siblings) - 1)) - 1; + + if (smp_num_siblings =3D=3D 1 || !(apicid & mask)) + cpumask_set_cpu(cpu, &__cpu_primary_thread_mask); +} + +/* + * Due to the utter mess of CPUID evaluation smp_num_siblings is not valid + * during early boot. Initialize the primary thread mask before SMP + * bringup. + */ +static int __init smp_init_primary_thread_mask(void) +{ + 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 =3D 0; cpu < nr_logical_cpuids; cpu++) + cpu_mark_primary_thread(cpu, cpuid_to_apicid[cpu]); + return 0; +} +early_initcall(smp_init_primary_thread_mask); +#else +static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int = apicid) { } +#endif + +/* + * Should use this API to allocate logical CPU IDs to keep nr_logical_cpui= ds + * and cpuid_to_apicid[] synchronized. + */ +static int allocate_logical_cpuid(int apicid) +{ + int i; + + /* + * cpuid <-> apicid mapping is persistent, so when a cpu is up, + * check if the kernel has allocated a cpuid for it. + */ + for (i =3D 0; i < nr_logical_cpuids; i++) { + if (cpuid_to_apicid[i] =3D=3D apicid) + return i; + } + + /* Allocate a new cpuid. */ + if (nr_logical_cpuids >=3D nr_cpu_ids) { + WARN_ONCE(1, "APIC: NR_CPUS/possible_cpus limit of %u reached. " + "Processor %d/0x%x and the rest are ignored.\n", + nr_cpu_ids, nr_logical_cpuids, apicid); + return -EINVAL; + } + + cpuid_to_apicid[nr_logical_cpuids] =3D apicid; + return nr_logical_cpuids++; +} + +static void cpu_update_apic(int cpu, u32 apicid) +{ +#if defined(CONFIG_SMP) || defined(CONFIG_X86_64) + early_per_cpu(x86_cpu_to_apicid, cpu) =3D apicid; +#endif + set_cpu_possible(cpu, true); + set_bit(apicid, phys_cpu_present_map); + set_cpu_present(cpu, true); + num_processors++; + + if (system_state !=3D SYSTEM_BOOTING) + cpu_mark_primary_thread(cpu, apicid); +} + +void __init topology_register_boot_apic(u32 apic_id) +{ + cpuid_to_apicid[0] =3D apic_id; + cpu_update_apic(0, apic_id); +} + +int generic_processor_info(int apicid) +{ + int cpu, max =3D nr_cpu_ids; + + /* The boot CPU must be set before MADT/MPTABLE parsing happens */ + if (cpuid_to_apicid[0] =3D=3D BAD_APICID) + panic("Boot CPU APIC not registered yet\n"); + + if (apicid =3D=3D boot_cpu_physical_apicid) + return 0; + + if (disabled_cpu_apicid =3D=3D apicid) { + int thiscpu =3D num_processors + disabled_cpus; + + pr_warn("APIC: Disabling requested cpu. Processor %d/0x%x ignored.\n", + thiscpu, apicid); + + disabled_cpus++; + return -ENODEV; + } + + if (num_processors >=3D nr_cpu_ids) { + int thiscpu =3D max + disabled_cpus; + + pr_warn("APIC: NR_CPUS/possible_cpus limit of %i reached. " + "Processor %d/0x%x ignored.\n", max, thiscpu, apicid); + + disabled_cpus++; + return -EINVAL; + } + + cpu =3D allocate_logical_cpuid(apicid); + if (cpu < 0) { + disabled_cpus++; + return -EINVAL; + } + + cpu_update_apic(cpu, apicid); + return cpu; +} + +static int __init apic_set_disabled_cpu_apicid(char *arg) +{ + if (!arg || !get_option(&arg, &disabled_cpu_apicid)) + return -EINVAL; + + return 0; +} +early_param("disable_cpu_apicid", apic_set_disabled_cpu_apicid); From nobody Fri Dec 19 02:50:56 2025 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 1D8F46168B for ; Tue, 23 Jan 2024 13:10:54 +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=1706015456; cv=none; b=lg89C2zvLK69n31ioTNJ7InojezWT5GpInNiBjYxdf1q9vcyHxp7LCt1BBy4c27YfA/wJ+rat4I4ZPb4R1M+agqXZTZZzzn5ibr5ieog6zRRNobrpFG8SmINrsYoMdo8ec6hWsD0PFRjiHdV4Nv7i49Ikz/7lczLCGm8Fn6w/MU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015456; c=relaxed/simple; bh=A6DRTtYolM0nxyqcZ/KT0BAawXUk3qAODO455OFbZPI=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=tQk4S/Z9MC6FPqQfK/Ce2laGrnVaHtEX6pgjC/9lQtlF5ooeZGrEZ03jmwEdU946MrsttW5+9M5YXYhp+unNCD/e2Sm/KqiVmpf4aS/p4l/BB601N9DyeNwTeDhG++yZPP/VxJ0r1bm33vLMcUHqG3IfTu/2uhbxQ1ZWpd+FgiE= 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=ySL+U1nZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=m/kXnXlc; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ySL+U1nZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="m/kXnXlc" Message-ID: <20240118123648.663415387@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015453; 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=VhgEhXRzZ2arG5ALV1ivGA8kAeYK0sQE/cl9vrjuqJo=; b=ySL+U1nZ3n4UeNsfDzhEtMIaoDIdADkBisarGWQxnluqfB/jLJN2TpOFAILJ6MtI+1EmBA MVqtFmJLLiedbo2Nhtku+tNEqMHO0x9siZm+eYM2Lggp+Ssg+wbmMaBwhMVCItoqKDAGVA sLVNezQxFy44k2hQ9Xq34P5DY1TNDRhnodotUT5wIKSdwOQfM405FRBO3GA9DcXOdvulxx wZS5O5oHjXjDhJYoIw4giYGkN/tIXmAMBobhlmGWZB6ViOdYdF0zUkylYKIWMRdG9dZLT3 bZ0tbvWYCFSUajuL4wEI3KnNLI4ylw3+VsYAhwEp9S9Dh8Tq7v6tZW7MM8J7Kw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015453; 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=VhgEhXRzZ2arG5ALV1ivGA8kAeYK0sQE/cl9vrjuqJo=; b=m/kXnXlctEnP1vZKB/ro8rRsdv6Y8oB8PWZXg7KgBzNDeGIYgTiVEasVZ0cbvkL0zZe26Z a5tHqp5cOGz2yADw== 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 02/30] x86/cpu/topology: Provide separate APIC registration functions 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 Date: Tue, 23 Jan 2024 14:10:52 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner generic_processor_info() aside of being a complete misnomer is used for both early boot registration and ACPI CPU hotplug. While it's arguable that this can share some code, it results in code which is hard to understand and kept around post init for no real reason. Also the call sites do lots of manual fiddling in topology related variables instead of having proper interfaces for the purpose which handle the topology internals correctly. Provide topology_register_apic(), topology_hotplug_apic() and topology_hotunplug_apic() which have the extra magic of the call sites incorporated and for now are wrappers around generic_processor_info(). Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/apic.h | 3 + arch/x86/kernel/cpu/topology.c | 113 ++++++++++++++++++++++++++++++++++--= ----- 2 files changed, 98 insertions(+), 18 deletions(-) --- --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -171,7 +171,10 @@ extern bool apic_needs_pit(void); =20 extern void apic_send_IPI_allbutself(unsigned int vector); =20 +extern void topology_register_apic(u32 apic_id, u32 acpi_id, bool present); extern void topology_register_boot_apic(u32 apic_id); +extern int topology_hotplug_apic(u32 apic_id, u32 acpi_id); +extern void topology_hotunplug_apic(unsigned int cpu); =20 #else /* !CONFIG_X86_LOCAL_APIC */ static inline void lapic_shutdown(void) { } --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -84,32 +84,38 @@ early_initcall(smp_init_primary_thread_m static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int = apicid) { } #endif =20 -/* - * Should use this API to allocate logical CPU IDs to keep nr_logical_cpui= ds - * and cpuid_to_apicid[] synchronized. - */ -static int allocate_logical_cpuid(int apicid) +static int topo_lookup_cpuid(u32 apic_id) { int i; =20 - /* - * cpuid <-> apicid mapping is persistent, so when a cpu is up, - * check if the kernel has allocated a cpuid for it. - */ + /* CPU# to APICID mapping is persistent once it is established */ for (i =3D 0; i < nr_logical_cpuids; i++) { - if (cpuid_to_apicid[i] =3D=3D apicid) + if (cpuid_to_apicid[i] =3D=3D apic_id) return i; } + return -ENODEV; +} + +/* + * Should use this API to allocate logical CPU IDs to keep nr_logical_cpui= ds + * and cpuid_to_apicid[] synchronized. + */ +static int allocate_logical_cpuid(u32 apic_id) +{ + int cpu =3D topo_lookup_cpuid(apic_id); + + if (cpu >=3D 0) + return cpu; =20 /* Allocate a new cpuid. */ if (nr_logical_cpuids >=3D nr_cpu_ids) { WARN_ONCE(1, "APIC: NR_CPUS/possible_cpus limit of %u reached. " "Processor %d/0x%x and the rest are ignored.\n", - nr_cpu_ids, nr_logical_cpuids, apicid); + nr_cpu_ids, nr_logical_cpuids, apic_id); return -EINVAL; } =20 - cpuid_to_apicid[nr_logical_cpuids] =3D apicid; + cpuid_to_apicid[nr_logical_cpuids] =3D apic_id; return nr_logical_cpuids++; } =20 @@ -127,12 +133,6 @@ static void cpu_update_apic(int cpu, u32 cpu_mark_primary_thread(cpu, apicid); } =20 -void __init topology_register_boot_apic(u32 apic_id) -{ - cpuid_to_apicid[0] =3D apic_id; - cpu_update_apic(0, apic_id); -} - int generic_processor_info(int apicid) { int cpu, max =3D nr_cpu_ids; @@ -174,6 +174,83 @@ int generic_processor_info(int apicid) return cpu; } =20 +/** + * topology_register_apic - Register an APIC in early topology maps + * @apic_id: The APIC ID to set up + * @acpi_id: The ACPI ID associated to the APIC + * @present: True if the corresponding CPU is present + */ +void __init topology_register_apic(u32 apic_id, u32 acpi_id, bool present) +{ + int cpu; + + if (apic_id >=3D MAX_LOCAL_APIC) { + pr_err_once("APIC ID %x exceeds kernel limit of: %x\n", apic_id, MAX_LOC= AL_APIC - 1); + return; + } + + if (!present) { + disabled_cpus++; + return; + } + + cpu =3D generic_processor_info(apic_id); + if (cpu >=3D 0) + early_per_cpu(x86_cpu_to_acpiid, cpu) =3D acpi_id; +} + +/** + * topology_register_boot_apic - Register the boot CPU APIC + * @apic_id: The APIC ID to set up + * + * Separate so CPU #0 can be assigned + */ +void __init topology_register_boot_apic(u32 apic_id) +{ + cpuid_to_apicid[0] =3D apic_id; + cpu_update_apic(0, apic_id); +} + +#ifdef CONFIG_ACPI_HOTPLUG_CPU +/** + * topology_hotplug_apic - Handle a physical hotplugged APIC after boot + * @apic_id: The APIC ID to set up + * @acpi_id: The ACPI ID associated to the APIC + */ +int topology_hotplug_apic(u32 apic_id, u32 acpi_id) +{ + int cpu; + + if (apic_id >=3D MAX_LOCAL_APIC) + return -EINVAL; + + cpu =3D topo_lookup_cpuid(apic_id); + if (cpu < 0) { + cpu =3D generic_processor_info(apic_id); + if (cpu >=3D 0) + per_cpu(x86_cpu_to_acpiid, cpu) =3D acpi_id; + } + return cpu; +} + +/** + * topology_hotunplug_apic - Remove a physical hotplugged APIC after boot + * @cpu: The CPU number for which the APIC ID is removed + */ +void topology_hotunplug_apic(unsigned int cpu) +{ + u32 apic_id =3D cpuid_to_apicid[cpu]; + + if (apic_id =3D=3D BAD_APICID) + return; + + per_cpu(x86_cpu_to_apicid, cpu) =3D BAD_APICID; + clear_bit(apic_id, phys_cpu_present_map); + set_cpu_present(cpu, false); + num_processors--; +} +#endif + static int __init apic_set_disabled_cpu_apicid(char *arg) { if (!arg || !get_option(&arg, &disabled_cpu_apicid)) From nobody Fri Dec 19 02:50:56 2025 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 47EE661694 for ; Tue, 23 Jan 2024 13:10: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=1706015457; cv=none; b=LYTMiH8PSevRQqWXTFp6miARbXvCSehxsblnXbcoCu/yowrxV7ujNKGlAiCffKWB592KBKeL87bgljMTusFD1JVQga5gVEBQ29JsewY2/2VsFHOC1EM+v0NL07D3Tt9wr2iM9UoGrZKr3nJszmKlnA4cpVdB2ZWTh9FY3nuCBc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015457; c=relaxed/simple; bh=PwaE2HACFCDykj/yrcUgOvhSX8G9pW7cBDNkwdCX7Zs=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=rKwDH5+lYTA1EMs9Zyhl4tk3anmexaViC7yyB+caX52GPt4HkyfQkJZXopiTceNVpN3QgB4JsYBlawJArGorL4qTELWUPp4l35FtDZ9u0rRQ2o9fmZntO/B1lgF59PQCktE9GTo2voP20QPc9XdEMP5NYXQnLPY87rS6W4uIOk0= 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=kxDs/roc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XjfiEL4S; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kxDs/roc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XjfiEL4S" Message-ID: <20240118123648.722879332@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015454; 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=u90NYRT/ZphVmVk3QeLAx65kqZq+Kn/J4FFlTTjOKYY=; b=kxDs/rocR0TOrKjLmasrpQ+VJegqjYOGjvJ2NmtacOW/fuGynZWyCQDiv5YvZDIpWh0osa zrCb2cx/lO9ZJWtPapNA1yiqnxNhbuBehpoBJDd8M44IgZQEFk02wlYfxfGz3F37hUoafe kXQXkpGitGE4PSWGy1ftW4GNV0RIzN9sV4ywChVahLAFYoGQD3WD9MlCf+anjyj34h4ow1 ICCNWRf1UEgoZsp7VVnkgdEMFuAGvWjeyBZC9phJf92tl4GY3EX8mvP9M3l0YnLJKXEiU0 qnPy6gBq392UFp0zDthhZUMz+eP3eZNErtswHm/m+qvAhBfoT3lBAKXvUCgabA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015454; 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=u90NYRT/ZphVmVk3QeLAx65kqZq+Kn/J4FFlTTjOKYY=; b=XjfiEL4SILgkYyJFEDNYXY95Bykqjalwo2YJ8aWpBkvhT1DcN2PONkttEvnB8DvtsiIG2I 7tl5zgxFrk/Ax5BQ== 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 03/30] x86/acpi: Use new APIC registration functions 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 Date: Tue, 23 Jan 2024 14:10:53 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Use the new topology registration functions and make the early boot code path __init. No functional change intended. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/acpi/boot.c | 44 +++++++--------------------------------= ----- 1 file changed, 7 insertions(+), 37 deletions(-) --- --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -164,33 +164,9 @@ static int __init acpi_parse_madt(struct return 0; } =20 -/** - * acpi_register_lapic - register a local apic and generates a logic cpu n= umber - * @id: local apic id to register - * @acpiid: ACPI id to register - * @enabled: this cpu is enabled or not - * - * Returns the logic cpu number which maps to the local apic - */ -static int acpi_register_lapic(int id, u32 acpiid, u8 enabled) +static __init void acpi_register_lapic(u32 apic_id, u32 acpi_id, bool pres= ent) { - int cpu; - - if (id >=3D MAX_LOCAL_APIC) { - pr_info("skipped apicid that is too big\n"); - return -EINVAL; - } - - if (!enabled) { - ++disabled_cpus; - return -EINVAL; - } - - cpu =3D generic_processor_info(id); - if (cpu >=3D 0) - early_per_cpu(x86_cpu_to_acpiid, cpu) =3D acpiid; - - return cpu; + topology_register_apic(apic_id, acpi_id, present); } =20 static bool __init acpi_is_processor_usable(u32 lapic_flags) @@ -844,12 +820,10 @@ static int acpi_map_cpu2node(acpi_handle return 0; } =20 -int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id, - int *pcpu) +int acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id, int= *pcpu) { - int cpu; + int cpu =3D topology_hotplug_apic(physid, acpi_id); =20 - cpu =3D acpi_register_lapic(physid, acpi_id, ACPI_MADT_ENABLED); if (cpu < 0) { pr_info("Unable to map lapic to logical cpu number\n"); return cpu; @@ -868,15 +842,11 @@ int acpi_unmap_cpu(int cpu) #ifdef CONFIG_ACPI_NUMA set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE); #endif - - per_cpu(x86_cpu_to_apicid, cpu) =3D BAD_APICID; - set_cpu_present(cpu, false); - num_processors--; - - return (0); + topology_hotunplug_apic(cpu); + return 0; } EXPORT_SYMBOL(acpi_unmap_cpu); -#endif /* CONFIG_ACPI_HOTPLUG_CPU */ +#endif /* CONFIG_ACPI_HOTPLUG_CPU */ =20 int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base) { From nobody Fri Dec 19 02:50:56 2025 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 E2164627F9 for ; Tue, 23 Jan 2024 13:10:57 +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=1706015459; cv=none; b=rv2Bce7HItH8Um4cPDcA46DsDEZt+AOO3UYi9ulDTWgZhZWB8+JbQZ89wYQ0mTxK3eRO5vs/dENaPGYqoFIo2jAvDttE9Nj3DofdYICffOS25OjsvnIcCNutHorYIpVevlEm371Nqs2A/gM6gYBVVHH+LipHoDQn0XXPbQAGiPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015459; c=relaxed/simple; bh=1BKSN1DKRpFuwYrUk2DSp5Ep6fmfjgFGAglqD62w0Us=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=oeknV7zIyhSBiAo/gdbS9UIlPEq4oFaHtoMAT9eaZwIkcP5GItCaPMGglMplXlewN0y1z/8mdkNSUM3NdNF7gEfKr6neweTcKlOMGpM/Y7gUDjQnLGzme2MvyXGZNBIa0q0If15NQCZPEOHJAZr+7dhT1ogPso4aaP8X/8Le0ro= 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=S6BedB4S; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ffwbn9mF; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="S6BedB4S"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ffwbn9mF" Message-ID: <20240118123648.779871266@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015456; 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=18yKEKGde+iVcK/8qscP13axTMaC1pWtYv9SEapVNnI=; b=S6BedB4Sx/6S6Fx5tiCeHsd0n63UmsC4InGxj7OE4CEGf4cH5a+3PkzHoUhrhjGbU6i5PU 0uD5NcvBNROJaQ17WRy4y4PkzllAjGJ06X2AqYYxdsXV6lpNJoxWSAY6VuGdnCX0OxdHJx GFfpGbuwlV06XTLsH3NjIYZCOBXnQDIUlNaucielEAHYmOic1w61bWzMk+StjnCfE8hSsd FZD54XgoPOV5AwV8oIe1YaAX2OWJeDCjD5NlSsFyAmtkteMg6GncuVx3VS5Ath7PwTAWtT rR67j+OsLliC2HCRT9UCzMWMGmXtYM2bbh4g1LUu6dDaNKokNsuZN2Ngl6PbUQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015456; 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=18yKEKGde+iVcK/8qscP13axTMaC1pWtYv9SEapVNnI=; b=ffwbn9mFlIdhoKuy5jcPYwrAQeirwQoirahpTYtilZiq2ChtwDGkL0aRv5jwKX8kU3Exw0 a3Iw5RYM64CQH9Ag== 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 04/30] x86/jailhouse: Use new APIC registration function 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 Date: Tue, 23 Jan 2024 14:10:55 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner No functional change intended. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/jailhouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- --- a/arch/x86/kernel/jailhouse.c +++ b/arch/x86/kernel/jailhouse.c @@ -102,7 +102,7 @@ static void __init jailhouse_parse_smp_c register_lapic_address(0xfee00000); =20 for (cpu =3D 0; cpu < setup_data.v1.num_cpus; cpu++) - generic_processor_info(setup_data.v1.cpu_ids[cpu]); + topology_register_apic(setup_data.v1.cpu_ids[cpu], CPU_ACPIID_INVALID, t= rue); =20 smp_found_config =3D 1; From nobody Fri Dec 19 02:50:56 2025 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 6F8DD5F579 for ; Tue, 23 Jan 2024 13:10:59 +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=1706015460; cv=none; b=aWR1WqpV7t3biIsjs0QF2vFKdlDU/e0Md8NaXHvJzYP7sqUhtFLnkf+ZowJQzWr4Du6bnKD/cYvtIm/BtsSb4Pa1gf8dtVUFtIs0JF1sM6bsSgwuvHNbbpGP+u5Y0aXO0jRepyfhvqyHoq7DMImHPtOEERFaaF1DR54s0Rtjp7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015460; c=relaxed/simple; bh=/BwHRCS+CLYxiYrDKtOabx9ENMJKOBslstVgo9aIw54=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=I23T36+R1qQ12Ur9uh9zxPfJ2cJoDorRVTpKkjsxvEJYDwKTlHNt1Osp7c8ZtNCRiwd/FnkhHCtIQ+RjcS6o2a6WDgpqBs7QszvgL7Ei3z8YD4R787aUXbVZvgdFU69MPzQn1lXxrDU/c0j+21WSTwutZFzK3qZPwTg0BvQglmQ= 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=LMBN3aBi; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gsT/JbH9; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LMBN3aBi"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gsT/JbH9" Message-ID: <20240118123648.836545448@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015457; 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=maxs2TKeF/0tW1+HW118Yxp9IM/22p0xUJceBYRgAg4=; b=LMBN3aBiuZo4PBUyhOaxBa2YMXeATFlTnIUt/cPWyzWwbVBFRiHVpOvyi1ek3uVgUlPT4T sbNRsLnk18wM18+vA3RrRrX704ijm89Mhvyd0An/O4M5eyCRGb6B4jrBjfho8IPHXz3PUJ /htwzTWhON+bqccDFQf81DapQoBer5EiqiRt6wrfhTddirwzqKonzbSDVYhSHS1YiWwLOl 2luTkCMGk1vdfCbQYTU7vma4p9PCpgwCQMEoqQXHBxILp4fUubrBvDW8DyD1tGeAI+CidF LgC5NsQ7gyeIIFvnusgwAlNZIY9q3rOtql2FmQCrKb72MLXxgU+ZxT/fxJHHYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015457; 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=maxs2TKeF/0tW1+HW118Yxp9IM/22p0xUJceBYRgAg4=; b=gsT/JbH9NyAPlfh05SdzLxjOxHXoce7DHybt8Aexrs3MkN5f3kOgxsBen+5i8C72T6bsI4 3kaYdQatGRUz6uAQ== 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 05/30] x86/of: Use new APIC registration functions 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 Date: Tue, 23 Jan 2024 14:10:57 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner No functional change intended. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/devicetree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- --- a/arch/x86/kernel/devicetree.c +++ b/arch/x86/kernel/devicetree.c @@ -136,7 +136,7 @@ static void __init dtb_cpu_setup(void) pr_warn("%pOF: missing local APIC ID\n", dn); continue; } - generic_processor_info(apic_id); + topology_register_apic(apic_id, CPU_ACPIID_INVALID, true); } } From nobody Fri Dec 19 02:50:56 2025 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 46BCC62A05 for ; Tue, 23 Jan 2024 13:11:01 +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=1706015463; cv=none; b=EDluDqXpGk6P1GNZDOkJCmo937EmUvi5hK8dXwN3yrL2JWEV0ndEW+qG1jOty3UxdbavojAnsoWslfrjsl1HS9uJB1qoziFjiK1xxfT/5o4VXl5cMfV1PWXcHie6GwixHSUVgq+uMLt8L7AMPe99uO/RrRLzBHYIV9X5TRhb0AA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015463; c=relaxed/simple; bh=1w/o7YVIWiDXvAdCfShv+rwlB99SYN+vDUkSBlSoNGg=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=rc6X/oj0e6taTrfaCX7QRHmmNkJADihp461E4mxnxYAQaVdNrqmNEngpXQVTFYg4ERIRHUjOaeFTWlrRT6L2AmKpiC9qTQzkUrQUGrUQFcLVjCYA3y3u2dON5n9xrrlHwWM9maGnGiQaXKgHRp94zKTVvrniaOSNOku2ir+4hgU= 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=KB9ghnAb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HaL3lWct; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KB9ghnAb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HaL3lWct" Message-ID: <20240118123648.892104721@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015459; 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=Uc7KzIR0wfn9fEJS+nF/aoHz/Ptcj21sdxZ0GDH72RI=; b=KB9ghnAbVHu6c0rULM5mVI87g5j9NdUf9C/SeASe67VOCa4IC7lfpw+i7eD5jCHsk1UYEA f2yRbsWtqoBy5N8xGxJD/eU9AGobY5cfndJXvEDHQIw8sAFx9AJbdaLE2kUk41m1ksRwQS /01IkP+1gYYxb0AVK7UGoYJjoeFj7twG0eZ4zsoLhhNsff4Jd0hzpcA7uh8TUNlmpA8c+r vbPVChXl49M03mkLxDEokkFvacXaZzj1APVPo8djbGEP1AE7IC53pakMMeoPvb4fk7Q/M8 XKd6wp5vf256TQz/pE/5E0WnVXpVZ3IFxQcAAumYQf4tiHnW0FybzKTCVy/uYA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015459; 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=Uc7KzIR0wfn9fEJS+nF/aoHz/Ptcj21sdxZ0GDH72RI=; b=HaL3lWct14EJ7o5vNDntKZzxkdA9qICGd2XKSNAma8Izsux2JjR8/DV1WY2et7uY4zopIN a/gQO3+bd8/6n6BQ== 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 06/30] x86/mpparse: Use new APIC registration function 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 Date: Tue, 23 Jan 2024 14:10:58 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Aside of switching over to the new interface, record the number of registered CPUs locally, which allows to make num_processors and disabled_cpus confined to the topology code. No functional change intended. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/mpspec.h | 2 -- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/mpparse.c | 17 +++++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) --- --- a/arch/x86/include/asm/mpspec.h +++ b/arch/x86/include/asm/mpspec.h @@ -61,8 +61,6 @@ static inline void e820__memblock_alloc_ #define mpparse_parse_smp_config x86_init_noop #endif =20 -int generic_processor_info(int apicid); - extern DECLARE_BITMAP(phys_cpu_present_map, MAX_LOCAL_APIC); =20 static inline void reset_phys_cpu_present_map(u32 apicid) --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -133,7 +133,7 @@ static void cpu_update_apic(int cpu, u32 cpu_mark_primary_thread(cpu, apicid); } =20 -int generic_processor_info(int apicid) +static int generic_processor_info(int apicid) { int cpu, max =3D nr_cpu_ids; =20 --- a/arch/x86/kernel/mpparse.c +++ b/arch/x86/kernel/mpparse.c @@ -36,6 +36,8 @@ * Checksum an MP configuration block. */ =20 +static unsigned int num_procs __initdata; + static int __init mpf_checksum(unsigned char *mp, int len) { int sum =3D 0; @@ -50,16 +52,15 @@ static void __init MP_processor_info(str { char *bootup_cpu =3D ""; =20 - if (!(m->cpuflag & CPU_ENABLED)) { - disabled_cpus++; + topology_register_apic(m->apicid, CPU_ACPIID_INVALID, m->cpuflag & CPU_EN= ABLED); + if (!(m->cpuflag & CPU_ENABLED)) return; - } =20 if (m->cpuflag & CPU_BOOTPROCESSOR) bootup_cpu =3D " (Bootup-CPU)"; =20 pr_info("Processor #%d%s\n", m->apicid, bootup_cpu); - generic_processor_info(m->apicid); + num_procs++; } =20 #ifdef CONFIG_X86_IO_APIC @@ -236,9 +237,9 @@ static int __init smp_read_mpc(struct mp } } =20 - if (!num_processors) + if (!num_procs && !acpi_lapic) pr_err("MPTABLE: no processors registered!\n"); - return num_processors; + return num_procs || acpi_lapic; } =20 #ifdef CONFIG_X86_IO_APIC @@ -529,8 +530,8 @@ static __init void mpparse_get_smp_confi } else BUG(); =20 - if (!early) - pr_info("Processors: %d\n", num_processors); + if (!early && !acpi_lapic) + pr_info("Processors: %d\n", num_procs); /* * Only use the first configuration found. */ From nobody Fri Dec 19 02:50:56 2025 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 4CAD262A19 for ; Tue, 23 Jan 2024 13:11: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=1706015464; cv=none; b=CXb5bV4nM6FiG+6vH+DZ9czgZBvYPmCXwigrgFLzkF72n4/ynRwA84MZcrBVURyogqtpATzPIm2efN1XQ4z96d//eItD7SV/w3i9UVMnPLQgbqdsekVvAorc8tPDbkH1pzi6jSmagbtDood9oPvsTeQqjeziyrntvh+aZ40gXOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015464; c=relaxed/simple; bh=sbC882hJWb/fNP4Yqsgrkp1IVTrtRgBvpz6ApXdOtig=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=ZBQo9fy/QJkFiTRhw/L2hOk5TZLE7FJVl+rwDSEJ4jKjqSr9Q2ZIx9Z/wRAVkxNVwxHcC+zhUNGutSi3NqU6PwfguA2cCwtpcQ+DFQ/lure3RxnqPhEbd6l4lKbLVSQe1lDfVP4XAXLAQwj8ze45bCqdyD23psz7neZxiC1Tinw= 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=d5BtuxLH; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/yLqH3ew; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="d5BtuxLH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/yLqH3ew" Message-ID: <20240118123648.948521234@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015461; 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=pLIvwy/vIOrYDLB+6HqyysBkTudlRmJDSmXo9JtDbRA=; b=d5BtuxLHl8fI+oemgL6BYKbt8SbxrCKUlc2z1cLl9nz1ptdMeTs/nYItoQms2MavzetvoZ YulaZd88wEsXSMU6cwNL6lZ7Udue4dLYVm+/Wx4olhaXg9E+XsO7k9Mn9q8AdwFzRUDdIT ch7+3aaiYp3jg16P2cJpdvaRbL7M5nHbd3UH1lcPKzKhAdBKh9wQehHhKCH1i10H7JdD/J hmYZdA8DVDXgi8TSPgDkIdoTTfXQoYq+jfcvTkhbPITKNrDQU1dO1cNW9WCv8nUpibic7V jM8j/S/GYNMHDZynWxWRxQMxQ7Oy7W5gw2BxCN877eYa3updOVDnNcy+92aQhQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015461; 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=pLIvwy/vIOrYDLB+6HqyysBkTudlRmJDSmXo9JtDbRA=; b=/yLqH3ewRAOkciIivfvbfhmtiQxfotNM2ssRiZOyt2tDnW5wbERoofQZ49tDamCDA7uv6B vSBHr7fUwOWjjrDg== 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 07/30] x86/acpi: Dont invoke topology_register_apic() for XEN PV 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 Date: Tue, 23 Jan 2024 14:11:00 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The MADT table for XEN/PV dom0 is not really useful and registering the APICs is momentarily a pointless exercise because XENPV does not use an APIC at all. It overrides the x86_init.mpparse.parse_smp_config() callback, resets num_processors and counts how many of them are provided by the hypervisor. This is in the way of cleaning up the APIC registration. Prevent MADT registration for XEN/PV temporarily until the rework is completed and XEN/PV can use the MADT again. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/acpi/boot.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -23,6 +23,8 @@ #include #include =20 +#include + #include #include #include @@ -166,7 +168,8 @@ static int __init acpi_parse_madt(struct =20 static __init void acpi_register_lapic(u32 apic_id, u32 acpi_id, bool pres= ent) { - topology_register_apic(apic_id, acpi_id, present); + if (!xen_pv_domain()) + topology_register_apic(apic_id, acpi_id, present); } =20 static bool __init acpi_is_processor_usable(u32 lapic_flags) @@ -1087,7 +1090,8 @@ static int __init early_acpi_parse_madt_ return count; } =20 - register_lapic_address(acpi_lapic_addr); + if (!xen_pv_domain()) + register_lapic_address(acpi_lapic_addr); =20 return count; } From nobody Fri Dec 19 02:50:56 2025 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 6BCE063124 for ; Tue, 23 Jan 2024 13:11:05 +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=1706015466; cv=none; b=aH5s9VsKg6SZxTSw7fzYzpFqDdnNxOHjeaXF/Pef9+StTYUMIDHGO6dR9IC+b9STG2mY5WGAUtLMT67V2pVx3pMQfBgGHQO4C93riZk8h4LwWLsF+R8pFHo4Na27HAgaixD6A4uVmt/9amrT69yENqKRIinT2upezQNEa6cEuWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015466; c=relaxed/simple; bh=2wV7ykerxk1/jQA/W/5bsZ8RwfdIrkcxyTy4F0//EiM=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=buYwDVoxjXEtxAREpmJZoVhshId50eWgtaZ2BBBl2bsD5EEl6rBmpVQ9SUxEDsOcG8gZEKObWfgTptGRXdH3xbh7E4l12Z5cONty/eA7nImH+RIlKQJa4Ate8qFO1pkjDuKR+uWv5vi4Eib6MKCFuCcp3D2MY2Ap+9iEiKZuU54= 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=vZ9RCMwl; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=scjIdNdh; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vZ9RCMwl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="scjIdNdh" Message-ID: <20240118123649.004729855@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015463; 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=kMpbD1VU1nu86eLTMCHECRFHSSIbIijtpAP8E+y+cAc=; b=vZ9RCMwlv2xR3Su3DwRWadenZREgrkyTjimh+GLRXeVelaPiZSHdvc7g49JNPqXvM+oQk/ 4bd1nRqM+orgW8DE67VCxGFqc6SHdb20ZGv1rXXGFKRWi9BgsOg/mY2vinHX2BnjxTdLRD 0zuCVKQlgU5ToOesDNfkYZE6t/i8ircClAMC5heSiEWogZ18/USs0h/yxV3Do+QDlY93OZ oio9cvWri8ihyNmzXZPAm7QYndpiCYnChU2D+AsJXIBPWGNb7aSMG4ZGg0XAVBMGVjI595 DB0nhmJkL8r7U+icqsETrxAPJlsR1yOE5CqEzwZ53uh/XR1nHHEkj7Urfm10xA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015463; 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=kMpbD1VU1nu86eLTMCHECRFHSSIbIijtpAP8E+y+cAc=; b=scjIdNdhyTN0nIAf8DAJEiprw5v7CK0zkgP8+4nx91HKkGkLRMHNTJEe3XyJFYatmx2IcH PDD5e/zcs0EcaqBg== 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 08/30] x86/xen/smp_pv: Register fake APICs 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 Date: Tue, 23 Jan 2024 14:11:02 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner XENPV does not use the APIC. It's just piggy packing on the infrastructure and fiddles with global variables as it sees fit. These global variables are going away, so let XENPV register pseudo APIC IDs to keep the accounting correct and keep up the illusion that XEN/PV is something sane. Signed-off-by: Thomas Gleixner --- arch/x86/xen/smp_pv.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) --- --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -29,6 +29,7 @@ #include #include #include +#include #include =20 #include @@ -150,34 +151,16 @@ int xen_smp_intr_init_pv(unsigned int cp =20 static void __init xen_pv_smp_config(void) { - int i, rc; - unsigned int subtract =3D 0; + u32 apicid =3D 0; + int i; =20 - num_processors =3D 0; - disabled_cpus =3D 0; - for (i =3D 0; i < nr_cpu_ids; i++) { - rc =3D HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL); - if (rc >=3D 0) { - num_processors++; - set_cpu_possible(i, true); - } else { - set_cpu_possible(i, false); - set_cpu_present(i, false); - subtract++; - } + topology_register_boot_apic(apicid++); + + for (i =3D 1; i < nr_cpu_ids; i++) { + if (HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL) < 0) + break; + topology_register_apic(apicid++, CPU_ACPIID_INVALID, true); } -#ifdef CONFIG_HOTPLUG_CPU - /* This is akin to using 'nr_cpus' on the Linux command line. - * Which is OK as when we use 'dom0_max_vcpus=3DX' we can only - * have up to X, while nr_cpu_ids is greater than X. This - * normally is not a problem, except when CPU hotplugging - * is involved and then there might be more than X CPUs - * in the guest - which will not work as there is no - * hypercall to expand the max number of VCPUs an already - * running guest has. So cap it up to X. */ - if (subtract) - set_nr_cpu_ids(nr_cpu_ids - subtract); -#endif /* Pretend to be a proper enumerated system */ smp_found_config =3D 1; } From nobody Fri Dec 19 02:50:56 2025 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 1F7D2633EA for ; Tue, 23 Jan 2024 13:11:06 +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=1706015468; cv=none; b=ZyEjbfNs+WCHcolXZw0hLDX8y67WHnZIKk9K5OgSg4QJ7M1Hpc60Kp9qBSc4CZM1BQIeU+8XbNV1msQQS3RYGiqZcI5RbqAZ9Zh9NRqWait/seJdH34V3Hvfu/il2nclh1F7ukzuT3YJooQYu0+vuUWHrYEiM7yoTXkpiy6bGs0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015468; c=relaxed/simple; bh=XBmMDfZ0gz2+VnrQJ9myM2OfczhLs81dGTuYtvW/uC0=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=nOwvAikGXpZZyrFifXCjDNA8csKuM5X1z6WKZ6KRR2fq4h/2AcHC2Qb17YviYPiEOiMXWEFA9UZPPUl/eLWtuj/V1mo4TRPPVrx6wIY/C14VD+U/lOU5Sy6DDk0qyGm8CgMNwXrqo7LIJKtAVTRN8kxhJfc0WaJRghHES++HoSM= 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=fem8r3jZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4aAwjwRh; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fem8r3jZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4aAwjwRh" Message-ID: <20240118123649.060808881@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015465; 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=TTj/Kz9C0JKUULVztd5kGPjD2rrtKpaEznufq9qVeRw=; b=fem8r3jZdpIU2irArkJuEdoK6c00kWvNfcj98kNu8vDgQUFt3U7nMu+/Y0zTt+zw4ws6iF tRESMqKpDkbPJfA4epYGd8riY5T3S02RVGNlu0xuq4RaiWKYYv6YTegY1mX90sTzkf0Wgo TivkN3KkTlPrsCdig3yCuzq1IZKJJLcPN9VyMmmz05+FOPQavWQKxq+vKolqQTk4bl91l7 8mN0GzCO6GPVdRIHpNv19VuO2TDtkYf5LSAb7ho+Rsdq6Amn8i89y05u+hNzVs0j0allRh Tdy9+vtKRZ4tJUSoGpP3zTD0TKDxQaUVZmd088bkK9CORpi6qD4X9pDKRBu70w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015465; 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=TTj/Kz9C0JKUULVztd5kGPjD2rrtKpaEznufq9qVeRw=; b=4aAwjwRhigkMn8/qA7i7OnsVchgdSkTn7ICM+7IWFl42FYWdjcIKxnTcR02X5FTa0huoKN fKFBY6zHYcTKBfAg== 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 09/30] x86/cpu/topology: Confine topology information 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 Date: Tue, 23 Jan 2024 14:11:04 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Now that all external fiddling with num_processors and disabled_cpus is gone, move the last user prefill_possible_map() into the topology code too and remove the global visibility of these variables. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/smp.h | 3 - arch/x86/kernel/apic/apic.c | 1=20 arch/x86/kernel/cpu/topology.c | 76 ++++++++++++++++++++++++++++++++++++= +++-- arch/x86/kernel/smpboot.c | 72 ------------------------------------= -- 4 files changed, 74 insertions(+), 78 deletions(-) --- --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -9,7 +9,6 @@ #include =20 extern int smp_num_siblings; -extern unsigned int num_processors; =20 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map); @@ -174,8 +173,6 @@ static inline struct cpumask *cpu_llc_sh } #endif /* CONFIG_SMP */ =20 -extern unsigned disabled_cpus; - #ifdef CONFIG_DEBUG_NMI_SELFTEST extern void nmi_selftest(void); #else --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -2054,7 +2054,6 @@ void __init init_apic_mappings(void) pr_info("APIC: disable apic facility\n"); apic_disable(); } - num_processors =3D 1; } } =20 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -29,8 +29,8 @@ u32 cpuid_to_apicid[] __read_mostly =3D { */ static u32 disabled_cpu_apicid __ro_after_init =3D BAD_APICID; =20 -unsigned int num_processors; -unsigned disabled_cpus; +static unsigned int num_processors; +static unsigned int disabled_cpus; =20 /* * The number of allocated logical CPU IDs. Since logical CPU IDs are allo= cated @@ -174,6 +174,71 @@ static int generic_processor_info(int ap return cpu; } =20 +static int __initdata setup_possible_cpus =3D -1; + +/* + * cpu_possible_mask should be static, it cannot change as cpu's + * are onlined, or offlined. The reason is per-cpu data-structures + * are allocated by some modules at init time, and don't expect to + * do this dynamically on cpu arrival/departure. + * cpu_present_mask on the other hand can change dynamically. + * In case when cpu_hotplug is not compiled, then we resort to current + * behaviour, which is cpu_possible =3D=3D cpu_present. + * - Ashok Raj + * + * Three ways to find out the number of additional hotplug CPUs: + * - If the BIOS specified disabled CPUs in ACPI/mptables use that. + * - The user can overwrite it with possible_cpus=3DNUM + * - Otherwise don't reserve additional CPUs. + * We do this because additional CPUs waste a lot of memory. + * -AK + */ +__init void prefill_possible_map(void) +{ + int i, possible; + + i =3D setup_max_cpus ?: 1; + if (setup_possible_cpus =3D=3D -1) { + possible =3D num_processors; +#ifdef CONFIG_HOTPLUG_CPU + if (setup_max_cpus) + possible +=3D disabled_cpus; +#else + if (possible > i) + possible =3D i; +#endif + } else + possible =3D setup_possible_cpus; + + total_cpus =3D max_t(int, possible, num_processors + disabled_cpus); + + /* nr_cpu_ids could be reduced via nr_cpus=3D */ + if (possible > nr_cpu_ids) { + pr_warn("%d Processors exceeds NR_CPUS limit of %u\n", + possible, nr_cpu_ids); + possible =3D nr_cpu_ids; + } + +#ifdef CONFIG_HOTPLUG_CPU + if (!setup_max_cpus) +#endif + if (possible > i) { + pr_warn("%d Processors exceeds max_cpus limit of %u\n", + possible, setup_max_cpus); + possible =3D i; + } + + set_nr_cpu_ids(possible); + + pr_info("Allowing %d CPUs, %d hotplug CPUs\n", + possible, max_t(int, possible - num_processors, 0)); + + reset_cpu_possible_mask(); + + for (i =3D 0; i < possible; i++) + set_cpu_possible(i, true); +} + /** * topology_register_apic - Register an APIC in early topology maps * @apic_id: The APIC ID to set up @@ -251,6 +316,13 @@ void topology_hotunplug_apic(unsigned in } #endif =20 +static int __init _setup_possible_cpus(char *str) +{ + get_option(&str, &setup_possible_cpus); + return 0; +} +early_param("possible_cpus", _setup_possible_cpus); + static int __init apic_set_disabled_cpu_apicid(char *arg) { if (!arg || !get_option(&arg, &disabled_cpu_apicid)) --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1291,78 +1291,6 @@ void __init native_smp_cpus_done(unsigne cache_aps_init(); } =20 -static int __initdata setup_possible_cpus =3D -1; -static int __init _setup_possible_cpus(char *str) -{ - get_option(&str, &setup_possible_cpus); - return 0; -} -early_param("possible_cpus", _setup_possible_cpus); - - -/* - * cpu_possible_mask should be static, it cannot change as cpu's - * are onlined, or offlined. The reason is per-cpu data-structures - * are allocated by some modules at init time, and don't expect to - * do this dynamically on cpu arrival/departure. - * cpu_present_mask on the other hand can change dynamically. - * In case when cpu_hotplug is not compiled, then we resort to current - * behaviour, which is cpu_possible =3D=3D cpu_present. - * - Ashok Raj - * - * Three ways to find out the number of additional hotplug CPUs: - * - If the BIOS specified disabled CPUs in ACPI/mptables use that. - * - The user can overwrite it with possible_cpus=3DNUM - * - Otherwise don't reserve additional CPUs. - * We do this because additional CPUs waste a lot of memory. - * -AK - */ -__init void prefill_possible_map(void) -{ - int i, possible; - - i =3D setup_max_cpus ?: 1; - if (setup_possible_cpus =3D=3D -1) { - possible =3D num_processors; -#ifdef CONFIG_HOTPLUG_CPU - if (setup_max_cpus) - possible +=3D disabled_cpus; -#else - if (possible > i) - possible =3D i; -#endif - } else - possible =3D setup_possible_cpus; - - total_cpus =3D max_t(int, possible, num_processors + disabled_cpus); - - /* nr_cpu_ids could be reduced via nr_cpus=3D */ - if (possible > nr_cpu_ids) { - pr_warn("%d Processors exceeds NR_CPUS limit of %u\n", - possible, nr_cpu_ids); - possible =3D nr_cpu_ids; - } - -#ifdef CONFIG_HOTPLUG_CPU - if (!setup_max_cpus) -#endif - if (possible > i) { - pr_warn("%d Processors exceeds max_cpus limit of %u\n", - possible, setup_max_cpus); - possible =3D i; - } - - set_nr_cpu_ids(possible); - - pr_info("Allowing %d CPUs, %d hotplug CPUs\n", - possible, max_t(int, possible - num_processors, 0)); - - reset_cpu_possible_mask(); - - for (i =3D 0; i < possible; i++) - set_cpu_possible(i, true); -} - /* correctly size the local cpu masks */ void __init setup_cpu_local_masks(void) { From nobody Fri Dec 19 02:50:56 2025 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 944CC63401 for ; Tue, 23 Jan 2024 13:11:08 +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=1706015470; cv=none; b=PwDNvZTqVKjbvxJlwEK8cvvGSECUOE8uStrX5HdYAEDmShvCrZPJ1ktssKb+gbnm4/kdmYG5yo1ABQ66hN7GLtHxnlVvogntabvEtE3/YAV2LJLDe2n70Gvs/GGu4QeUr6GeY4y3H3OegP+gr1KJcYRYbsn8qshtrPgXRScW0So= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015470; c=relaxed/simple; bh=phOYHJ76E4I6vwQrTIgrpWe8GD2hxqhRgGaMg8x5m2E=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=K7F6/7M5Le8u4+vA2YHUw1Mw0ZyQm8VOEVBJvPi/bb0taoNEuw8jaPkBOt+MQDGVQvbUNPIWbbsz7i20drY/dUuFOq4Ys0wtjh4VcBtOiU5+7Hmgnxp1MLhlwHRHp4sOOg6Zcnm52qXSadddMH9mDCU/7HUyxwsAPu3swZ8FULI= 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=MszRmXb2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IQQ0pc+Q; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MszRmXb2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IQQ0pc+Q" Message-ID: <20240118123649.118318548@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015467; 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=qx32kyDtRKstD9WHlYmov4Q45bwh6UDL0oPjSY28LYw=; b=MszRmXb2yTQVziYuG8JrgerlYF09g2fVHQl0X/7OGYsjdT3eK8qh8oLxl91oNJgndOx16J slBH1q/Z4YaUR4GpNoXmheORA2tKxxFRhwTxbH4zc3dNo1d+72R/i27k6gkSjUdrPW8vrV R70tTywAwgAXvAOmXfhRffAuehIaZUU+6dqQ2opt0Ey7nweYlvJPxjKxTmbYMbSCHF7lZ2 YC2gSpfajVhnUb7BTBMo9eBjX0/e1fUIJmXqWifTYceiYkRhujv0qUXNQQz2fv3JrijfrD KYuJXiRUa6ydO8n4w2OzUqbIJnlZiJ3c5+arNvS9KxWsYn3pH59TE/uzopFvfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015467; 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=qx32kyDtRKstD9WHlYmov4Q45bwh6UDL0oPjSY28LYw=; b=IQQ0pc+Qie5mK9Dtosi7LQmXLIblUEKS8N2BtexgzhEnCpYrBvzfscrGWbaRJfyOwcs+et mwo5XspV5ATNU7Cg== 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 10/30] x86/cpu/topology: Simplify APIC registration 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 Date: Tue, 23 Jan 2024 14:11:06 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Having the same check whether the number of assigned CPUs has reached the nr_cpu_ids limit twice in the same code path is pointless. Repeating the information that CPUs are ignored over and over is also pointless noise. Remove the redundant check and reduce the noise by using a pr_warn_once(). Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -107,14 +107,6 @@ static int allocate_logical_cpuid(u32 ap if (cpu >=3D 0) return cpu; =20 - /* Allocate a new cpuid. */ - if (nr_logical_cpuids >=3D nr_cpu_ids) { - WARN_ONCE(1, "APIC: NR_CPUS/possible_cpus limit of %u reached. " - "Processor %d/0x%x and the rest are ignored.\n", - nr_cpu_ids, nr_logical_cpuids, apic_id); - return -EINVAL; - } - cpuid_to_apicid[nr_logical_cpuids] =3D apic_id; return nr_logical_cpuids++; } @@ -135,7 +127,7 @@ static void cpu_update_apic(int cpu, u32 =20 static int generic_processor_info(int apicid) { - int cpu, max =3D nr_cpu_ids; + int cpu; =20 /* The boot CPU must be set before MADT/MPTABLE parsing happens */ if (cpuid_to_apicid[0] =3D=3D BAD_APICID) @@ -155,21 +147,12 @@ static int generic_processor_info(int ap } =20 if (num_processors >=3D nr_cpu_ids) { - int thiscpu =3D max + disabled_cpus; - - pr_warn("APIC: NR_CPUS/possible_cpus limit of %i reached. " - "Processor %d/0x%x ignored.\n", max, thiscpu, apicid); - + pr_warn_once("APIC: CPU limit of %d reached. Ignoring further CPUs\n", n= r_cpu_ids); disabled_cpus++; - return -EINVAL; + return -ENOSPC; } =20 cpu =3D allocate_logical_cpuid(apicid); - if (cpu < 0) { - disabled_cpus++; - return -EINVAL; - } - cpu_update_apic(cpu, apicid); return cpu; } From nobody Fri Dec 19 02:50:56 2025 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 1863B6341D for ; Tue, 23 Jan 2024 13:11:10 +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=1706015471; cv=none; b=TB16r72hVdmTicb7TLe7zPycZcLalrqWAeYnRAFL3uKoHxeacaOmvBZ5Kt6XT1VFMs69LgWL0jZkogYT8mcSAuDv/e2Kqd/mewjHpQOB+Dy9b7IxzMEZsZWAlLs/1OW02lIMW06dFrrUbLR1m2zaQ9ybN/e+8yDTiSa8MTeg3ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015471; c=relaxed/simple; bh=FUTIECry+bQ8RFAh9yFkdIi5+DkzHs3f3p6NIjEa5cs=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=DLqZRyQ8i2SQRb0NVk2FG0IalVL0pw/mO4BCz8ENf0MDuBvKQEJQcdIYCRTnIC8JG9AB+vGr3DmqiK1fg6x2T5X+K/r3KTosNfT54FEUCBusY+Vfa3I/AwCnk5HaDxT5bEwz8ADVV51sK7Actds1tyKvp8s4yGLEJtuXYJ8x3wI= 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=LGCvFzQd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7yl43YI7; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LGCvFzQd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7yl43YI7" Message-ID: <20240118123649.174566214@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015468; 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=/3oc2ZLZMtT1GGSM+F50BJRwamFMmJoEtBLGA//oVEY=; b=LGCvFzQdipix4lYAMkP64YXKblLZ0oE1+UmXNAMOr4NQjyA1/Ef5jqXmba3WkYuCOlXYB1 dUZ7lqIRF0Gua20ldNVYUo2Nm9b4bBipmWba3Y3ZVzNqmX9QvuZaA9BkxOama3ADlh7h2O fEFQZdHKGRw+rmYTlEXJVyPEj8P72VEmAnT/Cv7nIztGbQaGJTIb6xHBA64I9FJr8w+Kl7 n/MpnIacIX5b3u95wws6JWH7Ee8y+AmO7vFFjXNe0yBKSI1AiMI1Bkq4kfA+/TDfl+7LBe YKpn5xsXAaPLSPlPamvfZPj9VARaCNALKN9/PsHSGr6wA8sG5Vbs21knCgL9cA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015468; 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=/3oc2ZLZMtT1GGSM+F50BJRwamFMmJoEtBLGA//oVEY=; b=7yl43YI79rGp6vymn3HGbqztV+AblmSSKw4IFL/BdnI0SgIWs46yXnSIZ5R+Z17GJIXbko q850XISawTCaB1Bw== 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 11/30] x86/cpu/topology: Use a data structure for topology info 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 Date: Tue, 23 Jan 2024 14:11:07 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Put the processor accounting into a data structure, which will gain more topology related information in the next steps, and sanitize the accounting. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 59 ++++++++++++++++++++----------------= ----- 1 file changed, 29 insertions(+), 30 deletions(-) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -23,25 +23,24 @@ DECLARE_BITMAP(phys_cpu_present_map, MAX u32 cpuid_to_apicid[] __read_mostly =3D { [0 ... NR_CPUS - 1] =3D BAD_APIC= ID, }; =20 /* + * Keep track of assigned, disabled and rejected CPUs. Present assigned + * with 1 as CPU #0 is reserved for the boot CPU. + */ +static struct { + unsigned int nr_assigned_cpus; + unsigned int nr_disabled_cpus; + unsigned int nr_rejected_cpus; +} topo_info __read_mostly =3D { + .nr_assigned_cpus =3D 1, +}; + +/* * Processor to be disabled specified by kernel parameter * disable_cpu_apicid=3D, mostly used for the kdump 2nd kernel to * avoid undefined behaviour caused by sending INIT from AP to BSP. */ static u32 disabled_cpu_apicid __ro_after_init =3D BAD_APICID; =20 -static unsigned int num_processors; -static unsigned int disabled_cpus; - -/* - * The number of allocated logical CPU IDs. Since logical CPU IDs are allo= cated - * contiguously, it equals to current allocated max logical CPU ID plus 1. - * All allocated CPU IDs should be in the [0, nr_logical_cpuids) range, - * so the maximum of nr_logical_cpuids is nr_cpu_ids. - * - * NOTE: Reserve 0 for BSP. - */ -static int nr_logical_cpuids =3D 1; - bool arch_match_cpu_phys_id(int cpu, u64 phys_id) { return phys_id =3D=3D (u64)cpuid_to_apicid[cpu]; @@ -75,7 +74,7 @@ static int __init smp_init_primary_threa return 0; } =20 - for (cpu =3D 0; cpu < nr_logical_cpuids; cpu++) + for (cpu =3D 0; cpu < topo_info.nr_assigned_cpus; cpu++) cpu_mark_primary_thread(cpu, cpuid_to_apicid[cpu]); return 0; } @@ -89,7 +88,7 @@ static int topo_lookup_cpuid(u32 apic_id int i; =20 /* CPU# to APICID mapping is persistent once it is established */ - for (i =3D 0; i < nr_logical_cpuids; i++) { + for (i =3D 0; i < topo_info.nr_assigned_cpus; i++) { if (cpuid_to_apicid[i] =3D=3D apic_id) return i; } @@ -107,22 +106,21 @@ static int allocate_logical_cpuid(u32 ap if (cpu >=3D 0) return cpu; =20 - cpuid_to_apicid[nr_logical_cpuids] =3D apic_id; - return nr_logical_cpuids++; + return topo_info.nr_assigned_cpus++; } =20 -static void cpu_update_apic(int cpu, u32 apicid) +static void cpu_update_apic(unsigned int cpu, u32 apic_id) { #if defined(CONFIG_SMP) || defined(CONFIG_X86_64) - early_per_cpu(x86_cpu_to_apicid, cpu) =3D apicid; + early_per_cpu(x86_cpu_to_apicid, cpu) =3D apic_id; #endif + cpuid_to_apicid[cpu] =3D apic_id; set_cpu_possible(cpu, true); - set_bit(apicid, phys_cpu_present_map); + set_bit(apic_id, phys_cpu_present_map); set_cpu_present(cpu, true); - num_processors++; =20 if (system_state !=3D SYSTEM_BOOTING) - cpu_mark_primary_thread(cpu, apicid); + cpu_mark_primary_thread(cpu, apic_id); } =20 static int generic_processor_info(int apicid) @@ -137,18 +135,18 @@ static int generic_processor_info(int ap return 0; =20 if (disabled_cpu_apicid =3D=3D apicid) { - int thiscpu =3D num_processors + disabled_cpus; + int thiscpu =3D topo_info.nr_assigned_cpus + topo_info.nr_disabled_cpus; =20 pr_warn("APIC: Disabling requested cpu. Processor %d/0x%x ignored.\n", thiscpu, apicid); =20 - disabled_cpus++; + topo_info.nr_rejected_cpus++; return -ENODEV; } =20 - if (num_processors >=3D nr_cpu_ids) { + if (topo_info.nr_assigned_cpus >=3D nr_cpu_ids) { pr_warn_once("APIC: CPU limit of %d reached. Ignoring further CPUs\n", n= r_cpu_ids); - disabled_cpus++; + topo_info.nr_rejected_cpus++; return -ENOSPC; } =20 @@ -178,14 +176,16 @@ static int __initdata setup_possible_cpu */ __init void prefill_possible_map(void) { + unsigned int num_processors =3D topo_info.nr_assigned_cpus; + unsigned int disabled_cpus =3D topo_info.nr_disabled_cpus; int i, possible; =20 i =3D setup_max_cpus ?: 1; if (setup_possible_cpus =3D=3D -1) { - possible =3D num_processors; + possible =3D topo_info.nr_assigned_cpus; #ifdef CONFIG_HOTPLUG_CPU if (setup_max_cpus) - possible +=3D disabled_cpus; + possible +=3D num_processors; #else if (possible > i) possible =3D i; @@ -238,7 +238,7 @@ void __init topology_register_apic(u32 a } =20 if (!present) { - disabled_cpus++; + topo_info.nr_disabled_cpus++; return; } =20 @@ -295,7 +295,6 @@ void topology_hotunplug_apic(unsigned in per_cpu(x86_cpu_to_apicid, cpu) =3D BAD_APICID; clear_bit(apic_id, phys_cpu_present_map); set_cpu_present(cpu, false); - num_processors--; } #endif From nobody Fri Dec 19 02:50:56 2025 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 D59C3634FF for ; Tue, 23 Jan 2024 13:11:11 +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=1706015473; cv=none; b=T3pOWgYxmUbwOx5bJTqVgMtS7sUUxyaoisO/Ad9abZz/uMbiHADez1y8NBw3q6KF4RuhMTMi/J9PqAruh2X+I5Z+ijLTf5KFpWBHB7vwCiyZan0Nt38fLgp2UoR6iVJOdMzo/SG8zMy3BlJwmMrOSx6U0SZRv5ykyBIsw8lYcb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015473; c=relaxed/simple; bh=pTvuAnJJThSlgdgEbCQMraBnOPSI6z92HQWugFcBTWk=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=UlbPxV/r0Sgd/z23w6P+aId1s7ZR1KyBjJxnKgCi68OCkL9Y2MpgCz2D4L1t2Fb92xoBhfb2q4CTh60kpb0LZX4LfgHVNgQbsGee23S5qbXPdUEBTnM2dNYVZtySAZm2cOCk+AVTXDE5x8av2qtgkRqg8iDFQqOGVciVX+FZxrY= 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=vvBKomLL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wB07tUSJ; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vvBKomLL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wB07tUSJ" Message-ID: <20240118123649.231006046@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015470; 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=li4w2vdbyISE1XfrgLq8xoZs22npIVzG+ptbhVSgJdk=; b=vvBKomLLfP2ncIAAPY0Uj+Fd2PF7YFwzolmwW5SqFon861etYQk7Q1HEFK4+yZTqG0gIfa qLnlKHAQMgq/dXUnQSETbznYaVfzVwcdHgKv9vu5szCG9xGJFkDXvwdfDlrO6HKpP5Mvm6 FhQpQgNa5H845wDnFGl/Xte/WntpyFPkQ0+jsFPKCY9wR5Zc5jMFepyKJDVdWcleKgFzFt ZLw7QXTeIAC/jfIRym57ZfeOKaitQP8YwAyVZrEozX7y5A8gFOelQ8Buv76Xk+ezFi0z+D 6x14djNEqsqrPG0IisfALnoQtrMQtvp7SLuPqKdg1VGviLg7ITJw+SxxhTj25w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015470; 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=li4w2vdbyISE1XfrgLq8xoZs22npIVzG+ptbhVSgJdk=; b=wB07tUSJTGuD4NOPu+UBxyj2kfMtYyV1o9X9Pr0LMXrlzuPtJEoqZM6gw7eRhux67geJ9R yUhubWVnjW45MAAg== 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 12/30] x86/smpboot: Make error message actually useful 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 Date: Tue, 23 Jan 2024 14:11:09 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner "smpboot: native_kick_ap: bad cpu 33" is absolutely useless information. Replace it with something meaningful which allows to decode the failure condition. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/smpboot.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1072,9 +1072,13 @@ int native_kick_ap(unsigned int cpu, str =20 pr_debug("++++++++++++++++++++=3D_---CPU UP %u\n", cpu); =20 - if (apicid =3D=3D BAD_APICID || !test_bit(apicid, phys_cpu_present_map) || - !apic_id_valid(apicid)) { - pr_err("%s: bad cpu %d\n", __func__, cpu); + if (apicid =3D=3D BAD_APICID || !apic_id_valid(apicid)) { + pr_err("CPU %u has invalid APIC ID %x. Aborting bringup\n", cpu, apicid); + return -EINVAL; + } + + if (!test_bit(apicid, phys_cpu_present_map)) { + pr_err("CPU %u APIC ID %x is not present. Aborting bringup\n", cpu, apic= id); return -EINVAL; } From nobody Fri Dec 19 02:50:56 2025 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 976F35FB88 for ; Tue, 23 Jan 2024 13:11:13 +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=1706015475; cv=none; b=i3bteHFBAtOn6Z931l7iKObgkG0QgiCgc8Y5lg4GBkmrlbRCZ7HYkc++q/5pEIROZFGGorSgTI4K05UfpiW00PEhCa7M9+cqzU1ogp4Es/FEdUSQ9TeoTVf4j3mXstBNGACkn0OIqPhSOlvYAarvLJ/y2VZEbZxLUNpgTDvJAmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015475; c=relaxed/simple; bh=wnrsINmLR+LY+VkLruv5uhfAC/mCv21ArAmJxh4gDa8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=nc0KZRajUSwucPThOtdhECYHTIV86UnvjvonzaHS+WLxAoTTMPFxlQ8CzZRXkDIrzMX7O2lH2qsftAg7uhNc4ptbVUBW3D2EcUP16JOm3c8eGF9Fk4+AIgurAGwQJKcrOM/ao7MoPmSzOVtoJvSvMqaBS8p4uhMyVCLrptTp9kU= 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=UGYIsjwz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9+Kjv5uP; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UGYIsjwz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9+Kjv5uP" Message-ID: <20240118123649.287143098@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015472; 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=4JRDe/V227lnSowfg1qZVmiYTNeEvNK8Z2s6JWMeTBE=; b=UGYIsjwzRkrzbQ//xiJu31ZvmHqmlzu/UOvSDcdlcOdwoqAKhnQ33Z6iM4oFCpFDQ95Gbc vup7xJV345SKfpNXgKIHwOC6OINO5tWrirCmDRqBASNm9dvSnzPCWhiFCAqHcw+/8u5a4F nr/LTGkV4FJXXmv1fBJVTQBV0oijM3TSFLZi+gemd/zUBLOpatJTAHCXySu9ZDYf346d5c gdgBzuprvk+AZ3/dc3C3F4ngJ+yablDC+MbdKjtX2C+URLeTxNbEKIx6Zzg6nHRwEI9BzF XpK3Nqgn0EOh7jZ8lmrL88NKJm02WBaDRRZ/Q/5L/9M9wDe/amxcYNuFIrqS0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015472; 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=4JRDe/V227lnSowfg1qZVmiYTNeEvNK8Z2s6JWMeTBE=; b=9+Kjv5uPWtRINcrHi/ni5j8f83ccWoCyLO91ni8NQoWt9KlFHQtDrh4JvxZpLgD6MZmE/O gwhz3FgT6et/2cBg== 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 13/30] x86/cpu/topology: Sanitize the APIC admission logic 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 Date: Tue, 23 Jan 2024 14:11:10 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Move the actually required content of generic_processor_id() into the call sites and use common helper functions for them. This separates the early boot registration and the ACPI hotplug mechanism completely which allows further cleanups and improvements. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 160 +++++++++++++++++++-----------------= ----- 1 file changed, 78 insertions(+), 82 deletions(-) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -30,8 +30,10 @@ static struct { unsigned int nr_assigned_cpus; unsigned int nr_disabled_cpus; unsigned int nr_rejected_cpus; + u32 boot_cpu_apic_id; } topo_info __read_mostly =3D { .nr_assigned_cpus =3D 1, + .boot_cpu_apic_id =3D BAD_APICID, }; =20 /* @@ -83,78 +85,6 @@ early_initcall(smp_init_primary_thread_m static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int = apicid) { } #endif =20 -static int topo_lookup_cpuid(u32 apic_id) -{ - int i; - - /* CPU# to APICID mapping is persistent once it is established */ - for (i =3D 0; i < topo_info.nr_assigned_cpus; i++) { - if (cpuid_to_apicid[i] =3D=3D apic_id) - return i; - } - return -ENODEV; -} - -/* - * Should use this API to allocate logical CPU IDs to keep nr_logical_cpui= ds - * and cpuid_to_apicid[] synchronized. - */ -static int allocate_logical_cpuid(u32 apic_id) -{ - int cpu =3D topo_lookup_cpuid(apic_id); - - if (cpu >=3D 0) - return cpu; - - return topo_info.nr_assigned_cpus++; -} - -static void cpu_update_apic(unsigned int cpu, u32 apic_id) -{ -#if defined(CONFIG_SMP) || defined(CONFIG_X86_64) - early_per_cpu(x86_cpu_to_apicid, cpu) =3D apic_id; -#endif - cpuid_to_apicid[cpu] =3D apic_id; - set_cpu_possible(cpu, true); - set_bit(apic_id, phys_cpu_present_map); - set_cpu_present(cpu, true); - - if (system_state !=3D SYSTEM_BOOTING) - cpu_mark_primary_thread(cpu, apic_id); -} - -static int generic_processor_info(int apicid) -{ - int cpu; - - /* The boot CPU must be set before MADT/MPTABLE parsing happens */ - if (cpuid_to_apicid[0] =3D=3D BAD_APICID) - panic("Boot CPU APIC not registered yet\n"); - - if (apicid =3D=3D boot_cpu_physical_apicid) - return 0; - - if (disabled_cpu_apicid =3D=3D apicid) { - int thiscpu =3D topo_info.nr_assigned_cpus + topo_info.nr_disabled_cpus; - - pr_warn("APIC: Disabling requested cpu. Processor %d/0x%x ignored.\n", - thiscpu, apicid); - - topo_info.nr_rejected_cpus++; - return -ENODEV; - } - - if (topo_info.nr_assigned_cpus >=3D nr_cpu_ids) { - pr_warn_once("APIC: CPU limit of %d reached. Ignoring further CPUs\n", n= r_cpu_ids); - topo_info.nr_rejected_cpus++; - return -ENOSPC; - } - - cpu =3D allocate_logical_cpuid(apicid); - cpu_update_apic(cpu, apicid); - return cpu; -} - static int __initdata setup_possible_cpus =3D -1; =20 /* @@ -222,6 +152,43 @@ static int __initdata setup_possible_cpu set_cpu_possible(i, true); } =20 +static int topo_lookup_cpuid(u32 apic_id) +{ + int i; + + /* CPU# to APICID mapping is persistent once it is established */ + for (i =3D 0; i < topo_info.nr_assigned_cpus; i++) { + if (cpuid_to_apicid[i] =3D=3D apic_id) + return i; + } + return -ENODEV; +} + +static int topo_assign_cpunr(u32 apic_id) +{ + int cpu =3D topo_lookup_cpuid(apic_id); + + if (cpu >=3D 0) + return cpu; + + return topo_info.nr_assigned_cpus++; +} + +static void topo_set_cpuids(unsigned int cpu, u32 apic_id, u32 acpi_id) +{ +#if defined(CONFIG_SMP) || defined(CONFIG_X86_64) + early_per_cpu(x86_cpu_to_apicid, cpu) =3D apic_id; + early_per_cpu(x86_cpu_to_acpiid, cpu) =3D acpi_id; +#endif + cpuid_to_apicid[cpu] =3D apic_id; + + set_cpu_possible(cpu, true); + set_cpu_present(cpu, true); + + if (system_state !=3D SYSTEM_BOOTING) + cpu_mark_primary_thread(cpu, apic_id); +} + /** * topology_register_apic - Register an APIC in early topology maps * @apic_id: The APIC ID to set up @@ -234,17 +201,41 @@ void __init topology_register_apic(u32 a =20 if (apic_id >=3D MAX_LOCAL_APIC) { pr_err_once("APIC ID %x exceeds kernel limit of: %x\n", apic_id, MAX_LOC= AL_APIC - 1); + topo_info.nr_rejected_cpus++; return; } =20 - if (!present) { - topo_info.nr_disabled_cpus++; + /* CPU numbers exhausted? */ + if (topo_info.nr_assigned_cpus >=3D nr_cpu_ids) { + pr_warn_once("CPU limit of %d reached. Ignoring further CPUs\n", nr_cpu_= ids); + topo_info.nr_rejected_cpus++; return; } =20 - cpu =3D generic_processor_info(apic_id); - if (cpu >=3D 0) - early_per_cpu(x86_cpu_to_acpiid, cpu) =3D acpi_id; + if (disabled_cpu_apicid =3D=3D apic_id) { + pr_info("Disabling CPU as requested via 'disable_cpu_apicid=3D0x%x'.\n",= apic_id); + topo_info.nr_rejected_cpus++; + return; + } + + if (present) { + /* + * Prevent double registration, which is valid in case of + * the boot CPU APIC because that is registered before the + * enumeration of the APICs via firmware parsers or VM + * guest mechanisms. + */ + if (test_and_set_bit(apic_id, phys_cpu_present_map)) + return; + + if (apic_id =3D=3D topo_info.boot_cpu_apic_id) + cpu =3D 0; + else + cpu =3D topo_assign_cpunr(apic_id); + topo_set_cpuids(cpu, apic_id, acpi_id); + } else { + topo_info.nr_disabled_cpus++; + } } =20 /** @@ -255,8 +246,10 @@ void __init topology_register_apic(u32 a */ void __init topology_register_boot_apic(u32 apic_id) { - cpuid_to_apicid[0] =3D apic_id; - cpu_update_apic(0, apic_id); + WARN_ON_ONCE(topo_info.boot_cpu_apic_id !=3D BAD_APICID); + + topo_info.boot_cpu_apic_id =3D apic_id; + topology_register_apic(apic_id, CPU_ACPIID_INVALID, true); } =20 #ifdef CONFIG_ACPI_HOTPLUG_CPU @@ -274,10 +267,13 @@ int topology_hotplug_apic(u32 apic_id, u =20 cpu =3D topo_lookup_cpuid(apic_id); if (cpu < 0) { - cpu =3D generic_processor_info(apic_id); - if (cpu >=3D 0) - per_cpu(x86_cpu_to_acpiid, cpu) =3D acpi_id; + if (topo_info.nr_assigned_cpus >=3D nr_cpu_ids) + return -ENOSPC; + + cpu =3D topo_assign_cpunr(apic_id); } + set_bit(apic_id, phys_cpu_present_map); + topo_set_cpuids(cpu, apic_id, acpi_id); return cpu; } From nobody Fri Dec 19 02:50:56 2025 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 50FD9634F5 for ; Tue, 23 Jan 2024 13:11:15 +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=1706015477; cv=none; b=Vi/LuSv1rO8Hssrbb5M7mPwSrsAUf3PdnQFdEIGb178o8ziOwnspirrq+LJcmN2fEUSVFI+s9d1xpzEhT9D+gOT5jIZEwM2y8vx41MJTaBKoLgEtCr8AdqWw41KQTbXzRwZvYORCy21flLJDnSvCx49olt0Nt6LX/5MJVIud9tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015477; c=relaxed/simple; bh=Et5xySeTZi83KYXKc2FkwJnx8O9NcYHE4U3CDywajts=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=eUM3bEWfO+kIM0nwQtDm5pKVBIQfelhOkJOm10XPaP+o9QWj5RY8YIiW0nD+oOAyjIbm0MaIx60edpXyafTPE4r4Enp//6WCkJpf50+YXmcHhMAMAhhIIe/guAWKmvn//9ieX7dTGiqb+Q5+amE4m9Tke1IKK1Rs0duNT7EMW6Q= 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=n5G0LX0y; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BJmOWZnp; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="n5G0LX0y"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BJmOWZnp" Message-ID: <20240118123649.343911720@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015473; 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=RuBXZdFRC9sP10QxOqSGogzUcdmCDoZcvEhUBHpbiVk=; b=n5G0LX0ya2BbtJMTaSqZIvTvZ/o+tbfm0JnItxf1o9cnj2/2S+P3x0rgk7C4e0y98uFfqB CwsOKAK469xK/cIKQOYBJKcOn7tXnn950KUcrkklGpVRL591uG6hB5CRNvyeDIst0M056u IqLTeWZf7A/vMxJnQDLetwRLaLJO292o+FlNrJcYrB7sMaYKC17qmJ9exdSx+kj7e1RG40 ydqA9BsamCcWyqOguwpw82CQXN2FMAEfBlHITCCXKHjyTOmVc/lRVS3GYIT52RsKbvZuZP oCyqyHX/NSg0niFzEpOTicVV9lj3C6ca/FdBUeawoJuiERRVETIDLsHvLAe1Bw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015473; 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=RuBXZdFRC9sP10QxOqSGogzUcdmCDoZcvEhUBHpbiVk=; b=BJmOWZnpbD4YXaWo8JG5g/F+rHt1LJceZfvrWuGTmx2GkRp7uUXZyRECiArqRbgpdjBV5E 8bB0t3tx4qEnMVDA== 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 14/30] x86/cpu/topology: Rework possible CPU management 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 Date: Tue, 23 Jan 2024 14:11:12 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Managing possible CPUs is an unreadable and uncomprehensible maze. Aside of that it's backwards because it applies command line limits after registering all APICs. Rewrite it so that it: - Applies the command line limits upfront so that only the allowed amount of APIC IDs can be registered. - Applies eventual late restrictions in an understandable way - Uses simple min_t() calculations which are trivial to follow. - Provides a separate function for resetting to UP mode late in the bringup process. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/apic.h | 5 + arch/x86/include/asm/cpu.h | 10 -- arch/x86/include/asm/topology.h | 1=20 arch/x86/kernel/cpu/topology.c | 176 ++++++++++++++++++++++++-----------= ----- arch/x86/kernel/setup.c | 9 -- arch/x86/kernel/smpboot.c | 6 - 6 files changed, 118 insertions(+), 89 deletions(-) --- --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -175,6 +175,9 @@ extern void topology_register_apic(u32 a extern void topology_register_boot_apic(u32 apic_id); extern int topology_hotplug_apic(u32 apic_id, u32 acpi_id); extern void topology_hotunplug_apic(unsigned int cpu); +extern void topology_apply_cmdline_limits_early(void); +extern void topology_init_possible_cpus(void); +extern void topology_reset_possible_cpus_up(void); =20 #else /* !CONFIG_X86_LOCAL_APIC */ static inline void lapic_shutdown(void) { } @@ -190,6 +193,8 @@ static inline void apic_intr_mode_init(v static inline void lapic_assign_system_vectors(void) { } static inline void lapic_assign_legacy_vector(unsigned int i, bool r) { } static inline bool apic_needs_pit(void) { return true; } +static inline void topology_apply_cmdline_limits_early(void) { } +static inline void topology_init_possible_cpus(void) { } #endif /* !CONFIG_X86_LOCAL_APIC */ =20 #ifdef CONFIG_X86_X2APIC --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -9,18 +9,10 @@ #include #include =20 -#ifdef CONFIG_SMP - -extern void prefill_possible_map(void); - -#else /* CONFIG_SMP */ - -static inline void prefill_possible_map(void) {} - +#ifndef CONFIG_SMP #define cpu_physical_id(cpu) boot_cpu_physical_apicid #define cpu_acpi_id(cpu) 0 #define safe_smp_processor_id() 0 - #endif /* CONFIG_SMP */ =20 struct x86_cpu { --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -191,6 +191,7 @@ static inline bool topology_is_primary_t { return cpumask_test_cpu(cpu, cpu_primary_thread_mask); } + #else /* CONFIG_SMP */ #define topology_max_packages() (1) static inline int --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -5,6 +5,7 @@ #include =20 #include +#include #include #include =20 @@ -85,73 +86,6 @@ early_initcall(smp_init_primary_thread_m static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int = apicid) { } #endif =20 -static int __initdata setup_possible_cpus =3D -1; - -/* - * cpu_possible_mask should be static, it cannot change as cpu's - * are onlined, or offlined. The reason is per-cpu data-structures - * are allocated by some modules at init time, and don't expect to - * do this dynamically on cpu arrival/departure. - * cpu_present_mask on the other hand can change dynamically. - * In case when cpu_hotplug is not compiled, then we resort to current - * behaviour, which is cpu_possible =3D=3D cpu_present. - * - Ashok Raj - * - * Three ways to find out the number of additional hotplug CPUs: - * - If the BIOS specified disabled CPUs in ACPI/mptables use that. - * - The user can overwrite it with possible_cpus=3DNUM - * - Otherwise don't reserve additional CPUs. - * We do this because additional CPUs waste a lot of memory. - * -AK - */ -__init void prefill_possible_map(void) -{ - unsigned int num_processors =3D topo_info.nr_assigned_cpus; - unsigned int disabled_cpus =3D topo_info.nr_disabled_cpus; - int i, possible; - - i =3D setup_max_cpus ?: 1; - if (setup_possible_cpus =3D=3D -1) { - possible =3D topo_info.nr_assigned_cpus; -#ifdef CONFIG_HOTPLUG_CPU - if (setup_max_cpus) - possible +=3D num_processors; -#else - if (possible > i) - possible =3D i; -#endif - } else - possible =3D setup_possible_cpus; - - total_cpus =3D max_t(int, possible, num_processors + disabled_cpus); - - /* nr_cpu_ids could be reduced via nr_cpus=3D */ - if (possible > nr_cpu_ids) { - pr_warn("%d Processors exceeds NR_CPUS limit of %u\n", - possible, nr_cpu_ids); - possible =3D nr_cpu_ids; - } - -#ifdef CONFIG_HOTPLUG_CPU - if (!setup_max_cpus) -#endif - if (possible > i) { - pr_warn("%d Processors exceeds max_cpus limit of %u\n", - possible, setup_max_cpus); - possible =3D i; - } - - set_nr_cpu_ids(possible); - - pr_info("Allowing %d CPUs, %d hotplug CPUs\n", - possible, max_t(int, possible - num_processors, 0)); - - reset_cpu_possible_mask(); - - for (i =3D 0; i < possible; i++) - set_cpu_possible(i, true); -} - static int topo_lookup_cpuid(u32 apic_id) { int i; @@ -294,12 +228,114 @@ void topology_hotunplug_apic(unsigned in } #endif =20 -static int __init _setup_possible_cpus(char *str) +#ifdef CONFIG_SMP +static unsigned int max_possible_cpus __initdata =3D NR_CPUS; + +/** + * topology_apply_cmdline_limits_early - Apply topology command line limit= s early + * + * Ensure that command line limits are in effect before firmware parsing + * takes place. + */ +void __init topology_apply_cmdline_limits_early(void) +{ + unsigned int possible =3D nr_cpu_ids; + + /* 'maxcpus=3D0' 'nosmp' 'nolapic' 'disableapic' 'noapic' */ + if (!setup_max_cpus || ioapic_is_disabled || apic_is_disabled) + possible =3D 1; + + /* 'possible_cpus=3DN' */ + possible =3D min_t(unsigned int, max_possible_cpus, possible); + + if (possible < nr_cpu_ids) { + pr_info("Limiting to %u possible CPUs\n", possible); + set_nr_cpu_ids(possible); + } +} + +static __init bool restrict_to_up(void) +{ + if (!smp_found_config || ioapic_is_disabled) + return true; + /* + * XEN PV is special as it does not advertise the local APIC + * properly, but provides a fake topology for it so that the + * infrastructure works. So don't apply the restrictions vs. APIC + * here. + */ + if (xen_pv_domain()) + return false; + + return apic_is_disabled; +} + +void __init topology_init_possible_cpus(void) +{ + unsigned int assigned =3D topo_info.nr_assigned_cpus; + unsigned int disabled =3D topo_info.nr_disabled_cpus; + unsigned int total =3D assigned + disabled; + unsigned int cpu, allowed =3D 1; + + if (!restrict_to_up()) { + if (WARN_ON_ONCE(assigned > nr_cpu_ids)) { + disabled +=3D assigned - nr_cpu_ids; + assigned =3D nr_cpu_ids; + } + allowed =3D min_t(unsigned int, total, nr_cpu_ids); + } + + if (total > allowed) + pr_warn("%u possible CPUs exceed the limit of %u\n", total, allowed); + + assigned =3D min_t(unsigned int, allowed, assigned); + disabled =3D allowed - assigned; + + topo_info.nr_assigned_cpus =3D assigned; + topo_info.nr_disabled_cpus =3D disabled; + + total_cpus =3D allowed; + set_nr_cpu_ids(allowed); + + pr_info("Allowing %u present CPUs plus %u hotplug CPUs\n", assigned, disa= bled); + if (topo_info.nr_rejected_cpus) + pr_info("Rejected CPUs %u\n", topo_info.nr_rejected_cpus); + + init_cpu_present(cpumask_of(0)); + init_cpu_possible(cpumask_of(0)); + + for (cpu =3D 0; cpu < allowed; cpu++) { + u32 apicid =3D cpuid_to_apicid[cpu]; + + set_cpu_possible(cpu, true); + + if (apicid =3D=3D BAD_APICID) + continue; + + set_cpu_present(cpu, test_bit(apicid, phys_cpu_present_map)); + } +} + +/* + * Late SMP disable after sizing CPU masks when APIC/IOAPIC setup failed. + */ +void __init topology_reset_possible_cpus_up(void) { - get_option(&str, &setup_possible_cpus); + init_cpu_present(cpumask_of(0)); + init_cpu_possible(cpumask_of(0)); + + bitmap_zero(phys_cpu_present_map, MAX_LOCAL_APIC); + if (topo_info.boot_cpu_apic_id !=3D BAD_APICID) + set_bit(topo_info.boot_cpu_apic_id, phys_cpu_present_map); +} + +static int __init setup_possible_cpus(char *str) +{ + get_option(&str, &max_possible_cpus); return 0; } -early_param("possible_cpus", _setup_possible_cpus); +early_param("possible_cpus", setup_possible_cpus); +#endif =20 static int __init apic_set_disabled_cpu_apicid(char *arg) { --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -1129,6 +1129,8 @@ void __init setup_arch(char **cmdline_p) =20 early_quirks(); =20 + topology_apply_cmdline_limits_early(); + /* * Parse SMP configuration. Try ACPI first and then the platform * specific parser. @@ -1136,13 +1138,10 @@ void __init setup_arch(char **cmdline_p) acpi_boot_init(); x86_init.mpparse.parse_smp_cfg(); =20 - /* - * Systems w/o ACPI and mptables might not have it mapped the local - * APIC yet, but prefill_possible_map() might need to access it. - */ + /* Last opportunity to detect and map the local APIC */ init_apic_mappings(); =20 - prefill_possible_map(); + topology_init_possible_cpus(); =20 init_cpu_to_node(); init_gi_nodes(); --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1147,11 +1147,7 @@ static __init void disable_smp(void) pr_info("SMP disabled\n"); =20 disable_ioapic_support(); - - init_cpu_present(cpumask_of(0)); - init_cpu_possible(cpumask_of(0)); - - reset_phys_cpu_present_map(smp_found_config ? boot_cpu_physical_apicid : = 0); + topology_reset_possible_cpus_up(); =20 cpumask_set_cpu(0, topology_sibling_cpumask(0)); cpumask_set_cpu(0, topology_core_cpumask(0)); From nobody Fri Dec 19 02:50:56 2025 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 73C9864AAB for ; Tue, 23 Jan 2024 13:11:16 +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=1706015478; cv=none; b=EODJnAPdDARoA8gq/zggqFMfjVHLD6cvXeD7Ibiv13eiEipNVI9nd1WmARWfu0gZAxJPcXE0WbLaolJWmnfI4bN9FKtOlkzieSzoyRdosVKL7Rxvy6PAbzIO0Vjo3brtOPXrXzy7vvtbbQ1RuPvjsLufbnLY1Seeqs7C+NuAp+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015478; c=relaxed/simple; bh=S/cruE/QQLGcj32pqkqPez6jg+ROsg6v+GVfWyay5bQ=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=nQs12hok7XkLqf9H27KYM4PzEMH5PWyzqd3bIq7lXnIWIBDwVi0XChGY40YMai0aKOUJKKUCmKX8d+usScGaBwSt8HrIb2QVv3xcNKZ3AskMRO40ZXaMiZEtp9bnPKE91p8/83WgO4cjQ9F2IfRiVo3OZ4IyYiO/YQBd1MxP0e4= 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=Jtq+Cws2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cZHoE4U0; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Jtq+Cws2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cZHoE4U0" Message-ID: <20240118123649.400523172@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015475; 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=QLEwylqGwbzhYLElVBn/i/qBFw8mgtkgqBNqA7uX2R0=; b=Jtq+Cws27gkL61MWfxfl4MXJEPJjqiuIfpXkvihFthigQGCV9a1X22RUjZ9Sm6Z6nxBCGH 3Kuhvl9JPKKZ34W9+O9yEzDmb6ystSDlfZXfMIzj8THYPkqWiiWh8+tPOg37UDrubmVqrZ TaGl324f1enLaBPNA7fQxTK4lE78PJh4qoLiTiNNbC2DIZntfxddY7KgzxXicFK3YMPFLJ havJA7Wsq1QjgUoa3YcfbD3K2912qKT53ThI/SG87v3I50ou1pDb8q7xW5yHqeJ0EUZtiO vMCXQCMr0DFkGzjK/XOrvOxICrn7OlLIS0mi18BL7qiXQvZRB3DjRIYCBFhwgA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015475; 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=QLEwylqGwbzhYLElVBn/i/qBFw8mgtkgqBNqA7uX2R0=; b=cZHoE4U0oxRAtsgopS3SZg3et7SJaY3dqUQuqDZHPvsy6fSc2fDvlcOBgUrSgEl9hzOT4m evYRnpoAe7ldZdDA== 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 15/30] x86/cpu: Detect real BSP on crash kernels 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 Date: Tue, 23 Jan 2024 14:11:14 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When a kdump kernel is started from a crashing CPU then there is no guarantee that this CPU is the real boot CPU (BSP). If the kdump kernel tries to online the BSP then the INIT sequence will reset the machine. There is a command line option to prevent this, but in case of nested kdump kernels this is wrong. But that command line option is not required at all because the real BSP is enumerated as the first CPU by firmware. Support for the only known system which was different (Voyager) got removed long ago. Detect whether the boot CPU APIC ID is the first APIC ID enumerated by the firmware. If the first APIC ID enumerated is not matching the boot CPU APIC ID then skip registering it. Signed-off-by: Thomas Gleixner --- V2: Check for the first enumerated APIC ID (Rui) --- Documentation/admin-guide/kdump/kdump.rst | 7 - Documentation/admin-guide/kernel-parameters.txt | 9 -- arch/x86/kernel/cpu/topology.c | 99 ++++++++++++++-----= ----- 3 files changed, 61 insertions(+), 54 deletions(-) --- --- a/Documentation/admin-guide/kdump/kdump.rst +++ b/Documentation/admin-guide/kdump/kdump.rst @@ -191,9 +191,7 @@ Dump-capture kernel config options (Arch CPU is enough for kdump kernel to dump vmcore on most of systems. =20 However, you can also specify nr_cpus=3DX to enable multiple processors - in kdump kernel. In this case, "disable_cpu_apicid=3D" is needed to - tell kdump kernel which cpu is 1st kernel's BSP. Please refer to - admin-guide/kernel-parameters.txt for more details. + in kdump kernel. =20 With CONFIG_SMP=3Dn, the above things are not related. =20 @@ -454,8 +452,7 @@ loading dump-capture kernel. to use multi-thread programs with it, such as parallel dump feature of makedumpfile. Otherwise, the multi-thread program may have a great performance degradation. To enable multi-cpu support, you should bring u= p an - SMP dump-capture kernel and specify maxcpus/nr_cpus, disable_cpu_apicid= =3D[X] - options while loading it. + SMP dump-capture kernel and specify maxcpus/nr_cpus options while loadin= g it. =20 * For s390x there are two kdump modes: If a ELF header is specified with the elfcorehdr=3D kernel parameter, it is used by the kdump kernel as it --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1098,15 +1098,6 @@ Disable TLBIE instruction. Currently does not work with KVM, with HASH MMU, or with coherent accelerators. =20 - disable_cpu_apicid=3D [X86,APIC,SMP] - Format: - The number of initial APIC ID for the - corresponding CPU to be disabled at boot, - mostly used for the kdump 2nd kernel to - disable BSP to wake up multiple CPUs without - causing system reset or hang due to sending - INIT from AP to BSP. - disable_ddw [PPC/PSERIES] Disable Dynamic DMA Window support. Use this to workaround buggy firmware. --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -32,18 +32,13 @@ static struct { unsigned int nr_disabled_cpus; unsigned int nr_rejected_cpus; u32 boot_cpu_apic_id; + u32 real_bsp_apic_id; } topo_info __read_mostly =3D { .nr_assigned_cpus =3D 1, .boot_cpu_apic_id =3D BAD_APICID, + .real_bsp_apic_id =3D BAD_APICID, }; =20 -/* - * Processor to be disabled specified by kernel parameter - * disable_cpu_apicid=3D, mostly used for the kdump 2nd kernel to - * avoid undefined behaviour caused by sending INIT from AP to BSP. - */ -static u32 disabled_cpu_apicid __ro_after_init =3D BAD_APICID; - bool arch_match_cpu_phys_id(int cpu, u64 phys_id) { return phys_id =3D=3D (u64)cpuid_to_apicid[cpu]; @@ -123,34 +118,40 @@ static void topo_set_cpuids(unsigned int cpu_mark_primary_thread(cpu, apic_id); } =20 -/** - * topology_register_apic - Register an APIC in early topology maps - * @apic_id: The APIC ID to set up - * @acpi_id: The ACPI ID associated to the APIC - * @present: True if the corresponding CPU is present - */ -void __init topology_register_apic(u32 apic_id, u32 acpi_id, bool present) +static __init bool check_for_real_bsp(u32 apic_id) { - int cpu; + /* + * There is no real good way to detect whether this a kdump() + * kernel, but except on the Voyager SMP monstrosity which is not + * longer supported, the real BSP APIC ID is the first one which is + * enumerated by firmware. That allows to detect whether the boot + * CPU is the real BSP. If it is not, then do not register the APIC + * because sending INIT to the real BSP would reset the whole + * system. + * + * The first APIC ID which is enumerated by firmware is detectable + * because the boot CPU APIC ID is registered before that without + * invoking this code. + */ + if (topo_info.real_bsp_apic_id !=3D BAD_APICID) + return false; =20 - if (apic_id >=3D MAX_LOCAL_APIC) { - pr_err_once("APIC ID %x exceeds kernel limit of: %x\n", apic_id, MAX_LOC= AL_APIC - 1); - topo_info.nr_rejected_cpus++; - return; + if (apic_id =3D=3D topo_info.boot_cpu_apic_id) { + topo_info.real_bsp_apic_id =3D apic_id; + return false; } =20 - /* CPU numbers exhausted? */ - if (topo_info.nr_assigned_cpus >=3D nr_cpu_ids) { - pr_warn_once("CPU limit of %d reached. Ignoring further CPUs\n", nr_cpu_= ids); - topo_info.nr_rejected_cpus++; - return; - } + pr_warn("Boot CPU APIC ID not the first enumerated APIC ID: %x > %x\n", + topo_info.boot_cpu_apic_id, apic_id); + pr_warn("Crash kernel detected. Disabling real BSP to prevent machine INI= T\n"); =20 - if (disabled_cpu_apicid =3D=3D apic_id) { - pr_info("Disabling CPU as requested via 'disable_cpu_apicid=3D0x%x'.\n",= apic_id); - topo_info.nr_rejected_cpus++; - return; - } + topo_info.real_bsp_apic_id =3D apic_id; + return true; +} + +static __init void topo_register_apic(u32 apic_id, u32 acpi_id, bool prese= nt) +{ + int cpu; =20 if (present) { /* @@ -173,6 +174,33 @@ void __init topology_register_apic(u32 a } =20 /** + * topology_register_apic - Register an APIC in early topology maps + * @apic_id: The APIC ID to set up + * @acpi_id: The ACPI ID associated to the APIC + * @present: True if the corresponding CPU is present + */ +void __init topology_register_apic(u32 apic_id, u32 acpi_id, bool present) +{ + if (apic_id >=3D MAX_LOCAL_APIC) { + pr_err_once("APIC ID %x exceeds kernel limit of: %x\n", apic_id, MAX_LOC= AL_APIC - 1); + topo_info.nr_rejected_cpus++; + return; + } + + /* CPU numbers exhausted? */ + if (topo_info.nr_assigned_cpus >=3D nr_cpu_ids) { + pr_warn_once("CPU limit of %d reached. Ignoring further CPUs\n", nr_cpu_= ids); + topo_info.nr_rejected_cpus++; + return; + } + + if (check_for_real_bsp(apic_id)) + return; + + topo_register_apic(apic_id, acpi_id, present); +} + +/** * topology_register_boot_apic - Register the boot CPU APIC * @apic_id: The APIC ID to set up * @@ -183,7 +211,7 @@ void __init topology_register_boot_apic( WARN_ON_ONCE(topo_info.boot_cpu_apic_id !=3D BAD_APICID); =20 topo_info.boot_cpu_apic_id =3D apic_id; - topology_register_apic(apic_id, CPU_ACPIID_INVALID, true); + topo_register_apic(apic_id, CPU_ACPIID_INVALID, true); } =20 #ifdef CONFIG_ACPI_HOTPLUG_CPU @@ -336,12 +364,3 @@ static int __init setup_possible_cpus(ch } early_param("possible_cpus", setup_possible_cpus); #endif - -static int __init apic_set_disabled_cpu_apicid(char *arg) -{ - if (!arg || !get_option(&arg, &disabled_cpu_apicid)) - return -EINVAL; - - return 0; -} -early_param("disable_cpu_apicid", apic_set_disabled_cpu_apicid); From nobody Fri Dec 19 02:50:56 2025 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 0834464CC6 for ; Tue, 23 Jan 2024 13:11:18 +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=1706015479; cv=none; b=VgBjSMkuT4Q1ygMEJIcUXsJ35TsKCUaSmYoR4omEcInymhymOK6gEvafVNpJsuirQ4z42QfOuTb7uciy7h8kXgkz05ADQlOU+7EY+Aa/wFmuIhNQAy+SamP8ilAmZ4bdoKl29Ivudevlh04Sd0HE9hxpGBXS4yvK6n92BIUu2FE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015479; c=relaxed/simple; bh=I1SQtnTLZUxsrxlA6hOJKmFREclmLqWNgnpq8GQG2Dc=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=V+fU1LDMlkRmwlLm2iZKCXQv4Ku4HvvWcFGk8vxMJFZaZScudnorAy4AF9pm+PsgmOiYcGsUCmFMev8KgF9nNHrRtNepqQqRljksFlmKwiaYj42TiS6Wq3UM7D6FSFTO6MnfYla+LoShXq6Rxl8xpcNaDnxnPG9/Y5h5T5CPinI= 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=4gSjzZfW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gZlxwr6n; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4gSjzZfW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gZlxwr6n" Message-ID: <20240118123649.457293914@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015476; 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=k+aJuv8k1/XFPGcpFKqCzFGQQLJcSJpnrwligUkpyog=; b=4gSjzZfWP8b0oymelZ2lj37G/Bi2nbqhBjC7B/nG1yL3liRcOQ4ltxxSmyvNxAsVUXXnlX kkYlKw9228N23dl+x9gj606rBQblumQWf70MKKFmZzML+GXgO30i3UpVcLCFJqP3K0NuSX IdWF80z+KlM2RuO1a7vS/6wpZ5RwPUQZZqKRVG2D3vmpYQuWgzVor5NsqPIuE+dbT26LHY B9HLCgLfQwVbDlFRIDUZu8mEQJXeU5uj6zcDBtcxM+H+nUspQTnC6BXYlUw08P7bgbtxIA jOwHS9mHGHay86UznsvSc2Ctu4KKHBuPVOPW6Q2NNwlsw3OoCPDdaCQQGeGPtw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015476; 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=k+aJuv8k1/XFPGcpFKqCzFGQQLJcSJpnrwligUkpyog=; b=gZlxwr6nvXbpV7D5Fv0Pv1cx5/G/5if5Hx/DL158dtFHioqlKdL383kspd0v1og9dhjBKz BdKrJV6dNR8zalCw== 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 16/30] x86/topology: Add a mechanism to track topology via APIC IDs 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 Date: Tue, 23 Jan 2024 14:11:15 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Topology on X86 is determined by the registered APIC IDs and the segmentation information retrieved from CPUID. Depending on the granularity of the provided CPUID information the most fine grained scheme looks like this according to Intel terminology: [PKG][DIEGRP][DIE][TILE][MODULE][CORE][THREAD] Not enumerated domain levels consume 0 bits in the APIC ID. This allows to provide a consistent view at the topology and determine other information precisely like the number of cores in a package on hybrid systems, where the existing assumption that number or cores =3D=3D number of threads / thr= eads per core does not hold. Provide per domain level bitmaps which record the APIC ID split into the domain levels to make later evaluation of domain level specific information simple. This allows to calculate e.g. the logical IDs without any further extra logic. Contrary to the existing registration mechanism this records disabled CPUs, which are subject to later hotplug as well. That's useful for boot time sizing of package or die dependent allocations without using heuristics. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 48 ++++++++++++++++++++++++++++++++++++= +++-- 1 file changed, 46 insertions(+), 2 deletions(-) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -1,5 +1,27 @@ // SPDX-License-Identifier: GPL-2.0-only - +/* + * CPU/APIC topology + * + * The APIC IDs describe the system topology in multiple domain levels. + * The CPUID topology parser provides the information which part of the + * APIC ID is associated to the individual levels: + * + * [PACKAGE][DIEGRP][DIE][TILE][MODULE][CORE][THREAD] + * + * The root space contains the package (socket) IDs. + * + * Not enumerated levels consume 0 bits space, but conceptually they are + * always represented. If e.g. only CORE and THREAD levels are enumerated + * then the DIE, MODULE and TILE have the same physical ID as the PACKAGE. + * + * If SMT is not supported, then the THREAD domain is still used. It then + * has the same physical ID as the CORE domain and is the only child of + * the core domain. + * + * This allows a unified view on the system independent of the enumerated + * domain levels without requiring any conditionals in the code. + */ +#define pr_fmt(fmt) "CPU topo: " fmt #include =20 #include @@ -9,6 +31,8 @@ #include #include =20 +#include "cpu.h" + /* * Map cpu index to physical APIC ID */ @@ -23,6 +47,9 @@ DECLARE_BITMAP(phys_cpu_present_map, MAX /* Used for CPU number allocation and parallel CPU bringup */ u32 cpuid_to_apicid[] __read_mostly =3D { [0 ... NR_CPUS - 1] =3D BAD_APIC= ID, }; =20 +/* Bitmaps to mark registered APICs at each topology domain */ +static struct { DECLARE_BITMAP(map, MAX_LOCAL_APIC); } apic_maps[TOPO_MAX_= DOMAIN] __ro_after_init; + /* * Keep track of assigned, disabled and rejected CPUs. Present assigned * with 1 as CPU #0 is reserved for the boot CPU. @@ -39,6 +66,8 @@ static struct { .real_bsp_apic_id =3D BAD_APICID, }; =20 +#define domain_weight(_dom) bitmap_weight(apic_maps[_dom].map, MAX_LOCAL_A= PIC) + bool arch_match_cpu_phys_id(int cpu, u64 phys_id) { return phys_id =3D=3D (u64)cpuid_to_apicid[cpu]; @@ -81,6 +110,17 @@ early_initcall(smp_init_primary_thread_m static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int = apicid) { } #endif =20 +/* + * Convert the APIC ID to a domain level ID by masking out the low bits + * below the domain level @dom. + */ +static inline u32 topo_apicid(u32 apicid, enum x86_topology_domains dom) +{ + if (dom =3D=3D TOPO_SMT_DOMAIN) + return apicid; + return apicid & (UINT_MAX << x86_topo_system.dom_shifts[dom - 1]); +} + static int topo_lookup_cpuid(u32 apic_id) { int i; @@ -151,7 +191,7 @@ static __init bool check_for_real_bsp(u3 =20 static __init void topo_register_apic(u32 apic_id, u32 acpi_id, bool prese= nt) { - int cpu; + int cpu, dom; =20 if (present) { /* @@ -171,6 +211,10 @@ static __init void topo_register_apic(u3 } else { topo_info.nr_disabled_cpus++; } + + /* Register present and possible CPUs in the domain maps */ + for (dom =3D TOPO_SMT_DOMAIN; dom < TOPO_MAX_DOMAIN; dom++) + set_bit(topo_apicid(apic_id, dom), apic_maps[dom].map); } =20 /** From nobody Fri Dec 19 02:50:56 2025 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 DE0FF64CEE for ; Tue, 23 Jan 2024 13:11:19 +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=1706015481; cv=none; b=U4dBm2qc+be6Bz/1JeVe4G4IZpce1ODgZsRHaJN4njHl5sZyyrL/7FwDvnlzvEwaCDWfo3T91yS9qPF941TSdb1HrvcelzK5niKM/8eYjg/zptqwJQwxPjgULUalzIrKIziNnA6fU+SWcwQDco1s6pnN7jgo2fLI7fIOttPUHso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015481; c=relaxed/simple; bh=r5AGb/XQ+lkMk/28b6KQQlUOwH5R5IM2l6YzETADWPk=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=sOvUzrBauSZM2XcqKz8xvgHYVYJ4tpp7txJBrxFVXUp4AyUM+0Oez/K6lllhPbWpscMM7hQvSc/KjCXqsIcOjxzNyp8Sj6rwCXRNVIq6KI0Q6mHNSPFTEo9QrRbe7J88RVBYC5ZBrGnK15gVPErDXrbedZLPRNX8CxrCHVqxTJ0= 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=rMqAeOL8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QwHll0Gi; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rMqAeOL8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QwHll0Gi" Message-ID: <20240118123649.513878058@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015478; 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=AL6rtCpTcNHRwvmkB9lH73XsGA1kAtoRIuLTc7Fw7rE=; b=rMqAeOL8SfoskRhVnzzZ1cgGVKKHEy8/LjTFzaZoz/fPvYB43MMg84vcWq6nK+lgOyqL9L GG8IfX33+gpg2N/Hs/ZDmMe7kXAfPBsBUZiO0eVzhlpNmDeLYvGc7RfK19cGQjqGB+U4Qo //vhaLKF+OTuYmSpur0IcWJRGqpUwsLk9XuSHzLh3TvlibBeYWg94Vb9wF77FX4kXBSArN gDFmfu7707rducLbdtEdxKqVun2X9Lbu3jcmI/gNBh2/0dKCucm+H5ryLF2A8KuEHJMDgq 8XHpv0/ueVjniKnXbLOuJHaO7tV/3nJdwqTsFf3PzyTCDpo3+dlIOCpG4s/0GA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015478; 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=AL6rtCpTcNHRwvmkB9lH73XsGA1kAtoRIuLTc7Fw7rE=; b=QwHll0GiP2lanU8HeZcYPYuEpVbvjY7KofnkML6uapGHzV9/Wi5oW+JP41OoJnOWLPJwyw Vhoe8kGyemadi0Cw== 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 17/30] x86/cpu/topology: Reject unknown APIC IDs on ACPI hotplug 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 Date: Tue, 23 Jan 2024 14:11:17 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The topology bitmaps track all possible APIC IDs which have been registered during enumeration. As sizing and further topology information is going to be derived from these bitmaps, reject attempts to hotplug an APIC ID which was not registered during enumeration. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 4 ++++ 1 file changed, 4 insertions(+) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -266,6 +266,10 @@ int topology_hotplug_apic(u32 apic_id, u if (apic_id >=3D MAX_LOCAL_APIC) return -EINVAL; =20 + /* Reject if the APIC ID was not registered during enumeration. */ + if (!test_bit(apic_id, apic_maps[TOPO_SMT_DOMAIN].map)) + return -ENODEV; + cpu =3D topo_lookup_cpuid(apic_id); if (cpu < 0) { if (topo_info.nr_assigned_cpus >=3D nr_cpu_ids) From nobody Fri Dec 19 02:50:56 2025 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 80BB5651A1 for ; Tue, 23 Jan 2024 13:11:21 +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=1706015483; cv=none; b=OROf5tfBvdRu1Z3A8XguhBu+41IhdbC+cLDlrEoMvvXxLKAAPEKSGKzkLwVmFeeWJNFhjPZf0JRSBfbOL2AhcxKkC0h8UdsoTZVSrD5Px0gB22PqOG/0gdZJFnLfDoV+dQBm21ysuWnueKmzGMsA2xyd4IX1b1itx/LSC5L84F0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015483; c=relaxed/simple; bh=LL+PI2JUCSitbXIgL7C3Pzx3ABaDIfTVeVFPuGTNxPY=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=sjMUJzjB/QLJOHmPd7tJs4hFos4kW8thE/wnl7BXmNyk/T6bzgOTXsFoaTYbSI+jqqNDHkKEjZBay1g5kCZkJfLcR3DeO3qa0v/9cmuIG5xDKXPA+ftV8r4w2usQBX2Qr1F0pzGaTHBtFJfe00gHCbQIz5i6jkQU4ulMf2bSuxo= 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=45hvOrlB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jcmhl8rm; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="45hvOrlB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jcmhl8rm" Message-ID: <20240118123649.569833701@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015480; 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=1VEpaCzatSS1m78r8ucv1MaTrOUKxCMYoRkuUIJ9K54=; b=45hvOrlBFQnUc8jJdQos5iNICeC7pAp8FQdhqAzi9dhFJp7pl3RdXkzhqLPt4SXY5wYt6h EBH1aINGE9ZRYJWQ6RIOUSps4aioJr6tWVzpcpJ16+Ir3nYn+5qLaSKGdMCg+6Tbl21m6I L7JARKiMH/rcwESBx/cSjIFpq3D5D0OnkhtFhwidKvYbKAndVJBnaOrJOUAeJsTdNNqQvM b31YSfSwkeQ6bv/shMjGl8EhQe8btXI/+2cE7UGj48GsT14u1hmwBw2ZsML7zGznSvttaE 9RDhZ5EfIUtTKKF2lSO+T2Y/TS6wSSsJy+NIEzceIA5pquF8YtPdQcv1DwYX0A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015480; 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=1VEpaCzatSS1m78r8ucv1MaTrOUKxCMYoRkuUIJ9K54=; b=jcmhl8rmsEm6bqHidSV68CqF3PpvCJNe5yZN55wjy1Q09ke+VTVO9hxYzlsNxpyeVGU3aT F+TC2AtrlM33NcBw== 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 18/30] x86/cpu/topology: Assign hotpluggable CPUIDs during init 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 Date: Tue, 23 Jan 2024 14:11:19 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner There is no point in assigning the CPU numbers during ACPI physical hotplug. The number of possible hotplug CPUs is known when the possible map is initialized, so the CPU numbers can be associated to the registered non-present APIC IDs right there. This allows to put more code into the __init section and makes the related data __ro_after_init. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -45,7 +45,7 @@ EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_a DECLARE_BITMAP(phys_cpu_present_map, MAX_LOCAL_APIC) __read_mostly; =20 /* Used for CPU number allocation and parallel CPU bringup */ -u32 cpuid_to_apicid[] __read_mostly =3D { [0 ... NR_CPUS - 1] =3D BAD_APIC= ID, }; +u32 cpuid_to_apicid[] __ro_after_init =3D { [0 ... NR_CPUS - 1] =3D BAD_AP= ICID, }; =20 /* Bitmaps to mark registered APICs at each topology domain */ static struct { DECLARE_BITMAP(map, MAX_LOCAL_APIC); } apic_maps[TOPO_MAX_= DOMAIN] __ro_after_init; @@ -60,7 +60,7 @@ static struct { unsigned int nr_rejected_cpus; u32 boot_cpu_apic_id; u32 real_bsp_apic_id; -} topo_info __read_mostly =3D { +} topo_info __ro_after_init =3D { .nr_assigned_cpus =3D 1, .boot_cpu_apic_id =3D BAD_APICID, .real_bsp_apic_id =3D BAD_APICID, @@ -133,7 +133,7 @@ static int topo_lookup_cpuid(u32 apic_id return -ENODEV; } =20 -static int topo_assign_cpunr(u32 apic_id) +static __init int topo_assign_cpunr(u32 apic_id) { int cpu =3D topo_lookup_cpuid(apic_id); =20 @@ -149,8 +149,6 @@ static void topo_set_cpuids(unsigned int early_per_cpu(x86_cpu_to_apicid, cpu) =3D apic_id; early_per_cpu(x86_cpu_to_acpiid, cpu) =3D acpi_id; #endif - cpuid_to_apicid[cpu] =3D apic_id; - set_cpu_possible(cpu, true); set_cpu_present(cpu, true); =20 @@ -207,6 +205,8 @@ static __init void topo_register_apic(u3 cpu =3D 0; else cpu =3D topo_assign_cpunr(apic_id); + + cpuid_to_apicid[cpu] =3D apic_id; topo_set_cpuids(cpu, apic_id, acpi_id); } else { topo_info.nr_disabled_cpus++; @@ -276,12 +276,9 @@ int topology_hotplug_apic(u32 apic_id, u return -ENODEV; =20 cpu =3D topo_lookup_cpuid(apic_id); - if (cpu < 0) { - if (topo_info.nr_assigned_cpus >=3D nr_cpu_ids) - return -ENOSPC; + if (cpu < 0) + return -ENOSPC; =20 - cpu =3D topo_assign_cpunr(apic_id); - } set_bit(apic_id, phys_cpu_present_map); topo_set_cpuids(cpu, apic_id, acpi_id); return cpu; @@ -352,6 +349,7 @@ void __init topology_init_possible_cpus( unsigned int disabled =3D topo_info.nr_disabled_cpus; unsigned int total =3D assigned + disabled; unsigned int cpu, allowed =3D 1; + u32 apicid; =20 if (!restrict_to_up()) { if (WARN_ON_ONCE(assigned > nr_cpu_ids)) { @@ -380,8 +378,17 @@ void __init topology_init_possible_cpus( init_cpu_present(cpumask_of(0)); init_cpu_possible(cpumask_of(0)); =20 + /* Assign CPU numbers to non-present CPUs */ + for (apicid =3D 0; disabled; disabled--, apicid++) { + apicid =3D find_next_andnot_bit(apic_maps[TOPO_SMT_DOMAIN].map, phys_cpu= _present_map, + MAX_LOCAL_APIC, apicid); + if (apicid >=3D MAX_LOCAL_APIC) + break; + cpuid_to_apicid[topo_info.nr_assigned_cpus++] =3D apicid; + } + for (cpu =3D 0; cpu < allowed; cpu++) { - u32 apicid =3D cpuid_to_apicid[cpu]; + apicid =3D cpuid_to_apicid[cpu]; =20 set_cpu_possible(cpu, true); From nobody Fri Dec 19 02:50:56 2025 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 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" 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 Date: Tue, 23 Jan 2024 14:11:20 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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(); } =20 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); =20 +void xen_smp_count_cpus(void); void xen_smp_cpus_done(unsigned int max_cpus); =20 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 */ =20 #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; } =20 +void __init xen_smp_count_cpus(void) +{ + unsigned int cpus; + + for (cpus =3D 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 =3D { .smp_prepare_boot_cpu =3D xen_pv_smp_prepare_boot_cpu, .smp_prepare_cpus =3D xen_pv_smp_prepare_cpus, From nobody Fri Dec 19 02:50:56 2025 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 18F72657DF for ; Tue, 23 Jan 2024 13:11:24 +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=1706015486; cv=none; b=G79AiT1FZroBiTk4zmbAvREy0fOuWYIeVyTr7jhBUh6pSrf1rtpmn4CJHpAKyf2A2G8W7ejxWxPUoZ0ooZpzrhyUfEsBpjbPEVly3g6Ditm7F5MFDAqpMFRa8ouVP7CtTgEZQvJUnhnVZh71Xj6vxS3jr7AG9j9crGvJ8rKgepw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015486; c=relaxed/simple; bh=HC82UXbxGN1Hi6aLHsZ3ND2lVinY2vYNx0+m3CpHTwM=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=VqELLqmCI+/3L9BtyZ+UK5zvxyTS1HOaVbQOMRU2BnKKhHLWqLSbWFAcC8UgFxMyBMHk75fAeEPWxOv2US9j7qeI4wEddMU2yLyxqiH1h5Dd015aHLMrFZEsekHO3TNx+sGy/K8aZIRom8J0649Z1QieFOgOM6DqckmxIibn3E0= 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=wwMKRsBe; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4T75ydKM; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wwMKRsBe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4T75ydKM" Message-ID: <20240118123649.681917612@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015483; 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=GstJkdj4dzJr9Ab3z0mxhqERtIepnLSH1sYrgV3hkW4=; b=wwMKRsBeiYdmd0dpP7w1n+82pS/nLejWtW2GAs0RO+m1+MUFM85UJ7cti1JCH57kNhzYil O7AJeALTl2964UStLG4Gstf7cAIfGnPDNRvd/VZl7KI15I0rJBUxgrSl/EjS7Yhtf3OwPz jjOHF+frBsGuKV1gJq+03s4FLFmJrx8QOmM+F5p+v81Sfk+w8QQfjB1yinwTuIz6YIUWGk O+0T3dSHetb0rvvva9Ws+k9ruNcwJ/FJ5OY95rJbrUXc1l6x20R8pppGetFLj2RlapLOfN tOhZuJKGyzPNAEQTdY2G9bGuueAQcbpW2X6WA+SEHxHtry6wkkrNA8s0/C9w/g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015483; 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=GstJkdj4dzJr9Ab3z0mxhqERtIepnLSH1sYrgV3hkW4=; b=4T75ydKMf4OOkNimbbkD1vq/BWEk5vWqXQjYrvPugdepBNa9m2DSKycRTps6FP7w0Dj1hC yVRR8piDevyN3eDQ== 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 20/30] x86/cpu/topology: Let XEN/PV use topology from CPUID/MADT 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 Date: Tue, 23 Jan 2024 14:11:22 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner It turns out that XEN/PV Dom0 has halfways usable CPUID/MADT enumeration except that it cannot deal with CPUs which are enumerated as disabled in MADT. DomU has no MADT and provides at least rudimentary topology information in CPUID leaves 1 and 4. For both it's important that there are not more possible Linux CPUs than vCPUs provided by the hypervisor. As this is ensured by counting the vCPUs before enumeration happens: - lift the restrictions in the CPUID evaluation and the MADT parser - Utilize MADT registration for Dom0 - Keep the fake APIC ID registration for DomU - Fix the XEN APIC fake so the readout of the local APIC ID works for Dom0 via the hypercall and for DomU by returning the registered fake APIC IDs. With that the XEN/PV fake approximates usefulness. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/acpi/boot.c | 25 ++++++++----------------- arch/x86/kernel/cpu/topology_common.c | 2 +- arch/x86/xen/apic.c | 14 +++++++------- arch/x86/xen/smp_pv.c | 13 ++++++++----- 4 files changed, 24 insertions(+), 30 deletions(-) --- --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -23,8 +23,6 @@ #include #include =20 -#include - #include #include #include @@ -166,12 +164,6 @@ static int __init acpi_parse_madt(struct return 0; } =20 -static __init void acpi_register_lapic(u32 apic_id, u32 acpi_id, bool pres= ent) -{ - if (!xen_pv_domain()) - topology_register_apic(apic_id, acpi_id, present); -} - static bool __init acpi_is_processor_usable(u32 lapic_flags) { if (lapic_flags & ACPI_MADT_ENABLED) @@ -233,7 +225,7 @@ acpi_parse_x2apic(union acpi_subtable_he return 0; } =20 - acpi_register_lapic(apic_id, processor->uid, enabled); + topology_register_apic(apic_id, processor->uid, enabled); #else pr_warn("x2apic entry ignored\n"); #endif @@ -268,9 +260,9 @@ acpi_parse_lapic(union acpi_subtable_hea * to not preallocating memory for all NR_CPUS * when we use CPU hotplug. */ - acpi_register_lapic(processor->id, /* APIC ID */ - processor->processor_id, /* ACPI ID */ - processor->lapic_flags & ACPI_MADT_ENABLED); + topology_register_apic(processor->id, /* APIC ID */ + processor->processor_id, /* ACPI ID */ + processor->lapic_flags & ACPI_MADT_ENABLED); =20 has_lapic_cpus =3D true; return 0; @@ -288,9 +280,9 @@ acpi_parse_sapic(union acpi_subtable_hea =20 acpi_table_print_madt_entry(&header->common); =20 - acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */ - processor->processor_id, /* ACPI ID */ - processor->lapic_flags & ACPI_MADT_ENABLED); + topology_register_apic((processor->id << 8) | processor->eid,/* APIC ID */ + processor->processor_id, /* ACPI ID */ + processor->lapic_flags & ACPI_MADT_ENABLED); =20 return 0; } @@ -1090,8 +1082,7 @@ static int __init early_acpi_parse_madt_ return count; } =20 - if (!xen_pv_domain()) - register_lapic_address(acpi_lapic_addr); + register_lapic_address(acpi_lapic_addr); =20 return count; } --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -77,7 +77,7 @@ static bool fake_topology(struct topo_sc topology_set_dom(tscan, TOPO_SMT_DOMAIN, 0, 1); topology_set_dom(tscan, TOPO_CORE_DOMAIN, 0, 1); =20 - return tscan->c->cpuid_level < 1 || xen_pv_domain(); + return tscan->c->cpuid_level < 1; } =20 static void parse_topology(struct topo_scan *tscan, bool early) --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -43,20 +43,20 @@ static u32 xen_apic_read(u32 reg) struct xen_platform_op op =3D { .cmd =3D XENPF_get_cpuinfo, .interface_version =3D XENPF_INTERFACE_VERSION, - .u.pcpu_info.xen_cpuid =3D 0, }; - int ret; - - /* Shouldn't need this as APIC is turned off for PV, and we only - * get called on the bootup processor. But just in case. */ - if (!xen_initial_domain() || smp_processor_id()) - return 0; + int ret, cpu; =20 if (reg =3D=3D APIC_LVR) return 0x14; if (reg !=3D APIC_ID) return 0; =20 + cpu =3D smp_processor_id(); + if (!xen_initial_domain()) + return cpu ? cpuid_to_apicid[cpu] << 24 : 0; + + op.u.pcpu_info.xen_cpuid =3D cpu; + ret =3D HYPERVISOR_platform_op(&op); if (ret) op.u.pcpu_info.apic_id =3D BAD_APICID; --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -156,11 +156,9 @@ static void __init xen_pv_smp_config(voi =20 topology_register_boot_apic(apicid++); =20 - for (i =3D 1; i < nr_cpu_ids; i++) { - if (HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL) < 0) - break; + for (i =3D 1; i < nr_cpu_ids; i++) topology_register_apic(apicid++, CPU_ACPIID_INVALID, true); - } + /* Pretend to be a proper enumerated system */ smp_found_config =3D 1; } @@ -451,5 +449,10 @@ void __init xen_smp_init(void) /* Avoid searching for BIOS MP tables */ x86_init.mpparse.find_mptable =3D x86_init_noop; x86_init.mpparse.early_parse_smp_cfg =3D x86_init_noop; - x86_init.mpparse.parse_smp_cfg =3D xen_pv_smp_config; + + /* XEN/PV Dom0 has halfways sane topology information via CPUID/MADT */ + if (xen_initial_domain()) + x86_init.mpparse.parse_smp_cfg =3D x86_init_noop; + else + x86_init.mpparse.parse_smp_cfg =3D xen_pv_smp_config; } From nobody Fri Dec 19 02:50:56 2025 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 63A6C65BB9 for ; Tue, 23 Jan 2024 13:11:26 +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=1706015488; cv=none; b=a92jEG89mBqHAHEwMRGd4OYg85c+MqBT79t63ZJFuFkvzwLsRswPmp5nZA9cJ5Lyn2h0An8e3ZzAdfC/LXxV9zkRQEBxlkHQFEjqiEXSzFh3m610gb5SRbzyvCtQabQcOnQL5BDRIJWBzBaRVI4PPAWuJF7gZiSx0tSb+49AtK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015488; c=relaxed/simple; bh=8y88vOxznZQvU3EPYbq3TtfdFRDfqaVpme6cytD/E4s=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=htC76TSsvVwh2rEfUAMURGVhk5RYdVv23/fkpIMCcgkPAh8MHKtxiFKhYLz9rudh3/fkFg3yj7y8HwjqsIgvop5SLplwQhE0iNN/QExu5dVdTJ5b2HmR6jaPv5g89TUUGWEOjsI2Z+BgMDaZ3+ppBNbwCZvV6/pwn1auRq+SYZ4= 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=UbpTZssd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UD1ynFxI; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UbpTZssd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UD1ynFxI" Message-ID: <20240118123649.739960607@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015484; 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=qFjBKR9yAIFD5TSTkozL1zkc8ZsQppvHiWRQyCb/KsA=; b=UbpTZssd3FzgHlojNhvS6SCCKnFTnbEmd3z/hG2e4rMngtXWGpEQbrKWS2VDxmmzdm35eK M7aX4tvgE/vWRS6yirrYTaqUI8SUCY9Gh8GXmSdGofpRvGG1PleV307IZXss/XhofOjuxU beGNjng4FwwtFa9uBoAt7anFx5Pgqg8hTnSx5BbXtJ2ObitV3mSRJp7wFR1kZcrTyTp85Q 5Wx2fyqLdO62/i2C4V3jKmIyMDmKHx1I6PWtLJX+gTRqlQ+IfGxVwM9Hgg+9aWetn9qli3 Kx+BLt5ZoVYGSkdVavBsyk9D5CeWJ3VTVs5FMGjDqp4kgIfhv2n6e/ekWv/I6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015484; 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=qFjBKR9yAIFD5TSTkozL1zkc8ZsQppvHiWRQyCb/KsA=; b=UD1ynFxIkwNVMBRfUE5aB4NX1H8PaPc4bPldxHpp6yKsCGXi5oemRK2LKOnSDyqk0lUu0y 1rImx3SqYwueSzBw== 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 21/30] x86/cpu/topology: Use topology bitmaps for sizing 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 Date: Tue, 23 Jan 2024 14:11:23 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Now that all possible APIC IDs are tracked in the topology bitmaps, its trivial to retrieve the real information from there. This gets rid of the guesstimates for the maximal packages and dies per package as the actual numbers can be determined before a single AP has been brought up. The number of SMT threads can now be determined correctly from the bitmaps in all situations. Up to now a system which has SMT disabled in the BIOS will still claim that it is SMT capable, because the lowest APIC ID bit is reserved for that and CPUID leaf 0xb/0x1f still enumerates the SMT domain accordingly. By calculating the bitmap weights of the SMT and the CORE domain and setting them into relation the SMT disabled in BIOS situation reports correctly that the system is not SMT capable. It also handles the situation correctly when a hybrid systems boot CPU does not have SMT as it takes the SMT capability of the APs fully into account. Signed-off-by: Thomas Gleixner Tested-by: Sohil Mehta --- arch/x86/include/asm/smp.h | 3 +-- arch/x86/include/asm/topology.h | 23 ++++++++++++----------- arch/x86/kernel/cpu/common.c | 9 ++++++--- arch/x86/kernel/cpu/debugfs.c | 2 +- arch/x86/kernel/cpu/topology.c | 16 +++++++++++++++- arch/x86/kernel/cpu/topology_common.c | 24 ------------------------ arch/x86/kernel/smpboot.c | 16 ---------------- arch/x86/xen/smp.c | 2 -- 8 files changed, 35 insertions(+), 60 deletions(-) --- --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -8,7 +8,7 @@ #include #include =20 -extern int smp_num_siblings; +extern unsigned int smp_num_siblings; =20 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map); @@ -109,7 +109,6 @@ void cpu_disable_common(void); void native_smp_prepare_boot_cpu(void); void smp_prepare_cpus_common(void); void native_smp_prepare_cpus(unsigned int max_cpus); -void calculate_max_logical_packages(void); void native_smp_cpus_done(unsigned int max_cpus); int common_cpu_up(unsigned int cpunum, struct task_struct *tidle); int native_kick_ap(unsigned int cpu, struct task_struct *tidle); --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -143,7 +143,18 @@ extern const struct cpumask *cpu_cluster =20 #define topology_amd_node_id(cpu) (cpu_data(cpu).topo.amd_node_id) =20 -extern unsigned int __max_die_per_package; +extern unsigned int __max_dies_per_package; +extern unsigned int __max_logical_packages; + +static inline unsigned int topology_max_packages(void) +{ + return __max_logical_packages; +} + +static inline unsigned int topology_max_die_per_package(void) +{ + return __max_dies_per_package; +} =20 #ifdef CONFIG_SMP #define topology_cluster_id(cpu) (cpu_data(cpu).topo.l2c_id) @@ -152,14 +163,6 @@ extern unsigned int __max_die_per_packag #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) =20 -extern unsigned int __max_logical_packages; -#define topology_max_packages() (__max_logical_packages) - -static inline int topology_max_die_per_package(void) -{ - return __max_die_per_package; -} - extern int __max_smt_threads; =20 static inline int topology_max_smt_threads(void) @@ -193,13 +196,11 @@ static inline bool topology_is_primary_t } =20 #else /* CONFIG_SMP */ -#define topology_max_packages() (1) static inline int topology_update_package_map(unsigned int apicid, unsigned int cpu) { retur= n 0; } static inline int topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; } static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return = 0; } -static inline int topology_max_die_per_package(void) { return 1; } static inline int topology_max_smt_threads(void) { return 1; } static inline bool topology_is_primary_thread(unsigned int cpu) { return t= rue; } static inline unsigned int topology_amd_nodes_per_pkg(void) { return 0; }; --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -72,11 +72,14 @@ u32 elf_hwcap2 __read_mostly; =20 /* Number of siblings per CPU package */ -int smp_num_siblings =3D 1; +unsigned int smp_num_siblings __ro_after_init =3D 1; EXPORT_SYMBOL(smp_num_siblings); =20 -unsigned int __max_die_per_package __read_mostly =3D 1; -EXPORT_SYMBOL(__max_die_per_package); +unsigned int __max_dies_per_package __ro_after_init =3D 1; +EXPORT_SYMBOL(__max_dies_per_package); + +unsigned int __max_logical_packages __ro_after_init =3D 1; +EXPORT_SYMBOL(__max_logical_packages); =20 static struct ppin_info { int feature; --- a/arch/x86/kernel/cpu/debugfs.c +++ b/arch/x86/kernel/cpu/debugfs.c @@ -29,7 +29,7 @@ static int cpu_debug_show(struct seq_fil seq_printf(m, "amd_node_id: %u\n", c->topo.amd_node_id); seq_printf(m, "amd_nodes_per_pkg: %u\n", topology_amd_nodes_per_pkg()); seq_printf(m, "max_cores: %u\n", c->x86_max_cores); - seq_printf(m, "max_die_per_pkg: %u\n", __max_die_per_package); + seq_printf(m, "max_dies_per_pkg: %u\n", __max_dies_per_package); seq_printf(m, "smp_num_siblings: %u\n", smp_num_siblings); return 0; } --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -349,8 +349,8 @@ void __init topology_init_possible_cpus( { unsigned int assigned =3D topo_info.nr_assigned_cpus; unsigned int disabled =3D topo_info.nr_disabled_cpus; + unsigned int cnta, cntb, cpu, allowed =3D 1; unsigned int total =3D assigned + disabled; - unsigned int cpu, allowed =3D 1; u32 apicid; =20 if (!restrict_to_up()) { @@ -373,6 +373,20 @@ void __init topology_init_possible_cpus( total_cpus =3D allowed; set_nr_cpu_ids(allowed); =20 + cnta =3D domain_weight(TOPO_PKG_DOMAIN); + cntb =3D domain_weight(TOPO_DIE_DOMAIN); + __max_logical_packages =3D cnta; + __max_dies_per_package =3D 1U << (get_count_order(cntb) - get_count_order= (cnta)); + + pr_info("Max. logical packages: %3u\n", cnta); + pr_info("Max. logical dies: %3u\n", cntb); + pr_info("Max. dies per package: %3u\n", __max_dies_per_package); + + cnta =3D domain_weight(TOPO_CORE_DOMAIN); + cntb =3D domain_weight(TOPO_SMT_DOMAIN); + smp_num_siblings =3D 1U << (get_count_order(cntb) - get_count_order(cnta)= ); + pr_info("Max. threads per core: %3u\n", smp_num_siblings); + pr_info("Allowing %u present CPUs plus %u hotplug CPUs\n", assigned, disa= bled); if (topo_info.nr_rejected_cpus) pr_info("Rejected CPUs %u\n", topo_info.nr_rejected_cpus); --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -196,16 +196,6 @@ void cpu_parse_topology(struct cpuinfo_x tscan.dom_shifts[dom], x86_topo_system.dom_shifts[dom]); } =20 - /* Bug compatible with the existing parsers */ - if (tscan.dom_ncpus[TOPO_SMT_DOMAIN] > smp_num_siblings) { - if (system_state =3D=3D SYSTEM_BOOTING) { - pr_warn_once("CPU%d: SMT detected and enabled late\n", cpu); - smp_num_siblings =3D tscan.dom_ncpus[TOPO_SMT_DOMAIN]; - } else { - pr_warn_once("CPU%d: SMT detected after init. Too late!\n", cpu); - } - } - topo_set_ids(&tscan); topo_set_max_cores(&tscan); } @@ -232,20 +222,6 @@ void __init cpu_init_topology(struct cpu topo_set_max_cores(&tscan); =20 /* - * Bug compatible with the existing code. If the boot CPU does not - * have SMT this ends up with one sibling. This needs way deeper - * changes further down the road to get it right during early boot. - */ - smp_num_siblings =3D tscan.dom_ncpus[TOPO_SMT_DOMAIN]; - - /* - * Neither it's clear whether there are as many dies as the APIC - * space indicating die level is. But assume that the actual number - * of CPUs gives a proper indication for now to stay bug compatible. - */ - __max_die_per_package =3D tscan.dom_ncpus[TOPO_DIE_DOMAIN] / - tscan.dom_ncpus[TOPO_DIE_DOMAIN - 1]; - /* * AMD systems have Nodes per package which cannot be mapped to * APIC ID. */ --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -139,8 +139,6 @@ static DEFINE_PER_CPU_READ_MOSTLY(struct .phys_die_id =3D U32_MAX, }; =20 -unsigned int __max_logical_packages __read_mostly; -EXPORT_SYMBOL(__max_logical_packages); static unsigned int logical_packages __read_mostly; static unsigned int logical_die __read_mostly; =20 @@ -1267,24 +1265,10 @@ void __init native_smp_prepare_boot_cpu( native_pv_lock_init(); } =20 -void __init calculate_max_logical_packages(void) -{ - int ncpus; - - /* - * Today neither Intel nor AMD support heterogeneous systems so - * extrapolate the boot cpu's data to all packages. - */ - ncpus =3D cpu_data(0).booted_cores * topology_max_smt_threads(); - __max_logical_packages =3D DIV_ROUND_UP(total_cpus, ncpus); - pr_info("Max logical packages: %u\n", __max_logical_packages); -} - void __init native_smp_cpus_done(unsigned int max_cpus) { pr_debug("Boot done\n"); =20 - calculate_max_logical_packages(); build_sched_topology(); nmi_selftest(); impress_friends(); --- a/arch/x86/xen/smp.c +++ b/arch/x86/xen/smp.c @@ -123,8 +123,6 @@ void __init xen_smp_cpus_done(unsigned i { if (xen_hvm_domain()) native_smp_cpus_done(max_cpus); - else - calculate_max_logical_packages(); } =20 void xen_smp_send_reschedule(int cpu) From nobody Fri Dec 19 02:50:56 2025 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 2C6EC65BDF for ; Tue, 23 Jan 2024 13:11:28 +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=1706015490; cv=none; b=QB/uXZ8B3WQ54sP7S34gob0hcwah2nvnLHu4G4BIi5vTr9DARVC78W2Z5Rnr3ZNYZFVU/OZOy0H1WqyRwgs2ZPsRsIZQjPV4JLlv7MPrJyIWJMU7Kc+I80tATSpAHmGAYU6d5xIp7GWIBAWtQCvPT+sCi36z/DbPuKpnI7dQAJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015490; c=relaxed/simple; bh=g6J2asPgFD0LMsaQKbG6sg+BTdgOsXYI9ZSt8dfSSUM=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=cN8Vct+mJMr4f6YRPtQUhRMwIPxUsXtmfyCBByDNEgMZkvlkiNzdBufcbRHeiFsHVQYi5ShloQ/S4YcwDA1FgDMRuHONdCXXDFVPbqTydstMLJZQGdwFr2qKt6iMS5IWjBjJAyzdaYeJDgrXDv5g/39gBiLK9EpoiV0wb50zjEo= 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=S+qILiHH; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Rqc5v9+z; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="S+qILiHH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Rqc5v9+z" Message-ID: <20240118123649.804004114@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015487; 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=MpTsqbRm/7LUvkcxZ0AyD5uJRHhE5ALqrQ6PV/OvYUc=; b=S+qILiHHXkAV2EyV12l6SUzg4bOrkeMeqfcxYTq2fGIK9ysa6UCP1cTi7jEqLBzGOuNulh +z+uCDx02XhhNOiSvVd7fNoCKVit55iWZuOemkBdVdCOjY3XcNNGeYy+hqI1jF0rn9U75a 0lMtRAOavZgJQz8sjuMJ6yoyjahHdk1KIH9XOUkTE1wP5jsuiYTWiCtk0MrMLHHBagH8YO 2FNVh7FaFy9o9uA9pCcJ0bBfQDAM7I8w4QgWXleUr4nDdZhumt9FWtLgBM2TtjZk+ixyW7 80mhVnWwaMwv2uy/luEbbeb+sFK2haxI/Yh3liGimhxpX4fA1NUYo/Bykm0lOw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015487; 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=MpTsqbRm/7LUvkcxZ0AyD5uJRHhE5ALqrQ6PV/OvYUc=; b=Rqc5v9+zUQ+oABH3eVS3CDpEx390ImF/uMcW41yMzYE6744komWHBhxtLZ2WoumUxO5ViX nB9JP7YfNF+lv8CQ== 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 22/30] x86/cpu/topology: Mop up primary thread mask handling 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 Date: Tue, 23 Jan 2024 14:11:26 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The early initcall to initialize the primary thread mask is not longer required because topology_init_possible_cpus() can mark primary threads correctly when initializing the possible and present map as the number of SMT threads is already determined correctly. The XENPV workaround is not longer required because XENPV now registers fake APIC IDs which will just work like any other enumeration. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -82,30 +82,6 @@ static void cpu_mark_primary_thread(unsi if (smp_num_siblings =3D=3D 1 || !(apicid & mask)) cpumask_set_cpu(cpu, &__cpu_primary_thread_mask); } - -/* - * Due to the utter mess of CPUID evaluation smp_num_siblings is not valid - * during early boot. Initialize the primary thread mask before SMP - * bringup. - */ -static int __init smp_init_primary_thread_mask(void) -{ - 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 =3D 0; cpu < topo_info.nr_assigned_cpus; cpu++) - cpu_mark_primary_thread(cpu, cpuid_to_apicid[cpu]); - return 0; -} -early_initcall(smp_init_primary_thread_mask); #else static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int = apicid) { } #endif @@ -151,9 +127,6 @@ static void topo_set_cpuids(unsigned int #endif set_cpu_possible(cpu, true); set_cpu_present(cpu, true); - - if (system_state !=3D SYSTEM_BOOTING) - cpu_mark_primary_thread(cpu, apic_id); } =20 static __init bool check_for_real_bsp(u32 apic_id) @@ -276,6 +249,7 @@ int topology_hotplug_apic(u32 apic_id, u =20 set_bit(apic_id, phys_cpu_present_map); topo_set_cpuids(cpu, apic_id, acpi_id); + cpu_mark_primary_thread(cpu, apic_id); return cpu; } =20 @@ -411,6 +385,7 @@ void __init topology_init_possible_cpus( if (apicid =3D=3D BAD_APICID) continue; =20 + cpu_mark_primary_thread(cpu, apicid); set_cpu_present(cpu, test_bit(apicid, phys_cpu_present_map)); } } From nobody Fri Dec 19 02:50:56 2025 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 1646F664AE for ; Tue, 23 Jan 2024 13:11:30 +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=1706015491; cv=none; b=SwvBMBm8JEn+TTp2mObJlwqi+rMEM3tV58t8ZPzC7gL2t0vY9WLLRHPjEojBBe1bvbqFhYUwH/vGnGeDrYTB5JXpVkCkPDzCn+6bPqVy7Ze8sX8QSLb6MqnIPWVJraxAZjOB/9onR4ptNRftR0dMHK1amBshfQhh/fgwbAhYU04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015491; c=relaxed/simple; bh=Vn7gdV4WGfNx8aLyfIUr6q7nCYaATvUyyo4XK/qBAf4=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=rK/PQUVfd5WsXkWU4y+SBZGzfK5sLHb0ZWpGB9wmzJw1gYR6ovjsV3TEMkLEC7d8hq8KCPsUNk/WsFbBjycZqHF5bTcngR3CUhEAzJtVb0Bj5FAUblSl41/k8Kk22wzcZ1+insDiE4UvIANmmimrTVNvwahmKzqzeAhHNJBgSNw= 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=4gZenHUW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ff6/QnPC; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4gZenHUW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ff6/QnPC" Message-ID: <20240118123649.859589066@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015488; 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=z/7LKCK271zDhMePtD3LaOENCMpQvaSbIcr3vh7U/p4=; b=4gZenHUW0ZHyHU3KWNiCXBMCFACsK53OVjQX9jUZUSscAx4rIvzHJVeKv5GIE9CaAWlncs 3Q9vLvSZj/9xhzeN0CZ0YKuV8Tu+87X/CLHfWofGjWdRBkmCPrYUrzfCCK58wfwYUd38ju zvfsuQE9g1JM4MzLb1iiB6QBOO9YhKDXldJJZdc6pShpXU08rYZMKEwJ6U4YYsCPFHvu8t IqbUDmsvwIg8ojXMRNGaaixZZUB6kLBXGzpLmStnFugpjp+e9dQOUNMn7sRbPrFoQKeol3 PA9o+UAJ2MbuMzsekI+MiYXfwxWF3aN55Gd0daA/cZXfc9ufp911/JI7NsbLNA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015488; 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=z/7LKCK271zDhMePtD3LaOENCMpQvaSbIcr3vh7U/p4=; b=ff6/QnPCcCoCzV9cCY8Xb/KjEKlFohr0aBbSm4BPQJMXVngYfhiyEygy4Q14b6cozzKvP0 srY35JEAdoPwjMCw== 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 23/30] x86/cpu/topology: Simplify cpu_mark_primary_thread() 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 Date: Tue, 23 Jan 2024 14:11:27 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner No point in creating a mask via fls(). smp_num_siblings is guaranteed to be a power of 2. So just using (smp_num_siblings - 1) has the same effect. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -76,10 +76,7 @@ bool arch_match_cpu_phys_id(int cpu, u64 #ifdef CONFIG_SMP static void cpu_mark_primary_thread(unsigned int cpu, unsigned int apicid) { - /* Isolate the SMT bit(s) in the APICID and check for 0 */ - u32 mask =3D (1U << (fls(smp_num_siblings) - 1)) - 1; - - if (smp_num_siblings =3D=3D 1 || !(apicid & mask)) + if (!(apicid & (smp_num_siblings - 1))) cpumask_set_cpu(cpu, &__cpu_primary_thread_mask); } #else From nobody Fri Dec 19 02:50:56 2025 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 BC7F6664D0 for ; Tue, 23 Jan 2024 13:11:31 +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=1706015493; cv=none; b=IrlW84IVAir9KDj/f2pWcdJWhlBwqTIZrfIOSs9JtrlAHqxsD72Po4XTveIjq4/vFW0zCJUSLrEEHnxLJHBH4aTxzESRU+FfFoolOmOZCwe8eVi64HIgQGapH4P26lNMDclzUiifHO/mhVaozxYbV4Y/n6eJG3xmnRW4FTNqc3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015493; c=relaxed/simple; bh=Ct1lFW4Zt/3ZqqheSth0KhDYtCQXFpSWEQCu55WXYkw=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=bigcGeYAJNyVXHYIYWgJw5prH4iGFH34m9bVEDVJvPKngLRSkFQl0SQIj/Z60oQNDwowTe48NlqaK9J4dgaoSavwzB9DZy3Cc+O+wWl4KucKqUY2deIbTqONEltIosDBTcYp2+jTt169iwBBtKBp+V2X8fOlVol0OS9xVbcCFZw= 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=uX7ei09C; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VupscB6T; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uX7ei09C"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VupscB6T" Message-ID: <20240118123649.915802822@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015490; 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=6dhXYTos6w2yCRv5UATW39ekFguDcopd4GmFr46wLNc=; b=uX7ei09CmEb2eLpMfy2gC3gSHRHchP66lsJYQAt6PCqGtokPPQ+6SpykwWKm2iilmGd2/b we3INiR+R+4PjECbR9AITlaUa2W4z12zuirWewkule9D8qunYkYGR4vDu08ccYKDut60XD XeTc4DCNgediYHZH+oxQX/ZLJXxPKCR/3FHh/or3fiKuokDyoo7GZHQwVNKjZg3gZY57gU 7vJ0Vg0xmQH4ChZvi0uPJ6bSE/wNTa/ZT2g2wSDrJaXlDmcD88aFUL9xp/sdAhGfjNT0/O S2GNVW+AKM+/UUfmoFsOinb6OLpzn0LVklyrCCg46UW3nG3iycF9dGAanxsWKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015490; 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=6dhXYTos6w2yCRv5UATW39ekFguDcopd4GmFr46wLNc=; b=VupscB6TiZJvbX/r88yiwLAU9JMmN9+p80jDdh2UfuBQ3F12tKQs+qfR9A+MpPthaW/k72 dDKCL98TdIizKoCw== 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 24/30] x86/cpu/topology: Provide logical pkg/die mapping 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 Date: Tue, 23 Jan 2024 14:11:29 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner With the topology bitmaps in place the logical package and die IDs can trivially be retrieved by determining the bitmap weight of the relevant topology domain level up to and including the physical ID in question. Provide a function to that effect. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/topology.h | 9 +++++++++ arch/x86/kernel/cpu/topology.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -156,6 +156,15 @@ static inline unsigned int topology_max_ return __max_dies_per_package; } =20 +#ifdef CONFIG_X86_LOCAL_APIC +int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level= ); +#else +static inline int topology_get_logical_id(u32 apicid, enum x86_topology_do= mains at_level) +{ + return 0; +} +#endif + #ifdef CONFIG_SMP #define topology_cluster_id(cpu) (cpu_data(cpu).topo.l2c_id) #define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu)) --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -230,6 +230,34 @@ void __init topology_register_boot_apic( topo_register_apic(apic_id, CPU_ACPIID_INVALID, true); } =20 +/** + * topology_get_logical_id - Retrieve the logical ID at a given topology d= omain level + * @apicid: The APIC ID for which to lookup the logical ID + * @at_level: The topology domain level to use + * + * @apicid must be a full APIC ID, not the normalized variant. It's valid = to have + * all bits below the domain level specified by @at_level to be clear. So = both + * real APIC IDs and backshifted normalized APIC IDs work correctly. + * + * Returns: + * - >=3D 0: The requested logical ID + * - -ERANGE: @apicid is out of range + * - -ENODEV: @apicid is not registered + */ +int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level) +{ + /* Remove the bits below @at_level to get the proper level ID of @apicid = */ + unsigned int lvlid =3D topo_apicid(apicid, at_level); + + if (lvlid >=3D MAX_LOCAL_APIC) + return -ERANGE; + if (!test_bit(lvlid, apic_maps[at_level].map)) + return -ENODEV; + /* Get the number of set bits before @lvlid. */ + return bitmap_weight(apic_maps[at_level].map, lvlid); +} +EXPORT_SYMBOL_GPL(topology_get_logical_id); + #ifdef CONFIG_ACPI_HOTPLUG_CPU /** * topology_hotplug_apic - Handle a physical hotplugged APIC after boot From nobody Fri Dec 19 02:50:56 2025 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 58AD95EE99 for ; Tue, 23 Jan 2024 13:11:33 +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=1706015495; cv=none; b=UFJo5QrZkPqOSbAu115qgx4Kn8bcvJd1l0BmQAf1RN1r8nUQ4IdZcwUo5SY90SnX0YEasstQ/VB2ZzwEp4ekenQcvW6LtOuh8A4GZ0/qD12BwXGo9ERZTVW7Z0dXEgqI5Jak9GzPgXFUDSwffKd+uEhPoXXLzTyriJXhltzqd+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015495; c=relaxed/simple; bh=sdtYh6r2Z14DafjN7D+MaaZ8HLvRpnQtBgmsu94D0eQ=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=KaTvApj7vkMKal3kxpmoHXJLKZbU/yb40XqUezAVxVYNFy+wziJOMIa+lcgQNSjnub8HUKmNualiUgR6NcTbq+ZGcubrDD0YtIU5/pa3LQD7NJGNLFwisStr1pV+lEOupLyfa43bEQOvsOSzXJvkwwYl0wp7BPumiOabkf99zzs= 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=vsLYsE/w; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Q/HTN2I7; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vsLYsE/w"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Q/HTN2I7" Message-ID: <20240118123649.971809766@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015491; 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=l/8jC0XhRJ5zXpi1b6/tT+0MXsWhYQZ2bLtSZA+rv0E=; b=vsLYsE/wr+gnASvhYILxAnL1PDkW36TGAFxEEm4excXqGPauQmrdiwWIlAbr915INb/1w4 5lylWOXbZWeIg2+Zem8AVV03kXFHEtZQpapAtDJCUQDIG0N/ZKowUHDJUWpeI8/PQfbrP7 DggdN57qOoCSfzMwNFPUDkOHyg+v/Yx3AesUP3Lxa6oTKwG/Tamw4CKfogDIpdOhBOauSB NBvoum9NWJYgCSJzxXhGNQEqaOeGgEgTDHlU1OyQyB2um9A302owqHlDwHAVFmREAB9/ZQ UZaaASJ/+z3Jh5Wo0SoTwasP6CGfqX/o3nSjhLbGEf8HTAFphjZmtmPkN6Wk7w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015491; 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=l/8jC0XhRJ5zXpi1b6/tT+0MXsWhYQZ2bLtSZA+rv0E=; b=Q/HTN2I7emFiPUaTVJoFnbFqF+O7ITtcGhsprEkBMWPjeEobQhvYHHyoH6OTbMccGkaeJ8 xDkYWoOa/xJ9+rCg== 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 25/30] x86/cpu/topology: Use topology logical mapping mechanism 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 Date: Tue, 23 Jan 2024 14:11:30 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Replace the logical package and die management functionality and retrieve the logical IDs from the topology bitmaps. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/topology.h | 15 ++-- arch/x86/kernel/cpu/common.c | 13 --- arch/x86/kernel/cpu/topology_common.c | 4 + arch/x86/kernel/smpboot.c | 111 -----------------------------= ----- 4 files changed, 12 insertions(+), 131 deletions(-) --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -172,6 +172,13 @@ static inline int topology_get_logical_i #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) #define topology_sibling_cpumask(cpu) (per_cpu(cpu_sibling_map, cpu)) =20 + +static inline int topology_phys_to_logical_pkg(unsigned int pkg) +{ + return topology_get_logical_id(pkg << x86_topo_system.dom_shifts[TOPO_PKG= _DOMAIN], + TOPO_PKG_DOMAIN); +} + extern int __max_smt_threads; =20 static inline int topology_max_smt_threads(void) @@ -181,10 +188,6 @@ static inline int topology_max_smt_threa =20 #include =20 -int topology_update_package_map(unsigned int apicid, unsigned int cpu); -int topology_update_die_map(unsigned int dieid, unsigned int cpu); -int topology_phys_to_logical_pkg(unsigned int pkg); - extern unsigned int __amd_nodes_per_pkg; =20 static inline unsigned int topology_amd_nodes_per_pkg(void) @@ -205,10 +208,6 @@ static inline bool topology_is_primary_t } =20 #else /* CONFIG_SMP */ -static inline int -topology_update_package_map(unsigned int apicid, unsigned int cpu) { retur= n 0; } -static inline int -topology_update_die_map(unsigned int dieid, unsigned int cpu) { return 0; } static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return = 0; } static inline int topology_max_smt_threads(void) { return 1; } static inline bool topology_is_primary_thread(unsigned int cpu) { return t= rue; } --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1718,18 +1718,6 @@ static void generic_identify(struct cpui #endif } =20 -static void update_package_map(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned int cpu =3D smp_processor_id(); - - BUG_ON(topology_update_package_map(c->topo.pkg_id, cpu)); - BUG_ON(topology_update_die_map(c->topo.die_id, cpu)); -#else - c->topo.logical_pkg_id =3D 0; -#endif -} - /* * This does the hard work of actually picking apart the CPU stuff... */ @@ -1913,7 +1901,6 @@ void identify_secondary_cpu(struct cpuin #ifdef CONFIG_X86_32 enable_sep_cpu(); #endif - update_package_map(c); x86_spec_ctrl_setup_ap(); update_srbds_msr(); if (boot_cpu_has_bug(X86_BUG_GDS)) --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -10,6 +10,7 @@ #include "cpu.h" =20 struct x86_topology_system x86_topo_system __ro_after_init; +EXPORT_SYMBOL_GPL(x86_topo_system); =20 unsigned int __amd_nodes_per_pkg __ro_after_init; EXPORT_SYMBOL_GPL(__amd_nodes_per_pkg); @@ -147,6 +148,9 @@ static void topo_set_ids(struct topo_sca c->topo.pkg_id =3D topo_shift_apicid(apicid, TOPO_PKG_DOMAIN); c->topo.die_id =3D topo_shift_apicid(apicid, TOPO_DIE_DOMAIN); =20 + c->topo.logical_pkg_id =3D topology_get_logical_id(apicid, TOPO_PKG_DOMAI= N); + c->topo.logical_die_id =3D topology_get_logical_id(apicid, TOPO_DIE_DOMAI= N); + /* Package relative core ID */ c->topo.core_id =3D (apicid & topo_domain_mask(TOPO_PKG_DOMAIN)) >> x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN]; --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -125,23 +125,6 @@ struct mwait_cpu_dead { */ static DEFINE_PER_CPU_ALIGNED(struct mwait_cpu_dead, mwait_cpu_dead); =20 -/* Logical package management. */ -struct logical_maps { - u32 phys_pkg_id; - u32 phys_die_id; - u32 logical_pkg_id; - u32 logical_die_id; -}; - -/* Temporary workaround until the full topology mechanics is in place */ -static DEFINE_PER_CPU_READ_MOSTLY(struct logical_maps, logical_maps) =3D { - .phys_pkg_id =3D U32_MAX, - .phys_die_id =3D U32_MAX, -}; - -static unsigned int logical_packages __read_mostly; -static unsigned int logical_die __read_mostly; - /* Maximum number of SMT threads on any online core */ int __read_mostly __max_smt_threads =3D 1; =20 @@ -334,103 +317,11 @@ static void notrace start_secondary(void cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); } =20 -/** - * topology_phys_to_logical_pkg - Map a physical package id to a logical - * @phys_pkg: The physical package id to map - * - * Returns logical package id or -1 if not found - */ -int topology_phys_to_logical_pkg(unsigned int phys_pkg) -{ - int cpu; - - for_each_possible_cpu(cpu) { - if (per_cpu(logical_maps.phys_pkg_id, cpu) =3D=3D phys_pkg) - return per_cpu(logical_maps.logical_pkg_id, cpu); - } - return -1; -} -EXPORT_SYMBOL(topology_phys_to_logical_pkg); - -/** - * topology_phys_to_logical_die - Map a physical die id to logical - * @die_id: The physical die id to map - * @cur_cpu: The CPU for which the mapping is done - * - * Returns logical die id or -1 if not found - */ -static int topology_phys_to_logical_die(unsigned int die_id, unsigned int = cur_cpu) -{ - int cpu, proc_id =3D cpu_data(cur_cpu).topo.pkg_id; - - for_each_possible_cpu(cpu) { - if (per_cpu(logical_maps.phys_pkg_id, cpu) =3D=3D proc_id && - per_cpu(logical_maps.phys_die_id, cpu) =3D=3D die_id) - return per_cpu(logical_maps.logical_die_id, cpu); - } - return -1; -} - -/** - * topology_update_package_map - Update the physical to logical package map - * @pkg: The physical package id as retrieved via CPUID - * @cpu: The cpu for which this is updated - */ -int topology_update_package_map(unsigned int pkg, unsigned int cpu) -{ - int new; - - /* Already available somewhere? */ - new =3D topology_phys_to_logical_pkg(pkg); - if (new >=3D 0) - goto found; - - new =3D logical_packages++; - if (new !=3D pkg) { - pr_info("CPU %u Converting physical %u to logical package %u\n", - cpu, pkg, new); - } -found: - per_cpu(logical_maps.phys_pkg_id, cpu) =3D pkg; - per_cpu(logical_maps.logical_pkg_id, cpu) =3D new; - cpu_data(cpu).topo.logical_pkg_id =3D new; - return 0; -} -/** - * topology_update_die_map - Update the physical to logical die map - * @die: The die id as retrieved via CPUID - * @cpu: The cpu for which this is updated - */ -int topology_update_die_map(unsigned int die, unsigned int cpu) -{ - int new; - - /* Already available somewhere? */ - new =3D topology_phys_to_logical_die(die, cpu); - if (new >=3D 0) - goto found; - - new =3D logical_die++; - if (new !=3D die) { - pr_info("CPU %u Converting physical %u to logical die %u\n", - cpu, die, new); - } -found: - per_cpu(logical_maps.phys_die_id, cpu) =3D die; - per_cpu(logical_maps.logical_die_id, cpu) =3D new; - cpu_data(cpu).topo.logical_die_id =3D new; - return 0; -} - static void __init smp_store_boot_cpu_info(void) { - int id =3D 0; /* CPU 0 */ - struct cpuinfo_x86 *c =3D &cpu_data(id); + struct cpuinfo_x86 *c =3D &cpu_data(0); =20 *c =3D boot_cpu_data; - c->cpu_index =3D id; - topology_update_package_map(c->topo.pkg_id, id); - topology_update_die_map(c->topo.die_id, id); c->initialized =3D true; } From nobody Fri Dec 19 02:50:56 2025 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 B9A3C5FBBA for ; Tue, 23 Jan 2024 13:11:34 +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=1706015496; cv=none; b=FmnNdoy114g4fz9VMKtrCeoyAhmslVnd+WslnvV9kKLmUreTPlFNYGycKHM7DYUsAo0Xs9P41E7Xw3qxUfkBRTDk/tnHJcDNgEOEtkFNlvxZWiFfsblW9BcWEv608ezqyp10CDZdMlRpEgpq3dhz8eJfEHsxzM4Mya2JIw+A4zA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015496; c=relaxed/simple; bh=Z9yw3YyaWf/olDEzkdLgsFrWom4D6GNMQs0khKomLNA=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=u6cQgEOkPnbFxA3+aov4giDOSWfUAijQHeYuyDjRxMLk6gGFw21BALZ/5ZTLNcVx+sUxVpnoBv7gUg5IEZZ6DGYzrOAJyusIOBUUJYR3tfSrEiKjb6DnLW2VzUIG7VVlq33QalWBug8646arRVigV+NS3as1Jt2V9yIFvTgs+u0= 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=FJQ9QwoG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tBIZzr0z; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FJQ9QwoG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tBIZzr0z" Message-ID: <20240118123650.028320632@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015493; 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=Kanh4hNmVgcEwESDgRk7QWiOR9DqNwiGAJLu7VeT5K8=; b=FJQ9QwoGLpV5KQ7JkDijCKEG7ND0BHqtBLKciJelC+Ls3KGt4c+GrtfJgq6e2P/YimOOKl B5evuxh/z6GfeBxoQ+pM8zh+osMTfoPw7fDu/jkPMKVlAobOTH7nUM5m5StAJzUB5IEXRK wbijvK0Hv2rLcWtgQk4dlZKvCFTJMc91/CBsk7IITQa6PpZFPRMLGikgh0GJvXWrbBs52Z pjqAdy1cv9I1NBh5QW37aN6owpBreKjoVsr4HPz3glOSds0sBx7Y6AoTTiTWqYaGsSp1k9 xlryqBV7GlH412l+YrDQHUJzXpqw7ONTmlwPWqlajV019TdTbClXws7YVb4iaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015493; 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=Kanh4hNmVgcEwESDgRk7QWiOR9DqNwiGAJLu7VeT5K8=; b=tBIZzr0zcd41M3KUVhreoomqEKMc4lU+YzqBUputj1joT31gm9NbhlIsHfmqVYR0YExC9+ cvt7WX4hlb7N58Dw== 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 26/30] x86/cpu/topology: Retrieve cores per package from topology bitmaps 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 Date: Tue, 23 Jan 2024 14:11:32 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Similar to other sizing information the number of cores per package can be established from the topology bitmap. Provide a function for retrieving that information and replace the buggy hack in the CPUID evaluation with it. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/topology.c | 43 +++++++++++++++++++++++++++++= +++++ arch/x86/kernel/cpu/topology.h | 11 ++++++++ arch/x86/kernel/cpu/topology_common.c | 18 ++------------ 3 files changed, 57 insertions(+), 15 deletions(-) --- --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -217,6 +217,49 @@ int topology_get_logical_id(u32 apicid, } EXPORT_SYMBOL_GPL(topology_get_logical_id); =20 +/** + * topology_unit_count - Retrieve the count of specified units at a given = topology domain level + * @apicid: The APIC ID which specifies the search range + * @which_units: The domain level specifying the units to count + * @at_level: The domain level at which @which_units have to be counted + * + * This returns the number of possible units according to the enumerated + * information. + * + * E.g. topology_count_units(apicid, TOPO_CORE_DOMAIN, TOPO_PKG_DOMAIN) + * counts the number of possible cores in the package to which @apicid + * belongs. + * + * @at_level must obviously be greater than @which_level to produce useful + * results. If @at_level is equal to @which_units the result is + * unsurprisingly 1. If @at_level is less than @which_units the results + * is by definition undefined and the function returns 0. + */ +unsigned int topology_unit_count(u32 apicid, enum x86_topology_domains whi= ch_units, + enum x86_topology_domains at_level) +{ + /* Remove the bits below @at_level to get the proper level ID of @apicid = */ + unsigned int lvlid =3D topo_apicid(apicid, at_level); + unsigned int id, end, cnt =3D 0; + + if (lvlid >=3D MAX_LOCAL_APIC) + return 0; + if (!test_bit(lvlid, apic_maps[at_level].map)) + return 0; + if (which_units > at_level) + return 0; + if (which_units =3D=3D at_level) + return 1; + + /* Calculate the exclusive end */ + end =3D lvlid + (1U << x86_topo_system.dom_shifts[at_level]); + /* Unfortunately there is no bitmap_weight_range() */ + for (id =3D find_next_bit(apic_maps[which_units].map, end, lvlid); + id < end; id =3D find_next_bit(apic_maps[which_units].map, end, ++id= )) + cnt++; + return cnt; +} + #ifdef CONFIG_ACPI_HOTPLUG_CPU /** * topology_hotplug_apic - Handle a physical hotplugged APIC after boot --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -53,4 +53,15 @@ static inline void topology_update_dom(s tscan->dom_ncpus[dom] =3D ncpus; } =20 +#ifdef CONFIG_X86_LOCAL_APIC +unsigned int topology_unit_count(u32 apicid, enum x86_topology_domains whi= ch_units, + enum x86_topology_domains at_level); +#else +static inline unsigned int topology_unit_count(u32 apicid, enum x86_topolo= gy_domains which_units, + enum x86_topology_domains at_level) +{ + return 1; +} +#endif + #endif /* ARCH_X86_TOPOLOGY_H */ --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -155,25 +155,15 @@ static void topo_set_ids(struct topo_sca c->topo.core_id =3D (apicid & topo_domain_mask(TOPO_PKG_DOMAIN)) >> x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN]; =20 + /* Maximum number of cores on this package */ + c->x86_max_cores =3D topology_unit_count(apicid, TOPO_CORE_DOMAIN, TOPO_P= KG_DOMAIN); + c->topo.amd_node_id =3D tscan->amd_node_id; =20 if (c->x86_vendor =3D=3D X86_VENDOR_AMD) cpu_topology_fixup_amd(tscan); } =20 -static void topo_set_max_cores(struct topo_scan *tscan) -{ - /* - * Bug compatible for now. This is broken on hybrid systems: - * 8 cores SMT + 8 cores w/o SMT - * tscan.dom_ncpus[TOPO_DIEGRP_DOMAIN] =3D 24; 24 / 2 =3D 12 !! - * - * Cannot be fixed without further topology enumeration changes. - */ - tscan->c->x86_max_cores =3D tscan->dom_ncpus[TOPO_DIEGRP_DOMAIN] >> - x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN]; -} - void cpu_parse_topology(struct cpuinfo_x86 *c) { unsigned int dom, cpu =3D smp_processor_id(); @@ -201,7 +191,6 @@ void cpu_parse_topology(struct cpuinfo_x } =20 topo_set_ids(&tscan); - topo_set_max_cores(&tscan); } =20 void __init cpu_init_topology(struct cpuinfo_x86 *c) @@ -223,7 +212,6 @@ void __init cpu_init_topology(struct cpu } =20 topo_set_ids(&tscan); - topo_set_max_cores(&tscan); =20 /* * AMD systems have Nodes per package which cannot be mapped to From nobody Fri Dec 19 02:50:56 2025 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 EBD8866B3C for ; Tue, 23 Jan 2024 13:11:36 +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=1706015498; cv=none; b=CWIt7O5fah89WRkYL6cmGjnF/iqWoHXLq4dRXcpA9Vdhev4nbkxyn0OiJws1U3gleiRxIJ9Le0JMbZ6AdZh2OoKuX/Du/pvpb2/dnkiMCQPYHZZqR5aW2RnZUdRX+A6Wa9B2RMc0r9f9PUAXtFKRylvg2uLR0aUuOfchseMoeVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015498; c=relaxed/simple; bh=huGxQ3Ewzo2baC8rW+ihghAztBYkv0M3yYI9hmLu2ro=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=HaBVVq0m6smz9JbSTc3aATXpRKFdTkMHexYbyUfYAqLWnmgFzrEBhnmmHU+fCyySmpdqBgtsHd96qUvVKpUbTaehv3SuqHys+EfRE0IlN2fHYfsgf6u4fHAJDAi705RdvyxOhDNGrsQXNBRLhfp+7CFzWUb87MCN2U0oucHscIM= 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=aEW3K2YA; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=62mD8VSh; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aEW3K2YA"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="62mD8VSh" Message-ID: <20240118123650.084780415@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015495; 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=bfqHmBUeka7dQBa99Hi1JjEcqixFoWdCveZJ0DsGFw8=; b=aEW3K2YA0L5U6yZBdf7fH3Sikj4gnItzKDoUldMQ2W7IgjuVAmfyiRIUkYAlnOnosFBa6/ qjPVcIZeiig0UgMOLVH5tfxD9zLcIlUPfD3IF6gz9drJKrLRgnf2Gsznyp942LWgb7nnVv u6Zpfois3phLSD+/tsgSY5CPOIdeYE7tfKAr5lo5vmOL4s/Ye6vb7zRk/CcnFLVCTWHQWv xey73WCdwnp3Jv+1MPiCcjBzRgAfJPs0TiSbVvBZa2Gc1CktcZJKLtZNpKSSUzhPQCuiut udG8xHM30bO7mtjq+GU+++EkDDhEV3PkKONb+deYKVaunCoQRpCHIuhqkMyzUQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015495; 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=bfqHmBUeka7dQBa99Hi1JjEcqixFoWdCveZJ0DsGFw8=; b=62mD8VShiNiDuG+xMgN59PhRW3sDtLcRTNDnyW6Nszj1VwAJNcdP5mMD6qpwAEIFwoM8Z7 ivWQaCEsOpu2J6Bg== 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 27/30] x86/cpu/topology: Rename smp_num_siblings 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 Date: Tue, 23 Jan 2024 14:11:33 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner It's really a non-intuitive name. Rename it to __max_threads_per_core which is obvious. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/perf_event_p4.h | 4 ++-- arch/x86/include/asm/smp.h | 2 -- arch/x86/include/asm/topology.h | 1 + arch/x86/kernel/cpu/common.c | 6 +++--- arch/x86/kernel/cpu/debugfs.c | 2 +- arch/x86/kernel/cpu/mce/inject.c | 2 +- arch/x86/kernel/cpu/topology.c | 6 +++--- arch/x86/kernel/process.c | 2 +- arch/x86/kernel/smpboot.c | 2 +- 9 files changed, 13 insertions(+), 14 deletions(-) --- --- a/arch/x86/include/asm/perf_event_p4.h +++ b/arch/x86/include/asm/perf_event_p4.h @@ -181,7 +181,7 @@ static inline u64 p4_clear_ht_bit(u64 co static inline int p4_ht_active(void) { #ifdef CONFIG_SMP - return smp_num_siblings > 1; + return __max_threads_per_core > 1; #endif return 0; } @@ -189,7 +189,7 @@ static inline int p4_ht_active(void) static inline int p4_ht_thread(int cpu) { #ifdef CONFIG_SMP - if (smp_num_siblings =3D=3D 2) + if (__max_threads_per_core =3D=3D 2) return cpu !=3D cpumask_first(this_cpu_cpumask_var_ptr(cpu_sibling_map)); #endif return 0; --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -8,8 +8,6 @@ #include #include =20 -extern unsigned int smp_num_siblings; - DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map); --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -145,6 +145,7 @@ extern const struct cpumask *cpu_cluster =20 extern unsigned int __max_dies_per_package; extern unsigned int __max_logical_packages; +extern unsigned int __max_threads_per_core; =20 static inline unsigned int topology_max_packages(void) { --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -72,8 +72,8 @@ u32 elf_hwcap2 __read_mostly; =20 /* Number of siblings per CPU package */ -unsigned int smp_num_siblings __ro_after_init =3D 1; -EXPORT_SYMBOL(smp_num_siblings); +unsigned int __max_threads_per_core __ro_after_init =3D 1; +EXPORT_SYMBOL(__max_threads_per_core); =20 unsigned int __max_dies_per_package __ro_after_init =3D 1; EXPORT_SYMBOL(__max_dies_per_package); @@ -2249,7 +2249,7 @@ void __init arch_cpu_finalize_init(void) * identify_boot_cpu() initialized SMT support information, let the * core code know. */ - cpu_smt_set_num_threads(smp_num_siblings, smp_num_siblings); + cpu_smt_set_num_threads(__max_threads_per_core, __max_threads_per_core); =20 if (!IS_ENABLED(CONFIG_SMP)) { pr_info("CPU: "); --- a/arch/x86/kernel/cpu/debugfs.c +++ b/arch/x86/kernel/cpu/debugfs.c @@ -30,7 +30,7 @@ static int cpu_debug_show(struct seq_fil seq_printf(m, "amd_nodes_per_pkg: %u\n", topology_amd_nodes_per_pkg()); seq_printf(m, "max_cores: %u\n", c->x86_max_cores); seq_printf(m, "max_dies_per_pkg: %u\n", __max_dies_per_package); - seq_printf(m, "smp_num_siblings: %u\n", smp_num_siblings); + seq_printf(m, "max_threads_per_core:%u\n", __max_threads_per_core); return 0; } =20 --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -433,7 +433,7 @@ static u32 get_nbc_for_node(int node_id) struct cpuinfo_x86 *c =3D &boot_cpu_data; u32 cores_per_node; =20 - cores_per_node =3D (c->x86_max_cores * smp_num_siblings) / topology_amd_n= odes_per_pkg(); + cores_per_node =3D (c->x86_max_cores * __max_threads_per_core) / topology= _amd_nodes_per_pkg(); return cores_per_node * node_id; } =20 --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -76,7 +76,7 @@ bool arch_match_cpu_phys_id(int cpu, u64 #ifdef CONFIG_SMP static void cpu_mark_primary_thread(unsigned int cpu, unsigned int apicid) { - if (!(apicid & (smp_num_siblings - 1))) + if (!(apicid & (__max_threads_per_core - 1))) cpumask_set_cpu(cpu, &__cpu_primary_thread_mask); } #else @@ -417,8 +417,8 @@ void __init topology_init_possible_cpus( =20 cnta =3D domain_weight(TOPO_CORE_DOMAIN); cntb =3D domain_weight(TOPO_SMT_DOMAIN); - smp_num_siblings =3D 1U << (get_count_order(cntb) - get_count_order(cnta)= ); - pr_info("Max. threads per core: %3u\n", smp_num_siblings); + __max_threads_per_core =3D 1U << (get_count_order(cntb) - get_count_order= (cnta)); + pr_info("Max. threads per core: %3u\n", __max_threads_per_core); =20 pr_info("Allowing %u present CPUs plus %u hotplug CPUs\n", assigned, disa= bled); if (topo_info.nr_rejected_cpus) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -936,7 +936,7 @@ static __cpuidle void mwait_idle(void) void select_idle_routine(const struct cpuinfo_x86 *c) { #ifdef CONFIG_SMP - if (boot_option_idle_override =3D=3D IDLE_POLL && smp_num_siblings > 1) + if (boot_option_idle_override =3D=3D IDLE_POLL && __max_threads_per_core = > 1) pr_warn_once("WARNING: polling idle and HT enabled, performance may degr= ade\n"); #endif if (x86_idle_set() || boot_option_idle_override =3D=3D IDLE_POLL) --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -563,7 +563,7 @@ static void __init build_sched_topology( =20 void set_cpu_sibling_map(int cpu) { - bool has_smt =3D smp_num_siblings > 1; + bool has_smt =3D __max_threads_per_core > 1; bool has_mp =3D has_smt || boot_cpu_data.x86_max_cores > 1; struct cpuinfo_x86 *c =3D &cpu_data(cpu); struct cpuinfo_x86 *o; From nobody Fri Dec 19 02:50:56 2025 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 6015166B52 for ; Tue, 23 Jan 2024 13:11:38 +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=1706015500; cv=none; b=oRHD2Ao2nhMEzHkBj9aVaz/TA2O5/TrQUvwAevvzvkPXE4CP9hC9Jc356IPcl2x7wrp63h5AMbzlaT5stLaSVyg79wju0UmOQkRHqiqgNj8BOQmZIJufu1AqPN5164SrQ4nRPmQTCtr6+Ow2naCXkBsK0RMSXOokMo7gWnoyN+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015500; c=relaxed/simple; bh=evvK7ga7udVVxA8A5oaBHks8qKmsIHUbst7bXfEr5X8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=Twc5v1z28aM602pCdVPoP6TTzpPXYMRgpo9ZR5CbHlKLPT2oF9GdLOIYbpgTVR05kw1Z50cMaBq+cjU3N65lpdqCYa/vfhES5SkaOIFxqDy9RuwhhQ5XvBPo6PX6Y61XvuKNk9+PcTjQlS8XG24I28ZQo649WLddf1h/Saqywfc= 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=k3CVQvDR; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=p9vjR1pw; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k3CVQvDR"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="p9vjR1pw" Message-ID: <20240118123650.140932565@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015496; 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=NtCn1qIjdDagUvktcocvZnySBrSVkEHTjg+7jYEXYkc=; b=k3CVQvDRCvPF8Cbv3D1LJfnFe8ZqE1LdOR7FDjch0AP3QqC0hhYkD0QGgYZZs7ZUyt/wm7 sKYgb9uxd4gTqvUIhzKosEMnJdqXdlEcBYBREpYKiXbnxP/vzlWleTbHRWqbNhIXG5QrcE m87Hsdd6WiFCJducFUQjuQzC1Cg7ddkSxlVEcXzNlaR//Hy+d3jPtLOcGEszMFTSwlbk7e dpdlwagIjP+iLB7F9D4Q/V+D4btoGE5tMxYFozFAk3/lFIfh6sKNvQ3NrhwAdwFkIDkdO0 DSFDGs/08aKK99Mna48/IBA3QsKq4dNE3X6sjwB05PcK5zs6zQfU6MgCWGFnsA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015496; 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=NtCn1qIjdDagUvktcocvZnySBrSVkEHTjg+7jYEXYkc=; b=p9vjR1pwtgtuA3dBWfSxIoL0FWoPIHhLKXg8yLXmUM1OvrR6oGFq7Aw3rx2FdQIHtLQ8eW cqCCd941UModO8BA== 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 28/30] x86/cpu/topology: Rename topology_max_die_per_package() 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 Date: Tue, 23 Jan 2024 14:11:35 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The plural of die is dies. Signed-off-by: Thomas Gleixner --- arch/x86/events/intel/cstate.c | 2 +- arch/x86/events/intel/uncore.c | 2 +- arch/x86/events/intel/uncore_snbep.c | 2 +- arch/x86/events/rapl.c | 2 +- arch/x86/include/asm/topology.h | 2 +- drivers/hwmon/coretemp.c | 2 +- drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c | 2 +- drivers/powercap/intel_rapl_common.c | 2 +- drivers/thermal/intel/intel_hfi.c | 2 +- drivers/thermal/intel/intel_powerclamp.c | 2 +- drivers/thermal/intel/x86_pkg_temp_thermal.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) --- --- a/arch/x86/events/intel/cstate.c +++ b/arch/x86/events/intel/cstate.c @@ -834,7 +834,7 @@ static int __init cstate_init(void) } =20 if (has_cstate_pkg) { - if (topology_max_die_per_package() > 1) { + if (topology_max_dies_per_package() > 1) { err =3D perf_pmu_register(&cstate_pkg_pmu, "cstate_die", -1); } else { --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -1893,7 +1893,7 @@ static int __init intel_uncore_init(void return -ENODEV; =20 __uncore_max_dies =3D - topology_max_packages() * topology_max_die_per_package(); + topology_max_packages() * topology_max_dies_per_package(); =20 id =3D x86_match_cpu(intel_uncore_match); if (!id) { --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -1406,7 +1406,7 @@ static int topology_gidnid_map(int nodei */ for (i =3D 0; i < 8; i++) { if (nodeid =3D=3D GIDNIDMAP(gidnid, i)) { - if (topology_max_die_per_package() > 1) + if (topology_max_dies_per_package() > 1) die_id =3D i; else die_id =3D topology_phys_to_logical_pkg(i); --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -674,7 +674,7 @@ static const struct attribute_group *rap =20 static int __init init_rapl_pmus(void) { - int maxdie =3D topology_max_packages() * topology_max_die_per_package(); + int maxdie =3D topology_max_packages() * topology_max_dies_per_package(); size_t size; =20 size =3D sizeof(*rapl_pmus) + maxdie * sizeof(struct rapl_pmu *); --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -152,7 +152,7 @@ static inline unsigned int topology_max_ return __max_logical_packages; } =20 -static inline unsigned int topology_max_die_per_package(void) +static inline unsigned int topology_max_dies_per_package(void) { return __max_dies_per_package; } --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -780,7 +780,7 @@ static int __init coretemp_init(void) if (!x86_match_cpu(coretemp_ids)) return -ENODEV; =20 - max_zones =3D topology_max_packages() * topology_max_die_per_package(); + max_zones =3D topology_max_packages() * topology_max_dies_per_package(); zone_devices =3D kcalloc(max_zones, sizeof(struct platform_device *), GFP_KERNEL); if (!zone_devices) --- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c +++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c @@ -242,7 +242,7 @@ static int __init intel_uncore_init(void return -ENODEV; =20 uncore_max_entries =3D topology_max_packages() * - topology_max_die_per_package(); + topology_max_dies_per_package(); uncore_instances =3D kcalloc(uncore_max_entries, sizeof(*uncore_instances), GFP_KERNEL); if (!uncore_instances) --- a/drivers/powercap/intel_rapl_common.c +++ b/drivers/powercap/intel_rapl_common.c @@ -1564,7 +1564,7 @@ struct rapl_package *rapl_add_package(in if (id_is_cpu) { rp->id =3D topology_logical_die_id(id); rp->lead_cpu =3D id; - if (topology_max_die_per_package() > 1) + if (topology_max_dies_per_package() > 1) snprintf(rp->name, PACKAGE_DOMAIN_NAME_LENGTH, "package-%d-die-%d", topology_physical_package_id(id), topology_die_id(id)); else --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -581,7 +581,7 @@ void __init intel_hfi_init(void) =20 /* There is one HFI instance per die/package. */ max_hfi_instances =3D topology_max_packages() * - topology_max_die_per_package(); + topology_max_dies_per_package(); =20 /* * This allocation may fail. CPU hotplug callbacks must check --- a/drivers/thermal/intel/intel_powerclamp.c +++ b/drivers/thermal/intel/intel_powerclamp.c @@ -616,7 +616,7 @@ static int powerclamp_idle_injection_reg poll_pkg_cstate_enable =3D false; if (cpumask_equal(cpu_present_mask, idle_injection_cpu_mask)) { ii_dev =3D idle_inject_register_full(idle_injection_cpu_mask, idle_injec= t_update); - if (topology_max_packages() =3D=3D 1 && topology_max_die_per_package() = =3D=3D 1) + if (topology_max_packages() =3D=3D 1 && topology_max_dies_per_package() = =3D=3D 1) poll_pkg_cstate_enable =3D true; } else { ii_dev =3D idle_inject_register(idle_injection_cpu_mask); --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -494,7 +494,7 @@ static int __init pkg_temp_thermal_init( if (!x86_match_cpu(pkg_temp_thermal_ids)) return -ENODEV; =20 - max_id =3D topology_max_packages() * topology_max_die_per_package(); + max_id =3D topology_max_packages() * topology_max_dies_per_package(); zones =3D kcalloc(max_id, sizeof(struct zone_device *), GFP_KERNEL); if (!zones) From nobody Fri Dec 19 02:50:56 2025 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 0B08067745 for ; Tue, 23 Jan 2024 13:11:41 +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=1706015502; cv=none; b=sFLyXDaKBYmENPsS4/1InT5hF1E0lgGL1CAW7rpFOgvwwFpctWrR1GwnzEdIiiKe8GNWaJHQzqGqfcKrcI1u3j/DeVYi+0eGMtlPol0tOcrpp3pFSrnBHMp79OQJXuiHrCWxgA4FVv4cV1OUZIsfXeeHZcxvHxSiTzTZMtnh+Rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015502; c=relaxed/simple; bh=a7hyVcNtgOTV6ZyFP0GW+8CW5gYxmQj62A/C5scuKns=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=t4oz0AmiVAatRx2mnD/UkSNQfxmFGh16aowg1TvW/0BXTBiX+oTIsBvv4kNaHwAKLfFSjLhMRQ/H5XrQx/YY+4hpEJUW04jiT7lvXLgsKmpNxv53XjFjkakLv/DWqNHS5dyG7J4bWSTpmZwCw3lJ6hOitCyCNYzQ7J/32AjF8m0= 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=42W8aOdE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zKuaeNvg; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="42W8aOdE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zKuaeNvg" Message-ID: <20240118123650.197180058@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015499; 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=NchMEj6plFXnohvx3VS5b0MwN9MQsuMGVmncnXh1rOQ=; b=42W8aOdEwEdn3K3q6XuslbgC4efbM2IOiP0Fhz3ZoXmZF5eeSMorjJ+MKzDG0lV16wFJnK luTuVgt1qXuhf+yaIJFa1TgrzT5fQaW4T23zpQ1hqZAHDwzFL9Oy92u7HY4wz4seAiEQcq GX9jbHADZdBc312C20iLXhJZT7EMDzBMMRoLUvxUKZ3dJesJ7ueDBHlhlg+tXJoTeziCUV Pa/8NQVIdKKFGZKyQWWpIv/ns1LxHI5B1lPH05Rt5gnyKzAYhoZZBXtoRjMMrS7axOoJ/U 6lIcd38pbFtxkwuC48Uq5GC175ah7Kiu7a63cEtnvtyZGqnIgOqP+Qq6RmxYHQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015499; 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=NchMEj6plFXnohvx3VS5b0MwN9MQsuMGVmncnXh1rOQ=; b=zKuaeNvg/k+WXNIadQ3+SuKDxFRN6mz0sowRiaks93gSgk9VHhPPlRiNWSQdEfbihloJLR YeisJGt7nCFRWFDQ== 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 29/30] x86/cpu/topology: Provide __num_[cores|threads]_per_package 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 Date: Tue, 23 Jan 2024 14:11:37 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Expose properly accounted information and accessors so the fiddling with other topology variables can be replaced. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/topology.h | 12 ++++++++++++ arch/x86/kernel/cpu/common.c | 6 ++++++ arch/x86/kernel/cpu/topology.c | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-) --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -146,6 +146,8 @@ extern const struct cpumask *cpu_cluster extern unsigned int __max_dies_per_package; extern unsigned int __max_logical_packages; extern unsigned int __max_threads_per_core; +extern unsigned int __num_threads_per_package; +extern unsigned int __num_cores_per_package; =20 static inline unsigned int topology_max_packages(void) { @@ -157,6 +159,16 @@ static inline unsigned int topology_max_ return __max_dies_per_package; } =20 +static inline unsigned int topology_num_cores_per_package(void) +{ + return __num_cores_per_package; +} + +static inline unsigned int topology_num_threads_per_package(void) +{ + return __num_threads_per_package; +} + #ifdef CONFIG_X86_LOCAL_APIC int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level= ); #else --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -81,6 +81,12 @@ EXPORT_SYMBOL(__max_dies_per_package); unsigned int __max_logical_packages __ro_after_init =3D 1; EXPORT_SYMBOL(__max_logical_packages); =20 +unsigned int __num_cores_per_package __ro_after_init =3D 1; +EXPORT_SYMBOL(__num_cores_per_package); + +unsigned int __num_threads_per_package __ro_after_init =3D 1; +EXPORT_SYMBOL(__num_threads_per_package); + static struct ppin_info { int feature; int msr_ppin_ctl; --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -386,7 +386,7 @@ void __init topology_init_possible_cpus( unsigned int disabled =3D topo_info.nr_disabled_cpus; unsigned int cnta, cntb, cpu, allowed =3D 1; unsigned int total =3D assigned + disabled; - u32 apicid; + u32 apicid, firstid; =20 if (!restrict_to_up()) { if (WARN_ON_ONCE(assigned > nr_cpu_ids)) { @@ -422,6 +422,12 @@ void __init topology_init_possible_cpus( __max_threads_per_core =3D 1U << (get_count_order(cntb) - get_count_order= (cnta)); pr_info("Max. threads per core: %3u\n", __max_threads_per_core); =20 + firstid =3D find_first_bit(apic_maps[TOPO_SMT_DOMAIN].map, MAX_LOCAL_APIC= ); + __num_cores_per_package =3D topology_unit_count(firstid, TOPO_CORE_DOMAIN= , TOPO_PKG_DOMAIN); + pr_info("Num. cores per package: %3u\n", __num_cores_per_package); + __num_threads_per_package =3D topology_unit_count(firstid, TOPO_SMT_DOMAI= N, TOPO_PKG_DOMAIN); + pr_info("Num. threads per package: %3u\n", __num_threads_per_package); + pr_info("Allowing %u present CPUs plus %u hotplug CPUs\n", assigned, disa= bled); if (topo_info.nr_rejected_cpus) pr_info("Rejected CPUs %u\n", topo_info.nr_rejected_cpus); From nobody Fri Dec 19 02:50:56 2025 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 2D09067759 for ; Tue, 23 Jan 2024 13:11:41 +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=1706015503; cv=none; b=EcQM6ZPgq6q3rs0tmIVhufZvSlr8TeWPZ2gUlHbhoNBf0usk7s1Mx2byZSRbLk+nGRHv73lxuiKk0iV/EBW7SZ7aOI3txnV6cu1tyYKFWJADU7suKU867qvAi2gsK4bMTb3c837jnfjHSqRHzAjxlVadxN7HYKL3YFXTl1xi7Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706015503; c=relaxed/simple; bh=O8PAtX8pfo+fiAW/s8V3ywe8Lrl+NxLlS4N173AWA68=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=cLcvGESCiyvG9TnN7kAFnhpWfTExDivUQOgoPBab94R+oaeRghgqmbghO18u2tlvGJ199jaaGZbAmIPWYTz7IiDpWZ5PR01wwrfhB1j/DwCoz9cGfrlndIIyFkEMf6cVeCteSX0clY5uw2bf1jDVsAc507k3yW+8DWOuk3B9a1M= 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=wSOeptZk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=n32UEGzM; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wSOeptZk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="n32UEGzM" Message-ID: <20240118123650.253438239@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706015499; 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=MDB9nbznSrMD/b9LoNRbLQGrccIcibNBwWGQ1PLIlrY=; b=wSOeptZkfwOb1HX2TbpJY4PSgYbxcSY0BkaVpWrNPftNtskR9mOQW9vqN2XSJI2HhfoQ0d xYuNg+hLR7vUuJAEesEYVOGmelkP+j4vpxlAYUtF7IO8S8CX8XMv3PIaerX3QFxfMxfZrC GRtunUsnFvdXDbOCxcK/4j4FHwArxtslZIbc9hNw3MKKakME0dSiKkBN+Cp77Ymf4g7eyJ rFWBj/dnyCT6SGATn12k8lOPs2uaIw37dbZY6EP4k0U6zZXbAQG8J3pf6FRwKQ+wH6GLtc krH+SyPLEkcmRuvexQRdMf/PCKezdLjZEuMJzFK/qalyLj1RIIESYVdap5ZTDw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706015499; 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=MDB9nbznSrMD/b9LoNRbLQGrccIcibNBwWGQ1PLIlrY=; b=n32UEGzMLsBBI6jm+b/EFghYOUVuJAH0kp9HFl2EF4vyzkcfzg4c2vi61mwkLC9p7t16Cr xY8EuHiWjxVYumCQ== 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 30/30] x86/cpu/topology: Get rid of cpuinfo::x86_max_cores 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 Date: Tue, 23 Jan 2024 14:11:38 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Now that __num_cores_per_package and __num_threads_per_package are available, cpuinfo::x86_max_cores and the related math all over the place can be replaced with the ready to consume data. Signed-off-by: Thomas Gleixner --- Documentation/arch/x86/topology.rst | 24 ++++++++----------= ----- arch/x86/events/intel/uncore_nhmex.c | 4 +-- arch/x86/events/intel/uncore_snb.c | 8 +++---- arch/x86/events/intel/uncore_snbep.c | 16 +++++++-------- arch/x86/include/asm/processor.h | 2 - arch/x86/kernel/cpu/cacheinfo.c | 2 - arch/x86/kernel/cpu/common.c | 1=20 arch/x86/kernel/cpu/debugfs.c | 3 +- arch/x86/kernel/cpu/mce/inject.c | 3 -- arch/x86/kernel/cpu/microcode/intel.c | 2 - arch/x86/kernel/cpu/topology_common.c | 3 -- arch/x86/kernel/smpboot.c | 2 - drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 2 - drivers/hwmon/fam15h_power.c | 2 - 14 files changed, 31 insertions(+), 43 deletions(-) --- --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -47,17 +47,21 @@ AMD nomenclature for package is 'Node'. =20 Package-related topology information in the kernel: =20 - - cpuinfo_x86.x86_max_cores: + - topology_num_threads_per_package() =20 - The number of cores in a package. This information is retrieved via CP= UID. + The number of threads in a package. =20 - - cpuinfo_x86.x86_max_dies: + - topology_num_cores_per_package() =20 - The number of dies in a package. This information is retrieved via CPU= ID. + The number of cores in a package. + + - topology_max_dies_per_package() + + The maximum number of dies in a package. =20 - cpuinfo_x86.topo.die_id: =20 - The physical ID of the die. This information is retrieved via CPUID. + The physical ID of the die. =20 - cpuinfo_x86.topo.pkg_id: =20 @@ -96,16 +100,6 @@ are SMT- or CMT-type threads. AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses "core". =20 -Core-related topology information in the kernel: - - - smp_num_siblings: - - The number of threads in a core. The number of threads in a package ca= n be - calculated by:: - - threads_per_package =3D cpuinfo_x86.x86_max_cores * smp_num_siblings - - Threads =3D=3D=3D=3D=3D=3D=3D A thread is a single scheduling unit. It's the equivalent to a logical Lin= ux --- a/arch/x86/events/intel/uncore_nhmex.c +++ b/arch/x86/events/intel/uncore_nhmex.c @@ -1221,8 +1221,8 @@ void nhmex_uncore_cpu_init(void) uncore_nhmex =3D true; else nhmex_uncore_mbox.event_descs =3D wsmex_uncore_mbox_events; - if (nhmex_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) - nhmex_uncore_cbox.num_boxes =3D boot_cpu_data.x86_max_cores; + if (nhmex_uncore_cbox.num_boxes > topology_num_cores_per_package()) + nhmex_uncore_cbox.num_boxes =3D topology_num_cores_per_package(); uncore_msr_uncores =3D nhmex_msr_uncores; } /* end of Nehalem-EX uncore support */ --- a/arch/x86/events/intel/uncore_snb.c +++ b/arch/x86/events/intel/uncore_snb.c @@ -364,8 +364,8 @@ static struct intel_uncore_type *snb_msr void snb_uncore_cpu_init(void) { uncore_msr_uncores =3D snb_msr_uncores; - if (snb_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) - snb_uncore_cbox.num_boxes =3D boot_cpu_data.x86_max_cores; + if (snb_uncore_cbox.num_boxes > topology_num_cores_per_package()) + snb_uncore_cbox.num_boxes =3D topology_num_cores_per_package(); } =20 static void skl_uncore_msr_init_box(struct intel_uncore_box *box) @@ -428,8 +428,8 @@ static struct intel_uncore_type *skl_msr void skl_uncore_cpu_init(void) { uncore_msr_uncores =3D skl_msr_uncores; - if (skl_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) - skl_uncore_cbox.num_boxes =3D boot_cpu_data.x86_max_cores; + if (skl_uncore_cbox.num_boxes > topology_num_cores_per_package()) + skl_uncore_cbox.num_boxes =3D topology_num_cores_per_package(); snb_uncore_arb.ops =3D &skl_uncore_msr_ops; } =20 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -1172,8 +1172,8 @@ static struct intel_uncore_type *snbep_m =20 void snbep_uncore_cpu_init(void) { - if (snbep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) - snbep_uncore_cbox.num_boxes =3D boot_cpu_data.x86_max_cores; + if (snbep_uncore_cbox.num_boxes > topology_num_cores_per_package()) + snbep_uncore_cbox.num_boxes =3D topology_num_cores_per_package(); uncore_msr_uncores =3D snbep_msr_uncores; } =20 @@ -1845,8 +1845,8 @@ static struct intel_uncore_type *ivbep_m =20 void ivbep_uncore_cpu_init(void) { - if (ivbep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) - ivbep_uncore_cbox.num_boxes =3D boot_cpu_data.x86_max_cores; + if (ivbep_uncore_cbox.num_boxes > topology_num_cores_per_package()) + ivbep_uncore_cbox.num_boxes =3D topology_num_cores_per_package(); uncore_msr_uncores =3D ivbep_msr_uncores; } =20 @@ -2917,8 +2917,8 @@ static bool hswep_has_limit_sbox(unsigne =20 void hswep_uncore_cpu_init(void) { - if (hswep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) - hswep_uncore_cbox.num_boxes =3D boot_cpu_data.x86_max_cores; + if (hswep_uncore_cbox.num_boxes > topology_num_cores_per_package()) + hswep_uncore_cbox.num_boxes =3D topology_num_cores_per_package(); =20 /* Detect 6-8 core systems with only two SBOXes */ if (hswep_has_limit_sbox(HSWEP_PCU_DID)) @@ -3280,8 +3280,8 @@ static struct event_constraint bdx_uncor =20 void bdx_uncore_cpu_init(void) { - if (bdx_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) - bdx_uncore_cbox.num_boxes =3D boot_cpu_data.x86_max_cores; + if (bdx_uncore_cbox.num_boxes > topology_num_cores_per_package()) + bdx_uncore_cbox.num_boxes =3D topology_num_cores_per_package(); uncore_msr_uncores =3D bdx_msr_uncores; =20 /* Detect systems with no SBOXes */ --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -149,8 +149,6 @@ struct cpuinfo_x86 { unsigned long loops_per_jiffy; /* protected processor identification number */ u64 ppin; - /* cpuid returned max cores value: */ - u16 x86_max_cores; u16 x86_clflush_size; /* number of cores as seen by the OS: */ u16 booted_cores; --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -301,7 +301,7 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_ eax->split.type =3D types[leaf]; eax->split.level =3D levels[leaf]; eax->split.num_threads_sharing =3D 0; - eax->split.num_cores_on_die =3D __this_cpu_read(cpu_info.x86_max_cores) -= 1; + eax->split.num_cores_on_die =3D topology_num_cores_per_package(); =20 =20 if (assoc =3D=3D 0xffff) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1737,7 +1737,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_model =3D c->x86_stepping =3D 0; /* So far unknown... */ c->x86_vendor_id[0] =3D '\0'; /* Unset */ c->x86_model_id[0] =3D '\0'; /* Unset */ - c->x86_max_cores =3D 1; #ifdef CONFIG_X86_64 c->x86_clflush_size =3D 64; c->x86_phys_bits =3D 36; --- a/arch/x86/kernel/cpu/debugfs.c +++ b/arch/x86/kernel/cpu/debugfs.c @@ -28,7 +28,8 @@ static int cpu_debug_show(struct seq_fil seq_printf(m, "l2c_id: %u\n", c->topo.l2c_id); seq_printf(m, "amd_node_id: %u\n", c->topo.amd_node_id); seq_printf(m, "amd_nodes_per_pkg: %u\n", topology_amd_nodes_per_pkg()); - seq_printf(m, "max_cores: %u\n", c->x86_max_cores); + seq_printf(m, "num_threads: %u\n", __num_threads_per_package); + seq_printf(m, "num_cores: %u\n", __num_cores_per_package); seq_printf(m, "max_dies_per_pkg: %u\n", __max_dies_per_package); seq_printf(m, "max_threads_per_core:%u\n", __max_threads_per_core); return 0; --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -430,10 +430,9 @@ static void trigger_thr_int(void *info) =20 static u32 get_nbc_for_node(int node_id) { - struct cpuinfo_x86 *c =3D &boot_cpu_data; u32 cores_per_node; =20 - cores_per_node =3D (c->x86_max_cores * __max_threads_per_core) / topology= _amd_nodes_per_pkg(); + cores_per_node =3D topology_num_threads_per_package() / topology_amd_node= s_per_pkg(); return cores_per_node * node_id; } =20 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -641,7 +641,7 @@ static __init void calc_llc_size_per_cor { u64 llc_size =3D c->x86_cache_size * 1024ULL; =20 - do_div(llc_size, c->x86_max_cores); + do_div(llc_size, topology_num_cores_per_package()); llc_size_per_core =3D (unsigned int)llc_size; } =20 --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -155,9 +155,6 @@ static void topo_set_ids(struct topo_sca c->topo.core_id =3D (apicid & topo_domain_mask(TOPO_PKG_DOMAIN)) >> x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN]; =20 - /* Maximum number of cores on this package */ - c->x86_max_cores =3D topology_unit_count(apicid, TOPO_CORE_DOMAIN, TOPO_P= KG_DOMAIN); - c->topo.amd_node_id =3D tscan->amd_node_id; =20 if (c->x86_vendor =3D=3D X86_VENDOR_AMD) --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -564,7 +564,7 @@ static void __init build_sched_topology( void set_cpu_sibling_map(int cpu) { bool has_smt =3D __max_threads_per_core > 1; - bool has_mp =3D has_smt || boot_cpu_data.x86_max_cores > 1; + bool has_mp =3D has_smt || topology_num_cores_per_package() > 1; struct cpuinfo_x86 *c =3D &cpu_data(cpu); struct cpuinfo_x86 *o; int i, threads; --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c @@ -451,7 +451,7 @@ static int vangogh_init_smc_tables(struc =20 #ifdef CONFIG_X86 /* AMD x86 APU only */ - smu->cpu_core_num =3D boot_cpu_data.x86_max_cores; + smu->cpu_core_num =3D topology_num_cores_per_package(); #else smu->cpu_core_num =3D 4; #endif --- a/drivers/hwmon/fam15h_power.c +++ b/drivers/hwmon/fam15h_power.c @@ -209,7 +209,7 @@ static ssize_t power1_average_show(struc * With the new x86 topology modelling, x86_max_cores is the * compute unit number. */ - cu_num =3D boot_cpu_data.x86_max_cores; + cu_num =3D topology_num_cores_per_package(); =20 ret =3D read_registers(data); if (ret)