signal_struct is (mostly) protected by ->sighand->siglock, I think we don't need ->taskstats_lock to protect ->stats. This also allows us to simplify the locking in fill_tgid().
Showing the changes to kernel (2 of 4 files). Show all
Unified · Split
| @@ -830,7 +830,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts · 829 unmodified lines | ||
| 830 | 830 | if (clone_flags & CLONE_THREAD) { |
| 831 | 831 | atomic_inc(¤t->signal->count); |
| 832 | 832 | atomic_inc(¤t->signal->live); |
| 833 | − taskstats_tgid_alloc(current->signal); | |
| 833 | + taskstats_tgid_alloc(current); | |
| 834 | 834 | return 0; |
| 835 | 835 | } |
| 836 | 836 | sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL); |
| @@ -241,11 +241,11 @@ static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk, · 240 unmodified lines | ||
| 241 | 241 | tsk = first; |
| 242 | 242 | read_lock(&tasklist_lock); |
| 243 | 243 | /* Start with stats from dead tasks */ |
| 244 | − if (first->signal) { | |
| 245 | − spin_lock_irqsave(&first->signal->stats_lock, flags); | |
| 244 | + if (first->sighand) { | |
| 245 | + spin_lock_irqsave(&first->sighand->siglock, flags); | |
| 246 | 246 | if (first->signal->stats) |
| 247 | 247 | memcpy(stats, first->signal->stats, sizeof(*stats)); |
| 248 | − spin_unlock_irqrestore(&first->signal->stats_lock, flags); | |
| 248 | + spin_unlock_irqrestore(&first->sighand->siglock, flags); | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | do { |
| @@ -276,7 +276,7 @@ static void fill_tgid_exit(struct task_struct *tsk) · 24 unmodified lines | ||
| 276 | 276 | { |
| 277 | 277 | unsigned long flags; |
| 278 | 278 | |
| 279 | − spin_lock_irqsave(&tsk->signal->stats_lock, flags); | |
| 279 | + spin_lock_irqsave(&tsk->sighand->siglock, flags); | |
| 280 | 280 | if (!tsk->signal->stats) |
| 281 | 281 | goto ret; |
| 282 | 282 | |
| @@ -288,7 +288,7 @@ static void fill_tgid_exit(struct task_struct *tsk) · 5 unmodified lines | ||
| 288 | 288 | */ |
| 289 | 289 | delayacct_add_tsk(tsk->signal->stats, tsk); |
| 290 | 290 | ret: |
| 291 | − spin_unlock_irqrestore(&tsk->signal->stats_lock, flags); | |
| 291 | + spin_unlock_irqrestore(&tsk->sighand->siglock, flags); | |
| 292 | 292 | return; |
| 293 | 293 | } |
| 294 | 294 | |
| @@ -464,15 +464,10 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats, · 169 unmodified lines | ||
| 464 | 464 | size_t size; |
| 465 | 465 | int is_thread_group; |
| 466 | 466 | struct nlattr *na; |
| 467 | − unsigned long flags; | |
| 468 | 467 | |
| 469 | 468 | if (!family_registered || !tidstats) |
| 470 | 469 | return; |
| 471 | 470 | |
| 472 | − spin_lock_irqsave(&tsk->signal->stats_lock, flags); | |
| 473 | − is_thread_group = tsk->signal->stats ? 1 : 0; | |
| 474 | − spin_unlock_irqrestore(&tsk->signal->stats_lock, flags); | |
| 475 | − | |
| 476 | 471 | rc = 0; |
| 477 | 472 | /* |
| 478 | 473 | * Size includes space for nested attributes |
| @@ -480,6 +475,7 @@ void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats, · 1 unmodified line | ||
| 480 | 475 | size = nla_total_size(sizeof(u32)) + |
| 481 | 476 | nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); |
| 482 | 477 | |
| 478 | + is_thread_group = (tsk->signal->stats != NULL); | |
| 483 | 479 | if (is_thread_group) |
| 484 | 480 | size = 2 * size; /* PID + STATS + TGID + STATS */ |
| 485 | 481 | |