aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <[email protected]>2022-07-11 23:21:23 +0000
committerEric W. Biederman <[email protected]>2022-07-18 14:53:38 +0000
commita7c01fa93aeb03ab76cd3cb2107990dd160498e6 (patch)
tree23d0aa124d3946238594aea55bcf20eb97d33770 /net/unix/af_unix.c
parentLinux 5.19-rc1 (diff)
downloadkernel-a7c01fa93aeb03ab76cd3cb2107990dd160498e6.tar.gz
kernel-a7c01fa93aeb03ab76cd3cb2107990dd160498e6.zip
signal: break out of wait loops on kthread_stop()
I was recently surprised to learn that msleep_interruptible(), wait_for_completion_interruptible_timeout(), and related functions simply hung when I called kthread_stop() on kthreads using them. The solution to fixing the case with msleep_interruptible() was more simply to move to schedule_timeout_interruptible(). Why? The reason is that msleep_interruptible(), and many functions just like it, has a loop like this: while (timeout && !signal_pending(current)) timeout = schedule_timeout_interruptible(timeout); The call to kthread_stop() woke up the thread, so schedule_timeout_ interruptible() returned early, but because signal_pending() returned true, it went back into another timeout, which was never woken up. This wait loop pattern is common to various pieces of code, and I suspect that the subtle misuse in a kthread that caused a deadlock in the code I looked at last week is also found elsewhere. So this commit causes signal_pending() to return true when kthread_stop() is called, by setting TIF_NOTIFY_SIGNAL. The same also probably applies to the similar kthread_park() functionality, but that can be addressed later, as its semantics are slightly different. Cc: Eric W. Biederman <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]> v1: https://lkml.kernel.org/r/[email protected] v2: https://lkml.kernel.org/r/[email protected] v3: https://lkml.kernel.org/r/[email protected] v4: https://lkml.kernel.org/r/[email protected] v5: https://lkml.kernel.org/r/[email protected] Signed-off-by: Eric W. Biederman <[email protected]>
Diffstat (limited to 'net/unix/af_unix.c')
0 files changed, 0 insertions, 0 deletions