Created attachment 295871 [details]
Code to reproduce the issue
I've been experiencing some weird bugs with pipes sometimes being stuck in a deadlock since kernel v5.8 if they are being resized.
A child process is stuck in pipe_read:
While the parent process is stuck in the corresponding pipe_write:
The bug is only triggered if pipes get resized, which seemingly very little processes actually do.
A git bisect landed on the following commit:
Author: David Howells <firstname.lastname@example.org>
Date: Tue Jan 14 17:07:11 2020 +0000
pipe: Add general notification queue support
I've attached some code that reproduces the bug for me (may take a few hundred loops). Removing the fcntl for F_SETPIPE_SZ removes the pipe_read/write deadlocks, so I guess the bug is somewhere in the resizing logic.
I can reproduce the issue using the provided code.
Created attachment 295881 [details]
Patch fixing the race condition
I've found the race condition.
After resizing a pipe a wakeup is issued for pipe_write, before actually raising the max_usage value for that pipe.
Depending on wether the pipe was full before resizing or not this could result in a deadlock situation.
I've attached a patch for this to this issue. It's build against v5.8 because that's what I've been using for testing. If necessary please let me know and I'll rebase it for a newer version.
Created attachment 296031 [details]
[PATCH] fs/pipe: wakeup wr_wait after setting max_usage
I revised the patch to better address the regression instead of weirdly pasting code around and also sent it to the linux-kernel mailing list with Alan Cox and David Howells in Cc.
What is the current status of getting this merged? I recently encountered it in the wild. Thanks.