Skip to contentSkip to conversation

platform/x86/intel/tpmi: Clean up CPU mappings on offline

PATCH In review lirongqing 2 participants 2 messages Nov 14 – Nov 16 x86 platform drivers

lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH v2 1/1 platform/x86/intel/tpmi: Clean up CPU mappings on offline

From: Li RongQing <[email protected]>

The driver adds each online CPU to tpmi_cpu_hash and to its power domain mask. Neither entry is removed when the CPU goes offline, so the next online transition calls hash_add() on an hlist node that is still linked, corrupting the hash list.

Register an offline callback that removes the hash entry and clears the CPU from its power domain mask.

The TPMI feature does not depend on CPU online/offline and can update the MMIO area while a CPU is offline. There is currently no consumer that reads the mapping data of an offlined CPU; if such a use case appears, retaining the offline mapping can be added on top.

Fixes 17ca2780458c ("platform/x86/intel: TPMI domain id and CPU mapping")

---
Changes in v2:

- Add Acked-by from Srinivas Pandruvada
- Rename the title
- Add a new line after guard()

 drivers/platform/x86/intel/tpmi_power_domains.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/tpmi_power_domains.c +19 -1
index ebe052c..457abac 100644
@@ -220,6 +220,24 @@ static int tpmi_cpu_online(unsigned int cpu)
 	return 0;
 }
 
+static int tpmi_cpu_offline(unsigned int cpu)
+{
+	struct tpmi_cpu_info *info = &per_cpu(tpmi_cpu_info, cpu);
+	int index;
+
+	if (hlist_unhashed(&info->hnode) || !tpmi_domain_is_valid(info))
+		return 0;
+
+	index = info->pkg_id * MAX_POWER_DOMAINS + info->punit_domain_id;
+
+	guard(mutex)(&tpmi_lock);
+
+	cpumask_clear_cpu(cpu, &tpmi_power_domain_mask[index]);
+	hash_del(&info->hnode);
+
+	return 0;
+}
+
 static int __init tpmi_init(void)
 {
 	const struct x86_cpu_id *id;
@@ -249,7 +267,7 @@ static int __init tpmi_init(void)
 
 	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 				"platform/x86/tpmi_power_domains:online",
-				tpmi_cpu_online, NULL);
+				tpmi_cpu_online, tpmi_cpu_offline);
 	if (ret < 0)
 		goto free_domain_map;
 
Signature · 1 line
2.9.4
maintainer
#1 lore raw
Quoted 35 lines · lirongqing

From: Li RongQing <[email protected]>

The driver adds each online CPU to tpmi_cpu_hash and to its power domain mask. Neither entry is removed when the CPU goes offline, so the next online transition calls hash_add() on an hlist node that is still linked, corrupting the hash list.

Register an offline callback that removes the hash entry and clears the CPU from its power domain mask.

The TPMI feature does not depend on CPU online/offline and can update the MMIO area while a CPU is offline. There is currently no consumer that reads the mapping data of an offlined CPU; if such a use case appears, retaining the offline mapping can be added on top.

Fixes 17ca2780458c ("platform/x86/intel: TPMI domain id and CPU mapping")

---
Changes in v2:

- Add Acked-by from Srinivas Pandruvada
- Rename the title
- Add a new line after guard()

 drivers/platform/x86/intel/tpmi_power_domains.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/tpmi_power_domains.c +0 -0
index ebe052c..457abac 100644
@@ -220,6 +220,24 @@ static int tpmi_cpu_online(unsigned int cpu)
 	return 0;
 }

drivers/platform/x86/intel/tpmi_power_domains.c static int tpmi_cpu_online(unsigned int cpu) · line 231

Quoted 10 lines
drivers/platform/x86/intel/tpmi_power_domains.c +9 -0
 
+static int tpmi_cpu_offline(unsigned int cpu)
+{
+	struct tpmi_cpu_info *info = &per_cpu(tpmi_cpu_info, cpu);
+	int index;
+
+	if (hlist_unhashed(&info->hnode) || !tpmi_domain_is_valid(info))
+		return 0;
+
+	index = info->pkg_id * MAX_POWER_DOMAINS + info->punit_domain_id;

Hi,

I've taken this patch into the review-ilpo-next branch.

...But could you make another patch on top of it which adds a helper for this index calculation (from the tpmi_cpu_info struct, the one in tpmi_get_linux_die_id() seems to not have it so it can be left as is). It seems to be repeated a few times and is quite long, online func even calculates it twice.

Signature · 1 line
 i.
Quoted 22 lines
drivers/platform/x86/intel/tpmi_power_domains.c +10 -1
+
+	guard(mutex)(&tpmi_lock);
+
+	cpumask_clear_cpu(cpu, &tpmi_power_domain_mask[index]);
+	hash_del(&info->hnode);
+
+	return 0;
+}
+
 static int __init tpmi_init(void)
 {
 	const struct x86_cpu_id *id;
@@ -249,7 +267,7 @@ static int __init tpmi_init(void)
 
 	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 				"platform/x86/tpmi_power_domains:online",
-				tpmi_cpu_online, NULL);
+				tpmi_cpu_online, tpmi_cpu_offline);
 	if (ret < 0)
 		goto free_domain_map;
 
Signature · 1 line
 i.