x86/cpu/amd: Provide a separate accessor for Node ID
authorThomas Gleixner <tglx@linutronix.de>
Tue, 13 Feb 2024 21:04:10 +0000 (22:04 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 15 Feb 2024 21:07:37 +0000 (22:07 +0100)
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_die_per_pkg(). Will be mopped up after AMD and HYGON are
converted over.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Juergen Gross <jgross@suse.com>
Tested-by: Sohil Mehta <sohil.mehta@intel.com>
Tested-by: Michael Kelley <mhklinux@outlook.com>
Tested-by: Zhang Rui <rui.zhang@intel.com>
Tested-by: Wang Wendy <wendy.wang@intel.com>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Link: https://lore.kernel.org/r/20240212153624.956116738@linutronix.de
arch/x86/events/amd/core.c
arch/x86/include/asm/processor.h
arch/x86/include/asm/topology.h
arch/x86/kernel/amd_nb.c
arch/x86/kernel/cpu/cacheinfo.c
arch/x86/kernel/cpu/mce/amd.c
arch/x86/kernel/cpu/mce/inject.c
drivers/edac/amd64_edac.c
drivers/edac/mce_amd.c

index 81f6d8275b6bf2aab39ff40eac3fcf706192654b..69a3b02e50bb0cfbe2688769ad3a5ea72fd8e11f 100644 (file)
@@ -579,7 +579,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) {
index 26620d7642a9fcf9d4a822140a1dd009399ee16a..26a6001ddafd3fed2d531693f36d8381aad3533c 100644 (file)
@@ -100,6 +100,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;
index fa5d803ed7e21bf971886639f9ca830fda0ea63e..1fd12e98a28370df6fe6e6dd9577ef8924063674 100644 (file)
@@ -131,6 +131,8 @@ extern const struct cpumask *cpu_clustergroup_mask(int cpu);
 #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
@@ -161,6 +163,11 @@ int topology_update_package_map(unsigned int apicid, unsigned int cpu);
 int topology_update_die_map(unsigned int dieid, unsigned int cpu);
 int topology_phys_to_logical_pkg(unsigned int pkg);
 
+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_phys_to_logical_pkg(unsigned int pkg) { return 0; }
 static inline int topology_max_die_per_package(void) { return 1; }
 static inline int topology_max_smt_threads(void) { return 1; }
 static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
+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)
index 053f6dcc6b2c7026eb87c79f09b6d6a038aec628..5bf5f9fc5753a194fcc071b57af6184ad275a634 100644 (file)
@@ -386,7 +386,7 @@ struct resource *amd_get_mmconfig_range(struct resource *res)
 
 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))
@@ -400,7 +400,7 @@ int amd_get_subcaches(int cpu)
 int amd_set_subcaches(int cpu, unsigned long mask)
 {
        static unsigned int reset, ban;
-       struct amd_northbridge *nb = 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;
 
index c131c412db89c58e820cdfa6758c4db6b59d3429..4a33218cb103e293804daec984d12048ea3a7182 100644 (file)
@@ -595,7 +595,7 @@ static void amd_init_l3_cache(struct _cpuid4_info_regs *this_leaf, int index)
        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);
index 2b46eb0fdf3acd1e044ebb85707652c0af85e54d..9a0133ef7e20ab60e36fa1d3f2e89382767f3f23 100644 (file)
@@ -1231,7 +1231,7 @@ static int threshold_create_bank(struct threshold_bank **bp, unsigned int cpu,
                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) {
@@ -1335,7 +1335,7 @@ static void threshold_remove_bank(struct threshold_bank *bank)
                 * 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;
        }
 
index 72f0695c3dc1dd86055785e11b16bff16ea1c87a..308c5b5e0bbebbd26c2d9f337af903805a95dc0e 100644 (file)
@@ -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();
index 537b9987a431c23c263fd59631316cf3780b3e72..2b8c20bb926a21666daf06c8e22dd42127fddca1 100644 (file)
@@ -1915,7 +1915,7 @@ ddr3:
 /* 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;
@@ -3446,7 +3446,7 @@ static void get_cpus_on_this_dct_cpumask(struct cpumask *mask, u16 nid)
        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);
 }
 
index ec8b6c9fedfddf926692802a268155a5e27effad..8130c3dc64da56470ac60015897787a12005c5fc 100644 (file)
@@ -584,7 +584,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;
@@ -746,7 +746,7 @@ static void decode_smca_error(struct mce *m)
 
        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)