Skip to contentSkip to conversation

hwmon: (coretemp) Retry failed sensor creation

PATCH In review Ximing Zhang 3 participants 5 messages Oct 20 – Oct 21

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

PATCH 1/1 hwmon: (coretemp) Retry failed sensor creation

coretemp_add_core() only logs create_core_data() failures, but coretemp_cpu_online() still records the CPU in pdata->cpumask. When an SMT sibling is processed later, the mask makes the driver skip sensor creation. The core interface then remains absent until all siblings are cycled or the module is reloaded.

Package sensor creation is similarly attempted only when the hwmon device is first registered. A failure leaves the package interface absent for the lifetime of that device.

Retry missing package and core sensors whenever an eligible CPU comes online. Determine whether a core sensor exists from its temperature data instead of the CPU mask, which continues to track CPUs available for MSR reads and hotplug retargeting.

A package retry might fail after per-core data exists. Keep the core_data array alive until the hwmon device is unregistered so failure cleanup cannot discard live per-core pointers. Publish nr_cores only after that array is allocated successfully, and rate-limit errors because a permanent failure can now be retried.

Tested on an Intel Core i7-10510U running 7.2.5-1-cachyos. With test-only fault injection, two package creation failures and one Core 0 creation failure left the unpatched driver without both interfaces. The patched driver retried and exposed all five readable sensors. SMT sibling hotplug and 20 module unload/load cycles also retained the expected sensors.

---
coretemp currently treats a failed package or per-core sensor creation as permanent for the lifetime of the hwmon device. This change retries missing sensors as eligible CPUs come online while keeping the CPU mask available for MSR targeting and hotplug handling.

Tested on an Intel Core i7-10510U running 7.2.5-1-cachyos. Test-only fault injection reproduced missing package and Core 0 interfaces with the current driver. The patched driver recovered both interfaces after two package creation failures and one core creation failure. SMT sibling hotplug and 20 module unload/load cycles also completed with the expected readable sensors.

---
 drivers/hwmon/coretemp.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)
drivers/hwmon/coretemp.c +14 -16
index 3836beade59f..fa3b04d0e041 100644
@@ -489,13 +489,15 @@ static struct temp_data *
 init_temp_data(struct platform_data *pdata, unsigned int cpu, int pkg_flag)
 {
 	struct temp_data *tdata;
+	int nr_cores;
 
 	if (!pdata->core_data) {
-		pdata->nr_cores = topology_num_cores_per_package();
+		nr_cores = topology_num_cores_per_package();
 		pdata->core_data = kzalloc_objs(struct temp_data *,
-						pdata->nr_cores);
+						nr_cores);
 		if (!pdata->core_data)
 			return NULL;
+		pdata->nr_cores = nr_cores;
 	}
 
 	tdata = kzalloc_obj(struct temp_data);
@@ -533,9 +535,6 @@ 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);
-		pdata->core_data = NULL;
-		pdata->nr_cores = 0;
 	} else {
 		pdata->core_data[tdata->index] = NULL;
 		ida_free(&pdata->ida, tdata->index);
@@ -605,7 +604,7 @@ static void
 coretemp_add_core(struct platform_device *pdev, unsigned int cpu, int pkg_flag)
 {
 	if (create_core_data(pdev, cpu, pkg_flag))
-		dev_err(&pdev->dev, "Adding Core %u failed\n", cpu);
+		dev_err_ratelimited(&pdev->dev, "Adding Core %u failed\n", cpu);
 }
 
 static void coretemp_remove_core(struct platform_data *pdata, struct temp_data *tdata)
@@ -714,20 +713,16 @@ static int coretemp_cpu_online(unsigned int cpu)
 		if (IS_ERR(hwmon))
 			return PTR_ERR(hwmon);
 		pdata->hwmon_dev = hwmon;
-
-		/*
-		 * Check whether pkgtemp support is available.
-		 * If so, add interfaces for pkgtemp.
-		 */
-		if (cpu_has(c, X86_FEATURE_PTS))
-			coretemp_add_core(pdev, cpu, 1);
 	}
 
 	/*
-	 * Check whether a housekeeping thread sibling is already online. If
-	 * not, add the interface for this CPU core.
+	 * Add missing package and core interfaces. Besides handling the first
+	 * CPU in the zone, this retries an earlier failed creation attempt.
 	 */
-	if (!cpumask_intersects(&pdata->cpumask, topology_sibling_cpumask(cpu)))
+	if (cpu_has(c, X86_FEATURE_PTS) && !pdata->pkg_data)
+		coretemp_add_core(pdev, cpu, 1);
+
+	if (!get_temp_data(pdata, cpu))
 		coretemp_add_core(pdev, cpu, 0);
 
 	cpumask_set_cpu(cpu, &pdata->cpumask);
