Skip to content

Commit 0f7ced7

Browse files
jic23bp3tk0v
authored andcommitted
x86/aperfmperf: Fix deadlock on cpu_hotplug_lock
The broken patch results in a call to init_freq_invariance_cppc() in a CPU hotplug handler in both the path for initially present CPUs and those hotplugged later. That function includes a one time call to amd_set_max_freq_ratio() which in turn calls freq_invariance_enable() that has a static_branch_enable() which takes the cpu_hotlug_lock which is already held. Avoid the deadlock by using static_branch_enable_cpuslocked() as the lock will always be already held. The equivalent path on Intel does not already hold this lock, so take it around the call to freq_invariance_enable(), which results in it being held over the call to register_syscall_ops, which looks to be safe to do. Fixes: c1385c1 ("ACPI: processor: Simplify initial onlining to use same path for cold and hotplug") Closes: https://lore.kernel.org/all/CABXGCsPvqBfL5hQDOARwfqasLRJ_eNPBbCngZ257HOe=xbWDkA@mail.gmail.com/ Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com> Suggested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com> Tested-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20240729105504.2170-1-Jonathan.Cameron@huawei.com
1 parent 8400291 commit 0f7ced7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/x86/kernel/cpu/aperfmperf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static void freq_invariance_enable(void)
306306
WARN_ON_ONCE(1);
307307
return;
308308
}
309-
static_branch_enable(&arch_scale_freq_key);
309+
static_branch_enable_cpuslocked(&arch_scale_freq_key);
310310
register_freq_invariance_syscore_ops();
311311
pr_info("Estimated ratio of average max frequency by base frequency (times 1024): %llu\n", arch_max_freq_ratio);
312312
}
@@ -323,8 +323,10 @@ static void __init bp_init_freq_invariance(void)
323323
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
324324
return;
325325

326-
if (intel_set_max_freq_ratio())
326+
if (intel_set_max_freq_ratio()) {
327+
guard(cpus_read_lock)();
327328
freq_invariance_enable();
329+
}
328330
}
329331

330332
static void disable_freq_invariance_workfn(struct work_struct *work)

0 commit comments

Comments
 (0)