Skip to contentSkip to conversation

perf/x86/amd: Check CPU hotplug setup and unwind failures

PATCH New Ayush Yaduvanshi 2 participants 5 messages Nov 12 – Nov 13

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

cover perf/x86/amd: Check CPU hotplug setup and unwind failures

The AMD Power PMU and IBS drivers register CPU hotplug callbacks during initialization. Both paths need to handle failures in later initialization steps.

The Power PMU change checks the return value of cpuhp_setup_state() and removes the hotplug state if perf_pmu_register() fails.

The IBS change checks cpuhp_setup_state(), removes the hotplug state if perf_event_ibs_init() fails, unregisters the syscore operations registered earlier, and clears ibs_caps on failure.

This series makes the initialization error paths unwind resources acquired before failure.

Ayush Yaduvanshi (2):
perf/x86/amd/power: Fix missing CPU hotplug setup check and cleanup perf/x86/amd/ibs: Fix missing CPU hotplug cleanup and unchecked init
return

 arch/x86/events/amd/ibs.c   | 26 +++++++++++++++++++++-----
 arch/x86/events/amd/power.c |  9 ++++++---
 2 files changed, 27 insertions(+), 8 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 perf/x86/amd/power: Fix missing CPU hotplug setup check and cleanup

Check the return value of cpuhp_setup_state() and remove the hotplug state if perf_pmu_register() fails.

---
 arch/x86/events/amd/power.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/events/amd/power.c +6 -3
index 66197214b010..2627d5269b52 100644
@@ -282,13 +282,16 @@ static int __init amd_power_pmu_init(void)
 	}
 
 
-	cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
-			  "perf/x86/amd/power:online",
-			  power_cpu_init, power_cpu_exit);
+	ret = cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE,
+				"perf/x86/amd/power:online",
+				power_cpu_init, power_cpu_exit);
+	if (ret)
+		return ret;
 
 	ret = perf_pmu_register(&pmu_class, "power", -1);
 	if (WARN_ON(ret)) {
 		pr_warn("AMD Power PMU registration failed\n");
+		cpuhp_remove_state(CPUHP_AP_PERF_X86_AMD_POWER_ONLINE);
 		return ret;
 	}
 
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 1/2] perf/x86/amd/power: Fix missing CPU hotplug setup check and cleanup

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] perf/x86/amd/power: missing Fixes trailer for commit c6a84daa3498 --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] perf/x86/amd/power: missing Fixes trailer for commit c6a84daa3498
--

commit f8ef67a4aa6a417d77c332568d6bad06f58d1c90
Author: Ayush Yaduvanshi <[email protected]>

Quoted 6 lines

perf/x86/amd/power: Fix missing CPU hotplug setup check and cleanup

Check the return value of cpuhp_setup_state() and remove the hotplug state if perf_pmu_register() fails.

[Severity: Low]
This fixes the unchecked cpuhp_setup_state() call and missing error-path cleanup introduced when the driver was converted to the hotplug state machine. Should this include:

Fixes c6a84daa3498 ("perf/x86/amd/power: Convert the hotplug notifier to state machine")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH 2/2 perf/x86/amd/ibs: Fix missing CPU hotplug cleanup and unchecked init return

In reply to Ayush Yaduvanshi

Check the return value of cpuhp_setup_state() and remove the hotplug state if perf_event_ibs_init() fails. Unregister syscore operations and reset ibs_caps on initialization failure.

---
 arch/x86/events/amd/ibs.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)
arch/x86/events/amd/ibs.c +21 -5
index 66e67e27224f..2518cc7a24a6 100644
@@ -2129,6 +2129,7 @@ static int x86_pmu_amd_ibs_dying_cpu(unsigned int cpu)
 static __init int amd_ibs_init(void)
 {
 	u32 caps;
+	int ret;
 
 	caps = __get_ibs_caps();
 	if (!caps)
@@ -2156,12 +2157,27 @@ static __init int amd_ibs_init(void)
 	 * x86_pmu_amd_ibs_starting_cpu will be called from core on
 	 * all online cpus.
 	 */
-	cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
-			  "perf/x86/amd/ibs:starting",
-			  x86_pmu_amd_ibs_starting_cpu,
-			  x86_pmu_amd_ibs_dying_cpu);
+	ret = cpuhp_setup_state(CPUHP_AP_PERF_X86_AMD_IBS_STARTING,
+				"perf/x86/amd/ibs:starting",
+				x86_pmu_amd_ibs_starting_cpu,
+				x86_pmu_amd_ibs_dying_cpu);
+	if (ret)
+		goto err_pm;
+
+	ret = perf_event_ibs_init();
+	if (ret) {
+		cpuhp_remove_state(CPUHP_AP_PERF_X86_AMD_IBS_STARTING);
+		goto err_pm;
+	}
 
-	return perf_event_ibs_init();
+	return 0;
+
+err_pm:
+#ifdef CONFIG_PM
+	unregister_syscore(&perf_ibs_syscore);
+#endif
+	ibs_caps = 0;
+	return ret;
 }
 
 /* Since we need the pci subsystem to init ibs we can't do this earlier: */
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH 2/2] perf/x86/amd/ibs: Fix missing CPU hotplug cleanup and unchecked init return

Sashiko has reviewed this patch and found no issues.
Quoted 5 lines

Check the return value of cpuhp_setup_state() and remove the hotplug state if perf_event_ibs_init() fails. Unregister syscore operations and reset ibs_caps on initialization failure.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2