1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
4 #include <linux/file.h>
6 #include <linux/uaccess.h>
7 #include <linux/io_uring.h>
8 #include <linux/eventpoll.h>
10 #include <uapi/linux/io_uring.h>
12 #include "io_uring_types.h"
16 #if defined(CONFIG_EPOLL)
22 struct epoll_event event;
25 int io_epoll_ctl_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
27 struct io_epoll *epoll = io_kiocb_to_cmd(req);
29 pr_warn_once("%s: epoll_ctl support in io_uring is deprecated and will "
30 "be removed in a future Linux kernel version.\n",
33 if (sqe->buf_index || sqe->splice_fd_in)
36 epoll->epfd = READ_ONCE(sqe->fd);
37 epoll->op = READ_ONCE(sqe->len);
38 epoll->fd = READ_ONCE(sqe->off);
40 if (ep_op_has_event(epoll->op)) {
41 struct epoll_event __user *ev;
43 ev = u64_to_user_ptr(READ_ONCE(sqe->addr));
44 if (copy_from_user(&epoll->event, ev, sizeof(*ev)))
51 int io_epoll_ctl(struct io_kiocb *req, unsigned int issue_flags)
53 struct io_epoll *ie = io_kiocb_to_cmd(req);
55 bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
57 ret = do_epoll_ctl(ie->epfd, ie->op, ie->fd, &ie->event, force_nonblock);
58 if (force_nonblock && ret == -EAGAIN)
63 io_req_set_res(req, ret, 0);