From nobody Wed Dec 24 21:30:34 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 06B375F541 for ; Tue, 23 Jan 2024 12:53: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=1706014415; cv=none; b=K4y+6SPdAT+T1GYZB8u/dJxzGK3e208Y9A3QVUCw+TWfJ0J3cO3xylPV/Xt9XP3rKTWB5ozTIT579MmMGjyjd8W7vLwfAHIfk8QGpvYtmLF6mJHnZpdrohWxjT1nREHqaVspwjbFtZ/HDEapuZ30umyeUuwkuPw2Bj5Y4gxXWyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014415; c=relaxed/simple; bh=NE38U5sSq0KEn81KCUffHn/ZAXWYI8/Ra1pEbVF+fpk=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=G3fL9G0iU6u/qogcrcMWZLV0CZDQPzbw7SLj7AJDG3dhzt8QSuSeVHP0mIieiX7qe2/ovmWk1j5QVVZ2vwhmtedRrdR4IZclkDR7Hfsujf2MlJT1DhAg2tQwKpmB38TPKP/JdqwbiNGIw5o9AzTVo4E59Tez5DQX0Ougc7OA9A0= 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=FAfpbnaM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OwA8CbOf; 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="FAfpbnaM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OwA8CbOf" Message-ID: <20240117115908.344295552@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014411; 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=CHwg68P1vAZsPhjQ3yDPqQ0OD7LrrKUWUxcHvl79YxM=; b=FAfpbnaM66ByOQaVXjI9rCfUS1eMQPfzpTR08osAdyKX1ioK/p+OAFj97+Wd2dcHFCrLEh J6HQrCw2hTCTXQ8LeUfg+hwtgEoc2c/kED1xSbqayzUbfC+VA+EeiVTmsAPJCJqzDNkgUD uVrNlyRH1hbFZ5PGcnoGExUbzpHFk8RzNIedBTtvk2+I6IBF8GmRtlSTNmaxn/V2fZwa20 axOs5esqRYywB+mIFE+qo8y3CRX3twbxwk8LPzUtT9Z0/d+kcQqo+xmU67auZDGxbhgcBF 24maN2ACq+RzqPKrpOsFVhxmtD9n0BvyE48g/oWDfL4iqO9GCgc+nOa+7Ldetw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014411; 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=CHwg68P1vAZsPhjQ3yDPqQ0OD7LrrKUWUxcHvl79YxM=; b=OwA8CbOfTHWs1se1A3pSZMnJP84bPpNl3gY+gkKnrNG+TmOfV1qf0s23rNHZUQnQJN8Z34 6M/IP8M9c2Qc0ZBg== 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 v5 01/19] x86/cpu: Provide cpuid_read() et al. References: <20240117115752.863482697@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 13:53:30 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Provide a few helper functions to read CPUID leafs or individual registers into a data structure without requiring unions. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley Tested-by: Peter Zijlstra (Intel) Tested-by: Zhang Rui Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/cpuid.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) --- --- a/arch/x86/include/asm/cpuid.h +++ b/arch/x86/include/asm/cpuid.h @@ -127,6 +127,42 @@ static inline unsigned int cpuid_edx(uns return edx; } =20 +static inline void __cpuid_read(unsigned int leaf, unsigned int subleaf, u= 32 *regs) +{ + regs[CPUID_EAX] =3D leaf; + regs[CPUID_ECX] =3D subleaf; + __cpuid(regs, regs + 1, regs + 2, regs + 3); +} + +#define cpuid_subleaf(leaf, subleaf, regs) { \ + BUILD_BUG_ON(sizeof(*(regs)) !=3D 16); \ + __cpuid_read(leaf, subleaf, (u32 *)(regs)); \ +} + +#define cpuid_leaf(leaf, regs) { \ + BUILD_BUG_ON(sizeof(*(regs)) !=3D 16); \ + __cpuid_read(leaf, 0, (u32 *)(regs)); \ +} + +static inline void __cpuid_read_reg(unsigned int leaf, unsigned int sublea= f, + enum cpuid_regs_idx regidx, u32 *reg) +{ + u32 regs[4]; + + __cpuid_read(leaf, subleaf, regs); + *reg =3D regs[regidx]; +} + +#define cpuid_subleaf_reg(leaf, subleaf, regidx, reg) { \ + BUILD_BUG_ON(sizeof(*(reg)) !=3D 4); \ + __cpuid_read_reg(leaf, subleaf, regidx, (u32 *)(reg)); \ +} + +#define cpuid_leaf_reg(leaf, regidx, reg) { \ + BUILD_BUG_ON(sizeof(*(reg)) !=3D 4); \ + __cpuid_read_reg(leaf, 0, regidx, (u32 *)(reg)); \ +} + static __always_inline bool cpuid_function_is_indexed(u32 function) { switch (function) { From nobody Wed Dec 24 21:30:34 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 C275A5F557 for ; Tue, 23 Jan 2024 12:53:35 +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=1706014417; cv=none; b=AX5qySPCPqeOq782jIExXyjAtxrvFWVcX9PoqcUNwR4xOwW+YMcL6Mv/3pEHhlojVIr9LvBniZ2vuFFnWvq7p0R8+N5kHy00Uji4ebwk/17pxiWMEntaHDyjOqkhEGsnSaNFujcGtEaH3/JQZVe/PXxHkTioxpWeNsjf/Ahpbdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014417; c=relaxed/simple; bh=S5UEpkdnmFZk54KkEbrpDLOjpHobPfu6v0+356r3Zgo=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=UlBBdzcJo8L3jvsUSn8STZozK8RsFV61t3r1wSmQPwCqHM3GqVKUutjYOWRFcnGmO28Y6X48CxDBGMS2ZLR4xUbU+FWp6/baYYtkrp4e5Tm8ROYiYkSEULLUDuMu91+0H+wAQ2+pejIFrX6vkngTukqpH+BwUDmjgR4vfesz+Y4= 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=1T5Rqp2E; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Jgfe/XKH; 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="1T5Rqp2E"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Jgfe/XKH" Message-ID: <20240117115908.410413470@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014413; 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=RvRUYsTNNwwWp9r0G2x/rZu4+Ebmn28qhNzTvp+NAeE=; b=1T5Rqp2EfyFwsjGSZnWd08zR3nUiok8dnZ+BGYFeinQhV6H2gzc4efBSxFvCBIo8WATo0f II6LFPW/yW2S5X5e551tx1SPV7YDHRSVcjTD0PVP0U3Zs846HKVP+l4NNG06ykrK5ghcKA OZs7kPltbZCbZpPdkaze8hl7kBjT8D2aRB7QO0hhr/WszD16NSob3KNC/uakYYK/6X7NgL xona5x8BWioBi9jLR3VJs5lPk6oUF0cdTorXFPhdEJ8U/hAfpxwYzpZuM8taFwVb1n9xts +sLaxsE5rentyfFL5l1XxxdIHzQgHPduOICVq6H2dbQEnvbABvnZL+ec4Ohllg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014413; 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=RvRUYsTNNwwWp9r0G2x/rZu4+Ebmn28qhNzTvp+NAeE=; b=Jgfe/XKHztaOVIVwOB5xNoibnSvlU1Q/ZFxq26FE8bILM7PSE1UvIWhzA+6OlLYciYD74t 1TVxZs/MWyz/RTBw== 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 v5 02/19] x86/cpu: Provide cpu_init/parse_topology() References: <20240117115752.863482697@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 13:53:32 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Topology evaluation is a complete disaster and impenetrable mess. It's scattered all over the place with some vendor implementations doing early evaluation and some not. The most horrific part is the permanent overwriting of smt_max_siblings and __max_die_per_package, instead of establishing them once on the boot CPU and validating the result on the APs. The goals are: - One topology evaluation entry point - Proper sharing of pointlessly duplicated code - Proper structuring of the evaluation logic and preferences. - Evaluating important system wide information only once on the boot CPU - Making the 0xb/0x1f leaf parsing less convoluted and actually fixing the short comings of leaf 0x1f evaluation. Start to consolidate the topology evaluation code by providing the entry points for the early boot CPU evaluation and for the final parsing on the boot CPU and the APs. Move the trivial pieces into that new code: - The initialization of cpuinfo_x86::topo - The evaluation of CPUID leaf 1, which presets topo::initial_apicid - topo_apicid is set to topo::initial_apicid when invoked from early boot. When invoked for the final evaluation on the boot CPU it reads the actual APIC ID, which makes apic_get_initial_apicid() obsolete once everything is converted over. Provide a temporary helper function topo_converted() which shields off the not yet converted CPU vendors from invoking code which would break them. This shielding covers all vendor CPUs which support SMP, but not the historical pure UP ones as they only need the topology info init and eventually the initial APIC initialization. Provide two new members in cpuinfo_x86::topo to store the maximum number of SMT siblings and the number of dies per package and add them to the debugfs readout. These two members will be used to populate this information on the boot CPU and to validate the APs against it. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley Tested-by: Peter Zijlstra (Intel) Tested-by: Zhang Rui Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/topology.h | 19 +++ arch/x86/kernel/cpu/Makefile | 3=20 arch/x86/kernel/cpu/common.c | 24 +--- arch/x86/kernel/cpu/cpu.h | 6 + arch/x86/kernel/cpu/debugfs.c | 38 ++++++ arch/x86/kernel/cpu/topology.h | 36 ++++++ arch/x86/kernel/cpu/topology_common.c | 188 +++++++++++++++++++++++++++++= +++++ 7 files changed, 296 insertions(+), 18 deletions(-) create mode 100644 arch/x86/kernel/cpu/topology.h create mode 100644 arch/x86/kernel/cpu/topology_common.c --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -102,6 +102,25 @@ static inline void setup_node_to_cpumask =20 #include =20 +/* Topology information */ +enum x86_topology_domains { + TOPO_SMT_DOMAIN, + TOPO_CORE_DOMAIN, + TOPO_MODULE_DOMAIN, + TOPO_TILE_DOMAIN, + TOPO_DIE_DOMAIN, + TOPO_DIEGRP_DOMAIN, + TOPO_PKG_DOMAIN, + TOPO_MAX_DOMAIN, +}; + +struct x86_topology_system { + unsigned int dom_shifts[TOPO_MAX_DOMAIN]; + unsigned int dom_size[TOPO_MAX_DOMAIN]; +}; + +extern struct x86_topology_system x86_topo_system; + extern const struct cpumask *cpu_coregroup_mask(int cpu); extern const struct cpumask *cpu_clustergroup_mask(int cpu); =20 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -17,7 +17,8 @@ KMSAN_SANITIZE_common.o :=3D n # As above, instrumenting secondary CPU boot code causes boot hangs. KCSAN_SANITIZE_common.o :=3D n =20 -obj-y :=3D cacheinfo.o scattered.o topology.o +obj-y :=3D cacheinfo.o scattered.o +obj-y +=3D topology_common.o topology.o obj-y +=3D common.o obj-y +=3D rdrand.o obj-y +=3D match.o --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1590,6 +1590,8 @@ static void __init early_identify_cpu(st setup_force_cpu_cap(X86_FEATURE_CPUID); cpu_parse_early_param(); =20 + cpu_init_topology(c); + if (this_cpu->c_early_init) this_cpu->c_early_init(c); =20 @@ -1600,6 +1602,7 @@ static void __init early_identify_cpu(st this_cpu->c_bsp_init(c); } else { setup_clear_cpu_cap(X86_FEATURE_CPUID); + cpu_init_topology(c); } =20 get_cpu_address_sizes(c); @@ -1747,18 +1750,6 @@ static void generic_identify(struct cpui =20 get_cpu_address_sizes(c); =20 - if (c->cpuid_level >=3D 0x00000001) { - c->topo.initial_apicid =3D (cpuid_ebx(1) >> 24) & 0xFF; -#ifdef CONFIG_X86_32 -# ifdef CONFIG_SMP - c->topo.apicid =3D apic->phys_pkg_id(c->topo.initial_apicid, 0); -# else - c->topo.apicid =3D c->topo.initial_apicid; -# endif -#endif - c->topo.pkg_id =3D c->topo.initial_apicid; - } - get_model_name(c); /* Default name */ =20 /* @@ -1817,9 +1808,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_model_id[0] =3D '\0'; /* Unset */ c->x86_max_cores =3D 1; c->x86_coreid_bits =3D 0; - c->topo.cu_id =3D 0xff; - c->topo.llc_id =3D BAD_APICID; - c->topo.l2c_id =3D BAD_APICID; #ifdef CONFIG_X86_64 c->x86_clflush_size =3D 64; c->x86_phys_bits =3D 36; @@ -1838,6 +1826,8 @@ static void identify_cpu(struct cpuinfo_ =20 generic_identify(c); =20 + cpu_parse_topology(c); + if (this_cpu->c_identify) this_cpu->c_identify(c); =20 @@ -1845,10 +1835,10 @@ static void identify_cpu(struct cpuinfo_ apply_forced_caps(c); =20 #ifdef CONFIG_X86_64 - c->topo.apicid =3D apic->phys_pkg_id(c->topo.initial_apicid, 0); + if (!topo_is_converted(c)) + c->topo.apicid =3D apic->phys_pkg_id(c->topo.initial_apicid, 0); #endif =20 - /* * Set default APIC and TSC_DEADLINE MSR fencing flag. AMD and * Hygon will clear it in ->c_init() below. --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -2,6 +2,11 @@ #ifndef ARCH_X86_CPU_H #define ARCH_X86_CPU_H =20 +#include +#include + +#include "topology.h" + /* attempt to consolidate cpu attributes */ struct cpu_dev { const char *c_vendor; @@ -96,4 +101,5 @@ static inline bool spectre_v2_in_eibrs_m mode =3D=3D SPECTRE_V2_EIBRS_RETPOLINE || mode =3D=3D SPECTRE_V2_EIBRS_LFENCE; } + #endif /* ARCH_X86_CPU_H */ --- a/arch/x86/kernel/cpu/debugfs.c +++ b/arch/x86/kernel/cpu/debugfs.c @@ -5,6 +5,8 @@ #include #include =20 +#include "cpu.h" + static int cpu_debug_show(struct seq_file *m, void *p) { unsigned long cpu =3D (unsigned long)m->private; @@ -42,12 +44,48 @@ static const struct file_operations dfs_ .release =3D single_release, }; =20 +static int dom_debug_show(struct seq_file *m, void *p) +{ + static const char *domain_names[TOPO_MAX_DOMAIN] =3D { + [TOPO_SMT_DOMAIN] =3D "Thread", + [TOPO_CORE_DOMAIN] =3D "Core", + [TOPO_MODULE_DOMAIN] =3D "Module", + [TOPO_TILE_DOMAIN] =3D "Tile", + [TOPO_DIE_DOMAIN] =3D "Die", + [TOPO_DIEGRP_DOMAIN] =3D "DieGrp", + [TOPO_PKG_DOMAIN] =3D "Package", + }; + unsigned int dom, nthreads =3D 1; + + for (dom =3D 0; dom < TOPO_MAX_DOMAIN; dom++) { + nthreads *=3D x86_topo_system.dom_size[dom]; + seq_printf(m, "domain: %-10s shift: %u dom_size: %5u max_threads: %5u\n", + domain_names[dom], x86_topo_system.dom_shifts[dom], + x86_topo_system.dom_size[dom], nthreads); + } + return 0; +} + +static int dom_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, dom_debug_show, inode->i_private); +} + +static const struct file_operations dfs_dom_ops =3D { + .open =3D dom_debug_open, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D single_release, +}; + static __init int cpu_init_debugfs(void) { struct dentry *dir, *base =3D debugfs_create_dir("topo", arch_debugfs_dir= ); unsigned long id; char name[24]; =20 + debugfs_create_file("domains", 0444, base, NULL, &dfs_dom_ops); + dir =3D debugfs_create_dir("cpus", base); for_each_possible_cpu(id) { sprintf(name, "%lu", id); --- /dev/null +++ b/arch/x86/kernel/cpu/topology.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ARCH_X86_TOPOLOGY_H +#define ARCH_X86_TOPOLOGY_H + +struct topo_scan { + struct cpuinfo_x86 *c; + unsigned int dom_shifts[TOPO_MAX_DOMAIN]; + unsigned int dom_ncpus[TOPO_MAX_DOMAIN]; +}; + +bool topo_is_converted(struct cpuinfo_x86 *c); +void cpu_init_topology(struct cpuinfo_x86 *c); +void cpu_parse_topology(struct cpuinfo_x86 *c); +void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains d= om, + unsigned int shift, unsigned int ncpus); + +static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains = dom) +{ + if (dom =3D=3D TOPO_SMT_DOMAIN) + return apicid; + return apicid >> x86_topo_system.dom_shifts[dom - 1]; +} + +static inline u32 topo_relative_domain_id(u32 apicid, enum x86_topology_do= mains dom) +{ + if (dom !=3D TOPO_SMT_DOMAIN) + apicid >>=3D x86_topo_system.dom_shifts[dom - 1]; + return apicid & (x86_topo_system.dom_size[dom] - 1); +} + +static inline u32 topo_domain_mask(enum x86_topology_domains dom) +{ + return (1U << x86_topo_system.dom_shifts[dom]) - 1; +} + +#endif /* ARCH_X86_TOPOLOGY_H */ --- /dev/null +++ b/arch/x86/kernel/cpu/topology_common.c @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +#include + +#include +#include +#include + +#include "cpu.h" + +struct x86_topology_system x86_topo_system __ro_after_init; + +void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains d= om, + unsigned int shift, unsigned int ncpus) +{ + tscan->dom_shifts[dom] =3D shift; + tscan->dom_ncpus[dom] =3D ncpus; + + /* Propagate to the upper levels */ + for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { + tscan->dom_shifts[dom] =3D tscan->dom_shifts[dom - 1]; + tscan->dom_ncpus[dom] =3D tscan->dom_ncpus[dom - 1]; + } +} + +bool topo_is_converted(struct cpuinfo_x86 *c) +{ + /* Temporary until everything is converted over. */ + switch (boot_cpu_data.x86_vendor) { + case X86_VENDOR_AMD: + case X86_VENDOR_CENTAUR: + case X86_VENDOR_INTEL: + case X86_VENDOR_HYGON: + case X86_VENDOR_ZHAOXIN: + return false; + default: + /* Let all UP systems use the below */ + return true; + } +} + +static bool fake_topology(struct topo_scan *tscan) +{ + /* + * Preset the CORE level shift for CPUID less systems and XEN_PV, + * which has useless CPUID information. + */ + topology_set_dom(tscan, TOPO_SMT_DOMAIN, 0, 1); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, 1, 1); + + return tscan->c->cpuid_level < 1 || xen_pv_domain(); +} + +static void parse_topology(struct topo_scan *tscan, bool early) +{ + const struct cpuinfo_topology topo_defaults =3D { + .cu_id =3D 0xff, + .llc_id =3D BAD_APICID, + .l2c_id =3D BAD_APICID, + }; + struct cpuinfo_x86 *c =3D tscan->c; + struct { + u32 unused0 : 16, + nproc : 8, + apicid : 8; + } ebx; + + c->topo =3D topo_defaults; + + if (fake_topology(tscan)) + return; + + /* Preset Initial APIC ID from CPUID leaf 1 */ + cpuid_leaf_reg(1, CPUID_EBX, &ebx); + c->topo.initial_apicid =3D ebx.apicid; + + /* + * The initial invocation from early_identify_cpu() happens before + * the APIC is mapped or X2APIC enabled. For establishing the + * topology, that's not required. Use the initial APIC ID. + */ + if (early) + c->topo.apicid =3D c->topo.initial_apicid; + else + c->topo.apicid =3D read_apic_id(); + + /* The above is sufficient for UP */ + if (!IS_ENABLED(CONFIG_SMP)) + return; +} + +static void topo_set_ids(struct topo_scan *tscan) +{ + struct cpuinfo_x86 *c =3D tscan->c; + u32 apicid =3D c->topo.apicid; + + c->topo.pkg_id =3D topo_shift_apicid(apicid, TOPO_PKG_DOMAIN); + c->topo.die_id =3D topo_shift_apicid(apicid, TOPO_DIE_DOMAIN); + + /* Package relative core ID */ + c->topo.core_id =3D (apicid & topo_domain_mask(TOPO_PKG_DOMAIN)) >> + x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN]; +} + +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(); + struct topo_scan tscan =3D { .c =3D c, }; + + parse_topology(&tscan, false); + + if (!topo_is_converted(c)) + return; + + for (dom =3D TOPO_SMT_DOMAIN; dom < TOPO_MAX_DOMAIN; dom++) { + if (tscan.dom_shifts[dom] =3D=3D x86_topo_system.dom_shifts[dom]) + continue; + pr_err(FW_BUG "CPU%d: Topology domain %u shift %u !=3D %u\n", cpu, dom, + tscan.dom_shifts[dom], x86_topo_system.dom_shifts[dom]); + } + + /* 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); +} + +void __init cpu_init_topology(struct cpuinfo_x86 *c) +{ + struct topo_scan tscan =3D { .c =3D c, }; + unsigned int dom, sft; + + parse_topology(&tscan, true); + + if (!topo_is_converted(c)) + return; + + /* Copy the shift values and calculate the unit sizes. */ + memcpy(x86_topo_system.dom_shifts, tscan.dom_shifts, sizeof(x86_topo_syst= em.dom_shifts)); + + dom =3D TOPO_SMT_DOMAIN; + x86_topo_system.dom_size[dom] =3D 1U << x86_topo_system.dom_shifts[dom]; + + for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { + sft =3D x86_topo_system.dom_shifts[dom] - x86_topo_system.dom_shifts[dom= - 1]; + x86_topo_system.dom_size[dom] =3D 1U << sft; + } + + topo_set_ids(&tscan); + topo_set_max_cores(&tscan); + + /* + * 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]; +} From nobody Wed Dec 24 21:30:34 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 269E65F574 for ; Tue, 23 Jan 2024 12:53: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=1706014418; cv=none; b=CzckxtRKE38oAvqykMMVObZd1RIP5Ae+kO7dNmlOBFy53/u2G4Gk9gtm/iZXBXT5JQLKvKnvjE/EV4H5PKneXlay7dAih8FXPKaGcnloswfcoXbqzcHp3goH/fTYi9zl+MmkbZBGje50y9odGqWErZxTQTibdF8rmMhzOQW8cDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014418; c=relaxed/simple; bh=V70qJUYY8oyHztXjt5ElJsr4r84LmSynsQcDzBQCb0k=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=OEWbss+5HfDzUPJvJSK+bkh0vyixgRg9hgDnkX7JnGNfuVek2tqhHKIuwAxkDer3yfsw4xVrcIvbH+re0LgDVmHHZevY9T1nvMXrQv9fLUMRbugV7pgToYCbAOSEJtjPyWOSa3Pk2Rq2AvsVYF/RTPI+Isf92FmuWydCy0LCak0= 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=Gqo8fpm0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xXX2SZW9; 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="Gqo8fpm0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xXX2SZW9" Message-ID: <20240117115908.477060795@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014415; 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=8VUl7pYr590afD01ha6vPyQIe2lBly9mAJe0mtABk/E=; b=Gqo8fpm0jQugypsMtvfTEljTWrL5oNDuEgskAbYJsqlQzO9LM5HXrWDGIVXogvTAi+XiRa jOXC0NUfa8rrEuP9pmDKTa1PI6XW1WL7/EXT0hZASAofRhgk0DcOKYmZNHhphnETVNXPtN PP+nhUZViE4938xuDzKSLkIL6Jcwhtb91+41O+0yVjis+7mBoNMH6zphUwCGAxCuQFzUe3 uvoyUQgNvJDuzpXTZE8A/qizUImU+M3ygM8CnRVx8dY+B7sT0S4JEMDum7EaX9uUo6P8K0 oz9T/fkVWh/c2Lb4MxqfWKokO04MaeBnps6JtmNcwqedR4YD7fdtYNz3dziPYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014415; 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=8VUl7pYr590afD01ha6vPyQIe2lBly9mAJe0mtABk/E=; b=xXX2SZW9BI738ejKEPtAgf3doA5bSGLPZcxPAFtNrfqZt0uQPfYoB+k65P61uGSYDAGvG1 f7LSExxP27tSiPBA== 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 v5 03/19] x86/cpu: Add legacy topology parser References: <20240117115752.863482697@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 13:53:34 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The legacy topology detection via CPUID leaf 4, which provides the number of cores in the package and CPUID leaf 1 which provides the number of logical CPUs in case that FEATURE_HT is enabled and the CMP_LEGACY feature is not set, is shared for Intel, Centaur amd Zhaoxin CPUs. Lift the code from common.c without the early detection hack and provide it as common fallback mechanism. Will be utilized in later changes. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/cpu/common.c | 3 ++ arch/x86/kernel/cpu/topology.h | 3 ++ arch/x86/kernel/cpu/topology_common.c | 46 +++++++++++++++++++++++++++++= ++++- 3 files changed, 51 insertions(+), 1 deletion(-) --- --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -891,6 +891,9 @@ void detect_ht(struct cpuinfo_x86 *c) #ifdef CONFIG_SMP int index_msb, core_bits; =20 + if (topo_is_converted(c)) + return; + if (detect_ht_early(c) < 0) return; =20 --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -6,6 +6,9 @@ struct topo_scan { struct cpuinfo_x86 *c; unsigned int dom_shifts[TOPO_MAX_DOMAIN]; unsigned int dom_ncpus[TOPO_MAX_DOMAIN]; + + // Legacy CPUID[1]:EBX[23:16] number of logical processors + unsigned int ebx1_nproc_shift; }; =20 bool topo_is_converted(struct cpuinfo_x86 *c); --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -24,6 +24,48 @@ void topology_set_dom(struct topo_scan * } } =20 +static unsigned int parse_num_cores(struct cpuinfo_x86 *c) +{ + struct { + u32 cache_type : 5, + unused : 21, + ncores : 6; + } eax; + + if (c->cpuid_level < 4) + return 1; + + cpuid_subleaf_reg(4, 0, CPUID_EAX, &eax); + if (!eax.cache_type) + return 1; + + return eax.ncores + 1; +} + +static void __maybe_unused parse_legacy(struct topo_scan *tscan) +{ + unsigned int cores, core_shift, smt_shift =3D 0; + struct cpuinfo_x86 *c =3D tscan->c; + + cores =3D parse_num_cores(c); + core_shift =3D get_count_order(cores); + + if (cpu_has(c, X86_FEATURE_HT)) { + if (!WARN_ON_ONCE(tscan->ebx1_nproc_shift < core_shift)) + smt_shift =3D tscan->ebx1_nproc_shift - core_shift; + /* + * The parser expects leaf 0xb/0x1f format, which means + * the number of logical processors at core level is + * counting threads. + */ + core_shift +=3D smt_shift; + cores <<=3D smt_shift; + } + + topology_set_dom(tscan, TOPO_SMT_DOMAIN, smt_shift, 1U << smt_shift); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, core_shift, cores); +} + bool topo_is_converted(struct cpuinfo_x86 *c) { /* Temporary until everything is converted over. */ @@ -47,7 +89,7 @@ static bool fake_topology(struct topo_sc * which has useless CPUID information. */ topology_set_dom(tscan, TOPO_SMT_DOMAIN, 0, 1); - topology_set_dom(tscan, TOPO_CORE_DOMAIN, 1, 1); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, 0, 1); =20 return tscan->c->cpuid_level < 1 || xen_pv_domain(); } @@ -88,6 +130,8 @@ static void parse_topology(struct topo_s /* The above is sufficient for UP */ if (!IS_ENABLED(CONFIG_SMP)) return; + + tscan->ebx1_nproc_shift =3D get_count_order(ebx.nproc); } =20 static void topo_set_ids(struct topo_scan *tscan) From nobody Wed Dec 24 21:30:34 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 555905F846 for ; Tue, 23 Jan 2024 12:53: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=1706014419; cv=none; b=KbizqQT7sg7MHrUy05nwws1EjXdi+WX5D9XEcWNBDM1/2VgSR7L9xTjpoIfqgrnnlQyys3EblZbVqwtnxP6xdonQ8TzQFzSWy3Wubjz1OYdvysSFsgQXbYWT9s63hX3QcE+fdVxgPTEaO0xyTj8D8NMX502Zep9WInFJ0mJADDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014419; c=relaxed/simple; bh=hBxUau5onbyu+zjuJhrMNZuHL+WMvv5PXELy3ItN9yY=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=Ud7pEoB8M0stpd8J1SdGiWzNhJDGTX9FvSVVTtPmMcyR5Jo7y1pwu0SlDlgkcpiFW/LgUX92yxV9Z11oBzbn1E7At+uwVZPMcnrgFCptCZbch1Jo7WBt9Jl+0uVodVtqCOm26v4/FHLIuANdUxRQ1fIVFMfo+BOH7d21X8Sz/nE= 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=Sz195eBc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dOdjb4dZ; 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="Sz195eBc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dOdjb4dZ" Message-ID: <20240117115908.542473474@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014416; 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=RLy749FW2PFLvVXjhU8LmOLJWnw66SbG5wPjqrOoIvw=; b=Sz195eBcyIV/x/RdoIVyfC76Ecpk7SkM4lMDqqujWENkQG8P3hkwFRDqEQio7kDS+YE2uv q6hcAm8NvwBzjcQm16TAQbLJZxQADDf48DBN7mUrGouDRpJ7rc7N37OmkIhDT+BNf/oPj5 1li0fbEMIYZA9s346hin02nO3ZbnKQVxll8EUh4Rl+94iXpAYQRC8KQndMLqUe+XuKclmC D2B4u3jj6ABVIoHQTOHIxZdCZFm11GC6TJLke9qiTd8kPaTbOkpzpaMCd4TTShI7vpdiss R8yKC2AZKnMsTErHbtk/yYgnNPgzfAUiXpUTWh7sUcaku8qycTOPmrkj8FQIHA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014416; 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=RLy749FW2PFLvVXjhU8LmOLJWnw66SbG5wPjqrOoIvw=; b=dOdjb4dZsj1ct237gcypXb60Xf1HgmmKEUeAmpVyXeZ0lK6XfySO8/kOL41fYd9z3YI0Mj 71itvTZTje2cbrDA== 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 v5 04/19] x86/cpu: Use common topology code for Centaur and Zhaoxin References: <20240117115752.863482697@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 13:53:35 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Centaur and Zhaoxin CPUs use only the legacy SMP detection. Remove the invocations from their 32bit path and exempt them from the call 64bit. No functional change intended. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/cpu/centaur.c | 4 ---- arch/x86/kernel/cpu/topology_common.c | 11 ++++++++--- arch/x86/kernel/cpu/zhaoxin.c | 4 ---- 3 files changed, 8 insertions(+), 11 deletions(-) --- --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -128,10 +128,6 @@ static void init_centaur(struct cpuinfo_ #endif early_init_centaur(c); init_intel_cacheinfo(c); - detect_num_cpu_cores(c); -#ifdef CONFIG_X86_32 - detect_ht(c); -#endif =20 if (c->cpuid_level > 9) { unsigned int eax =3D cpuid_eax(10); --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -42,7 +42,7 @@ static unsigned int parse_num_cores(stru return eax.ncores + 1; } =20 -static void __maybe_unused parse_legacy(struct topo_scan *tscan) +static void parse_legacy(struct topo_scan *tscan) { unsigned int cores, core_shift, smt_shift =3D 0; struct cpuinfo_x86 *c =3D tscan->c; @@ -71,10 +71,8 @@ bool topo_is_converted(struct cpuinfo_x8 /* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) { case X86_VENDOR_AMD: - case X86_VENDOR_CENTAUR: case X86_VENDOR_INTEL: case X86_VENDOR_HYGON: - case X86_VENDOR_ZHAOXIN: return false; default: /* Let all UP systems use the below */ @@ -132,6 +130,13 @@ static void parse_topology(struct topo_s return; =20 tscan->ebx1_nproc_shift =3D get_count_order(ebx.nproc); + + switch (c->x86_vendor) { + case X86_VENDOR_CENTAUR: + case X86_VENDOR_ZHAOXIN: + parse_legacy(tscan); + break; + } } =20 static void topo_set_ids(struct topo_scan *tscan) --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -71,10 +71,6 @@ static void init_zhaoxin(struct cpuinfo_ { early_init_zhaoxin(c); init_intel_cacheinfo(c); - detect_num_cpu_cores(c); -#ifdef CONFIG_X86_32 - detect_ht(c); -#endif =20 if (c->cpuid_level > 9) { unsigned int eax =3D cpuid_eax(10); From nobody Wed Dec 24 21:30:34 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 EDC5C5F866 for ; Tue, 23 Jan 2024 12:53:39 +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=1706014421; cv=none; b=CyHXYp04A71m3Pl0l3dQoqZeI/Vnl04gjw+hvL6+zuVffig75Yhff9ZFIAljvU96Fiuf3Q96pxo48rn6iQvueYozVtXL6lAbW/QO0IRkIThcbCCUr1vnx5tmlBtaiwtFjvWXTQl8aPOcJu2cpHPLgSY5ywAE1bz/Pzy58M0Jwd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014421; c=relaxed/simple; bh=4HZ2n8xBznhGrWWyNa9CZ7scSju09FL9B9OOA/nZ0Pw=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=j3GB0NYeaFLzIvDd6xNyVZdutTePzAEwAvmwNHPC0XJc9XhqSAQ/buHXc1Cv8jO1b8FLz15jKUdSsr68BESyHEIU5oXyJivXnsCmki9LkUftv3AwoZPAGX9CFt2bqmiSwzI4M2T2gZKbTA+gvPlbOkAT6ZHkMlnCi3NmDSBlZlE= 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=x/oJxVld; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sQdvtvy2; 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="x/oJxVld"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sQdvtvy2" Message-ID: <20240117115908.608449830@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014418; 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=5SkHGXX2iNobIfvEprLaCMhF0AA0+N9lS14uXgc9Oxo=; b=x/oJxVldzzIyWd9ZZhwZhssdZKDrRgfxNHcYnKG/3GrGMwMZPNRatO+NrqBmIZ0uoyGtL2 brfSjrt0/B9WMLStSX8TZvDoXpyVQopg/COt5eOV2O92qQ4TInF4kTKd5AeY/TvWQ691RB KdhNzTCV3BglPj4vcgMZiiR7trTSDgLBRY6I/dAYGIQqivX2Lp7fSaT7LZxXn186Kn4yvv aVvq/4TeXYNHQ9hYPsPWaPapwe/bhB60eiMK12IOtYL6jAUd7v9zmAlZ5kM831j4TgdJXA 4hM6+GkQLNd0jU8G3QY9WIHvF2IjOzl45XulfQtI4WD7ZVfM4ZMUTnydEX4kNQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014418; 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=5SkHGXX2iNobIfvEprLaCMhF0AA0+N9lS14uXgc9Oxo=; b=sQdvtvy2kaOWzsmDxl+ZpL18NeCsTTrWDpPeVJYlmnDXHk0M7M6l9w1+tP4r++lryZxQMn 63IppdJg/LznmTAQ== 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 v5 05/19] x86/cpu: Move __max_die_per_package to common.c References: <20240117115752.863482697@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 13:53:37 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner In preparation of a complete replacement for the topology leaf 0xb/0x1f evaluation, move __max_die_per_package into the common code. Will be removed once everything is converted over. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kernel/cpu/topology.c | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) --- --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -75,6 +75,9 @@ u32 elf_hwcap2 __read_mostly; int smp_num_siblings =3D 1; EXPORT_SYMBOL(smp_num_siblings); =20 +unsigned int __max_die_per_package __read_mostly =3D 1; +EXPORT_SYMBOL(__max_die_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 @@ -25,9 +25,6 @@ #define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f) #define LEVEL_MAX_SIBLINGS(ebx) ((ebx) & 0xffff) =20 -unsigned int __max_die_per_package __read_mostly =3D 1; -EXPORT_SYMBOL(__max_die_per_package); - #ifdef CONFIG_SMP /* * Check if given CPUID extended topology "leaf" is implemented From nobody Wed Dec 24 21:30:34 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 D1AC95FB9A for ; Tue, 23 Jan 2024 12:53: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=1706014423; cv=none; b=mpoTCgOC64q38D7Rmaxu4+efnzymoHssDB6FpZiZ0jCVxFaA2q1IR/XFzjiHFmV1+Y91h2/6MIqJ/JaI5Io4BCobXnx3Yc1HgmUYWbCLMcnlNFwloweV2XHziY/yfIcakok59QsPd97YC2LZpLnKYdVM1ihYCGq9Ccbp1GgZfhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014423; c=relaxed/simple; bh=LZ+hdFscqw21doVmJGPqYJtmI0nuQURd9YgpM8ZRMF8=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=ZAgbM4kaM9NJN2Cf2K076zJAJ06B5GEbz2o+XkUpdldGiYqeMpaV7QaNa8r7GfYEvZR0ETR96ByzbUMdKZ5Z5M/LPQj3QDrqpLq8NBRVEB4Ybz+fTNw96Wjw8IabHFDRhkGt/R4ShwbhJW6pRxZEw3NUmwXTZhQ6BU23rpd0+Vg= 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=w0s9q8My; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8IKhx0z+; 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="w0s9q8My"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8IKhx0z+" Message-ID: <20240117115908.674834306@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014420; 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=xa9QeHy0/8Z9mNJNlPzATr7OmHRB2gYVAB1LSh4gcVs=; b=w0s9q8MyFkr8sr6QnSwHEJ+Vp/IKfpXf7fTGH9HH937ngRvzGE/jeEwkjVmD/p1ayWbpJY os5rjeyG20psmbsDNabqvLNe869ZTBp338hG58DUS+cKr7NI9bw35MwugfxCO10i5PvaLw 8/R6i84V+jTDZ3tRMFkvi8QAzox0AQKk9gMOojm0B79o0fdlKHa8XUuBDPnEPOJTooZLy9 ttJdKbQRMZQTCUjeAbGP8IW90fQ28/fM9T5yKzSxsIYyDAhkiwwUIxOoLxk4f8ntE8GOUq bk5JQMfir44atVzC9ZHYH7/QILPPIKZPK9wAAGs5JYARdbIuJqaNrXpGMoOBKQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014420; 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=xa9QeHy0/8Z9mNJNlPzATr7OmHRB2gYVAB1LSh4gcVs=; b=8IKhx0z+2ieqxogqZ1I90bNLCFSG8PFp3aW6q+mFj5QIhn51/qfh9JBv4PKOb/kV+zmyOK cFavGxuaweAGE4BA== 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 v5 06/19] x86/cpu: Provide a sane leaf 0xb/0x1f parser References: <20240117115752.863482697@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 13:53:39 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner detect_extended_topology() along with it's early() variant is a classic example for duct tape engineering: - It evaluates an array of subleafs with a boatload of local variables for the relevant topology levels instead of using an array to save the enumerated information and propagate it to the right level - It has no boundary checks for subleafs - It prevents updating the die_id with a crude workaround instead of checking for leaf 0xb which does not provide die information. - It's broken vs. the number of dies evaluation as it uses: num_processors[DIE_LEVEL] / num_processors[CORE_LEVEL] which "works" only correctly if there is none of the intermediate topology levels (MODULE/TILE) enumerated. There is zero value in trying to "fix" that code as the only proper fix is to rewrite it from scratch. Implement a sane parser with proper code documentation, which will be used for the consolidated topology evaluation in the next step. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley Reviewed-by: Thomas Gleixner --- arch/x86/kernel/cpu/Makefile | 2=20 arch/x86/kernel/cpu/topology.h | 12 +++ arch/x86/kernel/cpu/topology_ext.c | 130 ++++++++++++++++++++++++++++++++= +++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/cpu/topology_ext.c --- --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o :=3D n KCSAN_SANITIZE_common.o :=3D n =20 obj-y :=3D cacheinfo.o scattered.o -obj-y +=3D topology_common.o topology.o +obj-y +=3D topology_common.o topology_ext.o topology.o obj-y +=3D common.o obj-y +=3D rdrand.o obj-y +=3D match.o --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -16,6 +16,7 @@ void cpu_init_topology(struct cpuinfo_x8 void cpu_parse_topology(struct cpuinfo_x86 *c); void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains d= om, unsigned int shift, unsigned int ncpus); +bool cpu_parse_topology_ext(struct topo_scan *tscan); =20 static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains = dom) { @@ -36,4 +37,15 @@ static inline u32 topo_domain_mask(enum return (1U << x86_topo_system.dom_shifts[dom]) - 1; } =20 +/* + * Update a domain level after the fact without propagating. Used to fixup + * broken CPUID enumerations. + */ +static inline void topology_update_dom(struct topo_scan *tscan, enum x86_t= opology_domains dom, + unsigned int shift, unsigned int ncpus) +{ + tscan->dom_shifts[dom] =3D shift; + tscan->dom_ncpus[dom] =3D ncpus; +} + #endif /* ARCH_X86_TOPOLOGY_H */ --- /dev/null +++ b/arch/x86/kernel/cpu/topology_ext.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +#include +#include +#include + +#include "cpu.h" + +enum topo_types { + INVALID_TYPE =3D 0, + SMT_TYPE =3D 1, + CORE_TYPE =3D 2, + MAX_TYPE_0B =3D 3, + MODULE_TYPE =3D 3, + TILE_TYPE =3D 4, + DIE_TYPE =3D 5, + DIEGRP_TYPE =3D 6, + MAX_TYPE_1F =3D 7, +}; + +/* + * Use a lookup table for the case that there are future types > 6 which + * describe an intermediate domain level which does not exist today. + */ +static const unsigned int topo_domain_map_0b_1f[MAX_TYPE_1F] =3D { + [SMT_TYPE] =3D TOPO_SMT_DOMAIN, + [CORE_TYPE] =3D TOPO_CORE_DOMAIN, + [MODULE_TYPE] =3D TOPO_MODULE_DOMAIN, + [TILE_TYPE] =3D TOPO_TILE_DOMAIN, + [DIE_TYPE] =3D TOPO_DIE_DOMAIN, + [DIEGRP_TYPE] =3D TOPO_DIEGRP_DOMAIN, +}; + +static inline bool topo_subleaf(struct topo_scan *tscan, u32 leaf, u32 sub= leaf, + unsigned int *last_dom) +{ + unsigned int dom, maxtype; + const unsigned int *map; + struct { + // eax + u32 x2apic_shift : 5, // Number of bits to shift APIC ID right + // for the topology ID at the next level + : 27; // Reserved + // ebx + u32 num_processors : 16, // Number of processors at current level + : 16; // Reserved + // ecx + u32 level : 8, // Current topology level. Same as sub leaf number + type : 8, // Level type. If 0, invalid + : 16; // Reserved + // edx + u32 x2apic_id : 32; // X2APIC ID of the current logical processor + } sl; + + switch (leaf) { + case 0x0b: maxtype =3D MAX_TYPE_0B; map =3D topo_domain_map_0b_1f; break; + case 0x1f: maxtype =3D MAX_TYPE_1F; map =3D topo_domain_map_0b_1f; break; + default: return false; + } + + cpuid_subleaf(leaf, subleaf, &sl); + + if (!sl.num_processors || sl.type =3D=3D INVALID_TYPE) + return false; + + if (sl.type >=3D maxtype) { + pr_err_once("Topology: leaf 0x%x:%d Unknown domain type %u\n", + leaf, subleaf, sl.type); + /* + * It really would have been too obvious to make the domain + * type space sparse and leave a few reserved types between + * the points which might change instead of following the + * usual "this can be fixed in software" principle. + */ + dom =3D *last_dom + 1; + } else { + dom =3D map[sl.type]; + *last_dom =3D dom; + } + + if (!dom) { + tscan->c->topo.initial_apicid =3D sl.x2apic_id; + } else if (tscan->c->topo.initial_apicid !=3D sl.x2apic_id) { + pr_warn_once(FW_BUG "CPUID leaf 0x%x subleaf %d APIC ID mismatch %x !=3D= %x\n", + leaf, subleaf, tscan->c->topo.initial_apicid, sl.x2apic_id); + } + + topology_set_dom(tscan, dom, sl.x2apic_shift, sl.num_processors); + return true; +} + +static bool parse_topology_leaf(struct topo_scan *tscan, u32 leaf) +{ + unsigned int last_dom; + u32 subleaf; + + /* Read all available subleafs and populate the levels */ + for (subleaf =3D 0, last_dom =3D 0; topo_subleaf(tscan, leaf, subleaf, &l= ast_dom); subleaf++); + + /* If subleaf 0 failed to parse, give up */ + if (!subleaf) + return false; + + /* + * There are machines in the wild which have shift 0 in the subleaf + * 0, but advertise 2 logical processors at that level. They are + * truly SMT. + */ + if (!tscan->dom_shifts[TOPO_SMT_DOMAIN] && tscan->dom_ncpus[TOPO_SMT_DOMA= IN] > 1) { + unsigned int sft =3D get_count_order(tscan->dom_ncpus[TOPO_SMT_DOMAIN]); + + pr_warn_once(FW_BUG "CPUID leaf 0x%x subleaf 0 has shift level 0 but %u = CPUs\n", + leaf, tscan->dom_ncpus[TOPO_SMT_DOMAIN]); + topology_update_dom(tscan, TOPO_SMT_DOMAIN, sft, tscan->dom_ncpus[TOPO_S= MT_DOMAIN]); + } + + set_cpu_cap(tscan->c, X86_FEATURE_XTOPOLOGY); + return true; +} + +bool cpu_parse_topology_ext(struct topo_scan *tscan) +{ + /* Intel: Try leaf 0x1F first. */ + if (tscan->c->cpuid_level >=3D 0x1f && parse_topology_leaf(tscan, 0x1f)) + return true; + + /* Intel/AMD: Fall back to leaf 0xB if available */ + return tscan->c->cpuid_level >=3D 0x0b && parse_topology_leaf(tscan, 0x0b= ); +} From nobody Wed Dec 24 21:30:34 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 ECAFC5FDAE for ; Tue, 23 Jan 2024 12:53:43 +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=1706014425; cv=none; b=WGAHg+qJFCG2RLI0V8w+a60h+JRRkDYJS9Ut92tw4JPLl3yLvE/TOasyu6tsVZZVMKdDonZqaUZKwAtS60ckY4EaqDn8a1ASlRMk5ygzPZxuegc7FZUcpCv/XEUmAge91QwTgFWkY1XRyd0FoD6fefkS0kha56Cc/GmO40cOkFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014425; c=relaxed/simple; bh=1VXTKAfmMMh+RRXXMri++S8vkPmoJBMJLVsfWN/Ll/Y=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=hV+GmWmhNBEdLcNWb+oNDumL3jkQrPVoK0xANjveFlJgO2F7U3QrDNHlIdjABf3MSNYuUNySAZbTprKEI3K1xzbzr6z6UkYlYx6sVvj2G989zsRFJIWxHTVAJ2j4fkXC/Q4IICl3UpNfWEAZhwyw95gIc7MiYYmDGAh9JJeVw48= 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=sj94Vjye; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uaKjwzfC; 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="sj94Vjye"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uaKjwzfC" Message-ID: <20240117115908.740438007@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014422; 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=BXhmme64X7IhYeDIe8j69nb31VkeJzia7wTrN7xIZqo=; b=sj94VjyeKWUE+Z51bro3gSQINOLbbX/5yyR+kFgstarJT69aaKnsEecGfCgOAGc+Zf55tT AwKMFjU9hctDR1kOzJ/989rB8006i7q7Q+5fX7xLSwta+/zMH/zp+Z3UkiZiJtz13e/wwf WYSmlz8zEvf3VcsRNT+LLXwAQwyW6lrdw/moDhoOs7syaWUprgHXEFwd3FOs2Uaq3glJmT 8Ye9WhyOq4sDPWdXWzWSuQcTtSye6PJV+NDcjBJHsQ+tPSy2JtzJs99gP6R/o4L29h3aJ0 Ho9meF/xVN8DtV+Em3VJw871vsr3ZDZ4y+9AbbEKCLDBa59OhQSXHRt+WdWjBw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014422; 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=BXhmme64X7IhYeDIe8j69nb31VkeJzia7wTrN7xIZqo=; b=uaKjwzfCqVuMmjZCIi536Y3ES6QNjBoj6WxN+i/h0wUjP+mQk5k4gsMRKTvdyoJmxwjlWQ nksXB/L/pAX9UaBQ== 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 v5 07/19] x86/cpu: Use common topology code for Intel References: <20240117115752.863482697@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 13:53:40 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Intel CPUs use either topology leaf 0xb/0x1f evaluation or the legacy SMP/HT evaluation based on CPUID leaf 0x1/0x4. Move it over to the consolidated topology code and remove the random topology hacks which are sprinkled into the Intel and the common code. No functional change intended. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/cpu/common.c | 65 -----------------------------= ----- arch/x86/kernel/cpu/cpu.h | 4 -- arch/x86/kernel/cpu/intel.c | 25 ------------- arch/x86/kernel/cpu/topology_common.c | 5 ++ 4 files changed, 4 insertions(+), 95 deletions(-) --- --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -792,19 +792,6 @@ static void get_model_name(struct cpuinf *(s + 1) =3D '\0'; } =20 -void detect_num_cpu_cores(struct cpuinfo_x86 *c) -{ - unsigned int eax, ebx, ecx, edx; - - c->x86_max_cores =3D 1; - if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4) - return; - - cpuid_count(4, 0, &eax, &ebx, &ecx, &edx); - if (eax & 0x1f) - c->x86_max_cores =3D (eax >> 26) + 1; -} - void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) { unsigned int n, dummy, ebx, ecx, edx, l2size; @@ -866,54 +853,6 @@ static void cpu_detect_tlb(struct cpuinf tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]); } =20 -int detect_ht_early(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - u32 eax, ebx, ecx, edx; - - if (!cpu_has(c, X86_FEATURE_HT)) - return -1; - - if (cpu_has(c, X86_FEATURE_CMP_LEGACY)) - return -1; - - if (cpu_has(c, X86_FEATURE_XTOPOLOGY)) - return -1; - - cpuid(1, &eax, &ebx, &ecx, &edx); - - smp_num_siblings =3D (ebx & 0xff0000) >> 16; - if (smp_num_siblings =3D=3D 1) - pr_info_once("CPU0: Hyper-Threading is disabled\n"); -#endif - return 0; -} - -void detect_ht(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - int index_msb, core_bits; - - if (topo_is_converted(c)) - return; - - if (detect_ht_early(c) < 0) - return; - - index_msb =3D get_count_order(smp_num_siblings); - c->topo.pkg_id =3D apic->phys_pkg_id(c->topo.initial_apicid, index_msb); - - smp_num_siblings =3D smp_num_siblings / c->x86_max_cores; - - index_msb =3D get_count_order(smp_num_siblings); - - core_bits =3D get_count_order(c->x86_max_cores); - - c->topo.core_id =3D apic->phys_pkg_id(c->topo.initial_apicid, index_msb) & - ((1 << core_bits) - 1); -#endif -} - static void get_cpu_vendor(struct cpuinfo_x86 *c) { char *v =3D c->x86_vendor_id; @@ -1898,10 +1837,6 @@ static void identify_cpu(struct cpuinfo_ c->x86, c->x86_model); } =20 -#ifdef CONFIG_X86_64 - detect_ht(c); -#endif - x86_init_rdrand(c); setup_pku(c); setup_cet(c); --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -76,11 +76,7 @@ extern void init_intel_cacheinfo(struct extern void init_amd_cacheinfo(struct cpuinfo_x86 *c); extern void init_hygon_cacheinfo(struct cpuinfo_x86 *c); =20 -extern void detect_num_cpu_cores(struct cpuinfo_x86 *c); -extern int detect_extended_topology_early(struct cpuinfo_x86 *c); extern int detect_extended_topology(struct cpuinfo_x86 *c); -extern int detect_ht_early(struct cpuinfo_x86 *c); -extern void detect_ht(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); =20 void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c); --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -315,13 +315,6 @@ static void early_init_intel(struct cpui } =20 check_memory_type_self_snoop_errata(c); - - /* - * Get the number of SMT siblings early from the extended topology - * leaf, if available. Otherwise try the legacy SMT detection. - */ - if (detect_extended_topology_early(c) < 0) - detect_ht_early(c); } =20 static void bsp_init_intel(struct cpuinfo_x86 *c) @@ -603,24 +596,6 @@ static void init_intel(struct cpuinfo_x8 =20 intel_workarounds(c); =20 - /* - * Detect the extended topology information if available. This - * will reinitialise the initial_apicid which will be used - * in init_intel_cacheinfo() - */ - detect_extended_topology(c); - - if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) { - /* - * let's use the legacy cpuid vector 0x1 and 0x4 for topology - * detection. - */ - detect_num_cpu_cores(c); -#ifdef CONFIG_X86_32 - detect_ht(c); -#endif - } - init_intel_cacheinfo(c); =20 if (c->cpuid_level > 9) { --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -71,7 +71,6 @@ bool topo_is_converted(struct cpuinfo_x8 /* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) { case X86_VENDOR_AMD: - case X86_VENDOR_INTEL: case X86_VENDOR_HYGON: return false; default: @@ -136,6 +135,10 @@ static void parse_topology(struct topo_s case X86_VENDOR_ZHAOXIN: parse_legacy(tscan); break; + case X86_VENDOR_INTEL: + if (!IS_ENABLED(CONFIG_CPU_SUP_INTEL) || !cpu_parse_topology_ext(tscan)) + parse_legacy(tscan); + break; } } From nobody Wed Dec 24 21:30:34 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 04DDB5FDBC for ; Tue, 23 Jan 2024 12:53:44 +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=1706014426; cv=none; b=Db1+sys93mRi50b0AiO22BcyduvNoQyWed11702SFFJ7vRARHeKcWHCnWyD/XWLUCZ7ESmN3wrYAzakM6rYSh1rV/XLYPxZRUJUnBaPaTqRtyfR7aoZAKA6+6afNENV9LjRU3T8kqZP9W5mBFpPdivL5rbJSqRiFnm2YA8YpHe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014426; c=relaxed/simple; bh=eyqKpQtqG13TapBC9spo/8FS8k6C3l5xt6Iuf5GwVMs=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=dSU3dYmJXMG9DYYbipuh6ikuDizcTqr32MDvSjdkvzYNgF8ID2PJy7xKT6Oww/Cb75vM+vnvBsReFJVw6UdnIv+Dlaqlmj+NMN4V8o18vj2P/mNCxzfEK3bV+BExEZUs5JvCe8kdmCkXLmBqvGgEo0thFwz72NcWKCqxfWH9T3Y= 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=Ey5iOqHq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=p0zG90ME; 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="Ey5iOqHq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="p0zG90ME" Message-ID: <20240117115908.813770902@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014423; 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=YNO2Sr7yE41BCQs7/OS9aTwAqGVDP3j5N707H3szmAQ=; b=Ey5iOqHqON3u/Q83Vjlgc33ZwC1uEX9QrAyJQMWaxfmJa73d6O8Wf0yCpF31r73x6fPB64 DwmoKCCfCrIFzWYkSidAs1YtTtt8I6hYMBX6xj5TDWot0kHhcZaS0OtEEp4XPyERMxCQ4K b1vNpc06D797pBxxFOK7KEDdGdvJjIlQ2wlz+FlAs2dwDIA26MyRnsgRrLn0agwEnmYapH P3BR0cbhtIiHkjw7zTM7QGP4/2eZCiuFlRCL7dIyLwXGTYAWtTZgnnYTnNDyKeVMMuVeDz ebQtcnQdo9vzxnlHPAr7S8rZy0w06NN4r5mdorxdp3FLTLTtYQxo/W8zov4e2Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014423; 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=YNO2Sr7yE41BCQs7/OS9aTwAqGVDP3j5N707H3szmAQ=; b=p0zG90MEafx0eqExvvKgV4BwyNa7tar0Q0HEdX0+otqwZdp5FNSFBq44cl57DkJPNiGvB3 Hnw6mevP0SDoDrCg== 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 v5 08/19] x86/cpu/amd: Provide a separate accessor for Node ID References: <20240117115752.863482697@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 13:53:42 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner AMD (ab)uses topology_die_id() to store the Node ID information and topology_max_dies_per_pkg to store the number of nodes per package. This collides with the proper processor die level enumeration which is coming on AMD with CPUID 8000_0026, unless there is a correlation between the two. There is zero documentation about that. So provide new storage and new accessors which for now still access die_id and topology_max_dies_per_pkg. Will be mopped up after AMD and HYGON are converted over. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/events/amd/core.c | 2 +- arch/x86/include/asm/processor.h | 3 +++ arch/x86/include/asm/topology.h | 8 ++++++++ arch/x86/kernel/amd_nb.c | 4 ++-- arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/mce/amd.c | 4 ++-- arch/x86/kernel/cpu/mce/inject.c | 4 ++-- drivers/edac/amd64_edac.c | 4 ++-- drivers/edac/mce_amd.c | 4 ++-- 9 files changed, 23 insertions(+), 12 deletions(-) --- --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -579,7 +579,7 @@ static void amd_pmu_cpu_starting(int cpu if (!x86_pmu.amd_nb_constraints) return; =20 - nb_id =3D topology_die_id(cpu); + nb_id =3D topology_amd_node_id(cpu); WARN_ON_ONCE(nb_id =3D=3D BAD_APICID); =20 for_each_online_cpu(i) { --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -100,6 +100,9 @@ struct cpuinfo_topology { u32 logical_pkg_id; u32 logical_die_id; =20 + // AMD Node ID and Nodes per Package info + u32 amd_node_id; + // Cache level topology IDs u32 llc_id; u32 l2c_id; --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -131,6 +131,8 @@ extern const struct cpumask *cpu_cluster #define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) =20 +#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.die_id) + extern unsigned int __max_die_per_package; =20 #ifdef CONFIG_SMP @@ -161,6 +163,11 @@ int topology_update_package_map(unsigned int topology_update_die_map(unsigned int dieid, unsigned int cpu); int topology_phys_to_logical_pkg(unsigned int pkg); =20 +static inline unsigned int topology_amd_nodes_per_pkg(void) +{ + return __max_die_per_package; +} + extern struct cpumask __cpu_primary_thread_mask; #define cpu_primary_thread_mask ((const struct cpumask *)&__cpu_primary_th= read_mask) =20 @@ -182,6 +189,7 @@ static inline int topology_phys_to_logic 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; }; #endif /* !CONFIG_SMP */ =20 static inline void arch_fix_phys_package_id(int num, u32 slot) --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -386,7 +386,7 @@ struct resource *amd_get_mmconfig_range( =20 int amd_get_subcaches(int cpu) { - struct pci_dev *link =3D node_to_amd_nb(topology_die_id(cpu))->link; + struct pci_dev *link =3D node_to_amd_nb(topology_amd_node_id(cpu))->link; unsigned int mask; =20 if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) @@ -400,7 +400,7 @@ int amd_get_subcaches(int cpu) int amd_set_subcaches(int cpu, unsigned long mask) { static unsigned int reset, ban; - struct amd_northbridge *nb =3D node_to_amd_nb(topology_die_id(cpu)); + struct amd_northbridge *nb =3D node_to_amd_nb(topology_amd_node_id(cpu)); unsigned int reg; int cuid; =20 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -595,7 +595,7 @@ static void amd_init_l3_cache(struct _cp if (index < 3) return; =20 - node =3D topology_die_id(smp_processor_id()); + node =3D topology_amd_node_id(smp_processor_id()); this_leaf->nb =3D node_to_amd_nb(node); if (this_leaf->nb && !this_leaf->nb->l3_cache.indices) amd_calc_l3_indices(this_leaf->nb); --- a/arch/x86/kernel/cpu/mce/amd.c +++ b/arch/x86/kernel/cpu/mce/amd.c @@ -1231,7 +1231,7 @@ static int threshold_create_bank(struct return -ENODEV; =20 if (is_shared_bank(bank)) { - nb =3D node_to_amd_nb(topology_die_id(cpu)); + nb =3D node_to_amd_nb(topology_amd_node_id(cpu)); =20 /* threshold descriptor already initialized on this node? */ if (nb && nb->bank4) { @@ -1335,7 +1335,7 @@ static void threshold_remove_bank(struct * The last CPU on this node using the shared bank is going * away, remove that bank now. */ - nb =3D node_to_amd_nb(topology_die_id(smp_processor_id())); + nb =3D node_to_amd_nb(topology_amd_node_id(smp_processor_id())); nb->bank4 =3D NULL; } =20 --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -543,8 +543,8 @@ static void do_inject(void) if (boot_cpu_has(X86_FEATURE_AMD_DCM) && b =3D=3D 4 && boot_cpu_data.x86 < 0x17) { - toggle_nb_mca_mst_cpu(topology_die_id(cpu)); - cpu =3D get_nbc_for_node(topology_die_id(cpu)); + toggle_nb_mca_mst_cpu(topology_amd_node_id(cpu)); + cpu =3D get_nbc_for_node(topology_amd_node_id(cpu)); } =20 cpus_read_lock(); --- a/drivers/edac/amd64_edac.c +++ b/drivers/edac/amd64_edac.c @@ -1915,7 +1915,7 @@ static void dct_determine_memory_type(st /* On F10h and later ErrAddr is MC4_ADDR[47:1] */ static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m) { - u16 mce_nid =3D topology_die_id(m->extcpu); + u16 mce_nid =3D topology_amd_node_id(m->extcpu); struct mem_ctl_info *mci; u8 start_bit =3D 1; u8 end_bit =3D 47; @@ -3446,7 +3446,7 @@ static void get_cpus_on_this_dct_cpumask int cpu; =20 for_each_online_cpu(cpu) - if (topology_die_id(cpu) =3D=3D nid) + if (topology_amd_node_id(cpu) =3D=3D nid) cpumask_set_cpu(cpu, mask); } =20 --- a/drivers/edac/mce_amd.c +++ b/drivers/edac/mce_amd.c @@ -584,7 +584,7 @@ static void decode_mc3_mce(struct mce *m static void decode_mc4_mce(struct mce *m) { unsigned int fam =3D x86_family(m->cpuid); - int node_id =3D topology_die_id(m->extcpu); + int node_id =3D topology_amd_node_id(m->extcpu); u16 ec =3D EC(m->status); u8 xec =3D XEC(m->status, 0x1f); u8 offset =3D 0; @@ -746,7 +746,7 @@ static void decode_smca_error(struct mce =20 if ((bank_type =3D=3D SMCA_UMC || bank_type =3D=3D SMCA_UMC_V2) && xec =3D=3D 0 && decode_dram_ecc) - decode_dram_ecc(topology_die_id(m->extcpu), m); + decode_dram_ecc(topology_amd_node_id(m->extcpu), m); } =20 static inline void amd_decode_err_code(u16 ec) From nobody Wed Dec 24 21:30:34 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 7EB3D5FDD3 for ; Tue, 23 Jan 2024 12:53:46 +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=1706014428; cv=none; b=lfqTCAFbzt5gnnbePHwwcwEs1hqNqluF2ZGFetp/rwLE4i05HVYUFk2KyWeHBhNNNyn8R/e/uspEdKILIQOm15A+j+zWHoCHOiK0rTAbzUyf99jGq984GubIxfL9OKPyElPK82AQvwgeFPZolMzEaYQQ5jI/2RSS4i7Cokw5TtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014428; c=relaxed/simple; bh=NauXu52RoKqdcaOD2B+hLDjI/Y6ssoUFTDRZJl6xw/U=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=hWkicOSj6S5fDBA0a7LA6LlpeKntEPB73WQ2Hk3bQNmwFUHE+AsFZsJniWtUv3tB9QYIviCmynxUpH0oZRKn8qLV2c3JBjfse22zGHePYPJLby+ZcrYSXR0s8m35peWCvG4jBO2QVvrBra3Pro2l+XhdL8Sxf3o2cvhLQjFsrsA= 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=mryUyRdg; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OdSPHRqD; 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="mryUyRdg"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OdSPHRqD" Message-ID: <20240117115908.880472059@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014425; 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=A4Of+XftZinLuPRanFdBZCqF9Tl3XtBz9IIiozcbOEM=; b=mryUyRdg+i6UA6vDBHLQ89Z8ZS3tYGGv/1J+u0mNaCNLYbTyR24ZWbXecWySdNgFY/tg2a LiUo+DsVfKY8mgdmnnIXx059Wrj5mj51ujSd+mGHhG6jZc8mHL21mhvIxm/9xeCVjVhUo8 LR+EWlrZcl/Nr3ChQYjtYEIKLDSUJAjQcD80mXmgRbzoQCr62YQQjQ7fZ0P7+QdW8U33fN zdhls9Zo/Q4ARhXBRp138UWIh4LT+u7UDRbQGO64P06shbtUalo+AenpcgnJxSouHtx5TX RzJG+CJyuj4vHJUhKqMxzilM9XAegprMQxQtgNmE7FtFk/3MgKEg20VQ6C7EZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014425; 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=A4Of+XftZinLuPRanFdBZCqF9Tl3XtBz9IIiozcbOEM=; b=OdSPHRqDCCMcVItkCHWfr8N58g1AdaE2tByww438hRFFj4vQ8nY4lepJ8IATHMYtA/12Kp wKGUuJK45VK8kkCw== 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 v5 09/19] x86/cpu: Provide an AMD/HYGON specific topology parser References: <20240117115752.863482697@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 13:53:43 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner AMD/HYGON uses various methods for topology evaluation: - Leaf 0x80000008 and 0x8000001e based with an optional leaf 0xb, which is the preferred variant for modern CPUs. Leaf 0xb will be superseded by leaf 0x80000026 soon, which is just another variant of the Intel 0x1f leaf for whatever reasons. =20 - Subleaf 0x80000008 and NODEID_MSR base - Legacy fallback That code is following the principle of random bits and pieces all over the place which results in multiple evaluations and impenetrable code flows in the same way as the Intel parsing did. Provide a sane implementation by clearly separating the three variants and bringing them in the proper preference order in one place. This provides the parsing for both AMD and HYGON because there is no point in having a separate HYGON parser which only differs by 3 lines of code. Any further divergence between AMD and HYGON can be handled in different functions, while still sharing the existing parsers. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/include/asm/topology.h | 2=20 arch/x86/kernel/cpu/Makefile | 2=20 arch/x86/kernel/cpu/amd.c | 2=20 arch/x86/kernel/cpu/cacheinfo.c | 4=20 arch/x86/kernel/cpu/cpu.h | 2=20 arch/x86/kernel/cpu/debugfs.c | 2=20 arch/x86/kernel/cpu/topology.h | 6 + arch/x86/kernel/cpu/topology_amd.c | 182 +++++++++++++++++++++++++++++= +++++ arch/x86/kernel/cpu/topology_common.c | 19 +++ 9 files changed, 214 insertions(+), 7 deletions(-) create mode 100644 arch/x86/kernel/cpu/topology_amd.c --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -163,6 +163,8 @@ int topology_update_package_map(unsigned int topology_update_die_map(unsigned int dieid, unsigned int cpu); int topology_phys_to_logical_pkg(unsigned int pkg); =20 +extern unsigned int __amd_nodes_per_pkg; + static inline unsigned int topology_amd_nodes_per_pkg(void) { return __max_die_per_package; --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o :=3D n KCSAN_SANITIZE_common.o :=3D n =20 obj-y :=3D cacheinfo.o scattered.o -obj-y +=3D topology_common.o topology_ext.o topology.o +obj-y +=3D topology_common.o topology_ext.o topology_amd.o topology.o obj-y +=3D common.o obj-y +=3D rdrand.o obj-y +=3D match.o --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -351,7 +351,7 @@ static void amd_get_topology(struct cpui if (!err) c->x86_coreid_bits =3D get_count_order(c->x86_max_cores); =20 - cacheinfo_amd_init_llc_id(c); + cacheinfo_amd_init_llc_id(c, c->topo.die_id); =20 } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { u64 value; --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -661,7 +661,7 @@ static int find_num_cache_leaves(struct return i; } =20 -void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c) +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id) { /* * We may have multiple LLCs if L3 caches exist, so check if we @@ -672,7 +672,7 @@ void cacheinfo_amd_init_llc_id(struct cp =20 if (c->x86 < 0x17) { /* LLC is at the node level. */ - c->topo.llc_id =3D c->topo.die_id; + c->topo.llc_id =3D die_id; } else if (c->x86 =3D=3D 0x17 && c->x86_model <=3D 0x1F) { /* * LLC is at the core complex level. --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -79,7 +79,7 @@ extern void init_hygon_cacheinfo(struct extern int detect_extended_topology(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); =20 -void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c); +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id); void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c); =20 unsigned int aperfmperf_get_khz(int cpu); --- a/arch/x86/kernel/cpu/debugfs.c +++ b/arch/x86/kernel/cpu/debugfs.c @@ -26,6 +26,8 @@ static int cpu_debug_show(struct seq_fil seq_printf(m, "logical_die_id: %u\n", c->topo.logical_die_id); seq_printf(m, "llc_id: %u\n", c->topo.llc_id); 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, "max_die_per_pkg: %u\n", __max_die_per_package); seq_printf(m, "smp_num_siblings: %u\n", smp_num_siblings); --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -9,6 +9,10 @@ struct topo_scan { =20 // Legacy CPUID[1]:EBX[23:16] number of logical processors unsigned int ebx1_nproc_shift; + + // AMD specific node ID which cannot be mapped into APIC space. + u16 amd_nodes_per_pkg; + u16 amd_node_id; }; =20 bool topo_is_converted(struct cpuinfo_x86 *c); @@ -17,6 +21,8 @@ void cpu_parse_topology(struct cpuinfo_x void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains d= om, unsigned int shift, unsigned int ncpus); bool cpu_parse_topology_ext(struct topo_scan *tscan); +void cpu_parse_topology_amd(struct topo_scan *tscan); +void cpu_topology_fixup_amd(struct topo_scan *tscan); =20 static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains = dom) { --- /dev/null +++ b/arch/x86/kernel/cpu/topology_amd.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +#include +#include +#include + +#include "cpu.h" + +static bool parse_8000_0008(struct topo_scan *tscan) +{ + struct { + u32 ncores : 8, + __rsvd0 : 4, + apicidsize : 4, + perftscsize : 2, + __rsvd1 : 14; + } ecx; + unsigned int sft; + + if (tscan->c->extended_cpuid_level < 0x80000008) + return false; + + cpuid_leaf_reg(0x80000008, CPUID_ECX, &ecx); + + /* If the APIC ID size is 0, then get the shift value from ecx.ncores */ + sft =3D ecx.apicidsize; + if (!sft) + sft =3D get_count_order(ecx.ncores + 1); + + topology_set_dom(tscan, TOPO_CORE_DOMAIN, sft, ecx.ncores + 1); + return true; +} + +static void store_node(struct topo_scan *tscan, unsigned int nr_nodes, u16= node_id) +{ + /* + * Starting with Fam 17h the DIE domain could probably be used to + * retrieve the node info on AMD/HYGON. Analysis of CPUID dumps + * suggests it's the topmost bit(s) of the CPU cores area, but + * that's guess work and neither enumerated nor documented. + * + * Up to Fam 16h this does not work at all and the legacy node ID + * has to be used. + */ + tscan->amd_nodes_per_pkg =3D nr_nodes; + tscan->amd_node_id =3D node_id; +} + +static bool parse_8000_001e(struct topo_scan *tscan, bool has_0xb) +{ + struct { + // eax + u32 x2apic_id : 32; + // ebx + u32 cuid : 8, + threads_per_cu : 8, + __rsvd0 : 16; + // ecx + u32 nodeid : 8, + nodes_per_pkg : 3, + __rsvd1 : 21; + // edx + u32 __rsvd2 : 32; + } leaf; + + if (!boot_cpu_has(X86_FEATURE_TOPOEXT)) + return false; + + cpuid_leaf(0x8000001e, &leaf); + + tscan->c->topo.initial_apicid =3D leaf.x2apic_id; + + /* + * If leaf 0xb is available, then SMT shift is set already. If not + * take it from ecx.threads_per_cu and use topo_update_dom() - + * topology_set_dom() would propagate and overwrite the already + * propagated CORE level. + */ + if (!has_0xb) { + unsigned int nthreads =3D leaf.threads_per_cu + 1; + + topology_update_dom(tscan, TOPO_SMT_DOMAIN, get_count_order(nthreads), n= threads); + } + + store_node(tscan, leaf.nodes_per_pkg + 1, leaf.nodeid); + + if (tscan->c->x86_vendor =3D=3D X86_VENDOR_AMD) { + if (tscan->c->x86 =3D=3D 0x15) + tscan->c->topo.cu_id =3D leaf.cuid; + + cacheinfo_amd_init_llc_id(tscan->c, leaf.nodeid); + } else { + /* + * Package ID is ApicId[6..] on certain Hygon CPUs. See + * commit e0ceeae708ce for explanation. The topology info + * is screwed up: The package shift is always 6 and the + * node ID is bit [4:5]. + */ + if (!boot_cpu_has(X86_FEATURE_HYPERVISOR) && tscan->c->x86_model <=3D 0x= 3) { + topology_set_dom(tscan, TOPO_CORE_DOMAIN, 6, + tscan->dom_ncpus[TOPO_CORE_DOMAIN]); + } + cacheinfo_hygon_init_llc_id(tscan->c); + } + return true; +} + +static bool parse_fam10h_node_id(struct topo_scan *tscan) +{ + struct { + union { + u64 node_id : 3, + nodes_per_pkg : 3, + unused : 58; + u64 msr; + }; + } nid; + + if (!boot_cpu_has(X86_FEATURE_NODEID_MSR)) + return false; + + rdmsrl(MSR_FAM10H_NODE_ID, nid.msr); + store_node(tscan, nid.nodes_per_pkg + 1, nid.node_id); + tscan->c->topo.llc_id =3D nid.node_id; + return true; +} + +static void legacy_set_llc(struct topo_scan *tscan) +{ + unsigned int apicid =3D tscan->c->topo.initial_apicid; + + /* parse_8000_0008() set everything up except llc_id */ + tscan->c->topo.llc_id =3D apicid >> tscan->dom_shifts[TOPO_CORE_DOMAIN]; +} + +static void parse_topology_amd(struct topo_scan *tscan) +{ + bool has_0xb =3D false; + + /* + * If the extended topology leaf 0x8000_001e is available + * try to get SMT and CORE shift from leaf 0xb first, then + * try to get the CORE shift from leaf 0x8000_0008. + */ + if (boot_cpu_has(X86_FEATURE_TOPOEXT)) + has_0xb =3D cpu_parse_topology_ext(tscan); + + if (!has_0xb && !parse_8000_0008(tscan)) + return; + + /* Prefer leaf 0x8000001e if available */ + if (parse_8000_001e(tscan, has_0xb)) + return; + + /* Try the NODEID MSR */ + if (parse_fam10h_node_id(tscan)) + return; + + legacy_set_llc(tscan); +} + +void cpu_parse_topology_amd(struct topo_scan *tscan) +{ + tscan->amd_nodes_per_pkg =3D 1; + parse_topology_amd(tscan); + + if (tscan->amd_nodes_per_pkg > 1) + set_cpu_cap(tscan->c, X86_FEATURE_AMD_DCM); +} + +void cpu_topology_fixup_amd(struct topo_scan *tscan) +{ + struct cpuinfo_x86 *c =3D tscan->c; + + /* + * Adjust the core_id relative to the node when there is more than + * one node. + */ + if (tscan->c->x86 < 0x17 && tscan->amd_nodes_per_pkg > 1) + c->topo.core_id %=3D tscan->dom_ncpus[TOPO_CORE_DOMAIN] / tscan->amd_nod= es_per_pkg; +} --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -11,11 +11,13 @@ =20 struct x86_topology_system x86_topo_system __ro_after_init; =20 +unsigned int __amd_nodes_per_pkg __ro_after_init; +EXPORT_SYMBOL_GPL(__amd_nodes_per_pkg); + void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains d= om, unsigned int shift, unsigned int ncpus) { - tscan->dom_shifts[dom] =3D shift; - tscan->dom_ncpus[dom] =3D ncpus; + topology_update_dom(tscan, dom, shift, ncpus); =20 /* Propagate to the upper levels */ for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { @@ -153,6 +155,13 @@ static void topo_set_ids(struct topo_sca /* Package relative core ID */ c->topo.core_id =3D (apicid & topo_domain_mask(TOPO_PKG_DOMAIN)) >> x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN]; + + /* Temporary workaround */ + if (tscan->amd_nodes_per_pkg) + c->topo.amd_node_id =3D c->topo.die_id =3D tscan->amd_node_id; + + 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) @@ -237,4 +246,10 @@ void __init cpu_init_topology(struct cpu */ __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. + */ + if (c->x86_vendor =3D=3D X86_VENDOR_AMD || c->x86_vendor =3D=3D X86_VENDO= R_HYGON) + __amd_nodes_per_pkg =3D __max_die_per_package =3D tscan.amd_nodes_per_pk= g; } From nobody Wed Dec 24 21:30:34 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 A66655FF08 for ; Tue, 23 Jan 2024 12:53:48 +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=1706014430; cv=none; b=ojq/u4hk5nb2OhLNXdNIpDY1egRWzfl+vSabu+8Z0sOsM3tX9oMkSuU+sumB3P6KiaNeb2anDujg2Es/S+iWSJoatN64vsv3zHlTz/kzGcYGa4YeGZLGeKx7044uTthfZD0MdadMycXjcd5z429nUWqVrJxAh1hvi0W61B37iKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014430; c=relaxed/simple; bh=gFxZ6KbLw4Lt99rilp9cqM82dexaIth78lVoUc3FPnI=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=f+rVH36zOoVLaJBgRNwxGJAfSrQanIiGc0z5HadzwC2oqN+1NdDB7CJLneirxui+jRJn2RMzeO0J4AnOCd7QnMNcOOxcfRAZ9iIaBt43p1CK5Bo3AszbSvGpen5Mnxk/B5G71IzgeZQ7Y4rguQUuGzD7buJHhKhPfjKMAq3U5x8= 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=N5E32e75; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Pg7qMvhH; 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="N5E32e75"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Pg7qMvhH" Message-ID: <20240117115908.946275828@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014426; 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=fmYc6qJRzN0mRUVfJX+xYNMGI0DYcYKnYErEVWkqbJE=; b=N5E32e755CdPjnjokQF0HIWoyXW2Oon8EGUYDB/Hhb6bJ+mv02A2CSGqfx173Ho20aXoxf EGUf9t2e21nHb3W4vyXs1PO5BtZ5/kvyn05r8eK6zzz8w5FS/+XQYWPVNolyA2BaFL8DBN 5FeYjVKjHu+EM/E3AkRGKE33IWIYrn24GvPlCTY0HRIEMOqnwYQaNphO512ciB77+eewOy xvorRfkmnw42MLk/dPoBuhcV2RP1JfM7e9YzS3R0hlzF+pTfqDZTYq2PlpLYgg1XQF/WKL w31SmK+5/+xppfQkqdahY9SWaYUceBnivOP0qlbkzX/FCDdaTj47IgCp2/KoNQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014426; 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=fmYc6qJRzN0mRUVfJX+xYNMGI0DYcYKnYErEVWkqbJE=; b=Pg7qMvhH59ooLrRDLhSDZ0CcFRZhOPbqV562U44J8sSIdH8SYtGCSQtTdIdrxUkiucLVYF AcYH5UA/UPy2FFDg== 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 v5 10/19] x86/smpboot: Teach it about topo.amd_node_id References: <20240117115752.863482697@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 13:53:45 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner When switching AMD over to the new topology parser then the match functions need to look for AMD systems with the extended topology feature at the new topo.amd_node_id member which is then holding the node id information. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/smpboot.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -488,6 +488,7 @@ static bool match_smt(struct cpuinfo_x86 =20 if (c->topo.pkg_id =3D=3D o->topo.pkg_id && c->topo.die_id =3D=3D o->topo.die_id && + c->topo.amd_node_id =3D=3D o->topo.amd_node_id && per_cpu_llc_id(cpu1) =3D=3D per_cpu_llc_id(cpu2)) { if (c->topo.core_id =3D=3D o->topo.core_id) return topology_sane(c, o, "smt"); @@ -509,10 +510,13 @@ static bool match_smt(struct cpuinfo_x86 =20 static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { - if (c->topo.pkg_id =3D=3D o->topo.pkg_id && - c->topo.die_id =3D=3D o->topo.die_id) - return true; - return false; + if (c->topo.pkg_id !=3D o->topo.pkg_id || c->topo.die_id !=3D o->topo.die= _id) + return false; + + if (boot_cpu_has(X86_FEATURE_TOPOEXT) && topology_amd_nodes_per_pkg() > 1) + return c->topo.amd_node_id =3D=3D o->topo.amd_node_id; + + return true; } =20 static bool match_l2c(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) From nobody Wed Dec 24 21:30:34 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 4B4C56024A for ; Tue, 23 Jan 2024 12:53:50 +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=1706014432; cv=none; b=Z8Loo6zvNuOTOSemNg0Uz1LUvCt2vCUuXChRaalncc1KlCCDXVKd7vLO28pxEuzfL1Go0+ugYi0vK/WpfKCeuWJRrRSSoYwZdTeYkjyxUMXssvO7724rbOzhz0aVRHQkkaxGDH3St/904BwSGFAO7vd6CtPP8ieRN1jclJxrzfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014432; c=relaxed/simple; bh=ut2Yyn6jtCHDnuihiZYadk96CXRCOtJBYYjNrFJ8eLc=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=npiTuxhYNVd40LJfQtlHbIXVVJTxHXOaVvDMc/57pJdkTk01Dsuv7WTtiBm4R//tz8mBFozOaAtkwqmi1xpha7lAAfxiEKVMEP2EVLZ3XhH8aVrlGImaPSeIL2mtKnXvyj11cEXz7w9T2LW0kK9kbruAtcUq53ZouOdd+kMu+zU= 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=QIzNafCx; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iMtJwQwq; 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="QIzNafCx"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iMtJwQwq" Message-ID: <20240117115909.011311608@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014428; 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=nNbBcKntsu51emWMe4xO1eKvZQ/jFUq9n9pfVODd5Xg=; b=QIzNafCxINODEzm7d8rcVgHrQ8tST+5zTkK5icbpqD44rblTlDoI1AtlTgG3Jj7WDIrHY/ TtZ3a4YPfOtxzAtmoCwftblFDDJjoTpuBWBooH0KUMq1ro506qrV8Mi3hU9JZWWHEFp+tF XkJLfj5D8457RVncjHQZsfhDYwb0E0tk+6F31TTBCCQERn/J5CSOXt3X3LWWdTbdaCiD2p zTAwbxd/oTVKhE+xnSbuCIy2DRROFzu14lRlc2vPQ01O3us+lFgCUI0sJYYPSemQUNga9+ szZV/N0HyBvLYHwndk9I7ZfBYtHwfVj0IdXOoi5sv9nC6/br9UotV8fXvSEvNw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014428; 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=nNbBcKntsu51emWMe4xO1eKvZQ/jFUq9n9pfVODd5Xg=; b=iMtJwQwqiwTlMhPPKeXIgumiLujT+2JhLSSEQ0Z2y+RQpk7R2KvJw2LaOr1I3WOGUhfooW gjUBhx0qrRV81wCg== 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 v5 11/19] x86/cpu: Use common topology code for AMD References: <20240117115752.863482697@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 13:53:47 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Switch it over to the new topology evaluation mechanism and remove the random bits and pieces which are sprinkled all over the place. No functional change intended. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/cpu/amd.c | 146 -----------------------------= ----- arch/x86/kernel/cpu/mce/inject.c | 3=20 arch/x86/kernel/cpu/topology_common.c | 5 - 3 files changed, 5 insertions(+), 149 deletions(-) --- --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -27,13 +27,6 @@ =20 #include "cpu.h" =20 -/* - * nodes_per_socket: Stores the number of nodes per socket. - * Refer to Fam15h Models 00-0fh BKDG - CPUID Fn8000_001E_ECX - * Node Identifiers[10:8] - */ -static u32 nodes_per_socket =3D 1; - static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p) { u32 gprs[8] =3D { 0 }; @@ -300,97 +293,6 @@ static int nearby_node(int apicid) } #endif =20 -/* - * Fix up topo::core_id for pre-F17h systems to be in the - * [0 .. cores_per_node - 1] range. Not really needed but - * kept so as not to break existing setups. - */ -static void legacy_fixup_core_id(struct cpuinfo_x86 *c) -{ - u32 cus_per_node; - - if (c->x86 >=3D 0x17) - return; - - cus_per_node =3D c->x86_max_cores / nodes_per_socket; - c->topo.core_id %=3D cus_per_node; -} - -/* - * Fixup core topology information for - * (1) AMD multi-node processors - * Assumption: Number of cores in each internal node is the same. - * (2) AMD processors supporting compute units - */ -static void amd_get_topology(struct cpuinfo_x86 *c) -{ - /* get information required for multi-node processors */ - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - int err; - u32 eax, ebx, ecx, edx; - - cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); - - c->topo.die_id =3D ecx & 0xff; - - if (c->x86 =3D=3D 0x15) - c->topo.cu_id =3D ebx & 0xff; - - if (c->x86 >=3D 0x17) { - c->topo.core_id =3D ebx & 0xff; - - if (smp_num_siblings > 1) - c->x86_max_cores /=3D smp_num_siblings; - } - - /* - * In case leaf B is available, use it to derive - * topology information. - */ - err =3D detect_extended_topology(c); - if (!err) - c->x86_coreid_bits =3D get_count_order(c->x86_max_cores); - - cacheinfo_amd_init_llc_id(c, c->topo.die_id); - - } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { - u64 value; - - rdmsrl(MSR_FAM10H_NODE_ID, value); - c->topo.die_id =3D value & 7; - c->topo.llc_id =3D c->topo.die_id; - } else - return; - - if (nodes_per_socket > 1) { - set_cpu_cap(c, X86_FEATURE_AMD_DCM); - legacy_fixup_core_id(c); - } -} - -/* - * On a AMD dual core setup the lower bits of the APIC id distinguish the = cores. - * Assumes number of cores is a power of two. - */ -static void amd_detect_cmp(struct cpuinfo_x86 *c) -{ - unsigned bits; - - bits =3D c->x86_coreid_bits; - /* Low order bits define the core id (index of core in socket) */ - c->topo.core_id =3D c->topo.initial_apicid & ((1 << bits)-1); - /* Convert the initial APIC ID into the socket ID */ - c->topo.pkg_id =3D c->topo.initial_apicid >> bits; - /* use socket ID also for last level cache */ - c->topo.llc_id =3D c->topo.die_id =3D c->topo.pkg_id; -} - -u32 amd_get_nodes_per_socket(void) -{ - return nodes_per_socket; -} -EXPORT_SYMBOL_GPL(amd_get_nodes_per_socket); - static void srat_detect_node(struct cpuinfo_x86 *c) { #ifdef CONFIG_NUMA @@ -442,32 +344,6 @@ static void srat_detect_node(struct cpui #endif } =20 -static void early_init_amd_mc(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned bits, ecx; - - /* Multi core CPU? */ - if (c->extended_cpuid_level < 0x80000008) - return; - - ecx =3D cpuid_ecx(0x80000008); - - c->x86_max_cores =3D (ecx & 0xff) + 1; - - /* CPU telling us the core id bits shift? */ - bits =3D (ecx >> 12) & 0xF; - - /* Otherwise recompute */ - if (bits =3D=3D 0) { - while ((1 << bits) < c->x86_max_cores) - bits++; - } - - c->x86_coreid_bits =3D bits; -#endif -} - static void bsp_init_amd(struct cpuinfo_x86 *c) { if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { @@ -500,18 +376,6 @@ static void bsp_init_amd(struct cpuinfo_ if (cpu_has(c, X86_FEATURE_MWAITX)) use_mwaitx_delay(); =20 - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - u32 ecx; - - ecx =3D cpuid_ecx(0x8000001e); - __max_die_per_package =3D nodes_per_socket =3D ((ecx >> 8) & 7) + 1; - } else if (boot_cpu_has(X86_FEATURE_NODEID_MSR)) { - u64 value; - - rdmsrl(MSR_FAM10H_NODE_ID, value); - __max_die_per_package =3D nodes_per_socket =3D ((value >> 3) & 7) + 1; - } - if (!boot_cpu_has(X86_FEATURE_AMD_SSBD) && !boot_cpu_has(X86_FEATURE_VIRT_SSBD) && c->x86 >=3D 0x15 && c->x86 <=3D 0x17) { @@ -636,8 +500,6 @@ static void early_init_amd(struct cpuinf u64 value; u32 dummy; =20 - early_init_amd_mc(c); - if (c->x86 >=3D 0xf) set_cpu_cap(c, X86_FEATURE_K8); =20 @@ -717,9 +579,6 @@ static void early_init_amd(struct cpuinf } } =20 - if (cpu_has(c, X86_FEATURE_TOPOEXT)) - smp_num_siblings =3D ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; - if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && !cpu_has(c, X86_FEATURE_IBPB_B= RTYPE)) { if (c->x86 =3D=3D 0x17 && boot_cpu_has(X86_FEATURE_AMD_IBPB)) setup_force_cpu_cap(X86_FEATURE_IBPB_BRTYPE); @@ -1058,9 +917,6 @@ static void init_amd(struct cpuinfo_x86 if (cpu_has(c, X86_FEATURE_FSRM)) set_cpu_cap(c, X86_FEATURE_FSRS); =20 - /* get apicid instead of initial apic id from cpuid */ - c->topo.apicid =3D read_apic_id(); - /* K6s reports MCEs but don't actually have all the MSRs */ if (c->x86 < 6) clear_cpu_cap(c, X86_FEATURE_MCE); @@ -1094,8 +950,6 @@ static void init_amd(struct cpuinfo_x86 =20 cpu_detect_cache_sizes(c); =20 - amd_detect_cmp(c); - amd_get_topology(c); srat_detect_node(c); =20 init_amd_cacheinfo(c); --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -433,8 +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) / amd_get_nodes_= per_socket(); - + cores_per_node =3D (c->x86_max_cores * smp_num_siblings) / topology_amd_n= odes_per_pkg(); return cores_per_node * node_id; } =20 --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -72,7 +72,6 @@ bool topo_is_converted(struct cpuinfo_x8 { /* Temporary until everything is converted over. */ switch (boot_cpu_data.x86_vendor) { - case X86_VENDOR_AMD: case X86_VENDOR_HYGON: return false; default: @@ -133,6 +132,10 @@ static void parse_topology(struct topo_s tscan->ebx1_nproc_shift =3D get_count_order(ebx.nproc); =20 switch (c->x86_vendor) { + case X86_VENDOR_AMD: + if (IS_ENABLED(CONFIG_CPU_SUP_AMD)) + cpu_parse_topology_amd(tscan); + break; case X86_VENDOR_CENTAUR: case X86_VENDOR_ZHAOXIN: parse_legacy(tscan); From nobody Wed Dec 24 21:30:34 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 7E8EB60262 for ; Tue, 23 Jan 2024 12:53:51 +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=1706014433; cv=none; b=BQ9Tu6wiTqc2FNK7K0j6svRWpDo5foj70rFFb9ilScxNwJ4WDInXrJfemUecpVq9n2VODMvUQhctzfGyuzmZvpvFM039UAoiGahqaXJxzyq1kinE4zPtBiOn3ctZE8wmq9yxMgsXeXPX/hi9R9P+K9OjCS5ds57hcP+I0w9pONw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014433; c=relaxed/simple; bh=JYHySPxDxbbQ1dAyZE9gW4hdS/x411phGfCs/lBQi7A=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=jp/VLf5SAGbwkJMG8AebeizrjTNVeNKaV0lPpDEZd+NKRWnLU6EXNcQMl/Ez5Klo9wYylctE4rey/UNM14TbeOos/Cpa0ip8LNXVaAca6i4ekrubgRfkg8aFnFpSZv/eHPgqvGQK3YzuiuGbvHIkiFx9RzqsnC7kGNFJgTlrZ74= 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=D9YClnhu; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uV86SOWc; 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="D9YClnhu"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uV86SOWc" Message-ID: <20240117115909.076756744@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014429; 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=FUb7TfZsW/Y7E45ham8xFseu7lZDcdhrgEftbSxG8OU=; b=D9YClnhuu/15t5cbj1i8r0S8f7DiIWvj18M4ubqOyBgb7+pAG/RkqSncCVCnqeIZye+9o2 VcTalxQE2MIqHi33uEfBd2AQF9zC9e1fO1/XFc2QCrA4NI3CeQiW+L/7GD9UQ/Xmb3fSoB tI+w7VTpA2MjcfwN18rCU6Lc9ldeZbWlGMlsMgDec8HKIMPRVWYa+uVJS+NW3wxOvg2MN/ gBByKbRV3mprc1dnnGuUuHwekuaR1utYpfbv+ZCDGzjPeg0DxvPhMGqN2fi9Hf0Fm5qFpq nBNjsKNaH0bCR0jd1hcRFDAi3XbAOP7cmWerrx5TEv3liyiz/ZunpziamKF/Ag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014429; 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=FUb7TfZsW/Y7E45ham8xFseu7lZDcdhrgEftbSxG8OU=; b=uV86SOWc0DlEqela4+4iWBd7FBmqFYhzugfgzDnYLYcDSZqTA3ZOaZG/LaJdRnUzJ3KKA9 286NFWQxYE++bNCQ== 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 v5 12/19] x86/cpu: Use common topology code for HYGON References: <20240117115752.863482697@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 13:53:48 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Switch it over to use the consolidated topology evaluation and remove the temporary safe guards which are not longer needed. No functional change intended. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/cpu/common.c | 5 - arch/x86/kernel/cpu/cpu.h | 1=20 arch/x86/kernel/cpu/hygon.c | 129 -----------------------------= ----- arch/x86/kernel/cpu/topology.h | 1=20 arch/x86/kernel/cpu/topology_common.c | 22 +---- 5 files changed, 4 insertions(+), 154 deletions(-) --- --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1779,11 +1779,6 @@ static void identify_cpu(struct cpuinfo_ /* Clear/Set all flags overridden by options, after probe */ apply_forced_caps(c); =20 -#ifdef CONFIG_X86_64 - if (!topo_is_converted(c)) - c->topo.apicid =3D apic->phys_pkg_id(c->topo.initial_apicid, 0); -#endif - /* * Set default APIC and TSC_DEADLINE MSR fencing flag. AMD and * Hygon will clear it in ->c_init() below. --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -76,7 +76,6 @@ extern void init_intel_cacheinfo(struct extern void init_amd_cacheinfo(struct cpuinfo_x86 *c); extern void init_hygon_cacheinfo(struct cpuinfo_x86 *c); =20 -extern int detect_extended_topology(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); =20 void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id); --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -18,14 +18,6 @@ =20 #include "cpu.h" =20 -#define APICID_SOCKET_ID_BIT 6 - -/* - * nodes_per_socket: Stores the number of nodes per socket. - * Refer to CPUID Fn8000_001E_ECX Node Identifiers[10:8] - */ -static u32 nodes_per_socket =3D 1; - #ifdef CONFIG_NUMA /* * To workaround broken NUMA config. Read the comment in @@ -49,80 +41,6 @@ static int nearby_node(int apicid) } #endif =20 -static void hygon_get_topology_early(struct cpuinfo_x86 *c) -{ - if (cpu_has(c, X86_FEATURE_TOPOEXT)) - smp_num_siblings =3D ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; -} - -/* - * Fixup core topology information for - * (1) Hygon multi-node processors - * Assumption: Number of cores in each internal node is the same. - * (2) Hygon processors supporting compute units - */ -static void hygon_get_topology(struct cpuinfo_x86 *c) -{ - /* get information required for multi-node processors */ - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - int err; - u32 eax, ebx, ecx, edx; - - cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); - - c->topo.die_id =3D ecx & 0xff; - - c->topo.core_id =3D ebx & 0xff; - - if (smp_num_siblings > 1) - c->x86_max_cores /=3D smp_num_siblings; - - /* - * In case leaf B is available, use it to derive - * topology information. - */ - err =3D detect_extended_topology(c); - if (!err) - c->x86_coreid_bits =3D get_count_order(c->x86_max_cores); - - /* - * Socket ID is ApicId[6] for the processors with model <=3D 0x3 - * when running on host. - */ - if (!boot_cpu_has(X86_FEATURE_HYPERVISOR) && c->x86_model <=3D 0x3) - c->topo.pkg_id =3D c->topo.apicid >> APICID_SOCKET_ID_BIT; - - cacheinfo_hygon_init_llc_id(c); - } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { - u64 value; - - rdmsrl(MSR_FAM10H_NODE_ID, value); - c->topo.die_id =3D value & 7; - c->topo.llc_id =3D c->topo.die_id; - } else - return; - - if (nodes_per_socket > 1) - set_cpu_cap(c, X86_FEATURE_AMD_DCM); -} - -/* - * On Hygon setup the lower bits of the APIC id distinguish the cores. - * Assumes number of cores is a power of two. - */ -static void hygon_detect_cmp(struct cpuinfo_x86 *c) -{ - unsigned int bits; - - bits =3D c->x86_coreid_bits; - /* Low order bits define the core id (index of core in socket) */ - c->topo.core_id =3D c->topo.initial_apicid & ((1 << bits)-1); - /* Convert the initial APIC ID into the socket ID */ - c->topo.pkg_id =3D c->topo.initial_apicid >> bits; - /* Use package ID also for last level cache */ - c->topo.llc_id =3D c->topo.die_id =3D c->topo.pkg_id; -} - static void srat_detect_node(struct cpuinfo_x86 *c) { #ifdef CONFIG_NUMA @@ -173,32 +91,6 @@ static void srat_detect_node(struct cpui #endif } =20 -static void early_init_hygon_mc(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned int bits, ecx; - - /* Multi core CPU? */ - if (c->extended_cpuid_level < 0x80000008) - return; - - ecx =3D cpuid_ecx(0x80000008); - - c->x86_max_cores =3D (ecx & 0xff) + 1; - - /* CPU telling us the core id bits shift? */ - bits =3D (ecx >> 12) & 0xF; - - /* Otherwise recompute */ - if (bits =3D=3D 0) { - while ((1 << bits) < c->x86_max_cores) - bits++; - } - - c->x86_coreid_bits =3D bits; -#endif -} - static void bsp_init_hygon(struct cpuinfo_x86 *c) { if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { @@ -212,18 +104,6 @@ static void bsp_init_hygon(struct cpuinf if (cpu_has(c, X86_FEATURE_MWAITX)) use_mwaitx_delay(); =20 - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - u32 ecx; - - ecx =3D cpuid_ecx(0x8000001e); - __max_die_per_package =3D nodes_per_socket =3D ((ecx >> 8) & 7) + 1; - } else if (boot_cpu_has(X86_FEATURE_NODEID_MSR)) { - u64 value; - - rdmsrl(MSR_FAM10H_NODE_ID, value); - __max_die_per_package =3D nodes_per_socket =3D ((value >> 3) & 7) + 1; - } - if (!boot_cpu_has(X86_FEATURE_AMD_SSBD) && !boot_cpu_has(X86_FEATURE_VIRT_SSBD)) { /* @@ -242,8 +122,6 @@ static void early_init_hygon(struct cpui { u32 dummy; =20 - early_init_hygon_mc(c); - set_cpu_cap(c, X86_FEATURE_K8); =20 rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy); @@ -284,8 +162,6 @@ static void early_init_hygon(struct cpui * we can set it unconditionally. */ set_cpu_cap(c, X86_FEATURE_VMMCALL); - - hygon_get_topology_early(c); } =20 static void init_hygon(struct cpuinfo_x86 *c) @@ -302,9 +178,6 @@ static void init_hygon(struct cpuinfo_x8 =20 set_cpu_cap(c, X86_FEATURE_REP_GOOD); =20 - /* get apicid instead of initial apic id from cpuid */ - c->topo.apicid =3D read_apic_id(); - /* * XXX someone from Hygon needs to confirm this DTRT * @@ -316,8 +189,6 @@ static void init_hygon(struct cpuinfo_x8 =20 cpu_detect_cache_sizes(c); =20 - hygon_detect_cmp(c); - hygon_get_topology(c); srat_detect_node(c); =20 init_hygon_cacheinfo(c); --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -15,7 +15,6 @@ struct topo_scan { u16 amd_node_id; }; =20 -bool topo_is_converted(struct cpuinfo_x86 *c); void cpu_init_topology(struct cpuinfo_x86 *c); void cpu_parse_topology(struct cpuinfo_x86 *c); void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains d= om, --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -68,18 +68,6 @@ static void parse_legacy(struct topo_sca topology_set_dom(tscan, TOPO_CORE_DOMAIN, core_shift, cores); } =20 -bool topo_is_converted(struct cpuinfo_x86 *c) -{ - /* Temporary until everything is converted over. */ - switch (boot_cpu_data.x86_vendor) { - case X86_VENDOR_HYGON: - return false; - default: - /* Let all UP systems use the below */ - return true; - } -} - static bool fake_topology(struct topo_scan *tscan) { /* @@ -144,6 +132,10 @@ static void parse_topology(struct topo_s if (!IS_ENABLED(CONFIG_CPU_SUP_INTEL) || !cpu_parse_topology_ext(tscan)) parse_legacy(tscan); break; + case X86_VENDOR_HYGON: + if (IS_ENABLED(CONFIG_CPU_SUP_HYGON)) + cpu_parse_topology_amd(tscan); + break; } } =20 @@ -187,9 +179,6 @@ void cpu_parse_topology(struct cpuinfo_x =20 parse_topology(&tscan, false); =20 - if (!topo_is_converted(c)) - return; - for (dom =3D TOPO_SMT_DOMAIN; dom < TOPO_MAX_DOMAIN; dom++) { if (tscan.dom_shifts[dom] =3D=3D x86_topo_system.dom_shifts[dom]) continue; @@ -218,9 +207,6 @@ void __init cpu_init_topology(struct cpu =20 parse_topology(&tscan, true); =20 - if (!topo_is_converted(c)) - return; - /* Copy the shift values and calculate the unit sizes. */ memcpy(x86_topo_system.dom_shifts, tscan.dom_shifts, sizeof(x86_topo_syst= em.dom_shifts)); From nobody Wed Dec 24 21:30:34 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 01325604BB for ; Tue, 23 Jan 2024 12:53: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=1706014435; cv=none; b=FhD5iUfK3WeOMQu9F9MqPwQfHQ8XcwbG8BTul8zyqQpRKkGL1DVApkfskYBWhX4JDIo8hRuFLijtw3A8HJOrbvg6IfUzsaCT59pyM81kot5L0X45zqxM14zr46TIpjmqDgz3eQHjCAbqw1fw1gUEgj0aU8f93+Jmsnm0wHc8pkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014435; c=relaxed/simple; bh=cwuXnq3/bfsRA6gd3Cmv/vE1KIT+6qbbvUHp22hvsww=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=NneJhQIwGzHWvquKOCqUv2Ij+jZtbrCipEjl96HRedqvcaYG5eRSdrE/HX3jYmXNbCOe8y2Anw6CXZDhG+ZUcddo10VH2LYAPkhLI0Vb7DNbG88tChRGxIQYm/gDqCJDQwncQueC7WQ1Ib5MLSxiFYJ2KcIYZWK8StoQg+7Fyso= 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=MPgHBCAW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=29fejpEh; 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="MPgHBCAW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="29fejpEh" Message-ID: <20240117115909.142089057@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014431; 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=bGJfOwxea2Kzkpm6jN0bfhkDx1w055b9eqyYHBC+Rt4=; b=MPgHBCAWenhjltLbt1mj9/hPj+TgPDdNbAxfp9bJ8FdqNit6f4OxPc3OGCwecsuKGIGC9y WdQU8Kjut+4GDL4dDeZuppgtVQQzAf4QreWTv1w+vFk847ISie/0DSZPFvKc8lX/1Aeek2 llSrdEYy+q2fQPwk1h3F5emnDbmphf7qmYEOQCqnjiEwKUDf2D7Dd8W1urf1p8e4i9OeCK uwqCZddcDu6qWk/59VsWhu+B2zxZoQlpWlhHpbk8y/5973AMBEYjINXXuoUUoeVmFiwi64 fOnHijzgSRgVC+GZtK3A2RIpJQN5HYdZANzb05hl5M6qz92sxN5QzPgIM51JXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014431; 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=bGJfOwxea2Kzkpm6jN0bfhkDx1w055b9eqyYHBC+Rt4=; b=29fejpEhesOhnZ9wsgFnV8n2wT9d0ZivSWRM+k+OoJ5+/5LJ16C0dris2zqBjFf2y2j6u9 aFWlilt48t33naAA== 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 v5 13/19] x86/mm/numa: Use core domain size on AMD References: <20240117115752.863482697@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 13:53:50 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner cpuinfo::topo::x86_coreid_bits is about to be phased out. Use the core domain size from the topology information. Add a comment why the early MPTABLE parsing is required and decrapify the loop which sets the APIC ID to node map. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/include/asm/topology.h | 5 +++++ arch/x86/mm/amdtopology.c | 35 ++++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -121,6 +121,11 @@ struct x86_topology_system { =20 extern struct x86_topology_system x86_topo_system; =20 +static inline unsigned int topology_get_domain_size(enum x86_topology_doma= ins dom) +{ + return x86_topo_system.dom_size[dom]; +} + extern const struct cpumask *cpu_coregroup_mask(int cpu); extern const struct cpumask *cpu_clustergroup_mask(int cpu); =20 --- a/arch/x86/mm/amdtopology.c +++ b/arch/x86/mm/amdtopology.c @@ -54,13 +54,11 @@ static __init int find_northbridge(void) =20 int __init amd_numa_init(void) { - u64 start =3D PFN_PHYS(0); + unsigned int numnodes, cores, apicid; + u64 prevbase, start =3D PFN_PHYS(0); u64 end =3D PFN_PHYS(max_pfn); - unsigned numnodes; - u64 prevbase; - int i, j, nb; u32 nodeid, reg; - unsigned int bits, cores, apicid_base; + int i, j, nb; =20 if (!early_pci_allowed()) return -EINVAL; @@ -158,26 +156,25 @@ int __init amd_numa_init(void) return -ENOENT; =20 /* - * We seem to have valid NUMA configuration. Map apicids to nodes - * using the coreid bits from early_identify_cpu. + * We seem to have valid NUMA configuration. Map apicids to nodes + * using the size of the core domain in the APIC space. */ - bits =3D boot_cpu_data.x86_coreid_bits; - cores =3D 1 << bits; - apicid_base =3D 0; + cores =3D topology_get_domain_size(TOPO_CORE_DOMAIN); =20 /* - * get boot-time SMP configuration: + * Scan MPTABLE to map the local APIC and ensure that the boot CPU + * APIC ID is valid. This is required because on pre ACPI/SRAT + * systems IO-APICs are mapped before the boot CPU. */ early_get_smp_config(); =20 - if (boot_cpu_physical_apicid > 0) { - pr_info("BSP APIC ID: %02x\n", boot_cpu_physical_apicid); - apicid_base =3D boot_cpu_physical_apicid; + apicid =3D boot_cpu_physical_apicid; + if (apicid > 0) + pr_info("BSP APIC ID: %02x\n", apicid); + + for_each_node_mask(i, numa_nodes_parsed) { + for (j =3D 0; j < cores; j++, apicid++) + set_apicid_to_node(apicid, i); } - - for_each_node_mask(i, numa_nodes_parsed) - for (j =3D apicid_base; j < cores + apicid_base; j++) - set_apicid_to_node((i << bits) + j, i); - return 0; } From nobody Wed Dec 24 21:30:34 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 D228D604C9 for ; Tue, 23 Jan 2024 12:53: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=1706014436; cv=none; b=DhhwcvmA6LDLtkqXaOh5yd74/psFDEMQtZXPNbeSYjcTUZoYkX7NgyLpBiAHPVzVEMgG+SOFS+aJ2dT990SKyaZzzelmQp8P4ogc8VW68DN5ArltnTTKpKB+P+ADWLQulvoKQ9MLyi13SMk+YtbXrZm9l1o5xRQg6wdbBiQxIvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014436; c=relaxed/simple; bh=dxJPvwsmxdFo/LFFVRtcyswigBmF+7W8Cgmx74fu2jA=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=Qo9E9nvu2/9gtDGICKK8sHJFmmik9IwAF2i1sp8SA9RKF01gl8WpNvYmtuK/c4jFfRKq0zctw9JGcBX8JJNo+kdorRnfWCKEw6YYSF8Uu7NluknDYQtsXjmFajQKz02jzzHqZdccOiJlj2MIuSf9BaIe7QTC2xfqJsmnetFs/PU= 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=IOC3Q1Nf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hiUJeyIv; 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="IOC3Q1Nf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hiUJeyIv" Message-ID: <20240117115909.207795463@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014432; 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=LX3PhNTWCMPpuLR0eISm6zXY5IPronq86Dl5H/SqaXU=; b=IOC3Q1NfZoYkF2fUzZ84snVBGvQ7qQPuJa7wto/Fp5PguyXR5ZrOcwruDzLypsR8sd8jW3 ayWFiud+i1RldfMfLKPPrfYguuXXz2yatNNOi+EnK6rlenFnVSPjm5KXjxnRNSDKEQyBNf YAG1ezk1YU4lomTyOChB3opnW+AWfrsdiMBgmcFANL5E5sb7XN+h5kvVtA3MBpotPBPMgF afpPnBwJNiabzW7Z8mOKOA/U8ROqPd7LF6mqhdh0C0LnkaMNIWeJYWy3txf+Bt4zxPM50r Bah8w2pZj/YUMPJrh6SDvBdPJxSuvDmJ7n660XqixxgJgmtr77w1lv0GaQcHqA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014432; 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=LX3PhNTWCMPpuLR0eISm6zXY5IPronq86Dl5H/SqaXU=; b=hiUJeyIvJJiyUuLZ23DsYlP/DPL0gfMcE8mi/OMP+Sq2nN/BbnBGc4/Ef84h0bBLdtyBh8 8t7mLZ2Qvxu1eQCQ== 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 v5 14/19] x86/cpu: Make topology_amd_node_id() use the actual node info References: <20240117115752.863482697@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 13:53:52 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Now that everything is converted switch it over and remove the intermediate operation. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/topology_common.c | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -136,7 +136,7 @@ extern const struct cpumask *cpu_cluster #define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) =20 -#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.die_id) +#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.amd_node_id) =20 extern unsigned int __max_die_per_package; =20 @@ -172,7 +172,7 @@ extern unsigned int __amd_nodes_per_pkg; =20 static inline unsigned int topology_amd_nodes_per_pkg(void) { - return __max_die_per_package; + return __amd_nodes_per_pkg; } =20 extern struct cpumask __cpu_primary_thread_mask; --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -151,9 +151,7 @@ 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 - /* Temporary workaround */ - if (tscan->amd_nodes_per_pkg) - c->topo.amd_node_id =3D c->topo.die_id =3D tscan->amd_node_id; + 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); @@ -239,6 +237,5 @@ void __init cpu_init_topology(struct cpu * AMD systems have Nodes per package which cannot be mapped to * APIC ID. */ - if (c->x86_vendor =3D=3D X86_VENDOR_AMD || c->x86_vendor =3D=3D X86_VENDO= R_HYGON) - __amd_nodes_per_pkg =3D __max_die_per_package =3D tscan.amd_nodes_per_pk= g; + __amd_nodes_per_pkg =3D tscan.amd_nodes_per_pkg; } From nobody Wed Dec 24 21:30:34 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 21F885F543 for ; Tue, 23 Jan 2024 12:53:55 +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=1706014437; cv=none; b=PNbDDS5sx+UHlP6C5S39PGdcs3DWq4nEFvFn8fjxCXoc8AXYDirijxKcFysmB/cMDHtMyouzlPNHoqCt6emyJK0eOdUF2uurgTFDRjhIyaGTrzDZNIGKyjuTPvOSvjBLdYdmE/HsnGYo40sIU4XneI0UoxjHifU1DrB3bHQCfk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014437; c=relaxed/simple; bh=AJ63wiLn+lBQYuE12DVNuHDEDNoTQTNoVPZuy3Gu2ec=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=RrIgsLs3TOSqV9bGdgGaY9+LmG9vh69k0QKL0Ba+9+4ZhCPuRVBnihzro/+ZGLayFsUVLIZiOj6r+UqfxGEBtWaUDGA5m9E+KfADMXycoKcdjdVMM4VfKjQI/n0/HE8e8qnA7Ny+uxg+v4g6Dk/zeteEcarqZe74/1kHldfof98= 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=4jXmitxY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rG7Lrp3m; 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="4jXmitxY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rG7Lrp3m" Message-ID: <20240117115909.273485469@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014434; 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=rd2HJGNJw1JP8IFfPVX6/xOUnueGA05Bvgwqv19nM5U=; b=4jXmitxY+avN5cHBXIS8wUXQ8xcPjbu1T/4lJRt4EqU9YW48lqIqrvjlUn49aink5MV0Fo foKoR52nJn9GXy4dhW5160RTeHis2uAA67t3yk0q4savsL13YzK0EDQwRCx2wDsSG8LfPb emL4+vkNSjlvogAlmppI6m+ZTkJ7FZKxJCf7N0L+QBt7ffJ0QMvw2eBn4uwlZTuwLMoaXT 0vFM2jG7caOFORpgIvy5nOvz3FNUywOH83+cYC/7jgtSTxSel4zFTPxsl1a8pZIiktlxp4 Xu48UEkQLl2eXubU7NrAULcIM8ueY5b652VtRAQ9VxWAbEimME+jw8J6xE1w7w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014434; 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=rd2HJGNJw1JP8IFfPVX6/xOUnueGA05Bvgwqv19nM5U=; b=rG7Lrp3mMwGFVW8jH3X1gkssIBWFc3ZdiY8kbxFkelXuLol/afxnmRI0s5NdkxfLAdozpl vJbJLqYV1oCG43Bw== 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 v5 15/19] x86/cpu: Remove topology.c References: <20240117115752.863482697@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 13:53:53 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner No more users. Stick it into the ugly code museum. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/kernel/cpu/Makefile | 2=20 arch/x86/kernel/cpu/topology.c | 164 ------------------------------------= ----- 2 files changed, 1 insertion(+), 165 deletions(-) delete mode 100644 arch/x86/kernel/cpu/topology.c --- --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o :=3D n KCSAN_SANITIZE_common.o :=3D n =20 obj-y :=3D cacheinfo.o scattered.o -obj-y +=3D topology_common.o topology_ext.o topology_amd.o topology.o +obj-y +=3D topology_common.o topology_ext.o topology_amd.o obj-y +=3D common.o obj-y +=3D rdrand.o obj-y +=3D match.o --- a/arch/x86/kernel/cpu/topology.c +++ /dev/null @@ -1,164 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Check for extended topology enumeration cpuid leaf 0xb and if it - * exists, use it for populating initial_apicid and cpu topology - * detection. - */ - -#include -#include -#include -#include - -#include "cpu.h" - -/* leaf 0xb SMT level */ -#define SMT_LEVEL 0 - -/* extended topology sub-leaf types */ -#define INVALID_TYPE 0 -#define SMT_TYPE 1 -#define CORE_TYPE 2 -#define DIE_TYPE 5 - -#define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff) -#define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f) -#define LEVEL_MAX_SIBLINGS(ebx) ((ebx) & 0xffff) - -#ifdef CONFIG_SMP -/* - * Check if given CPUID extended topology "leaf" is implemented - */ -static int check_extended_topology_leaf(int leaf) -{ - unsigned int eax, ebx, ecx, edx; - - cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - - if (ebx =3D=3D 0 || (LEAFB_SUBTYPE(ecx) !=3D SMT_TYPE)) - return -1; - - return 0; -} -/* - * Return best CPUID Extended Topology Leaf supported - */ -static int detect_extended_topology_leaf(struct cpuinfo_x86 *c) -{ - if (c->cpuid_level >=3D 0x1f) { - if (check_extended_topology_leaf(0x1f) =3D=3D 0) - return 0x1f; - } - - if (c->cpuid_level >=3D 0xb) { - if (check_extended_topology_leaf(0xb) =3D=3D 0) - return 0xb; - } - - return -1; -} -#endif - -int detect_extended_topology_early(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned int eax, ebx, ecx, edx; - int leaf; - - leaf =3D detect_extended_topology_leaf(c); - if (leaf < 0) - return -1; - - set_cpu_cap(c, X86_FEATURE_XTOPOLOGY); - - cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - /* - * initial apic id, which also represents 32-bit extended x2apic id. - */ - c->topo.initial_apicid =3D edx; - smp_num_siblings =3D max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)= ); -#endif - return 0; -} - -/* - * Check for extended topology enumeration cpuid leaf, and if it - * exists, use it for populating initial_apicid and cpu topology - * detection. - */ -int detect_extended_topology(struct cpuinfo_x86 *c) -{ -#ifdef CONFIG_SMP - unsigned int eax, ebx, ecx, edx, sub_index; - unsigned int ht_mask_width, core_plus_mask_width, die_plus_mask_width; - unsigned int core_select_mask, core_level_siblings; - unsigned int die_select_mask, die_level_siblings; - unsigned int pkg_mask_width; - bool die_level_present =3D false; - int leaf; - - leaf =3D detect_extended_topology_leaf(c); - if (leaf < 0) - return -1; - - /* - * Populate HT related information from sub-leaf level 0. - */ - cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - c->topo.initial_apicid =3D edx; - core_level_siblings =3D LEVEL_MAX_SIBLINGS(ebx); - smp_num_siblings =3D max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)= ); - core_plus_mask_width =3D ht_mask_width =3D BITS_SHIFT_NEXT_LEVEL(eax); - die_level_siblings =3D LEVEL_MAX_SIBLINGS(ebx); - pkg_mask_width =3D die_plus_mask_width =3D BITS_SHIFT_NEXT_LEVEL(eax); - - sub_index =3D 1; - while (true) { - cpuid_count(leaf, sub_index, &eax, &ebx, &ecx, &edx); - - /* - * Check for the Core type in the implemented sub leaves. - */ - if (LEAFB_SUBTYPE(ecx) =3D=3D CORE_TYPE) { - core_level_siblings =3D LEVEL_MAX_SIBLINGS(ebx); - core_plus_mask_width =3D BITS_SHIFT_NEXT_LEVEL(eax); - die_level_siblings =3D core_level_siblings; - die_plus_mask_width =3D BITS_SHIFT_NEXT_LEVEL(eax); - } - if (LEAFB_SUBTYPE(ecx) =3D=3D DIE_TYPE) { - die_level_present =3D true; - die_level_siblings =3D LEVEL_MAX_SIBLINGS(ebx); - die_plus_mask_width =3D BITS_SHIFT_NEXT_LEVEL(eax); - } - - if (LEAFB_SUBTYPE(ecx) !=3D INVALID_TYPE) - pkg_mask_width =3D BITS_SHIFT_NEXT_LEVEL(eax); - else - break; - - sub_index++; - } - - core_select_mask =3D (~(-1 << pkg_mask_width)) >> ht_mask_width; - die_select_mask =3D (~(-1 << die_plus_mask_width)) >> - core_plus_mask_width; - - c->topo.core_id =3D apic->phys_pkg_id(c->topo.initial_apicid, - ht_mask_width) & core_select_mask; - - if (die_level_present) { - c->topo.die_id =3D apic->phys_pkg_id(c->topo.initial_apicid, - core_plus_mask_width) & die_select_mask; - } - - c->topo.pkg_id =3D apic->phys_pkg_id(c->topo.initial_apicid, pkg_mask_wid= th); - /* - * Reinit the apicid, now that we have extended initial_apicid. - */ - c->topo.apicid =3D apic->phys_pkg_id(c->topo.initial_apicid, 0); - - c->x86_max_cores =3D (core_level_siblings / smp_num_siblings); - __max_die_per_package =3D (die_level_siblings / core_level_siblings); -#endif - return 0; -} From nobody Wed Dec 24 21:30:34 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 8E119604D6 for ; Tue, 23 Jan 2024 12:53: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=1706014438; cv=none; b=DkZ9DWhyOSeq2vbk4jSwbBqQzbHwTuOEklSmyFWtaa28fvb76l7kSe5/BMl1ub646MJ/jRkr/ESxdkJBmESSekxerfxY/dFnBuSLE33/5uuQ9w+MPQmL5Nb3xExJT6UHCgcktuHURLQbrp/GoR1fkFX1wVTJUyHPQcrnR92K60w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014438; c=relaxed/simple; bh=AEkyGqvQxZvvnLheJ+2RsHCBjK//W9SgFIwdXPvgaWs=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=q4DUprjhbaeODkdoGG9Ll1LzAAKu7GySmyeIIe06G/WxP3oC8a5dl+q4stOQT0gjK1y8HEVc6smC9eZbq5THtLsVnEKtJjSHGt4gFLKRseGqnjmVH6sb2Bvl56QS1TapglPMZxUPo3oinEiTslxLK7zbx7nkqbjq8F2kSB4NJJ0= 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=xsTodtkB; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3ixWbFge; 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="xsTodtkB"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3ixWbFge" Message-ID: <20240117115909.337697156@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014436; 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=uV+ip67x+Ju70E82zPTuRlEtqmL25y3HTAwmTVToZH8=; b=xsTodtkBe+S8NIX3G5ZldqUFBkqsEehEY96jhuFD7OdLXgbNdJuHKaaYDrMV7GFnhNq+vv SdcrwVQgHgNY4VcOl7nOApSoDN4GYAw8LIvZoxKUIBvSSUra1vkmoasOGKE5RM4QgcrD6g SwahfZOMuWQ65fqIfg43v6KjQl/cUpz8eeVi4AbexhJ4YNdX3AN7Zgb/1xRfLF96CYCVww QttvSLNoys8UtFYQj8zG03kD7lrII/oBEvv9oXCUpFSX3hP73JQLmGuQ+s+bXRXrc8t41B uHFbJP/qU+FrsamXeRDBgMQuDN2JdTzuy/T82v8WTSD6K66vdGcsoyZ2tlHSTw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014436; 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=uV+ip67x+Ju70E82zPTuRlEtqmL25y3HTAwmTVToZH8=; b=3ixWbFge7/xPU/BX6nHvWPaNlvw6PFzA/W0mxlfQPb++cTYz5iCLKE3YjL5wWJBSNjpjmO 5dDKfJkI0ds5i2CA== 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 v5 16/19] x86/cpu: Remove x86_coreid_bits References: <20240117115752.863482697@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 13:53:55 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner No more users. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/include/asm/processor.h | 2 -- arch/x86/kernel/cpu/common.c | 1 - 2 files changed, 3 deletions(-) --- --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -122,8 +122,6 @@ struct cpuinfo_x86 { #endif __u8 x86_virt_bits; __u8 x86_phys_bits; - /* CPUID returned core id bits: */ - __u8 x86_coreid_bits; /* Max extended CPUID function supported: */ __u32 extended_cpuid_level; /* Maximum supported CPUID level, -1=3Dno CPUID: */ --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1752,7 +1752,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_vendor_id[0] =3D '\0'; /* Unset */ c->x86_model_id[0] =3D '\0'; /* Unset */ c->x86_max_cores =3D 1; - c->x86_coreid_bits =3D 0; #ifdef CONFIG_X86_64 c->x86_clflush_size =3D 64; c->x86_phys_bits =3D 36; From nobody Wed Dec 24 21:30:34 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 8C9E9605D8 for ; Tue, 23 Jan 2024 12:53: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=1706014441; cv=none; b=Xbas8dDeIymP+4ig3X+dB4E20TTV8NgovdvW1Ip+fx295yNMUvJzIcqqUV7Og+XXcuvkEPpf6ltiJ++nyo1zLGEG10VZC81EMECNBnIPrjb5C6ce3gY/UvLTW9t9TSD4KQwT3kl/hz+0riWA9GZPwIEm0T4xE4XJN4dha2SH/A8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014441; c=relaxed/simple; bh=PnsbmsuQuKaUVhkSUBDu0PEUx5aW5bL8PrtHc9WcVTI=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=dFbnMIOdiy1y4ea82SbmEHyHxK0ftNmgg8xDx6+XNLrLHHkSibbVljDxApIUYVZ+WBzgk1J5BlKcRrcrrdCATa17ejrB+ve8dfcxAbznuxvxLx+9kvb+YR4d/qT1F1GXPq1CLYZnWIzml2uymaLpAgTjxCBV9aFB/4EH5okXJUA= 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=1Y5U0jkh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=trkjBPOT; 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="1Y5U0jkh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="trkjBPOT" Message-ID: <20240117115909.402462466@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014437; 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=N8YeS5UV8uEweP5dy/7M8glzwMeJnPQXY60aHFhlneU=; b=1Y5U0jkhn7CnBqdIdQDGeo+rIt7jr+R5MtlYU4g8vtKaSy+bYyO8iik/rl2j8xk2JtKr47 8kJd5fShxCj5wBS13FSJrfxygM8Ti6p6gBN6Z+7mtovqEEn0NOk5uZUKHne/cbKXKz6IMl F67Nxg2dDG72mF9267cFFpgNLo5mSxt3i+SbcpT1F92QD8nHrxCYcbcT4CDhaFAGOYBF2k MIDIr4zeYcZ9nkQiU/aasMgArbeCNLwNXYSzuM0x7R0OT2oP5vq68QhxCyipcp2dv+ZQ/O TXZs1L2b0mk4Up7QiDRhDAsgVI0tyhbZ1bS7wXYwL2WrI9Ay7TVtV6T70n9L8g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014437; 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=N8YeS5UV8uEweP5dy/7M8glzwMeJnPQXY60aHFhlneU=; b=trkjBPOTpvkSKnHQi5xs6WKgaGPJDhQ/mhsUFTEcjL51x9xEwvirUOp32qGj+J3hXFhDS/ 7786lUq6gu5xcmDw== 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 v5 17/19] x86/apic: Remove unused phys_pkg_id() callback References: <20240117115752.863482697@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 13:53:56 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Now that the core code does not use this monstrosity anymore, it's time to put it to rest. The only real purpose was to read the APIC ID on UV and VSMP systems for the actual evaluation. That's what the core code does now. For doing the actual shift operation there is truly no APIC callback required. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/include/asm/apic.h | 1 - arch/x86/kernel/apic/apic_flat_64.c | 7 ------- arch/x86/kernel/apic/apic_noop.c | 3 --- arch/x86/kernel/apic/apic_numachip.c | 7 ------- arch/x86/kernel/apic/bigsmp_32.c | 6 ------ arch/x86/kernel/apic/local.h | 1 - arch/x86/kernel/apic/probe_32.c | 6 ------ arch/x86/kernel/apic/x2apic_cluster.c | 1 - arch/x86/kernel/apic/x2apic_phys.c | 6 ------ arch/x86/kernel/apic/x2apic_uv_x.c | 11 ----------- arch/x86/kernel/vsmp_64.c | 13 ------------- arch/x86/xen/apic.c | 6 ------ 12 files changed, 68 deletions(-) --- --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -295,7 +295,6 @@ struct apic { void (*init_apic_ldr)(void); void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap= ); u32 (*cpu_present_to_apicid)(int mps_cpu); - u32 (*phys_pkg_id)(u32 cpuid_apic, int index_msb); =20 u32 (*get_apic_id)(u32 id); u32 (*set_apic_id)(u32 apicid); --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -66,11 +66,6 @@ static u32 set_apic_id(u32 id) return (id & 0xFF) << 24; } =20 -static u32 flat_phys_pkg_id(u32 initial_apic_id, int index_msb) -{ - return initial_apic_id >> index_msb; -} - static int flat_probe(void) { return 1; @@ -88,7 +83,6 @@ static struct apic apic_flat __ro_after_ =20 .init_apic_ldr =3D default_init_apic_ldr, .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D flat_phys_pkg_id, =20 .max_apic_id =3D 0xFE, .get_apic_id =3D flat_get_apic_id, @@ -158,7 +152,6 @@ static struct apic apic_physflat __ro_af .disable_esr =3D 0, =20 .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D flat_phys_pkg_id, =20 .max_apic_id =3D 0xFE, .get_apic_id =3D flat_get_apic_id, --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -29,7 +29,6 @@ static void noop_send_IPI_self(int vecto static void noop_apic_icr_write(u32 low, u32 id) { } static int noop_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip) = { return -1; } static u64 noop_apic_icr_read(void) { return 0; } -static u32 noop_phys_pkg_id(u32 cpuid_apic, int index_msb) { return 0; } static u32 noop_get_apic_id(u32 apicid) { return 0; } static void noop_apic_eoi(void) { } =20 @@ -55,8 +54,6 @@ struct apic apic_noop __ro_after_init =3D .ioapic_phys_id_map =3D default_ioapic_phys_id_map, .cpu_present_to_apicid =3D default_cpu_present_to_apicid, =20 - .phys_pkg_id =3D noop_phys_pkg_id, - .max_apic_id =3D 0xFE, .get_apic_id =3D noop_get_apic_id, =20 --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -56,11 +56,6 @@ static u32 numachip2_set_apic_id(u32 id) return id << 24; } =20 -static u32 numachip_phys_pkg_id(u32 initial_apic_id, int index_msb) -{ - return initial_apic_id >> index_msb; -} - static void numachip1_apic_icr_write(int apicid, unsigned int val) { write_lcsr(CSR_G3_EXT_IRQ_GEN, (apicid << 16) | val); @@ -227,7 +222,6 @@ static const struct apic apic_numachip1 .disable_esr =3D 0, =20 .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D numachip_phys_pkg_id, =20 .max_apic_id =3D UINT_MAX, .get_apic_id =3D numachip1_get_apic_id, @@ -263,7 +257,6 @@ static const struct apic apic_numachip2 .disable_esr =3D 0, =20 .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D numachip_phys_pkg_id, =20 .max_apic_id =3D UINT_MAX, .get_apic_id =3D numachip2_get_apic_id, --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -29,11 +29,6 @@ static void bigsmp_ioapic_phys_id_map(ph physids_promote(0xFFL, retmap); } =20 -static u32 bigsmp_phys_pkg_id(u32 cpuid_apic, int index_msb) -{ - return cpuid_apic >> index_msb; -} - static void bigsmp_send_IPI_allbutself(int vector) { default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector); @@ -87,7 +82,6 @@ static struct apic apic_bigsmp __ro_afte .check_apicid_used =3D bigsmp_check_apicid_used, .ioapic_phys_id_map =3D bigsmp_ioapic_phys_id_map, .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D bigsmp_phys_pkg_id, =20 .max_apic_id =3D 0xFE, .get_apic_id =3D bigsmp_get_apic_id, --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -17,7 +17,6 @@ void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int = dest); u32 x2apic_get_apic_id(u32 id); u32 x2apic_set_apic_id(u32 id); -u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb); =20 void x2apic_send_IPI_all(int vector); void x2apic_send_IPI_allbutself(int vector); --- a/arch/x86/kernel/apic/probe_32.c +++ b/arch/x86/kernel/apic/probe_32.c @@ -18,11 +18,6 @@ =20 #include "local.h" =20 -static u32 default_phys_pkg_id(u32 cpuid_apic, int index_msb) -{ - return cpuid_apic >> index_msb; -} - static u32 default_get_apic_id(u32 x) { unsigned int ver =3D GET_APIC_VERSION(apic_read(APIC_LVR)); @@ -53,7 +48,6 @@ static struct apic apic_default __ro_aft .init_apic_ldr =3D default_init_apic_ldr, .ioapic_phys_id_map =3D default_ioapic_phys_id_map, .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D default_phys_pkg_id, =20 .max_apic_id =3D 0xFE, .get_apic_id =3D default_get_apic_id, --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -235,7 +235,6 @@ static struct apic apic_x2apic_cluster _ .init_apic_ldr =3D init_x2apic_ldr, .ioapic_phys_id_map =3D NULL, .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D x2apic_phys_pkg_id, =20 .max_apic_id =3D UINT_MAX, .x2apic_set_max_apicid =3D true, --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -134,11 +134,6 @@ u32 x2apic_set_apic_id(u32 id) return id; } =20 -u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb) -{ - return initial_apicid >> index_msb; -} - static struct apic apic_x2apic_phys __ro_after_init =3D { =20 .name =3D "physical x2apic", @@ -150,7 +145,6 @@ static struct apic apic_x2apic_phys __ro .disable_esr =3D 0, =20 .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D x2apic_phys_pkg_id, =20 .max_apic_id =3D UINT_MAX, .x2apic_set_max_apicid =3D true, --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -784,16 +784,6 @@ static u32 set_apic_id(u32 id) return id; } =20 -static unsigned int uv_read_apic_id(void) -{ - return x2apic_get_apic_id(apic_read(APIC_ID)); -} - -static u32 uv_phys_pkg_id(u32 initial_apicid, int index_msb) -{ - return uv_read_apic_id() >> index_msb; -} - static int uv_probe(void) { return apic =3D=3D &apic_x2apic_uv_x; @@ -810,7 +800,6 @@ static struct apic apic_x2apic_uv_x __ro .disable_esr =3D 0, =20 .cpu_present_to_apicid =3D default_cpu_present_to_apicid, - .phys_pkg_id =3D uv_phys_pkg_id, =20 .max_apic_id =3D UINT_MAX, .get_apic_id =3D x2apic_get_apic_id, --- a/arch/x86/kernel/vsmp_64.c +++ b/arch/x86/kernel/vsmp_64.c @@ -127,25 +127,12 @@ static void __init vsmp_cap_cpus(void) #endif } =20 -static u32 apicid_phys_pkg_id(u32 initial_apic_id, int index_msb) -{ - return read_apic_id() >> index_msb; -} - -static void vsmp_apic_post_init(void) -{ - /* need to update phys_pkg_id */ - apic->phys_pkg_id =3D apicid_phys_pkg_id; -} - void __init vsmp_init(void) { detect_vsmp_box(); if (!is_vsmp_box()) return; =20 - x86_platform.apic_post_init =3D vsmp_apic_post_init; - vsmp_cap_cpus(); =20 set_vsmp_ctl(); --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -110,11 +110,6 @@ static int xen_madt_oem_check(char *oem_ return xen_pv_domain(); } =20 -static u32 xen_phys_pkg_id(u32 initial_apic_id, int index_msb) -{ - return initial_apic_id >> index_msb; -} - static u32 xen_cpu_present_to_apicid(int cpu) { if (cpu_present(cpu)) @@ -133,7 +128,6 @@ static struct apic xen_pv_apic __ro_afte .disable_esr =3D 0, =20 .cpu_present_to_apicid =3D xen_cpu_present_to_apicid, - .phys_pkg_id =3D xen_phys_pkg_id, /* detect_ht */ =20 .max_apic_id =3D UINT_MAX, .get_apic_id =3D xen_get_apic_id, From nobody Wed Dec 24 21:30:34 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 CCD4660882 for ; Tue, 23 Jan 2024 12:54: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=1706014443; cv=none; b=BpVnSskYjCOijg/tLJ7JTGQPpwnJn0st7HOUMzY/p5Q157VcI9LOduWgi3cRwWGiWesrdA5yVTya7T8rDB8dw0hjqtJpHOv/PJKwRFd7fvwwajQxEybHxRPTMuYgJgkOoCM44DU1NGxG1VezNXGTJGOs8rbfzYmgVk6WJiRvAL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014443; c=relaxed/simple; bh=hNdvmf+GcuI6Qqrr7dcRGCr10KX039mF7IbsepcDHes=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=bDhKw8m+tSTvCRPg9v/gcJbmOnE3OZTZ5ylTo3W/bGk5xfckAR12z1R1daZCVPJiO6bOncUgkrcso4dDN+o1YbqJJ3eeMEXomqNkcGcaGXVSvuQeh2xe4DJHwm70j9BVqN+Ch+PJ9ysjDN++MozYcgj9G1cu4bRW+K3WkbGe1+M= 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=C5n09rJ6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YUY3vMse; 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="C5n09rJ6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YUY3vMse" Message-ID: <20240117115909.467809167@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014439; 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=XBJ9whjiLYJSa7ZVPKMljupzMZu9OX7b/3pvXVcku2Q=; b=C5n09rJ6TShguJq64ARFuRgYtLsXNMI/HVK8w1uK+Med+S7lGFPBraObsnzKSR5tBDjXwR Ix2reEM7SLB1Z1pzL72NGheje+n3PnqGxg4AIPpdM5CPbpdysr98hcZg0n/anpSCXm1IgR rx8gQ03aSr2x96Z8211Gaty8S5hgeQRQBKGfGodas79jHIDJECIf/RQNfVkc5lQPpDZWT+ K7IB7QCQ3aLEENPvBANZRZ9/oPuPk9cBH/KK2JTXh0GfMgLPIFK3YrfB0ZZGR/N0BGRSwS I5hzVMmXzI+6mrkXL1a/rvF0/vo7v3MVO8Tt7Tk12bQAw8MlGZzvE+j6us5z8g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014439; 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=XBJ9whjiLYJSa7ZVPKMljupzMZu9OX7b/3pvXVcku2Q=; b=YUY3vMseFJsvX0EoWf52T960x8+5L5Kgr2LDt9dHOVpR3uYaxqsiu6cqe3WGKfE2Rivqg2 ocro2TAnS8FtZsAA== 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 v5 18/19] x86/xen/smp_pv: Remove cpudata fiddling References: <20240117115752.863482697@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 13:53:58 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The new topology CPUID parser installs already fake topology for XEN/PV, which ends up with cpuinfo::max_cores =3D 1. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/xen/smp_pv.c | 3 --- 1 file changed, 3 deletions(-) --- --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -73,7 +73,6 @@ static void cpu_bringup(void) } cpu =3D smp_processor_id(); smp_store_cpu_info(cpu); - cpu_data(cpu).x86_max_cores =3D 1; set_cpu_sibling_map(cpu); =20 speculative_store_bypass_ht_init(); @@ -224,8 +223,6 @@ static void __init xen_pv_smp_prepare_cp =20 smp_prepare_cpus_common(); =20 - cpu_data(0).x86_max_cores =3D 1; - speculative_store_bypass_ht_init(); =20 xen_pmu_init(0); From nobody Wed Dec 24 21:30:34 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 2DE126088E for ; Tue, 23 Jan 2024 12:54: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=1706014444; cv=none; b=CrGHomN7RNbjxZP+jkli2bMyyABysT1uEwfNGcCSQLdt0l1ihHWcZMgGosSK/Kcw/0xxlux3gypa/ak2HjB7N1TtbYlwJ+tHzcZHxzQ0b/tCouiygJ6seD50cOgENZGzeNdQvsDyZcWN2XNHfX8431YDCwajPNOf/AaOMcnz3Lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706014444; c=relaxed/simple; bh=IiVU/EQPGLAtjCv4Y2GFk70d/aytmYANUKUADaDyc3w=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=sWCNEC+6EvO96eMahJiOdz1OJuPZvfYChHGUyrtPdeEIyCZDxnSbbQ9oX8x5/KA4N2EvH5HPsF8JYx0fAcInAZIGvzg0CD4DljiJD/LmN2UC9+qPGz8vUgFNXPWo2YIN0Hw9dT4tsJU61lxLuxxMXsI1UTr4lWYlaqxksRn3yc0= 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=HsZoHXy8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tbSHBNLm; 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="HsZoHXy8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tbSHBNLm" Message-ID: <20240117115909.537148439@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706014441; 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=FJqT3mPgCqqamnmXXVMxEDykuKO5FlyIcFcBDU9yaR4=; b=HsZoHXy8+gRXUpUOH/XUP7HwSjmrpPS5d/+Kg8DwCvQZKiGhYiAPjs6grU2ThZbaDKEVo6 ZhYfHva3KHDLjem4JbfPVv4eO4Vd67OkaR16OJK5uRUFslYuH/pJLTlzpgPQG+08iUIZ5q vJpwqS8uV4XoYHO4zswYi8c6ukPDV9e0Hk1IlyAyUrSP3y/JYvVatdyvjGGRYQOkYNf4Ae 02FmC0gaSfN2nmKY1BIWzPaXeCaHsDXPTZn8dLlYgFIocI4TJYWjiDvrFUNS4MDkax2sGg I+Hs/8FV3THpoYMhuSiSAWCAfAVuvkeoTy42Scyf/DGLWjmIETQpfAGnhOwMcw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706014441; 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=FJqT3mPgCqqamnmXXVMxEDykuKO5FlyIcFcBDU9yaR4=; b=tbSHBNLmr0ByTI4PN3XIyfrGmgJGJ/lnJFqsBh2M5NYZzTUdI/wfz10ReiSqh533LX3R8Z lrl/msVk4iPWaEDA== 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 v5 19/19] x86/apic/uv: Remove the private leaf 0xb parser References: <20240117115752.863482697@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 13:53:59 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The package shift has been already evaluated by the early CPU init. Put the mindless copy right next to the original leaf 0xb parser. Signed-off-by: Thomas Gleixner Tested-by: Juergen Gross Tested-by: Sohil Mehta Tested-by: Michael Kelley --- arch/x86/include/asm/topology.h | 5 +++ arch/x86/kernel/apic/x2apic_uv_x.c | 52 ++++++--------------------------= ----- 2 files changed, 14 insertions(+), 43 deletions(-) --- --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -126,6 +126,11 @@ static inline unsigned int topology_get_ return x86_topo_system.dom_size[dom]; } =20 +static inline unsigned int topology_get_domain_shift(enum x86_topology_dom= ains dom) +{ + return dom =3D=3D TOPO_SMT_DOMAIN ? 0 : x86_topo_system.dom_shifts[dom - = 1]; +} + extern const struct cpumask *cpu_coregroup_mask(int cpu); extern const struct cpumask *cpu_clustergroup_mask(int cpu); =20 --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -241,54 +241,20 @@ static void __init uv_tsc_check_sync(voi is_uv(UV3) ? sname.s3.field : \ undef) =20 -/* [Copied from arch/x86/kernel/cpu/topology.c:detect_extended_topology()]= */ - -#define SMT_LEVEL 0 /* Leaf 0xb SMT level */ -#define INVALID_TYPE 0 /* Leaf 0xb sub-leaf types */ -#define SMT_TYPE 1 -#define CORE_TYPE 2 -#define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff) -#define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f) - -static void set_x2apic_bits(void) -{ - unsigned int eax, ebx, ecx, edx, sub_index; - unsigned int sid_shift; - - cpuid(0, &eax, &ebx, &ecx, &edx); - if (eax < 0xb) { - pr_info("UV: CPU does not have CPUID.11\n"); - return; - } - - cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - if (ebx =3D=3D 0 || (LEAFB_SUBTYPE(ecx) !=3D SMT_TYPE)) { - pr_info("UV: CPUID.11 not implemented\n"); - return; - } - - sid_shift =3D BITS_SHIFT_NEXT_LEVEL(eax); - sub_index =3D 1; - do { - cpuid_count(0xb, sub_index, &eax, &ebx, &ecx, &edx); - if (LEAFB_SUBTYPE(ecx) =3D=3D CORE_TYPE) { - sid_shift =3D BITS_SHIFT_NEXT_LEVEL(eax); - break; - } - sub_index++; - } while (LEAFB_SUBTYPE(ecx) !=3D INVALID_TYPE); - - uv_cpuid.apicid_shift =3D 0; - uv_cpuid.apicid_mask =3D (~(-1 << sid_shift)); - uv_cpuid.socketid_shift =3D sid_shift; -} - static void __init early_get_apic_socketid_shift(void) { + unsigned int sid_shift =3D topology_get_domain_shift(TOPO_PKG_DOMAIN); + if (is_uv2_hub() || is_uv3_hub()) uvh_apicid.v =3D uv_early_read_mmr(UVH_APICID); =20 - set_x2apic_bits(); + if (sid_shift) { + uv_cpuid.apicid_shift =3D 0; + uv_cpuid.apicid_mask =3D (~(-1 << sid_shift)); + uv_cpuid.socketid_shift =3D sid_shift; + } else { + pr_info("UV: CPU does not have valid CPUID.11\n"); + } =20 pr_info("UV: apicid_shift:%d apicid_mask:0x%x\n", uv_cpuid.apicid_shift, = uv_cpuid.apicid_mask); pr_info("UV: socketid_shift:%d pnode_mask:0x%x\n", uv_cpuid.socketid_shif= t, uv_cpuid.pnode_mask);