Merge tag 'please-pull-fix-ia64-warnings' of git://git.kernel.org/pub/scm/linux/kerne...
[firefly-linux-kernel-4.4.55.git] / fs / select.c
index 36540754bad785d8eb16544b6303ea6761d0f4b1..f9f49c40cfd48b99442041f8b6f2e82ecd2d0101 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/rcupdate.h>
 #include <linux/hrtimer.h>
 #include <linux/sched/rt.h>
+#include <linux/freezer.h>
 #include <net/ll_poll.h>
 
 #include <asm/uaccess.h>
@@ -237,7 +238,8 @@ int poll_schedule_timeout(struct poll_wqueues *pwq, int state,
 
        set_current_state(state);
        if (!pwq->triggered)
-               rc = schedule_hrtimeout_range(expires, slack, HRTIMER_MODE_ABS);
+               rc = freezable_schedule_hrtimeout_range(expires, slack,
+                                                       HRTIMER_MODE_ABS);
        __set_current_state(TASK_RUNNING);
 
        /*
@@ -402,8 +404,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
        poll_table *wait;
        int retval, i, timed_out = 0;
        unsigned long slack = 0;
-       unsigned int ll_flag = ll_get_flag();
-       u64 ll_time = ll_end_time();
+       unsigned int busy_flag = net_busy_loop_on() ? POLL_BUSY_LOOP : 0;
+       unsigned long busy_end = 0;
 
        rcu_read_lock();
        retval = max_select_fd(n, fds);
@@ -426,7 +428,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
        retval = 0;
        for (;;) {
                unsigned long *rinp, *routp, *rexp, *inp, *outp, *exp;
-               bool can_ll = false;
+               bool can_busy_loop = false;
 
                inp = fds->in; outp = fds->out; exp = fds->ex;
                rinp = fds->res_in; routp = fds->res_out; rexp = fds->res_ex;
@@ -455,7 +457,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
                                        mask = DEFAULT_POLLMASK;
                                        if (f_op && f_op->poll) {
                                                wait_key_set(wait, in, out,
-                                                            bit, ll_flag);
+                                                            bit, busy_flag);
                                                mask = (*f_op->poll)(f.file, wait);
                                        }
                                        fdput(f);
@@ -474,11 +476,18 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
                                                retval++;
                                                wait->_qproc = NULL;
                                        }
-                                       if (mask & POLL_LL)
-                                               can_ll = true;
                                        /* got something, stop busy polling */
-                                       if (retval)
-                                               ll_flag = 0;
+                                       if (retval) {
+                                               can_busy_loop = false;
+                                               busy_flag = 0;
+
+                                       /*
+                                        * only remember a returned
+                                        * POLL_BUSY_LOOP if we asked for it
+                                        */
+                                       } else if (busy_flag & mask)
+                                               can_busy_loop = true;
+
                                }
                        }
                        if (res_in)
@@ -497,9 +506,16 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
                        break;
                }
 
-               /* only if on, have sockets with POLL_LL and not out of time */
-               if (ll_flag && can_ll && can_poll_ll(ll_time))
-                       continue;
+               /* only if found POLL_BUSY_LOOP sockets && not out of time */
+               if (can_busy_loop && !need_resched()) {
+                       if (!busy_end) {
+                               busy_end = busy_loop_end_time();
+                               continue;
+                       }
+                       if (!busy_loop_timeout(busy_end))
+                               continue;
+               }
+               busy_flag = 0;
 
                /*
                 * If this is the first loop and we have a timeout
@@ -733,7 +749,8 @@ struct poll_list {
  * if pwait->_qproc is non-NULL.
  */
 static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait,
-                                    bool *can_ll, unsigned int ll_flag)
+                                    bool *can_busy_poll,
+                                    unsigned int busy_flag)
 {
        unsigned int mask;
        int fd;
@@ -747,10 +764,10 @@ static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait,
                        mask = DEFAULT_POLLMASK;
                        if (f.file->f_op && f.file->f_op->poll) {
                                pwait->_key = pollfd->events|POLLERR|POLLHUP;
-                               pwait->_key |= ll_flag;
+                               pwait->_key |= busy_flag;
                                mask = f.file->f_op->poll(f.file, pwait);
-                               if (mask & POLL_LL)
-                                       *can_ll = true;
+                               if (mask & busy_flag)
+                                       *can_busy_poll = true;
                        }
                        /* Mask out unneeded events. */
                        mask &= pollfd->events | POLLERR | POLLHUP;
@@ -769,8 +786,8 @@ static int do_poll(unsigned int nfds,  struct poll_list *list,
        ktime_t expire, *to = NULL;
        int timed_out = 0, count = 0;
        unsigned long slack = 0;
-       unsigned int ll_flag = ll_get_flag();
-       u64 ll_time = ll_end_time();
+       unsigned int busy_flag = net_busy_loop_on() ? POLL_BUSY_LOOP : 0;
+       unsigned long busy_end = 0;
 
        /* Optimise the no-wait case */
        if (end_time && !end_time->tv_sec && !end_time->tv_nsec) {
@@ -783,7 +800,7 @@ static int do_poll(unsigned int nfds,  struct poll_list *list,
 
        for (;;) {
                struct poll_list *walk;
-               bool can_ll = false;
+               bool can_busy_loop = false;
 
                for (walk = list; walk != NULL; walk = walk->next) {
                        struct pollfd * pfd, * pfd_end;
@@ -798,10 +815,13 @@ static int do_poll(unsigned int nfds,  struct poll_list *list,
                                 * this. They'll get immediately deregistered
                                 * when we break out and return.
                                 */
-                               if (do_pollfd(pfd, pt, &can_ll, ll_flag)) {
+                               if (do_pollfd(pfd, pt, &can_busy_loop,
+                                             busy_flag)) {
                                        count++;
                                        pt->_qproc = NULL;
-                                       ll_flag = 0;
+                                       /* found something, stop busy polling */
+                                       busy_flag = 0;
+                                       can_busy_loop = false;
                                }
                        }
                }
@@ -818,9 +838,16 @@ static int do_poll(unsigned int nfds,  struct poll_list *list,
                if (count || timed_out)
                        break;
 
-               /* only if on, have sockets with POLL_LL and not out of time */
-               if (ll_flag && can_ll && can_poll_ll(ll_time))
-                       continue;
+               /* only if found POLL_BUSY_LOOP sockets && not out of time */
+               if (can_busy_loop && !need_resched()) {
+                       if (!busy_end) {
+                               busy_end = busy_loop_end_time();
+                               continue;
+                       }
+                       if (!busy_loop_timeout(busy_end))
+                               continue;
+               }
+               busy_flag = 0;
 
                /*
                 * If this is the first loop and we have a timeout