public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86/intel-uncore-freq: fix inconsistent state on init failure
@ 2025-04-14  9:21 shouyeliu
  2025-04-14 10:41 ` Ilpo Järvinen
  0 siblings, 1 reply; 7+ messages in thread
From: shouyeliu @ 2025-04-14  9:21 UTC (permalink / raw)
  To: srinivas.pandruvada, hdegoede, ilpo.jarvinen
  Cc: platform-driver-x86, linux-kernel, shouyeliu

When uncore_event_cpu_online() fails to initialize a control CPU (e.g.,
due to memory allocation failure or uncore_freq_add_entry() errors),
the code leaves stale entries in uncore_cpu_mask after that online CPU
will not try to call uncore_freq_add_entry, resulting in no sys interface.

Signed-off-by: shouyeliu <shouyeliu@gmail.com>
---
 .../x86/intel/uncore-frequency/uncore-frequency.c    | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
index 40bbf8e45fa4..1de0a4a9d6cd 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
@@ -146,15 +146,13 @@ static int uncore_event_cpu_online(unsigned int cpu)
 {
 	struct uncore_data *data;
 	int target;
+	int ret;
 
 	/* Check if there is an online cpu in the package for uncore MSR */
 	target = cpumask_any_and(&uncore_cpu_mask, topology_die_cpumask(cpu));
 	if (target < nr_cpu_ids)
 		return 0;
 
-	/* Use this CPU on this die as a control CPU */
-	cpumask_set_cpu(cpu, &uncore_cpu_mask);
-
 	data = uncore_get_instance(cpu);
 	if (!data)
 		return 0;
@@ -163,7 +161,13 @@ static int uncore_event_cpu_online(unsigned int cpu)
 	data->die_id = topology_die_id(cpu);
 	data->domain_id = UNCORE_DOMAIN_ID_INVALID;
 
-	return uncore_freq_add_entry(data, cpu);
+	ret = uncore_freq_add_entry(data, cpu);
+	if (!ret) {
+		/* Use this CPU on this die as a control CPU */
+		cpumask_set_cpu(cpu, &uncore_cpu_mask);
+	}
+
+	return ret;
 }
 
 static int uncore_event_cpu_offline(unsigned int cpu)
-- 
2.19.1


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

end of thread, other threads:[~2025-04-16  2:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14  9:21 [PATCH] platform/x86/intel-uncore-freq: fix inconsistent state on init failure shouyeliu
2025-04-14 10:41 ` Ilpo Järvinen
2025-04-14 16:06   ` srinivas pandruvada
2025-04-15  6:54     ` liu shouye
     [not found]     ` <CAAscG3VHVdNDQGfsdBs_ht5H-WUtCBksMYPXLKW2D6Uqu3yeAA@mail.gmail.com>
     [not found]       ` <331a55fe7334cf425ddb8826160b64a5af37c805.camel@linux.intel.com>
2025-04-15 15:10         ` Ilpo Järvinen
2025-04-15 22:11           ` srinivas pandruvada
2025-04-16  2:34             ` liu shouye

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