Skip to contentSkip to conversation

smp: Warn on function calls from softirq context

PATCH New Wen Yang 1 participant 1 message Feb 19, 2021 Stable branch

lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 smp: Warn on function calls from softirq context

From: Peter Zijlstra <[email protected]>

commit 19dbdcb8039cff16669a05136a29180778d16d0a upstream.

It's clearly documented that smp function calls cannot be invoked from softirq handling context. Unfortunately nothing enforces that or emits a warning.

A single function call can be invoked from softirq context only via smp_call_function_single_async().

The only legit context is task context, so add a warning to that effect.

---
 kernel/smp.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
kernel/smp.c +16 -0
index c94dd85..7d00d3e 100644
@@ -290,6 +290,14 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info,
 	WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled()
 		     && !oops_in_progress);
 
+	/*
+	 * When @wait we can deadlock when we interrupt between llist_add() and
+	 * arch_send_call_function_ipi*(); when !@wait we can deadlock due to
+	 * csd_lock() on because the interrupt context uses the same csd
+	 * storage.
+	 */
+	WARN_ON_ONCE(!in_task());
+
 	csd = &csd_stack;
 	if (!wait) {
 		csd = this_cpu_ptr(&csd_data);
@@ -415,6 +423,14 @@ void smp_call_function_many(const struct cpumask *mask,
 	WARN_ON_ONCE(cpu_online(this_cpu) && irqs_disabled()
 		     && !oops_in_progress && !early_boot_irqs_disabled);
 
+	/*
+	 * When @wait we can deadlock when we interrupt between llist_add() and
+	 * arch_send_call_function_ipi*(); when !@wait we can deadlock due to
+	 * csd_lock() on because the interrupt context uses the same csd
+	 * storage.
+	 */
+	WARN_ON_ONCE(!in_task());
+
 	/* Try to fastpath.  So, what's a CPU they want? Ignoring this one. */
 	cpu = cpumask_first_and(mask, cpu_online_mask);
 	if (cpu == this_cpu)
Signature · 1 line
1.8.3.1