2727#include <linux/rcupdate.h>
2828#include <linux/hrtimer.h>
2929#include <linux/sched/rt.h>
30+ #include <net/ll_poll.h>
3031
3132#include <asm/uaccess.h>
3233
@@ -384,9 +385,10 @@ static int max_select_fd(unsigned long n, fd_set_bits *fds)
384385#define POLLEX_SET (POLLPRI)
385386
386387static inline void wait_key_set (poll_table * wait , unsigned long in ,
387- unsigned long out , unsigned long bit )
388+ unsigned long out , unsigned long bit ,
389+ unsigned int ll_flag )
388390{
389- wait -> _key = POLLEX_SET ;
391+ wait -> _key = POLLEX_SET | ll_flag ;
390392 if (in & bit )
391393 wait -> _key |= POLLIN_SET ;
392394 if (out & bit )
@@ -400,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
400402 poll_table * wait ;
401403 int retval , i , timed_out = 0 ;
402404 unsigned long slack = 0 ;
405+ unsigned int ll_flag = POLL_LL ;
406+ u64 ll_time = ll_end_time ();
403407
404408 rcu_read_lock ();
405409 retval = max_select_fd (n , fds );
@@ -422,6 +426,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
422426 retval = 0 ;
423427 for (;;) {
424428 unsigned long * rinp , * routp , * rexp , * inp , * outp , * exp ;
429+ bool can_ll = false;
425430
426431 inp = fds -> in ; outp = fds -> out ; exp = fds -> ex ;
427432 rinp = fds -> res_in ; routp = fds -> res_out ; rexp = fds -> res_ex ;
@@ -449,7 +454,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
449454 f_op = f .file -> f_op ;
450455 mask = DEFAULT_POLLMASK ;
451456 if (f_op && f_op -> poll ) {
452- wait_key_set (wait , in , out , bit );
457+ wait_key_set (wait , in , out ,
458+ bit , ll_flag );
453459 mask = (* f_op -> poll )(f .file , wait );
454460 }
455461 fdput (f );
@@ -468,6 +474,11 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
468474 retval ++ ;
469475 wait -> _qproc = NULL ;
470476 }
477+ if (mask & POLL_LL )
478+ can_ll = true;
479+ /* got something, stop busy polling */
480+ if (retval )
481+ ll_flag = 0 ;
471482 }
472483 }
473484 if (res_in )
@@ -486,6 +497,9 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
486497 break ;
487498 }
488499
500+ if (can_ll && can_poll_ll (ll_time ))
501+ continue ;
502+
489503 /*
490504 * If this is the first loop and we have a timeout
491505 * given, then we convert to ktime_t and set the to
@@ -717,7 +731,8 @@ struct poll_list {
717731 * pwait poll_table will be used by the fd-provided poll handler for waiting,
718732 * if pwait->_qproc is non-NULL.
719733 */
720- static inline unsigned int do_pollfd (struct pollfd * pollfd , poll_table * pwait )
734+ static inline unsigned int do_pollfd (struct pollfd * pollfd , poll_table * pwait ,
735+ bool * can_ll , unsigned int ll_flag )
721736{
722737 unsigned int mask ;
723738 int fd ;
@@ -731,7 +746,10 @@ static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait)
731746 mask = DEFAULT_POLLMASK ;
732747 if (f .file -> f_op && f .file -> f_op -> poll ) {
733748 pwait -> _key = pollfd -> events |POLLERR |POLLHUP ;
749+ pwait -> _key |= ll_flag ;
734750 mask = f .file -> f_op -> poll (f .file , pwait );
751+ if (mask & POLL_LL )
752+ * can_ll = true;
735753 }
736754 /* Mask out unneeded events. */
737755 mask &= pollfd -> events | POLLERR | POLLHUP ;
@@ -750,6 +768,8 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
750768 ktime_t expire , * to = NULL ;
751769 int timed_out = 0 , count = 0 ;
752770 unsigned long slack = 0 ;
771+ unsigned int ll_flag = POLL_LL ;
772+ u64 ll_time = ll_end_time ();
753773
754774 /* Optimise the no-wait case */
755775 if (end_time && !end_time -> tv_sec && !end_time -> tv_nsec ) {
@@ -762,6 +782,7 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
762782
763783 for (;;) {
764784 struct poll_list * walk ;
785+ bool can_ll = false;
765786
766787 for (walk = list ; walk != NULL ; walk = walk -> next ) {
767788 struct pollfd * pfd , * pfd_end ;
@@ -776,9 +797,10 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
776797 * this. They'll get immediately deregistered
777798 * when we break out and return.
778799 */
779- if (do_pollfd (pfd , pt )) {
800+ if (do_pollfd (pfd , pt , & can_ll , ll_flag )) {
780801 count ++ ;
781802 pt -> _qproc = NULL ;
803+ ll_flag = 0 ;
782804 }
783805 }
784806 }
@@ -795,6 +817,8 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
795817 if (count || timed_out )
796818 break ;
797819
820+ if (can_ll && can_poll_ll (ll_time ))
821+ continue ;
798822 /*
799823 * If this is the first loop and we have a timeout
800824 * given, then we convert to ktime_t and set the to
0 commit comments