Skip to content

Commit

Permalink
smp/scf: Evaluate local cond_func() before IPI side-effects
Browse files Browse the repository at this point in the history
In smp_call_function_many_cond(), the local cond_func() is evaluated
after triggering the remote CPU IPIs.

If cond_func() depends on loading shared state updated by other CPU's
IPI handlers func(), then triggering execution of remote CPUs IPI before
evaluating cond_func() may have unexpected consequences.

One example scenario is evaluating a jiffies delay in cond_func(), which
is updated by func() in the IPI handlers. This situation can prevent
execution of periodic cleanup code on the local CPU.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Rik van Riel <riel@surriel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20241203163558.3455535-1-mathieu.desnoyers@efficios.com
  • Loading branch information
Mathieu Desnoyers authored and Ingo Molnar committed Dec 5, 2024
1 parent d387ceb commit 63a4818
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,8 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
WARN_ON_ONCE(!in_task());

/* Check if we need local execution. */
if ((scf_flags & SCF_RUN_LOCAL) && cpumask_test_cpu(this_cpu, mask))
if ((scf_flags & SCF_RUN_LOCAL) && cpumask_test_cpu(this_cpu, mask) &&
(!cond_func || cond_func(this_cpu, info)))
run_local = true;

/* Check if we need remote execution, i.e., any CPU excluding this one. */
Expand Down Expand Up @@ -868,7 +869,7 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
send_call_function_ipi_mask(cfd->cpumask_ipi);
}

if (run_local && (!cond_func || cond_func(this_cpu, info))) {
if (run_local) {
unsigned long flags;

local_irq_save(flags);
Expand Down

0 comments on commit 63a4818

Please sign in to comment.