From 602852c6388dd700e45c7c9817e9fc7e55cb4711 Mon Sep 17 00:00:00 2001 From: Pu Wen Date: Thu, 8 Jun 2023 11:44:25 +0800 Subject: [PATCH] x86/cpu/hygon: Modify the CPU topology deriving method for Hygon Hygon processors before model 4h have not use the CPUID leaf 0xB, so use commit e0ceeae708ce ("x86/CPU/hygon: Fix phys_proc_id calculation logic for multi-die processors") to derive the socket ID when running on host. If kernel running on guest, use the hypervisor's default. For model 4h, Hygon processors use CPUID leaf 0xB to identify SMT and CORE level types, so use function detect_extended_topology() to derive the core ID, socket ID and APIC ID. But it still set __max_die_per_package to nodes_per_socket because it lacks the DIE level type. Signed-off-by: Pu Wen Signed-off-by: Jinliang Zheng Reviewed-by: Bin Lai Signed-off-by: Jinliang Zheng Reviewed-by: caelli Signed-off-by: Jianping Liu --- arch/x86/kernel/cpu/hygon.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c index 0c14650fc034..0196de7638fa 100644 --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -80,16 +80,27 @@ static void hygon_get_topology(struct cpuinfo_x86 *c) if (smp_num_siblings > 1) c->x86_max_cores /= smp_num_siblings; - /* - * In case leaf B is available, use it to derive - * topology information. - */ - err = detect_extended_topology(c); - if (!err) - c->x86_coreid_bits = get_count_order(c->x86_max_cores); - - /* Socket ID is ApicId[6] for these processors. */ - c->phys_proc_id = c->apicid >> APICID_SOCKET_ID_BIT; + switch (c->x86_model) { + case 0x0 ... 0x3: + if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) + break; + /* Socket ID is ApicId[6] for these processors. */ + c->phys_proc_id = c->apicid >> APICID_SOCKET_ID_BIT; + break; + case 0x4: + /* + * In case leaf 0xB is available, use it to derive + * topology information. + */ + err = detect_extended_topology(c); + if (!err) + c->x86_coreid_bits = + get_count_order(c->x86_max_cores); + __max_die_per_package = nodes_per_socket; + break; + default: + break; + } cacheinfo_hygon_init_llc_id(c, cpu); } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {