• Home
  • Raw
  • Download

Lines Matching +full:poll +full:- +full:timeout +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-or-later
18 #include <linux/poll.h>
47 * 2) ep->mtx (mutex)
48 * 3) ep->lock (rwlock)
51 * We need a rwlock (ep->lock) because we manipulate objects
52 * from inside the poll callback, that might be triggered from
54 * So we can't sleep inside the poll callback and hence we need
58 * mutex (ep->mtx). It is acquired during the event transfer loop,
67 * It is necessary to acquire multiple "ep->mtx"es at once in the
70 * epoll_ctl(e1, EPOLL_CTL_ADD, e2), e1->mtx will always be acquired
71 * before e2->mtx). Since we disallow cycles of epoll file
72 * descriptors, this ensures that the mutexes are well-ordered. In
76 * It is possible to drop the "ep->mtx" and to use the global
77 * mutex "epnested_mutex" (together with "ep->lock") to have it working,
78 * but having "ep->mtx" will make the interface more scalable.
80 * normal operations the epoll private "ep->mtx" will guarantee
97 #define EP_UNACTIVE_PTR ((void *) -1L)
106 /* Wait structure used by the poll hooks */
142 * Works together "struct eventpoll"->ovflist in keeping the
151 * Protected by file->f_lock, true for to-be-released epitem already
153 * eventpoll->refcount orchestrates "struct eventpoll" disposal
157 /* List containing poll wait queues */
190 /* Wait queue used by file->poll() */
205 * holding ->lock.
222 * usage count, used together with epitem->dying to
228 /* used to track busy poll napi_id */
238 /* Wrapper struct used by poll queueing */
286 head = container_of(file->f_ep, struct epitems_head, epitems); in list_file()
287 if (!head->next) { in list_file()
288 head->next = tfile_check_list; in list_file()
296 struct hlist_node *p = rcu_dereference(hlist_first_rcu(&head->epitems)); in unlist_file()
299 spin_lock(&epi->ffd.file->f_lock); in unlist_file()
300 if (!hlist_empty(&head->epitems)) in unlist_file()
302 head->next = NULL; in unlist_file()
303 spin_unlock(&epi->ffd.file->f_lock); in unlist_file()
340 return f->f_op == &eventpoll_fops; in is_file_epoll()
347 ffd->file = file; in ep_set_ffd()
348 ffd->fd = fd; in ep_set_ffd()
355 return (p1->file > p2->file ? +1: in ep_cmp_ffd()
356 (p1->file < p2->file ? -1 : p1->fd - p2->fd)); in ep_cmp_ffd()
362 return !list_empty(&epi->rdllink); in ep_is_linked()
373 return container_of(p, struct eppoll_entry, wait)->base; in ep_item_from_wait()
377 * ep_events_available - Checks if ready events might be available.
386 return !list_empty_careful(&ep->rdllist) || in ep_events_available()
387 READ_ONCE(ep->ovflist) != EP_UNACTIVE_PTR; in ep_events_available()
399 * Busy poll if globally on and supporting sockets found && no events,
406 unsigned int napi_id = READ_ONCE(ep->napi_id); in ep_busy_loop()
414 * Busy poll timed out. Drop NAPI ID for now, we can add in ep_busy_loop()
418 ep->napi_id = 0; in ep_busy_loop()
425 * Set epoll busy poll NAPI ID from sk.
437 sock = sock_from_file(epi->ffd.file); in ep_set_busy_poll_napi_id()
441 sk = sock->sk; in ep_set_busy_poll_napi_id()
445 napi_id = READ_ONCE(sk->sk_napi_id); in ep_set_busy_poll_napi_id()
446 ep = epi->ep; in ep_set_busy_poll_napi_id()
448 /* Non-NAPI IDs can be rejected in ep_set_busy_poll_napi_id()
452 if (napi_id < MIN_NAPI_ID || napi_id == ep->napi_id) in ep_set_busy_poll_napi_id()
455 /* record NAPI ID for use in next busy poll */ in ep_set_busy_poll_napi_id()
456 ep->napi_id = napi_id; in ep_set_busy_poll_napi_id()
485 * issue a wake_up() on its poll wake list. Epoll (efd1) has installed a
489 * the waiters on its poll wait list (efd2). So it calls ep_poll_safewake()
508 * it might be natural to create a per-cpu nest count. However, since in ep_poll_safewake()
509 * we can recurse on ep->poll_wait.lock, and a non-raw spinlock can in ep_poll_safewake()
510 * schedule() in the -rt kernel, the per-cpu variable are no longer in ep_poll_safewake()
522 if ((is_file_epoll(epi->ffd.file))) { in ep_poll_safewake()
523 ep_src = epi->ffd.file->private_data; in ep_poll_safewake()
524 nests = ep_src->nests; in ep_poll_safewake()
529 spin_lock_irqsave_nested(&ep->poll_wait.lock, flags, nests); in ep_poll_safewake()
530 ep->nests = nests + 1; in ep_poll_safewake()
531 wake_up_locked_poll(&ep->poll_wait, EPOLLIN | pollflags); in ep_poll_safewake()
532 ep->nests = 0; in ep_poll_safewake()
533 spin_unlock_irqrestore(&ep->poll_wait.lock, flags); in ep_poll_safewake()
541 wake_up_poll(&ep->poll_wait, EPOLLIN | pollflags); in ep_poll_safewake()
552 * If it is cleared by POLLFREE, it should be rcu-safe. in ep_remove_wait_queue()
555 * we rely on whead->lock. in ep_remove_wait_queue()
557 whead = smp_load_acquire(&pwq->whead); in ep_remove_wait_queue()
559 remove_wait_queue(whead, &pwq->wait); in ep_remove_wait_queue()
564 * This function unregisters poll callbacks from the associated file
569 struct eppoll_entry **p = &epi->pwqlist; in ep_unregister_pollwait()
573 *p = pwq->next; in ep_unregister_pollwait()
579 /* call only when ep->mtx is held */
582 return rcu_dereference_check(epi->ws, lockdep_is_held(&epi->ep->mtx)); in ep_wakeup_source()
585 /* call only when ep->mtx is held */
596 return rcu_access_pointer(epi->ws) ? true : false; in ep_has_wakeup_source()
599 /* call when ep->mtx cannot be held (ep_poll_callback) */
605 ws = rcu_dereference(epi->ws); in ep_pm_stay_awake_rcu()
613 * ep->mutex needs to be held because we could be hit by
619 * Steal the ready list, and re-init the original one to the in ep_start_scan()
620 * empty list. Also, set ep->ovflist to NULL so that events in ep_start_scan()
622 * have the poll callback to queue directly on ep->rdllist, in ep_start_scan()
627 write_lock_irq(&ep->lock); in ep_start_scan()
628 list_splice_init(&ep->rdllist, txlist); in ep_start_scan()
629 WRITE_ONCE(ep->ovflist, NULL); in ep_start_scan()
630 write_unlock_irq(&ep->lock); in ep_start_scan()
638 write_lock_irq(&ep->lock); in ep_done_scan()
641 * other events might have been queued by the poll callback. in ep_done_scan()
642 * We re-insert them inside the main ready-list here. in ep_done_scan()
644 for (nepi = READ_ONCE(ep->ovflist); (epi = nepi) != NULL; in ep_done_scan()
645 nepi = epi->next, epi->next = EP_UNACTIVE_PTR) { in ep_done_scan()
649 * queued into ->ovflist but the "txlist" might already in ep_done_scan()
654 * ->ovflist is LIFO, so we have to reverse it in order in ep_done_scan()
657 list_add(&epi->rdllink, &ep->rdllist); in ep_done_scan()
662 * We need to set back ep->ovflist to EP_UNACTIVE_PTR, so that after in ep_done_scan()
664 * ep->rdllist. in ep_done_scan()
666 WRITE_ONCE(ep->ovflist, EP_UNACTIVE_PTR); in ep_done_scan()
669 * Quickly re-inject items left on "txlist". in ep_done_scan()
671 list_splice(txlist, &ep->rdllist); in ep_done_scan()
672 __pm_relax(ep->ws); in ep_done_scan()
674 if (!list_empty(&ep->rdllist)) { in ep_done_scan()
675 if (waitqueue_active(&ep->wq)) in ep_done_scan()
676 wake_up(&ep->wq); in ep_done_scan()
679 write_unlock_irq(&ep->lock); in ep_done_scan()
690 refcount_inc(&ep->refcount); in ep_get()
694 * Returns true if the event poll can be disposed
698 if (!refcount_dec_and_test(&ep->refcount)) in ep_refcount_dec_and_test()
701 WARN_ON_ONCE(!RB_EMPTY_ROOT(&ep->rbr.rb_root)); in ep_refcount_dec_and_test()
707 mutex_destroy(&ep->mtx); in ep_free()
708 free_uid(ep->user); in ep_free()
709 wakeup_source_unregister(ep->ws); in ep_free()
723 struct file *file = epi->ffd.file; in __ep_remove()
730 * Removes poll wait queue hooks. in __ep_remove()
735 spin_lock(&file->f_lock); in __ep_remove()
736 if (epi->dying && !force) { in __ep_remove()
737 spin_unlock(&file->f_lock); in __ep_remove()
742 head = file->f_ep; in __ep_remove()
743 if (head->first == &epi->fllink && !epi->fllink.next) { in __ep_remove()
744 file->f_ep = NULL; in __ep_remove()
748 if (!smp_load_acquire(&v->next)) in __ep_remove()
752 hlist_del_rcu(&epi->fllink); in __ep_remove()
753 spin_unlock(&file->f_lock); in __ep_remove()
756 rb_erase_cached(&epi->rbn, &ep->rbr); in __ep_remove()
758 write_lock_irq(&ep->lock); in __ep_remove()
760 list_del_init(&epi->rdllink); in __ep_remove()
761 write_unlock_irq(&ep->lock); in __ep_remove()
766 * field epi->rcu, since we are trying to minimize the size of in __ep_remove()
768 * ep->mtx. The rcu read side, reverse_path_check_proc(), does not make in __ep_remove()
771 call_rcu(&epi->rcu, epi_rcu_free); in __ep_remove()
773 percpu_counter_dec(&ep->user->epoll_watches); in __ep_remove()
792 if (waitqueue_active(&ep->poll_wait)) in ep_clear_and_put()
795 mutex_lock(&ep->mtx); in ep_clear_and_put()
798 * Walks through the whole tree by unregistering poll callbacks. in ep_clear_and_put()
800 for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) { in ep_clear_and_put()
811 * At this point we are sure no poll callbacks will be lingering around. in ep_clear_and_put()
815 for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = next) { in ep_clear_and_put()
823 mutex_unlock(&ep->mtx); in ep_clear_and_put()
831 struct eventpoll *ep = file->private_data; in ep_eventpoll_release()
843 struct eventpoll *ep = file->private_data; in __ep_eventpoll_poll()
851 /* Insert inside our poll wait queue */ in __ep_eventpoll_poll()
852 poll_wait(file, &ep->poll_wait, wait); in __ep_eventpoll_poll()
858 mutex_lock_nested(&ep->mtx, depth); in __ep_eventpoll_poll()
866 * Item has been dropped into the ready list by the poll in __ep_eventpoll_poll()
871 list_del_init(&epi->rdllink); in __ep_eventpoll_poll()
875 mutex_unlock(&ep->mtx); in __ep_eventpoll_poll()
881 * the ep->mtx so we need to start from depth=1, such that mutex_lock_nested()
887 struct file *file = epi->ffd.file; in ep_item_poll()
890 pt->_key = epi->event.events; in ep_item_poll()
895 return res & epi->event.events; in ep_item_poll()
906 struct eventpoll *ep = f->private_data; in ep_show_fdinfo()
909 mutex_lock(&ep->mtx); in ep_show_fdinfo()
910 for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) { in ep_show_fdinfo()
912 struct inode *inode = file_inode(epi->ffd.file); in ep_show_fdinfo()
916 epi->ffd.fd, epi->event.events, in ep_show_fdinfo()
917 (long long)epi->event.data, in ep_show_fdinfo()
918 (long long)epi->ffd.file->f_pos, in ep_show_fdinfo()
919 inode->i_ino, inode->i_sb->s_dev); in ep_show_fdinfo()
923 mutex_unlock(&ep->mtx); in ep_show_fdinfo()
933 .poll = ep_eventpoll_poll,
951 * the ep->mtx. in eventpoll_release_file()
954 spin_lock(&file->f_lock); in eventpoll_release_file()
955 if (file->f_ep && file->f_ep->first) { in eventpoll_release_file()
956 epi = hlist_entry(file->f_ep->first, struct epitem, fllink); in eventpoll_release_file()
957 epi->dying = true; in eventpoll_release_file()
958 spin_unlock(&file->f_lock); in eventpoll_release_file()
964 ep = epi->ep; in eventpoll_release_file()
965 mutex_lock(&ep->mtx); in eventpoll_release_file()
967 mutex_unlock(&ep->mtx); in eventpoll_release_file()
973 spin_unlock(&file->f_lock); in eventpoll_release_file()
982 return -ENOMEM; in ep_alloc()
984 mutex_init(&ep->mtx); in ep_alloc()
985 rwlock_init(&ep->lock); in ep_alloc()
986 init_waitqueue_head(&ep->wq); in ep_alloc()
987 init_waitqueue_head(&ep->poll_wait); in ep_alloc()
988 INIT_LIST_HEAD(&ep->rdllist); in ep_alloc()
989 ep->rbr = RB_ROOT_CACHED; in ep_alloc()
990 ep->ovflist = EP_UNACTIVE_PTR; in ep_alloc()
991 ep->user = get_current_user(); in ep_alloc()
992 refcount_set(&ep->refcount, 1); in ep_alloc()
1012 for (rbp = ep->rbr.rb_root.rb_node; rbp; ) { in ep_find()
1014 kcmp = ep_cmp_ffd(&ffd, &epi->ffd); in ep_find()
1016 rbp = rbp->rb_right; in ep_find()
1018 rbp = rbp->rb_left; in ep_find()
1034 for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) { in ep_find_tfd()
1036 if (epi->ffd.fd == tfd) { in ep_find_tfd()
1040 toff--; in ep_find_tfd()
1056 return ERR_PTR(-EINVAL); in get_epoll_tfile_raw_ptr()
1058 ep = file->private_data; in get_epoll_tfile_raw_ptr()
1060 mutex_lock(&ep->mtx); in get_epoll_tfile_raw_ptr()
1063 file_raw = epi->ffd.file; in get_epoll_tfile_raw_ptr()
1065 file_raw = ERR_PTR(-ENOENT); in get_epoll_tfile_raw_ptr()
1066 mutex_unlock(&ep->mtx); in get_epoll_tfile_raw_ptr()
1096 * This is simple 'new->next = head' operation, but cmpxchg() in list_add_tail_lockless()
1099 * new->next == new. in list_add_tail_lockless()
1101 if (!try_cmpxchg(&new->next, &new, head)) in list_add_tail_lockless()
1105 * Initially ->next of a new element must be updated with the head in list_add_tail_lockless()
1107 * exchanged. XCHG guarantees memory ordering, thus ->next should be in list_add_tail_lockless()
1109 * swapped before prev->next is updated. in list_add_tail_lockless()
1112 prev = xchg(&head->prev, new); in list_add_tail_lockless()
1115 * It is safe to modify prev->next and new->prev, because a new element in list_add_tail_lockless()
1116 * is added only to the tail and new->next is updated before XCHG. in list_add_tail_lockless()
1119 prev->next = new; in list_add_tail_lockless()
1120 new->prev = prev; in list_add_tail_lockless()
1126 * Chains a new epi entry to the tail of the ep->ovflist in a lockless way,
1133 struct eventpoll *ep = epi->ep; in chain_epi_lockless()
1136 if (epi->next != EP_UNACTIVE_PTR) in chain_epi_lockless()
1140 if (cmpxchg(&epi->next, EP_UNACTIVE_PTR, NULL) != EP_UNACTIVE_PTR) in chain_epi_lockless()
1144 epi->next = xchg(&ep->ovflist, epi); in chain_epi_lockless()
1155 * events from another file descriptor, thus all modifications to ->rdllist
1156 * or ->ovflist are lockless. Read lock is paired with the write lock from
1161 * concurrently for the same @epi from different CPUs if poll table was inited
1171 struct eventpoll *ep = epi->ep; in ep_poll_callback()
1176 read_lock_irqsave(&ep->lock, flags); in ep_poll_callback()
1181 * If the event mask does not contain any poll(2) event, we consider the in ep_poll_callback()
1186 if (!(epi->event.events & ~EP_PRIVATE_BITS)) in ep_poll_callback()
1195 if (pollflags && !(pollflags & epi->event.events)) in ep_poll_callback()
1200 * (because we're accessing user memory, and because of linux f_op->poll() in ep_poll_callback()
1202 * chained in ep->ovflist and requeued later on. in ep_poll_callback()
1204 if (READ_ONCE(ep->ovflist) != EP_UNACTIVE_PTR) { in ep_poll_callback()
1209 if (list_add_tail_lockless(&epi->rdllink, &ep->rdllist)) in ep_poll_callback()
1214 * Wake up ( if active ) both the eventpoll wait list and the ->poll() in ep_poll_callback()
1217 if (waitqueue_active(&ep->wq)) { in ep_poll_callback()
1218 if ((epi->event.events & EPOLLEXCLUSIVE) && in ep_poll_callback()
1222 if (epi->event.events & EPOLLIN) in ep_poll_callback()
1226 if (epi->event.events & EPOLLOUT) in ep_poll_callback()
1234 wake_up(&ep->wq); in ep_poll_callback()
1236 if (waitqueue_active(&ep->poll_wait)) in ep_poll_callback()
1240 read_unlock_irqrestore(&ep->lock, flags); in ep_poll_callback()
1246 if (!(epi->event.events & EPOLLEXCLUSIVE)) in ep_poll_callback()
1252 * ->whead = NULL and do another remove_wait_queue() after in ep_poll_callback()
1255 list_del_init(&wait->entry); in ep_poll_callback()
1257 * ->whead != NULL protects us from the race with in ep_poll_callback()
1259 * takes whead->lock held by the caller. Once we nullify it, in ep_poll_callback()
1262 smp_store_release(&ep_pwq_from_wait(wait)->whead, NULL); in ep_poll_callback()
1276 struct epitem *epi = epq->epi; in ep_ptable_queue_proc()
1284 epq->epi = NULL; in ep_ptable_queue_proc()
1288 init_waitqueue_func_entry(&pwq->wait, ep_poll_callback); in ep_ptable_queue_proc()
1289 pwq->whead = whead; in ep_ptable_queue_proc()
1290 pwq->base = epi; in ep_ptable_queue_proc()
1291 if (epi->event.events & EPOLLEXCLUSIVE) in ep_ptable_queue_proc()
1292 add_wait_queue_exclusive(whead, &pwq->wait); in ep_ptable_queue_proc()
1294 add_wait_queue(whead, &pwq->wait); in ep_ptable_queue_proc()
1295 pwq->next = epi->pwqlist; in ep_ptable_queue_proc()
1296 epi->pwqlist = pwq; in ep_ptable_queue_proc()
1302 struct rb_node **p = &ep->rbr.rb_root.rb_node, *parent = NULL; in ep_rbtree_insert()
1309 kcmp = ep_cmp_ffd(&epi->ffd, &epic->ffd); in ep_rbtree_insert()
1311 p = &parent->rb_right; in ep_rbtree_insert()
1314 p = &parent->rb_left; in ep_rbtree_insert()
1316 rb_link_node(&epi->rbn, parent, p); in ep_rbtree_insert()
1317 rb_insert_color_cached(&epi->rbn, &ep->rbr, leftmost); in ep_rbtree_insert()
1344 return -1; in path_count_inc()
1362 return -1; in reverse_path_check_proc()
1366 struct hlist_head *refs = &epi->ep->refs; in reverse_path_check_proc()
1378 * reverse_path_check - The tfile_check_list is list of epitem_head, which have
1385 * %-1 otherwise.
1391 for (p = tfile_check_list; p != EP_UNACTIVE_PTR; p = p->next) { in reverse_path_check()
1395 error = reverse_path_check_proc(&p->epitems, 0); in reverse_path_check()
1408 if (!epi->ep->ws) { in ep_create_wakeup_source()
1409 epi->ep->ws = wakeup_source_register(NULL, "eventpoll"); in ep_create_wakeup_source()
1410 if (!epi->ep->ws) in ep_create_wakeup_source()
1411 return -ENOMEM; in ep_create_wakeup_source()
1414 take_dentry_name_snapshot(&n, epi->ffd.file->f_path.dentry); in ep_create_wakeup_source()
1419 return -ENOMEM; in ep_create_wakeup_source()
1420 rcu_assign_pointer(epi->ws, ws); in ep_create_wakeup_source()
1430 RCU_INIT_POINTER(epi->ws, NULL); in ep_destroy_wakeup_source()
1448 ep = file->private_data; in attach_epitem()
1451 head = &ep->refs; in attach_epitem()
1452 } else if (!READ_ONCE(file->f_ep)) { in attach_epitem()
1456 return -ENOMEM; in attach_epitem()
1457 head = &to_free->epitems; in attach_epitem()
1459 spin_lock(&file->f_lock); in attach_epitem()
1460 if (!file->f_ep) { in attach_epitem()
1462 spin_unlock(&file->f_lock); in attach_epitem()
1465 file->f_ep = head; in attach_epitem()
1468 hlist_add_head_rcu(&epi->fllink, file->f_ep); in attach_epitem()
1469 spin_unlock(&file->f_lock); in attach_epitem()
1487 tep = tfile->private_data; in ep_insert()
1491 if (unlikely(percpu_counter_compare(&ep->user->epoll_watches, in ep_insert()
1493 return -ENOSPC; in ep_insert()
1494 percpu_counter_inc(&ep->user->epoll_watches); in ep_insert()
1497 percpu_counter_dec(&ep->user->epoll_watches); in ep_insert()
1498 return -ENOMEM; in ep_insert()
1502 INIT_LIST_HEAD(&epi->rdllink); in ep_insert()
1503 epi->ep = ep; in ep_insert()
1504 ep_set_ffd(&epi->ffd, tfile, fd); in ep_insert()
1505 epi->event = *event; in ep_insert()
1506 epi->next = EP_UNACTIVE_PTR; in ep_insert()
1509 mutex_lock_nested(&tep->mtx, 1); in ep_insert()
1513 mutex_unlock(&tep->mtx); in ep_insert()
1515 percpu_counter_dec(&ep->user->epoll_watches); in ep_insert()
1516 return -ENOMEM; in ep_insert()
1528 mutex_unlock(&tep->mtx); in ep_insert()
1539 return -EINVAL; in ep_insert()
1542 if (epi->event.events & EPOLLWAKEUP) { in ep_insert()
1550 /* Initialize the poll table using the queue callback */ in ep_insert()
1555 * Attach the item to the poll hooks and get current event bits. in ep_insert()
1558 * this operation completes, the poll callback can start hitting in ep_insert()
1564 * We have to check if something went wrong during the poll wait queue in ep_insert()
1570 return -ENOMEM; in ep_insert()
1574 write_lock_irq(&ep->lock); in ep_insert()
1581 list_add_tail(&epi->rdllink, &ep->rdllist); in ep_insert()
1585 if (waitqueue_active(&ep->wq)) in ep_insert()
1586 wake_up(&ep->wq); in ep_insert()
1587 if (waitqueue_active(&ep->poll_wait)) in ep_insert()
1591 write_unlock_irq(&ep->lock); in ep_insert()
1615 * Set the new event interest mask before calling f_op->poll(); in ep_modify()
1617 * f_op->poll() call and the new event set registering. in ep_modify()
1619 epi->event.events = event->events; /* need barrier below */ in ep_modify()
1620 epi->event.data = event->data; /* protected by mtx */ in ep_modify()
1621 if (epi->event.events & EPOLLWAKEUP) { in ep_modify()
1633 * event occurs immediately after we call f_op->poll(). in ep_modify()
1634 * We need this because we did not take ep->lock while in ep_modify()
1636 * ep->lock). in ep_modify()
1639 * when calling f_op->poll(). This barrier also in ep_modify()
1643 * This barrier will now guarantee ep_poll_callback or f_op->poll in ep_modify()
1655 write_lock_irq(&ep->lock); in ep_modify()
1657 list_add_tail(&epi->rdllink, &ep->rdllist); in ep_modify()
1661 if (waitqueue_active(&ep->wq)) in ep_modify()
1662 wake_up(&ep->wq); in ep_modify()
1663 if (waitqueue_active(&ep->poll_wait)) in ep_modify()
1666 write_unlock_irq(&ep->lock); in ep_modify()
1685 * Always short-circuit for fatal signals to allow threads to make a in ep_send_events()
1690 return -EINTR; in ep_send_events()
1694 mutex_lock(&ep->mtx); in ep_send_events()
1699 * Items cannot vanish during the loop we are holding ep->mtx. in ep_send_events()
1709 * Activate ep->ws before deactivating epi->ws to prevent in ep_send_events()
1710 * triggering auto-suspend here (in case we reactive epi->ws in ep_send_events()
1713 * This could be rearranged to delay the deactivation of epi->ws in ep_send_events()
1714 * instead, but then epi->ws would temporarily be out of sync in ep_send_events()
1719 if (ws->active) in ep_send_events()
1720 __pm_stay_awake(ep->ws); in ep_send_events()
1724 list_del_init(&epi->rdllink); in ep_send_events()
1727 * If the event mask intersect the caller-requested one, in ep_send_events()
1728 * deliver the event to userspace. Again, we are holding ep->mtx, in ep_send_events()
1735 events = epoll_put_uevent(revents, epi->event.data, events); in ep_send_events()
1737 list_add(&epi->rdllink, &txlist); in ep_send_events()
1740 res = -EFAULT; in ep_send_events()
1744 if (epi->event.events & EPOLLONESHOT) in ep_send_events()
1745 epi->event.events &= EP_PRIVATE_BITS; in ep_send_events()
1746 else if (!(epi->event.events & EPOLLET)) { in ep_send_events()
1753 * into ep->rdllist besides us. The epoll_ctl() in ep_send_events()
1756 * poll callback will queue them in ep->ovflist. in ep_send_events()
1758 list_add_tail(&epi->rdllink, &ep->rdllist); in ep_send_events()
1763 mutex_unlock(&ep->mtx); in ep_send_events()
1768 static struct timespec64 *ep_timeout_to_timespec(struct timespec64 *to, long ms) in ep_timeout_to_timespec() argument
1772 if (ms < 0) in ep_timeout_to_timespec()
1775 if (!ms) { in ep_timeout_to_timespec()
1776 to->tv_sec = 0; in ep_timeout_to_timespec()
1777 to->tv_nsec = 0; in ep_timeout_to_timespec()
1781 to->tv_sec = ms / MSEC_PER_SEC; in ep_timeout_to_timespec()
1782 to->tv_nsec = NSEC_PER_MSEC * (ms % MSEC_PER_SEC); in ep_timeout_to_timespec()
1804 list_del_init_careful(&wq_entry->entry); in ep_autoremove_wake_function()
1809 * ep_poll - Retrieves ready events, and delivers them to the caller-supplied
1816 * @timeout: Maximum timeout for the ready events fetch operation, in
1817 * timespec. If the timeout is zero, the function will not block,
1818 * while if the @timeout ptr is NULL, the function will block
1826 int maxevents, struct timespec64 *timeout) in ep_poll() argument
1835 if (timeout && (timeout->tv_sec | timeout->tv_nsec)) { in ep_poll()
1836 slack = select_estimate_accuracy(timeout); in ep_poll()
1838 *to = timespec64_to_ktime(*timeout); in ep_poll()
1839 } else if (timeout) { in ep_poll()
1850 * with a non-zero timeout, this thread will check the ready list under in ep_poll()
1852 * timeout, the user by definition should not care and will have to in ep_poll()
1861 * 0 events and there's still timeout left over, we go in ep_poll()
1877 return -EINTR; in ep_poll()
1885 * lost. This is also good performance-wise, because on in ep_poll()
1887 * explicitly, thus ep->lock is not taken, which halts the in ep_poll()
1899 write_lock_irq(&ep->lock); in ep_poll()
1909 * plays with two lists (->rdllist and ->ovflist) and there in ep_poll()
1916 __add_wait_queue_exclusive(&ep->wq, &wait); in ep_poll()
1918 write_unlock_irq(&ep->lock); in ep_poll()
1933 write_lock_irq(&ep->lock); in ep_poll()
1937 * timeout expired before it could reacquire the lock. in ep_poll()
1943 __remove_wait_queue(&ep->wq, &wait); in ep_poll()
1944 write_unlock_irq(&ep->lock); in ep_poll()
1950 * ep_loop_check_proc - verify that adding an epoll file inside another
1959 * structure @ep does not violate the constraints, or %-1 otherwise.
1967 mutex_lock_nested(&ep->mtx, depth + 1); in ep_loop_check_proc()
1968 ep->gen = loop_check_gen; in ep_loop_check_proc()
1969 for (rbp = rb_first_cached(&ep->rbr); rbp; rbp = rb_next(rbp)) { in ep_loop_check_proc()
1971 if (unlikely(is_file_epoll(epi->ffd.file))) { in ep_loop_check_proc()
1973 ep_tovisit = epi->ffd.file->private_data; in ep_loop_check_proc()
1974 if (ep_tovisit->gen == loop_check_gen) in ep_loop_check_proc()
1977 error = -1; in ep_loop_check_proc()
1991 list_file(epi->ffd.file); in ep_loop_check_proc()
1994 mutex_unlock(&ep->mtx); in ep_loop_check_proc()
2000 * ep_loop_check - Performs a check to verify that adding an epoll file (@to)
2008 * does not violate the constraints, or %-1 otherwise.
2021 tfile_check_list = head->next; in clear_tfile_check_list()
2040 return -EINVAL; in do_epoll_create()
2062 ep->file = file; in do_epoll_create()
2081 return -EINVAL; in SYSCALL_DEFINE1()
2089 if ((epev->events & EPOLLWAKEUP) && !capable(CAP_BLOCK_SUSPEND)) in ep_take_care_of_epollwakeup()
2090 epev->events &= ~EPOLLWAKEUP; in ep_take_care_of_epollwakeup()
2095 epev->events &= ~EPOLLWAKEUP; in ep_take_care_of_epollwakeup()
2108 return -EAGAIN; in epoll_mutex_lock()
2121 error = -EBADF; in do_epoll_ctl()
2131 /* The target file descriptor must support poll */ in do_epoll_ctl()
2132 error = -EPERM; in do_epoll_ctl()
2145 error = -EINVAL; in do_epoll_ctl()
2154 if (ep_op_has_event(op) && (epds->events & EPOLLEXCLUSIVE)) { in do_epoll_ctl()
2158 (epds->events & ~EPOLLEXCLUSIVE_OK_BITS))) in do_epoll_ctl()
2166 ep = f.file->private_data; in do_epoll_ctl()
2183 error = epoll_mutex_lock(&ep->mtx, 0, nonblock); in do_epoll_ctl()
2187 if (READ_ONCE(f.file->f_ep) || ep->gen == loop_check_gen || in do_epoll_ctl()
2189 mutex_unlock(&ep->mtx); in do_epoll_ctl()
2196 tep = tf.file->private_data; in do_epoll_ctl()
2197 error = -ELOOP; in do_epoll_ctl()
2201 error = epoll_mutex_lock(&ep->mtx, 0, nonblock); in do_epoll_ctl()
2214 error = -EINVAL; in do_epoll_ctl()
2218 epds->events |= EPOLLERR | EPOLLHUP; in do_epoll_ctl()
2221 error = -EEXIST; in do_epoll_ctl()
2232 error = -ENOENT; in do_epoll_ctl()
2237 if (!(epi->event.events & EPOLLEXCLUSIVE)) { in do_epoll_ctl()
2238 epds->events |= EPOLLERR | EPOLLHUP; in do_epoll_ctl()
2242 error = -ENOENT; in do_epoll_ctl()
2245 mutex_unlock(&ep->mtx); in do_epoll_ctl()
2274 return -EFAULT; in SYSCALL_DEFINE4()
2292 return -EINVAL; in do_epoll_wait()
2296 return -EFAULT; in do_epoll_wait()
2301 return -EBADF; in do_epoll_wait()
2307 error = -EINVAL; in do_epoll_wait()
2315 ep = f.file->private_data; in do_epoll_wait()
2326 int, maxevents, int, timeout) in SYSCALL_DEFINE4() argument
2331 ep_timeout_to_timespec(&to, timeout)); in SYSCALL_DEFINE4()
2354 restore_saved_sigmask_unless(error == -EINTR); in do_epoll_pwait()
2360 int, maxevents, int, timeout, const sigset_t __user *, sigmask, in SYSCALL_DEFINE6() argument
2366 ep_timeout_to_timespec(&to, timeout), in SYSCALL_DEFINE6()
2371 int, maxevents, const struct __kernel_timespec __user *, timeout, in SYSCALL_DEFINE6() argument
2376 if (timeout) { in SYSCALL_DEFINE6()
2377 if (get_timespec64(&ts, timeout)) in SYSCALL_DEFINE6()
2378 return -EFAULT; in SYSCALL_DEFINE6()
2381 return -EINVAL; in SYSCALL_DEFINE6()
2390 int maxevents, struct timespec64 *timeout, in do_compat_epoll_pwait() argument
2404 err = do_epoll_wait(epfd, events, maxevents, timeout); in do_compat_epoll_pwait()
2406 restore_saved_sigmask_unless(err == -EINTR); in do_compat_epoll_pwait()
2413 int, maxevents, int, timeout, in COMPAT_SYSCALL_DEFINE6() argument
2420 ep_timeout_to_timespec(&to, timeout), in COMPAT_SYSCALL_DEFINE6()
2427 const struct __kernel_timespec __user *, timeout, in COMPAT_SYSCALL_DEFINE6() argument
2433 if (timeout) { in COMPAT_SYSCALL_DEFINE6()
2434 if (get_timespec64(&ts, timeout)) in COMPAT_SYSCALL_DEFINE6()
2435 return -EFAULT; in COMPAT_SYSCALL_DEFINE6()
2438 return -EINVAL; in COMPAT_SYSCALL_DEFINE6()
2455 max_user_watches = (((si.totalram - si.totalhigh) / 25) << PAGE_SHIFT) / in eventpoll_init()
2461 * using an extra cache line on 64-bit (and smaller) CPUs in eventpoll_init()