mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwmon: (coretemp) Retry failed sensor creation
@ 2026-10-20 17:39 Ximing Zhang via B4 Relay
  2026-10-20 18:35 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Ximing Zhang via B4 Relay @ 2026-10-20 17:39 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-hwmon, linux-kernel, Ximing Zhang

From: Ximing Zhang <xzhangjr@gmail.com>

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.

Signed-off-by: Ximing Zhang <xzhangjr@gmail.com>
---
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(-)

diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 3836beade59f..fa3b04d0e041 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -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,
--  
Ximing Zhang <xzhangjr@gmail.com>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-20 18:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-20 17:39 [PATCH] hwmon: (coretemp) Retry failed sensor creation Ximing Zhang via B4 Relay
2026-10-20 18:35 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®