Rename tsk_restore_flags() to current_restore_flags()
Subsystems (8)
PATCH 1/1 Rename tsk_restore_flags() to current_restore_flags()
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.
---
get_maintainer.pl suggested 35 recipients for this patch. I decided to trim that a bit ....
Can it just go through the tip tree?? It should be completely uncontroversial.
Thanks,
NeilBrown
drivers/block/nbd.c | 2 +- drivers/scsi/iscsi_tcp.c | 2 +- fs/nfsd/vfs.c | 2 +- include/linux/sched.h | 6 +++--- kernel/softirq.c | 2 +- net/core/dev.c | 2 +- net/core/sock.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)
drivers/block/nbd.c +1 -1
@@ -239,7 +239,7 @@ static int sock_xmit(struct nbd_device *nbd, int index, int send, } }while (msg_data_left (&msg)); -tsk_restore_flags (current, pflags,PF_MEMALLOC ); +current_restore_flags (pflags,PF_MEMALLOC );return result; }
drivers/scsi/iscsi_tcp.c +1 -1
@@ -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; }
fs/nfsd/vfs.c +1 -1
@@ -1004,7 +1004,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,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; }
include/linux/sched.h +3 -3
@@ -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);
kernel/softirq.c +1 -1
@@ -309,7 +309,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)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)
net/core/dev.c +1 -1
@@ -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);
net/core/sock.c +1 -1
@@ -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; }
Signature · 1 line
2.12.2
Quoted 7 lines · NeilBrown
It is not safe for one thread to modify the ->flags of another thread as there is no locking that can protect the update.
Sotsk_restore_flags(), which takes a task pointer and modifies the flags, is an invitation to do the wrong thing.
Quoted 6 lines
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()tocurrent_restore_flags()and don't pass in atask_structpointer. Always operate oncurrent->flags.
yes this makes a lot of sense to me.
It would be great if somebody cleaned up setting of ->flags to be always set on current as well. This seems to be the case but there are places where we do
struct task_struct *tsk = current; [...] tsk->flags |= PF_$FOO
Quoted 1 line
Signed-off-by NeilBrown <[email protected]>
Quoted 119 lines
---
get_maintainer.pl suggested 35 recipients for this patch. I decided to trim that a bit ....
Can it just go through the tip tree?? It should be completely uncontroversial.
Thanks,
NeilBrowndrivers/block/nbd.c | 2 +- drivers/scsi/iscsi_tcp.c | 2 +- fs/nfsd/vfs.c | 2 +- include/linux/sched.h | 6 +++--- kernel/softirq.c | 2 +- net/core/dev.c | 2 +- net/core/sock.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)drivers/block/nbd.c +1
-1@@ -239,7 +239,7 @@ static int sock_xmit(struct nbd_device *nbd, int index, int send, } }while (msg_data_left (&msg)); -tsk_restore_flags (current, pflags,PF_MEMALLOC ); +current_restore_flags (pflags,PF_MEMALLOC );return result; }drivers/scsi/iscsi_tcp.c +1
-1@@ -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; }fs/nfsd/vfs.c +1
-1@@ -1004,7 +1004,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,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; }include/linux/sched.h +3
-3@@ -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);kernel/softirq.c +1
-1@@ -309,7 +309,7 @@ asmlinkage __visible void __softirq_entry __do_softirq(void)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)net/core/dev.c +1
-1@@ -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);net/core/sock.c +1
-1@@ -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; }Signature · 1 line
2.12.2
Signature · 2 lines
Michal Hocko SUSE Labs