aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/eventfd.h
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-02-02 08:23:03 -0700
committerJens Axboe <axboe@kernel.dk>2020-02-03 17:27:38 -0700
commitb5e683d5cab8cd433b06ae178621f083cabd4f63 (patch)
treeff80c1fcdd40441ae015b35d67897c1f63129a9c /include/linux/eventfd.h
parentio_uring: add BUILD_BUG_ON() to assert the layout of struct io_uring_sqe (diff)
downloadlinux-dev-b5e683d5cab8cd433b06ae178621f083cabd4f63.tar.xz
linux-dev-b5e683d5cab8cd433b06ae178621f083cabd4f63.zip
eventfd: track eventfd_signal() recursion depth
eventfd use cases from aio and io_uring can deadlock due to circular or resursive calling, when eventfd_signal() tries to grab the waitqueue lock. On top of that, it's also possible to construct notification chains that are deep enough that we could blow the stack. Add a percpu counter that tracks the percpu recursion depth, warn if we exceed it. The counter is also exposed so that users of eventfd_signal() can do the right thing if it's non-zero in the context where it is called. Cc: stable@vger.kernel.org # 4.19+ Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/eventfd.h')
-rw-r--r--include/linux/eventfd.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index ffcc7724ca21..dc4fd8a6644d 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -12,6 +12,8 @@
#include <linux/fcntl.h>
#include <linux/wait.h>
#include <linux/err.h>
+#include <linux/percpu-defs.h>
+#include <linux/percpu.h>
/*
* CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining
@@ -40,6 +42,13 @@ __u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_entry_t *wait,
__u64 *cnt);
+DECLARE_PER_CPU(int, eventfd_wake_count);
+
+static inline bool eventfd_signal_count(void)
+{
+ return this_cpu_read(eventfd_wake_count);
+}
+
#else /* CONFIG_EVENTFD */
/*
@@ -68,6 +77,11 @@ static inline int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx,
return -ENOSYS;
}
+static inline bool eventfd_signal_count(void)
+{
+ return false;
+}
+
#endif
#endif /* _LINUX_EVENTFD_H */