mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH] smp: Evaluate local cond_func() before IPI side-effects
@ 2024-12-03 16:35 Mathieu Desnoyers
  2024-12-03 17:21 ` Rik van Riel
  2024-12-05 14:42 ` [tip: locking/core] smp/scf: " tip-bot2 for Mathieu Desnoyers
  0 siblings, 2 replies; 3+ messages in thread
From: Mathieu Desnoyers @ 2024-12-03 16:35 UTC (permalink / raw)
  To: Rik van Riel
  Cc: linux-kernel, Mathieu Desnoyers, Peter Zijlstra, Ingo Molnar,
	Dave Hansen, Linus Torvalds, Mel Gorman, x86

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.

Link: https://lore.kernel.org/lkml/20241202202213.26a79ed6@fangorn/
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: x86@kernel.org
---
 kernel/smp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index 27dc31a146a3..f104c8e83fc4 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -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. */
@@ -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);
-- 
2.39.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] smp: Evaluate local cond_func() before IPI side-effects
  2024-12-03 16:35 [RFC PATCH] smp: Evaluate local cond_func() before IPI side-effects Mathieu Desnoyers
@ 2024-12-03 17:21 ` Rik van Riel
  2024-12-05 14:42 ` [tip: locking/core] smp/scf: " tip-bot2 for Mathieu Desnoyers
  1 sibling, 0 replies; 3+ messages in thread
From: Rik van Riel @ 2024-12-03 17:21 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: linux-kernel, Peter Zijlstra, Ingo Molnar, Dave Hansen,
	Linus Torvalds, Mel Gorman, x86

On Tue, 2024-12-03 at 11:35 -0500, Mathieu Desnoyers wrote:
> 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.
> 
> Link: https://lore.kernel.org/lkml/20241202202213.26a79ed6@fangorn/
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> 

Reviewed-by: Rik van Riel <riel@surriel.com>

-- 
All Rights Reversed.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: locking/core] smp/scf: Evaluate local cond_func() before IPI side-effects
  2024-12-03 16:35 [RFC PATCH] smp: Evaluate local cond_func() before IPI side-effects Mathieu Desnoyers
  2024-12-03 17:21 ` Rik van Riel
@ 2024-12-05 14:42 ` tip-bot2 for Mathieu Desnoyers
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Mathieu Desnoyers @ 2024-12-05 14:42 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Mathieu Desnoyers, Ingo Molnar, Rik van Riel, Linus Torvalds,
	Peter Zijlstra, Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     63a48181fbcddefe5fb4c6618938bb64c543945b
Gitweb:        https://git.kernel.org/tip/63a48181fbcddefe5fb4c6618938bb64c543945b
Author:        Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
AuthorDate:    Tue, 03 Dec 2024 11:35:58 -05:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 05 Dec 2024 14:25:28 +01:00

smp/scf: Evaluate local cond_func() before IPI side-effects

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
---
 kernel/smp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index 27dc31a..f104c8e 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -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. */
@@ -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);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-05 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-03 16:35 [RFC PATCH] smp: Evaluate local cond_func() before IPI side-effects Mathieu Desnoyers
2024-12-03 17:21 ` Rik van Riel
2024-12-05 14:42 ` [tip: locking/core] smp/scf: " tip-bot2 for Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®