Skip to content

Commit 7e3ec62

Browse files
committed
x86/cpu/amd: Provide a separate accessor for Node ID
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 <[email protected]> Tested-by: Juergen Gross <[email protected]> Tested-by: Sohil Mehta <[email protected]> Tested-by: Michael Kelley <[email protected]> Tested-by: Zhang Rui <[email protected]> Tested-by: Wang Wendy <[email protected]> Tested-by: K Prateek Nayak <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 22d6366 commit 7e3ec62

File tree

9 files changed

+23
-12
lines changed

9 files changed

+23
-12
lines changed

arch/x86/events/amd/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ static void amd_pmu_cpu_starting(int cpu)
579579
if (!x86_pmu.amd_nb_constraints)
580580
return;
581581

582-
nb_id = topology_die_id(cpu);
582+
nb_id = topology_amd_node_id(cpu);
583583
WARN_ON_ONCE(nb_id == BAD_APICID);
584584

585585
for_each_online_cpu(i) {

arch/x86/include/asm/processor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ struct cpuinfo_topology {
100100
u32 logical_pkg_id;
101101
u32 logical_die_id;
102102

103+
// AMD Node ID and Nodes per Package info
104+
u32 amd_node_id;
105+
103106
// Cache level topology IDs
104107
u32 llc_id;
105108
u32 l2c_id;

arch/x86/include/asm/topology.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ extern const struct cpumask *cpu_clustergroup_mask(int cpu);
131131
#define topology_core_id(cpu) (cpu_data(cpu).topo.core_id)
132132
#define topology_ppin(cpu) (cpu_data(cpu).ppin)
133133

134+
#define topology_amd_node_id(cpu) (cpu_data(cpu).topo.die_id)
135+
134136
extern unsigned int __max_die_per_package;
135137

136138
#ifdef CONFIG_SMP
@@ -161,6 +163,11 @@ int topology_update_package_map(unsigned int apicid, unsigned int cpu);
161163
int topology_update_die_map(unsigned int dieid, unsigned int cpu);
162164
int topology_phys_to_logical_pkg(unsigned int pkg);
163165

166+
static inline unsigned int topology_amd_nodes_per_pkg(void)
167+
{
168+
return __max_die_per_package;
169+
}
170+
164171
extern struct cpumask __cpu_primary_thread_mask;
165172
#define cpu_primary_thread_mask ((const struct cpumask *)&__cpu_primary_thread_mask)
166173

@@ -182,6 +189,7 @@ static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
182189
static inline int topology_max_die_per_package(void) { return 1; }
183190
static inline int topology_max_smt_threads(void) { return 1; }
184191
static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
192+
static inline unsigned int topology_amd_nodes_per_pkg(void) { return 0; };
185193
#endif /* !CONFIG_SMP */
186194

187195
static inline void arch_fix_phys_package_id(int num, u32 slot)

arch/x86/kernel/amd_nb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ struct resource *amd_get_mmconfig_range(struct resource *res)
386386

387387
int amd_get_subcaches(int cpu)
388388
{
389-
struct pci_dev *link = node_to_amd_nb(topology_die_id(cpu))->link;
389+
struct pci_dev *link = node_to_amd_nb(topology_amd_node_id(cpu))->link;
390390
unsigned int mask;
391391

392392
if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
@@ -400,7 +400,7 @@ int amd_get_subcaches(int cpu)
400400
int amd_set_subcaches(int cpu, unsigned long mask)
401401
{
402402
static unsigned int reset, ban;
403-
struct amd_northbridge *nb = node_to_amd_nb(topology_die_id(cpu));
403+
struct amd_northbridge *nb = node_to_amd_nb(topology_amd_node_id(cpu));
404404
unsigned int reg;
405405
int cuid;
406406

arch/x86/kernel/cpu/cacheinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static void amd_init_l3_cache(struct _cpuid4_info_regs *this_leaf, int index)
595595
if (index < 3)
596596
return;
597597

598-
node = topology_die_id(smp_processor_id());
598+
node = topology_amd_node_id(smp_processor_id());
599599
this_leaf->nb = node_to_amd_nb(node);
600600
if (this_leaf->nb && !this_leaf->nb->l3_cache.indices)
601601
amd_calc_l3_indices(this_leaf->nb);

arch/x86/kernel/cpu/mce/amd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ static int threshold_create_bank(struct threshold_bank **bp, unsigned int cpu,
12311231
return -ENODEV;
12321232

12331233
if (is_shared_bank(bank)) {
1234-
nb = node_to_amd_nb(topology_die_id(cpu));
1234+
nb = node_to_amd_nb(topology_amd_node_id(cpu));
12351235

12361236
/* threshold descriptor already initialized on this node? */
12371237
if (nb && nb->bank4) {
@@ -1335,7 +1335,7 @@ static void threshold_remove_bank(struct threshold_bank *bank)
13351335
* The last CPU on this node using the shared bank is going
13361336
* away, remove that bank now.
13371337
*/
1338-
nb = node_to_amd_nb(topology_die_id(smp_processor_id()));
1338+
nb = node_to_amd_nb(topology_amd_node_id(smp_processor_id()));
13391339
nb->bank4 = NULL;
13401340
}
13411341

arch/x86/kernel/cpu/mce/inject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,8 @@ static void do_inject(void)
543543
if (boot_cpu_has(X86_FEATURE_AMD_DCM) &&
544544
b == 4 &&
545545
boot_cpu_data.x86 < 0x17) {
546-
toggle_nb_mca_mst_cpu(topology_die_id(cpu));
547-
cpu = get_nbc_for_node(topology_die_id(cpu));
546+
toggle_nb_mca_mst_cpu(topology_amd_node_id(cpu));
547+
cpu = get_nbc_for_node(topology_amd_node_id(cpu));
548548
}
549549

550550
cpus_read_lock();

drivers/edac/amd64_edac.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ static void dct_determine_memory_type(struct amd64_pvt *pvt)
19151915
/* On F10h and later ErrAddr is MC4_ADDR[47:1] */
19161916
static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m)
19171917
{
1918-
u16 mce_nid = topology_die_id(m->extcpu);
1918+
u16 mce_nid = topology_amd_node_id(m->extcpu);
19191919
struct mem_ctl_info *mci;
19201920
u8 start_bit = 1;
19211921
u8 end_bit = 47;
@@ -3446,7 +3446,7 @@ static void get_cpus_on_this_dct_cpumask(struct cpumask *mask, u16 nid)
34463446
int cpu;
34473447

34483448
for_each_online_cpu(cpu)
3449-
if (topology_die_id(cpu) == nid)
3449+
if (topology_amd_node_id(cpu) == nid)
34503450
cpumask_set_cpu(cpu, mask);
34513451
}
34523452

drivers/edac/mce_amd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static void decode_mc3_mce(struct mce *m)
584584
static void decode_mc4_mce(struct mce *m)
585585
{
586586
unsigned int fam = x86_family(m->cpuid);
587-
int node_id = topology_die_id(m->extcpu);
587+
int node_id = topology_amd_node_id(m->extcpu);
588588
u16 ec = EC(m->status);
589589
u8 xec = XEC(m->status, 0x1f);
590590
u8 offset = 0;
@@ -746,7 +746,7 @@ static void decode_smca_error(struct mce *m)
746746

747747
if ((bank_type == SMCA_UMC || bank_type == SMCA_UMC_V2) &&
748748
xec == 0 && decode_dram_ecc)
749-
decode_dram_ecc(topology_die_id(m->extcpu), m);
749+
decode_dram_ecc(topology_amd_node_id(m->extcpu), m);
750750
}
751751

752752
static inline void amd_decode_err_code(u16 ec)

0 commit comments

Comments
 (0)