Skip to content

Commit 2ed6edd

Browse files
Barret RhodenPeter Zijlstra
authored andcommitted
perf: Add cond_resched() to task_function_call()
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: [email protected] Signed-off-by: Barret Rhoden <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 3a4ac12 commit 2ed6edd

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

kernel/events/core.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ static void remote_function(void *data)
9595
* @info: the function call argument
9696
*
9797
* Calls the function @func when the task is currently running. This might
98-
* be on the current CPU, which just calls the function directly
98+
* be on the current CPU, which just calls the function directly. This will
99+
* retry due to any failures in smp_call_function_single(), such as if the
100+
* task_cpu() goes offline concurrently.
99101
*
100-
* returns: @func return value, or
101-
* -ESRCH - when the process isn't running
102-
* -EAGAIN - when the process moved away
102+
* returns @func return value or -ESRCH when the process isn't running
103103
*/
104104
static int
105105
task_function_call(struct task_struct *p, remote_function_f func, void *info)
@@ -112,11 +112,16 @@ task_function_call(struct task_struct *p, remote_function_f func, void *info)
112112
};
113113
int ret;
114114

115-
do {
116-
ret = smp_call_function_single(task_cpu(p), remote_function, &data, 1);
117-
if (!ret)
118-
ret = data.ret;
119-
} while (ret == -EAGAIN);
115+
for (;;) {
116+
ret = smp_call_function_single(task_cpu(p), remote_function,
117+
&data, 1);
118+
ret = !ret ? data.ret : -EAGAIN;
119+
120+
if (ret != -EAGAIN)
121+
break;
122+
123+
cond_resched();
124+
}
120125

121126
return ret;
122127
}

0 commit comments

Comments
 (0)