mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-30 08:02:30 +00:00
b5e683d5ca
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>
88 lines
2 KiB
C
88 lines
2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* include/linux/eventfd.h
|
|
*
|
|
* Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org>
|
|
*
|
|
*/
|
|
|
|
#ifndef _LINUX_EVENTFD_H
|
|
#define _LINUX_EVENTFD_H
|
|
|
|
#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
|
|
* new flags, since they might collide with O_* ones. We want
|
|
* to re-use O_* flags that couldn't possibly have a meaning
|
|
* from eventfd, in order to leave a free define-space for
|
|
* shared O_* flags.
|
|
*/
|
|
#define EFD_SEMAPHORE (1 << 0)
|
|
#define EFD_CLOEXEC O_CLOEXEC
|
|
#define EFD_NONBLOCK O_NONBLOCK
|
|
|
|
#define EFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
|
|
#define EFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS | EFD_SEMAPHORE)
|
|
|
|
struct eventfd_ctx;
|
|
struct file;
|
|
|
|
#ifdef CONFIG_EVENTFD
|
|
|
|
void eventfd_ctx_put(struct eventfd_ctx *ctx);
|
|
struct file *eventfd_fget(int fd);
|
|
struct eventfd_ctx *eventfd_ctx_fdget(int fd);
|
|
struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
|
|
__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 */
|
|
|
|
/*
|
|
* Ugly ugly ugly error layer to support modules that uses eventfd but
|
|
* pretend to work in !CONFIG_EVENTFD configurations. Namely, AIO.
|
|
*/
|
|
|
|
static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
|
|
{
|
|
return ERR_PTR(-ENOSYS);
|
|
}
|
|
|
|
static inline int eventfd_signal(struct eventfd_ctx *ctx, int n)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
|
|
static inline void eventfd_ctx_put(struct eventfd_ctx *ctx)
|
|
{
|
|
|
|
}
|
|
|
|
static inline int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx,
|
|
wait_queue_entry_t *wait, __u64 *cnt)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
|
|
static inline bool eventfd_signal_count(void)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* _LINUX_EVENTFD_H */
|
|
|