sched/core: Remove 'task' parameter and rename tsk_restore_flags() to current_restore...
authorNeilBrown <neilb@suse.com>
Fri, 7 Apr 2017 00:03:26 +0000 (10:03 +1000)
committerIngo Molnar <mingo@kernel.org>
Tue, 11 Apr 2017 07:06:32 +0000 (09:06 +0200)
It is not safe for one thread to modify the ->flags
of another thread as there is no locking that can protect
the update.

So tsk_restore_flags(), which takes a task pointer and modifies
the flags, is an invitation to do the wrong thing.

All current users pass "current" as the task, so no developers have
accepted that invitation.  It would be best to ensure it remains
that way.

So rename tsk_restore_flags() to current_restore_flags() and don't
pass in a task_struct pointer.  Always operate on current->flags.

Signed-off-by: NeilBrown <neilb@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
drivers/block/nbd.c
drivers/scsi/iscsi_tcp.c
fs/nfsd/vfs.c
include/linux/sched.h
kernel/softirq.c
net/core/dev.c
net/core/sock.c

index d8a23561b4cb4b720065ccf1bd97714a07395c73..3c9052bf232795bd14acc0e170997ba31387615f 100644 (file)
@@ -244,7 +244,7 @@ static int sock_xmit(struct nbd_device *nbd, int index, int send,
                        *sent += result;
        } while (msg_data_left(&msg));
 
-       tsk_restore_flags(current, pflags, PF_MEMALLOC);
+       current_restore_flags(pflags, PF_MEMALLOC);
 
        return result;
 }
index 4228aba1f654e10b6d18bf32153a1a0825ce6dc2..bbea8eac9abb737b7be67366ab9cdcde89830609 100644 (file)
@@ -387,7 +387,7 @@ static int iscsi_sw_tcp_pdu_xmit(struct iscsi_task *task)
                rc = 0;
        }
 
-       tsk_restore_flags(current, pflags, PF_MEMALLOC);
+       current_restore_flags(pflags, PF_MEMALLOC);
        return rc;
 }
 
index 19d50f600e8d48c6f493130076606a6213de258d..9aaf6ca7756998f9f872db91e7d1ef5f92351e8c 100644 (file)
@@ -1004,7 +1004,7 @@ out_nfserr:
        else
                err = nfserrno(host_err);
        if (test_bit(RQ_LOCAL, &rqstp->rq_flags))
-               tsk_restore_flags(current, pflags, PF_LESS_THROTTLE);
+               current_restore_flags(pflags, PF_LESS_THROTTLE);
        return err;
 }
 
index d67eee84fd430f3c44b77d4ba007ec5d2dcabb2b..0978fb74e45a7862afdb138264260fdff498462b 100644 (file)
@@ -1286,10 +1286,10 @@ TASK_PFA_TEST(LMK_WAITING, lmk_waiting)
 TASK_PFA_SET(LMK_WAITING, lmk_waiting)
 
 static inline void
-tsk_restore_flags(struct task_struct *task, unsigned long orig_flags, unsigned long flags)
+current_restore_flags(unsigned long orig_flags, unsigned long flags)
 {
-       task->flags &= ~flags;
-       task->flags |= orig_flags & flags;
+       current->flags &= ~flags;
+       current->flags |= orig_flags & flags;
 }
 
 extern int cpuset_cpumask_can_shrink(const struct cpumask *cur, const struct cpumask *trial);
index 744fa611cae06b26d89a04e915f0d7fadf37035b..4e09821f9d9e8b5815037bd469110e2618abb7f6 100644 (file)
@@ -309,7 +309,7 @@ restart:
        account_irq_exit_time(current);
        __local_bh_enable(SOFTIRQ_OFFSET);
        WARN_ON_ONCE(in_interrupt());
-       tsk_restore_flags(current, old_flags, PF_MEMALLOC);
+       current_restore_flags(old_flags, PF_MEMALLOC);
 }
 
 asmlinkage __visible void do_softirq(void)
index 7869ae3837ca741e344b1731dc50d8408d8bcb6c..e8a366387a99c96b36b22ac92d78e765a41484b7 100644 (file)
@@ -4240,7 +4240,7 @@ static int __netif_receive_skb(struct sk_buff *skb)
                 */
                current->flags |= PF_MEMALLOC;
                ret = __netif_receive_skb_core(skb, true);
-               tsk_restore_flags(current, pflags, PF_MEMALLOC);
+               current_restore_flags(pflags, PF_MEMALLOC);
        } else
                ret = __netif_receive_skb_core(skb, false);
 
index 2c4f574168fbdcebc0cc82c0c8a36214992d6224..b416a537bd0ac24998381fa76d7df65e108917dc 100644 (file)
@@ -325,7 +325,7 @@ int __sk_backlog_rcv(struct sock *sk, struct sk_buff *skb)
 
        current->flags |= PF_MEMALLOC;
        ret = sk->sk_backlog_rcv(sk, skb);
-       tsk_restore_flags(current, pflags, PF_MEMALLOC);
+       current_restore_flags(pflags, PF_MEMALLOC);
 
        return ret;
 }