From patchwork Fri Jul 28 12:12:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127628 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp426380vqg; Fri, 28 Jul 2023 06:14:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlEyPo6lYt2MgB7JONz+2BowunKNtNETnOF59V8MGOx10ywG0eyzdir5BCillPAx5ZSDtlJU X-Received: by 2002:a05:6a20:1001:b0:13c:3b5e:a12a with SMTP id gs1-20020a056a20100100b0013c3b5ea12amr1427383pzc.34.1690550080356; Fri, 28 Jul 2023 06:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550080; cv=none; d=google.com; s=arc-20160816; b=hku9QLsf5iNv5UJhBIUrFn42Rm/PuTpyteY7Yy4WbfBvrY5xVx4bxCsogi0iCkZLuU E17Bz8u9XQBqUyYhSqfQRzag5hLqSVtoHTjKY5Fgz+xxNVuixYyifS9UJ0FlqB4525lj EoN0S/+yClENUr2cz0XQZFDj6nPxLD8a10bfcQOvTyh0xyaIc2GuCTW3nOx2GfP2Ogx/ ldJ3F7LysEhLUkFL7K4LUeIw6mFO2ajh6QDFa0gOCAxJXFtS+UqLPKBittwFXYXw2dAQ IKclHqM1Mx4t7oNnGUxZRG3hUtDYbVdlefmz0UFxpBHx0m7helNPZLN7JnC4xSYc+0Rq UPqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=nJP92ZJMXC8M/YJGPnD+1ew7/OovV6r/sIvEynfyO4k=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=fqecObjQpLNcdql2of7PQ9IhGkc4wC+vaCss/MXE/pUnlCLc6vUPQ6M+7tNzxeWot9 OtWtKdFM0vXlib6Ddalnt8ERB+xJeMxipIModhcHjDs0JnUlMYwwrp/5S0Eq1w6bIx+F jzByq8KtP/qIKRuIdsLShnx9LnLdIMNLR9bg54vnw78sQGGeSQKp1zinpXJPic8sQQ/Y Ajz1U8Ba9zeOSEXMNZ8UVsJZ9PLwsKOHPBmDa76nPWjwJQx1/pSjKTBAGguw5eAGyEpH ek8uXTg8zXJMeisTP9id9ZW4qxd+9TCRvkR7uqGjSSMrt3d8tbQ9UKHAneHGPPk+B38I sjsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D+x8c1G2; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c17-20020a63a451000000b0051b90567f99si3009962pgp.690.2023.07.28.06.14.16; Fri, 28 Jul 2023 06:14:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=D+x8c1G2; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235361AbjG1MNE (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234685AbjG1MMs (ORCPT ); Fri, 28 Jul 2023 08:12:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F096D2688; Fri, 28 Jul 2023 05:12:45 -0700 (PDT) Message-ID: <20230728120929.721437044@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546364; 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=nJP92ZJMXC8M/YJGPnD+1ew7/OovV6r/sIvEynfyO4k=; b=D+x8c1G21dE4h3sWNkyK1wLmM1BnFbaOM8f87nWYcP1FYR6IuFk0XUfVQUgEeLP+yQsOQc B+yyZDhCO78QMXYrEh2vSiJ3m5iTEfUaklhaNJyKxqCJAvTlGodG2fEGyDzamU60G4p3Np w1et+mhCby9XC+jU18TQU5RDhy9afgkyFCnEDW3p21yH3JIfZRt/oP2z4C5HoKl6OsT5u5 9CmJrNI3akj1UD1o3pCDAa9l3qvXe4oScv8FH5OA3vAYvhHnLdAzBDPxIethtZlEnSyBff tqdTy1Gm13vCZgDjHX16sl8IVnRR4YOPjEa6Z39vm9rkfBcxfbPu819AE+rXZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546364; 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=nJP92ZJMXC8M/YJGPnD+1ew7/OovV6r/sIvEynfyO4k=; b=+lYFiTzD93g6xC7nhEQPukKijdfpLqkqhekeOF1H1bbCz6oUPhUoGRCCVrXfH1zDF1j7ae dgM3Zl9NHAe2xDCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 01/38] x86/cpu: Encapsulate topology information in cpuinfo_x86 References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:43 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772670240794661106 X-GMAIL-MSGID: 1772670240794661106 The topology related information is randomly scattered across cpuinfo_x86. Create a new structure cpuinfo_topo and move in a first step initial_apicid and apicid into it. Aside of being better readable this is in preparation for replacing the horribly fragile CPU topology evaluation code further down the road. Consolidate APIC ID fields to u32 as that represents the hardware type. No functional change. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 14 +++++++++----- arch/x86/kernel/cpu/amd.c | 10 +++++----- arch/x86/kernel/cpu/cacheinfo.c | 20 ++++++++++---------- arch/x86/kernel/cpu/common.c | 18 +++++++++--------- arch/x86/kernel/cpu/hygon.c | 12 ++++++------ arch/x86/kernel/cpu/mce/apei.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/cpu/proc.c | 4 ++-- arch/x86/kernel/cpu/topology.c | 12 ++++++------ arch/x86/xen/apic.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 2 +- drivers/virt/acrn/hsm.c | 2 +- 12 files changed, 52 insertions(+), 48 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -74,11 +74,16 @@ extern u16 __read_mostly tlb_lld_4m[NR_I extern u16 __read_mostly tlb_lld_1g[NR_INFO]; /* - * CPU type and hardware bug flags. Kept separately for each CPU. - * Members of this structure are referenced in head_32.S, so think twice - * before touching them. [mj] + * CPU type and hardware bug flags. Kept separately for each CPU. */ +struct cpuinfo_topology { + // Real APIC ID read from the local APIC + u32 apicid; + // The initial APIC ID provided by CPUID + u32 initial_apicid; +}; + struct cpuinfo_x86 { __u8 x86; /* CPU family */ __u8 x86_vendor; /* CPU vendor */ @@ -111,6 +116,7 @@ struct cpuinfo_x86 { }; char x86_vendor_id[16]; char x86_model_id[64]; + struct cpuinfo_topology topo; /* in KB - valid for CPUS which support this call: */ unsigned int x86_cache_size; int x86_cache_alignment; /* In bytes */ @@ -124,8 +130,6 @@ struct cpuinfo_x86 { u64 ppin; /* cpuid returned max cores value: */ u16 x86_max_cores; - u16 apicid; - u16 initial_apicid; u16 x86_clflush_size; /* number of cores as seen by the OS: */ u16 booted_cores; --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -387,9 +387,9 @@ static void amd_detect_cmp(struct cpuinf bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->initial_apicid & ((1 << bits)-1); + c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->initial_apicid >> bits; + c->phys_proc_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; } @@ -405,7 +405,7 @@ static void srat_detect_node(struct cpui #ifdef CONFIG_NUMA int cpu = smp_processor_id(); int node; - unsigned apicid = c->apicid; + unsigned apicid = c->topo.apicid; node = numa_cpu_node(cpu); if (node == NUMA_NO_NODE) @@ -439,7 +439,7 @@ static void srat_detect_node(struct cpui * through CPU mapping may alter the outcome, directly * access __apicid_to_node[]. */ - int ht_nodeid = c->initial_apicid; + int ht_nodeid = c->topo.initial_apicid; if (__apicid_to_node[ht_nodeid] != NUMA_NO_NODE) node = __apicid_to_node[ht_nodeid]; @@ -934,7 +934,7 @@ static void init_amd(struct cpuinfo_x86 set_cpu_cap(c, X86_FEATURE_FSRS); /* get apicid instead of initial apic id from cpuid */ - c->apicid = read_apic_id(); + c->topo.apicid = read_apic_id(); /* K6s reports MCEs but don't actually have all the MSRs */ if (c->x86 < 6) --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -678,7 +678,7 @@ void cacheinfo_amd_init_llc_id(struct cp * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ - per_cpu(cpu_llc_id, cpu) = c->apicid >> 3; + per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> 3; } else { /* * LLC ID is calculated from the number of threads sharing the @@ -694,7 +694,7 @@ void cacheinfo_amd_init_llc_id(struct cp if (num_sharing_cache) { int bits = get_count_order(num_sharing_cache); - per_cpu(cpu_llc_id, cpu) = c->apicid >> bits; + per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> bits; } } } @@ -712,7 +712,7 @@ void cacheinfo_hygon_init_llc_id(struct * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ - per_cpu(cpu_llc_id, cpu) = c->apicid >> 3; + per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> 3; } void init_amd_cacheinfo(struct cpuinfo_x86 *c) @@ -776,13 +776,13 @@ void init_intel_cacheinfo(struct cpuinfo new_l2 = this_leaf.size/1024; num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing; index_msb = get_count_order(num_threads_sharing); - l2_id = c->apicid & ~((1 << index_msb) - 1); + l2_id = c->topo.apicid & ~((1 << index_msb) - 1); break; case 3: new_l3 = this_leaf.size/1024; num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing; index_msb = get_count_order(num_threads_sharing); - l3_id = c->apicid & ~((1 << index_msb) - 1); + l3_id = c->topo.apicid & ~((1 << index_msb) - 1); break; default: break; @@ -915,7 +915,7 @@ static int __cache_amd_cpumap_setup(unsi unsigned int apicid, nshared, first, last; nshared = base->eax.split.num_threads_sharing + 1; - apicid = cpu_data(cpu).apicid; + apicid = cpu_data(cpu).topo.apicid; first = apicid - (apicid % nshared); last = first + nshared - 1; @@ -924,14 +924,14 @@ static int __cache_amd_cpumap_setup(unsi if (!this_cpu_ci->info_list) continue; - apicid = cpu_data(i).apicid; + apicid = cpu_data(i).topo.apicid; if ((apicid < first) || (apicid > last)) continue; this_leaf = this_cpu_ci->info_list + index; for_each_online_cpu(sibling) { - apicid = cpu_data(sibling).apicid; + apicid = cpu_data(sibling).topo.apicid; if ((apicid < first) || (apicid > last)) continue; cpumask_set_cpu(sibling, @@ -969,7 +969,7 @@ static void __cache_cpumap_setup(unsigne index_msb = get_count_order(num_threads_sharing); for_each_online_cpu(i) - if (cpu_data(i).apicid >> index_msb == c->apicid >> index_msb) { + if (cpu_data(i).topo.apicid >> index_msb == c->topo.apicid >> index_msb) { struct cpu_cacheinfo *sib_cpu_ci = get_cpu_cacheinfo(i); if (i == cpu || !sib_cpu_ci->info_list) @@ -1024,7 +1024,7 @@ static void get_cache_id(int cpu, struct num_threads_sharing = 1 + id4_regs->eax.split.num_threads_sharing; index_msb = get_count_order(num_threads_sharing); - id4_regs->id = c->apicid >> index_msb; + id4_regs->id = c->topo.apicid >> index_msb; } int populate_cache_leaves(unsigned int cpu) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -899,7 +899,7 @@ void detect_ht(struct cpuinfo_x86 *c) return; index_msb = get_count_order(smp_num_siblings); - c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb); + c->phys_proc_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb); smp_num_siblings = smp_num_siblings / c->x86_max_cores; @@ -907,7 +907,7 @@ void detect_ht(struct cpuinfo_x86 *c) core_bits = get_count_order(c->x86_max_cores); - c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, index_msb) & + c->cpu_core_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb) & ((1 << core_bits) - 1); #endif } @@ -1721,15 +1721,15 @@ static void generic_identify(struct cpui get_cpu_address_sizes(c); if (c->cpuid_level >= 0x00000001) { - c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; + c->topo.initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; #ifdef CONFIG_X86_32 # ifdef CONFIG_SMP - c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); + c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); # else - c->apicid = c->initial_apicid; + c->topo.apicid = c->topo.initial_apicid; # endif #endif - c->phys_proc_id = c->initial_apicid; + c->phys_proc_id = c->topo.initial_apicid; } get_model_name(c); /* Default name */ @@ -1763,9 +1763,9 @@ static void validate_apic_and_package_id apicid = apic->cpu_present_to_apicid(cpu); - if (apicid != c->apicid) { + if (apicid != c->topo.apicid) { pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n", - cpu, apicid, c->initial_apicid); + cpu, apicid, c->topo.initial_apicid); } BUG_ON(topology_update_package_map(c->phys_proc_id, cpu)); BUG_ON(topology_update_die_map(c->cpu_die_id, cpu)); @@ -1815,7 +1815,7 @@ static void identify_cpu(struct cpuinfo_ apply_forced_caps(c); #ifdef CONFIG_X86_64 - c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); + c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); #endif /* --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -88,7 +88,7 @@ static void hygon_get_topology(struct cp 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; + c->phys_proc_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; cacheinfo_hygon_init_llc_id(c, cpu); } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { @@ -116,9 +116,9 @@ static void hygon_detect_cmp(struct cpui bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->initial_apicid & ((1 << bits)-1); + c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->initial_apicid >> bits; + c->phys_proc_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; } @@ -128,7 +128,7 @@ static void srat_detect_node(struct cpui #ifdef CONFIG_NUMA int cpu = smp_processor_id(); int node; - unsigned int apicid = c->apicid; + unsigned int apicid = c->topo.apicid; node = numa_cpu_node(cpu); if (node == NUMA_NO_NODE) @@ -161,7 +161,7 @@ static void srat_detect_node(struct cpui * through CPU mapping may alter the outcome, directly * access __apicid_to_node[]. */ - int ht_nodeid = c->initial_apicid; + int ht_nodeid = c->topo.initial_apicid; if (__apicid_to_node[ht_nodeid] != NUMA_NO_NODE) node = __apicid_to_node[ht_nodeid]; @@ -301,7 +301,7 @@ static void init_hygon(struct cpuinfo_x8 set_cpu_cap(c, X86_FEATURE_REP_GOOD); /* get apicid instead of initial apic id from cpuid */ - c->apicid = read_apic_id(); + c->topo.apicid = read_apic_id(); /* * XXX someone from Hygon needs to confirm this DTRT --- a/arch/x86/kernel/cpu/mce/apei.c +++ b/arch/x86/kernel/cpu/mce/apei.c @@ -103,7 +103,7 @@ int apei_smca_report_x86_error(struct cp m.socketid = -1; for_each_possible_cpu(cpu) { - if (cpu_data(cpu).initial_apicid == lapic_id) { + if (cpu_data(cpu).topo.initial_apicid == lapic_id) { m.extcpu = cpu; m.socketid = cpu_data(m.extcpu).phys_proc_id; break; --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -124,7 +124,7 @@ void mce_setup(struct mce *m) m->cpuvendor = boot_cpu_data.x86_vendor; m->cpuid = cpuid_eax(1); m->socketid = cpu_data(m->extcpu).phys_proc_id; - m->apicid = cpu_data(m->extcpu).initial_apicid; + m->apicid = cpu_data(m->extcpu).topo.initial_apicid; m->mcgcap = __rdmsr(MSR_IA32_MCG_CAP); m->ppin = cpu_data(m->extcpu).ppin; m->microcode = boot_cpu_data.microcode; --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -23,8 +23,8 @@ static void show_cpuinfo_core(struct seq cpumask_weight(topology_core_cpumask(cpu))); seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id); seq_printf(m, "cpu cores\t: %d\n", c->booted_cores); - seq_printf(m, "apicid\t\t: %d\n", c->apicid); - seq_printf(m, "initial apicid\t: %d\n", c->initial_apicid); + seq_printf(m, "apicid\t\t: %d\n", c->topo.apicid); + seq_printf(m, "initial apicid\t: %d\n", c->topo.initial_apicid); #endif } --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -78,7 +78,7 @@ int detect_extended_topology_early(struc /* * initial apic id, which also represents 32-bit extended x2apic id. */ - c->initial_apicid = edx; + c->topo.initial_apicid = edx; smp_num_siblings = max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)); #endif return 0; @@ -108,7 +108,7 @@ int detect_extended_topology(struct cpui * Populate HT related information from sub-leaf level 0. */ cpuid_count(leaf, SMT_LEVEL, &eax, &ebx, &ecx, &edx); - c->initial_apicid = edx; + c->topo.initial_apicid = edx; core_level_siblings = LEVEL_MAX_SIBLINGS(ebx); smp_num_siblings = max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)); core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); @@ -146,20 +146,20 @@ int detect_extended_topology(struct cpui die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width; - c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, + c->cpu_core_id = apic->phys_pkg_id(c->topo.initial_apicid, ht_mask_width) & core_select_mask; if (die_level_present) { - c->cpu_die_id = apic->phys_pkg_id(c->initial_apicid, + c->cpu_die_id = apic->phys_pkg_id(c->topo.initial_apicid, core_plus_mask_width) & die_select_mask; } - c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, + c->phys_proc_id = apic->phys_pkg_id(c->topo.initial_apicid, pkg_mask_width); /* * Reinit the apicid, now that we have extended initial_apicid. */ - c->apicid = apic->phys_pkg_id(c->initial_apicid, 0); + c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); c->x86_max_cores = (core_level_siblings / smp_num_siblings); __max_die_per_package = (die_level_siblings / core_level_siblings); --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -118,7 +118,7 @@ static int xen_phys_pkg_id(int initial_a static int xen_cpu_present_to_apicid(int cpu) { if (cpu_present(cpu)) - return cpu_data(cpu).apicid; + return cpu_data(cpu).topo.apicid; else return BAD_APICID; } --- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c @@ -2255,7 +2255,7 @@ static int kfd_cpumask_to_apic_id(const if (first_cpu_of_numa_node >= nr_cpu_ids) return -1; #ifdef CONFIG_X86_64 - return cpu_data(first_cpu_of_numa_node).apicid; + return cpu_data(first_cpu_of_numa_node).topo.apicid; #else return first_cpu_of_numa_node; #endif --- a/drivers/virt/acrn/hsm.c +++ b/drivers/virt/acrn/hsm.c @@ -447,7 +447,7 @@ static ssize_t remove_cpu_store(struct d if (cpu_online(cpu)) remove_cpu(cpu); - lapicid = cpu_data(cpu).apicid; + lapicid = cpu_data(cpu).topo.apicid; dev_dbg(dev, "Try to remove cpu %lld with lapicid %lld\n", cpu, lapicid); ret = hcall_sos_remove_cpu(lapicid); if (ret < 0) { From patchwork Fri Jul 28 12:12:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp406327vqg; Fri, 28 Jul 2023 05:42:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlHm0isD4j7/2KPoT4pFTVs2YfLbcO3aO4v3PYIUCEfLRFGGBEQ8LbI9vxpGWo4Hl0awn8lC X-Received: by 2002:a17:903:22c1:b0:1b8:b2c6:7e8d with SMTP id y1-20020a17090322c100b001b8b2c67e8dmr1835185plg.66.1690548179117; Fri, 28 Jul 2023 05:42:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548179; cv=none; d=google.com; s=arc-20160816; b=OIJndtZO+7Lt1ANcSm9wlUfMHjfYi/spNm21Qhf8i0xr1XnjXEdHPzYYH+Iz0+Gwlq wWWeVGERhG5JTa64nT6vDXusZ9lG95Nb/eEomkqgEJIV5y8sNRCkvN5Xr82ONwOoS3dK /D+Sr628jGU+6+uQwzgQXF1+vBuNRXGTqacGT0ycmxN0BvjrEfCiGEhdLFc+ovOQt+9Z OZp5IKwkrt0W0OcREEfiV2dgVleKeuNs0q33fttQ08hjyYWpoDb1jkQfc73WJ/GdvU+o 8jS242f2JC3awa4qV0J6RvnMP8rmwIfV/N1lGAkhcy7H3zIbxUN13AkZWIHRVfZjX6vm E+qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=I51FvGvV/xruMOQFpSsZxNsz8mCYiGuaQ5bmqM+I82Y=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=oJOOOb/0xDmzVAgPIbOsbarS7HIoNN5HxErWdRnUSILO7bgrDvZFZqLmIfIZkh3BDX tpaTn0GOqtv9iZMzEMEawVa3EysNAt5BnZknMkww2+7IlmXZgPP/cNb5BxiAb7OyB4Y2 hKe8YpMh0Gm6NzZQLEjhyFN29qkv7eYTFbBW/j6rXim/rcJQ0zH+GKgIt2e5HbxwyCzA HvMaNQGnUFdzpWZDg1nufmAiHuK17cySGopyOY1CYQlgUuxouZvjZTChyMhA+IsRV6ya 9BpaOUEsvin29u0v2pQRoXFDwxcZk/UFQ03z8HoJwV3ANIB3LNSd439gCCnd8zDJvrvF Koaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=shCtGBp5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="/jSdtju8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a170902d50f00b001b8ac52a1b2si3132574plg.551.2023.07.28.05.42.45; Fri, 28 Jul 2023 05:42:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=shCtGBp5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="/jSdtju8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235914AbjG1MNV (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234744AbjG1MMs (ORCPT ); Fri, 28 Jul 2023 08:12:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FB67268B; Fri, 28 Jul 2023 05:12:46 -0700 (PDT) Message-ID: <20230728120929.778470356@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546365; 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=I51FvGvV/xruMOQFpSsZxNsz8mCYiGuaQ5bmqM+I82Y=; b=shCtGBp54RgfNwMgK/zSxAri0088zWyln/116ufB+gBIUaEXmCHazpEtS6cL7g/bf2bVAT VOdsZJ0eoKj/ZIEP6pQ/SXjw2wJa1Pt4GDFmIzz/8asmRjhVDFDGfE3GaYsZlaoojxSuFY 2DraHIH2ytyvJ3vFnIyw1jBcsu3aJPDoRjTS3x9u++xY3AZXiyMEhVsPvreZloaIP+yQCU NrOWl6e1YF73p0Z1/7hKG0H1jFLzIONOQrBfluWYSgCqFp4yo26A6Rtv1+xrLPSZqaFAyg La9CY1GMOKctBA06traH4z8WHs7xQFYWFw2lKzeNpzOC3NEO239h2v5d4YKanw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546365; 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=I51FvGvV/xruMOQFpSsZxNsz8mCYiGuaQ5bmqM+I82Y=; b=/jSdtju8deI+4oeqdsZfotPeer8nnFqoo4nYwqX2ymKTciG4HqYWW9pVPok/1oFa404lBF YoQbLXSfnFgX/kBw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 02/38] x86/cpu: Move phys_proc_id into topology info References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:45 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668247537066162 X-GMAIL-MSGID: 1772668247537066162 Rename it to pkg_id which is the terminology used in the kernel. No functional change. Signed-off-by: Thomas Gleixner --- Documentation/arch/x86/topology.rst | 2 +- arch/x86/include/asm/processor.h | 5 +++-- arch/x86/include/asm/topology.h | 2 +- arch/x86/include/asm/x86_init.h | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 4 ++-- arch/x86/kernel/cpu/cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/common.c | 6 +++--- arch/x86/kernel/cpu/hygon.c | 6 +++--- arch/x86/kernel/cpu/mce/apei.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 2 +- arch/x86/kernel/cpu/proc.c | 2 +- arch/x86/kernel/cpu/topology.c | 3 +-- arch/x86/kernel/smpboot.c | 16 ++++++++-------- drivers/scsi/lpfc/lpfc_init.c | 6 +----- 15 files changed, 30 insertions(+), 34 deletions(-) --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -59,7 +59,7 @@ AMD nomenclature for package is 'Node'. The physical ID of the die. This information is retrieved via CPUID. - - cpuinfo_x86.phys_proc_id: + - cpuinfo_x86.topo.pkg_id: The physical ID of the package. This information is retrieved via CPUID and deduced from the APIC IDs of the cores in the package. --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -82,6 +82,9 @@ struct cpuinfo_topology { u32 apicid; // The initial APIC ID provided by CPUID u32 initial_apicid; + + // Physical package ID + u32 pkg_id; }; struct cpuinfo_x86 { @@ -133,8 +136,6 @@ struct cpuinfo_x86 { u16 x86_clflush_size; /* number of cores as seen by the OS: */ u16 booted_cores; - /* Physical processor id: */ - u16 phys_proc_id; /* Logical processor id: */ u16 logical_proc_id; /* Core id: */ --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -106,7 +106,7 @@ extern const struct cpumask *cpu_coregro extern const struct cpumask *cpu_clustergroup_mask(int cpu); #define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id) -#define topology_physical_package_id(cpu) (cpu_data(cpu).phys_proc_id) +#define topology_physical_package_id(cpu) (cpu_data(cpu).topo.pkg_id) #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) #define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id) #define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -177,7 +177,7 @@ struct x86_init_ops { * struct x86_cpuinit_ops - platform specific cpu hotplug setups * @setup_percpu_clockev: set up the per cpu clock event device * @early_percpu_clock_init: early init of the per cpu clock event device - * @fixup_cpu_id: fixup function for cpuinfo_x86::phys_proc_id + * @fixup_cpu_id: fixup function for cpuinfo_x86::topo.pkg_id * @parallel_bringup: Parallel bringup control */ struct x86_cpuinit_ops { --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -169,7 +169,7 @@ static void fixup_cpu_id(struct cpuinfo_ nodes = ((val >> 3) & 7) + 1; } - c->phys_proc_id = node / nodes; + c->topo.pkg_id = node / nodes; } static int __init numachip_system_init(void) --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -389,9 +389,9 @@ static void amd_detect_cmp(struct cpuinf /* Low order bits define the core id (index of core in socket) */ c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->topo.initial_apicid >> bits; + c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; + per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; } u32 amd_get_nodes_per_socket(void) --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -875,10 +875,10 @@ void init_intel_cacheinfo(struct cpuinfo * turns means that the only possibility is SMT (as indicated in * cpuid1). Since cpuid2 doesn't specify shared caches, and we know * that SMT shares all caches, we can unconditionally set cpu_llc_id to - * c->phys_proc_id. + * c->topo.pkg_id. */ if (per_cpu(cpu_llc_id, cpu) == BAD_APICID) - per_cpu(cpu_llc_id, cpu) = c->phys_proc_id; + per_cpu(cpu_llc_id, cpu) = c->topo.pkg_id; #endif c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d)); --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -899,7 +899,7 @@ void detect_ht(struct cpuinfo_x86 *c) return; index_msb = get_count_order(smp_num_siblings); - c->phys_proc_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb); + c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb); smp_num_siblings = smp_num_siblings / c->x86_max_cores; @@ -1729,7 +1729,7 @@ static void generic_identify(struct cpui c->topo.apicid = c->topo.initial_apicid; # endif #endif - c->phys_proc_id = c->topo.initial_apicid; + c->topo.pkg_id = c->topo.initial_apicid; } get_model_name(c); /* Default name */ @@ -1767,7 +1767,7 @@ static void validate_apic_and_package_id pr_err(FW_BUG "CPU%u: APIC id mismatch. Firmware: %x APIC: %x\n", cpu, apicid, c->topo.initial_apicid); } - BUG_ON(topology_update_package_map(c->phys_proc_id, cpu)); + BUG_ON(topology_update_package_map(c->topo.pkg_id, cpu)); BUG_ON(topology_update_die_map(c->cpu_die_id, cpu)); #else c->logical_proc_id = 0; --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -88,7 +88,7 @@ static void hygon_get_topology(struct cp c->x86_coreid_bits = get_count_order(c->x86_max_cores); /* Socket ID is ApicId[6] for these processors. */ - c->phys_proc_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; + c->topo.pkg_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; cacheinfo_hygon_init_llc_id(c, cpu); } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { @@ -118,9 +118,9 @@ static void hygon_detect_cmp(struct cpui /* Low order bits define the core id (index of core in socket) */ c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ - c->phys_proc_id = c->topo.initial_apicid >> bits; + c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->phys_proc_id; + per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; } static void srat_detect_node(struct cpuinfo_x86 *c) --- a/arch/x86/kernel/cpu/mce/apei.c +++ b/arch/x86/kernel/cpu/mce/apei.c @@ -105,7 +105,7 @@ int apei_smca_report_x86_error(struct cp for_each_possible_cpu(cpu) { if (cpu_data(cpu).topo.initial_apicid == lapic_id) { m.extcpu = cpu; - m.socketid = cpu_data(m.extcpu).phys_proc_id; + m.socketid = cpu_data(m.extcpu).topo.pkg_id; break; } } --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -123,7 +123,7 @@ void mce_setup(struct mce *m) m->time = __ktime_get_real_seconds(); m->cpuvendor = boot_cpu_data.x86_vendor; m->cpuid = cpuid_eax(1); - m->socketid = cpu_data(m->extcpu).phys_proc_id; + m->socketid = cpu_data(m->extcpu).topo.pkg_id; m->apicid = cpu_data(m->extcpu).topo.initial_apicid; m->mcgcap = __rdmsr(MSR_IA32_MCG_CAP); m->ppin = cpu_data(m->extcpu).ppin; --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -18,7 +18,7 @@ static void show_cpuinfo_core(struct seq unsigned int cpu) { #ifdef CONFIG_SMP - seq_printf(m, "physical id\t: %d\n", c->phys_proc_id); + seq_printf(m, "physical id\t: %d\n", c->topo.pkg_id); seq_printf(m, "siblings\t: %d\n", cpumask_weight(topology_core_cpumask(cpu))); seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id); --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -154,8 +154,7 @@ int detect_extended_topology(struct cpui core_plus_mask_width) & die_select_mask; } - c->phys_proc_id = apic->phys_pkg_id(c->topo.initial_apicid, - pkg_mask_width); + c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, pkg_mask_width); /* * Reinit the apicid, now that we have extended initial_apicid. */ --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -347,7 +347,7 @@ int topology_phys_to_logical_pkg(unsigne for_each_possible_cpu(cpu) { struct cpuinfo_x86 *c = &cpu_data(cpu); - if (c->initialized && c->phys_proc_id == phys_pkg) + if (c->initialized && c->topo.pkg_id == phys_pkg) return c->logical_proc_id; } return -1; @@ -363,13 +363,13 @@ EXPORT_SYMBOL(topology_phys_to_logical_p */ static int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu) { - int cpu, proc_id = cpu_data(cur_cpu).phys_proc_id; + int cpu, proc_id = cpu_data(cur_cpu).topo.pkg_id; for_each_possible_cpu(cpu) { struct cpuinfo_x86 *c = &cpu_data(cpu); if (c->initialized && c->cpu_die_id == die_id && - c->phys_proc_id == proc_id) + c->topo.pkg_id == proc_id) return c->logical_die_id; } return -1; @@ -429,7 +429,7 @@ void __init smp_store_boot_cpu_info(void *c = boot_cpu_data; c->cpu_index = id; - topology_update_package_map(c->phys_proc_id, id); + topology_update_package_map(c->topo.pkg_id, id); topology_update_die_map(c->cpu_die_id, id); c->initialized = true; } @@ -484,7 +484,7 @@ static bool match_smt(struct cpuinfo_x86 if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { int cpu1 = c->cpu_index, cpu2 = o->cpu_index; - if (c->phys_proc_id == o->phys_proc_id && + if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id && per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { if (c->cpu_core_id == o->cpu_core_id) @@ -496,7 +496,7 @@ static bool match_smt(struct cpuinfo_x86 return topology_sane(c, o, "smt"); } - } else if (c->phys_proc_id == o->phys_proc_id && + } else if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id && c->cpu_core_id == o->cpu_core_id) { return topology_sane(c, o, "smt"); @@ -507,7 +507,7 @@ static bool match_smt(struct cpuinfo_x86 static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { - if (c->phys_proc_id == o->phys_proc_id && + if (c->topo.pkg_id == o->topo.pkg_id && c->cpu_die_id == o->cpu_die_id) return true; return false; @@ -535,7 +535,7 @@ static bool match_l2c(struct cpuinfo_x86 */ static bool match_pkg(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { - if (c->phys_proc_id == o->phys_proc_id) + if (c->topo.pkg_id == o->topo.pkg_id) return true; return false; } --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -12428,9 +12428,6 @@ lpfc_cpu_affinity_check(struct lpfc_hba int max_core_id, min_core_id; struct lpfc_vector_map_info *cpup; struct lpfc_vector_map_info *new_cpup; -#ifdef CONFIG_X86 - struct cpuinfo_x86 *cpuinfo; -#endif #ifdef CONFIG_SCSI_LPFC_DEBUG_FS struct lpfc_hdwq_stat *c_stat; #endif @@ -12444,8 +12441,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba for_each_present_cpu(cpu) { cpup = &phba->sli4_hba.cpu_map[cpu]; #ifdef CONFIG_X86 - cpuinfo = &cpu_data(cpu); - cpup->phys_id = cpuinfo->phys_proc_id; + cpup->phys_id = topology_physical_package_id(cpu); cpup->core_id = cpuinfo->cpu_core_id; if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) cpup->flag |= LPFC_CPU_MAP_HYPER; From patchwork Fri Jul 28 12:12:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp402162vqg; Fri, 28 Jul 2023 05:35:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGLa0+bYU6UALtr095kxCRAqYPf2XDgjCr94zqIu+dL9mDLJ26mrZgcTdwrXH2axgOLdS1J X-Received: by 2002:a05:6a20:296:b0:133:3682:3cdf with SMTP id 22-20020a056a20029600b0013336823cdfmr1108022pza.11.1690547726853; Fri, 28 Jul 2023 05:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690547726; cv=none; d=google.com; s=arc-20160816; b=DfwsEaAfVEptqQYFBKLpo6TVCWPus/Ue1w8pwatjJASRN6gvuamQVtb8BgtOQfylrr cOLr72TZHj/63LQYVqPuNOw5zErFb4eLZ/TEyDJY54C9aW11ItM1ZW7ujvzekEK4Z7A1 6vBLy5lkYE1hyK60CHlokl1JZJNeTz4Rg9TgWfnSYemTt0cfJQElTr0MPkMfWg5beaAk ZayfndT8ZwY6lkj8NwJF8vaIIVuseCRNT9B8ZMK+tTM3w6o70KlHZMxjY4HOXu4Ano7g NwBy/+5/pz/JZiK/Jgya1UMDhO6L5beiRWtgKzdTD5ZM+NBpFfqUKM3X3Jz9zqD1T/Nz HK8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=bc5Q0JSTqg9+ffQ7s8oKfLAz7DN9aGciy8PBD8PIdfE=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=JfrW+PM9jhR2cxakN3+eZZOUuOnf+sGYM0cRTxZUo06mlLY3PC4D5Fo/St2VAMu2bW lePf8vcKyTcgXXBdqoEKgYtS+gr+iiWI/+zJYItF6dfTTNzQqyscjfXNIc84etgqzB4V A4uiVrDojM+oF9XT6luhwPYI00m4B7JuAMgMBOAKIAUAsmI3hHWsunoLX95Sl11m6gh8 Wf7C9ECid4t5/rf2Fk5cXv05Hhb1EXOYnnW2qkZAXQ5W3ilJcws0aIz065+wqVk2Y8zQ IppRYgyK8xxMfNCJ9DNovJGLXMfKG5ry53M0iqBaID6cVy/VB0XPS7aHa8jIG8hC2WbW CeyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mv41NMlB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=a2p3cgpW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o14-20020a056a0015ce00b00686680dc33esi3108043pfu.404.2023.07.28.05.35.13; Fri, 28 Jul 2023 05:35:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mv41NMlB; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=a2p3cgpW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235541AbjG1MNN (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234764AbjG1MMt (ORCPT ); Fri, 28 Jul 2023 08:12:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9C242686; Fri, 28 Jul 2023 05:12:47 -0700 (PDT) Message-ID: <20230728120929.833540176@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546366; 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=bc5Q0JSTqg9+ffQ7s8oKfLAz7DN9aGciy8PBD8PIdfE=; b=mv41NMlBAaxhGOiELLJOWdF+5WAlkrsqca4XRQ+z8XHjOdgOb5w3YqiJr320cRvDd4wrA9 LXn1K1NrcSyPye0qJ8Id8lGlk5zZWrQru4ksPNvvcqFrkA3FeDQb2WIud9w10GZV8ivZ5C xdSWWvYMy8OkJ1xqoiGFqa93UbUGMNaNE+25cQsokLXkHgPGkbDEd61KUYWyEKqpFiI7pa PZMzjoH3PWFC2XGHXgtVES6E8NWPSZMR9H1/+bsnorwhuETU0Kmv9R5XSkyUQIR5dAIIl7 q/Q9GgZ+5ZCc6b0duWrabmbZKnmYcTFwV4n6ru7rjGviFO+yv7QsPG+aoq3oWA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546366; 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=bc5Q0JSTqg9+ffQ7s8oKfLAz7DN9aGciy8PBD8PIdfE=; b=a2p3cgpWx6ISKZo1DGTjbDDI7IFU2b1wiX8XM4+EIyQ1GyuyWEwh1K7zTw6u6bb/jRsyQS lA58EA0+34Xf8pAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 03/38] x86/cpu: Move cpu_die_id into topology info References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:46 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772667772820241800 X-GMAIL-MSGID: 1772667772820241800 Move the next member. No functional change. Signed-off-by: Thomas Gleixner --- Documentation/arch/x86/topology.rst | 4 ++-- arch/x86/include/asm/processor.h | 4 +++- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/cpu/amd.c | 8 ++++---- arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/hygon.c | 8 ++++---- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/smpboot.c | 10 +++++----- 9 files changed, 22 insertions(+), 20 deletions(-) --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -55,7 +55,7 @@ AMD nomenclature for package is 'Node'. The number of dies in a package. This information is retrieved via CPUID. - - cpuinfo_x86.cpu_die_id: + - cpuinfo_x86.topo_die_id: The physical ID of the die. This information is retrieved via CPUID. @@ -65,7 +65,7 @@ AMD nomenclature for package is 'Node'. and deduced from the APIC IDs of the cores in the package. Modern systems use this value for the socket. There may be multiple - packages within a socket. This value may differ from cpu_die_id. + packages within a socket. This value may differ from topo.die_id. - cpuinfo_x86.logical_proc_id: --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -85,6 +85,9 @@ struct cpuinfo_topology { // Physical package ID u32 pkg_id; + + // Physical die ID on AMD, Relative on Intel + u32 die_id; }; struct cpuinfo_x86 { @@ -140,7 +143,6 @@ struct cpuinfo_x86 { u16 logical_proc_id; /* Core id: */ u16 cpu_core_id; - u16 cpu_die_id; u16 logical_die_id; /* Index into per_cpu list: */ u16 cpu_index; --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -108,7 +108,7 @@ extern const struct cpumask *cpu_cluster #define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id) #define topology_physical_package_id(cpu) (cpu_data(cpu).topo.pkg_id) #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) -#define topology_die_id(cpu) (cpu_data(cpu).cpu_die_id) +#define topology_die_id(cpu) (cpu_data(cpu).topo.die_id) #define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -338,7 +338,7 @@ static void amd_get_topology(struct cpui cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); - c->cpu_die_id = ecx & 0xff; + c->topo.die_id = ecx & 0xff; if (c->x86 == 0x15) c->cu_id = ebx & 0xff; @@ -364,9 +364,9 @@ static void amd_get_topology(struct cpui u64 value; rdmsrl(MSR_FAM10H_NODE_ID, value); - c->cpu_die_id = value & 7; + c->topo.die_id = value & 7; - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id; } else return; @@ -391,7 +391,7 @@ static void amd_detect_cmp(struct cpuinf /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; } u32 amd_get_nodes_per_socket(void) --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -672,7 +672,7 @@ void cacheinfo_amd_init_llc_id(struct cp if (c->x86 < 0x17) { /* LLC is at the node level. */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id; } else if (c->x86 == 0x17 && c->x86_model <= 0x1F) { /* * LLC is at the core complex level. --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1768,7 +1768,7 @@ static void validate_apic_and_package_id cpu, apicid, c->topo.initial_apicid); } BUG_ON(topology_update_package_map(c->topo.pkg_id, cpu)); - BUG_ON(topology_update_die_map(c->cpu_die_id, cpu)); + BUG_ON(topology_update_die_map(c->topo.die_id, cpu)); #else c->logical_proc_id = 0; #endif --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -72,7 +72,7 @@ static void hygon_get_topology(struct cp cpuid(0x8000001e, &eax, &ebx, &ecx, &edx); - c->cpu_die_id = ecx & 0xff; + c->topo.die_id = ecx & 0xff; c->cpu_core_id = ebx & 0xff; @@ -95,9 +95,9 @@ static void hygon_get_topology(struct cp u64 value; rdmsrl(MSR_FAM10H_NODE_ID, value); - c->cpu_die_id = value & 7; + c->topo.die_id = value & 7; - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id; } else return; @@ -120,7 +120,7 @@ static void hygon_detect_cmp(struct cpui /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->cpu_die_id = c->topo.pkg_id; + per_cpu(cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; } static void srat_detect_node(struct cpuinfo_x86 *c) --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -150,7 +150,7 @@ int detect_extended_topology(struct cpui ht_mask_width) & core_select_mask; if (die_level_present) { - c->cpu_die_id = apic->phys_pkg_id(c->topo.initial_apicid, + c->topo.die_id = apic->phys_pkg_id(c->topo.initial_apicid, core_plus_mask_width) & die_select_mask; } --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -368,7 +368,7 @@ static int topology_phys_to_logical_die( for_each_possible_cpu(cpu) { struct cpuinfo_x86 *c = &cpu_data(cpu); - if (c->initialized && c->cpu_die_id == die_id && + if (c->initialized && c->topo.die_id == die_id && c->topo.pkg_id == proc_id) return c->logical_die_id; } @@ -430,7 +430,7 @@ void __init smp_store_boot_cpu_info(void *c = boot_cpu_data; c->cpu_index = id; topology_update_package_map(c->topo.pkg_id, id); - topology_update_die_map(c->cpu_die_id, id); + topology_update_die_map(c->topo.die_id, id); c->initialized = true; } @@ -485,7 +485,7 @@ static bool match_smt(struct cpuinfo_x86 int cpu1 = c->cpu_index, cpu2 = o->cpu_index; if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id && + c->topo.die_id == o->topo.die_id && per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { if (c->cpu_core_id == o->cpu_core_id) return topology_sane(c, o, "smt"); @@ -497,7 +497,7 @@ static bool match_smt(struct cpuinfo_x86 } } else if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id && + c->topo.die_id == o->topo.die_id && c->cpu_core_id == o->cpu_core_id) { return topology_sane(c, o, "smt"); } @@ -508,7 +508,7 @@ static bool match_smt(struct cpuinfo_x86 static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { if (c->topo.pkg_id == o->topo.pkg_id && - c->cpu_die_id == o->cpu_die_id) + c->topo.die_id == o->topo.die_id) return true; return false; } From patchwork Fri Jul 28 12:12:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp406609vqg; Fri, 28 Jul 2023 05:43:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlHRcilV9hdivDRUTepKXUdfWqtKJmIQ5qUijrpaGHnaMYIt2sF4MkqAAA2JHBuuuUU87a6z X-Received: by 2002:a05:6a00:301b:b0:686:b732:8792 with SMTP id ay27-20020a056a00301b00b00686b7328792mr2044689pfb.8.1690548209926; Fri, 28 Jul 2023 05:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548209; cv=none; d=google.com; s=arc-20160816; b=IPogp96gamJUiATHXbu2udDBEpjKXCOb8PSMr6+Fm/10AyKxDUfJBB3p+BKLLduek6 8ZfdNHLXZXbp62zfJemct5Esj+nE1oVa5ac/eX2f/XcWHF9d091XzdVP0fhhtdaoRY2k jbYVEHhhTGJE8kdXka2Tt9lg1/m6J8a7FCdCHmQT3pn9mgcDJAHnpeoBduUwORx1OF+m dRxRCpXaW2WGDO88urwCukoW3cSDHstJNnLZavN3D+J+IKJIP1NTBciFi++L7oUnTzmx oVngU8/2C+TtM3HVzejqfvVakZglKyDztsMYlEaUGVe3IKFI5weE9VcRS6Fbxqf/vf5g DlJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=+1QBA7VHZ0Y4GyIw3wTYa2EiSrzVOoXvVDOvnVaT6BY=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=iYV2zyBOW90DgqkSgly+w3qei06K3Yr1gGtxNL8wh3tEuMXqHWEY0MmAmbTL+Gy41p HCKfb6kFjsIZsrXuigZoGsQUTQXYc7gt5wsAegV5e+sXxKDXP+zTHtvxiGpWdYakAi+y EbOeyvzWDKjbF7RnzwXjASltfHMjbKXo4hyU1vkR7p5W/Chogt7vKQ4hwpUsh8NeMQsv V+wkqYvC3BRcEbguWl7PYynwE74YdXP4QoVF3VRq82LW7mPVn+hg1569FhKZgveIiEhN PcOj1ASkn1RPV6vDvsYy2P4sarG01G3Pqg3kctPhmsAlqqcnMd/QBAHMsrN5gVK1ZCTY zF7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fWvBZAtr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=L4xnuGbj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p30-20020a631e5e000000b0055b7319a311si2923617pgm.356.2023.07.28.05.43.17; Fri, 28 Jul 2023 05:43:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fWvBZAtr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=L4xnuGbj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235742AbjG1MNQ (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233512AbjG1MMu (ORCPT ); Fri, 28 Jul 2023 08:12:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16160269E; Fri, 28 Jul 2023 05:12:49 -0700 (PDT) Message-ID: <20230728120929.888713412@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546367; 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=+1QBA7VHZ0Y4GyIw3wTYa2EiSrzVOoXvVDOvnVaT6BY=; b=fWvBZAtr1+b7OwhEu0kVqpNM13lP2fyyhOFWfJTTI3uFnsBcnEq3eWD6OPi0V/kdIofsBD IWlcRLGqiQ/cmiDi0EWkLzMTw7phJe7v9wjk0XrBX6BmAdVHcGsNlg6jQbzGWWexfHKtzF 1ZmgunT47P0OUI+815tf6BjkrRuo61gkVY/iLx/rwtXMN0raoQQF/OKZaVhT4HDEOEXpPq BRVVv+uYxU6BrAdcgmdY1/9zX3XSj0YrSFhHjjb3+oPf3o46Aq8HPQ7lbDb/2a6Nv9ROoe HgKdL4a2ald+wdDQ83SGgrWPMDHY7aGmYhZMEV3mbjhbTuF7BNUmQBhO6tVs5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546367; 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=+1QBA7VHZ0Y4GyIw3wTYa2EiSrzVOoXvVDOvnVaT6BY=; b=L4xnuGbjTILMT48eR30EY7wea8T/sKtJtOh08OVrf89pbFR2Vv/khTIC6uOE4LxgEQoM+Y Xg2ntVr6c10qiODQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 04/38] scsi: lpfc: Use topology_core_id() References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:47 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668279916636822 X-GMAIL-MSGID: 1772668279916636822 Use the provided topology helper. Signed-off-by: Thomas Gleixner Cc: "James E.J. Bottomley" Cc: Dick Kennedy Cc: James Smart Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org --- drivers/scsi/lpfc/lpfc_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -12442,7 +12442,7 @@ lpfc_cpu_affinity_check(struct lpfc_hba cpup = &phba->sli4_hba.cpu_map[cpu]; #ifdef CONFIG_X86 cpup->phys_id = topology_physical_package_id(cpu); - cpup->core_id = cpuinfo->cpu_core_id; + cpup->core_id = topology_core_id(cpu); if (lpfc_find_hyper(phba, cpu, cpup->phys_id, cpup->core_id)) cpup->flag |= LPFC_CPU_MAP_HYPER; #else From patchwork Fri Jul 28 12:12:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127650 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp442346vqg; Fri, 28 Jul 2023 06:40:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSE1Yw1RaA0uobAr6WY/sfkjQO1ZEsgn1lk/jeatp0skHU3GwzCTu2w9Nit8ILX9StOOt3 X-Received: by 2002:a17:902:ce84:b0:1b8:b4d5:4c3d with SMTP id f4-20020a170902ce8400b001b8b4d54c3dmr1456111plg.51.1690551639050; Fri, 28 Jul 2023 06:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690551639; cv=none; d=google.com; s=arc-20160816; b=gkeE41EAJ0zZjUYxkkc+VRMcmUEJ+GE6RDwQwHHn3rkqTKNYoAw8bKqICag29RSuo+ F8uptQGqeCxtTN5GM46/s/lDVemzi/PO1GZ5H0O8tFJUpZji97YH/RSydEbXgL80i2IU RnePwCC6WZlU6356FD39lAOMVyajlKkfUN+Uu72PTJfyBb+NCegqaMmBL6tIYN8Z9hnP oyESMyCYaZQ672i1YDLv6IcG3xYOeINDGddtj9WOr5F5ZYP/xWh1MlhxtHnKMPWWyAY/ 7jKF23bvdDudI2qQhkqIJCX0lxPgNc53noNiIkre1TjEdCCCTcL6xScbnIgK7AkdATRb 3A0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=W37gGs0lCrcES4uNg1Zl0+g2c0hE6iWg5mZxC7Tosgc=; fh=lv3AW8nk/fXivlP2csiV80MS+JKDczHVGDVGDf22KyU=; b=i9vyxWrLYkrujqXLaBxWvZRkIsHS63R+s1TZIp0N3YZFDrpJbwLMagg26Um84tTjaF PiO9ow/zgpZLEgG0uqqFPTHNT8hl8c42diOrkaCpuDJ7xDm8ypzliBFAAxg4L+XFVodV 0cx8MQweM0kLb2dolwzcLFYjILQaID80ZweEfR76yKz0rhUS2HZBw9ISmX+M85MrccKJ SroUoo7ZRowvitpvARsnsV4C6qR8D2toN5DpWNGpOK1HXRD0I8F8QZA7el22v38mzFQ1 mglNdq96wGekmfLfYHADO56ULRW3PabAZ55DPeqSOHNg0zi2Ukf8MLZbMUBEuIf/+wSa nstQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LOYZuo50; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x16-20020a170902ec9000b001b8a8f359fcsi3191892plg.208.2023.07.28.06.40.24; Fri, 28 Jul 2023 06:40:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LOYZuo50; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235258AbjG1MNK (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234849AbjG1MMv (ORCPT ); Fri, 28 Jul 2023 08:12:51 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CFD526BC; Fri, 28 Jul 2023 05:12:50 -0700 (PDT) Message-ID: <20230728120929.944578301@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546369; 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=W37gGs0lCrcES4uNg1Zl0+g2c0hE6iWg5mZxC7Tosgc=; b=LOYZuo50rp6pzKVY1Fnas4hlljh8Dcx+O7JxDpCZVwY11odiab00Z6zUTMe+C4rORSDShX Av7wImZZKDcpWsxz3EkDneqXmmnUZ9Iejm33NVM0rAFEtQyelifeUwUha2v7ye+T4FRXfs LfsXr5/faRsUZXuIId3JcEZtF4HkhhQQBnomZe4DKT/Lab0wyfg90a+uu2pJxO7/lp8tL1 dkSoME+zzHBeiccBod+V90gGSV8C3Tp/3MIDMBFioEm9MkDrSvpqQm575nG+ajbIrf18TA EUnfcb1aaj4cWghdBfukHif7u9I4JsSNY8MP1z8ybxlEhaOp/FRIJCrdsMPNXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546369; 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=W37gGs0lCrcES4uNg1Zl0+g2c0hE6iWg5mZxC7Tosgc=; b=a6l8K8mqvplkdOJM9DVMpMo/hwRXJORjx2hRIi6zSgLhEApv/7A8+HtV7z6NdaPzjKqpot V/O2k2hBSmH97IDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 05/38] hwmon: (fam15h_power) Use topology_core_id() References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:48 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772671875196457633 X-GMAIL-MSGID: 1772671875196457633 Use the provided topology helper function instead of fiddling in cpu_data. Signed-off-by: Thomas Gleixner Acked-by: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Cc: Jean Delvare Cc: Huang Rui --- drivers/hwmon/fam15h_power.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/drivers/hwmon/fam15h_power.c +++ b/drivers/hwmon/fam15h_power.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -134,15 +135,13 @@ static DEVICE_ATTR_RO(power1_crit); static void do_read_registers_on_cu(void *_data) { struct fam15h_power_data *data = _data; - int cpu, cu; - - cpu = smp_processor_id(); + int cu; /* * With the new x86 topology modelling, cpu core id actually * is compute unit id. */ - cu = cpu_data(cpu).cpu_core_id; + cu = topology_core_id(smp_processor_id()); rdmsrl_safe(MSR_F15H_CU_PWR_ACCUMULATOR, &data->cu_acc_power[cu]); rdmsrl_safe(MSR_F15H_PTSC, &data->cpu_sw_pwr_ptsc[cu]); From patchwork Fri Jul 28 12:12:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127604 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp406953vqg; Fri, 28 Jul 2023 05:44:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlGkLAJRobZHl512wUa+RzG0AbPT9WOW0aGwRbuLYV6XyJr0eh0oEgwhEg6pIsnzcclaT+mB X-Received: by 2002:a05:6a00:23cf:b0:63a:ea82:b7b7 with SMTP id g15-20020a056a0023cf00b0063aea82b7b7mr2338007pfc.28.1690548249280; Fri, 28 Jul 2023 05:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548249; cv=none; d=google.com; s=arc-20160816; b=x1h6nEKtRnxD6a7dhgRHfK7/XD0BMKVdH4Smo2hONJZm6chxzgdtnXXR2GMGiPBxag C78qWBPpt+A3actSQK1OrPzUQHHVByEGIYFGPBzVADnGXgZSzmMdVRUIG2cMHUL1j1le vNSUBirTX7JLdQ1yCNvH+/hv2/t4aayu9S0iTq9zCIqXGbprABoH0rLM+zjklacEzpWt OJ+HrDEYMoDRH6PzWycXf+AKUQ9/vu/tjYHKL4XdaM5PFb/UC/kCs4/H7+DB5QaCjDco GcDkR67k7vHuQ1Z5plGKXm0jJwVqzYafZN9raP160+qIT+I5aYfGaI9nKZ8PFiDjSzpE V8GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=H/RRg/Ng7gVCWf1JKUraosEsbY2lA8TZJktDOeNxV1s=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=FAjA3lnuJmIymgyb3zEr2Q3zP/3UWZdL7Knmb9QiqkRmCdMUTNt/bv9aQr4lGa0p/t nIGYXZBmZMi2BrjXMWoECM2FK55em1Q4xeqQcqSUX3XssVFXNd7N5BKV9J96G3+o1hVf vzRGAP5n1oeVbk2LIbuzNIHbR5KJpdeE8NZtvzzugsls07d0LcV6bcQFltyFC01waU2c niI6C1Z/P7/r+of6/3H0NsdVBM5xuaUVT93LMSbrLq05xcqs+jgfMZV6DGDw8u/ZJhmh 5hiOQldeUa6xLToR7Y8PCW5ABCbisUTYs/W7zj7ApEaSFSszwrmjcjtXgEWyVoyzCJQu bAcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3UrsRE4W; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b26-20020a6567da000000b005641ddd031esi930079pgs.752.2023.07.28.05.43.55; Fri, 28 Jul 2023 05:44:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3UrsRE4W; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235324AbjG1MNY (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235015AbjG1MMx (ORCPT ); Fri, 28 Jul 2023 08:12:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FF1C2686; Fri, 28 Jul 2023 05:12:51 -0700 (PDT) Message-ID: <20230728120929.999999181@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546370; 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=H/RRg/Ng7gVCWf1JKUraosEsbY2lA8TZJktDOeNxV1s=; b=3UrsRE4WRm4OOqhdx7LP7GiPPhAmxHzaaXw4MJSEvuWYy6IpN8iUDNvYHMVddR+u6YP7XN cVhaJQBVkOJ51fdWmqFBIyDOjYvZy1HxQ2hmHCzj+oBseZuziAo0P3xZhcTT+ZkNJzNAFQ MUPcfFngsLV37UugJJt3/hOM6xNQS9+qoHWsmrl+tmyZl7H0RaH+iTLXfMpVel0da5lFM3 ez9wpaa7h1AEDa3zEWUNSjyP5KVVbpZOn+BXVKDHmEGkdUPwDG+SGeeT24GfcVGtMEyH90 T0hTV5drWsyaR1kcVNbeCgweJ4YWllRazasql5jxAjusRzRQP1DqgxM52oKGEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546370; 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=H/RRg/Ng7gVCWf1JKUraosEsbY2lA8TZJktDOeNxV1s=; b=MSA+oTRKgcWeg9fgLvntobCencHRr4d1dXLMkSiWbyOQ6TNIy12IcvOpnL68uCIOH/Rz/M s9eazTjHYE0j1OAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 06/38] x86/cpu: Move cpu_core_id into topology info References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:50 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668321027030526 X-GMAIL-MSGID: 1772668321027030526 Rename it to core_id and stick it to the other ID fields. No functional change. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 4 +++- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/amd_nb.c | 4 ++-- arch/x86/kernel/cpu/amd.c | 8 ++++---- arch/x86/kernel/cpu/common.c | 4 ++-- arch/x86/kernel/cpu/hygon.c | 4 ++-- arch/x86/kernel/cpu/proc.c | 2 +- arch/x86/kernel/cpu/topology.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++--- 9 files changed, 19 insertions(+), 17 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -88,6 +88,9 @@ struct cpuinfo_topology { // Physical die ID on AMD, Relative on Intel u32 die_id; + + // Core ID relative to the package + u32 core_id; }; struct cpuinfo_x86 { @@ -142,7 +145,6 @@ struct cpuinfo_x86 { /* Logical processor id: */ u16 logical_proc_id; /* Core id: */ - u16 cpu_core_id; u16 logical_die_id; /* Index into per_cpu list: */ u16 cpu_index; --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -109,7 +109,7 @@ extern const struct cpumask *cpu_cluster #define topology_physical_package_id(cpu) (cpu_data(cpu).topo.pkg_id) #define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) #define topology_die_id(cpu) (cpu_data(cpu).topo.die_id) -#define topology_core_id(cpu) (cpu_data(cpu).cpu_core_id) +#define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) extern unsigned int __max_die_per_package; --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -378,7 +378,7 @@ int amd_get_subcaches(int cpu) pci_read_config_dword(link, 0x1d4, &mask); - return (mask >> (4 * cpu_data(cpu).cpu_core_id)) & 0xf; + return (mask >> (4 * cpu_data(cpu).topo.core_id)) & 0xf; } int amd_set_subcaches(int cpu, unsigned long mask) @@ -404,7 +404,7 @@ int amd_set_subcaches(int cpu, unsigned pci_write_config_dword(nb->misc, 0x1b8, reg & ~0x180000); } - cuid = cpu_data(cpu).cpu_core_id; + cuid = cpu_data(cpu).topo.core_id; mask <<= 4 * cuid; mask |= (0xf ^ (1 << cuid)) << 26; --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -306,7 +306,7 @@ static int nearby_node(int apicid) #endif /* - * Fix up cpu_core_id for pre-F17h systems to be in the + * 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. */ @@ -318,7 +318,7 @@ static void legacy_fixup_core_id(struct return; cus_per_node = c->x86_max_cores / nodes_per_socket; - c->cpu_core_id %= cus_per_node; + c->topo.core_id %= cus_per_node; } /* @@ -344,7 +344,7 @@ static void amd_get_topology(struct cpui c->cu_id = ebx & 0xff; if (c->x86 >= 0x17) { - c->cpu_core_id = ebx & 0xff; + c->topo.core_id = ebx & 0xff; if (smp_num_siblings > 1) c->x86_max_cores /= smp_num_siblings; @@ -387,7 +387,7 @@ static void amd_detect_cmp(struct cpuinf bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); + c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -907,8 +907,8 @@ void detect_ht(struct cpuinfo_x86 *c) core_bits = get_count_order(c->x86_max_cores); - c->cpu_core_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb) & - ((1 << core_bits) - 1); + c->topo.core_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb) & + ((1 << core_bits) - 1); #endif } --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -74,7 +74,7 @@ static void hygon_get_topology(struct cp c->topo.die_id = ecx & 0xff; - c->cpu_core_id = ebx & 0xff; + c->topo.core_id = ebx & 0xff; if (smp_num_siblings > 1) c->x86_max_cores /= smp_num_siblings; @@ -116,7 +116,7 @@ static void hygon_detect_cmp(struct cpui bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ - c->cpu_core_id = c->topo.initial_apicid & ((1 << bits)-1); + c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -21,7 +21,7 @@ static void show_cpuinfo_core(struct seq seq_printf(m, "physical id\t: %d\n", c->topo.pkg_id); seq_printf(m, "siblings\t: %d\n", cpumask_weight(topology_core_cpumask(cpu))); - seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id); + seq_printf(m, "core id\t\t: %d\n", c->topo.core_id); seq_printf(m, "cpu cores\t: %d\n", c->booted_cores); seq_printf(m, "apicid\t\t: %d\n", c->topo.apicid); seq_printf(m, "initial apicid\t: %d\n", c->topo.initial_apicid); --- a/arch/x86/kernel/cpu/topology.c +++ b/arch/x86/kernel/cpu/topology.c @@ -146,7 +146,7 @@ int detect_extended_topology(struct cpui die_select_mask = (~(-1 << die_plus_mask_width)) >> core_plus_mask_width; - c->cpu_core_id = apic->phys_pkg_id(c->topo.initial_apicid, + c->topo.core_id = apic->phys_pkg_id(c->topo.initial_apicid, ht_mask_width) & core_select_mask; if (die_level_present) { --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -487,7 +487,7 @@ static bool match_smt(struct cpuinfo_x86 if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { - if (c->cpu_core_id == o->cpu_core_id) + if (c->topo.core_id == o->topo.core_id) return topology_sane(c, o, "smt"); if ((c->cu_id != 0xff) && @@ -498,7 +498,7 @@ static bool match_smt(struct cpuinfo_x86 } else if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && - c->cpu_core_id == o->cpu_core_id) { + c->topo.core_id == o->topo.core_id) { return topology_sane(c, o, "smt"); } @@ -1439,7 +1439,7 @@ static void remove_siblinginfo(int cpu) cpumask_clear(topology_sibling_cpumask(cpu)); cpumask_clear(topology_core_cpumask(cpu)); cpumask_clear(topology_die_cpumask(cpu)); - c->cpu_core_id = 0; + c->topo.core_id = 0; c->booted_cores = 0; cpumask_clear_cpu(cpu, cpu_sibling_setup_mask); recompute_smt_state(); From patchwork Fri Jul 28 12:12:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127642 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp434249vqg; Fri, 28 Jul 2023 06:27:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlERMRcyx+zwD6ExlPAim+ngfcsDrVfY3ePLMHnmtHb/xj/jKsSRnNc5Enn4T2taQS37bwH8 X-Received: by 2002:a05:6a20:244b:b0:12e:3d1c:4ba9 with SMTP id t11-20020a056a20244b00b0012e3d1c4ba9mr2219818pzc.30.1690550865798; Fri, 28 Jul 2023 06:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550865; cv=none; d=google.com; s=arc-20160816; b=Zt3u/eRAGdrjIIMo/Fp++/EegT7W22tVfsNnnzM0eyKE9HuUs+B7wzv3x5U+SNl3Lx ASM2BY0BcM3BSPZoaKv/qSyXlaVGeeLlsCLv5S22mGO2WQeyhs+G3ZZLlDEjkRsD0Yp3 AUBPIg457UbfNtVMEdaG2EqGKgxZfXWOZe7Zh1Mgg8BSwSJ8LxeQ8qIwdfC9k4/WPOXl 8goEMTOpIQHWPR3wzmyESS9TTDfyb4rljohnEQidTWaLZWK5JYjkMlMZaUGhBftHIfp8 WiQtghR9xtPvyBjSE9HhM3K4OG0BTRFV3WRIVe+JVYgbS50LDIjKmZu5MDM60thDRIOA /XPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=WfNPFKAN9GG2GFdyit2jWhoSZIUriu/Y8Ta0CK3Muoc=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=tqzd7iq1vsK5JUIc0ELinsFFhmFxpOdx5cOKVweiWlXKh4tnHtZ89btJuqstvO5/5K iz4pYq2gbPBYpRULar4D1op6u0kqoGtHDqQ19W4A/WaE5CwWnv6Lv9Xa9PX2PcN3dSjd N6KvvXYFD8RWvisireywDwiJ3kxCDIhG3m4yfTvtRZIvpNhaAKfZBR4xk9YXkDB4v4L0 byxtVWfUn2SFhOenZp0ohYd7UzR4A7zT09M+NPwT5iRcSATJAthqSlRNRsXhRTm+ZLoS YYP/ngvB6Qq7tIYnFDbElWxeuxj4P5cG49Ae1x3yPGrbUSDLq5fYM10f68raodYUpZjl 7GPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fmUzRCRg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs1-20020a632801000000b00563e6c095a9si495403pgb.402.2023.07.28.06.27.29; Fri, 28 Jul 2023 06:27:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fmUzRCRg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235717AbjG1MN3 (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235168AbjG1MMy (ORCPT ); Fri, 28 Jul 2023 08:12:54 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5EB1268B; Fri, 28 Jul 2023 05:12:52 -0700 (PDT) Message-ID: <20230728120930.055388145@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546371; 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=WfNPFKAN9GG2GFdyit2jWhoSZIUriu/Y8Ta0CK3Muoc=; b=fmUzRCRg7yR2P9DmPno2iwKqUa/L1iNvs+O7AUmd4kIAmUT4fMakJpdvK0MPA1cVWsXKr8 AcAa4z8GCuOZuEuYsvXY7kkt70i2xlBdZlSP0q1UUxXbVpHR56wgtqxCIO9JZrp7TbXU48 paINd20ybEWFgxAHbtD+0DSlQKMZfsIlubSiXlLZuiYVlTSyhhsxR6eq5BElO7R0tv3znI jgQu8y2p1U7B4zlJJ6R2Fpj5uHzALuFGq5QAX6gcCRrJOYaGyrgAtwrDstu8c+sI2PFxKc oncHCfSY5oQnNO/aRAW0GfDbvmoX8Rc77qxisAnfeddue3K91oMNGu4sQUyEow== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546371; 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=WfNPFKAN9GG2GFdyit2jWhoSZIUriu/Y8Ta0CK3Muoc=; b=ymtc3pobhOczipG+blBIQKfKln91uF8i+irowFLB4i13KBEAhcn5Fkx+nwjjjbLq2mtD0S ATWxtqL4UhsgbTDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 07/38] x86/cpu: Move cu_id into topology info References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:51 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772671064397840953 X-GMAIL-MSGID: 1772671064397840953 No functional change. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 4 +++- arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/smpboot.c | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -89,6 +89,9 @@ struct cpuinfo_topology { // Physical die ID on AMD, Relative on Intel u32 die_id; + // Compute unit ID - AMD specific + u32 cu_id; + // Core ID relative to the package u32 core_id; }; @@ -109,7 +112,6 @@ struct cpuinfo_x86 { __u8 x86_phys_bits; /* CPUID returned core id bits: */ __u8 x86_coreid_bits; - __u8 cu_id; /* Max extended CPUID function supported: */ __u32 extended_cpuid_level; /* Maximum supported CPUID level, -1=no CPUID: */ --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -341,7 +341,7 @@ static void amd_get_topology(struct cpui c->topo.die_id = ecx & 0xff; if (c->x86 == 0x15) - c->cu_id = ebx & 0xff; + c->topo.cu_id = ebx & 0xff; if (c->x86 >= 0x17) { c->topo.core_id = ebx & 0xff; --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1789,7 +1789,7 @@ static void identify_cpu(struct cpuinfo_ c->x86_model_id[0] = '\0'; /* Unset */ c->x86_max_cores = 1; c->x86_coreid_bits = 0; - c->cu_id = 0xff; + c->topo.cu_id = 0xff; #ifdef CONFIG_X86_64 c->x86_clflush_size = 64; c->x86_phys_bits = 36; --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -490,9 +490,9 @@ static bool match_smt(struct cpuinfo_x86 if (c->topo.core_id == o->topo.core_id) return topology_sane(c, o, "smt"); - if ((c->cu_id != 0xff) && - (o->cu_id != 0xff) && - (c->cu_id == o->cu_id)) + if ((c->topo.cu_id != 0xff) && + (o->topo.cu_id != 0xff) && + (c->topo.cu_id == o->topo.cu_id)) return topology_sane(c, o, "smt"); } From patchwork Fri Jul 28 12:12:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127649 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp441107vqg; Fri, 28 Jul 2023 06:38:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlFypl7ZrDeb+iuZhva65d2RLrIXvq3A+viWn/pXj0UvCn4sdrWdfEadpkqNy6/P9fpoLFh5 X-Received: by 2002:a05:6a00:15d2:b0:682:e24c:f4e0 with SMTP id o18-20020a056a0015d200b00682e24cf4e0mr2466558pfu.11.1690551508644; Fri, 28 Jul 2023 06:38:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690551508; cv=none; d=google.com; s=arc-20160816; b=wfUpkpLBb5g8PEb5ztW/ovVVvdNgoUmI0iJ/y6p10X8wvuYiHl9lXffTVRCx3NklTc Ib9ToAxMIR9A4kxcS0AeJVZ5uNBYg69iS1PIdF8GSml1NIJChL16iqgGzuMxPt+tvcjI P41QJWtftMBygb7w12lDr5fn6YSxwVHfGTQfB5G4Wzc3HOn8usEJ64wrE35bJsmyHx3S NZmyotcG+ecMu/xdKWLa+/UMEao9CEuu1F4uFNnrrUR0y+tz0skHB1FCvbBAtCmNcIyq F4DDMAxdPfzeaKm6dZHQHWug6OtsAhDjGESkfYMpB0QRIrq8pDO4UqVuPyW6IClLIEOn NaYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=t8GxhNF6HGOaqAPuRwkda5YYxZL4VSRyQt8u47FAxec=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=YfA01a1Hp9BsPOsYwJhXrxJ5sPJxMIrUf3Dw/usdExPt9bwfr1mLMAzjmSxTKiDGQQ 8MNJeCHcVRCm0wUhTPgX7BCjE87BIrLCOfJiauBvzstXYQ2leEcPH6KeSKldbBmAs+kt VGq2f/1TMBBKc/2WmIkKcnN0sZZmaRYp2mUFOuKPTLzH5PSGfZd0A0lFWi4bssGkrTLI Zpj2xNSPnDqp/EWK40Vii2F85RcbYgyg4cNDPKCyMjK4uoT09oVFMYFACukmqTonuRRt TlM60+2e/XA4Gx8iUUq6HuAI9BJ9jlMv6aUMCO87WDrXjZp3PAckd0e1fdkCenf2DD61 Laww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IOXoiWw+; dkim=neutral (no key) header.i=@linutronix.de header.b=snq8KALa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eg26-20020a056a00801a00b006870c16c9d4si1385515pfb.123.2023.07.28.06.38.12; Fri, 28 Jul 2023 06:38:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IOXoiWw+; dkim=neutral (no key) header.i=@linutronix.de header.b=snq8KALa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235371AbjG1MN2 (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235336AbjG1MMz (ORCPT ); Fri, 28 Jul 2023 08:12:55 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32681269E; Fri, 28 Jul 2023 05:12:54 -0700 (PDT) Message-ID: <20230728120930.111031350@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546372; 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=t8GxhNF6HGOaqAPuRwkda5YYxZL4VSRyQt8u47FAxec=; b=IOXoiWw+rOTs13GC6sSM/dyeIKF5LXtjixTLgtq62v7HiRGIsOqObtivsD+0nuwNHz3oX4 PtQwaF43W87MMuaAnlaDrGJaut5iJzivv0Z/12NAQNTinOBxKREE/SwxQEev35ACWDu+3f ZfQTHUEIfQKodJG0iyhaYlYmKLvNQEEYor2tb376hAy32piCmFraxKQ1N3EJG9vCNnX4c7 Mo5gYN7OQL6TG0p1Q7ac1gnaZrDLK/nUYjW0sKyuTaFEI8MGJrfBb3Td3V6ev9Xf28aKlE c/+aSATN5IGRwg6W1NMVolraSzR1Fjpe6gFEOm3whqQuurOpbKRf7CWPPX2VrA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546372; 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=t8GxhNF6HGOaqAPuRwkda5YYxZL4VSRyQt8u47FAxec=; b=snq8KALad7v+S/vb1OXyySj9T7QIYG3Rub8YXGB69qbicSWOiMfWL4dO6s4YWrhGO9kNnd mtRPiKcVTOqZ2XAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 08/38] x86/cpu: Remove pointless evaluation of x86_coreid_bits References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:52 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772671738894356650 X-GMAIL-MSGID: 1772671738894356650 cpuinfo_x86::x86_coreid_bits is only used by the AMD numa topology code. No point in evaluating it on non AMD systems. No functional change. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/intel.c | 13 ------------- arch/x86/kernel/cpu/zhaoxin.c | 14 -------------- 2 files changed, 27 deletions(-) --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -488,19 +488,6 @@ static void early_init_intel(struct cpui setup_clear_cpu_cap(X86_FEATURE_PGE); } - if (c->cpuid_level >= 0x00000001) { - u32 eax, ebx, ecx, edx; - - cpuid(0x00000001, &eax, &ebx, &ecx, &edx); - /* - * If HTT (EDX[28]) is set EBX[16:23] contain the number of - * apicids which are reserved per package. Store the resulting - * shift value for the package management code. - */ - if (edx & (1U << 28)) - c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff); - } - check_memory_type_self_snoop_errata(c); /* --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -65,20 +65,6 @@ static void early_init_zhaoxin(struct cp set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); } - - if (c->cpuid_level >= 0x00000001) { - u32 eax, ebx, ecx, edx; - - cpuid(0x00000001, &eax, &ebx, &ecx, &edx); - /* - * If HTT (EDX[28]) is set EBX[16:23] contain the number of - * apicids which are reserved per package. Store the resulting - * shift value for the package management code. - */ - if (edx & (1U << 28)) - c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff); - } - } static void init_zhaoxin(struct cpuinfo_x86 *c) From patchwork Fri Jul 28 12:12:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp415570vqg; Fri, 28 Jul 2023 06:01:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlH3oq9wkhvGWz5hoMAc2bdOMZixhpOzo6iY4NubF5mTtrvJjv/Ji0GRpVK7fhvqHDrymjUQ X-Received: by 2002:a05:6a20:3d91:b0:132:c07c:f042 with SMTP id s17-20020a056a203d9100b00132c07cf042mr1542518pzi.15.1690549270295; Fri, 28 Jul 2023 06:01:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690549270; cv=none; d=google.com; s=arc-20160816; b=eoOGO9f4OpsymcU6B+Wv9K12R1Wac3CQfIpMT0yaS/1YJ0PhC275Y/9r3/jd1nKh2v GGoRPPYkqI3+jhj4PVZUF7KftNVZH3q9PNqypMr0CwiLTTcw4uDxRoyz0tk5PPOLDC+M Uv8CFDp3gZ/kH0r4OqXHnyFTRWoo59cWEZvi2aVo8rV4r/MjB/SS9jpw11qzKcf5yhaJ HvYGw0Sdo3+vmfZtiptk7rwAjAxc0lo5hjbc3aPltLF2S3oPw08N54mjXhyxTL2lIKtU xJ14RnKD+VyNjAnXaRoSSpV5DYZVoak6JaAxI+U9BX99cEA+IGxjlzNdyjH1epODwZAq NIZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=2RANHxmSCQq3gd8prDSNXS5TE/ZWoRk9LvjezfySwEw=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=t5n5Vj4Q6Zw/D9UKxxF50TwWvhzbimdpSCUPXn6Tt3KzABpJqHTdOeeIMGk9qZdtf/ 35R7qkYWfDqE58dE5a0Fc5gAj23F3XiAjNmtZRiJcwqLN1Xyaq+vpmDbrIBRk7sYWNqv uEpIU1YyAOWNvMHHH9K4KlBnLr5liBafM85kXk1hPH70wgYjS/k8I7oKu9f0LkSgeF85 W4FpmB2/r6T6SrBlC0HfDD6QmjnXrtGljshd70loqX1MLrychaHNpqjM0lJTS17vQtwb rgfO1ltZY20T4QyfnCGLNJcnp/2YIsx7yTzxQO3ABMsGLu2x63D0KDs7P9yTfrAGmRa7 EF9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MRuvYwRN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q24-20020a637518000000b00540107fc033si2703999pgc.282.2023.07.28.06.00.57; Fri, 28 Jul 2023 06:01:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=MRuvYwRN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234744AbjG1MNd (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235412AbjG1MM4 (ORCPT ); Fri, 28 Jul 2023 08:12:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE3E268B; Fri, 28 Jul 2023 05:12:55 -0700 (PDT) Message-ID: <20230728120930.166316762@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546373; 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=2RANHxmSCQq3gd8prDSNXS5TE/ZWoRk9LvjezfySwEw=; b=MRuvYwRNVH0Jwe4ANKER/YiSCUMPBsPoRxXflROQHvfrqvJJN6kqkw08bj/UNDmPo4b2VD rZwhwLC5l7eH6cP4gQwL+zgWXtV471/ofGsgyN5LQtbdUz+7jILBHKYq/l3/JlJrvjkPX+ +56JhPv+mWHU5tXjKJ4XQBOsfmaYhyOMCcRq/al07HLFts9GB5+Pcd0NCpz2IZ0P/Esci7 +e7IhbGIeSu0F+7ZvQNF6WMyk6zRDsRC/5LbrRLNStZDbML34OBWcA/0SvNEZJloaKQ/xF Bs/gtfmsh/8W2wt20cNYoMmN148YYc4AoRjjianWyntsPT2TARhF9jGqELU2Hw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546373; 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=2RANHxmSCQq3gd8prDSNXS5TE/ZWoRk9LvjezfySwEw=; b=YFrZa4hDEnAG3AhL5jDj33Prp95jSZkr1qE+gat+Uvzl76/Lu7fADLRFcMqQp75ZC/i40o MXYiUAWajIGKofCg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 09/38] x86/cpu: Move logical package and die IDs into topology info References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:53 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772669391357498050 X-GMAIL-MSGID: 1772669391357498050 Yet another topology related data pair. Rename logical_proc_id to logical_pkg_id so it fits the common naming conventions. No functional change. Signed-off-by: Thomas Gleixner --- Documentation/arch/x86/topology.rst | 2 +- arch/x86/events/intel/uncore.c | 2 +- arch/x86/include/asm/processor.h | 8 ++++---- arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/smpboot.c | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -67,7 +67,7 @@ AMD nomenclature for package is 'Node'. Modern systems use this value for the socket. There may be multiple packages within a socket. This value may differ from topo.die_id. - - cpuinfo_x86.logical_proc_id: + - cpuinfo_x86.topo.logical_pkg_id: The logical ID of the package. As we do not trust BIOSes to enumerate the packages in a consistent way, we introduced the concept of logical package --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -74,7 +74,7 @@ int uncore_device_to_die(struct pci_dev struct cpuinfo_x86 *c = &cpu_data(cpu); if (c->initialized && cpu_to_node(cpu) == node) - return c->logical_die_id; + return c->topo.logical_die_id; } return -1; --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -94,6 +94,10 @@ struct cpuinfo_topology { // Core ID relative to the package u32 core_id; + + // Logical ID mappings + u32 logical_pkg_id; + u32 logical_die_id; }; struct cpuinfo_x86 { @@ -144,10 +148,6 @@ struct cpuinfo_x86 { u16 x86_clflush_size; /* number of cores as seen by the OS: */ u16 booted_cores; - /* Logical processor id: */ - u16 logical_proc_id; - /* Core id: */ - u16 logical_die_id; /* Index into per_cpu list: */ u16 cpu_index; /* Is SMT active on this core? */ --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -105,9 +105,9 @@ static inline void setup_node_to_cpumask extern const struct cpumask *cpu_coregroup_mask(int cpu); extern const struct cpumask *cpu_clustergroup_mask(int cpu); -#define topology_logical_package_id(cpu) (cpu_data(cpu).logical_proc_id) +#define topology_logical_package_id(cpu) (cpu_data(cpu).topo.logical_pkg_id) #define topology_physical_package_id(cpu) (cpu_data(cpu).topo.pkg_id) -#define topology_logical_die_id(cpu) (cpu_data(cpu).logical_die_id) +#define topology_logical_die_id(cpu) (cpu_data(cpu).topo.logical_die_id) #define topology_die_id(cpu) (cpu_data(cpu).topo.die_id) #define topology_core_id(cpu) (cpu_data(cpu).topo.core_id) #define topology_ppin(cpu) (cpu_data(cpu).ppin) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1770,7 +1770,7 @@ static void validate_apic_and_package_id BUG_ON(topology_update_package_map(c->topo.pkg_id, cpu)); BUG_ON(topology_update_die_map(c->topo.die_id, cpu)); #else - c->logical_proc_id = 0; + c->topo.logical_pkg_id = 0; #endif } --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -348,7 +348,7 @@ int topology_phys_to_logical_pkg(unsigne struct cpuinfo_x86 *c = &cpu_data(cpu); if (c->initialized && c->topo.pkg_id == phys_pkg) - return c->logical_proc_id; + return c->topo.logical_pkg_id; } return -1; } @@ -370,7 +370,7 @@ static int topology_phys_to_logical_die( if (c->initialized && c->topo.die_id == die_id && c->topo.pkg_id == proc_id) - return c->logical_die_id; + return c->topo.logical_die_id; } return -1; } @@ -395,7 +395,7 @@ int topology_update_package_map(unsigned cpu, pkg, new); } found: - cpu_data(cpu).logical_proc_id = new; + cpu_data(cpu).topo.logical_pkg_id = new; return 0; } /** @@ -418,7 +418,7 @@ int topology_update_die_map(unsigned int cpu, die, new); } found: - cpu_data(cpu).logical_die_id = new; + cpu_data(cpu).topo.logical_die_id = new; return 0; } From patchwork Fri Jul 28 12:12:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127603 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp406788vqg; Fri, 28 Jul 2023 05:43:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlGB//aec0L6uurlTqw9CAb3dIUUG4d5HPBiL6z7teKqcMm57sKxVbXgRdDwz+Hnr7ZgEfSY X-Received: by 2002:a05:6a00:194f:b0:662:5146:c761 with SMTP id s15-20020a056a00194f00b006625146c761mr2372838pfk.17.1690548230605; Fri, 28 Jul 2023 05:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548230; cv=none; d=google.com; s=arc-20160816; b=tfJhEt+9qpoYWdGS3NuyDF+vQtDO/wpQF34nX8i+821UPGLAULzZTtIpmip4nFjFzE 6FEKBD6U0cSOI3onHvr4wE2soP/O+wnBVNbD//uKkW9qlEe7rlojXjzftHjeW5skVewV gQeisBdgftY8IsBXu2pTcowRRaXJtr/FDf/o5KNx9LATzg0M66u55QmOlHFUBgG1e8G4 uX22GtJFYKpb/ZgSc5+2uuwQux6yyVsTEThedFnZzTfEVQ8c+NMWe+iwKnEymsSJgeuE bGUh2TIahe8l0eis/myq094Jw7i4xqtNtUheSCGIe1+i25Lh/ktft6rMtSnyBfXRdEaG QXFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=THjcCsc2GGXII7qdrYLkqctLPB1i0Li4c4N8xoVrrCo=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=o/H3vJTswE7mQ5jn09OF/iPzIyRDiupC5mzHYehGKYe3ecleUlsVL2mP48Tu4bVIAy yohIvqrAzr5ZXuVfsadMqlo2aTfIwarj4BZ7U4+s1Zy7Uc7Qwoxx/AROU+u7MQETv+Fp 8an7s4WIWcgmF/hySE2Q9AgYYOTc2zkrcB3S0DpH9tyRpSBhdqFqmKWccnlPubi+x+xn 8YCMPFlqfEdNIOHcGBKpBPlaLGqXW7AIA38FufX998DsKVtJppBhK4Dw4ou4TiyzSq9O Yx8lCNHLsj231QvL7esNVL+ENeaP5ACU50DJtlTOxYQWvZ7GYsylNs41RsrngTyYiLS2 bIyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EaoJHnav; dkim=neutral (no key) header.i=@linutronix.de header.b="sqFDG3/x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay21-20020a056a00301500b006862e207c34si3104966pfb.66.2023.07.28.05.43.37; Fri, 28 Jul 2023 05:43:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EaoJHnav; dkim=neutral (no key) header.i=@linutronix.de header.b="sqFDG3/x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236456AbjG1MNq (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235762AbjG1MM7 (ORCPT ); Fri, 28 Jul 2023 08:12:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90C7635A8; Fri, 28 Jul 2023 05:12:56 -0700 (PDT) Message-ID: <20230728120930.224888914@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546375; 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=THjcCsc2GGXII7qdrYLkqctLPB1i0Li4c4N8xoVrrCo=; b=EaoJHnavVzcDK+wH5NbFrxiPp5dAOZEvjCfg5UcyMgiI3u0welfFe5AU0hhfMWC/jZElGT Knbc1RtYa0xCYmQsFjVdEJFmnFwdoN9O2v2r3AWtJmUBMcMSpaERbhbU6JHZrJC44YM1nU 0GMFLJOk71naSv9f+XvUn8GEwOtGQeBwHEBPQt6TinR9DHkeUrbkfHKESMLIMg1WwG3R3y JcG3qruVKbCHNacGCqTDMwBebSZ7iLwUi8tT0femiqMXeoTTcRgfOZgnndtBv6lcIIDYYC Q+rP9/j3+VqgKhNdEf7gz5OXfEg2Cpxu/2cgtSpKWpeEtlroKGmMX+OKntFboA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546375; 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=THjcCsc2GGXII7qdrYLkqctLPB1i0Li4c4N8xoVrrCo=; b=sqFDG3/xB1n64u0/7dRDUB/5S5dqla8moh50VgAohgJyHdewnipie+3pJ3j7OPyQH+faxN ENp7AduQeL5v6cDQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 10/38] x86/cpu: Move cpu_l[l2]c_id into topology info References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:55 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668301327915156 X-GMAIL-MSGID: 1772668301327915156 The topology IDs which identify the LLC and L2 domains clearly belong to the per CPU topology information. Move them into cpuinfo_x86::cpuinfo_topo and get rid of the extra per CPU data and the related exports. This also paves the way to do proper topology evaluation during early boot because it removes the only per CPU dependency for that. No functional change. Signed-off-by: Thomas Gleixner --- Documentation/arch/x86/topology.rst | 4 +--- arch/x86/events/amd/uncore.c | 2 +- arch/x86/include/asm/cacheinfo.h | 3 --- arch/x86/include/asm/processor.h | 14 +++++++++++++- arch/x86/include/asm/smp.h | 2 -- arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 12 ++++-------- arch/x86/kernel/cpu/cacheinfo.c | 33 ++++++++++++--------------------- arch/x86/kernel/cpu/common.c | 14 ++------------ arch/x86/kernel/cpu/cpu.h | 3 +++ arch/x86/kernel/cpu/hygon.c | 14 +++++--------- arch/x86/kernel/smpboot.c | 10 +++++----- 13 files changed, 48 insertions(+), 67 deletions(-) --- a/Documentation/arch/x86/topology.rst +++ b/Documentation/arch/x86/topology.rst @@ -79,9 +79,7 @@ AMD nomenclature for package is 'Node'. The maximum possible number of packages in the system. Helpful for per package facilities to preallocate per package information. - - cpu_llc_id: - - A per-CPU variable containing: + - cpuinfo_x86.topo.llc_id: - On Intel, the first APIC ID of the list of CPUs sharing the Last Level Cache --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -537,7 +537,7 @@ static int amd_uncore_cpu_starting(unsig if (amd_uncore_llc) { uncore = *per_cpu_ptr(amd_uncore_llc, cpu); - uncore->id = get_llc_id(cpu); + uncore->id = per_cpu_llc_id(cpu); uncore = amd_uncore_find_online_sibling(uncore, amd_uncore_llc); *per_cpu_ptr(amd_uncore_llc, cpu) = uncore; --- a/arch/x86/include/asm/cacheinfo.h +++ b/arch/x86/include/asm/cacheinfo.h @@ -7,9 +7,6 @@ extern unsigned int memory_caching_contr #define CACHE_MTRR 0x01 #define CACHE_PAT 0x02 -void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu); -void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu); - void cache_disable(void); void cache_enable(void); void set_cache_aps_delayed_init(bool val); --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -98,6 +98,10 @@ struct cpuinfo_topology { // Logical ID mappings u32 logical_pkg_id; u32 logical_die_id; + + // Cache level topology IDs + u32 llc_id; + u32 l2c_id; }; struct cpuinfo_x86 { @@ -687,7 +691,15 @@ extern int set_tsc_mode(unsigned int val DECLARE_PER_CPU(u64, msr_misc_features_shadow); -extern u16 get_llc_id(unsigned int cpu); +static inline u16 per_cpu_llc_id(unsigned int cpu) +{ + return per_cpu(cpu_info.topo.llc_id, cpu); +} + +static inline u16 per_cpu_l2c_id(unsigned int cpu) +{ + return per_cpu(cpu_info.topo.l2c_id, cpu); +} #ifdef CONFIG_CPU_SUP_AMD extern u32 amd_get_nodes_per_socket(void); --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -17,8 +17,6 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_ /* cpus sharing the last level cache: */ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map); -DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id); -DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id); DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid); DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid); --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -115,7 +115,7 @@ extern const struct cpumask *cpu_cluster extern unsigned int __max_die_per_package; #ifdef CONFIG_SMP -#define topology_cluster_id(cpu) (per_cpu(cpu_l2c_id, cpu)) +#define topology_cluster_id(cpu) (cpu_data(cpu).topo.l2c_id) #define topology_die_cpumask(cpu) (per_cpu(cpu_die_map, cpu)) #define topology_cluster_cpumask(cpu) (cpu_clustergroup_mask(cpu)) #define topology_core_cpumask(cpu) (per_cpu(cpu_core_map, cpu)) --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -161,7 +161,7 @@ static void fixup_cpu_id(struct cpuinfo_ u64 val; u32 nodes = 1; - this_cpu_write(cpu_llc_id, node); + c->topo.llc_id = node; /* Account for nodes per socket in multi-core-module processors */ if (boot_cpu_has(X86_FEATURE_NODEID_MSR)) { --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -329,8 +329,6 @@ static void legacy_fixup_core_id(struct */ static void amd_get_topology(struct cpuinfo_x86 *c) { - int cpu = smp_processor_id(); - /* get information required for multi-node processors */ if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { int err; @@ -358,15 +356,14 @@ static void amd_get_topology(struct cpui if (!err) c->x86_coreid_bits = get_count_order(c->x86_max_cores); - cacheinfo_amd_init_llc_id(c, cpu); + cacheinfo_amd_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 = value & 7; - - per_cpu(cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; } else return; @@ -383,7 +380,6 @@ static void amd_get_topology(struct cpui static void amd_detect_cmp(struct cpuinfo_x86 *c) { unsigned bits; - int cpu = smp_processor_id(); bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ @@ -391,7 +387,7 @@ static void amd_detect_cmp(struct cpuinf /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; + c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; } u32 amd_get_nodes_per_socket(void) @@ -409,7 +405,7 @@ static void srat_detect_node(struct cpui node = numa_cpu_node(cpu); if (node == NUMA_NO_NODE) - node = get_llc_id(cpu); + node = per_cpu_llc_id(cpu); /* * On multi-fabric platform (e.g. Numascale NumaChip) a --- 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; } -void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, int cpu) +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c) { /* * We may have multiple LLCs if L3 caches exist, so check if we @@ -672,13 +672,13 @@ void cacheinfo_amd_init_llc_id(struct cp if (c->x86 < 0x17) { /* LLC is at the node level. */ - per_cpu(cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; } else if (c->x86 == 0x17 && c->x86_model <= 0x1F) { /* * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ - per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> 3; + c->topo.llc_id = c->topo.apicid >> 3; } else { /* * LLC ID is calculated from the number of threads sharing the @@ -694,12 +694,12 @@ void cacheinfo_amd_init_llc_id(struct cp if (num_sharing_cache) { int bits = get_count_order(num_sharing_cache); - per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> bits; + c->topo.llc_id = c->topo.apicid >> bits; } } } -void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c, int cpu) +void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) { /* * We may have multiple LLCs if L3 caches exist, so check if we @@ -712,7 +712,7 @@ void cacheinfo_hygon_init_llc_id(struct * LLC is at the core complex level. * Core complex ID is ApicId[3] for these processors. */ - per_cpu(cpu_llc_id, cpu) = c->topo.apicid >> 3; + c->topo.llc_id = c->topo.apicid >> 3; } void init_amd_cacheinfo(struct cpuinfo_x86 *c) @@ -740,9 +740,6 @@ void init_intel_cacheinfo(struct cpuinfo unsigned int new_l1d = 0, new_l1i = 0; /* Cache sizes from cpuid(4) */ unsigned int new_l2 = 0, new_l3 = 0, i; /* Cache sizes from cpuid(4) */ unsigned int l2_id = 0, l3_id = 0, num_threads_sharing, index_msb; -#ifdef CONFIG_SMP - unsigned int cpu = c->cpu_index; -#endif if (c->cpuid_level > 3) { static int is_initialized; @@ -856,30 +853,24 @@ void init_intel_cacheinfo(struct cpuinfo if (new_l2) { l2 = new_l2; -#ifdef CONFIG_SMP - per_cpu(cpu_llc_id, cpu) = l2_id; - per_cpu(cpu_l2c_id, cpu) = l2_id; -#endif + c->topo.llc_id = l2_id; + c->topo.l2c_id = l2_id; } if (new_l3) { l3 = new_l3; -#ifdef CONFIG_SMP - per_cpu(cpu_llc_id, cpu) = l3_id; -#endif + c->topo.llc_id = l3_id; } -#ifdef CONFIG_SMP /* - * If cpu_llc_id is not yet set, this means cpuid_level < 4 which in + * If llc_id is not yet set, this means cpuid_level < 4 which in * turns means that the only possibility is SMT (as indicated in * cpuid1). Since cpuid2 doesn't specify shared caches, and we know * that SMT shares all caches, we can unconditionally set cpu_llc_id to * c->topo.pkg_id. */ - if (per_cpu(cpu_llc_id, cpu) == BAD_APICID) - per_cpu(cpu_llc_id, cpu) = c->topo.pkg_id; -#endif + if (c->topo.llc_id == BAD_APICID) + c->topo.llc_id = c->topo.pkg_id; c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d)); --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -75,18 +75,6 @@ u32 elf_hwcap2 __read_mostly; int smp_num_siblings = 1; EXPORT_SYMBOL(smp_num_siblings); -/* Last level cache ID of each logical CPU */ -DEFINE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id) = BAD_APICID; - -u16 get_llc_id(unsigned int cpu) -{ - return per_cpu(cpu_llc_id, cpu); -} -EXPORT_SYMBOL_GPL(get_llc_id); - -/* L2 cache ID of each logical CPU */ -DEFINE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id) = BAD_APICID; - static struct ppin_info { int feature; int msr_ppin_ctl; @@ -1790,6 +1778,8 @@ static void identify_cpu(struct cpuinfo_ c->x86_max_cores = 1; c->x86_coreid_bits = 0; c->topo.cu_id = 0xff; + c->topo.llc_id = BAD_APICID; + c->topo.l2c_id = BAD_APICID; #ifdef CONFIG_X86_64 c->x86_clflush_size = 64; c->x86_phys_bits = 36; --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -78,6 +78,9 @@ extern int detect_ht_early(struct cpuinf extern void detect_ht(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); +void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c); +void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c); + unsigned int aperfmperf_get_khz(int cpu); void cpu_select_mitigations(void); --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -63,8 +63,6 @@ static void hygon_get_topology_early(str */ static void hygon_get_topology(struct cpuinfo_x86 *c) { - int cpu = smp_processor_id(); - /* get information required for multi-node processors */ if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { int err; @@ -90,14 +88,13 @@ static void hygon_get_topology(struct cp /* Socket ID is ApicId[6] for these processors. */ c->topo.pkg_id = c->topo.apicid >> APICID_SOCKET_ID_BIT; - cacheinfo_hygon_init_llc_id(c, cpu); + 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 = value & 7; - - per_cpu(cpu_llc_id, cpu) = c->topo.die_id; + c->topo.llc_id = c->topo.die_id; } else return; @@ -112,15 +109,14 @@ static void hygon_get_topology(struct cp static void hygon_detect_cmp(struct cpuinfo_x86 *c) { unsigned int bits; - int cpu = smp_processor_id(); bits = c->x86_coreid_bits; /* Low order bits define the core id (index of core in socket) */ c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); /* Convert the initial APIC ID into the socket ID */ c->topo.pkg_id = c->topo.initial_apicid >> bits; - /* use socket ID also for last level cache */ - per_cpu(cpu_llc_id, cpu) = c->topo.die_id = c->topo.pkg_id; + /* Use package ID also for last level cache */ + c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; } static void srat_detect_node(struct cpuinfo_x86 *c) @@ -132,7 +128,7 @@ static void srat_detect_node(struct cpui node = numa_cpu_node(cpu); if (node == NUMA_NO_NODE) - node = per_cpu(cpu_llc_id, cpu); + node = c->topo.llc_id; /* * On multi-fabric platform (e.g. Numascale NumaChip) a --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -486,7 +486,7 @@ static bool match_smt(struct cpuinfo_x86 if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && - per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) { + per_cpu_llc_id(cpu1) == per_cpu_llc_id(cpu2)) { if (c->topo.core_id == o->topo.core_id) return topology_sane(c, o, "smt"); @@ -518,11 +518,11 @@ static bool match_l2c(struct cpuinfo_x86 int cpu1 = c->cpu_index, cpu2 = o->cpu_index; /* If the arch didn't set up l2c_id, fall back to SMT */ - if (per_cpu(cpu_l2c_id, cpu1) == BAD_APICID) + if (per_cpu_l2c_id(cpu1) == BAD_APICID) return match_smt(c, o); /* Do not match if L2 cache id does not match: */ - if (per_cpu(cpu_l2c_id, cpu1) != per_cpu(cpu_l2c_id, cpu2)) + if (per_cpu_l2c_id(cpu1) != per_cpu_l2c_id(cpu2)) return false; return topology_sane(c, o, "l2c"); @@ -568,11 +568,11 @@ static bool match_llc(struct cpuinfo_x86 bool intel_snc = id && id->driver_data; /* Do not match if we do not have a valid APICID for cpu: */ - if (per_cpu(cpu_llc_id, cpu1) == BAD_APICID) + if (per_cpu_llc_id(cpu1) == BAD_APICID) return false; /* Do not match if LLC id does not match: */ - if (per_cpu(cpu_llc_id, cpu1) != per_cpu(cpu_llc_id, cpu2)) + if (per_cpu_llc_id(cpu1) != per_cpu_llc_id(cpu2)) return false; /* From patchwork Fri Jul 28 12:12:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp391545vqg; Fri, 28 Jul 2023 05:16:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlHChdsxzrGgAuWHXfmnPaAlMQHhIq6o9MKEX53M9ce1FE6YFLVVGussV0cQ1th9nM83dWfT X-Received: by 2002:a05:6a00:1a90:b0:641:3bf8:6514 with SMTP id e16-20020a056a001a9000b006413bf86514mr2239294pfv.10.1690546612078; Fri, 28 Jul 2023 05:16:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690546612; cv=none; d=google.com; s=arc-20160816; b=c/CAjmhXHRBIzDgDE3ATYpZ4fLAZWpIXjUOOR+Duf7ESA/Fm7BTvvFXi3SdMVlQzT4 DxlBUeEM4dT70LRWYg9czy3hCFcSHNmA6FHibt0DXwsWMg7VNvRqfLjW1uI6/l6QKok4 vLA0srSvJUV/iK8gwzgb8UIld2rvsCzw9uEvLe4EwFeQIHeJGXHYTT8CMmS3jcnuQ28s cZVVCqFW6jVI5wLQBbSXonHgG0L0dwV6kl3u2mS1N9T4sckzUSj+UR7pEARwSBJSdyEX In2LUSeQANo8fJt3zgz6ghFzwD+o8CNtvwfsZH9AIkWCiNyWFi1+XBbvlht0S4ZpoTvg AXew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=0qZzNXCX/ZoHr7seeBhbra6OnJEhbVbzB3A+CK/YtPY=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=0SPAbSQ13WW5E/xjPVOW/imzEqAfwvxYfQeHg7JjngTIUjLs7S0AW460noa5lp7oZE qALuLg7FbQLToGncUd+KU/0SM19z7xEzrhufcKno1J9AzjS6PicT0uNRVgz4UUfO6jlQ 2MDK0sHDndtzLmdaKEwgpD0aXjscbeQe85DKBJwuUPa1HdYRFTguROXYA83avbjporu5 PO97wzIq2XQnAv7nCtK8kl/SIDNIrTOtxe95c50i39gN/ob2LoEpfKSTZn51mC6ZaOfR Yx2dIHpaX+3dxhsSv32YRwxSuTc3lf5OYhO9Y7UGRlXjPmkwlgKVFTlDfoCIXENd19XF UuAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aQhl26Q+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e8-20020a056a001a8800b0064d28b68d8fsi3095610pfv.94.2023.07.28.05.16.38; Fri, 28 Jul 2023 05:16:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aQhl26Q+; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235609AbjG1MNo (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235834AbjG1MM7 (ORCPT ); Fri, 28 Jul 2023 08:12:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C29DD30F9; Fri, 28 Jul 2023 05:12:57 -0700 (PDT) Message-ID: <20230728120930.281607646@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546376; 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=0qZzNXCX/ZoHr7seeBhbra6OnJEhbVbzB3A+CK/YtPY=; b=aQhl26Q+265Qq/fhYiRlN5fOjPIfdWfE4i/pA7Eu1rA4J3Wj/qwoAa3ee07MJ+9vwfl2Nk KycP3jgfVk5U60YwfcF03eQ7ADhePjr3FnYR1WEUYlelUPaTkAc1XpD6Z6/Q85hW/ElsZH Pr6xvewphzdNBOUaYVo+TbSw4tyDeDX/yJ43zcUsORDxN8y+zpRs1vmOH1IarLjai6sA1Y 6hRD5x8yoHPXh8TjwZPAZHaoQmYFR3CsYB2SM1buBYU4ULsm6nhzycxI57q7jIG+i9ln7z LA8OE/3xN5DwJamyTxVX86Y9Ozt7k5ROgyghBsFuwm4lDirsy0uSx1kAvyGDWQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546376; 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=0qZzNXCX/ZoHr7seeBhbra6OnJEhbVbzB3A+CK/YtPY=; b=D23S9P1Jgmvogv+U7+ey+IT9etYh6L1tpz90dqcqB5tNkgrHrxgR+LueL/5dsolZ4N8T1U WlujtX9edVEg1KAg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 11/38] x86/apic: Use BAD_APICID consistently; References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:56 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772666604177670926 X-GMAIL-MSGID: 1772666604177670926 APIC ID checks compare with BAD_APICID all over the place, but some initializers and some code which fiddles with global data structure use -1[U] instead. That simply cannot work at all. Fix it up and use BAD_APICID consistenly all over the place. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/acpi/boot.c | 2 +- arch/x86/kernel/apic/apic.c | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -852,7 +852,7 @@ int acpi_unmap_cpu(int cpu) set_apicid_to_node(per_cpu(x86_cpu_to_apicid, cpu), NUMA_NO_NODE); #endif - per_cpu(x86_cpu_to_apicid, cpu) = -1; + per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID; set_cpu_present(cpu, false); num_processors--; --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -70,7 +70,7 @@ unsigned int num_processors; unsigned disabled_cpus; /* Processor that is doing the boot up */ -unsigned int boot_cpu_physical_apicid __ro_after_init = -1U; +unsigned int boot_cpu_physical_apicid __ro_after_init = BAD_APICID; EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid); u8 boot_cpu_apic_version __ro_after_init; @@ -2316,9 +2316,7 @@ static int nr_logical_cpuids = 1; /* * Used to store mapping between logical CPU IDs and APIC IDs. */ -int cpuid_to_apicid[] = { - [0 ... NR_CPUS - 1] = -1, -}; +int cpuid_to_apicid[] = { [0 ... NR_CPUS - 1] = BAD_APICID, }; bool arch_match_cpu_phys_id(int cpu, u64 phys_id) { From patchwork Fri Jul 28 12:12:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp403456vqg; Fri, 28 Jul 2023 05:37:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlG5Mk/okaV8S6kvbEnm6jfbzwgGw+4zbTrRGFEC96DPp8F9J25UIToGLoMfIWNI2ChodbZ3 X-Received: by 2002:a05:6a20:938a:b0:133:8784:15f7 with SMTP id x10-20020a056a20938a00b00133878415f7mr2063045pzh.14.1690547863042; Fri, 28 Jul 2023 05:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690547863; cv=none; d=google.com; s=arc-20160816; b=Mp+Ywrp8lSgqsOulfyAQ98dXiKzKqUWoB9msHB6voZkDyX1KU77fCO6ymKGRRyI4gk Az94uHeSr2N+hl91MCRG+CyInLBaFfJvaDO6QjV0Q7upChfV1Bf0qQzRSUcjMqDDXTTY qp4FSwtw1NcfDMeG/rdhpCqgfpqVCd9rqIKQpq/2Ls67+pi6AezAewzLGy9x7J4jAu49 s+j4z5r6uf4dbX4laD9wZ28qSNYKSdw+P4CLizOmIrBkVP83AqGPOKON/S4CSgBFIWfK OmByJqST3bwHU4UFgm7a4anvW980vteyn9By85YhzPI556wICRSrtbj0QuZmdhthy+cM Eetw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=Xnwiz9iCKI1I53auLbuHOTbXvl9rMUcrLr9wRf4UYHw=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=nJ/+LXtQ8C4fuQHlOsa8Au+RfVix4ztJtB0VQz6gRvB/k/MDwvYcUnxuDTpeKT3/NM BOkjXoC84EKAypujd3L1YzYEYsi00WFzSCfBEKKtRjcv+NTk6OESh9uo3yy38N0GR6M5 vRXXiDFG9uaJINMK7D2G/8TdDfjk2NF6y0df0Yc+vCAdhBjcgaG9wuu1XBLxUpZDxK5G J1w+53rA99pNbTxKNtRMoHtwJ7CaoK1T+nwYI0dRLZ9p6ILaDlARDeADOxz9Nm4/tqEY iic/biKFDPWfpAk6soxGZ7c9oVKI9H978uR0KNlqxT/wVnUE/zxym6nyrcZL1dLPTb4m L3LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LvbYQBqh; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i184-20020a6387c1000000b00563de641cf1si2894523pge.724.2023.07.28.05.37.29; Fri, 28 Jul 2023 05:37:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=LvbYQBqh; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236247AbjG1MNm (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235929AbjG1MNA (ORCPT ); Fri, 28 Jul 2023 08:13:00 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31FDC2686; Fri, 28 Jul 2023 05:12:59 -0700 (PDT) Message-ID: <20230728120930.336948106@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546377; 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=Xnwiz9iCKI1I53auLbuHOTbXvl9rMUcrLr9wRf4UYHw=; b=LvbYQBqh7dAF6kKAjxl7XESs0XMnvTsqMsSZP0EV1lffMeyQKTIC4CbUsc8yF+urEOEuPF NmLeSFNl0OQ6Mwl/4BvBXXxt3SraXjp8O1LekLczKSo1rFf1HpA7jHHjKBnPbfCkwi5S7Z OOG+MuAZbzpvayKr2UrizrWCc5+dbFSRTFTCiSPJPyloDX7zDj4ZhSCSutn745gbB09ei6 Yjm0WZ71EArV/06E+tW3Ur5nhLRfke3HTRXRCQJ4J3CYs9oEEpyDRdTO3Ts631YA/zduVx F/L0V1p+fHyWEyBalv6hEtaROaKoM2p3V1WJ/EViLSbbm/B1WZA/i4lXLWRMYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546377; 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=Xnwiz9iCKI1I53auLbuHOTbXvl9rMUcrLr9wRf4UYHw=; b=oVSdjxtYMK03GOfqCK+pyrNwThne8WeNYDCRLs3SBbR/aENC+i0fMI9VB5annhKkjaaVuZ KqwcGDZpbRTlgfDQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 12/38] x86/apic: Use u32 for APIC IDs in global data References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:57 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772667915913522112 X-GMAIL-MSGID: 1772667915913522112 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width and fixup the most obvious usage sites of that. The APIC callbacks will be addressed separately. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/mpspec.h | 2 +- arch/x86/include/asm/processor.h | 4 ++-- arch/x86/include/asm/smp.h | 2 +- arch/x86/kernel/apic/apic.c | 12 ++++++------ arch/x86/kernel/kvm.c | 6 +++--- arch/x86/mm/numa.c | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -54,7 +54,7 @@ extern int local_apic_timer_c2_ok; extern bool apic_is_disabled; extern unsigned int lapic_timer_period; -extern int cpuid_to_apicid[]; +extern u32 cpuid_to_apicid[]; extern enum apic_intr_mode_id apic_intr_mode; enum apic_intr_mode_id { --- a/arch/x86/include/asm/mpspec.h +++ b/arch/x86/include/asm/mpspec.h @@ -37,7 +37,7 @@ extern int mp_bus_id_to_type[MAX_MP_BUSS extern DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); -extern unsigned int boot_cpu_physical_apicid; +extern u32 boot_cpu_physical_apicid; extern u8 boot_cpu_apic_version; #ifdef CONFIG_X86_LOCAL_APIC --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -691,12 +691,12 @@ extern int set_tsc_mode(unsigned int val DECLARE_PER_CPU(u64, msr_misc_features_shadow); -static inline u16 per_cpu_llc_id(unsigned int cpu) +static inline u32 per_cpu_llc_id(unsigned int cpu) { return per_cpu(cpu_info.topo.llc_id, cpu); } -static inline u16 per_cpu_l2c_id(unsigned int cpu) +static inline u32 per_cpu_l2c_id(unsigned int cpu) { return per_cpu(cpu_info.topo.l2c_id, cpu); } --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -18,7 +18,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map); -DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid); +DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_apicid); DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid); struct task_struct; --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -70,7 +70,7 @@ unsigned int num_processors; unsigned disabled_cpus; /* Processor that is doing the boot up */ -unsigned int boot_cpu_physical_apicid __ro_after_init = BAD_APICID; +u32 boot_cpu_physical_apicid __ro_after_init = BAD_APICID; EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid); u8 boot_cpu_apic_version __ro_after_init; @@ -85,7 +85,7 @@ physid_mask_t phys_cpu_present_map; * disable_cpu_apicid=, mostly used for the kdump 2nd kernel to * avoid undefined behaviour caused by sending INIT from AP to BSP. */ -static unsigned int disabled_cpu_apicid __ro_after_init = BAD_APICID; +static u32 disabled_cpu_apicid __ro_after_init = BAD_APICID; /* * This variable controls which CPUs receive external NMIs. By default, @@ -109,7 +109,7 @@ static inline bool apic_accessible(void) /* * Map cpu index to physical APIC ID */ -DEFINE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid, BAD_APICID); +DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_apicid, BAD_APICID); DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid, U32_MAX); EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid); EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_acpiid); @@ -2316,11 +2316,11 @@ static int nr_logical_cpuids = 1; /* * Used to store mapping between logical CPU IDs and APIC IDs. */ -int cpuid_to_apicid[] = { [0 ... NR_CPUS - 1] = BAD_APICID, }; +u32 cpuid_to_apicid[] = { [0 ... NR_CPUS - 1] = BAD_APICID, }; bool arch_match_cpu_phys_id(int cpu, u64 phys_id) { - return phys_id == cpuid_to_apicid[cpu]; + return phys_id == (u64)cpuid_to_apicid[cpu]; } #ifdef CONFIG_SMP @@ -2380,7 +2380,7 @@ static int allocate_logical_cpuid(int ap return nr_logical_cpuids++; } -static void cpu_update_apic(int cpu, int apicid) +static void cpu_update_apic(int cpu, u32 apicid) { #if defined(CONFIG_SMP) || defined(CONFIG_X86_64) early_per_cpu(x86_cpu_to_apicid, cpu) = apicid; --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -500,13 +500,13 @@ static bool pv_sched_yield_supported(voi static void __send_ipi_mask(const struct cpumask *mask, int vector) { unsigned long flags; - int cpu, apic_id, icr; - int min = 0, max = 0; + int cpu, min = 0, max = 0; #ifdef CONFIG_X86_64 __uint128_t ipi_bitmap = 0; #else u64 ipi_bitmap = 0; #endif + u32 apic_id, icr; long ret; if (cpumask_empty(mask)) @@ -1030,8 +1030,8 @@ arch_initcall(activate_jump_labels); /* Kick a cpu by its apicid. Used to wake up a halted vcpu */ static void kvm_kick_cpu(int cpu) { - int apicid; unsigned long flags = 0; + u32 apicid; apicid = per_cpu(x86_cpu_to_apicid, cpu); kvm_hypercall2(KVM_HC_KICK_CPU, flags, apicid); --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -56,7 +56,7 @@ s16 __apicid_to_node[MAX_LOCAL_APIC] = { int numa_cpu_node(int cpu) { - int apicid = early_per_cpu(x86_cpu_to_apicid, cpu); + u32 apicid = early_per_cpu(x86_cpu_to_apicid, cpu); if (apicid != BAD_APICID) return __apicid_to_node[apicid]; @@ -786,7 +786,7 @@ void __init init_gi_nodes(void) void __init init_cpu_to_node(void) { int cpu; - u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid); + u32 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid); BUG_ON(cpu_to_apicid == NULL); From patchwork Fri Jul 28 12:12:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp394743vqg; Fri, 28 Jul 2023 05:22:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFPqvLt5JV37OizHGedwxvhrkS1suE56x6uu5nTQJXnaE91sNdvbYFd//mU/9GPrdSVqMn X-Received: by 2002:a17:906:518c:b0:988:8be0:3077 with SMTP id y12-20020a170906518c00b009888be03077mr2261355ejk.31.1690546932399; Fri, 28 Jul 2023 05:22:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690546932; cv=none; d=google.com; s=arc-20160816; b=VPLGDz1/Hmfvcp5ZxRoL4GWA+2ukYKpevGCtyKoJtrQgoKf3apC3XvFNflI28aMCm7 kRqsX42S4bQWHoUJ67on9tkgAwuxCHMWBJgP345JcLp2Sj88BiOz2OKLE1FaC+jrxyRG xwJck1/+Z1ZAuxG76S+5TrKc4uInB0LG2fp20OB2toWV6M/ecvdSLarr5Y5LO1q6pFlD wv/cstT2q0Bf25oPP7rbS8g74c0cWxQhWas/VMSU6fcszwv+Ws/kqtnGLlTo7FfsNVIX p0THLTpXKDwxDEXvRRSynXl+jIo+SnmWa3lTSb8mcKPPXTX6wSnRY0EyEwsQNpHWzYe/ YBqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=ZpujbDnKtKDSL5RBSdIZ4PFgwYRWpF+NGFguVXH8Iqo=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=IbgfwUm0e/7qnqGKy3pkkdCT8ONai5wBRSduuV2hmwM1chGdQAK9nVDklADgxH+SO3 xuMkQI6DPjxAziHL0jO2cSR88wQTLFOtYyNb90+1dTC4syWCyu6rP/P+zsHH7haiPmSW URzLMVM0sBt3fJ5+iwdJyS1j6yT4gXlc3OMtw2VLHmuyFU67Qp/y1JhRYHChMkVJhoVX LOHoUVRN2N6NFLl/u49ogHdiTObcoX8IgOtX57u5ztQE+g6FdFFtqwbRAcvq3NkYHxJd 5NiRS8joUQQr4+/DrFc1FX4IHQ5fcAXz6ecs/GTXv7Q72hJxVsxxK1bRUUW/wlYiw6Sx JLtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Dt4c3GI/"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a17090686cd00b0098e42bef73asi2598274ejy.98.2023.07.28.05.21.48; Fri, 28 Jul 2023 05:22:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Dt4c3GI/"; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234903AbjG1MNh (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235989AbjG1MNB (ORCPT ); Fri, 28 Jul 2023 08:13:01 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47505268B; Fri, 28 Jul 2023 05:13:00 -0700 (PDT) Message-ID: <20230728120930.393454382@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546378; 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=ZpujbDnKtKDSL5RBSdIZ4PFgwYRWpF+NGFguVXH8Iqo=; b=Dt4c3GI/uH1CtRHMqAx7aMPQt/hsPsr7oslzBVtQb7/eJfTlHvgsZfZiJMhpPq2nDWv11A m5ZWvdthqFFYZXJQHY4+Q/nw8MHNOn446oc1/gl+O8wdI+FdiW0RptTzoORfyCweWm4c5b gR23ufjz+akCv09zIlwTCNsofDxJTU1nmulM62txMTqnPnqAXJPk8SOqQgN8XPSuWPaOcg LB21WpfL5SfMv7nkVWwFTc92V/nThUhncHFFcol+Rvo+IX0mRcLBG7sH+IO+ij9HvSTPKK xAogulpBnq4G2EXIOQueKFkBZMBlHag03OCObWbXFiipBoIdzO3FO4LrrJthrw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546378; 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=ZpujbDnKtKDSL5RBSdIZ4PFgwYRWpF+NGFguVXH8Iqo=; b=sa9a1TbpxDEC8tqSsyc8C8ruLGPDkoFGT/OsNRO2pqdgQKae16rFSAk3Ew3DYwcp6BghN6 SsqcUTf4I0GEAeCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 13/38] x86/apic: Use u32 for check_apicid_used() References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:12:58 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772666940494200907 X-GMAIL-MSGID: 1772666940494200907 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width and move the default implementation to local.h as there are no users outside the apic directory. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/apic.h | 3 +-- arch/x86/kernel/apic/apic_common.c | 2 +- arch/x86/kernel/apic/apic_flat_64.c | 2 -- arch/x86/kernel/apic/apic_noop.c | 2 ++ arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 1 + 6 files changed, 6 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -292,7 +292,7 @@ struct apic { int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); bool (*apic_id_registered)(void); - bool (*check_apicid_used)(physid_mask_t *map, int apicid); + bool (*check_apicid_used)(physid_mask_t *map, u32 apicid); void (*init_apic_ldr)(void); void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap); int (*cpu_present_to_apicid)(int mps_cpu); @@ -538,7 +538,6 @@ extern int default_apic_id_valid(u32 api extern u32 apic_default_calc_apicid(unsigned int cpu); extern u32 apic_flat_calc_apicid(unsigned int cpu); -extern bool default_check_apicid_used(physid_mask_t *map, int apicid); extern void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap); extern int default_cpu_present_to_apicid(int mps_cpu); --- a/arch/x86/kernel/apic/apic_common.c +++ b/arch/x86/kernel/apic/apic_common.c @@ -18,7 +18,7 @@ u32 apic_flat_calc_apicid(unsigned int c return 1U << cpu; } -bool default_check_apicid_used(physid_mask_t *map, int apicid) +bool default_check_apicid_used(physid_mask_t *map, u32 apicid) { return physid_isset(apicid, *map); } --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -158,8 +158,6 @@ static struct apic apic_physflat __ro_af .disable_esr = 0, - .check_apicid_used = NULL, - .ioapic_phys_id_map = NULL, .cpu_present_to_apicid = default_cpu_present_to_apicid, .phys_pkg_id = flat_phys_pkg_id, --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -18,6 +18,8 @@ #include +#include "local.h" + static void noop_send_IPI(int cpu, int vector) { } static void noop_send_IPI_mask(const struct cpumask *cpumask, int vector) { } static void noop_send_IPI_mask_allbutself(const struct cpumask *cpumask, int vector) { } --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -18,7 +18,7 @@ static unsigned bigsmp_get_apic_id(unsig return (x >> 24) & 0xFF; } -static bool bigsmp_check_apicid_used(physid_mask_t *map, int apicid) +static bool bigsmp_check_apicid_used(physid_mask_t *map, u32 apicid) { return false; } --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -64,6 +64,7 @@ void default_send_IPI_all(int vector); void default_send_IPI_self(int vector); bool default_apic_id_registered(void); +bool default_check_apicid_used(physid_mask_t *map, u32 apicid); #ifdef CONFIG_X86_32 void default_send_IPI_mask_sequence_logical(const struct cpumask *mask, int vector); From patchwork Fri Jul 28 12:13:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp404829vqg; Fri, 28 Jul 2023 05:40:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlGhIKVWAwGTQJg0gDuHg0ZmA/cuVF6zeFeMGjvAJ1xdY31NgPu2KMt8ky2SMpBp/2QIe77w X-Received: by 2002:a17:906:5a53:b0:993:e809:b9ff with SMTP id my19-20020a1709065a5300b00993e809b9ffmr1841568ejc.21.1690548012619; Fri, 28 Jul 2023 05:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548012; cv=none; d=google.com; s=arc-20160816; b=OD4MgQoLVS42p5BAdW439ZWLde5NscNpvKL6qiAB5pX46I/8c+vlHMLavu9USe5T46 JxEl1LasyaYsQtZtSs2irZoayArONerZjJT7AC7JpjQ5pTXDU3gLE14RuCAimGt8onpH 6sF2b5Sz2c/wUfSESs5qCIj2FxCA1tUjDIwRL/UCR00OQEGmk6h/TrC/kDGwDLD1pFrU 8AbD9fvW0OHPP/rIO8Tzg2QoUkeX3w8HDIVZskJH7Kv4hGCnVL2h6r933us+wiAopprR rWcbnGQ+ivuV0a1BPUuKMDDd0oue3sCzaNfgwrNvhc5lu2lb8irDojTguccQX51I0L0o lOiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=bDtvqTv62bVKXWY5/pM9aukhZJLaTDTi9tslIEVsSDg=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=yiobUrADW144V3oTttWFT10Z7lTMnHiDykydFY1eCLXEy3SezTWRXauAKHVx1+P8Fs mecU64cSWECh8gDgE5MsM2mZ8fpnmc4wszP5sXzorKJx4aBKJ9SPGFefbNqe6+Xw2ksP 1HNLFISfwRQIQ0haEdV3cJWASkQbplff1NfJ4g6H7Hgh+X/ZbLHrJrsKvmij3VuaEQTn IV1BnI1XjDNbuJGRmjOwZLMuHz3NpPy56vMRjfWzodJ9TraUyUztsXpi5htdefTaf56c XIp7Yo9/vU6gKwiAXjvBKTTLCdNtD1ih/4D3C4V0i6J16wgqeLiOQN6IGvF6xO/BPt+N /oZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2CajffM9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ggSyxMBK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a1709065a8c00b00988b6ffa850si2495412ejq.1028.2023.07.28.05.39.48; Fri, 28 Jul 2023 05:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2CajffM9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=ggSyxMBK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236467AbjG1MNv (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235193AbjG1MNE (ORCPT ); Fri, 28 Jul 2023 08:13:04 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AFCB30F7; Fri, 28 Jul 2023 05:13:01 -0700 (PDT) Message-ID: <20230728120930.450147524@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546380; 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=bDtvqTv62bVKXWY5/pM9aukhZJLaTDTi9tslIEVsSDg=; b=2CajffM9SENGzZhMNSYX6kkRu6yzEQ2F4BHD1gC/NvYnBJzFslLV7fuINmE60RQOjmrSEU QTpWEAhuAIZkil7THXBjVUPw91DaIRGGXJLg8JY0VQMJOka717pHYUbJNaj4M3RV/AaNsm zRsPpJPvny7abdNqlkfKOl/JrBCDnwSdF1tv6m4nFjI+XXkrFa9FejfAP7XcuwRy0VvDgu rA8rBtiqAJWspRJAJgWaOFbHz24vuncP9Cxl3L+RMyXODKRtTDZBU9drEL7X+p0v9CQCFh lj2USUYi9y4lR8+7vgmdYxRAByU79+sY5cjJ15nNjDiOq/pRFaNEEDCei0roYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546380; 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=bDtvqTv62bVKXWY5/pM9aukhZJLaTDTi9tslIEVsSDg=; b=ggSyxMBKI2zaSM1/Vxwpad0Cn+kW/eehXKJO3Fwx4ARr3j5J/ZG5nIwDA+J60rM2kWU5tt RjQbP3L7cikX/oAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 14/38] x86/apic: Use u32 for cpu_present_to_apicid() References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:00 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668073116789242 X-GMAIL-MSGID: 1772668073116789242 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width and fixup a few related usage sites for consistency sake. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/apic.h | 4 ++-- arch/x86/kernel/apic/apic_common.c | 2 +- arch/x86/kernel/cpu/common.c | 3 ++- arch/x86/kernel/smpboot.c | 10 +++++----- arch/x86/xen/apic.c | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -295,7 +295,7 @@ struct apic { bool (*check_apicid_used)(physid_mask_t *map, u32 apicid); void (*init_apic_ldr)(void); void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap); - int (*cpu_present_to_apicid)(int mps_cpu); + u32 (*cpu_present_to_apicid)(int mps_cpu); int (*phys_pkg_id)(int cpuid_apic, int index_msb); u32 (*get_apic_id)(unsigned long x); @@ -539,7 +539,7 @@ extern u32 apic_default_calc_apicid(unsi extern u32 apic_flat_calc_apicid(unsigned int cpu); extern void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap); -extern int default_cpu_present_to_apicid(int mps_cpu); +extern u32 default_cpu_present_to_apicid(int mps_cpu); #else /* CONFIG_X86_LOCAL_APIC */ --- a/arch/x86/kernel/apic/apic_common.c +++ b/arch/x86/kernel/apic/apic_common.c @@ -28,7 +28,7 @@ void default_ioapic_phys_id_map(physid_m *retmap = *phys_map; } -int default_cpu_present_to_apicid(int mps_cpu) +u32 default_cpu_present_to_apicid(int mps_cpu) { if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu)) return (int)per_cpu(x86_cpu_to_apicid, mps_cpu); --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1747,7 +1747,8 @@ static void generic_identify(struct cpui static void validate_apic_and_package_id(struct cpuinfo_x86 *c) { #ifdef CONFIG_SMP - unsigned int apicid, cpu = smp_processor_id(); + unsigned int cpu = smp_processor_id(); + u32 apicid; apicid = apic->cpu_present_to_apicid(cpu); --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -816,7 +816,7 @@ static void __init smp_quirk_init_udelay /* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static void send_init_sequence(int phys_apicid) +static void send_init_sequence(u32 phys_apicid) { int maxlvt = lapic_get_maxlvt(); @@ -842,7 +842,7 @@ static void send_init_sequence(int phys_ /* * Wake up AP by INIT, INIT, STARTUP sequence. */ -static int wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip) +static int wakeup_secondary_cpu_via_init(u32 phys_apicid, unsigned long start_eip) { unsigned long send_status = 0, accept_status = 0; int num_starts, j, maxlvt; @@ -989,7 +989,7 @@ int common_cpu_up(unsigned int cpu, stru * Returns zero if startup was successfully sent, else error code from * ->wakeup_secondary_cpu. */ -static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle) +static int do_boot_cpu(u32 apicid, int cpu, struct task_struct *idle) { unsigned long start_ip = real_mode_header->trampoline_start; int ret; @@ -1057,7 +1057,7 @@ static int do_boot_cpu(int apicid, int c int native_kick_ap(unsigned int cpu, struct task_struct *tidle) { - int apicid = apic->cpu_present_to_apicid(cpu); + u32 apicid = apic->cpu_present_to_apicid(cpu); int err; lockdep_assert_irqs_enabled(); @@ -1250,7 +1250,7 @@ void arch_thaw_secondary_cpus_end(void) bool smp_park_other_cpus_in_init(void) { unsigned int cpu, this_cpu = smp_processor_id(); - unsigned int apicid; + u32 apicid; if (apic->wakeup_secondary_cpu_64 || apic->wakeup_secondary_cpu) return false; --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -115,7 +115,7 @@ static int xen_phys_pkg_id(int initial_a return initial_apic_id >> index_msb; } -static int xen_cpu_present_to_apicid(int cpu) +static u32 xen_cpu_present_to_apicid(int cpu) { if (cpu_present(cpu)) return cpu_data(cpu).topo.apicid; From patchwork Fri Jul 28 12:13:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp433499vqg; Fri, 28 Jul 2023 06:26:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlGX1rqzJXzKRMXx7l3P8eKNGcP3PFkINuBlkawMgk/yX9UNnNk+0M5s43HMWutvWwacjwdw X-Received: by 2002:a05:6a00:301b:b0:686:b732:8792 with SMTP id ay27-20020a056a00301b00b00686b7328792mr2160552pfb.8.1690550785108; Fri, 28 Jul 2023 06:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550785; cv=none; d=google.com; s=arc-20160816; b=w3xjg5q56r62cDdtnZqRd984W7sNnNHEQz5iYEOy2dJYkr2DrOffE6OjZr+kiGd4Nt /V7IkN2x02ezI1B5z0adyMW1aVx5yTYnRuFsPoupsZN15nIjo2w/QchYxfUwC1IpsvKE L8OfvLggzJlCCa5lDS7Gj5H4U3WlNQLXl867LN/IzrtxlFKZ2DfJ0N508giJ1GOfJ78I BU8xuOozE04yPO42jVHcNrM++vSMpJSfeK39gKc6nWzncNgN45LaABwm/33FyodJefN5 UP9CCdrSDRaU0RwfbaFBGb0D08awmTnssTPmznSDIUg1N2IPF3jH4iGSmUXQRC0QZkiV iZqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=W4xJH6LNgggvbfJwkBitKsfr5A0Xep6DiT5K2fgkXGw=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=xrVFwF5AYXqJweei2rZpmYoLDD7EX1TFlPp8NdxBvsoGvNwBOgTWGimzZNhVdp+Lw3 Wr0hBil5hNPhUUdadILMakWdpIsyGyFRbMXuXDetqEg7aAR8bfELPhAh4NsJTqoQqP1S yH7AbzMWnszUf4BwxG3OtQvTQ2qkfE7FFecFCrtxOze1KZw0+Gj+x9XVQENlZvcs4NVS 1EvCyy5OPXdVOyWCJpISx9HLMGBEZKPrvoLWbz85PxZ9ieQl+FMvLPFq0GB0Bh3lQIe1 LbvNkLnplTqa9hYBzqm2+e2kRhdxRF6uEzMD8SHf9cekW/14JaqLFKRYe9lvVDV67+rc cUww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kbqWVwwO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=4QoM3dLW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cj7-20020a056a00298700b00675807330basi2156333pfb.206.2023.07.28.06.26.04; Fri, 28 Jul 2023 06:26:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kbqWVwwO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=4QoM3dLW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236489AbjG1MN5 (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235681AbjG1MNP (ORCPT ); Fri, 28 Jul 2023 08:13:15 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA7A130F9; Fri, 28 Jul 2023 05:13:02 -0700 (PDT) Message-ID: <20230728120930.507111034@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546381; 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=W4xJH6LNgggvbfJwkBitKsfr5A0Xep6DiT5K2fgkXGw=; b=kbqWVwwOzXpAft31szPAljDVPfjIblzxpOgU/0ALd58Z90/UObD4LkwKM6676TUNaM67nE 5DTSKxXu78WS+4TshVrx0yYTQEJhwQLUHHGK9t1MdYYD8CMxzbt/93Ztj1YlJSnE1xs5hT aILVnUgoQfxwyJ31EHTcp/bJnQw1YKf7PCMC59WpEoFuG3ufy0f9+X8fADW50M04hNRyEG w982dqy480CJeOGkv7iG021Cs93aDWg1PEOeMdHVm13WfHiNBZguunYkK6iv1nO9/UCX3Z +MHOilHVZc87CGNlH/0P01sYa9HNTVj+DMrTdPhf8bAW5+Jua86qITMxN5Q3uA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546381; 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=W4xJH6LNgggvbfJwkBitKsfr5A0Xep6DiT5K2fgkXGw=; b=4QoM3dLWvdVm6eqIf2FsVieDCiPNIhPXjfsQvnvU+Q5oSUg4SioE9lAzulimAeUTU8DYE8 kMu+pOwRfHgVZUAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 15/38] x86/apic: Use u32 for phys_pkg_id() References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:01 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772670980269970973 X-GMAIL-MSGID: 1772670980269970973 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width even if that callback going to be removed soonish. Signed-off-by: Thomas Gleixner Reviewed-by: Steve Wahl --- arch/x86/include/asm/apic.h | 2 +- arch/x86/kernel/apic/apic_flat_64.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 2 +- arch/x86/kernel/apic/probe_32.c | 2 +- arch/x86/kernel/apic/x2apic_phys.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/vsmp_64.c | 2 +- arch/x86/xen/apic.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -296,7 +296,7 @@ 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); - int (*phys_pkg_id)(int cpuid_apic, int index_msb); + u32 (*phys_pkg_id)(u32 cpuid_apic, int index_msb); u32 (*get_apic_id)(unsigned long x); u32 (*set_apic_id)(unsigned int id); --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -66,7 +66,7 @@ static u32 set_apic_id(unsigned int id) return (id & 0xFF) << 24; } -static int flat_phys_pkg_id(int initial_apic_id, int index_msb) +static u32 flat_phys_pkg_id(u32 initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; } --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -29,7 +29,7 @@ static void noop_send_IPI_self(int vecto static void noop_apic_icr_write(u32 low, u32 id) { } static int noop_wakeup_secondary_cpu(int apicid, unsigned long start_eip) { return -1; } static u64 noop_apic_icr_read(void) { return 0; } -static int noop_phys_pkg_id(int cpuid_apic, int index_msb) { return 0; } +static u32 noop_phys_pkg_id(u32 cpuid_apic, int index_msb) { return 0; } static unsigned int noop_get_apic_id(unsigned long x) { return 0; } static void noop_apic_eoi(void) { } --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -56,7 +56,7 @@ static u32 numachip2_set_apic_id(unsigne return id << 24; } -static int numachip_phys_pkg_id(int initial_apic_id, int index_msb) +static u32 numachip_phys_pkg_id(u32 initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; } --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -29,7 +29,7 @@ static void bigsmp_ioapic_phys_id_map(ph physids_promote(0xFFL, retmap); } -static int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb) +static u32 bigsmp_phys_pkg_id(u32 cpuid_apic, int index_msb) { return cpuid_apic >> index_msb; } --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -17,7 +17,7 @@ void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest); unsigned int x2apic_get_apic_id(unsigned long id); u32 x2apic_set_apic_id(unsigned int id); -int x2apic_phys_pkg_id(int initial_apicid, int index_msb); +u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb); 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,7 +18,7 @@ #include "local.h" -static int default_phys_pkg_id(int cpuid_apic, int index_msb) +static u32 default_phys_pkg_id(u32 cpuid_apic, int index_msb) { return cpuid_apic >> index_msb; } --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -134,7 +134,7 @@ u32 x2apic_set_apic_id(unsigned int id) return id; } -int x2apic_phys_pkg_id(int initial_apicid, int index_msb) +u32 x2apic_phys_pkg_id(u32 initial_apicid, int index_msb) { return initial_apicid >> index_msb; } --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -790,7 +790,7 @@ static unsigned int uv_read_apic_id(void return x2apic_get_apic_id(apic_read(APIC_ID)); } -static int uv_phys_pkg_id(int initial_apicid, int index_msb) +static u32 uv_phys_pkg_id(u32 initial_apicid, int index_msb) { return uv_read_apic_id() >> index_msb; } --- a/arch/x86/kernel/vsmp_64.c +++ b/arch/x86/kernel/vsmp_64.c @@ -127,7 +127,7 @@ static void __init vsmp_cap_cpus(void) #endif } -static int apicid_phys_pkg_id(int initial_apic_id, int index_msb) +static u32 apicid_phys_pkg_id(u32 initial_apic_id, int index_msb) { return read_apic_id() >> index_msb; } --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -110,7 +110,7 @@ static int xen_madt_oem_check(char *oem_ return xen_pv_domain(); } -static int xen_phys_pkg_id(int initial_apic_id, int index_msb) +static u32 xen_phys_pkg_id(u32 initial_apic_id, int index_msb) { return initial_apic_id >> index_msb; } From patchwork Fri Jul 28 12:13:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127637 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp433661vqg; Fri, 28 Jul 2023 06:26:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlE82CGpv7yDs5sAFZnPzPWHUynXhdhEePygvenuzxQfD9lIhO5XEknFmluULGab6vbeoBtO X-Received: by 2002:a05:6a00:996:b0:682:54b9:1093 with SMTP id u22-20020a056a00099600b0068254b91093mr2658877pfg.15.1690550801064; Fri, 28 Jul 2023 06:26:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550801; cv=none; d=google.com; s=arc-20160816; b=TOmKUjlozgSm5jIG11IjahszMCyiC0+AQ7yHRYCK4UBrp/2pqVc2YHVY5LzHbgig+m V360wMibVGSh6Mt3VSfZ5tpuMjx4m+VhOVofdEyk4r8WzdaeIe+8Pvw12V0kAOlddIBY pqWFfD3L13G+s2pADxhffhu+4/guMokUXpuaduXv92hHUqKJNzwDALUiFVjs3nerxSbZ MhFeyvD5Mf3n+DOM4GrY4l9/w0/aXAhnd8QROGLAw5oVJSp/8/eKEvzbxlp+hcLzkadQ VItb2cERjTbUnn2R+TL+Mzj1nhC2EZe6zeEC/wNBIQPwbivnlIQUuhHMnXh5pqj/24jc s/Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=N1azWL9rFTheZgbP+psN/3Z4a3oFTh1DV0QsrK11aoI=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=dzhjz65OJtli7yjuAUG4kjVcxBE93RkbwBQ7TyNEPi7f8a15I70pbMwSBXaOUoI9oK 5ANnkAgc8BupTiKDDiZ+fF/twhQyPFweHKWwFkrE5yD9HODLM0pKKmKFCOdKTAOQ7qVj 2OmI4ndsyp6S5XJvmWeUuB7CdvkfRNIMAWVRQZdvNasDxoJH7i5ajo0VdaFRnifzJgsv cpoGjamjMYMTiVVSdCh6v0pSCyQ0AsJy5zMKcmfyOv19I1kdKmxMs+fcoHLvZWyB0oKP mDWmFjwf7KAHvKgMlWKxJMAvSDZoGlc0FpRPPz/JVjU8OVHixQyqnNVP8nDZkHUwIpUW XWFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jvnEp0RU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="mYKn/dGx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a6540cb000000b005640a32d25esi2363016pgp.517.2023.07.28.06.26.25; Fri, 28 Jul 2023 06:26:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=jvnEp0RU; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="mYKn/dGx"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235824AbjG1MN7 (ORCPT + 99 others); Fri, 28 Jul 2023 08:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235700AbjG1MNP (ORCPT ); Fri, 28 Jul 2023 08:13:15 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 142053A8C; Fri, 28 Jul 2023 05:13:04 -0700 (PDT) Message-ID: <20230728120930.562193563@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546382; 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=N1azWL9rFTheZgbP+psN/3Z4a3oFTh1DV0QsrK11aoI=; b=jvnEp0RUySTYsQMDRy0hadFx25NRrqyNFc3TdF9Srco0GwFKdbOnkto+P1xmQj95ii21SW Sv3pHOBAtBHK5ZbplBmc5Arg3lzCws+wyBNzrP3aRYLPzFKB2zF8CZLbo4h4HLiN4hn45Y BMVnp9xqNWJZM/Q+XjuAcRVqH+t1AfkboiSnasuKVEElDOMnyZzh5HrPnsQXGLv6ShiJBi ZIJ8bcbdBDlWgPUvXQUDKTP4TAxbWQrUf4OhPXDwYOGN3rkizDZcisVEEVEh0TSTyJm07y aq6deJSoN+M20y3YXXOGi+KtuQkLHT/YsLzbWVTnISkpoAWahGiKsJapxKyEsw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546382; 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=N1azWL9rFTheZgbP+psN/3Z4a3oFTh1DV0QsrK11aoI=; b=mYKn/dGxle2YzslkUTlllFvelg4ik+cXxsknBAkfJcsXGgF5rHVWziOxts7DYO2mbCI+hK TF5tHiKxRFqDnTDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 16/38] x86/apic: Use u32 for [gs]et_apic_id() References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:02 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772670996894025682 X-GMAIL-MSGID: 1772670996894025682 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width. Signed-off-by: Thomas Gleixner Reviewed-by: Steve Wahl --- arch/x86/include/asm/apic.h | 14 ++------------ arch/x86/kernel/apic/apic_flat_64.c | 4 ++-- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 8 ++++---- arch/x86/kernel/apic/bigsmp_32.c | 2 +- arch/x86/kernel/apic/local.h | 4 ++-- arch/x86/kernel/apic/probe_32.c | 10 ++++++++++ arch/x86/kernel/apic/x2apic_phys.c | 4 ++-- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/xen/apic.c | 4 ++-- 10 files changed, 27 insertions(+), 27 deletions(-) --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -298,8 +298,8 @@ struct apic { u32 (*cpu_present_to_apicid)(int mps_cpu); u32 (*phys_pkg_id)(u32 cpuid_apic, int index_msb); - u32 (*get_apic_id)(unsigned long x); - u32 (*set_apic_id)(unsigned int id); + u32 (*get_apic_id)(u32 id); + u32 (*set_apic_id)(u32 apicid); /* wakeup_secondary_cpu */ int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip); @@ -493,16 +493,6 @@ static inline bool lapic_vector_set_in_i return !!(irr & (1U << (vector % 32))); } -static inline unsigned default_get_apic_id(unsigned long x) -{ - unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR)); - - if (APIC_XAPIC(ver) || boot_cpu_has(X86_FEATURE_EXTD_APICID)) - return (x >> 24) & 0xFF; - else - return (x >> 24) & 0x0F; -} - /* * Warm reset vector position: */ --- a/arch/x86/kernel/apic/apic_flat_64.c +++ b/arch/x86/kernel/apic/apic_flat_64.c @@ -56,12 +56,12 @@ flat_send_IPI_mask_allbutself(const stru _flat_send_IPI_mask(mask, vector); } -static unsigned int flat_get_apic_id(unsigned long x) +static u32 flat_get_apic_id(u32 x) { return (x >> 24) & 0xFF; } -static u32 set_apic_id(unsigned int id) +static u32 set_apic_id(u32 id) { return (id & 0xFF) << 24; } --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -30,7 +30,7 @@ static void noop_apic_icr_write(u32 low, static int noop_wakeup_secondary_cpu(int 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 unsigned int noop_get_apic_id(unsigned long x) { return 0; } +static u32 noop_get_apic_id(u32 apicid) { return 0; } static void noop_apic_eoi(void) { } static u32 noop_apic_read(u32 reg) --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -25,7 +25,7 @@ static const struct apic apic_numachip1; static const struct apic apic_numachip2; static void (*numachip_apic_icr_write)(int apicid, unsigned int val) __read_mostly; -static unsigned int numachip1_get_apic_id(unsigned long x) +static u32 numachip1_get_apic_id(u32 x) { unsigned long value; unsigned int id = (x >> 24) & 0xff; @@ -38,12 +38,12 @@ static unsigned int numachip1_get_apic_i return id; } -static u32 numachip1_set_apic_id(unsigned int id) +static u32 numachip1_set_apic_id(u32 id) { return (id & 0xff) << 24; } -static unsigned int numachip2_get_apic_id(unsigned long x) +static u32 numachip2_get_apic_id(u32 x) { u64 mcfg; @@ -51,7 +51,7 @@ static unsigned int numachip2_get_apic_i return ((mcfg >> (28 - 8)) & 0xfff00) | (x >> 24); } -static u32 numachip2_set_apic_id(unsigned int id) +static u32 numachip2_set_apic_id(u32 id) { return id << 24; } --- a/arch/x86/kernel/apic/bigsmp_32.c +++ b/arch/x86/kernel/apic/bigsmp_32.c @@ -13,7 +13,7 @@ #include "local.h" -static unsigned bigsmp_get_apic_id(unsigned long x) +static u32 bigsmp_get_apic_id(u32 x) { return (x >> 24) & 0xFF; } --- a/arch/x86/kernel/apic/local.h +++ b/arch/x86/kernel/apic/local.h @@ -15,8 +15,8 @@ /* X2APIC */ void __x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest); -unsigned int x2apic_get_apic_id(unsigned long id); -u32 x2apic_set_apic_id(unsigned int id); +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); void x2apic_send_IPI_all(int vector); --- a/arch/x86/kernel/apic/probe_32.c +++ b/arch/x86/kernel/apic/probe_32.c @@ -23,6 +23,16 @@ static u32 default_phys_pkg_id(u32 cpuid return cpuid_apic >> index_msb; } +static u32 default_get_apic_id(u32 x) +{ + unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR)); + + if (APIC_XAPIC(ver) || boot_cpu_has(X86_FEATURE_EXTD_APICID)) + return (x >> 24) & 0xFF; + else + return (x >> 24) & 0x0F; +} + /* should be called last. */ static int probe_default(void) { --- a/arch/x86/kernel/apic/x2apic_phys.c +++ b/arch/x86/kernel/apic/x2apic_phys.c @@ -124,12 +124,12 @@ static int x2apic_phys_probe(void) return apic == &apic_x2apic_phys; } -unsigned int x2apic_get_apic_id(unsigned long id) +u32 x2apic_get_apic_id(u32 id) { return id; } -u32 x2apic_set_apic_id(unsigned int id) +u32 x2apic_set_apic_id(u32 id) { return id; } --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -780,7 +780,7 @@ static void uv_send_IPI_all(int vector) uv_send_IPI_mask(cpu_online_mask, vector); } -static u32 set_apic_id(unsigned int id) +static u32 set_apic_id(u32 id) { return id; } --- a/arch/x86/xen/apic.c +++ b/arch/x86/xen/apic.c @@ -33,13 +33,13 @@ static unsigned int xen_io_apic_read(uns return 0xfd; } -static u32 xen_set_apic_id(unsigned int x) +static u32 xen_set_apic_id(u32 x) { WARN_ON(1); return x; } -static unsigned int xen_get_apic_id(unsigned long x) +static u32 xen_get_apic_id(u32 x) { return ((x)>>24) & 0xFFu; } From patchwork Fri Jul 28 12:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp503137vqg; Fri, 28 Jul 2023 08:13:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlEvqa5MNQJauh5qiMbpm5cTAAxle5MFFDtnp/Ib1pch3YqbuOXFfYsn3Nl6JTo/VGW9BqUE X-Received: by 2002:a05:6a20:c1:b0:12e:98a3:77b7 with SMTP id 1-20020a056a2000c100b0012e98a377b7mr1606448pzh.59.1690557199494; Fri, 28 Jul 2023 08:13:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690557199; cv=none; d=google.com; s=arc-20160816; b=J8GdlZmYcny71fEztsuZDI9yEESD1gg1ww0IX/fHvyPTYOf80FeIqFKyL8cyK6LPPO KgR0/q6TanHQAy8Ft5qbFVIR0ph6EN1PSVwlnOc3zQ5gfRx0RwJA5Eokc/Jg0gML98Vv ELotW7bTaYr74CzpgQxa9vAg6iySTcF9lkxtDBIhveOdA8++hkp4VyTUcS2PuBtiFCOS LyvsT+EBl9wia0XFcTeEJKBvLG7ipmGoXU8ktNViz8Cg5U/bC3i1WzX05ZxJm50pucNl G86fL0v90gH1Pt7zPnj29F7smpjaWkjTctV+2TNx0D6HqKuQRDTbrrVJCXt7K+XsnWNj vYdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=5gVNK3rCq4noBF0xg9HsQLWamUWdjKHKucBFvU6ybvE=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=1KQZRwKLTSewr68jqPPkkFLlbA3v0RFwOE3o0mDNYmMj520ByCf1EzYMEj1/b7Xw4q LxR7bwu4X8a1UtX7JauqkWTub0xQ4SMSutyZ2eGENv3gpOZSkmLPuhfMvOmy0KDR8RsE ha6+Q3Am55HQ1703HRfCZvq6LooArVej689bE/NEmmxuZEvSaN5bNZhSYTOYzzOFAK39 w1une/m91iMrOFZ5nbkmtSR1yua63cVHqOtyjrP6+1uQO5KqjaqZkcjs8+oCqSuMUTaM ztzBmxBH7WVsb7MDfZRDt9Umo+ePs4XIXv6+Vii3IfLiNUXowopJp/GwdUalrDBy3arB E74Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=G2xt2VMQ; dkim=neutral (no key) header.i=@linutronix.de header.b=QG238KyZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 16-20020a631650000000b00563b0cbe820si3061540pgw.688.2023.07.28.08.12.57; Fri, 28 Jul 2023 08:13:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=G2xt2VMQ; dkim=neutral (no key) header.i=@linutronix.de header.b=QG238KyZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234437AbjG1MOF (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236053AbjG1MNX (ORCPT ); Fri, 28 Jul 2023 08:13:23 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A83F63C29; Fri, 28 Jul 2023 05:13:05 -0700 (PDT) Message-ID: <20230728120930.617454900@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546384; 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=5gVNK3rCq4noBF0xg9HsQLWamUWdjKHKucBFvU6ybvE=; b=G2xt2VMQ0POlA92nedDC+wu1TLMwvF68Xl6/B0JqQ001JqNPuPvQe7iJuLNQ/l5TNyo6bs KZhHwDYIdT1vr9BD4voWtUWuqEbZnjtKSh9JMC1MazsiwrXZlawWVaT+JWffgsnlOcJ/Lr bBY6sETe22ClCa0KXAFufp1hE3KM+BAISyalVByMB368H16IfhBzVoAq/t4nr1W01C0nSC z0F8AwGuN/i1F1LjD6YZ0yuWxlJ9rjxXyjtyxLaOz2VGZRYvh/K0/5fij1CAsclvF4oo7W 8xMFamlpue6kPqSjXw/8WmBJ6X9HBM/IgZmyEyFIeUgjoORRYFnVEsXVx2yvvg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546384; 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=5gVNK3rCq4noBF0xg9HsQLWamUWdjKHKucBFvU6ybvE=; b=QG238KyZZUyzVmtipu84Nj0/Jegu+8qNBqa2QpsmaNZEQIx29D0ntPxP0CO0Gzd42F6QYP 4G4SB4vTFr5F1kCw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 17/38] x86/apic: Use u32 for wakeup_secondary_cpu[_64]() References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:03 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772677706180311295 X-GMAIL-MSGID: 1772677706180311295 APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width. Signed-off-by: Thomas Gleixner Reviewed-by: Steve Wahl --- arch/x86/hyperv/hv_vtl.c | 2 +- arch/x86/include/asm/apic.h | 8 ++++---- arch/x86/kernel/acpi/boot.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/apic/x2apic_uv_x.c | 2 +- arch/x86/kernel/sev.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -192,7 +192,7 @@ static int hv_vtl_apicid_to_vp_id(u32 ap return ret; } -static int hv_vtl_wakeup_secondary_cpu(int apicid, unsigned long start_eip) +static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip) { int vp_id; --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -302,9 +302,9 @@ struct apic { u32 (*set_apic_id)(u32 apicid); /* wakeup_secondary_cpu */ - int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip); + int (*wakeup_secondary_cpu)(u32 apicid, unsigned long start_eip); /* wakeup secondary CPU using 64-bit wakeup point */ - int (*wakeup_secondary_cpu_64)(int apicid, unsigned long start_eip); + int (*wakeup_secondary_cpu_64)(u32 apicid, unsigned long start_eip); char *name; }; @@ -322,8 +322,8 @@ struct apic_override { void (*send_IPI_self)(int vector); u64 (*icr_read)(void); void (*icr_write)(u32 low, u32 high); - int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip); - int (*wakeup_secondary_cpu_64)(int apicid, unsigned long start_eip); + int (*wakeup_secondary_cpu)(u32 apicid, unsigned long start_eip); + int (*wakeup_secondary_cpu_64)(u32 apicid, unsigned long start_eip); }; /* --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -358,7 +358,7 @@ acpi_parse_lapic_nmi(union acpi_subtable } #ifdef CONFIG_X86_64 -static int acpi_wakeup_cpu(int apicid, unsigned long start_ip) +static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip) { /* * Remap mailbox memory only for the first call to acpi_wakeup_cpu(). --- a/arch/x86/kernel/apic/apic_noop.c +++ b/arch/x86/kernel/apic/apic_noop.c @@ -27,7 +27,7 @@ static void noop_send_IPI_allbutself(int static void noop_send_IPI_all(int vector) { } static void noop_send_IPI_self(int vector) { } static void noop_apic_icr_write(u32 low, u32 id) { } -static int noop_wakeup_secondary_cpu(int apicid, unsigned long start_eip) { return -1; } +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; } --- a/arch/x86/kernel/apic/apic_numachip.c +++ b/arch/x86/kernel/apic/apic_numachip.c @@ -71,7 +71,7 @@ static void numachip2_apic_icr_write(int numachip2_write32_lcsr(NUMACHIP2_APIC_ICR, (apicid << 12) | val); } -static int numachip_wakeup_secondary(int phys_apicid, unsigned long start_rip) +static int numachip_wakeup_secondary(u32 phys_apicid, unsigned long start_rip) { numachip_apic_icr_write(phys_apicid, APIC_DM_INIT); numachip_apic_icr_write(phys_apicid, APIC_DM_STARTUP | --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -702,7 +702,7 @@ static __init void build_uv_gr_table(voi } } -static int uv_wakeup_secondary(int phys_apicid, unsigned long start_rip) +static int uv_wakeup_secondary(u32 phys_apicid, unsigned long start_rip) { unsigned long val; int pnode; --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -940,7 +940,7 @@ static void snp_cleanup_vmsa(struct sev_ free_page((unsigned long)vmsa); } -static int wakeup_cpu_via_vmgexit(int apic_id, unsigned long start_ip) +static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip) { struct sev_es_save_area *cur_vmsa, *vmsa; struct ghcb_state state; From patchwork Fri Jul 28 12:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp426458vqg; Fri, 28 Jul 2023 06:14:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlEfl6UH1LCjijG1n4rlpDA2ydwyqZpoHJKNmcAzhNcEU0BBdeamZsHA77oN1YyVjqGQgB0Y X-Received: by 2002:a92:c84d:0:b0:349:3c0:3974 with SMTP id b13-20020a92c84d000000b0034903c03974mr987828ilq.18.1690550087931; Fri, 28 Jul 2023 06:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550087; cv=none; d=google.com; s=arc-20160816; b=WNe846aIUADcqzszZiAcEnmPWH5ZVEJptG0jBqrFWuf+2kzCXIPlJzYA6jmTo7YEW+ c0YffN6Ap/ndecy8+r1bRNCT6lC3A8uJa2LYzCdUuEDkOQftPlPuwRMGCBbElWtB7nL3 vCKaEF6rr9Uu8X0BdZk0xtPKKVJ8g37bxsnXA6Z1LcVI1AGDCz8ZXGp9DEe7ZAZ4T04j 12cQ7LnQXV4ugp9ch1dMaJ+9aqKfg+xoo6K/CK+Xtzy5xKo2JI+ybXBtHS+2W64jqTGV tQCDfeOgAYduNhcXsRA11QMaBemagvoV5A4dNHCnKANwgiPyAKiulJq0xu15C445yuaf K2JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=LotaVQs4RlrtT3Fsb/omzWTh9eCCKi/NbM3QS9xGwX0=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=Y/NNQtQY9lj8BjJ+yTcXuuT5VsjydJdm6KGXJU1wvEOqVFSVlrYxGqjCRURaNVfTps +ZDnotT4qGuC1rJ2W34MCZW0d3T9+NZrxvz45So5bmMMVM1rGD5kG0cVskLDSUof0lNr B9Hze4iO85oi0WJfmKLb5p4lsDaJ02zE0cK4vqBp+fpxUOObkJc8pB/FxBB65l/twRIL w2yon9Jsvk+zwqCoyJQ5VsqUxZ4FU1pKHcQfAhp2RUkbX/Xp742hyShgtdiSQmWZmtUc 4gMKuuc6aSbYlM42U50YqH3iQtKP7TrebCNF/WUapxGZXB96C1Njjplv0a2yvwFjs0Ja W/iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yNqXWhzp; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wQFyFMOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a63360b000000b00563db11bacbsi3022904pga.466.2023.07.28.06.14.26; Fri, 28 Jul 2023 06:14:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yNqXWhzp; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wQFyFMOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236493AbjG1MOD (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236025AbjG1MNX (ORCPT ); Fri, 28 Jul 2023 08:13:23 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4F523C31; Fri, 28 Jul 2023 05:13:06 -0700 (PDT) Message-ID: <20230728120930.672330175@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546385; 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=LotaVQs4RlrtT3Fsb/omzWTh9eCCKi/NbM3QS9xGwX0=; b=yNqXWhzplelPEC6EqufzV+PoVxUllAeo/Wi+p1hFo5vurLPMbYblXp4jGlR+9otM3JuTtM +viqKycR0ud2Z6znI05wUqOWt04KOT7tsUi4dJOl2lSxrZAMpL3uPBkBr0TGce0RXYhxqE dKWkAES7ZFTztoI33OonKhlt3QUZdgdBl3g1OyipOdBa5TrCCX0Vd7mDwFYvQEzck8N8Y1 68KZSE5vB3RAPQwCjf+G3FkMB0lRTdyDAwMrMyla4RBp6/xMzDaOxEFA3OjogF6NApMA7O 3nG+FCaeEg+iLV2GGB6qLt/548OkVmdrTJFrcXEk0oA1Q1sUoQ+KuH+Ri3/bQg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546385; 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=LotaVQs4RlrtT3Fsb/omzWTh9eCCKi/NbM3QS9xGwX0=; b=wQFyFMOjMztzLvHuRRL8abQLdZo6Iawb1LV3/u9l0jn7S5GkkfyF2TuM8sNXVifAIuRJhj 7k0sg+o64YADRaCQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 18/38] x86/cpu/topology: Cure the abuse of cpuinfo for persisting logical ids References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:05 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772670249168804991 X-GMAIL-MSGID: 1772670249168804991 Per CPU cpuinfo is used to persist the logical package and die IDs. That's really not the right place simply because cpuinfo is subject to be reinitialized when a CPU goes through an offline/online cycle. This works by chance today, but that's far from correct and neither obvious nor documented. Add a per cpu datastructure which persists those logical IDs, which allows to cleanup the CPUID evaluation code. This is a temporary workaround until the larger topology management is in place, which makes all of this logical management mechanics obsolete. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/smpboot.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -124,7 +124,20 @@ struct mwait_cpu_dead { */ static DEFINE_PER_CPU_ALIGNED(struct mwait_cpu_dead, mwait_cpu_dead); -/* Logical package management. We might want to allocate that dynamically */ +/* Logical package management. */ +struct logical_maps { + u32 phys_pkg_id; + u32 phys_die_id; + u32 logical_pkg_id; + u32 logical_die_id; +}; + +/* Temporary workaround until the full topology mechanics is in place */ +static DEFINE_PER_CPU_READ_MOSTLY(struct logical_maps, logical_maps) = { + .phys_pkg_id = U32_MAX, + .phys_die_id = U32_MAX, +}; + unsigned int __max_logical_packages __read_mostly; EXPORT_SYMBOL(__max_logical_packages); static unsigned int logical_packages __read_mostly; @@ -345,10 +358,8 @@ int topology_phys_to_logical_pkg(unsigne int cpu; for_each_possible_cpu(cpu) { - struct cpuinfo_x86 *c = &cpu_data(cpu); - - if (c->initialized && c->topo.pkg_id == phys_pkg) - return c->topo.logical_pkg_id; + if (per_cpu(logical_maps.phys_pkg_id, cpu) == phys_pkg) + return per_cpu(logical_maps.logical_pkg_id, cpu); } return -1; } @@ -366,11 +377,9 @@ static int topology_phys_to_logical_die( int cpu, proc_id = cpu_data(cur_cpu).topo.pkg_id; for_each_possible_cpu(cpu) { - struct cpuinfo_x86 *c = &cpu_data(cpu); - - if (c->initialized && c->topo.die_id == die_id && - c->topo.pkg_id == proc_id) - return c->topo.logical_die_id; + if (per_cpu(logical_maps.phys_pkg_id, cpu) == proc_id && + per_cpu(logical_maps.phys_die_id, cpu) == die_id) + return per_cpu(logical_maps.logical_die_id, cpu); } return -1; } @@ -395,6 +404,8 @@ int topology_update_package_map(unsigned cpu, pkg, new); } found: + per_cpu(logical_maps.phys_pkg_id, cpu) = pkg; + per_cpu(logical_maps.logical_pkg_id, cpu) = new; cpu_data(cpu).topo.logical_pkg_id = new; return 0; } @@ -418,6 +429,8 @@ int topology_update_die_map(unsigned int cpu, die, new); } found: + per_cpu(logical_maps.phys_die_id, cpu) = die; + per_cpu(logical_maps.logical_die_id, cpu) = new; cpu_data(cpu).topo.logical_die_id = new; return 0; } From patchwork Fri Jul 28 12:13:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp452147vqg; Fri, 28 Jul 2023 06:57:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlG7Nn08T71ZnVdhe0MQ5t1BckOuyN4sNaSW8DwRqiQppWtiPnSNJ9udeKqcMSC/2UzJmb8p X-Received: by 2002:a17:902:8f8b:b0:1b6:b445:36d4 with SMTP id z11-20020a1709028f8b00b001b6b44536d4mr1239120plo.43.1690552670021; Fri, 28 Jul 2023 06:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690552670; cv=none; d=google.com; s=arc-20160816; b=lNhLMmNkyGqu4T4klJKUIzY1TRNIZGeKVTAkxUE+bLeeZaWRBxyWQ9nk9JgaRV8wk6 /MEnPDNwcaTyH1ZjnnJTv4N86mdDDSBFKCOXxJxgi63PgS/Cy/Xtrt+HtApL+mTePCOy Vay2hdpfpG0zsho+dkq5GQmr99kSJEPIwmVxHX5EyeCIsgYylK9dOfcQadAAeJVzo+cI JccxutDxQJI+QeIc65EBTMif5Jk1aWS5he/b0eDJmqy/vzdVfTrxqSN+mKnobRiD+Ozb mC+TcEjOcyiVKXNXedapdY85Yb61TQ0xsZ78bVRcRCQgHDYGsNlEdNs/KCY9EDeolcDc 90Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=FytBYElyGEIkDLoNOYBMDUbfYGktH+yBC5OWWqC5tQQ=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=P2woHmXJah/805JAxP2MGSK9O/jzQsZtfpiiTY92XGfiCVKF1lL0W83gK7JRyOoonw nK0ZGhN9vNqPZ464Xw6cQg19XbUSx6yKqI8BppVY4dYVuz+gpLzLn0t7ZQctw8o9H9tZ X78luoL9UJtUiXSlEV73rQYgx1YCnB/ZJLo5+HZDOyLwNzzNFnJo1EYJj2SM9p5ziMtK JGB2gajneKDLezyVufOabyFWesvQYVTeaKXO7xVUWkOkSmY2idpNz/wTRbipqSu0XGW3 g5jGHeFwptC4vZx3iEm3iGspB0MAf6jORynkPkStY/WJ1uCqP3zq3bFPMixoUNDR2BmE Lp+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hZ41luBM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb14-20020a170903338e00b001b88997ababsi3049124plb.412.2023.07.28.06.57.35; Fri, 28 Jul 2023 06:57:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hZ41luBM; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236501AbjG1MOK (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236275AbjG1MNa (ORCPT ); Fri, 28 Jul 2023 08:13:30 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B173C38; Fri, 28 Jul 2023 05:13:07 -0700 (PDT) Message-ID: <20230728120930.727298737@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546386; 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=FytBYElyGEIkDLoNOYBMDUbfYGktH+yBC5OWWqC5tQQ=; b=hZ41luBM+cti3euUpMK4zrf7WtFnCgKHLtyziGAZkLcWHfkkOK1fLCTSc8+omhqrlivgwL 3xQ44xGTq6miYIs6Xd5UTTbDgV+NK/IT8fgk84D8Dl8fbIwlG8EGuOH48Kl8IQagMdDQlg kF+F7o482+zX2yF0GFjALI+UAwm55CcdfgSYjb1+rr9n0ZZfViaAZLB3XPGSYgtOs9saz+ kSsA+/X2BeExBUcJDxro5VX/BlQmukaMrVIIzcRp8MmPshfm8Znxmxg/Mcx7Ahz6m+x1vo R0wEwVHpVMRqRZgxLfraY2whEviOuMJjdnnAWi9LmBVordDd+T5s6agMaGSLWg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546386; 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=FytBYElyGEIkDLoNOYBMDUbfYGktH+yBC5OWWqC5tQQ=; b=dzTdqmDzRwOd4rwCfjlNdB7I/QXFPa+mOtg/PmnlywJ665y6b6j0aC+/R8q1fb1PfVO/rE Fjt9pzUzUtdK6vBQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 19/38] x86/cpu: Provide debug interface References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:06 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772672956499708270 X-GMAIL-MSGID: 1772672956499708270 Provide debug files which dump the topology related information of cpuinfo_x86. This is useful to validate the upcoming conversion of the topology evaluation for correctness or bug compatibility. Signed-off-by: Thomas Gleixner --- V2: Don't return ENODEV when offline and make online a field. --- arch/x86/kernel/cpu/Makefile | 2 + arch/x86/kernel/cpu/debugfs.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -54,6 +54,8 @@ obj-$(CONFIG_X86_LOCAL_APIC) += perfctr obj-$(CONFIG_HYPERVISOR_GUEST) += vmware.o hypervisor.o mshyperv.o obj-$(CONFIG_ACRN_GUEST) += acrn.o +obj-$(CONFIG_DEBUG_FS) += debugfs.o + quiet_cmd_mkcapflags = MKCAP $@ cmd_mkcapflags = $(CONFIG_SHELL) $(srctree)/$(src)/mkcapflags.sh $@ $^ --- /dev/null +++ b/arch/x86/kernel/cpu/debugfs.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include +#include + +static int cpu_debug_show(struct seq_file *m, void *p) +{ + unsigned long cpu = (unsigned long)m->private; + struct cpuinfo_x86 *c = per_cpu_ptr(&cpu_info, cpu); + + seq_printf(m, "online: %d\n", cpu_online(cpu)); + if (!c->initialized) + return 0; + + seq_printf(m, "initial_apicid: %x\n", c->topo.initial_apicid); + seq_printf(m, "apicid: %x\n", c->topo.apicid); + seq_printf(m, "pkg_id: %u\n", c->topo.pkg_id); + seq_printf(m, "die_id: %u\n", c->topo.die_id); + seq_printf(m, "cu_id: %u\n", c->topo.cu_id); + seq_printf(m, "core_id: %u\n", c->topo.core_id); + seq_printf(m, "logical_pkg_id: %u\n", c->topo.logical_pkg_id); + 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, "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); + return 0; +} + +static int cpu_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, cpu_debug_show, inode->i_private); +} + +static const struct file_operations dfs_cpu_ops = { + .open = cpu_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static __init int cpu_init_debugfs(void) +{ + struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir); + unsigned long id; + char name [10]; + + dir = debugfs_create_dir("cpus", base); + for_each_possible_cpu(id) { + sprintf(name, "%lu", id); + debugfs_create_file(name, 0444, dir, (void *)id, &dfs_cpu_ops); + } + return 0; +} +late_initcall(cpu_init_debugfs); From patchwork Fri Jul 28 12:13:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp449020vqg; Fri, 28 Jul 2023 06:52:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlFVblUme1Dyby7VIZ4MuS5SBlsIMyeKoIzOdy6HxK8uP2SYOrxBizEZKA8GvEbUbWW0MNhc X-Received: by 2002:a05:6a00:982:b0:686:85be:1171 with SMTP id u2-20020a056a00098200b0068685be1171mr2208674pfg.26.1690552329303; Fri, 28 Jul 2023 06:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690552329; cv=none; d=google.com; s=arc-20160816; b=PsKfJ4v+44Mul4ymBUD56+Diw2xVgRKGgOfji4uhX50q3XV12FcNE/Zq2upgqqXo6b 2csc4pvan6qaUGRBF5AzA882w7Pg1PnKkJAbnUvrgqWAhOZPG5jHTi68hyVSgp5e1kDJ 4ODoAbxU9V6lZ2dT9xad9khLslm9cxQHvodiYF4Lw113oFHhrJFnXY9uHpVEc/KhRWh5 uAWUHGJj9Bw45Y3dVp/rI6u1V1yCoLsJq/Lb2jXNA0XSd0K3egXOz/RiRrH3vULareAX W5zLQPt1fH4xZrQ8rZiSgnZuC1CzWlXBMKS2f8QpFdNFTewPZgQ/1rYjLsTqw94kmwvk gQng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=15fa3zOR6FTjADI+P/8aKC6n9dvVMoPwTnUjFsnPU9g=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=wH0oY5Q9PbibowupE27yMdlf2bLjHE1/AnqGYDdTrm0HSEp029KOoC8OE92ePsSlzt kLI0BjIi+vT9ZXbhFbhB+XhMCur5BDaipkxkOjsYnuhTzdOhYDla1t/eeQovy6ObDZ5F TMB0h5/4MToL4WmyQ5hnYvJJYsnRDiOk0cBAErFVJy+H7ZNAfxM2SE+JvTtVdxVLazKh 5M5YMjmmurGiLSPEK6FfRIwPUsx84ntekR8s0X/FzaVjhKp9k7DQyo+KmMi55MDDQiRp 8+ytL+XFNS0qXA3dSh9QxXdNL/gT1coCcdCD4Qe3AiA5h0l2CTxjNhTPF9mgpMPAxZP4 3P9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=X1ze7eAF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dw14-20020a056a00368e00b0066882062113si3150147pfb.9.2023.07.28.06.51.31; Fri, 28 Jul 2023 06:52:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=X1ze7eAF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236340AbjG1MOQ (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236382AbjG1MNa (ORCPT ); Fri, 28 Jul 2023 08:13:30 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74F5E3C3C; Fri, 28 Jul 2023 05:13:09 -0700 (PDT) Message-ID: <20230728120930.782489826@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546387; 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=15fa3zOR6FTjADI+P/8aKC6n9dvVMoPwTnUjFsnPU9g=; b=X1ze7eAF1ZgivSjF0qcksy3/n3S9JitfBJ9X1w6X9YXwyJmFRYZeznANg0WAEPRxqZ0ClR 3qsPUxShLPZe7IDBlI0wYtcIFCCwxtX0xrdO/obYujwE1JJuN7fmw2DtJsiQNmcNtLad1m j+kNmGs5JO+wxZMR0gmP0jAQyCoXEMXTObRRTrXGs+lRNA9bOMpS65i9Ic9IrASyAXyofS 3FmlnrIxmiGt3DAOkGwQAI7idTTNrEqoSjDURyYpxGuIN9P2cLscgoTTjgkvQUaoCZ7I5D 7D2aMORq9sIHAhXMWTvkuW+8wF1c1H3hw44gtGemy8zkSGSAJmAl+GeB2sQtgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546387; 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=15fa3zOR6FTjADI+P/8aKC6n9dvVMoPwTnUjFsnPU9g=; b=Wg0SMtSPSrhjwKk8nJJJ3LaDAuFeGb5c3Y1xV4erTsfpOWGBCBNJxL9Uibo6QZgKdHRD1R Dv7cmn/4nxUZraCg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 20/38] x86/cpu: Provide cpuid_read() et al. References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:07 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772672599688157436 X-GMAIL-MSGID: 1772672599688157436 Provide a few helper functions to read CPUID leafs or individual registers into a data structure without requiring unions. Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/cpuid.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) --- a/arch/x86/include/asm/cpuid.h +++ b/arch/x86/include/asm/cpuid.h @@ -127,6 +127,38 @@ static inline unsigned int cpuid_edx(uns return edx; } +static inline void __cpuid_read(unsigned int leaf, unsigned int subleaf, u32 *regs) +{ + regs[CPUID_EAX] = leaf; + regs[CPUID_ECX] = subleaf; + __cpuid(regs, regs + 1, regs + 2, regs + 3); +} + +#define cpuid_subleaf(leaf, subleaf, regs) \ + BUILD_BUG_ON(sizeof(*(regs)) != 16); \ + __cpuid_read(leaf, subleaf, (u32 *)(regs)) + +#define cpuid_leaf(leaf, regs) \ + BUILD_BUG_ON(sizeof(*(regs)) != 16); \ + __cpuid_read(leaf, 0, (u32 *)(regs)) + +static inline void __cpuid_read_reg(unsigned int leaf, unsigned int subleaf, + enum cpuid_regs_idx regidx, u32 *reg) +{ + u32 regs[4]; + + __cpuid_read(leaf, subleaf, regs); + *reg = regs[regidx]; +} + +#define cpuid_subleaf_reg(leaf, subleaf, regidx, reg) \ + BUILD_BUG_ON(sizeof(*(reg)) != 4); \ + __cpuid_read_reg(leaf, subleaf, regidx, (u32 *)(reg)) + +#define cpuid_leaf_reg(leaf, regidx, reg) \ + BUILD_BUG_ON(sizeof(*(reg)) != 4); \ + __cpuid_read_reg(leaf, 0, regidx, (u32 *)(reg)) + static __always_inline bool cpuid_function_is_indexed(u32 function) { switch (function) { From patchwork Fri Jul 28 12:13:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp404321vqg; Fri, 28 Jul 2023 05:39:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlGJemRAUyqJ8Wa/0loEpBrr8WINeQe6dHjG9j/CZSf+1SDmBT+K+olKPz4QZD23OyzTPTwQ X-Received: by 2002:a17:907:a073:b0:994:34a6:50cf with SMTP id ia19-20020a170907a07300b0099434a650cfmr1288324ejc.49.1690547955481; Fri, 28 Jul 2023 05:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690547955; cv=none; d=google.com; s=arc-20160816; b=ak91ZufW+owiYEmFIrVuXnifRA3eEqbr8bjmus9K4gcHosC8OMjFFSx85km4ftuvWL STYxbU5+KBHCtY/xkSiVxJmK6z3yOcvRFyU73URTTwNbBujjdTeTCfeItGD5ix41lh6F pjSJFhzzrcUjeZdNNuYgcbO7Pcz05j/i/eRV20PHr5U2aXwL2Sj5OiWgwRF8xKTqjiKF Jf3ulX1I0oK0SVB71jFE5yHSOc2bJUtYjz5IuyKHRopknUMl34PWYM/iv0b2H3Co8oxe lIVQXHzAqiRL7fjC3PfUWzVLjF310d39eWC5tLrT5NgXRsFdOhO1U4C+Nie2Mj9qKdgx QDCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=YbDdAZqyzWrK2heF1xyr6o/lR/Gq7vEWfWpmCuCMzDc=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=Ek1kuBUhnJclAhuIEAoIPXQLGISFCpwMqlHRlYpU8J9lYNwaZ9kfFsU02E0RJm82rh gW7GTPy+DKKKcB3OmypQNFQOe0lee9qZUndvoZagJh7cUveSTMRbD4PDyZAnAhIL5gQL 0Zo7vbDGZ2/xxcc+ZDKhNXjZL/TmMDeT8NLF0/oBSxm3pC4esPaYA83hHOg3iteITgnd PFiEn92T3cuu8cxu16y/qFxvbQ3oar5UeiAgZKag1rjO20+BPns8m2r4BZwBphlwtfvX ifo8oNZjo4V2WIgg+0tjRAnHxrtRb+9J0c4jJf1ngDXbUhdqPQKd7JU5CwpXQx6ZPbgh K6FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cfLNVYH8; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="NuP/0xcl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a1709064c5300b0099bc7292ed0si2461230ejw.806.2023.07.28.05.38.51; Fri, 28 Jul 2023 05:39:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cfLNVYH8; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="NuP/0xcl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236367AbjG1MOX (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236412AbjG1MNb (ORCPT ); Fri, 28 Jul 2023 08:13:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DE644205; Fri, 28 Jul 2023 05:13:10 -0700 (PDT) Message-ID: <20230728120930.839913695@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546389; 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=YbDdAZqyzWrK2heF1xyr6o/lR/Gq7vEWfWpmCuCMzDc=; b=cfLNVYH8VfnbRgURMoVmcBD1OkotVpcbl19tcXApkxtcNkjaVS0MaXn+pnsHDIFHs99KS6 T+X2+xWShmZU9fhhNEhybriiyWtbj45RH1xRYmbAX4+rJ5AcvnWwGWFuIf6wRdgyQ+mDGR qeFOl7+Qc3bfmqm5Yl01cOORbO9GtGzurYWY5FA6wOngzuTeJiLuxjq533xzOcvUoqfHJv i/rOKFiNFvi3lsIF1hj+iDxdAetYTcPWAB/2mz4QVrRpFNFIq7czD8RhVyFqipB9frVp7x cUcfdM22L7d4Er7p9ekRBtDJb53jn9cyPW28UHmmcDGZ3FqqXCQd0RNEmf6YxQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546389; 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=YbDdAZqyzWrK2heF1xyr6o/lR/Gq7vEWfWpmCuCMzDc=; b=NuP/0xclKIUn+yTqdmnWTm1LGcS3J2fuaLjLJdm87Fvwuwd3bkTfhWuAVFxFjkB5R+3qql 1J67zFuvD1d/jrCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 21/38] x86/cpu: Provide cpu_init/parse_topology() References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:08 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668013203844470 X-GMAIL-MSGID: 1772668013203844470 Topology evaluation is a complete disaster and impenetrable mess. It's scattered all over the place with some vendor implementatins 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 --- arch/x86/include/asm/topology.h | 19 +++ arch/x86/kernel/cpu/Makefile | 3 arch/x86/kernel/cpu/common.c | 23 +--- arch/x86/kernel/cpu/cpu.h | 6 + arch/x86/kernel/cpu/debugfs.c | 37 ++++++ arch/x86/kernel/cpu/topology.h | 32 +++++ arch/x86/kernel/cpu/topology_common.c | 187 ++++++++++++++++++++++++++++++++++ 7 files changed, 290 insertions(+), 17 deletions(-) --- 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 #include +/* Topology information */ +enum x86_topology_domains { + TOPO_SMT_DOMAIN, + TOPO_CORE_DOMAIN, + TOPO_MODULE_DOMAIN, + TOPO_TILE_DOMAIN, + TOPO_DIE_DOMAIN, + TOPO_PKG_DOMAIN, + TOPO_ROOT_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); --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -17,7 +17,8 @@ KMSAN_SANITIZE_common.o := n # As above, instrumenting secondary CPU boot code causes boot hangs. KCSAN_SANITIZE_common.o := n -obj-y := cacheinfo.o scattered.o topology.o +obj-y := cacheinfo.o scattered.o +obj-y += topology_common.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += match.o --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1553,6 +1553,8 @@ static void __init early_identify_cpu(st setup_force_cpu_cap(X86_FEATURE_CPUID); cpu_parse_early_param(); + cpu_init_topology(c); + if (this_cpu->c_early_init) this_cpu->c_early_init(c); @@ -1563,6 +1565,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); } setup_force_cpu_cap(X86_FEATURE_ALWAYS); @@ -1708,18 +1711,6 @@ static void generic_identify(struct cpui get_cpu_address_sizes(c); - if (c->cpuid_level >= 0x00000001) { - c->topo.initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; -#ifdef CONFIG_X86_32 -# ifdef CONFIG_SMP - c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); -# else - c->topo.apicid = c->topo.initial_apicid; -# endif -#endif - c->topo.pkg_id = c->topo.initial_apicid; - } - get_model_name(c); /* Default name */ /* @@ -1778,9 +1769,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_model_id[0] = '\0'; /* Unset */ c->x86_max_cores = 1; c->x86_coreid_bits = 0; - c->topo.cu_id = 0xff; - c->topo.llc_id = BAD_APICID; - c->topo.l2c_id = BAD_APICID; #ifdef CONFIG_X86_64 c->x86_clflush_size = 64; c->x86_phys_bits = 36; @@ -1799,6 +1787,8 @@ static void identify_cpu(struct cpuinfo_ generic_identify(c); + cpu_parse_topology(c); + if (this_cpu->c_identify) this_cpu->c_identify(c); @@ -1806,7 +1796,8 @@ static void identify_cpu(struct cpuinfo_ apply_forced_caps(c); #ifdef CONFIG_X86_64 - c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); + if (!topo_is_converted(c)) + c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); #endif /* --- 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 +#include +#include + +#include "topology.h" + /* attempt to consolidate cpu attributes */ struct cpu_dev { const char *c_vendor; @@ -95,4 +100,5 @@ static inline bool spectre_v2_in_eibrs_m mode == SPECTRE_V2_EIBRS_RETPOLINE || mode == 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 +#include "cpu.h" + static int cpu_debug_show(struct seq_file *m, void *p) { unsigned long cpu = (unsigned long)m->private; @@ -43,12 +45,47 @@ static const struct file_operations dfs_ .release = single_release, }; +static int dom_debug_show(struct seq_file *m, void *p) +{ + static const char *domain_names[TOPO_ROOT_DOMAIN] = { + [TOPO_SMT_DOMAIN] = "Thread", + [TOPO_CORE_DOMAIN] = "Core", + [TOPO_MODULE_DOMAIN] = "Module", + [TOPO_TILE_DOMAIN] = "Tile", + [TOPO_DIE_DOMAIN] = "Die", + [TOPO_PKG_DOMAIN] = "Package", + }; + unsigned int dom, nthreads = 1; + + for (dom = 0; dom < TOPO_ROOT_DOMAIN; dom++) { + nthreads *= 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 = { + .open = dom_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static __init int cpu_init_debugfs(void) { struct dentry *dir, *base = debugfs_create_dir("topo", arch_debugfs_dir); unsigned long id; char name [10]; + debugfs_create_file("domains", 0444, base, NULL, &dfs_dom_ops); + dir = 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,32 @@ +/* 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 dom, + unsigned int shift, unsigned int ncpus); + +static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains dom) +{ + if (dom == 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_domains dom) +{ + if (dom != TOPO_SMT_DOMAIN) + apicid >>= x86_topo_system.dom_shifts[dom - 1]; + return apicid & (x86_topo_system.dom_size[dom] - 1); +} + +#endif /* ARCH_X86_TOPOLOGY_H */ --- /dev/null +++ b/arch/x86/kernel/cpu/topology_common.c @@ -0,0 +1,187 @@ +// 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 dom, + unsigned int shift, unsigned int ncpus) +{ + tscan->dom_shifts[dom] = shift; + tscan->dom_ncpus[dom] = ncpus; + + /* Propagate to the upper levels */ + for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { + tscan->dom_shifts[dom] = tscan->dom_shifts[dom - 1]; + tscan->dom_ncpus[dom] = 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 = { + .cu_id = 0xff, + .llc_id = BAD_APICID, + .l2c_id = BAD_APICID, + }; + struct cpuinfo_x86 *c = tscan->c; + struct { + u32 unused0 : 16, + nproc : 8, + apicid : 8; + } ebx; + + c->topo = 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 = 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 = c->topo.initial_apicid; + else + c->topo.apicid = 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 = tscan->c; + u32 apicid = c->topo.apicid; + + c->topo.pkg_id = topo_shift_apicid(apicid, TOPO_ROOT_DOMAIN); + c->topo.die_id = topo_shift_apicid(apicid, TOPO_DIE_DOMAIN); + + /* Relative core ID */ + c->topo.core_id = topo_relative_domain_id(apicid, TOPO_CORE_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_CORE_DOMAIN] = 24; 24 / 2 = 12 !! + * + * Cannot be fixed without further topology enumeration changes. + */ + tscan->c->x86_max_cores = tscan->dom_ncpus[TOPO_CORE_DOMAIN] >> + x86_topo_system.dom_shifts[TOPO_SMT_DOMAIN]; +} + +void cpu_parse_topology(struct cpuinfo_x86 *c) +{ + unsigned int dom, cpu = smp_processor_id(); + struct topo_scan tscan = { .c = c, }; + + parse_topology(&tscan, false); + + if (!topo_is_converted(c)) + return; + + for (dom = TOPO_SMT_DOMAIN; dom < TOPO_MAX_DOMAIN; dom++) { + if (tscan.dom_shifts[dom] == x86_topo_system.dom_shifts[dom]) + continue; + pr_err(FW_BUG "CPU%d: Topology domain %u shift %u != %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 == SYSTEM_BOOTING) { + pr_warn_once("CPU%d: SMT detected and enabled late\n", cpu); + smp_num_siblings = 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 = { .c = 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_system.dom_shifts)); + + dom = TOPO_SMT_DOMAIN; + x86_topo_system.dom_size[dom] = 1U << x86_topo_system.dom_shifts[dom]; + + for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { + sft = x86_topo_system.dom_shifts[dom] - x86_topo_system.dom_shifts[dom - 1]; + x86_topo_system.dom_size[dom] = 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 = 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 = tscan.dom_ncpus[TOPO_DIE_DOMAIN] / + tscan.dom_ncpus[TOPO_DIE_DOMAIN - 1]; +} From patchwork Fri Jul 28 12:13:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp416745vqg; Fri, 28 Jul 2023 06:02:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlFn94hTl5ENX9kMeBWQmICeALFoZmM3GbNgDcHYKCD1Pq7cXLmdlA0FGVbA8ZHpU3cuKlzQ X-Received: by 2002:a05:6a00:cc1:b0:668:846b:9b5d with SMTP id b1-20020a056a000cc100b00668846b9b5dmr1857197pfv.5.1690549343413; Fri, 28 Jul 2023 06:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690549343; cv=none; d=google.com; s=arc-20160816; b=nXF7b3R2Az6wwfu57kzUuBdqd8zmd185crVoUzAnwmUyKP6I1d2HILBKqZ9Q8hfT1g MpgjYh97jX8twvNET4JApj4pXjXn75/wvWqDne1GN5tnunTzMkxVreujYFzP8PuQf+9l 0BNPygsLhX8nWTSXQc0rhyZFlonpUmOHNAzk/ou5+pUWkgmpleT2I9W5mK9Fe5vQRmRJ fbQh6WDbokEcxLFUkOHI1Up4IiynCbxrjKoX4n25d9VHvx4ej6JORkGGG8whDeWJiv0X Ss6/4XSjS7Slih6+vyuYInRnwIamNAfXqU1r4AhoD4lwPwIH9xbgsTIPRgCaKQa+aGvK mWVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=UqiiOrV6qFVmLayEKJExgkdA2s95N7jm4m59y0h1Wug=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=UIiscBMAHVrkG2CUYsjrpIolLLEWHrHNAl5jZYs9LVAWof7zCNB/4VHT9zMHCia5o3 ZZMnnBDXB5xLE4DggqOG3Bc8FTQWUd66fGISKidpYwcJx+HwuT8KXdekZs5TNv4Wkk2P vecR/p/H9Ti4NMwu7rrMjGLZqLuGPPcgkNAfeuOBVd3J9CKdwLowJKBOnVjiQm7RyeDM uC6tjSLkhQbygru8z9QvwzpFCna+a72gGvvsywxO4vVCwx+u6FXjfVKsRWJsxWv2HrU7 eBp4VnhED/o0r1J0+jDO6dMv5m8/fBRK/5Ak2Z4WeNhGxQREV+LDFKChIcxZ/zIbdklg JGSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fgQReNQd; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fh38-20020a056a00392600b006826f3512f1si3196556pfb.204.2023.07.28.06.02.10; Fri, 28 Jul 2023 06:02:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fgQReNQd; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236522AbjG1MO1 (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235646AbjG1MNe (ORCPT ); Fri, 28 Jul 2023 08:13:34 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE524219; Fri, 28 Jul 2023 05:13:11 -0700 (PDT) Message-ID: <20230728120930.895466874@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546390; 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=UqiiOrV6qFVmLayEKJExgkdA2s95N7jm4m59y0h1Wug=; b=fgQReNQdRn9/yvbqP/CdlFu5LxypeGGTwddlcC0s2G4u4MHGhhmMqNYZv7BFy91KwwEA0k bSRfOJloS28zA4wkd/8zyrawfF3UwJjhX/bEVbcYRI4u+JL8urA4X2WgJAEG69/NB8AD+1 RG3xnrU98QmiXPR/m/3n8zmtF8FuOzGZZgTuUHPv5pDPovgODKVqPw+tLbarNZgkhxA/JR +9tTAIF7TKAs1nGuald5SFQdQcbI1MQCufZwoXIXudZQXh2dduR0mSnt3HgmxIE7QxqFKP hV8mZgmeqDTrdyf9VrN1C+26dFuz2qbJIbePoIoQ6/TMGacFEhs0bGVNUuPEeA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546390; 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=UqiiOrV6qFVmLayEKJExgkdA2s95N7jm4m59y0h1Wug=; b=yCt1+DeZ/St5T5qYw7lNG+ybbKk1llaPu80y6NgiEy+tqc+ASby7vzN4wQVwyFcdeT4YCe CS0ai21ctKzAMbAQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 22/38] x86/cpu: Add legacy topology parser References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:10 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772669468253361536 X-GMAIL-MSGID: 1772669468253361536 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 --- arch/x86/kernel/cpu/common.c | 3 ++ arch/x86/kernel/cpu/topology.h | 2 + arch/x86/kernel/cpu/topology_common.c | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -883,6 +883,9 @@ 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; --- a/arch/x86/kernel/cpu/topology.h +++ b/arch/x86/kernel/cpu/topology.h @@ -7,6 +7,8 @@ struct topo_scan { 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; }; 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,41 @@ void topology_set_dom(struct topo_scan * } } +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 = 0; + struct cpuinfo_x86 *c = tscan->c; + + cores = parse_num_cores(c); + core_shift = get_count_order(cores); + + if (cpu_has(c, X86_FEATURE_HT)) { + if (!WARN_ON_ONCE(tscan->ebx1_nproc_shift < core_shift)) + smt_shift = tscan->ebx1_nproc_shift - core_shift; + } + + topology_set_dom(tscan, TOPO_SMT_DOMAIN, smt_shift, 1U << smt_shift); + topology_set_dom(tscan, TOPO_CORE_DOMAIN, core_shift, cores >> smt_shift); +} + bool topo_is_converted(struct cpuinfo_x86 *c) { /* Temporary until everything is converted over. */ @@ -88,6 +123,8 @@ static void parse_topology(struct topo_s /* The above is sufficient for UP */ if (!IS_ENABLED(CONFIG_SMP)) return; + + tscan->ebx1_nproc_shift = get_count_order(ebx.nproc); } static void topo_set_ids(struct topo_scan *tscan) From patchwork Fri Jul 28 12:13:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp406552vqg; Fri, 28 Jul 2023 05:43:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlG00LW+yS9+q6YuIYPvm6sfH+nuJD0qd7ueUuHVrk2bm6s/DxFcRM+e9K1dBXbIsDxBjX4c X-Received: by 2002:a05:6a00:24d0:b0:668:8705:57cf with SMTP id d16-20020a056a0024d000b00668870557cfmr2205963pfv.25.1690548201840; Fri, 28 Jul 2023 05:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548201; cv=none; d=google.com; s=arc-20160816; b=tjAu8P+bmjWEem1tdpij+QNDFbcyHAiOq37gx2XsGhrJi2l3cx5AjkTWNogRY5M1O8 Ujtegs2+yzIbuv0sWqQ6QhE0I5C3kjdxyYTtjpX14DX2YkCkMg9dtRkYxTzIh2B+30c0 xdTyygihaeDhoYDao9ngiY26W5NhU0frCgB8o6k2NfukLqGvY2n5ziex7QmPbpyw0Smr De9EvLc9Sda4x6W5vupK2vNzJmIFERl4D3yK8GYa92jJq5dpjBuCjAUaV9laAdpiL+AA D8R7XXRhxp/eLB0M5BVUiy5Fl0Fqq5QICp9RJHNzwIjzb2EHPS9UXZkVvIkOaWY0KYyw H7aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=8j9Csrsczl1+89ZENZFtTchVmi22SuFWjwFyU4WiA04=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=TkhgJ+wPDmtWZt2RtSZEkIFs9hVWL1hQnICNpE8GqoBsXcOOmxhOtTamClitDSb63j IumxH+8GHWTvsdJ7SG7EAkZWsyRxVXjWniJC8Q4bp8D92zYvw/0kGT2WRk5x6NZ/jXmy B7jqOQG3BqflBmwLWvqP2wlafvrJ5N8OOgpV8ohDqhh/1RzzRYJt7Yg8RvGRCsqZlY+1 /TRuejAWarAImPB9i/2H0sd9JdFhaevQ0KHZdmLCnRyH8ZwQKyhRCqdgwvQb8aVn/3rm WFxUEm4Dz4EFyqiqqYmP18krxItslQuQL94hgAiRO7N9mcs6WH9BoEs6tlR4aAAehSlp XswQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QZDQKCS1; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l65-20020a639144000000b005642019ea7csi672481pge.864.2023.07.28.05.43.09; Fri, 28 Jul 2023 05:43:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QZDQKCS1; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236527AbjG1MOl (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234494AbjG1MNg (ORCPT ); Fri, 28 Jul 2023 08:13:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15ACC4227; Fri, 28 Jul 2023 05:13:13 -0700 (PDT) Message-ID: <20230728120930.952069383@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546391; 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=8j9Csrsczl1+89ZENZFtTchVmi22SuFWjwFyU4WiA04=; b=QZDQKCS1kBmU9oozZ6D3561g0CmzwmjmKcw6lBDyhApig1kDACMGecuP9Tpl2DWmwh0Pfy nb3w3uQZSIXmh95Y30fd8NEwAK89sFSkqy2LbjTym2AZHONtgT9oEFZXOL4at4EWDK0CQx cgx7ImQFZ2HmNKvHmOeqvrBWyyW2w3PDBZqXH45R2JXrWJlCZXxaFuOr5Z+fYF1xj6U/ZH GskExaoSLYyFKInF59nUZulwPyaIT8DzWZnT/M+7aUeW3Z0DBVLiCr0KNjJPhZNticF1UY XPPOTqiPG2Rg6+lwiZ7ingSaRENhrKySJRauqFfhwmnQntAxQVAu+QWpovfSIg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546391; 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=8j9Csrsczl1+89ZENZFtTchVmi22SuFWjwFyU4WiA04=; b=hqEf29XziUG9U3h6D9xcYDVRXgCSya5ClMe/wlyPDnsszrWwssYrmFugeH81LPjs0XD3AG ojdF7lwnhsWnMxDA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 23/38] x86/cpu: Use common topology code for Centaur and Zhaoxin References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:11 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668271321705507 X-GMAIL-MSGID: 1772668271321705507 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 --- 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 if (c->cpuid_level > 9) { unsigned int eax = 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; } -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 = 0; struct cpuinfo_x86 *c = tscan->c; @@ -64,10 +64,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 */ @@ -125,6 +123,13 @@ static void parse_topology(struct topo_s return; tscan->ebx1_nproc_shift = get_count_order(ebx.nproc); + + switch (c->x86_vendor) { + case X86_VENDOR_CENTAUR: + case X86_VENDOR_ZHAOXIN: + parse_legacy(tscan); + break; + } } 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 if (c->cpuid_level > 9) { unsigned int eax = cpuid_eax(10); From patchwork Fri Jul 28 12:13:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp433206vqg; Fri, 28 Jul 2023 06:25:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlEprymUFVq8+thc5Tlq184UDnKP82z+CLLeX8sPQH2U/zr+VPPc1L7L4VzW3hBlK76X7d4b X-Received: by 2002:aa7:cd88:0:b0:522:57d6:4acb with SMTP id x8-20020aa7cd88000000b0052257d64acbmr1620742edv.16.1690550755606; Fri, 28 Jul 2023 06:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550755; cv=none; d=google.com; s=arc-20160816; b=esBXWDHBF8cAUNF4fKTokb9ISGtIzYfWJyUuYG618F2o0ylUUdXei2eeysrTmJJsTf J7GcT5aZOsLQpF1y5mlMQjQc50HIEhyCKe3NB3/ufq3XDGhXDczjHMsJFw7n/nsVPIcQ GRTubifQIm8Z17BZoARyHgV6sV5nBkvvoddYuKA9G5IX1NBBTrxca7TnPKpiv0xfIGG8 D+gx6ee/QjIvtbe63BwX2KTpZQi0Nh9CMvLjauupPNHSo/dfxFqpLXb8Rtt7CVrCiht7 NBOE4LZegj/7CxQ9XnNwxf7S63F5O5kXGaBtLzzyGDELcda7psr9R8JF7EufGzdPIZ6O yixw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=R30kgmHCGWHq0zLlNoJY82eQjQTUWAtGppL/g8UfpDM=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=sms3YcbruQ5Le7QlT5JDSer0TEDqzJ7y5R0HFMmFL9ZbfI9xQrEd5vIhS3LFRtGABS YFzL1y1Bxdv1RhPz0VIvqmBuNPpwST+Qyp/pZEwiryAuqnU0yeOR3xMuBTR4s5MW75If +ylYe4NogBLxw5bcQEdR9cLbwi8zhBLQm18sdbYBdexNgEFDGa5G2CADBlNVt0Nj7Evq wWLlE0/bUw+17CVATn06e7gRat1mF3uJqp6/lE8VWQV+R8cDKtgdaMm1Hjea1ZDHm0qr V1MAETUt+MsisYsNnX86OQ7rjOcc85IYfxgs/cR8EhQCX24+yMQJ6D427PHUYIVZw9aw vb8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OcdeD+K4; dkim=neutral (no key) header.i=@linutronix.de header.b=TauKNaxN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ba8-20020a0564021ac800b005222991a3d4si2555787edb.453.2023.07.28.06.25.28; Fri, 28 Jul 2023 06:25:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OcdeD+K4; dkim=neutral (no key) header.i=@linutronix.de header.b=TauKNaxN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236535AbjG1MO7 (ORCPT + 99 others); Fri, 28 Jul 2023 08:14:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236482AbjG1MNy (ORCPT ); Fri, 28 Jul 2023 08:13:54 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30224488; Fri, 28 Jul 2023 05:13:14 -0700 (PDT) Message-ID: <20230728120931.007571739@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546392; 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=R30kgmHCGWHq0zLlNoJY82eQjQTUWAtGppL/g8UfpDM=; b=OcdeD+K47LagVHhbUTFW0HWmbg527ioHizlrWIVtWMqemkNmU3bRC93QSvXZ2JjPBBdwj9 id63sOY/cGprDxAnyG8/ISXkVIFXtBvwCzjpuy5I0VQbpT2fXfhU4P9aveuse3FpN211CO LeWDBdUWoShLYSdhOMPzabZZEzQUmmS4SEYGjbrxcSDeVYvnZNor9QELm038SbNJxepEKV rDsgwy6fHsjJaIF9hHti39/rd0/0L0mnAK6Ba9sQ03fdc0PGv5ZnMxw7I2eGlQF38D1CzS A/wZQouOdrS3WuqPORQmpu7fyPBqsjCNFKSnxQDhuxuyQJZ//ImfpIg2J9KKKQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546392; 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=R30kgmHCGWHq0zLlNoJY82eQjQTUWAtGppL/g8UfpDM=; b=TauKNaxNPwe9knjpTLPHgNWEc4opHe/7dKLdhEmMnhnGx4oqcCCuwdI8liKC33xubJtsD4 sntrcMNHQHUdn3Bw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 24/38] x86/cpu: Move __max_die_per_package to common.c References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:12 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772670949273066590 X-GMAIL-MSGID: 1772670949273066590 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 --- 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 = 1; EXPORT_SYMBOL(smp_num_siblings); +unsigned int __max_die_per_package __read_mostly = 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) -unsigned int __max_die_per_package __read_mostly = 1; -EXPORT_SYMBOL(__max_die_per_package); - #ifdef CONFIG_SMP /* * Check if given CPUID extended topology "leaf" is implemented From patchwork Fri Jul 28 12:13:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127646 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp435035vqg; Fri, 28 Jul 2023 06:29:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlHEiIg6jR+P7g4Tvp2IVrTmEq75uhsVKZitg/TtqKesiZrZ7trVIHVq1J6ExBtBLDaGklTy X-Received: by 2002:a05:6808:1452:b0:3a4:7f2:2980 with SMTP id x18-20020a056808145200b003a407f22980mr4104739oiv.27.1690550956723; Fri, 28 Jul 2023 06:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550956; cv=none; d=google.com; s=arc-20160816; b=ziVj2a1OaQmZGvUHDkuii8NBHAOs7/dIfK2Tr+XoNivaDRPLHzUw6n4JGZlShQ5gM2 V+Zy8i0Bn5l8HFoWiTD6iSJQwvxNvzBY8hNEyqKH73Cgvot8Lp+Bmw7IDUZSd2NapuQ4 AIj4n3N1fIqgq4ycgMtyAD/acdlExFINinrzqAJ0MTY08OKGzGIHvtwLy9HpzPOLiLqL 1ho87VYk8kEL4fIXow9dQIPSP5WAB6fb/yRejp5GV/3mkgVO/sSRaMcJvPY57WPTMd27 FgrfEP25fN8qH2xFEio7Qoc7mH4277+kMTAJsJrZa0qgQkPo/h7qcMysqO1vwRzVrt/l qHUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=K8G3BegNCqpNmXITgAr+wce0GBx04jSPNL1AU9AAQFg=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=dwa1hO0JYDvp//B+KfiFwLYl0CzTTYzodhN//pxzJTTvTVVFtOwHUkOMKR8G2cXkR9 g16mV3nvJhYToPG2ZSNzzGqtXjL1hUtAWq8O+JWJIDq0FyoOPehj98+eAgiU59nkvkEa 6rJ5khaywBMBpIWJS+F/A6/scQ5/HC153F/PV3SPe6WsTG7wtSS7y5U+hnJ+U/BYGJcH zLpyiFns7F0Rb4z2TfYdUEEWXpk7zgBKagfwbWhrQRjgLklso+cYNZ3YnwqkGJITI+eZ NELs3cdiL6Kyr84i4+W8H1xyWS52X3wy6fimQ5NFAovFB/hggULo+ltdYzpOXlvhO0zA C70g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZmfO0ZG8; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a19-20020a63e853000000b005574c3ac68esi2648943pgk.489.2023.07.28.06.29.03; Fri, 28 Jul 2023 06:29:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZmfO0ZG8; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236553AbjG1MPo (ORCPT + 99 others); Fri, 28 Jul 2023 08:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236409AbjG1MOU (ORCPT ); Fri, 28 Jul 2023 08:14:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F208449C; Fri, 28 Jul 2023 05:13:16 -0700 (PDT) Message-ID: <20230728120931.061954955@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546393; 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=K8G3BegNCqpNmXITgAr+wce0GBx04jSPNL1AU9AAQFg=; b=ZmfO0ZG85nF2KpiFv7XwqajVJe9Muy6CaGajI9VAfA1GZjUwtnMvMGpQVF2VCKJ/oMXvmZ vgxdQsPyqLpRzoC8+xI8J0Fyly2TaRdcbmJVVSF2mpHLNw3lZDMKfGL1qvaJzgkfmYiBik wo4EWqDisK5dss2o6fkLLMLFZLGiqtYfVS9nGXoFpjlUwfhSxmiWDuZDLqgq710AL8KXKv e8ntog7V9iYpU/k8cw3WENDKNWMecL5Y4PxpZHpLvv8Tzu/p/MML8AnWAIBCmdpAyJyM9T DGA3R6BeFyDPRgNs5c2xgtdvNwPssStIYMfFow7P0h3meq/Wh2eV9EZ/ULvMow== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546394; 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=K8G3BegNCqpNmXITgAr+wce0GBx04jSPNL1AU9AAQFg=; b=JzUXj7G04RfjLgdBdsYnKFK2gxODl0kiyFsYPQP0BBIi28zDY0//K8fIIVTk+Fr4uhRHz6 Mmvz2u0bgvTzRRAw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 25/38] x86/cpu: Provide a sane leaf 0xb/0x1f parser References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:13 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772671160099217647 X-GMAIL-MSGID: 1772671160099217647 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 --- V2: Fixed up the comment alignment for registers - Peterz --- arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/topology.h | 12 +++ arch/x86/kernel/cpu/topology_ext.c | 136 +++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology.o +obj-y += topology_common.o topology_ext.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += 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 dom, unsigned int shift, unsigned int ncpus); +bool cpu_parse_topology_ext(struct topo_scan *tscan); static inline u32 topo_shift_apicid(u32 apicid, enum x86_topology_domains dom) { @@ -31,4 +32,15 @@ static inline u32 topo_relative_domain_i return apicid & (x86_topo_system.dom_size[dom] - 1); } +/* + * 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_topology_domains dom, + unsigned int shift, unsigned int ncpus) +{ + tscan->dom_shifts[dom] = shift; + tscan->dom_ncpus[dom] = ncpus; +} + #endif /* ARCH_X86_TOPOLOGY_H */ --- /dev/null +++ b/arch/x86/kernel/cpu/topology_ext.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +#include +#include +#include + +#include "cpu.h" + +enum topo_types { + INVALID_TYPE = 0, + SMT_TYPE = 1, + CORE_TYPE = 2, + MODULE_TYPE = 3, + TILE_TYPE = 4, + DIE_TYPE = 5, + DIEGRP_TYPE = 6, + MAX_TYPE = 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. + * + * A table will also be handy to parse the new AMD 0x80000026 leaf which + * has defined different domain types, but otherwise uses the same layout + * with some of the reserved bits used for new information. + */ +static const unsigned int topo_domain_map[MAX_TYPE] = { + [SMT_TYPE] = TOPO_SMT_DOMAIN, + [CORE_TYPE] = TOPO_CORE_DOMAIN, + [MODULE_TYPE] = TOPO_MODULE_DOMAIN, + [TILE_TYPE] = TOPO_TILE_DOMAIN, + [DIE_TYPE] = TOPO_DIE_DOMAIN, + [DIEGRP_TYPE] = TOPO_PKG_DOMAIN, +}; + +static inline bool topo_subleaf(struct topo_scan *tscan, u32 leaf, u32 subleaf) +{ + unsigned int dom, maxtype = leaf == 0xb ? CORE_TYPE + 1 : MAX_TYPE; + struct { + // eax + u32 x2apic_shift : 5, // Number of bits to shift APIC ID right + // for the topology ID at the next level + __rsvd0 : 27; // Reserved + // ebx + u32 num_processors : 16, // Number of processors at current level + __rsvd1 : 16; // Reserved + // ecx + u32 level : 8, // Current topology level. Same as sub leaf number + type : 8, // Level type. If 0, invalid + __rsvd2 : 16; // Reserved + // edx + u32 x2apic_id : 32; // X2APIC ID of the current logical processor + } sl; + + cpuid_subleaf(leaf, subleaf, &sl); + + if (!sl.num_processors || sl.type == INVALID_TYPE) + return false; + + if (sl.type >= maxtype) { + /* + * As the subleafs are ordered in domain level order, this + * could be recovered in theory by propagating the + * information at the last parsed level. + * + * But if the infinite wisdom of hardware folks decides to + * create a new domain type between CORE and MODULE or DIE + * and DIEGRP, then that would overwrite the CORE or DIE + * information. + * + * 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 forcing + * software to either create a monstrosity of workarounds + * or just being up the creek without a paddle. + * + * Refuse to implement monstrosity, emit an error and try + * to survive. + */ + pr_err_once("Topology: leaf 0x%x:%d Unknown domain type %u\n", + leaf, subleaf, sl.type); + return true; + } + + dom = topo_domain_map[sl.type]; + if (!dom) { + tscan->c->topo.initial_apicid = sl.x2apic_id; + } else if (tscan->c->topo.initial_apicid != sl.x2apic_id) { + pr_warn_once(FW_BUG "CPUID leaf 0x%x subleaf %d APIC ID mismatch %x != %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) +{ + u32 subleaf; + + if (tscan->c->cpuid_level < leaf) + return false; + + /* Read all available subleafs and populate the levels */ + for (subleaf = 0; topo_subleaf(tscan, leaf, subleaf); 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_DOMAIN] > 1) { + unsigned int sft = 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_SMT_DOMAIN]); + } + + set_cpu_cap(tscan->c, X86_FEATURE_XTOPOLOGY); + return true; +} + +bool cpu_parse_topology_ext(struct topo_scan *tscan) +{ + /* Try lead 0x1F first. If not available try leaf 0x0b */ + if (parse_topology_leaf(tscan, 0x1f)) + return true; + return parse_topology_leaf(tscan, 0x0b); +} From patchwork Fri Jul 28 12:13:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127640 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp434139vqg; Fri, 28 Jul 2023 06:27:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlHiJx0/CZZAGgG7XM2dzkJCOg5V7VXBTu85NLYULCZ+Uz21bCtVe5ldypb63wsTJ5hx+0Ps X-Received: by 2002:a05:6a20:9703:b0:13c:8e50:34b8 with SMTP id hr3-20020a056a20970300b0013c8e5034b8mr1277148pzc.35.1690550856301; Fri, 28 Jul 2023 06:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550856; cv=none; d=google.com; s=arc-20160816; b=bQDjqAzyd2UJMy8lYgRKzEJDEjPBcsdKz27zG3SDUYm27LNTIoBNq5u9yYsTMwM5VE bwZXAxpTpyD9N9cJsqq3MCW6FSKTypLRS5UmJEDZgIqBnjG7Jyg0fmspPkOUg+scalKg Q4wgm+/YdKWOVodx0zUjFL3b2yiSJEEg8coUVW4ZcwSeoj4S/vF2OQp9Brr8N70AbHtY V/2KL5E3+1gAAQkJ78NNGCRHbi82Kv6WxBUE9uyfznVWBfDVj/+EbEInsGdXSh8Pob1+ QEWNdUy3Oq69tA/LHhiRtktrpvfTKe+zQb9iRKlRNrDy+5uLp7V8zskspOQk5KxMlyjp pr4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=3BTOZBcdzyy0AoTkbsTzY5XJZ5iS307qvXgzpSumcTA=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=VpycPHri/ZKe0YjFMyIcZ99S9s/e1+wyh/N/3/EyWO3Ou2hmbhTpDlQVb1WQ3sgQDm kPW7gOrT8QSsCyjqiG03MNc55mJtGewk+XeBQS9tbD5niY9FGrxSlWdVS4lnaak+uqxf F4tmPDVrpSZ6wsdG8lvLDqjoj6k9A7jn4Tnm+XweysAtTRVtv8Kw0K+BOEHEjNHMfewY WZA3aXa2i3w8hQU+3rmtRu5UZAtOgw80JtWOvSnd2mxk+GOj99lUc4BLOKEMVd5dDXoJ OA1eYxhRU7Y3hJ0DhI8iNpU9+RE6W/xym1oC5WztIrG+ZIMAq8U5H4oZP/Wuo15dtsJe ZmCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=e6WnG+CB; dkim=neutral (no key) header.i=@linutronix.de header.b=TfJnUv5F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8-20020a637348000000b0055bedcc9b47si1258441pgn.285.2023.07.28.06.27.20; Fri, 28 Jul 2023 06:27:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=e6WnG+CB; dkim=neutral (no key) header.i=@linutronix.de header.b=TfJnUv5F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236518AbjG1MPr (ORCPT + 99 others); Fri, 28 Jul 2023 08:15:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbjG1MOj (ORCPT ); Fri, 28 Jul 2023 08:14:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A000A44B1; Fri, 28 Jul 2023 05:13:18 -0700 (PDT) Message-ID: <20230728120931.116763463@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546395; 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=3BTOZBcdzyy0AoTkbsTzY5XJZ5iS307qvXgzpSumcTA=; b=e6WnG+CBD7qibzUX2EKlmiFgkEhB1GuA5mWZ/broNje/Ltu1ebSOd9PC4Fcow0ar2MDsC7 1IvEbIE2poKEknGKAMUMrpKS91HYHaV+xmqafNTa65jiuDEEwb/loWxpJNn/PR4MnXCaiR JuH+ejVO0cHoL+1QE5l4OMV6VlkA84FGOo5WCjcOVXMWkCMIH906YOc7gvuRe3F1WirVUo j5Mftx1hBmZpJ5tVw3VPIRFTSIkOMlRvRNATT8upPGshl5qC6zx6eUgJYAWVmBshpyT8Zf 5Qbb5AJlPp3w5glkgDyuPo/06MDYB4tDE9BnLVHhoTO74H5/sT5mN1aB+GE/tA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546395; 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=3BTOZBcdzyy0AoTkbsTzY5XJZ5iS307qvXgzpSumcTA=; b=TfJnUv5FyaqhFECG71uZpWXd6e4mLSlRrr3G5fqYm1TaqYh5WezoyJiowKT0ctAmlAwDMu aYMhonhRwTxvg0Aw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 26/38] x86/cpu: Use common topology code for Intel References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:15 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772671054785478041 X-GMAIL-MSGID: 1772671054785478041 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 --- 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 @@ -784,19 +784,6 @@ static void get_model_name(struct cpuinf *(s + 1) = '\0'; } -void detect_num_cpu_cores(struct cpuinfo_x86 *c) -{ - unsigned int eax, ebx, ecx, edx; - - c->x86_max_cores = 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 = (eax >> 26) + 1; -} - void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) { unsigned int n, dummy, ebx, ecx, edx, l2size; @@ -858,54 +845,6 @@ static void cpu_detect_tlb(struct cpuinf tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]); } -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 = (ebx & 0xff0000) >> 16; - if (smp_num_siblings == 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 = get_count_order(smp_num_siblings); - c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, index_msb); - - smp_num_siblings = smp_num_siblings / c->x86_max_cores; - - index_msb = get_count_order(smp_num_siblings); - - core_bits = get_count_order(c->x86_max_cores); - - c->topo.core_id = 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 = c->x86_vendor_id; @@ -1853,10 +1792,6 @@ static void identify_cpu(struct cpuinfo_ c->x86, c->x86_model); } -#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); -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); void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c); --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -489,13 +489,6 @@ static void early_init_intel(struct cpui } 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); } static void bsp_init_intel(struct cpuinfo_x86 *c) @@ -777,24 +770,6 @@ static void init_intel(struct cpuinfo_x8 intel_workarounds(c); - /* - * 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); if (c->cpuid_level > 9) { --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -64,7 +64,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: @@ -129,6 +128,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 patchwork Fri Jul 28 12:13:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127615 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp415407vqg; Fri, 28 Jul 2023 06:00:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlGEgffIlCRzYnKO5TcHTlM9p6uJ87Cqu0GLErzwA+nsiRcuxssX3+WhFiaBcSF2KPymS17P X-Received: by 2002:a05:6a00:2314:b0:67b:a681:4ab2 with SMTP id h20-20020a056a00231400b0067ba6814ab2mr1668267pfh.25.1690549259392; Fri, 28 Jul 2023 06:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690549259; cv=none; d=google.com; s=arc-20160816; b=NqsQP1n1PRxQZ0dqaL/CP5aMpR2oGy7FVvGOSn7KDRRPtGIg+7vV0L9eAQWRsFeMyR ZLDHBzI6raKUoREZZLBuDZsDZUrrSHCyyN/fvdDnY06zn3g3DuwWyPoMKoO5yA3BIQGW KqV7KrFKXLMBoLwSQgRZGsga7ffribVra7Mg14hZqn5hwOF8ySkm5WIPfsZj5YEHbSQg jRn3aPJXzVZ/6BdCD8LyUbR6YASXkl+uy9kXa8G+F2NVIihtjt9IQKUb5Eh0Z2c5FRed SPNSxkN+IZwSnQRV2t36h7XkHgtFxlQVNRu0hN5t6MK1Q7vTQx/BMlHvo8j+JsMXceZ9 c8yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=2HJ6gKC8xKh7ZYiNVCch9OIndLCiZ8cyEEDMpJCZ4Vw=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=skRWmJf7WmDYmOnAt9dV9apQWHTqOIzCuKip3RIMcn69DapIIT091vkPaqkuAbvw02 n9oHtBbW5gLo3MP/H4ZE4LkqUmNI7Jt8QHqdOoj/uiSLj6aFTBgVDvnBoNhdiNRDKg/L 3MVo4FgcyxKunwU/BzW/YcumSc9otjXLBlezdhdc5eiqjMtXzv5iWRxZL5NDzP9kA6es IENl6XSYOtwWcMp5A3HNrj9dL6EIVHe118u2I0M6u7w2gp5y32WaKAQg+kifAx02Sdo9 b1Gp5Rwtu2RDrK6yMUQpCu1mwY93gydYZe4Kwpi5FZVqmCuYGT9GNcmo/Wy2Nn18CZTi I2dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=268An0Wd; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a63600c000000b005481915c0cfsi151126pgb.1.2023.07.28.06.00.44; Fri, 28 Jul 2023 06:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=268An0Wd; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235329AbjG1MQF (ORCPT + 99 others); Fri, 28 Jul 2023 08:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234600AbjG1MO5 (ORCPT ); Fri, 28 Jul 2023 08:14:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF5D468B; Fri, 28 Jul 2023 05:13:19 -0700 (PDT) Message-ID: <20230728120931.171636739@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546396; 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=2HJ6gKC8xKh7ZYiNVCch9OIndLCiZ8cyEEDMpJCZ4Vw=; b=268An0Wdt8WDCqWB6ogz67S7THbiKKdr0joGalaA/BjcTBklK44CL33wZ/6AbFONyWJjUu WJyLIRBiaMEIETbPszvkvXljF+0OemFHLZ/yhG1bOywTkVfUaKLUevTKYeiYN2gmoLdaF3 HJjPW0G4To59aowXtQxrzEkzBJV9zapPbbZvrGoHgGgibub5m+dFVPTxhiDi9JPmCkuyFF XyMd8YGhO2FzbslZgxseWWn9NrkOgb1jCCGhJuIpA1wsyREOyQWhz1rRfTFQMrivtLy9H3 nfJdSr/YnSHsKtXkboJSzxnifb6Ru06uQAEKHDQgfxZwZaq4IqeYHB8ac/NIdw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546396; 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=2HJ6gKC8xKh7ZYiNVCch9OIndLCiZ8cyEEDMpJCZ4Vw=; b=ry2Er7K03tg+AZilQfvD5tNI69BX8w50u4TFKp8V1GLhVAZMyEQNR29HtTvzzUEhgnlbP+ Vq7R6HQdNAgRvvCQ== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 27/38] x86/cpu/amd: Provide a separate acessor for Node ID References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:16 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772669380494070099 X-GMAIL-MSGID: 1772669380494070099 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 --- 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 @@ -574,7 +574,7 @@ static void amd_pmu_cpu_starting(int cpu if (!x86_pmu.amd_nb_constraints) return; - nb_id = topology_die_id(cpu); + nb_id = topology_amd_node_id(cpu); WARN_ON_ONCE(nb_id == BAD_APICID); for_each_online_cpu(i) { --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -99,6 +99,9 @@ struct cpuinfo_topology { u32 logical_pkg_id; u32 logical_die_id; + // 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) +#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.die_id) + extern unsigned int __max_die_per_package; #ifdef CONFIG_SMP @@ -160,6 +162,11 @@ int topology_update_die_map(unsigned int int topology_phys_to_logical_pkg(unsigned int pkg); bool topology_smt_supported(void); +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_thread_mask) @@ -182,6 +189,7 @@ static inline int topology_max_die_per_p static inline int topology_max_smt_threads(void) { return 1; } static inline bool topology_is_primary_thread(unsigned int cpu) { return true; } static inline bool topology_smt_supported(void) { return false; } +static inline unsigned int topology_amd_nodes_per_pkg(void) { return 0; }; #endif /* !CONFIG_SMP */ 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 @@ -370,7 +370,7 @@ struct resource *amd_get_mmconfig_range( int amd_get_subcaches(int cpu) { - struct pci_dev *link = node_to_amd_nb(topology_die_id(cpu))->link; + struct pci_dev *link = node_to_amd_nb(topology_amd_node_id(cpu))->link; unsigned int mask; if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) @@ -384,7 +384,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 = node_to_amd_nb(topology_die_id(cpu)); + struct amd_northbridge *nb = node_to_amd_nb(topology_amd_node_id(cpu)); unsigned int reg; int cuid; --- 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; - node = topology_die_id(smp_processor_id()); + node = topology_amd_node_id(smp_processor_id()); this_leaf->nb = 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 @@ -1181,7 +1181,7 @@ static int threshold_create_bank(struct return -ENODEV; if (is_shared_bank(bank)) { - nb = node_to_amd_nb(topology_die_id(cpu)); + nb = node_to_amd_nb(topology_amd_node_id(cpu)); /* threshold descriptor already initialized on this node? */ if (nb && nb->bank4) { @@ -1285,7 +1285,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 = node_to_amd_nb(topology_die_id(smp_processor_id())); + nb = node_to_amd_nb(topology_amd_node_id(smp_processor_id())); nb->bank4 = NULL; } --- 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 == 4 && boot_cpu_data.x86 < 0x17) { - toggle_nb_mca_mst_cpu(topology_die_id(cpu)); - cpu = get_nbc_for_node(topology_die_id(cpu)); + toggle_nb_mca_mst_cpu(topology_amd_node_id(cpu)); + cpu = get_nbc_for_node(topology_amd_node_id(cpu)); } cpus_read_lock(); --- a/drivers/edac/amd64_edac.c +++ b/drivers/edac/amd64_edac.c @@ -1907,7 +1907,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 = topology_die_id(m->extcpu); + u16 mce_nid = topology_amd_node_id(m->extcpu); struct mem_ctl_info *mci; u8 start_bit = 1; u8 end_bit = 47; @@ -3438,7 +3438,7 @@ static void get_cpus_on_this_dct_cpumask int cpu; for_each_online_cpu(cpu) - if (topology_die_id(cpu) == nid) + if (topology_amd_node_id(cpu) == nid) cpumask_set_cpu(cpu, mask); } --- a/drivers/edac/mce_amd.c +++ b/drivers/edac/mce_amd.c @@ -1060,7 +1060,7 @@ static void decode_mc3_mce(struct mce *m static void decode_mc4_mce(struct mce *m) { unsigned int fam = x86_family(m->cpuid); - int node_id = topology_die_id(m->extcpu); + int node_id = topology_amd_node_id(m->extcpu); u16 ec = EC(m->status); u8 xec = XEC(m->status, 0x1f); u8 offset = 0; @@ -1188,7 +1188,7 @@ static void decode_smca_error(struct mce if ((bank_type == SMCA_UMC || bank_type == SMCA_UMC_V2) && xec == 0 && decode_dram_ecc) - decode_dram_ecc(topology_die_id(m->extcpu), m); + decode_dram_ecc(topology_amd_node_id(m->extcpu), m); } static inline void amd_decode_err_code(u16 ec) From patchwork Fri Jul 28 12:13:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127687 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp500880vqg; Fri, 28 Jul 2023 08:10:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8U/TaB4oPk3girAAMIQlIwQTkWZdYKWF/+K7cWXCcg2A6GvYOCo9I9pKFfl+2xHhnMG5i X-Received: by 2002:a17:902:9a06:b0:1bb:edd5:4644 with SMTP id v6-20020a1709029a0600b001bbedd54644mr1671708plp.68.1690557011015; Fri, 28 Jul 2023 08:10:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690557011; cv=none; d=google.com; s=arc-20160816; b=Zoe2VDy7QwQRe0OCElEDhWkbz5chkKoIRNte7nUex+q/ih2nPXqjIKkUYCYRXRbAEV O5OUvg1noc4jm1TwlH5HYxDx0hauJoBM0shifOw8kpspwd/INbcRAnYv8EDhARhz5mMc JYJdOM/nkIEoHUzFsI9wNumh0e7gNB8T25yDqpqbCBbQ9ItEmbBHf5cUG4v8Q2BGPaXa l98Ckn8JUVX581h1wvjTp0tA+RK+cS+EBfxsdU7NnS5s2ivPMlPR21pHv7nLYbEWCWd7 N7iQmMCNXJOtvXO+nv/ruVZ7XvBBJFwY2Sjk03f7u5QwzHYc1J3Ekrn4EB/Re4lbBNHB J2rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=AiIpnDgCXovqfdpged1yPFBSGlYqsnfbd48JRNcAym4=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=VRixz4yn+uhA970YblUWJ19TPsAYk+tZ7fzjPYXQxuc0fB00QjXGaWy9wLrEC1jf/B nO64ryJpMKoxoPfkujF+NhQk3Ti+Qzkwup5ewlrBtiRIASRqLV2hJ8fSsKsRTNurSXDw uQTKZfhenGdSvaAvic/VKLLo32uakiDyrZCNgV6RqPnp2vqxWmbc0iHHBc2EyjK9fKNT /wuz+P0ovcAy9jNUBoLsf0L5Z6pkapnvOaGiXt+DfJ1abGLKcP2jHoY9VPZV5/IQOHCL Uyri/Un0Xo1uECJW5xSKLtop1ZYi+uufasCFBQRRQ1l9uNLxSxTIY71rCfAMqb754DMY l4KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TJWA+vew; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jf18-20020a170903269200b001b9da8b4eb8si3147829plb.373.2023.07.28.08.09.50; Fri, 28 Jul 2023 08:10:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=TJWA+vew; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236482AbjG1MQI (ORCPT + 99 others); Fri, 28 Jul 2023 08:16:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236378AbjG1MPW (ORCPT ); Fri, 28 Jul 2023 08:15:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4F20468D; Fri, 28 Jul 2023 05:13:20 -0700 (PDT) Message-ID: <20230728120931.226185847@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546397; 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=AiIpnDgCXovqfdpged1yPFBSGlYqsnfbd48JRNcAym4=; b=TJWA+vewEGHcIKX9ZHG1lfkUl163BFeLfNavoHxZ1vj4nX25Oj7jCWaC5P0kpAcD7fm5Ww y3O5yHy7Fbv6NRUxWWDM/iAv3Ar8H7TZ/TrhtOLtZmTu3BD89zQhAt9z3mvfBayetrgE6r hFBIJchUHN+VUagIZJ8qbdzomvdx3ZJYN9TnqgucYIvzC4FI1Us1PbnKWfo6x3Lnu6yaEw 969PqvT2HER7JWFH1Q6ednX8cLo7GjbcoCLwDMHe3sTI+FjeggeG0iXwIsh+mH1JUi0MzD D4trudJxLD0Sniq5S967o2wQXaq0QQs9UlwniyzutcUvAGrTVKQBKSHS4SwH+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546397; 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=AiIpnDgCXovqfdpged1yPFBSGlYqsnfbd48JRNcAym4=; b=Z4sv9opZd+WrZySBhC4j23KPYFWu2hijwblgcvM95bTeDZnYogRrcI7VNsCBJataYHAEtE cE12Jm5FMYweyiCg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 28/38] x86/cpu: Provide an AMD/HYGON specific topology parser References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:17 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772677508450067926 X-GMAIL-MSGID: 1772677508450067926 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 superseeded by leaf 0x80000026 soon, which is just another variant of the Intel 0x1f leaf for whatever reasons. - 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 --- arch/x86/include/asm/topology.h | 2 arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/amd.c | 2 arch/x86/kernel/cpu/cacheinfo.c | 4 arch/x86/kernel/cpu/cpu.h | 2 arch/x86/kernel/cpu/debugfs.c | 2 arch/x86/kernel/cpu/topology.h | 6 + arch/x86/kernel/cpu/topology_amd.c | 179 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/topology_common.c | 19 +++ 9 files changed, 211 insertions(+), 7 deletions(-) --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -162,6 +162,8 @@ int topology_update_die_map(unsigned int int topology_phys_to_logical_pkg(unsigned int pkg); bool topology_smt_supported(void); +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 := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology_ext.o topology.o +obj-y += topology_common.o topology_ext.o topology_amd.o topology.o obj-y += common.o obj-y += rdrand.o obj-y += match.o --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -356,7 +356,7 @@ static void amd_get_topology(struct cpui if (!err) c->x86_coreid_bits = get_count_order(c->x86_max_cores); - cacheinfo_amd_init_llc_id(c); + cacheinfo_amd_init_llc_id(c, c->topo.die_id); } 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; } -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 if (c->x86 < 0x17) { /* LLC is at the node level. */ - c->topo.llc_id = c->topo.die_id; + c->topo.llc_id = die_id; } else if (c->x86 == 0x17 && c->x86_model <= 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); -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); unsigned int aperfmperf_get_khz(int cpu); --- a/arch/x86/kernel/cpu/debugfs.c +++ b/arch/x86/kernel/cpu/debugfs.c @@ -27,6 +27,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 { // 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; }; 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 dom, 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); 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,179 @@ +// 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 = ecx.apicidsize; + if (!sft) + sft = 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 its 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 = nr_nodes; + tscan->amd_node_id = 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 = leaf.x2apic_id; + + /* + * If leaf 0xb is available, then SMT shift is set already. If not + * take it from ecx.threads_per_cpu and use topo_update_dom() as + * topology_set_dom() would propagate and overwrite the already + * propagated CORE level. + */ + if (!has_0xb) { + topology_update_dom(tscan, TOPO_SMT_DOMAIN, get_count_order(leaf.threads_per_cu), + leaf.threads_per_cu); + } + + store_node(tscan, leaf.nodes_per_pkg + 1, leaf.nodeid); + + if (tscan->c->x86_vendor == X86_VENDOR_AMD) { + if (tscan->c->x86 == 0x15) + tscan->c->topo.cu_id = leaf.cuid; + + cacheinfo_amd_init_llc_id(tscan->c, leaf.nodeid); + } else { + /* + * Pacakge ID is ApicId[6..] on 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]. Don't touch the latter without + * confirmation from the Hygon developers. + */ + 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 = nid.node_id; + return true; +} + +static void legacy_set_llc(struct topo_scan *tscan) +{ + unsigned int apicid = tscan->c->topo.initial_apicid; + + /* parse_8000_0008() set everything up except llc_id */ + tscan->c->topo.llc_id = apicid >> tscan->dom_shifts[TOPO_CORE_DOMAIN]; +} + +static void parse_topology_amd(struct topo_scan *tscan) +{ + bool has_0xb = 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 = 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 = 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 = 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 %= tscan->dom_ncpus[TOPO_CORE_DOMAIN] / tscan->amd_nodes_per_pkg; +} --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -11,11 +11,13 @@ struct x86_topology_system x86_topo_system __ro_after_init; +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 dom, unsigned int shift, unsigned int ncpus) { - tscan->dom_shifts[dom] = shift; - tscan->dom_ncpus[dom] = ncpus; + topology_update_dom(tscan, dom, shift, ncpus); /* Propagate to the upper levels */ for (dom++; dom < TOPO_MAX_DOMAIN; dom++) { @@ -145,6 +147,13 @@ static void topo_set_ids(struct topo_sca /* Relative core ID */ c->topo.core_id = topo_relative_domain_id(apicid, TOPO_CORE_DOMAIN); + + /* Temporary workaround */ + if (tscan->amd_nodes_per_pkg) + c->topo.amd_node_id = c->topo.die_id = tscan->amd_node_id; + + if (c->x86_vendor == X86_VENDOR_AMD) + cpu_topology_fixup_amd(tscan); } static void topo_set_max_cores(struct topo_scan *tscan) @@ -229,4 +238,10 @@ void __init cpu_init_topology(struct cpu */ __max_die_per_package = 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 (yet). + */ + if (c->x86_vendor == X86_VENDOR_AMD || c->x86_vendor == X86_VENDOR_HYGON) + __amd_nodes_per_pkg = __max_die_per_package = tscan.amd_nodes_per_pkg; } From patchwork Fri Jul 28 12:13:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp415505vqg; Fri, 28 Jul 2023 06:01:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlEZFoPqFFFK8yu1PLQ3XzxJtLLyxeOBAkfLqK4lZt/nLIeIN/2lZ2tc7p0TTfv7cLMZqkYu X-Received: by 2002:a17:90a:a798:b0:267:f094:afcf with SMTP id f24-20020a17090aa79800b00267f094afcfmr1193337pjq.12.1690549266500; Fri, 28 Jul 2023 06:01:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690549266; cv=none; d=google.com; s=arc-20160816; b=p5HURKKrsZffc+IVLDdKAwTS/4eCpTTbDD5by1LZ8IP9Cm7Lqd0DvU1JMQE2yD4Uc9 yca7mk2nZrgjhZDIFkfdQ6O7Qr958hKjJjibkyithpN3iVs2uPPKhyzG8qhIqnGvKtsC mZOWY8Y+6YpkLIPmK3rQt1lZtKhXinrW1MciF5mX9Mc0VCGwoKvkVnv1QEayrO4n7K8+ TFlU4QpChbnYEMVgnZ38reYjOWdJ7A5UZshsTpmZserSI3bo/0Z+EgfPXMQ9pxLkUPEi LxacFKZqeBkqt8v/VWDeb+3S2ZtdbMFy3tFgghiRe3ewnukuPFsYLnYgMaqPaySAE3Sv Nvwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=4pQHURzHcwcFZ9S0vbzPTsi43pbiloyiG3aJ+/xAmII=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=UXuNJrU+AgGQSqnK9YnwiNFsNvvmaKg8uQvYCXWakZ2MkkVFqW8LlN2A2jKr4IyKXE Wq766UQCBs+ibLcby5GTFkrVbxWUGTzjY0NJ6wfen1u2/BEZqLMnwRgoi2OwhpE8wAph 4YNmMf0rv77PzqMUrlDTUbNBm+yMuuNS7UXd/zTJUHaJVB3oy19ntB6L8CO/DzhpSKap 9Chk4K26yWN/U6ut9ksLNVKShXvEUYXKcB/QCC+MWEudIduAtPid7PkTya+6pgDGQkxR GkcSUV3Vk3uDPK49vlVbo+KjiausEE6fwmzzBgQDFjPuTXD85q3GIr3Fs4DM2KftiGJ2 IIVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2uxuTBpL; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a17090ad30100b00268122b5e44si916784pju.134.2023.07.28.06.00.51; Fri, 28 Jul 2023 06:01:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2uxuTBpL; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236579AbjG1MQU (ORCPT + 99 others); Fri, 28 Jul 2023 08:16:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233770AbjG1MPZ (ORCPT ); Fri, 28 Jul 2023 08:15:25 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4717346B3; Fri, 28 Jul 2023 05:13:22 -0700 (PDT) Message-ID: <20230728120931.280604061@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546399; 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=4pQHURzHcwcFZ9S0vbzPTsi43pbiloyiG3aJ+/xAmII=; b=2uxuTBpLwnNiWyOhNirtwcOZpXwsG5iYOGFKkk99p4gjv1Oj/UngUBmdoPuvcVAjIiN93Z Sx2kaSkgPgpSWs4Rg7uoHcdnWZ5PKbWM8AfjsqSLM4URWGaCs8mZPenAnBIlIMN3Fj6kgm aMzoJVmcJotI7QeMswhSuvMjcAWPmNowqMe44Y6IpY214nOPHimYFzbg3F2U2t9LZMIiRo T63RAeQEKfj7M8DfJyO+9k2OOQm3GIrmhNbAnsuY4/3UzGDUJnGRkSbRrDtRTk0gibHa49 Vo+e93PhMaoNznQyDGsU2WX43qHtv3zTKUgCCpWOjEf4+Fk4b1f5lVLNGoPl4g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546399; 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=4pQHURzHcwcFZ9S0vbzPTsi43pbiloyiG3aJ+/xAmII=; b=LnATTY+oDj8YYsxyo2raV/mPTp7jHEzbX3HxCfkoy8KZGvnR5TSACd4nF/Kli099gpgUGo avDL74KfZwjcj7Cg== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 29/38] x86/smpboot: Teach it about topo.amd_node_id References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:18 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772669387757041307 X-GMAIL-MSGID: 1772669387757041307 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 --- 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 @@ -486,6 +486,7 @@ static bool match_smt(struct cpuinfo_x86 if (c->topo.pkg_id == o->topo.pkg_id && c->topo.die_id == o->topo.die_id && + c->topo.amd_node_id == o->topo.amd_node_id && per_cpu_llc_id(cpu1) == per_cpu_llc_id(cpu2)) { if (c->topo.core_id == o->topo.core_id) return topology_sane(c, o, "smt"); @@ -507,10 +508,13 @@ static bool match_smt(struct cpuinfo_x86 static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { - if (c->topo.pkg_id == o->topo.pkg_id && - c->topo.die_id == o->topo.die_id) - return true; - return false; + if (c->topo.pkg_id != o->topo.pkg_id || c->topo.die_id != 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 == o->topo.amd_node_id; + + return true; } static bool match_l2c(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) From patchwork Fri Jul 28 12:13:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp419810vqg; Fri, 28 Jul 2023 06:05:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlG9T68dtQC1ls1pFgvyvJDmYavpE3IQ8wJhZOmDHEi1Xfztu3e6aG6uww0Kyht/OUpllmUO X-Received: by 2002:aa7:c994:0:b0:51e:f83:6de6 with SMTP id c20-20020aa7c994000000b0051e0f836de6mr1625344edt.16.1690549552294; Fri, 28 Jul 2023 06:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690549552; cv=none; d=google.com; s=arc-20160816; b=lcH7olAXDgiRTAe9Id0RfFVC5zkmiW9uZcnmDC+PSedGTnPUQwxwkGDnLPWKAALP7v CL4igttG11Nty12tWFjWsAMOMZseopQ9hEgfWrQPuaxlnpaZgsAtWyjbySXlJmn0EZ7b SgEzhv/JwtK6qLWm2baaiXC8DdjRngItst8IKVABStyb8NdfpTfdQYnolLEmPpKCYxaG RffWEvBIAYYtJSoOJjTpcHb2L0WZTtTIAKpbEfqNem+hgmGCISSWYHB1CQI0/xUlly3x gsidPbn3pT/twPU7f6BY+qb1pVAwTB3dT7poe2babtkFMDnp1xcKh3GmXH2mJnQ53uAr fpTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=yNNNqA4YmsDMwHMpycsoN40Z1ogmgffhWH84zvaD3i8=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=TuRS2IMZGN3HB+xF/M2XUmytFB1YpuX+9KJvub3gzAfpFAfKwILp7ZSSTpwhSfVSGW OO7e/KlPRYclTt3jB1yr1Ck0QK3i6DLfSGh1VEMdxXAMf+wTLZV0h3yBoBoTIseVB1eI p/TBOVD4Pl6Tlql5sPVTD8jPv6v0yFO5MriadeuFwPx+Dan7BK3awetp/JjGstbaSDnU 1esSqL8EUh+tS+BUA8VJjxkbmc21gXFz5s56+3g9Z+L+yktbp2wAyUQTU/MH6BNg+jqL ADdSkdQ/1rnH5wTP3mtL13oGQKy0rif3SdNUASUK0iCffMto++SZD+/8zD1Jd8XJynhF u5/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EXlo5xhl; dkim=neutral (no key) header.i=@linutronix.de header.b="cry/+3UO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020a056402164d00b005222b1807e7si2561152edx.370.2023.07.28.06.05.16; Fri, 28 Jul 2023 06:05:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EXlo5xhl; dkim=neutral (no key) header.i=@linutronix.de header.b="cry/+3UO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236585AbjG1MQX (ORCPT + 99 others); Fri, 28 Jul 2023 08:16:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235301AbjG1MP0 (ORCPT ); Fri, 28 Jul 2023 08:15:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8977830DC; Fri, 28 Jul 2023 05:13:23 -0700 (PDT) Message-ID: <20230728120931.335390967@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546400; 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=yNNNqA4YmsDMwHMpycsoN40Z1ogmgffhWH84zvaD3i8=; b=EXlo5xhlHD3lPrnSXvLvoN+ve0JzPvTXRPojcdFCVw01PHAGj9cQv20XRzgYYKjpOCQfHX 4ENkaPbwcMSuqPhTvEtX5PQzVVM/Rb0tO9+ealxte4Dqp53rzblJVHi8qN/bm1aW5woU8h yT0DQSz5m4pVQP9cONWaoWBF385pcnoXLGW7EUg0LVmTzkl8bXZMz4kyj6HoJB9Ty1UHkp PhU6NG0F09A1hqz+URXf40G2gw17ljERM0DRpjYE0qv+/8lGrFDtwsmQH/h7MzO9OrrnQg Obj/MdGKqZP2gMwmrh/aN4uEBplCFJhzqj2WJyk6RbmW1rYTZYkRzyBu2XyeQw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546400; 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=yNNNqA4YmsDMwHMpycsoN40Z1ogmgffhWH84zvaD3i8=; b=cry/+3UOBJk73zkqqoxGZ6zQ6/H6NHFN7DyINX3p/DwkwgUGXVC375PduiJG9/CgibzorW d8HUYMJ4+7Ub/kDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 30/38] x86/cpu: Use common topology code for AMD References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:20 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772669687298685000 X-GMAIL-MSGID: 1772669687298685000 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 --- arch/x86/include/asm/processor.h | 2 arch/x86/include/asm/topology.h | 5 + arch/x86/kernel/cpu/amd.c | 146 ---------------------------------- arch/x86/kernel/cpu/mce/inject.c | 3 arch/x86/kernel/cpu/topology_common.c | 5 - 5 files changed, 10 insertions(+), 151 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -703,10 +703,8 @@ static inline u16 per_cpu_l2c_id(unsigne } #ifdef CONFIG_CPU_SUP_AMD -extern u32 amd_get_nodes_per_socket(void); extern u32 amd_get_highest_perf(void); #else -static inline u32 amd_get_nodes_per_socket(void) { return 0; } static inline u32 amd_get_highest_perf(void) { return 0; } #endif --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -121,6 +121,11 @@ struct x86_topology_system { extern struct x86_topology_system x86_topo_system; +static inline unsigned int topology_get_domain_size(enum x86_topology_domains 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); --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -32,13 +32,6 @@ static const int amd_erratum_400[]; static const int amd_erratum_1054[]; static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum); -/* - * 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 = 1; - static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p) { u32 gprs[8] = { 0 }; @@ -305,97 +298,6 @@ static int nearby_node(int apicid) } #endif -/* - * 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 >= 0x17) - return; - - cus_per_node = c->x86_max_cores / nodes_per_socket; - c->topo.core_id %= 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 = ecx & 0xff; - - if (c->x86 == 0x15) - c->topo.cu_id = ebx & 0xff; - - if (c->x86 >= 0x17) { - c->topo.core_id = ebx & 0xff; - - 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); - - 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 = value & 7; - c->topo.llc_id = 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 = c->x86_coreid_bits; - /* Low order bits define the core id (index of core in socket) */ - c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); - /* Convert the initial APIC ID into the socket ID */ - c->topo.pkg_id = c->topo.initial_apicid >> bits; - /* use socket ID also for last level cache */ - c->topo.llc_id = c->topo.die_id = 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 @@ -447,32 +349,6 @@ static void srat_detect_node(struct cpui #endif } -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 = cpuid_ecx(0x80000008); - - c->x86_max_cores = (ecx & 0xff) + 1; - - /* CPU telling us the core id bits shift? */ - bits = (ecx >> 12) & 0xF; - - /* Otherwise recompute */ - if (bits == 0) { - while ((1 << bits) < c->x86_max_cores) - bits++; - } - - c->x86_coreid_bits = bits; -#endif -} - static void bsp_init_amd(struct cpuinfo_x86 *c) { if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { @@ -505,18 +381,6 @@ static void bsp_init_amd(struct cpuinfo_ if (cpu_has(c, X86_FEATURE_MWAITX)) use_mwaitx_delay(); - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - u32 ecx; - - ecx = cpuid_ecx(0x8000001e); - __max_die_per_package = nodes_per_socket = ((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 = nodes_per_socket = ((value >> 3) & 7) + 1; - } - if (!boot_cpu_has(X86_FEATURE_AMD_SSBD) && !boot_cpu_has(X86_FEATURE_VIRT_SSBD) && c->x86 >= 0x15 && c->x86 <= 0x17) { @@ -598,8 +462,6 @@ static void early_init_amd(struct cpuinf u64 value; u32 dummy; - early_init_amd_mc(c); - if (c->x86 >= 0xf) set_cpu_cap(c, X86_FEATURE_K8); @@ -687,9 +549,6 @@ static void early_init_amd(struct cpuinf } } } - - if (cpu_has(c, X86_FEATURE_TOPOEXT)) - smp_num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; } static void init_amd_k8(struct cpuinfo_x86 *c) @@ -929,9 +788,6 @@ static void init_amd(struct cpuinfo_x86 if (cpu_has(c, X86_FEATURE_FSRM)) set_cpu_cap(c, X86_FEATURE_FSRS); - /* get apicid instead of initial apic id from cpuid */ - c->topo.apicid = 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); @@ -959,8 +815,6 @@ static void init_amd(struct cpuinfo_x86 cpu_detect_cache_sizes(c); - amd_detect_cmp(c); - amd_get_topology(c); srat_detect_node(c); 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 = &boot_cpu_data; u32 cores_per_node; - cores_per_node = (c->x86_max_cores * smp_num_siblings) / amd_get_nodes_per_socket(); - + cores_per_node = (c->x86_max_cores * smp_num_siblings) / topology_amd_nodes_per_pkg(); return cores_per_node * node_id; } --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -65,7 +65,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: @@ -126,6 +125,10 @@ static void parse_topology(struct topo_s tscan->ebx1_nproc_shift = get_count_order(ebx.nproc); 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 patchwork Fri Jul 28 12:13:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127597 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp405122vqg; Fri, 28 Jul 2023 05:40:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlEuGd+Am8AB1VAD05fnIaeQ06YIPMQ6VsJEvySka1sNcuC3bOBc+BgTtLfKZr298F1IJH7/ X-Received: by 2002:aa7:da81:0:b0:522:2f8c:8953 with SMTP id q1-20020aa7da81000000b005222f8c8953mr1539143eds.39.1690548045858; Fri, 28 Jul 2023 05:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548045; cv=none; d=google.com; s=arc-20160816; b=HdV0sOKM53WdpHbhuxSLmI61KEDIgchAFJY13jFU5VmWYkp2UPeYAOTRo7iEvcFnNC szvJL2OfZcCdQ7y+Kh3SUqMy95OEaIMItzotf3ML0kZC3CVznyh4hpF6SrOXOqmGh0W1 FwkY75gduCi84msHPQu6kCnIXk6qmiw03T/H4HmdtszDoN231vGDvj/uZMqrPPqG+Qkb 5+ylbWfnBmawNF+vdS9o5FuclaTnSVuohK3C7UWyoeJRp2A0yD41qrmyJ+yxj4ENYXpG 9cvwgayw/0AfR4gP3bgGqR2CIAdyL5TO6jX+egVNbXF/LkfB0AMGJPnOioQWtVm5R2kD 9T8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=cKAYZyjPZyLQruSPE+euoA5SHlzUu7NxwCy0PweV3wQ=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=0EsjlcV8Lu+iD6EkyAHn7rg+m+m2ELi42lPROBujgpt2FbatGX+CuJdeEW1RAO+myX JFuIN8uNXrywd00AczdsSbKU5MIULdQlmleXalNuj/Zyss5NNj0RqkwFuxchX3f4U4Uf S99Q9gVHhFc9OfsRZUoE9h0L1LfOpMENECHAfpLa60RGmXhh85ECZCUy71a1Ec+emOfY 0pCIv6+D2GQqt9HoXf791DnNmNSqnQQ+dCexzRo1eqqC9qyepuAd2qtftzjrLk7bYbmc 4rE/fFGIShkrXTDrUqo2JS+BO0xtLWHgtZZBeMHC2F8uIjWQGSi46+wyXQri3ixXosiP NH4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ez37EywE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=P9bdI0zO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v11-20020aa7dbcb000000b005227d29788csi2437742edt.352.2023.07.28.05.40.21; Fri, 28 Jul 2023 05:40:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ez37EywE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=P9bdI0zO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236597AbjG1MQl (ORCPT + 99 others); Fri, 28 Jul 2023 08:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236544AbjG1MPc (ORCPT ); Fri, 28 Jul 2023 08:15:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB9DA3AB7; Fri, 28 Jul 2023 05:13:23 -0700 (PDT) Message-ID: <20230728120931.389991894@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546401; 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=cKAYZyjPZyLQruSPE+euoA5SHlzUu7NxwCy0PweV3wQ=; b=Ez37EywE1ZklXFB145X3pS/b9UEj9QquxLGmck5ll35RLUBiDkc5M1UXvYgSxltWLsvxdA T/NGBWbP6TptEuVegwRKCJprcdv9lMrc8jWj6FhchH5f0qPN6lC7j67zQIdnbpF66aWmNw /48eshwkM0xSrLRtXtgvNmODIDWS+6Jl600vFRc4LYXF/WnTULB60hU1kBQVMtPfiJWgKQ leyuq1F/VRuifLYvMke+ynsos05a1W9KzU4Aujq9sJ00omp9KSh9ixnLS8Ok+InynyLX7K gjJDGgHa185D4IdblIjXW0F7uB4vvxxETY5J5rW2Rtw944nG8UKSGsokRZDhsA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546401; 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=cKAYZyjPZyLQruSPE+euoA5SHlzUu7NxwCy0PweV3wQ=; b=P9bdI0zOh5LYFj0WtRefJYfg1TqFhpb0es8smjvOLjequKInRs1KsORzQRudeHpKDRWVLN cHq75iNi3fVJTyCw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 31/38] x86/cpu: Use common topology code for HYGON References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:21 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668107867729086 X-GMAIL-MSGID: 1772668107867729086 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 --- arch/x86/kernel/cpu/common.c | 5 - arch/x86/kernel/cpu/cpu.h | 1 arch/x86/kernel/cpu/hygon.c | 123 ---------------------------------- arch/x86/kernel/cpu/topology.h | 1 arch/x86/kernel/cpu/topology_common.c | 22 +----- 5 files changed, 4 insertions(+), 148 deletions(-) --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1739,11 +1739,6 @@ static void identify_cpu(struct cpuinfo_ /* Clear/Set all flags overridden by options, after probe */ apply_forced_caps(c); -#ifdef CONFIG_X86_64 - if (!topo_is_converted(c)) - c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); -#endif - /* * Vendor-specific initialization. In this section we * canonicalize the feature flags, meaning if there are --- 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); -extern int detect_extended_topology(struct cpuinfo_x86 *c); extern void check_null_seg_clears_base(struct cpuinfo_x86 *c); 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 @@ -20,12 +20,6 @@ #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 = 1; - #ifdef CONFIG_NUMA /* * To workaround broken NUMA config. Read the comment in @@ -49,76 +43,6 @@ static int nearby_node(int apicid) } #endif -static void hygon_get_topology_early(struct cpuinfo_x86 *c) -{ - if (cpu_has(c, X86_FEATURE_TOPOEXT)) - smp_num_siblings = ((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 = ecx & 0xff; - - c->topo.core_id = ebx & 0xff; - - 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->topo.pkg_id = 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 = value & 7; - c->topo.llc_id = 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 = c->x86_coreid_bits; - /* Low order bits define the core id (index of core in socket) */ - c->topo.core_id = c->topo.initial_apicid & ((1 << bits)-1); - /* Convert the initial APIC ID into the socket ID */ - c->topo.pkg_id = c->topo.initial_apicid >> bits; - /* Use package ID also for last level cache */ - c->topo.llc_id = c->topo.die_id = c->topo.pkg_id; -} - static void srat_detect_node(struct cpuinfo_x86 *c) { #ifdef CONFIG_NUMA @@ -169,32 +93,6 @@ static void srat_detect_node(struct cpui #endif } -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 = cpuid_ecx(0x80000008); - - c->x86_max_cores = (ecx & 0xff) + 1; - - /* CPU telling us the core id bits shift? */ - bits = (ecx >> 12) & 0xF; - - /* Otherwise recompute */ - if (bits == 0) { - while ((1 << bits) < c->x86_max_cores) - bits++; - } - - c->x86_coreid_bits = bits; -#endif -} - static void bsp_init_hygon(struct cpuinfo_x86 *c) { if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { @@ -208,18 +106,6 @@ static void bsp_init_hygon(struct cpuinf if (cpu_has(c, X86_FEATURE_MWAITX)) use_mwaitx_delay(); - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { - u32 ecx; - - ecx = cpuid_ecx(0x8000001e); - __max_die_per_package = nodes_per_socket = ((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 = nodes_per_socket = ((value >> 3) & 7) + 1; - } - if (!boot_cpu_has(X86_FEATURE_AMD_SSBD) && !boot_cpu_has(X86_FEATURE_VIRT_SSBD)) { /* @@ -238,8 +124,6 @@ static void early_init_hygon(struct cpui { u32 dummy; - early_init_hygon_mc(c); - set_cpu_cap(c, X86_FEATURE_K8); rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy); @@ -280,8 +164,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); } static void init_hygon(struct cpuinfo_x86 *c) @@ -296,9 +178,6 @@ static void init_hygon(struct cpuinfo_x8 set_cpu_cap(c, X86_FEATURE_REP_GOOD); - /* get apicid instead of initial apic id from cpuid */ - c->topo.apicid = read_apic_id(); - /* * XXX someone from Hygon needs to confirm this DTRT * @@ -310,8 +189,6 @@ static void init_hygon(struct cpuinfo_x8 cpu_detect_cache_sizes(c); - hygon_detect_cmp(c); - hygon_get_topology(c); srat_detect_node(c); 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; }; -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 dom, --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -61,18 +61,6 @@ static void parse_legacy(struct topo_sca topology_set_dom(tscan, TOPO_CORE_DOMAIN, core_shift, cores >> smt_shift); } -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) { /* @@ -137,6 +125,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; } } @@ -179,9 +171,6 @@ void cpu_parse_topology(struct cpuinfo_x parse_topology(&tscan, false); - if (!topo_is_converted(c)) - return; - for (dom = TOPO_SMT_DOMAIN; dom < TOPO_MAX_DOMAIN; dom++) { if (tscan.dom_shifts[dom] == x86_topo_system.dom_shifts[dom]) continue; @@ -210,9 +199,6 @@ void __init cpu_init_topology(struct cpu 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_system.dom_shifts)); From patchwork Fri Jul 28 12:13:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp407061vqg; Fri, 28 Jul 2023 05:44:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlGlUi3viK3RBXbTrRiaXBSfngPoG8y42j5m7ThlWHy477YOnpNvO89FaeAsQPZBaNFTzfyW X-Received: by 2002:a05:6a00:1302:b0:686:bd88:605e with SMTP id j2-20020a056a00130200b00686bd88605emr1844247pfu.11.1690548262191; Fri, 28 Jul 2023 05:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548262; cv=none; d=google.com; s=arc-20160816; b=KwcdviH+oyZY/jIINQbiJXNvFNMVznA8tWXQpUfEWnxAJFZrRq2SICxq51cH4mKwHg h1k7yJ85+EFHzCBo3xukqAyIXci2HielVMKvHJ7/dvHJGaaHBkqee1GpCx3cBNgNEYB3 Qlha+fb/7bAwHNW8iY5CkaPNjbHwFrgfOojXqernu2C+LPjkxs5OjVU7WLBEyGeg9IqH mXXosDUXW/PDFLIMVR45tMItXraD8wULqE+MHyrTWRFs3UZwGAZ7/EMjD9xJQyctMdak xfvSmoJSK4+dP2MMCkCiiccUxqjHh3NLGkW6qHL6kWUcYlUu8AQX14vkQ9fBlo+MEiK1 cgiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=v1jagm3qezJbhLi1KwbMq1PXX83lXTZZ+4TGqrP0z90=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=xt+JYr3z5aiLYnwc1fxupTCDeUUeOAjl04QM2Y2uyk6u7AuxMo0oDoymkuDi4xJhT1 RR2EKkvPAsXDFYJKsJ4e+4UPYtNaDhRCawq5OO31S9aAR12oR3rP6J5bHGDukTJgaWZo 2T0TlGM+Qn9sQWI3zSknBfG4YSXpu1zp9yWdTMkFjycPRcT6VlregTPlzn5o732HijPa fMhE6I1joVkNGbOBnjIjY9YQX1dJpMmmPlVI4kIhTdRC0OrzbqybebgWlYveUiSjPyxA 6cOZIz1CdIurV5QxH/XpI+yqaytr3z9553QcdumO5E20eJ7Wu6Q/KnZnAWurB4S5ufr6 eIJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OaTxVvEk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vjKBc1lA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay21-20020a056a00301500b006862e207c34si3104966pfb.66.2023.07.28.05.44.09; Fri, 28 Jul 2023 05:44:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OaTxVvEk; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vjKBc1lA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236589AbjG1MQ1 (ORCPT + 99 others); Fri, 28 Jul 2023 08:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234567AbjG1MPb (ORCPT ); Fri, 28 Jul 2023 08:15:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78C1949CC; Fri, 28 Jul 2023 05:13:24 -0700 (PDT) Message-ID: <20230728120931.448157949@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546402; 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=v1jagm3qezJbhLi1KwbMq1PXX83lXTZZ+4TGqrP0z90=; b=OaTxVvEkBn8or9jvNdmQrVSkU7kbk6MdUYHBPqPvE3wbQk91EKdmBkdwW5cTUh0ohjVeZ/ 12rsXDyg/bDlbfRu5PQDd2wnvaxpTqYmed4W8xQCBeFIZeHfFqTxccMjm77jD4t/LmEE1g FzqGG24CYrpgWPN7yF8zMw0SMqm4PojNWv4ohANuHzeA3Li1O2Pe+7cmHFI1eZyI9awM4i 5KVSm+7/Ts4oVObTBC5T2vcvMjy6g7yyQdZBQnWV85yhhrZTdopob/PWtaIJvjWCOGAWBk g2OaccF3YJckfYJfKdtYSxcpKSvoS2/OGETHJUXA5WkQa0e7kFfVHE67BYw5qg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546402; 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=v1jagm3qezJbhLi1KwbMq1PXX83lXTZZ+4TGqrP0z90=; b=vjKBc1lAvNSZpBzqQct6EMy+KlJwl47uNDI5KZB7JlhCw7KdOCBpBKMVBDQ/FCoheBWmal ewVNnLaHvO6uwXDw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 32/38] x86/mm/numa: Use core domain size on AMD References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:22 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668334744431878 X-GMAIL-MSGID: 1772668334744431878 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 --- arch/x86/mm/amdtopology.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) --- a/arch/x86/mm/amdtopology.c +++ b/arch/x86/mm/amdtopology.c @@ -54,13 +54,11 @@ static __init int find_northbridge(void) int __init amd_numa_init(void) { - u64 start = PFN_PHYS(0); + unsigned int numnodes, cores, apicid; + u64 prevbase, start = PFN_PHYS(0); u64 end = 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; if (!early_pci_allowed()) return -EINVAL; @@ -158,26 +156,25 @@ int __init amd_numa_init(void) return -ENOENT; /* - * 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 = boot_cpu_data.x86_coreid_bits; - cores = 1 << bits; - apicid_base = 0; + cores = topology_get_domain_size(TOPO_CORE_DOMAIN); /* - * 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(); - if (boot_cpu_physical_apicid > 0) { - pr_info("BSP APIC ID: %02x\n", boot_cpu_physical_apicid); - apicid_base = boot_cpu_physical_apicid; + apicid = 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 = 0; j < cores; j++, apicid++) + set_apicid_to_node(apicid, i); } - - for_each_node_mask(i, numa_nodes_parsed) - for (j = apicid_base; j < cores + apicid_base; j++) - set_apicid_to_node((i << bits) + j, i); - return 0; } From patchwork Fri Jul 28 12:13:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp406318vqg; Fri, 28 Jul 2023 05:42:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlHs9k56ejmvxHi2Xkx6SgAko9FqT7LoE17H8Vat2nWr7dUo3oVyJqDfkddwrfLAJLHbAGfp X-Received: by 2002:a17:903:1246:b0:1b6:9fec:8134 with SMTP id u6-20020a170903124600b001b69fec8134mr1889258plh.46.1690548177993; Fri, 28 Jul 2023 05:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548177; cv=none; d=google.com; s=arc-20160816; b=nIjkOlbVdiSFwPwgXfIhVXiB/h0zEmNsugpkF8uwGNqJL3G9DLwxIIamrYT5KbY1JJ q1VeOSNATwG6mUQTjsOC0KZb2b4G+mv6BP1XF+uG6aWM6Fpg6YnPEk9g6/1SsPjokFPM Jf499UUjbWACz7zYRFGIjvp0uiQ1+BCqnI97wNOR7IotMVCH779Vrry9UbTzM3KQeT1V 7CWowW5/nBWYapp9Z9XXsAdw+cX0lis516uKLQVvtRIdYBVtiPw0iNmTmJ0ISinEpy+P CnX4IXsoY2C1N5UXqY2d4PzwTZJP+fkBrHQDlxFCh4pc+pBCpjh2gVIffMRCDBh4B76h hlEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=u2nALLK7m8WtmbLIhAtObAjpwOgRje3zo0FH2XahcbM=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=QvKDGKQ7UFmAiiQqveFJqG/9MQ1r0hr+TLH3Mzqn9kHuLON6C6sWd3ROSY46C094d1 9hkcxpHOw7NC+YUqoFWcCoJWHZ3SH13L/pXVcVd3O+xFckGGmputiAyS/PtSdabe18Rv v3VXtGTdebUWwdtxVkh1RfpMeNak3qVdwS7u5HOQb9Z6aoqyShgbdu1VGXxuf3ozkeui yOFcgt+hnDJNs2ARZ5erpY+kQfX92zNpr9G9+kGdavUz+SVIgi26aW4ZTTIl9GYErs3K vmWRL7d0rwji9ly+Rv/VuSomukiQR7c3TCdOdfcFPU32sp6twW0viJ4uW8mVjG+x1P13 SHGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GIvlp94L; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a1709029b8c00b001b8a591d5b9si2968917plp.133.2023.07.28.05.42.44; Fri, 28 Jul 2023 05:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GIvlp94L; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236603AbjG1MQy (ORCPT + 99 others); Fri, 28 Jul 2023 08:16:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236513AbjG1MPn (ORCPT ); Fri, 28 Jul 2023 08:15:43 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06F0349E2; Fri, 28 Jul 2023 05:13:25 -0700 (PDT) Message-ID: <20230728120931.505785260@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546403; 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=u2nALLK7m8WtmbLIhAtObAjpwOgRje3zo0FH2XahcbM=; b=GIvlp94LV25tQrX80pxbX/N70wOTOXl1hgm7O+jOavcl0fQA2otJl17nloVDkKpxNsC+tf VqhBvakOcB+OEaQBOilNAcwansF4pm2rplTzJvmFkP8+2Dvv2PdTPZE/Ue8oh7acRjdqnz slBG2awD5EDNozNpnKV6AI6lDHA+8XcylXRRHAsHWm++PPHfr+QQCHueFPrAdHLfDzfCZ7 v/I/fIYM0A7j7kwe6PFkKUiSvx/t9BzMIIwMsG0djbeI0Oadafq8sDzHNx/5udykaHWLTL 3j2IWHY7Yp1v8V2DaBJhpotKV/aU3km1rfD4wCBhT6UThxZz04OTKt7TleAvPw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546403; 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=u2nALLK7m8WtmbLIhAtObAjpwOgRje3zo0FH2XahcbM=; b=xHo81PcfzjVzlw4YP6rbYGVCqC/Pe6iPvoQokP8a/dLP6VigQIChE6ZgDwpueKeHkYjTNC spr9cjMUyha7RtCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 33/38] x86/cpu: Make topology_amd_node_id() use the actual node info References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:23 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668246584026374 X-GMAIL-MSGID: 1772668246584026374 Now that everything is converted switch it over and remove the intermediate operation. Signed-off-by: Thomas Gleixner --- 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) -#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) extern unsigned int __max_die_per_package; @@ -171,7 +171,7 @@ extern unsigned int __amd_nodes_per_pkg; static inline unsigned int topology_amd_nodes_per_pkg(void) { - return __max_die_per_package; + return __amd_nodes_per_pkg; } extern struct cpumask __cpu_primary_thread_mask; --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -143,9 +143,7 @@ static void topo_set_ids(struct topo_sca /* Relative core ID */ c->topo.core_id = topo_relative_domain_id(apicid, TOPO_CORE_DOMAIN); - /* Temporary workaround */ - if (tscan->amd_nodes_per_pkg) - c->topo.amd_node_id = c->topo.die_id = tscan->amd_node_id; + c->topo.amd_node_id = tscan->amd_node_id; if (c->x86_vendor == X86_VENDOR_AMD) cpu_topology_fixup_amd(tscan); @@ -231,6 +229,5 @@ void __init cpu_init_topology(struct cpu * AMD systems have Nodes per package which cannot be mapped to * APIC ID (yet). */ - if (c->x86_vendor == X86_VENDOR_AMD || c->x86_vendor == X86_VENDOR_HYGON) - __amd_nodes_per_pkg = __max_die_per_package = tscan.amd_nodes_per_pkg; + __amd_nodes_per_pkg = tscan.amd_nodes_per_pkg; } From patchwork Fri Jul 28 12:13:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp407184vqg; Fri, 28 Jul 2023 05:44:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlHeBvew0KVFFM2qDCRhSBNpA4dq0u6gV5+Y/jU5BDHbXuvLbsqTVqxfYmakI5LjR6o+zh+a X-Received: by 2002:aca:280d:0:b0:3a4:ccf:53e8 with SMTP id 13-20020aca280d000000b003a40ccf53e8mr2661028oix.29.1690548281225; Fri, 28 Jul 2023 05:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548281; cv=none; d=google.com; s=arc-20160816; b=dddZuOlOzxV/EpLv7/KMS+oLCgS3KI3ptGdjbJHVQthcDG/w/IoyZqUcwtHPyOHHuq t3pGZzRP7iXjjYJjxRJiYQc9i+MHE0hlvXF+aTVBXioWrZLwIFU34jjfbkPTwAGAwGnD oM2ahRtOPTU9riNTpdTzRoOv0bt6Rw1H8/e3yag7blpNlzf9Nt6xlodWaC1WS4dvP5sB LAiOPvvSx9l/4S3Z1s+6hRd1xkU8zHxsjPN0oRcACSJ5e2LLwNM3LaKEa0hbPGVofG/A bZ4LN64BJTUG/sig7/e3rfCE86yGA0HaVge1LQJJOi4OKf0BAA4shAze1eHtZZ7Q/5CV iEuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=nCoiYGGGz2nXOq7tjWjNlQvkWfPVDpABc4VMP3k40m8=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=a2hIwGWrwzxgzUvm7j2ZixhT3bUM2WWuaoBU/Dd6kWxl4Tnju3tVXMURWAlPdJdcEq bAqtw3OyTM2wStGLGFdudSccSoTXScHjQ6uLm6M0NpQxS+htLwOMMHua8WFn/jEABS5Q 3wNUaVOq66Jag1BonfEpaLXNdzgh1jU/tPZQ+4dSFfV93yCjFJv3EfvnV0nc9xE8FNE0 e/QaFf3HjORKEnZtv1zuSXoFzixnpvi1QBbO86vOXpQEWgeUycpnUyx5PqAI5vTZLjfc vtP/KVt4GroAP4nlbR7/ecqX1i+ndidWDEdaG3xzUxgkXvvtynDVwoAEgLdYVrQpV7mK DnUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qFxzT50j; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Vf0Vfep2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b26-20020a6567da000000b005641ddd031esi930079pgs.752.2023.07.28.05.44.28; Fri, 28 Jul 2023 05:44:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qFxzT50j; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Vf0Vfep2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236517AbjG1MQ5 (ORCPT + 99 others); Fri, 28 Jul 2023 08:16:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236516AbjG1MPo (ORCPT ); Fri, 28 Jul 2023 08:15:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9216349ED; Fri, 28 Jul 2023 05:13:27 -0700 (PDT) Message-ID: <20230728120931.562662422@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546405; 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=nCoiYGGGz2nXOq7tjWjNlQvkWfPVDpABc4VMP3k40m8=; b=qFxzT50jTavLLoEQ77yObGJ9BEeuEBzoRRyYm9dxI5NmTeND5jLlD/NMYXMZuWiE9G8or7 zkDPf58WCa8bd4JtBBVFBW6HFMNLHdaRCDiI+z7rp2xIqpG5WBrF6giExATTtSF0CYXWVU DruQsfOgjWQDmYEUOtUJ68iY5l+AByEEZnHg/QWuVq235luPItuHW339ZdMYcOP6mjqniy 3fri5VV8ZL3WFod2CDQIx8/ws/MUzHxS3ieP39ik/rbsT9yQZTMJ3hYV8a12QWJS/OKph4 Rz1tXAcQZ3BeV4dg/FGbrbLK13MHz9/KccNlKR8hDaB8H6mOufKuyMZGrZYBgQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546405; 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=nCoiYGGGz2nXOq7tjWjNlQvkWfPVDpABc4VMP3k40m8=; b=Vf0Vfep2H7CXZWz//AyK4Vsu86Uu/ZnmtipWbfaqWgYLFi3O2g1CE0JPH4mqQqb5NuLAxY +mZCfEL4ihLEsLCA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 34/38] x86/cpu: Remove topology.c References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:25 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668354131836543 X-GMAIL-MSGID: 1772668354131836543 No more users. Stick it into the ugly code museum. Signed-off-by: Thomas Gleixner --- arch/x86/kernel/cpu/Makefile | 2 arch/x86/kernel/cpu/topology.c | 164 ----------------------------------------- 2 files changed, 1 insertion(+), 165 deletions(-) --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -18,7 +18,7 @@ KMSAN_SANITIZE_common.o := n KCSAN_SANITIZE_common.o := n obj-y := cacheinfo.o scattered.o -obj-y += topology_common.o topology_ext.o topology_amd.o topology.o +obj-y += topology_common.o topology_ext.o topology_amd.o obj-y += common.o obj-y += rdrand.o obj-y += 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 == 0 || (LEAFB_SUBTYPE(ecx) != 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 >= 0x1f) { - if (check_extended_topology_leaf(0x1f) == 0) - return 0x1f; - } - - if (c->cpuid_level >= 0xb) { - if (check_extended_topology_leaf(0xb) == 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 = 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 = edx; - smp_num_siblings = 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 = false; - int leaf; - - leaf = 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 = edx; - core_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - smp_num_siblings = max_t(int, smp_num_siblings, LEVEL_MAX_SIBLINGS(ebx)); - core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - die_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - pkg_mask_width = die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - - sub_index = 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) == CORE_TYPE) { - core_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - core_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - die_level_siblings = core_level_siblings; - die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - } - if (LEAFB_SUBTYPE(ecx) == DIE_TYPE) { - die_level_present = true; - die_level_siblings = LEVEL_MAX_SIBLINGS(ebx); - die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - } - - if (LEAFB_SUBTYPE(ecx) != INVALID_TYPE) - pkg_mask_width = BITS_SHIFT_NEXT_LEVEL(eax); - else - break; - - sub_index++; - } - - core_select_mask = (~(-1 << pkg_mask_width)) >> ht_mask_width; - die_select_mask = (~(-1 << die_plus_mask_width)) >> - core_plus_mask_width; - - c->topo.core_id = apic->phys_pkg_id(c->topo.initial_apicid, - ht_mask_width) & core_select_mask; - - if (die_level_present) { - c->topo.die_id = apic->phys_pkg_id(c->topo.initial_apicid, - core_plus_mask_width) & die_select_mask; - } - - c->topo.pkg_id = apic->phys_pkg_id(c->topo.initial_apicid, pkg_mask_width); - /* - * Reinit the apicid, now that we have extended initial_apicid. - */ - c->topo.apicid = apic->phys_pkg_id(c->topo.initial_apicid, 0); - - c->x86_max_cores = (core_level_siblings / smp_num_siblings); - __max_die_per_package = (die_level_siblings / core_level_siblings); -#endif - return 0; -} From patchwork Fri Jul 28 12:13:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp407901vqg; Fri, 28 Jul 2023 05:46:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHpLfHISy1237qmsazLzRsWfPewMFzBBmBOfNc0Wyq6kpNKdihck6/b9OUU194/fFRMc/bT X-Received: by 2002:a17:902:da84:b0:1ba:1704:89d3 with SMTP id j4-20020a170902da8400b001ba170489d3mr1362296plx.54.1690548371281; Fri, 28 Jul 2023 05:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548371; cv=none; d=google.com; s=arc-20160816; b=eekV6TOrRMIBqqdicC0Ih/m7Agyq75BgecoeDOo9Ji6WN/GfQAFpsSbD9pVc9uB7g8 6eXhPloGjj0oJ4GwuVmKeOgC8Lr9PSC98PpHOYm9C2xuPIGkHrKFv1gI7S5G287urRvs xSZYuP1FwEsMgxF01wFOSO4ZqAL4AMp+7Ilm3xnLNMSPgvEo71vAumL0REMxK/dNEkWn b30iUZ2hIZan4KtnrEVprNeuYs8TcWEWEFgoqwaZXJlAtQUgDqpxpUkIyJRnD+RWmrgr BaNoTNWQWQVMnEnkEvRa8tlqWrHznjn0v/D0HH7PMyH3F40TsD4VM5cNatqC7/D0hEas wg5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=NtDDi1Qa1O0ardBTEkM6u4SIs1c9Ae4E5SceZDfIb58=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=dQjJQzIbiaEk6dbF1fHpMPdcPOSDW2CsflyNic61BNirAfvs+uoyy/ubD7Wx0BSMy5 +oNaJEju672gShXJKfC7c5M8r5Y76Ml06CeqGJohduJUqcXXv1he4JzppjzP6V5L49k1 B3/99oyQFuq7JRMbb1CWjMZEGR+MUTj9vUuHL9VCwO4YWXaxU7TxiUWWKhhnz8FpNXfG UR5uUUK4CCp4weMjrNNIQhclv9uC2PxVnI0rmAwKYTriXJfMDzWo62PDJDPX63gOhYj6 ULn7Eg2XjWj39sms9t1a7GfZTjtqLk1v0Od56x6Qg8Vh3MeWsjSNmXzhbrgmpfz3DVov IS9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=r87HcYXC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kz14-20020a170902f9ce00b001b8944aa943si2936993plb.315.2023.07.28.05.45.56; Fri, 28 Jul 2023 05:46:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=r87HcYXC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236424AbjG1MRJ (ORCPT + 99 others); Fri, 28 Jul 2023 08:17:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235946AbjG1MQC (ORCPT ); Fri, 28 Jul 2023 08:16:02 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EC4F35A8; Fri, 28 Jul 2023 05:13:31 -0700 (PDT) Message-ID: <20230728120931.616473086@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546406; 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=NtDDi1Qa1O0ardBTEkM6u4SIs1c9Ae4E5SceZDfIb58=; b=r87HcYXC5VxwN7lbT21rEN+fOrq6p9RZR9jq9xgY23KLboCkbYvRaOvyeLpMjDRMfD5ZF6 1anYC5E3KWrOuiG3eaZqMl6ijI5DTMNkaUSvM9cspDeBbhpNWeRJDUKwSIUTCa8CIjHt1C OU1tOSBC8Wxfh5mPJv9Nvb2oTf6t4pRvPAIhDZcXlTvQkOyKYeVKJp0V4+/JtKHi7DBovV ZbtLiJ2pSom2S9SHRShsPvHnWZLOeQsJMV8eNhjHZ0t024HZYlM3ElU2MLSsO9eVjsVWhU 3+L2abxm9S7ZYYGzSlvHs5tyPzMQwt4fmRPfLW/la5lgYYXKKbi8JkTOVJ4Y9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546406; 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=NtDDi1Qa1O0ardBTEkM6u4SIs1c9Ae4E5SceZDfIb58=; b=1fikPVLwoXhP6UJ3Yl4j8y9VSSWMxgdqWAWyyU2l/Hw2ZGVO0gDKpk1EbZrXil9Xkd9Brn GWJdyJyW7BwL2rBA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 35/38] x86/cpu: Remove x86_coreid_bits References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:26 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668449090501681 X-GMAIL-MSGID: 1772668449090501681 No more users. Signed-off-by: Thomas Gleixner --- 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 @@ -119,8 +119,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=no CPUID: */ --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1712,7 +1712,6 @@ static void identify_cpu(struct cpuinfo_ c->x86_vendor_id[0] = '\0'; /* Unset */ c->x86_model_id[0] = '\0'; /* Unset */ c->x86_max_cores = 1; - c->x86_coreid_bits = 0; #ifdef CONFIG_X86_64 c->x86_clflush_size = 64; c->x86_phys_bits = 36; From patchwork Fri Jul 28 12:13:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp411368vqg; Fri, 28 Jul 2023 05:53:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlGr77+zRFUiJ73HBX3hLV8nFnga4ykz2LTk+XieLvlK2xvX2dZdYYrkwV0AaaHhxmUWZl5G X-Received: by 2002:a17:90a:6947:b0:268:284c:46be with SMTP id j7-20020a17090a694700b00268284c46bemr1325193pjm.1.1690548796301; Fri, 28 Jul 2023 05:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548796; cv=none; d=google.com; s=arc-20160816; b=WgAsY+Sj29aPqs1bSxHq8k+cl/RabpVSMWfTvIl99+X8ipczDnvCavBw6/lUhQimoV lwC5wP9zc9zPSUSG06hcsGvcTfoWMBiqVePd54YojBB0ZOII81Bn8nEq6X05pVDyB2be DOIZ9a5sukNuN96hoeZ3C2uKwin5I+1wXqWt9aoxGZI/e5ed4XAXzveJZEDSn+YQM0JA 4BsNb3EtedxCpV5iuJoged9ScxF6YCiqlvOPE++OXVbFidLNqX3IbdgJkhNN4skLQQx/ wNwSnffO0DAtehPqJqZQ6E1yt4tK9426OgjzIK4VT6UfbtgoSxtoS1tU5FttGHjD60pZ MuyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=ERFK+VFh6rECY3YAEH1UcTGlweh3EwxmdvhVGEi5pZg=; fh=y/slnYrqOPbByUK75sFPvq3cYp2SbZKM1q7UWSqjNrY=; b=K1ANXenVE02BHfzgmWNI8WgXddH9+kmpFljrrAjAy71n9x4RVajXcMh2ytlMh9+f78 oSES5xpxlm0WjPu8/ZgZTdZ7vafaOzWBpACgDryPP7mgAkGfM+tbPFzBUpJXUvXv9EH/ /Q263NMiOFIeBHivdDaXl7UdcWQan1UA2MkIJgrl88wy8UjNLhIU181mmZj9lWji8kBh xKcBG4bIzCnVLDBFe/9SpujenDHlBLK1mQ8S6tYKhPS31BVcYRS815FPL79qchoOsXLx NUBwk6ZsItr1ehI9s68BXymfj1f6mH2HozrLUzFym0XzkT3KJqr82Ej4B2l8tV2ur69A x7nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=a7U75a44; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n2-20020a17090ade8200b0025bec4468c2si3072332pjv.167.2023.07.28.05.53.02; Fri, 28 Jul 2023 05:53:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=a7U75a44; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236532AbjG1MRU (ORCPT + 99 others); Fri, 28 Jul 2023 08:17:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236573AbjG1MQT (ORCPT ); Fri, 28 Jul 2023 08:16:19 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFA6A3C35; Fri, 28 Jul 2023 05:13:38 -0700 (PDT) Message-ID: <20230728120931.670346058@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546407; 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=ERFK+VFh6rECY3YAEH1UcTGlweh3EwxmdvhVGEi5pZg=; b=a7U75a44tK481qN0qUGw08Za0yzjGyAf8b4wVCIo3s4Ar5XdPs0LqTW/6KRgiSV4PuWXL2 M4hSVxxTzFaZ4zM24sYrRzo0IKd44qzfON/0vgzqJC0v2VcvHtVoHz9CcCIBfpM674V0EZ g/Fo9RZVnM4UNRN4v5ohJPMW+oF8qwotIkVZu6u9e0hzzi8/1wc2aracf8P8jw7weR6AEb xFPFdzAJfgxYkpaTB5k6IDa6Zp6S5yCtv45BRGkscboKlW25sh51zRyJNVDdiHEo+I9yOO +KtF9fFm+357FWT7kJslPEWTzNb4sNRAKNpADB3txJLI6EABps8u/OyQExtkSw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546407; 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=ERFK+VFh6rECY3YAEH1UcTGlweh3EwxmdvhVGEi5pZg=; b=9Rn1PQDl9/Kal5HExVNqsl6Bdwq18J5sVLyeCfYvpo6+jF1rghhD8x2z9ZQVRuKpqrEAzt v1SxQ54kmsXvPXCw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 36/38] x86/apic: Remove unused phys_pkg_id() callback References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:27 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668894514369274 X-GMAIL-MSGID: 1772668894514369274 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 Reviewed-by: Steve Wahl --- 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 @@ -296,7 +296,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); 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; } -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; @@ -89,7 +84,6 @@ static struct apic apic_flat __ro_after_ .init_apic_ldr = default_init_apic_ldr, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = flat_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = flat_get_apic_id, @@ -159,7 +153,6 @@ static struct apic apic_physflat __ro_af .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = flat_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = 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) { } @@ -56,8 +55,6 @@ struct apic apic_noop __ro_after_init = .ioapic_phys_id_map = default_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = noop_phys_pkg_id, - .max_apic_id = 0xFE, .get_apic_id = noop_get_apic_id, --- 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; } -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); @@ -228,7 +223,6 @@ static const struct apic apic_numachip1 .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = numachip_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = numachip1_get_apic_id, @@ -265,7 +259,6 @@ static const struct apic apic_numachip2 .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = numachip_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = 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); } -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); @@ -88,7 +83,6 @@ static struct apic apic_bigsmp __ro_afte .check_apicid_used = bigsmp_check_apicid_used, .ioapic_phys_id_map = bigsmp_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = bigsmp_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = 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); 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 @@ #include "local.h" -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 = GET_APIC_VERSION(apic_read(APIC_LVR)); @@ -54,7 +49,6 @@ static struct apic apic_default __ro_aft .init_apic_ldr = default_init_apic_ldr, .ioapic_phys_id_map = default_ioapic_phys_id_map, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = default_phys_pkg_id, .max_apic_id = 0xFE, .get_apic_id = default_get_apic_id, --- a/arch/x86/kernel/apic/x2apic_cluster.c +++ b/arch/x86/kernel/apic/x2apic_cluster.c @@ -236,7 +236,6 @@ static struct apic apic_x2apic_cluster _ .init_apic_ldr = init_x2apic_ldr, .ioapic_phys_id_map = NULL, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = x2apic_phys_pkg_id, .max_apic_id = UINT_MAX, .x2apic_set_max_apicid = 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; } -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 = { .name = "physical x2apic", @@ -151,7 +146,6 @@ static struct apic apic_x2apic_phys __ro .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = x2apic_phys_pkg_id, .max_apic_id = UINT_MAX, .x2apic_set_max_apicid = true, --- a/arch/x86/kernel/apic/x2apic_uv_x.c +++ b/arch/x86/kernel/apic/x2apic_uv_x.c @@ -785,16 +785,6 @@ static u32 set_apic_id(u32 id) return id; } -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 == &apic_x2apic_uv_x; @@ -812,7 +802,6 @@ static struct apic apic_x2apic_uv_x __ro .disable_esr = 0, .cpu_present_to_apicid = default_cpu_present_to_apicid, - .phys_pkg_id = uv_phys_pkg_id, .max_apic_id = UINT_MAX, .get_apic_id = 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 } -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 = apicid_phys_pkg_id; -} - void __init vsmp_init(void) { detect_vsmp_box(); if (!is_vsmp_box()) return; - x86_platform.apic_post_init = vsmp_apic_post_init; - vsmp_cap_cpus(); 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(); } -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 = 0, .cpu_present_to_apicid = xen_cpu_present_to_apicid, - .phys_pkg_id = xen_phys_pkg_id, /* detect_ht */ .max_apic_id = UINT_MAX, .get_apic_id = xen_get_apic_id, From patchwork Fri Jul 28 12:13:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp406967vqg; Fri, 28 Jul 2023 05:44:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlGKLijkuO0qMWYEev+2oeNrtZwM9Fr35J4WQTXLBNyfWhFdArMKgLLt0czTLZcryjL8tmje X-Received: by 2002:a05:6a20:7349:b0:133:5352:c7ac with SMTP id v9-20020a056a20734900b001335352c7acmr1696463pzc.38.1690548250816; Fri, 28 Jul 2023 05:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690548250; cv=none; d=google.com; s=arc-20160816; b=0BKSWor/GVrY4rZR9geefT+NJYChqfctK5n3/42w1nnnBqxPyTchiaTMfxqKLBp1hg A/jGuyGXcuf2Dk3R24d+QaVukaQHvrDHu7cr0DE4jybyNh1FDv4FUNiIczu2B2tTaawU 9jiDV6cLgNQ4pTQNKtfJDG235HIdBfisz9uJ7dy+Tfk3T1sfrqeMsmYqdy1AXsEdWFfE S1M7Evcyk6erEJ+y9AmBU9drk3K4XMGoGmQeq3ndAdwf7JArQL4qbMCaPTcBIDN1ZxXH YS1NReVURwI4Q7gz09G7lw7JwYfstS30QnuuPtYIi+TC5oUZOif7KfKVnpshuxLhtmVl nFyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=dCJ675XRBN0nH/FVG6be5pN6/XKm3FLkxuXqtWJHHNE=; fh=P1e+g912YsfGu4wfaoMQf7V7StbyDwQzgNS7j8eV4VU=; b=ifm9owLb8ms+8AFMnO5tHi5S14xtlnZO3mejp29oRP23wzg77swcCKglMetTJQBti/ sUuAAkFvRI8bqHjSOh8xLDDTetcuUGsmRDLOkE8j++8r7tiWp1LYL+3Hzf4+1zmoYesy WupdFAehmXG2mzd0zGHui3U2Urx5cQKZGCgyrnTp1PHBfgLINPrRi4LLIgSftmY0D2bd lVskqrMGwWNxKrTKhGqaRUUascd3kMpfZKcTiDo1b2HsDTQb3+7elk6AUk5kfm7y2Ifp Z4kZZ8Q2xAkYrFHHXeq04PHRaJtZWdyDI9FPEPjrtu96IQpLb1gpZTimmEJ0i5Ato8tH aXoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fVICMZBM; dkim=neutral (no key) header.i=@linutronix.de header.b=JRqEBwF7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a63600c000000b005481915c0cfsi131462pgb.1.2023.07.28.05.43.57; Fri, 28 Jul 2023 05:44:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fVICMZBM; dkim=neutral (no key) header.i=@linutronix.de header.b=JRqEBwF7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235413AbjG1MRi (ORCPT + 99 others); Fri, 28 Jul 2023 08:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233909AbjG1MQ4 (ORCPT ); Fri, 28 Jul 2023 08:16:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CB0C4C3C; Fri, 28 Jul 2023 05:13:53 -0700 (PDT) Message-ID: <20230728120931.725126693@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546408; 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=dCJ675XRBN0nH/FVG6be5pN6/XKm3FLkxuXqtWJHHNE=; b=fVICMZBMeAB3LJx89czNoWL6pf/02XOmngVd1QmHmO03PyVsHJhQVG4ROl8TxW7toESKtk 8rCcgi8b/nV4IZGR7TMnN0MVwdlEQq+M60OkMIHGjhbNQ8APBhjJFcS9bbUibc8VtTHVId /TeWcfYHuzr8zIrut1w9NuvOwuhLxnFjhWd8MNj5ZoU+IpFwXHym50B+EQmDriJdJQiyOi F6jQZPBV75O0i9rZ8xNjsqcZkVbYlBvYicVQAjIqNmyC+VlxT8SGIurCaNUWGremjgExEf vtvEptqjv05bo0gu8Ge9lv4jtA6WLYvqS4JF8v1JKnjXo9o+mNHx6Vkry9MW+w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546408; 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=dCJ675XRBN0nH/FVG6be5pN6/XKm3FLkxuXqtWJHHNE=; b=JRqEBwF7tvlV9Cp1QN4pPZV2BzwgbiRZ2sfwBEgY5aXWT2gA6p6elfdQVttsoMpJ0YwHeK 9XUNsE++KH4SlwAA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Juergen Gross , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson Subject: [patch v2 37/38] x86/xen/smp_pv: Remove cpudata fiddling References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:28 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772668322634617429 X-GMAIL-MSGID: 1772668322634617429 The new topology CPUID parser installs already fake topology for XEN/PV, which ends up with cpuinfo::max_cores = 1. Signed-off-by: Thomas Gleixner Cc: Juergen Gross --- V2: New patch --- 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 = smp_processor_id(); smp_store_cpu_info(cpu); - cpu_data(cpu).x86_max_cores = 1; set_cpu_sibling_map(cpu); speculative_store_bypass_ht_init(); @@ -223,8 +222,6 @@ static void __init xen_pv_smp_prepare_cp smp_prepare_cpus_common(); - cpu_data(0).x86_max_cores = 1; - speculative_store_bypass_ht_init(); xen_pmu_init(0); From patchwork Fri Jul 28 12:13:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 127631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp428839vqg; Fri, 28 Jul 2023 06:18:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlFG40aMkOceuFFoPcXHDUFzpbbE8L5LAO9z4PJBsi35v0TqVQMv1K0wuF8dNMu+kq5RSMVq X-Received: by 2002:a05:6a00:2185:b0:682:4ef7:9b17 with SMTP id h5-20020a056a00218500b006824ef79b17mr1629204pfi.32.1690550303619; Fri, 28 Jul 2023 06:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690550303; cv=none; d=google.com; s=arc-20160816; b=HnBzuGgB1F+qoqBTVMGZyZTshyHcgf9ksHBNgO0+G7JwQcpnN10No9pvm1jx/FJe86 ME4R87L852FCNUzBs1CFcQ47uWeNLpZVblXnm22izikQtT8/IoqKEPGGXkK0j3NOBGPy RUEBIkrhYiGsM2LiL0NEoDceoMo+o8F/SbXCJWq0MDZT6Ncc68r6ZDxWtwBm32cO4swV 9nxbl+FlmXMn37pClvcbYDygWYWOjDqh3QhJM+Q0ePIAYbFDcOTEIzbMxhES6uSoJHt4 9/9dZ8m9ajq7aZjwUq3+F28bWcdX1B1bjlEOXJFQS9H/YwgadXeqUjDb3R2XHnpnYkWW iIBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:mime-version:references:subject:cc:to:from :dkim-signature:dkim-signature:message-id; bh=y/zw4jIEoXHpKelNkwXOESHKGmmFcaqzgwgGslsADMM=; fh=ephNY1uQZm0Xdwp8V1zOdls2aVbRmi9mPSpGYw8cb7k=; b=MqHQZ6ABySW3mET0U8VSN3p4SORfk21YUIN80HMxenPwKE6clFZ66tLnWRTG2OIVjt mEMuj+EqeyhwWe3ZfaZig/x/BvG+LQozbgnT7GgV3JXoNTfGHr66PwYn4ly+jeQCGEQT AMY8+WKnjl0jxHS7a29Lh95+7Oml2j3/H/tm+ckUFi0n7kxFzFVo/TlbQBM3RfsiVwO6 zIXtSmu3JbZKl3xBtgLCl+d9f8/uO37MD749Z4wS2nBhu16qWsHA2fJCisjPMrX0Jc6t OEM0wXs/uHP6Ly8bk+7tp1rqBrAm8579KBr/8QY8iqHD18XZ1h7rqB2bRh2qg9490Ilp WCSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AnEZ7VoW; dkim=neutral (no key) header.i=@linutronix.de header.b=HJe2giYO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t184-20020a6381c1000000b0055c7702855esi3008681pgd.41.2023.07.28.06.18.09; Fri, 28 Jul 2023 06:18:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AnEZ7VoW; dkim=neutral (no key) header.i=@linutronix.de header.b=HJe2giYO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236629AbjG1MRe (ORCPT + 99 others); Fri, 28 Jul 2023 08:17:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbjG1MQy (ORCPT ); Fri, 28 Jul 2023 08:16:54 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68F8A4C3A; Fri, 28 Jul 2023 05:13:53 -0700 (PDT) Message-ID: <20230728120931.779678736@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1690546410; 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=y/zw4jIEoXHpKelNkwXOESHKGmmFcaqzgwgGslsADMM=; b=AnEZ7VoWUTvWtXC1ibtT5HXqKOG+cy3yzrfXl8I7r6daB9egwcQ38TAqcn89WB2NIxrFB5 4s1OpDv/kJBhIK1uYNfcGyz7YWxxQNwhuuHXMRx5Zs4rg1tVJDEhfr5QThVcX66espYpau RbXblyBEoaj3qStf1vA/li0XHOfTdQ1BkZZFkCpV9j/fe/zqRHkyllYWOuRpTfDWeWNVxk JJ8Wb1CGqhAe8IbesqYJxBGfNZb+sZ627QDrtzf0+0taVnb2em2T3O2hnFrIOJVscEGYmH b/QD610RCbSGTpBjrWLCbwlVtqWFcScL7GAYSAdbdKDVP861xoEEZY+RdfQhEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1690546410; 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=y/zw4jIEoXHpKelNkwXOESHKGmmFcaqzgwgGslsADMM=; b=HJe2giYO+kEa5X6fjGgFeX3ZcFgqjgGJtCJPjAe17sJdfvvKhQELfZxtp5XOaDNP/Akhqo KS2Uaj2zzZ8B9QBw== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Tom Lendacky , Andrew Cooper , Arjan van de Ven , Steve Wahl , Mike Travis , Dimitri Sivanich , Russ Anderson , "James E.J. Bottomley" , Dick Kennedy , James Smart , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Guenter Roeck , linux-hwmon@vger.kernel.org, Jean Delvare , Huang Rui , Juergen Gross Subject: [patch v2 38/38] x86/apic/uv: Remove the private leaf 0xb parser References: <20230728105650.565799744@linutronix.de> MIME-Version: 1.0 Date: Fri, 28 Jul 2023 14:13:30 +0200 (CEST) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772670475251573526 X-GMAIL-MSGID: 1772670475251573526 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 Cc: Steve Wahl Cc: Mike Travis Cc: Dimitri Sivanich Cc: Russ Anderson Reviewed-by: Steve Wahl --- 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]; } +static inline unsigned int topology_get_domain_shift(enum x86_topology_domains dom) +{ + return dom == 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); --- 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) -/* [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 == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE)) { - pr_info("UV: CPUID.11 not implemented\n"); - return; - } - - sid_shift = BITS_SHIFT_NEXT_LEVEL(eax); - sub_index = 1; - do { - cpuid_count(0xb, sub_index, &eax, &ebx, &ecx, &edx); - if (LEAFB_SUBTYPE(ecx) == CORE_TYPE) { - sid_shift = BITS_SHIFT_NEXT_LEVEL(eax); - break; - } - sub_index++; - } while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE); - - uv_cpuid.apicid_shift = 0; - uv_cpuid.apicid_mask = (~(-1 << sid_shift)); - uv_cpuid.socketid_shift = sid_shift; -} - static void __init early_get_apic_socketid_shift(void) { + unsigned int sid_shift = topology_get_domain_shift(TOPO_ROOT_DOMAIN); + if (is_uv2_hub() || is_uv3_hub()) uvh_apicid.v = uv_early_read_mmr(UVH_APICID); - set_x2apic_bits(); + if (sid_shift) { + uv_cpuid.apicid_shift = 0; + uv_cpuid.apicid_mask = (~(-1 << sid_shift)); + uv_cpuid.socketid_shift = sid_shift; + } else { + pr_info("UV: CPU does not have valid CPUID.11\n"); + } 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_shift, uv_cpuid.pnode_mask);