All of lore.kernel.org
 help / color / mirror / Atom feed
* perf: add cond_resched() to task_function_call()
@ 2020-04-14 19:03 Barret Rhoden
  2020-04-14 20:42 ` Peter Zijlstra
  2020-04-14 22:29 ` Barret Rhoden
  0 siblings, 2 replies; 7+ messages in thread
From: Barret Rhoden @ 2020-04-14 19:03 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo
  Cc: Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	linux-kernel, syzbot+bb4935a5c09b5ff79940

Under rare circumstances, task_function_call() can repeatedly fail and
cause a soft lockup.

There is a slight race where the process is no longer running on the cpu
we targeted by the time remote_function() runs.  The code will simply
try again.  If we are very unlucky, this will continue to fail, until a
watchdog fires.  This can happen in a heavily loaded, multi-core virtual
machine.

Reported-by: syzbot+bb4935a5c09b5ff79940@syzkaller.appspotmail.com
Signed-off-by: Barret Rhoden <brho@google.com>
---
 kernel/events/core.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 55e44417f66d..65c2c05e24c2 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -99,7 +99,7 @@ static void remote_function(void *data)
  *
  * returns: @func return value, or
  *	    -ESRCH  - when the process isn't running
- *	    -EAGAIN - when the process moved away
+ *	    -ENXIO  - when the cpu the process was on has gone offline
  */
 static int
 task_function_call(struct task_struct *p, remote_function_f func, void *info)
@@ -112,11 +112,15 @@ task_function_call(struct task_struct *p, remote_function_f func, void *info)
 	};
 	int ret;
 
-	do {
-		ret = smp_call_function_single(task_cpu(p), remote_function, &data, 1);
+	while (1) {
+		ret = smp_call_function_single(task_cpu(p), remote_function,
+					       &data, 1);
 		if (!ret)
 			ret = data.ret;
-	} while (ret == -EAGAIN);
+		if (ret != -EAGAIN)
+			break;
+		cond_resched();
+	}
 
 	return ret;
 }
-- 
2.26.0.110.g2183baf09c-goog


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

end of thread, other threads:[~2020-05-23  9:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-14 19:03 perf: add cond_resched() to task_function_call() Barret Rhoden
2020-04-14 20:42 ` Peter Zijlstra
2020-04-14 21:16   ` Barret Rhoden
2020-04-14 22:29 ` Barret Rhoden
2020-05-01 18:22   ` [tip: perf/core] perf: Add " tip-bot2 for Barret Rhoden
2020-05-23  9:20     ` Jiri Olsa
2020-05-23  9:27       ` Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.