Bug 205933
Summary: | There seems to be an in-kernel race between epoll_wait and epoll_ctl which leads to lost events on an eventfd file descriptor | ||
---|---|---|---|
Product: | IO/Storage | Reporter: | Max Neunhöffer (max) |
Component: | Other | Assignee: | io_other |
Status: | NEW --- | ||
Severity: | normal | CC: | joh82875, leitao |
Priority: | P1 | ||
Hardware: | x86-64 | ||
OS: | Linux | ||
Kernel Version: | Stock 5.4.0 from tag v5.4 | Subsystem: | |
Regression: | Yes | Bisected commit-id: | |
Attachments: |
Program which shows the bug.
Kernel configuration of Stock 5.4 kernel which shows the behaviour Another program showing a variant of the buggy behaviour. Kernel config for commit a218cc4914209ac14476cb32769b31a556355b22 to see the problem. Kernel config for commit c3e320b61581ef7919269ca242ff13951ccfc763 to see the problem not yet there. Example program for bug with level triggered events. |
Description
Max Neunhöffer
2019-12-20 15:52:24 UTC
Dear All, I have now replicated the problem on a stock vanilla kernel version 5.4. I used this git repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git and the "v5.4" tag in there. Best regards, Max. Created attachment 286655 [details]
Kernel configuration of Stock 5.4 kernel which shows the behaviour
Dear All, I have exchanged emails with Chris Kohlhoff who uses this functionality in `boost::asio`. He has kindly provided a patched version of the program which displays the buggy behaviour. The patched version uses `eventfd` and `epoll_wait` in a way which "some would consider a more traditional use". This time, the flag `EPOLLONESHOT` is used and the `eventfd` is explicitly rearmed by a `epoll_ctl` call with `EPOLL_CTL_MOD` as suggested in the `epoll_ctl` manpage. Furthermore, the flag `EFD_SEMAPHORE` is used for the event fd. I would imagine that other projects than `boost::asio` would follow similar usage patterns like this one and might therefore also suffer from lost wakeup events. Furthermore, Chris has reproduced the problem on a 5.4 kernel. I attach the patched program. Any comment or help with this would be really appreciated. Cheers, Max. Created attachment 287007 [details]
Another program showing a variant of the buggy behaviour.
I did a git bisect and have tracked down the bug to this commit: https://github.com/torvalds/linux/commit/a218cc4914209ac14476cb32769b31a556355b22 The latest kernel at https://github.com/torvalds/linux still shows the problem. Note furthermore that the problem does not occur if the VM to run the kernel has only one CPU. With 4 CPUs I could reproduce. Below I will post the kernel configs I used to compile the two commits a218cc4914209ac14476cb32769b31a556355b22 (bad) c3e320b61581ef7919269ca242ff13951ccfc763 (good) Cheers, Max. Created attachment 287089 [details]
Kernel config for commit a218cc4914209ac14476cb32769b31a556355b22 to see the problem.
Kernel config for commit a218cc4914209ac14476cb32769b31a556355b22 to see the problem.
Created attachment 287091 [details]
Kernel config for commit c3e320b61581ef7919269ca242ff13951ccfc763 to see the problem not yet there.
Christopher Kohlhoff has produced another program to show that the bug also shows up with level triggered eventfds. I attach the program. Max. Created attachment 287093 [details]
Example program for bug with level triggered events.
For info: This has in the meantime been discussed and fixed on the netdev mailing list, see https://lore.kernel.org/netdev/d4d188512ea84f243310dd9464922a82@suse.de/ Cheers, Max I understand that this bug is still not fixed upstream (5.6-rc5), is this right? |