Skip to content

Commit 405d6a3

Browse files
author
Herton R. Krzesinski
committed
Merge: ADL-N: Fix multiple packages shown on a single-package system
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1863 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2159554 Tested: TBD Signed-off-by: David Arcari <darcari@redhat.com> Approved-by: Lenny Szubowicz <lszubowi@redhat.com> Approved-by: Steve Best <sbest@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 0fb5909 + 4cf2b0e commit 405d6a3

File tree

2 files changed

+52
-20
lines changed

2 files changed

+52
-20
lines changed

arch/x86/kernel/cpu/topology.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
9696
unsigned int ht_mask_width, core_plus_mask_width, die_plus_mask_width;
9797
unsigned int core_select_mask, core_level_siblings;
9898
unsigned int die_select_mask, die_level_siblings;
99+
unsigned int pkg_mask_width;
99100
bool die_level_present = false;
100101
int leaf;
101102

@@ -111,10 +112,10 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
111112
core_level_siblings = smp_num_siblings = LEVEL_MAX_SIBLINGS(ebx);
112113
core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
113114
die_level_siblings = LEVEL_MAX_SIBLINGS(ebx);
114-
die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
115+
pkg_mask_width = die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
115116

116117
sub_index = 1;
117-
do {
118+
while (true) {
118119
cpuid_count(leaf, sub_index, &eax, &ebx, &ecx, &edx);
119120

120121
/*
@@ -132,10 +133,15 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
132133
die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
133134
}
134135

136+
if (LEAFB_SUBTYPE(ecx) != INVALID_TYPE)
137+
pkg_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
138+
else
139+
break;
140+
135141
sub_index++;
136-
} while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE);
142+
}
137143

138-
core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width;
144+
core_select_mask = (~(-1 << pkg_mask_width)) >> ht_mask_width;
139145
die_select_mask = (~(-1 << die_plus_mask_width)) >>
140146
core_plus_mask_width;
141147

@@ -148,7 +154,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
148154
}
149155

150156
c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid,
151-
die_plus_mask_width);
157+
pkg_mask_width);
152158
/*
153159
* Reinit the apicid, now that we have extended initial_apicid.
154160
*/

drivers/hwmon/coretemp.c

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
4646
#define TOTAL_ATTRS (MAX_CORE_ATTRS + 1)
4747
#define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO)
4848

49-
#define TO_CORE_ID(cpu) (cpu_data(cpu).cpu_core_id)
50-
#define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO)
51-
5249
#ifdef CONFIG_SMP
5350
#define for_each_sibling(i, cpu) \
5451
for_each_cpu(i, topology_sibling_cpumask(cpu))
@@ -91,6 +88,8 @@ struct temp_data {
9188
struct platform_data {
9289
struct device *hwmon_dev;
9390
u16 pkg_id;
91+
u16 cpu_map[NUM_REAL_CORES];
92+
struct ida ida;
9493
struct cpumask cpumask;
9594
struct temp_data *core_data[MAX_CORE_DATA];
9695
struct device_attribute name_attr;
@@ -441,7 +440,7 @@ static struct temp_data *init_temp_data(unsigned int cpu, int pkg_flag)
441440
MSR_IA32_THERM_STATUS;
442441
tdata->is_pkg_data = pkg_flag;
443442
tdata->cpu = cpu;
444-
tdata->cpu_core_id = TO_CORE_ID(cpu);
443+
tdata->cpu_core_id = topology_core_id(cpu);
445444
tdata->attr_size = MAX_CORE_ATTRS;
446445
mutex_init(&tdata->update_lock);
447446
return tdata;
@@ -454,22 +453,34 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu,
454453
struct platform_data *pdata = platform_get_drvdata(pdev);
455454
struct cpuinfo_x86 *c = &cpu_data(cpu);
456455
u32 eax, edx;
457-
int err, attr_no;
456+
int err, index, attr_no;
458457

459458
/*
460459
* Find attr number for sysfs:
461460
* We map the attr number to core id of the CPU
462461
* The attr number is always core id + 2
463462
* The Pkgtemp will always show up as temp1_*, if available
464463
*/
465-
attr_no = pkg_flag ? PKG_SYSFS_ATTR_NO : TO_ATTR_NO(cpu);
464+
if (pkg_flag) {
465+
attr_no = PKG_SYSFS_ATTR_NO;
466+
} else {
467+
index = ida_alloc(&pdata->ida, GFP_KERNEL);
468+
if (index < 0)
469+
return index;
470+
pdata->cpu_map[index] = topology_core_id(cpu);
471+
attr_no = index + BASE_SYSFS_ATTR_NO;
472+
}
466473

467-
if (attr_no > MAX_CORE_DATA - 1)
468-
return -ERANGE;
474+
if (attr_no > MAX_CORE_DATA - 1) {
475+
err = -ERANGE;
476+
goto ida_free;
477+
}
469478

470479
tdata = init_temp_data(cpu, pkg_flag);
471-
if (!tdata)
472-
return -ENOMEM;
480+
if (!tdata) {
481+
err = -ENOMEM;
482+
goto ida_free;
483+
}
473484

474485
/* Test if we can access the status register */
475486
err = rdmsr_safe_on_cpu(cpu, tdata->status_reg, &eax, &edx);
@@ -505,6 +516,9 @@ static int create_core_data(struct platform_device *pdev, unsigned int cpu,
505516
exit_free:
506517
pdata->core_data[attr_no] = NULL;
507518
kfree(tdata);
519+
ida_free:
520+
if (!pkg_flag)
521+
ida_free(&pdata->ida, index);
508522
return err;
509523
}
510524

@@ -528,6 +542,9 @@ static void coretemp_remove_core(struct platform_data *pdata, int indx)
528542

529543
kfree(pdata->core_data[indx]);
530544
pdata->core_data[indx] = NULL;
545+
546+
if (indx >= BASE_SYSFS_ATTR_NO)
547+
ida_free(&pdata->ida, indx - BASE_SYSFS_ATTR_NO);
531548
}
532549

533550
static int coretemp_probe(struct platform_device *pdev)
@@ -541,6 +558,7 @@ static int coretemp_probe(struct platform_device *pdev)
541558
return -ENOMEM;
542559

543560
pdata->pkg_id = pdev->id;
561+
ida_init(&pdata->ida);
544562
platform_set_drvdata(pdev, pdata);
545563

546564
pdata->hwmon_dev = devm_hwmon_device_register_with_groups(dev, DRVNAME,
@@ -557,6 +575,7 @@ static int coretemp_remove(struct platform_device *pdev)
557575
if (pdata->core_data[i])
558576
coretemp_remove_core(pdata, i);
559577

578+
ida_destroy(&pdata->ida);
560579
return 0;
561580
}
562581

@@ -651,7 +670,7 @@ static int coretemp_cpu_offline(unsigned int cpu)
651670
struct platform_device *pdev = coretemp_get_pdev(cpu);
652671
struct platform_data *pd;
653672
struct temp_data *tdata;
654-
int indx, target;
673+
int i, indx = -1, target;
655674

656675
/*
657676
* Don't execute this on suspend as the device remove locks
@@ -664,12 +683,19 @@ static int coretemp_cpu_offline(unsigned int cpu)
664683
if (!pdev)
665684
return 0;
666685

667-
/* The core id is too big, just return */
668-
indx = TO_ATTR_NO(cpu);
669-
if (indx > MAX_CORE_DATA - 1)
686+
pd = platform_get_drvdata(pdev);
687+
688+
for (i = 0; i < NUM_REAL_CORES; i++) {
689+
if (pd->cpu_map[i] == topology_core_id(cpu)) {
690+
indx = i + BASE_SYSFS_ATTR_NO;
691+
break;
692+
}
693+
}
694+
695+
/* Too many cores and this core is not populated, just return */
696+
if (indx < 0)
670697
return 0;
671698

672-
pd = platform_get_drvdata(pdev);
673699
tdata = pd->core_data[indx];
674700

675701
cpumask_clear_cpu(cpu, &pd->cpumask);

0 commit comments

Comments
 (0)