1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
5 #include <linux/file.h>
7 #include <linux/slab.h>
8 #include <linux/poll.h>
9 #include <linux/hashtable.h>
10 #include <linux/io_uring.h>
12 #include <trace/events/io_uring.h>
14 #include <uapi/linux/io_uring.h>
23 struct io_poll_update {
29 bool update_user_data;
32 struct io_poll_table {
33 struct poll_table_struct pt;
39 #define IO_POLL_CANCEL_FLAG BIT(31)
40 #define IO_POLL_REF_MASK GENMASK(30, 0)
42 #define IO_WQE_F_DOUBLE 1
44 static inline struct io_kiocb *wqe_to_req(struct wait_queue_entry *wqe)
46 unsigned long priv = (unsigned long)wqe->private;
48 return (struct io_kiocb *)(priv & ~IO_WQE_F_DOUBLE);
51 static inline bool wqe_is_double(struct wait_queue_entry *wqe)
53 unsigned long priv = (unsigned long)wqe->private;
55 return priv & IO_WQE_F_DOUBLE;
59 * If refs part of ->poll_refs (see IO_POLL_REF_MASK) is 0, it's free. We can
60 * bump it and acquire ownership. It's disallowed to modify requests while not
61 * owning it, that prevents from races for enqueueing task_work's and b/w
62 * arming poll and wakeups.
64 static inline bool io_poll_get_ownership(struct io_kiocb *req)
66 return !(atomic_fetch_inc(&req->poll_refs) & IO_POLL_REF_MASK);
69 static void io_poll_mark_cancelled(struct io_kiocb *req)
71 atomic_or(IO_POLL_CANCEL_FLAG, &req->poll_refs);
74 static struct io_poll *io_poll_get_double(struct io_kiocb *req)
76 /* pure poll stashes this in ->async_data, poll driven retry elsewhere */
77 if (req->opcode == IORING_OP_POLL_ADD)
78 return req->async_data;
79 return req->apoll->double_poll;
82 static struct io_poll *io_poll_get_single(struct io_kiocb *req)
84 if (req->opcode == IORING_OP_POLL_ADD)
85 return io_kiocb_to_cmd(req);
86 return &req->apoll->poll;
89 static void io_poll_req_insert(struct io_kiocb *req)
91 struct io_hash_table *table = &req->ctx->cancel_table;
92 u32 index = hash_long(req->cqe.user_data, table->hash_bits);
93 struct io_hash_bucket *hb = &table->hbs[index];
96 hlist_add_head(&req->hash_node, &hb->list);
97 spin_unlock(&hb->lock);
100 static void io_poll_req_delete(struct io_kiocb *req, struct io_ring_ctx *ctx)
102 struct io_hash_table *table = &req->ctx->cancel_table;
103 u32 index = hash_long(req->cqe.user_data, table->hash_bits);
104 spinlock_t *lock = &table->hbs[index].lock;
107 hash_del(&req->hash_node);
111 static void io_poll_req_insert_locked(struct io_kiocb *req)
113 struct io_hash_table *table = &req->ctx->cancel_table_locked;
114 u32 index = hash_long(req->cqe.user_data, table->hash_bits);
116 hlist_add_head(&req->hash_node, &table->hbs[index].list);
119 static void io_poll_tw_hash_eject(struct io_kiocb *req, bool *locked)
121 struct io_ring_ctx *ctx = req->ctx;
123 if (req->flags & REQ_F_HASH_LOCKED) {
125 * ->cancel_table_locked is protected by ->uring_lock in
126 * contrast to per bucket spinlocks. Likely, tctx_task_work()
127 * already grabbed the mutex for us, but there is a chance it
130 io_tw_lock(ctx, locked);
131 hash_del(&req->hash_node);
133 io_poll_req_delete(req, ctx);
137 static void io_init_poll_iocb(struct io_poll *poll, __poll_t events,
138 wait_queue_func_t wake_func)
141 #define IO_POLL_UNMASK (EPOLLERR|EPOLLHUP|EPOLLNVAL|EPOLLRDHUP)
142 /* mask in events that we always want/need */
143 poll->events = events | IO_POLL_UNMASK;
144 INIT_LIST_HEAD(&poll->wait.entry);
145 init_waitqueue_func_entry(&poll->wait, wake_func);
148 static inline void io_poll_remove_entry(struct io_poll *poll)
150 struct wait_queue_head *head = smp_load_acquire(&poll->head);
153 spin_lock_irq(&head->lock);
154 list_del_init(&poll->wait.entry);
156 spin_unlock_irq(&head->lock);
160 static void io_poll_remove_entries(struct io_kiocb *req)
163 * Nothing to do if neither of those flags are set. Avoid dipping
164 * into the poll/apoll/double cachelines if we can.
166 if (!(req->flags & (REQ_F_SINGLE_POLL | REQ_F_DOUBLE_POLL)))
170 * While we hold the waitqueue lock and the waitqueue is nonempty,
171 * wake_up_pollfree() will wait for us. However, taking the waitqueue
172 * lock in the first place can race with the waitqueue being freed.
174 * We solve this as eventpoll does: by taking advantage of the fact that
175 * all users of wake_up_pollfree() will RCU-delay the actual free. If
176 * we enter rcu_read_lock() and see that the pointer to the queue is
177 * non-NULL, we can then lock it without the memory being freed out from
180 * Keep holding rcu_read_lock() as long as we hold the queue lock, in
181 * case the caller deletes the entry from the queue, leaving it empty.
182 * In that case, only RCU prevents the queue memory from being freed.
185 if (req->flags & REQ_F_SINGLE_POLL)
186 io_poll_remove_entry(io_poll_get_single(req));
187 if (req->flags & REQ_F_DOUBLE_POLL)
188 io_poll_remove_entry(io_poll_get_double(req));
193 * All poll tw should go through this. Checks for poll events, manages
194 * references, does rewait, etc.
196 * Returns a negative error on failure. >0 when no action require, which is
197 * either spurious wakeup or multishot CQE is served. 0 when it's done with
198 * the request, then the mask is stored in req->cqe.res.
200 static int io_poll_check_events(struct io_kiocb *req, bool *locked)
202 struct io_ring_ctx *ctx = req->ctx;
205 /* req->task == current here, checking PF_EXITING is safe */
206 if (unlikely(req->task->flags & PF_EXITING))
210 v = atomic_read(&req->poll_refs);
212 /* tw handler should be the owner, and so have some references */
213 if (WARN_ON_ONCE(!(v & IO_POLL_REF_MASK)))
215 if (v & IO_POLL_CANCEL_FLAG)
219 struct poll_table_struct pt = { ._key = req->apoll_events };
220 req->cqe.res = vfs_poll(req->file, &pt) & req->apoll_events;
223 if ((unlikely(!req->cqe.res)))
225 if (req->apoll_events & EPOLLONESHOT)
228 /* multishot, just fill a CQE and proceed */
229 if (!(req->flags & REQ_F_APOLL_MULTISHOT)) {
230 __poll_t mask = mangle_poll(req->cqe.res &
233 if (!io_post_aux_cqe(ctx, req->cqe.user_data,
234 mask, IORING_CQE_F_MORE))
237 ret = io_poll_issue(req, locked);
243 * Release all references, retry if someone tried to restart
244 * task_work while we were executing it.
246 } while (atomic_sub_return(v & IO_POLL_REF_MASK, &req->poll_refs));
251 static void io_poll_task_func(struct io_kiocb *req, bool *locked)
255 ret = io_poll_check_events(req, locked);
260 struct io_poll *poll = io_kiocb_to_cmd(req);
262 req->cqe.res = mangle_poll(req->cqe.res & poll->events);
268 io_poll_remove_entries(req);
269 io_poll_tw_hash_eject(req, locked);
271 io_req_set_res(req, req->cqe.res, 0);
272 io_req_task_complete(req, locked);
275 static void io_apoll_task_func(struct io_kiocb *req, bool *locked)
279 ret = io_poll_check_events(req, locked);
283 io_poll_remove_entries(req);
284 io_poll_tw_hash_eject(req, locked);
287 io_req_task_submit(req, locked);
289 io_req_complete_failed(req, ret);
292 static void __io_poll_execute(struct io_kiocb *req, int mask,
293 __poll_t __maybe_unused events)
295 io_req_set_res(req, mask, 0);
297 * This is useful for poll that is armed on behalf of another
298 * request, and where the wakeup path could be on a different
299 * CPU. We want to avoid pulling in req->apoll->events for that
302 if (req->opcode == IORING_OP_POLL_ADD)
303 req->io_task_work.func = io_poll_task_func;
305 req->io_task_work.func = io_apoll_task_func;
307 trace_io_uring_task_add(req, mask);
308 io_req_task_work_add(req);
311 static inline void io_poll_execute(struct io_kiocb *req, int res,
314 if (io_poll_get_ownership(req))
315 __io_poll_execute(req, res, events);
318 static void io_poll_cancel_req(struct io_kiocb *req)
320 io_poll_mark_cancelled(req);
321 /* kick tw, which should complete the request */
322 io_poll_execute(req, 0, 0);
325 #define IO_ASYNC_POLL_COMMON (EPOLLONESHOT | EPOLLPRI)
327 static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,
330 struct io_kiocb *req = wqe_to_req(wait);
331 struct io_poll *poll = container_of(wait, struct io_poll, wait);
332 __poll_t mask = key_to_poll(key);
334 if (unlikely(mask & POLLFREE)) {
335 io_poll_mark_cancelled(req);
336 /* we have to kick tw in case it's not already */
337 io_poll_execute(req, 0, poll->events);
340 * If the waitqueue is being freed early but someone is already
341 * holds ownership over it, we have to tear down the request as
342 * best we can. That means immediately removing the request from
343 * its waitqueue and preventing all further accesses to the
344 * waitqueue via the request.
346 list_del_init(&poll->wait.entry);
349 * Careful: this *must* be the last step, since as soon
350 * as req->head is NULL'ed out, the request can be
351 * completed and freed, since aio_poll_complete_work()
352 * will no longer need to take the waitqueue lock.
354 smp_store_release(&poll->head, NULL);
358 /* for instances that support it check for an event match first */
359 if (mask && !(mask & (poll->events & ~IO_ASYNC_POLL_COMMON)))
362 if (io_poll_get_ownership(req)) {
363 /* optional, saves extra locking for removal in tw handler */
364 if (mask && poll->events & EPOLLONESHOT) {
365 list_del_init(&poll->wait.entry);
367 if (wqe_is_double(wait))
368 req->flags &= ~REQ_F_DOUBLE_POLL;
370 req->flags &= ~REQ_F_SINGLE_POLL;
372 __io_poll_execute(req, mask, poll->events);
377 static void __io_queue_proc(struct io_poll *poll, struct io_poll_table *pt,
378 struct wait_queue_head *head,
379 struct io_poll **poll_ptr)
381 struct io_kiocb *req = pt->req;
382 unsigned long wqe_private = (unsigned long) req;
385 * The file being polled uses multiple waitqueues for poll handling
386 * (e.g. one for read, one for write). Setup a separate io_poll
389 if (unlikely(pt->nr_entries)) {
390 struct io_poll *first = poll;
392 /* double add on the same waitqueue head, ignore */
393 if (first->head == head)
395 /* already have a 2nd entry, fail a third attempt */
397 if ((*poll_ptr)->head == head)
403 poll = kmalloc(sizeof(*poll), GFP_ATOMIC);
408 /* mark as double wq entry */
409 wqe_private |= IO_WQE_F_DOUBLE;
410 req->flags |= REQ_F_DOUBLE_POLL;
411 io_init_poll_iocb(poll, first->events, first->wait.func);
413 if (req->opcode == IORING_OP_POLL_ADD)
414 req->flags |= REQ_F_ASYNC_DATA;
417 req->flags |= REQ_F_SINGLE_POLL;
420 poll->wait.private = (void *) wqe_private;
422 if (poll->events & EPOLLEXCLUSIVE)
423 add_wait_queue_exclusive(head, &poll->wait);
425 add_wait_queue(head, &poll->wait);
428 static void io_poll_queue_proc(struct file *file, struct wait_queue_head *head,
429 struct poll_table_struct *p)
431 struct io_poll_table *pt = container_of(p, struct io_poll_table, pt);
432 struct io_poll *poll = io_kiocb_to_cmd(pt->req);
434 __io_queue_proc(poll, pt, head,
435 (struct io_poll **) &pt->req->async_data);
438 static int __io_arm_poll_handler(struct io_kiocb *req,
439 struct io_poll *poll,
440 struct io_poll_table *ipt, __poll_t mask)
442 struct io_ring_ctx *ctx = req->ctx;
445 INIT_HLIST_NODE(&req->hash_node);
446 req->work.cancel_seq = atomic_read(&ctx->cancel_seq);
447 io_init_poll_iocb(poll, mask, io_poll_wake);
448 poll->file = req->file;
450 req->apoll_events = poll->events;
458 * Take the ownership to delay any tw execution up until we're done
459 * with poll arming. see io_poll_get_ownership().
461 atomic_set(&req->poll_refs, 1);
462 mask = vfs_poll(req->file, &ipt->pt) & poll->events;
465 ((poll->events & (EPOLLET|EPOLLONESHOT)) == (EPOLLET|EPOLLONESHOT))) {
466 io_poll_remove_entries(req);
467 /* no one else has access to the req, forget about the ref */
471 if (!mask && unlikely(ipt->error || !ipt->nr_entries)) {
472 io_poll_remove_entries(req);
474 ipt->error = -EINVAL;
478 if (req->flags & REQ_F_HASH_LOCKED)
479 io_poll_req_insert_locked(req);
481 io_poll_req_insert(req);
483 if (mask && (poll->events & EPOLLET)) {
484 /* can't multishot if failed, just queue the event we've got */
485 if (unlikely(ipt->error || !ipt->nr_entries)) {
486 poll->events |= EPOLLONESHOT;
487 req->apoll_events |= EPOLLONESHOT;
490 __io_poll_execute(req, mask, poll->events);
495 * Release ownership. If someone tried to queue a tw while it was
496 * locked, kick it off for them.
498 v = atomic_dec_return(&req->poll_refs);
499 if (unlikely(v & IO_POLL_REF_MASK))
500 __io_poll_execute(req, 0, poll->events);
504 static void io_async_queue_proc(struct file *file, struct wait_queue_head *head,
505 struct poll_table_struct *p)
507 struct io_poll_table *pt = container_of(p, struct io_poll_table, pt);
508 struct async_poll *apoll = pt->req->apoll;
510 __io_queue_proc(&apoll->poll, pt, head, &apoll->double_poll);
513 int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
515 const struct io_op_def *def = &io_op_defs[req->opcode];
516 struct io_ring_ctx *ctx = req->ctx;
517 struct async_poll *apoll;
518 struct io_poll_table ipt;
519 __poll_t mask = POLLPRI | POLLERR | EPOLLET;
523 * apoll requests already grab the mutex to complete in the tw handler,
524 * so removal from the mutex-backed hash is free, use it by default.
526 if (issue_flags & IO_URING_F_UNLOCKED)
527 req->flags &= ~REQ_F_HASH_LOCKED;
529 req->flags |= REQ_F_HASH_LOCKED;
531 if (!def->pollin && !def->pollout)
532 return IO_APOLL_ABORTED;
533 if (!file_can_poll(req->file))
534 return IO_APOLL_ABORTED;
535 if ((req->flags & (REQ_F_POLLED|REQ_F_PARTIAL_IO)) == REQ_F_POLLED)
536 return IO_APOLL_ABORTED;
537 if (!(req->flags & REQ_F_APOLL_MULTISHOT))
538 mask |= EPOLLONESHOT;
541 mask |= EPOLLIN | EPOLLRDNORM;
543 /* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */
544 if (req->flags & REQ_F_CLEAR_POLLIN)
547 mask |= EPOLLOUT | EPOLLWRNORM;
549 if (def->poll_exclusive)
550 mask |= EPOLLEXCLUSIVE;
551 if (req->flags & REQ_F_POLLED) {
553 kfree(apoll->double_poll);
554 } else if (!(issue_flags & IO_URING_F_UNLOCKED) &&
555 !list_empty(&ctx->apoll_cache)) {
556 apoll = list_first_entry(&ctx->apoll_cache, struct async_poll,
558 list_del_init(&apoll->poll.wait.entry);
560 apoll = kmalloc(sizeof(*apoll), GFP_ATOMIC);
561 if (unlikely(!apoll))
562 return IO_APOLL_ABORTED;
564 apoll->double_poll = NULL;
566 req->flags |= REQ_F_POLLED;
567 ipt.pt._qproc = io_async_queue_proc;
569 io_kbuf_recycle(req, issue_flags);
571 ret = __io_arm_poll_handler(req, &apoll->poll, &ipt, mask);
572 if (ret || ipt.error)
573 return ret ? IO_APOLL_READY : IO_APOLL_ABORTED;
575 trace_io_uring_poll_arm(req, mask, apoll->poll.events);
579 static __cold bool io_poll_remove_all_table(struct task_struct *tsk,
580 struct io_hash_table *table,
583 unsigned nr_buckets = 1U << table->hash_bits;
584 struct hlist_node *tmp;
585 struct io_kiocb *req;
589 for (i = 0; i < nr_buckets; i++) {
590 struct io_hash_bucket *hb = &table->hbs[i];
592 spin_lock(&hb->lock);
593 hlist_for_each_entry_safe(req, tmp, &hb->list, hash_node) {
594 if (io_match_task_safe(req, tsk, cancel_all)) {
595 hlist_del_init(&req->hash_node);
596 io_poll_cancel_req(req);
600 spin_unlock(&hb->lock);
606 * Returns true if we found and killed one or more poll requests
608 __cold bool io_poll_remove_all(struct io_ring_ctx *ctx, struct task_struct *tsk,
610 __must_hold(&ctx->uring_lock)
614 ret = io_poll_remove_all_table(tsk, &ctx->cancel_table, cancel_all);
615 ret |= io_poll_remove_all_table(tsk, &ctx->cancel_table_locked, cancel_all);
619 static struct io_kiocb *io_poll_find(struct io_ring_ctx *ctx, bool poll_only,
620 struct io_cancel_data *cd,
621 struct io_hash_table *table,
622 struct io_hash_bucket **out_bucket)
624 struct io_kiocb *req;
625 u32 index = hash_long(cd->data, table->hash_bits);
626 struct io_hash_bucket *hb = &table->hbs[index];
630 spin_lock(&hb->lock);
631 hlist_for_each_entry(req, &hb->list, hash_node) {
632 if (cd->data != req->cqe.user_data)
634 if (poll_only && req->opcode != IORING_OP_POLL_ADD)
636 if (cd->flags & IORING_ASYNC_CANCEL_ALL) {
637 if (cd->seq == req->work.cancel_seq)
639 req->work.cancel_seq = cd->seq;
644 spin_unlock(&hb->lock);
648 static struct io_kiocb *io_poll_file_find(struct io_ring_ctx *ctx,
649 struct io_cancel_data *cd,
650 struct io_hash_table *table,
651 struct io_hash_bucket **out_bucket)
653 unsigned nr_buckets = 1U << table->hash_bits;
654 struct io_kiocb *req;
659 for (i = 0; i < nr_buckets; i++) {
660 struct io_hash_bucket *hb = &table->hbs[i];
662 spin_lock(&hb->lock);
663 hlist_for_each_entry(req, &hb->list, hash_node) {
664 if (!(cd->flags & IORING_ASYNC_CANCEL_ANY) &&
665 req->file != cd->file)
667 if (cd->seq == req->work.cancel_seq)
669 req->work.cancel_seq = cd->seq;
673 spin_unlock(&hb->lock);
678 static int io_poll_disarm(struct io_kiocb *req)
682 if (!io_poll_get_ownership(req))
684 io_poll_remove_entries(req);
685 hash_del(&req->hash_node);
689 static int __io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd,
690 struct io_hash_table *table)
692 struct io_hash_bucket *bucket;
693 struct io_kiocb *req;
695 if (cd->flags & (IORING_ASYNC_CANCEL_FD|IORING_ASYNC_CANCEL_ANY))
696 req = io_poll_file_find(ctx, cd, table, &bucket);
698 req = io_poll_find(ctx, false, cd, table, &bucket);
701 io_poll_cancel_req(req);
703 spin_unlock(&bucket->lock);
704 return req ? 0 : -ENOENT;
707 int io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd,
708 unsigned issue_flags)
712 ret = __io_poll_cancel(ctx, cd, &ctx->cancel_table);
716 io_ring_submit_lock(ctx, issue_flags);
717 ret = __io_poll_cancel(ctx, cd, &ctx->cancel_table_locked);
718 io_ring_submit_unlock(ctx, issue_flags);
722 static __poll_t io_poll_parse_events(const struct io_uring_sqe *sqe,
727 events = READ_ONCE(sqe->poll32_events);
729 events = swahw32(events);
731 if (!(flags & IORING_POLL_ADD_MULTI))
732 events |= EPOLLONESHOT;
733 if (!(flags & IORING_POLL_ADD_LEVEL))
735 return demangle_poll(events) |
736 (events & (EPOLLEXCLUSIVE|EPOLLONESHOT|EPOLLET));
739 int io_poll_remove_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
741 struct io_poll_update *upd = io_kiocb_to_cmd(req);
744 if (sqe->buf_index || sqe->splice_fd_in)
746 flags = READ_ONCE(sqe->len);
747 if (flags & ~(IORING_POLL_UPDATE_EVENTS | IORING_POLL_UPDATE_USER_DATA |
748 IORING_POLL_ADD_MULTI))
750 /* meaningless without update */
751 if (flags == IORING_POLL_ADD_MULTI)
754 upd->old_user_data = READ_ONCE(sqe->addr);
755 upd->update_events = flags & IORING_POLL_UPDATE_EVENTS;
756 upd->update_user_data = flags & IORING_POLL_UPDATE_USER_DATA;
758 upd->new_user_data = READ_ONCE(sqe->off);
759 if (!upd->update_user_data && upd->new_user_data)
761 if (upd->update_events)
762 upd->events = io_poll_parse_events(sqe, flags);
763 else if (sqe->poll32_events)
769 int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
771 struct io_poll *poll = io_kiocb_to_cmd(req);
774 if (sqe->buf_index || sqe->off || sqe->addr)
776 flags = READ_ONCE(sqe->len);
777 if (flags & ~(IORING_POLL_ADD_MULTI|IORING_POLL_ADD_LEVEL))
779 if ((flags & IORING_POLL_ADD_MULTI) && (req->flags & REQ_F_CQE_SKIP))
782 poll->events = io_poll_parse_events(sqe, flags);
786 int io_poll_add(struct io_kiocb *req, unsigned int issue_flags)
788 struct io_poll *poll = io_kiocb_to_cmd(req);
789 struct io_poll_table ipt;
792 ipt.pt._qproc = io_poll_queue_proc;
795 * If sqpoll or single issuer, there is no contention for ->uring_lock
796 * and we'll end up holding it in tw handlers anyway.
798 if (!(issue_flags & IO_URING_F_UNLOCKED) &&
799 (req->ctx->flags & (IORING_SETUP_SQPOLL | IORING_SETUP_SINGLE_ISSUER)))
800 req->flags |= REQ_F_HASH_LOCKED;
802 req->flags &= ~REQ_F_HASH_LOCKED;
804 ret = __io_arm_poll_handler(req, poll, &ipt, poll->events);
806 io_req_set_res(req, ret, 0);
814 return IOU_ISSUE_SKIP_COMPLETE;
817 int io_poll_remove(struct io_kiocb *req, unsigned int issue_flags)
819 struct io_poll_update *poll_update = io_kiocb_to_cmd(req);
820 struct io_cancel_data cd = { .data = poll_update->old_user_data, };
821 struct io_ring_ctx *ctx = req->ctx;
822 struct io_hash_bucket *bucket;
823 struct io_kiocb *preq;
827 preq = io_poll_find(ctx, true, &cd, &ctx->cancel_table, &bucket);
828 ret2 = io_poll_disarm(preq);
830 spin_unlock(&bucket->lock);
833 if (ret2 != -ENOENT) {
838 io_ring_submit_lock(ctx, issue_flags);
839 preq = io_poll_find(ctx, true, &cd, &ctx->cancel_table_locked, &bucket);
840 ret2 = io_poll_disarm(preq);
842 spin_unlock(&bucket->lock);
843 io_ring_submit_unlock(ctx, issue_flags);
850 if (WARN_ON_ONCE(preq->opcode != IORING_OP_POLL_ADD)) {
855 if (poll_update->update_events || poll_update->update_user_data) {
856 /* only mask one event flags, keep behavior flags */
857 if (poll_update->update_events) {
858 struct io_poll *poll = io_kiocb_to_cmd(preq);
860 poll->events &= ~0xffff;
861 poll->events |= poll_update->events & 0xffff;
862 poll->events |= IO_POLL_UNMASK;
864 if (poll_update->update_user_data)
865 preq->cqe.user_data = poll_update->new_user_data;
867 ret2 = io_poll_add(preq, issue_flags);
868 /* successfully updated, don't complete poll request */
869 if (!ret2 || ret2 == -EIOCBQUEUED)
874 io_req_set_res(preq, -ECANCELED, 0);
875 locked = !(issue_flags & IO_URING_F_UNLOCKED);
876 io_req_task_complete(preq, &locked);
882 /* complete update request, we're done with it */
883 io_req_set_res(req, ret, 0);