@@ -778,6 +773,9 @@ static int coretemp_cpu_offline(unsigned int cpu)
 			coretemp_remove_core(pd, tdata);
 		hwmon_device_unregister(pd->hwmon_dev);
 		pd->hwmon_dev = NULL;
+		kfree(pd->core_data);
+		pd->core_data = NULL;
+		pd->nr_cores = 0;
 		return 0;
 	}
 

---
base-commit: 0b6eda22f9ab67ddb2a872b0c3fc578ad9f4e27e
change-id: 20261020-coretemp-retry-sensor-creation-df49c07a2c86

Best regards,

Signature · 1 line
Ximing Zhang <[email protected]>
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 20 lines

From: Ximing Zhang <[email protected]>

coretemp_add_core() only logs create_core_data() failures, but coretemp_cpu_online() still records the CPU in pdata->cpumask. When an SMT sibling is processed later, the mask makes the driver skip sensor creation. The core interface then remains absent until all siblings are cycled or the module is reloaded.

Package sensor creation is similarly attempted only when the hwmon device is first registered. A failure leaves the package interface absent for the lifetime of that device.

Retry missing package and core sensors whenever an eligible CPU comes online. Determine whether a core sensor exists from its temperature data instead of the CPU mask, which continues to track CPUs available for MSR [ ... ]
patched driver retried and exposed all five readable sensors. SMT sibling hotplug and 20 module unload/load cycles also retained the expected sensors.

Quoted 1 line

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20261020-coretemp-retry-sensor-creation-v1-1-7dd4851a34dc@gmail.com?part=1
maintainer
#2 lore raw
In reply to Ximing Zhang
Quoted 31 lines · On Tue, Oct 20, 2026 at 09:39:35PM +0400, Ximing Zhang via B4 Relay wrote:

From: Ximing Zhang <[email protected]>

coretemp_add_core() only logs create_core_data() failures, but coretemp_cpu_online() still records the CPU in pdata->cpumask. When an SMT sibling is processed later, the mask makes the driver skip sensor creation. The core interface then remains absent until all siblings are cycled or the module is reloaded.

Package sensor creation is similarly attempted only when the hwmon device is first registered. A failure leaves the package interface absent for the lifetime of that device.

Retry missing package and core sensors whenever an eligible CPU comes online. Determine whether a core sensor exists from its temperature data instead of the CPU mask, which continues to track CPUs available for MSR reads and hotplug retargeting.

A package retry might fail after per-core data exists. Keep the core_data array alive until the hwmon device is unregistered so failure cleanup cannot discard live per-core pointers. Publish nr_cores only after that array is allocated successfully, and rate-limit errors because a permanent failure can now be retried.

Tested on an Intel Core i7-10510U running 7.2.5-1-cachyos. With test-only fault injection, two package creation failures and one Core 0 creation failure left the unpatched driver without both interfaces. The patched driver retried and exposed all five readable sensors. SMT sibling hotplug and 20 module unload/load cycles also retained the expected sensors.

Quoted 8 lines

---
coretemp currently treats a failed package or per-core sensor creation as permanent for the lifetime of the hwmon device. This change retries missing sensors as eligible CPUs come online while keeping the CPU mask available for MSR targeting and hotplug handling.

Tested on an Intel Core i7-10510U running 7.2.5-1-cachyos. Test-only fault injection reproduced missing package and Core 0 interfaces with the current

Is that a theoretic or a real problem ? "Test-only fault injection" very much suggests that it is a theoretic problem. Have you observed it on a real system (without artificial fault injection) ?

Thanks,
Guenter

#3 lore raw
Quoted 3 lines

Is that a theoretic or a real problem ? "Test-only fault injection" very much suggests that it is a theoretic problem. Have you observed it on a real system (without artificial fault injection) ?

It is theoretical. I have not observed the failure on an unmodified system. I found the unretried error path while auditing the driver and used fault injection to verify the existing behavior and the proposed recovery.

I agree that the fault-injection test establishes the behavior but not real-world impact. Please disregard this patch.

Thanks,
Ximing

maintainer
#4 lore raw
Quoted 4 lines · Ximing Zhang
Quoted 3 lines

Is that a theoretic or a real problem ? "Test-only fault injection" very much suggests that it is a theoretic problem. Have you observed it on a real system (without artificial fault injection) ?

Quoted 8 lines

It is theoretical. I have not observed the failure on an unmodified system. I found the unretried error path while auditing the driver and used fault injection to verify the existing behavior and the proposed recovery.

I agree that the fault-injection test establishes the behavior but not real-world impact. Please disregard this patch.

Please refrain from submitting similar patches. As it is, I am already overloaded with patches fixing real problems. Patches like this result in me getting even further behind, and real problems are not getting fixed.

Thanks,
Guenter