Skip to content

Commit 60f92ac

Browse files
oleg-nesterovakpm00
authored andcommitted
fs/proc: do_task_stat: move thread_group_cputime_adjusted() outside of lock_task_sighand()
Patch series "fs/proc: do_task_stat: use sig->stats_". do_task_stat() has the same problem as getrusage() had before "getrusage: use sig->stats_lock rather than lock_task_sighand()": a hard lockup. If NR_CPUS threads call lock_task_sighand() at the same time and the process has NR_THREADS, spin_lock_irq will spin with irqs disabled O(NR_CPUS * NR_THREADS) time. This patch (of 3): thread_group_cputime() does its own locking, we can safely shift thread_group_cputime_adjusted() which does another for_each_thread loop outside of ->siglock protected section. Not only this removes for_each_thread() from the critical section with irqs disabled, this removes another case when stats_lock is taken with siglock held. We want to remove this dependency, then we can change the users of stats_lock to not disable irqs. Link: https://lkml.kernel.org/r/20240123153313.GA21832@redhat.com Link: https://lkml.kernel.org/r/20240123153355.GA21854@redhat.com Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Dylan Hatch <dylanbhatch@google.com> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f7ec1cd commit 60f92ac

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fs/proc/array.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
511511

512512
sigemptyset(&sigign);
513513
sigemptyset(&sigcatch);
514-
cutime = cstime = utime = stime = 0;
514+
cutime = cstime = 0;
515515
cgtime = gtime = 0;
516516

517517
if (lock_task_sighand(task, &flags)) {
@@ -546,7 +546,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
546546

547547
min_flt += sig->min_flt;
548548
maj_flt += sig->maj_flt;
549-
thread_group_cputime_adjusted(task, &utime, &stime);
550549
gtime += sig->gtime;
551550

552551
if (sig->flags & (SIGNAL_GROUP_EXIT | SIGNAL_STOP_STOPPED))
@@ -562,10 +561,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
562561

563562
if (permitted && (!whole || num_threads < 2))
564563
wchan = !task_is_running(task);
565-
if (!whole) {
564+
565+
if (whole) {
566+
thread_group_cputime_adjusted(task, &utime, &stime);
567+
} else {
568+
task_cputime_adjusted(task, &utime, &stime);
566569
min_flt = task->min_flt;
567570
maj_flt = task->maj_flt;
568-
task_cputime_adjusted(task, &utime, &stime);
569571
gtime = task_gtime(task);
570572
}
571573

0 commit comments

Comments
 (0)