Skip to contentSkip to conversation

hwmon: (coretemp) Fix missing sensors with uneven core counts

PATCH Applied Aveline Noir 4 participants 4 messages Dec 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hwmon: (coretemp) Fix missing sensors with uneven core counts

topology_num_cores_per_package() returns the core count of the package with the lowest APIC ID. If another package has more cores, e.g. because the BIOS disabled cores on only one CPU, the extra cores get no temperature sensors and "Adding Core N failed" is logged.

Use num_possible_cpus() as the limit instead, and allocate the array with kvzalloc_objs() so large systems don't need a high-order allocation.

Fixes b89e1255c92b ("hwmon: (coretemp) replace hardcoded core count with dynamic value")

---
v2: Use kvzalloc_objs() as Guenter suggested, and state the exact condition in the commit message. Kept Asaf's tags since the allocation change is small.

Only tested in QEMU, with 2+4 cores.

v1: https://lore.kernel.org/r/[email protected]

---
 drivers/hwmon/coretemp.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/hwmon/coretemp.c +5 -4
index 96d57fe12de6..936c16310c10 100644
@@ -491,9 +491,10 @@ init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag)
 	struct temp_data *tdata;
 
 	if (!pdata->core_data) {
-		int nr_cores = topology_num_cores_per_package();
+		/* Packages can have different numbers of cores */
+		int nr_cores = num_possible_cpus();
 
-		pdata->core_data = kzalloc_objs(struct temp_data *, nr_cores);
+		pdata->core_data = kvzalloc_objs(struct temp_data *, nr_cores);
 		if (!pdata->core_data)
 			return NULL;
 		pdata->nr_cores = nr_cores;
@@ -531,7 +532,7 @@ static void destroy_temp_data(struct platform_data *pdata, struct temp_data *tda
 {
 	if (is_pkg_temp_data(tdata)) {
 		pdata->pkg_data = NULL;
-		kfree(pdata->core_data);
+		kvfree(pdata->core_data);
 		pdata->core_data = NULL;
 		pdata->nr_cores = 0;
 	} else {
@@ -659,7 +660,7 @@ static void coretemp_device_remove(int zoneid)
 	struct platform_data *pdata = platform_get_drvdata(pdev);
 
 	ida_destroy(&pdata->ida);
-	kfree(pdata->core_data);
+	kvfree(pdata->core_data);
 	kfree(pdata);
 	platform_device_unregister(pdev);
 }

---
base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
change-id: 20261205-coretemp-core-limit-4e403bcd7b15

#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

topology_num_cores_per_package() returns the core count of the package with the lowest APIC ID. If another package has more cores, e.g. because the BIOS disabled cores on only one CPU, the extra cores get no temperature sensors and "Adding Core N failed" is logged.

Use num_possible_cpus() as the limit instead, and allocate the array with kvzalloc_objs() so large systems don't need a high-order allocation.

Quoted 6 lines
Fixes b89e1255c92b ("hwmon: (coretemp) replace hardcoded core count with dynamic value")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Aveline Noir
Quoted 3 lines · Aveline Noir

v2: Use kvzalloc_objs() as Guenter suggested, and state the exact condition in the commit message. Kept Asaf's tags since the allocation change is small.

Since the code changed, I retested v2.

With your QEMU command line, package 1 gets Core 0 and Core 1, and no "Adding Core" error is logged.

On the i7-14700F, 30 hotplug rounds (cpu2/cpu3 and cpu16) and 20 rmmod/insmod rounds, with a loop reading all coretemp sysfs files in the background, gave 21/21 temperature inputs and no warnings in dmesg. The array is small on this machine, so the vmalloc fallback was not exercised.

The allocation and both kfree() calls on core_data are converted. My tags still stand.

Thanks,
Asaf

maintainer Applied
#3 lore raw
In reply to Aveline Noir
Quoted 9 lines · Aveline Noir

topology_num_cores_per_package() returns the core count of the package with the lowest APIC ID. If another package has more cores, e.g. because the BIOS disabled cores on only one CPU, the extra cores get no temperature sensors and "Adding Core N failed" is logged.

Use num_possible_cpus() as the limit instead, and allocate the array with kvzalloc_objs() so large systems don't need a high-order allocation.

Quoted 6 lines
Fixes b89e1255c92b ("hwmon: (coretemp) replace hardcoded core count with dynamic value")

Applied.

Thanks
Guenter