Skip to content

Commit 5ffd2c3

Browse files
oleg-nesterovakpm00
authored andcommitted
kill do_each_thread()
Eric has pointed out that we still have 3 users of do_each_thread(). Change them to use for_each_process_thread() and kill this helper. There is a subtle change, after do_each_thread/while_each_thread g == t == &init_task, while after for_each_process_thread() they both point to nowhere, but this doesn't matter. > Why is for_each_process_thread() better than do_each_thread()? Say, for_each_process_thread() is rcu safe, do_each_thread() is not. And certainly for_each_process_thread(p, t) { do_something(p, t); } looks better than do_each_thread(p, t) { do_something(p, t); } while_each_thread(p, t); And again, there are only 3 users of this awkward helper left. It should have been killed years ago and in fact I thought it had already been killed. It uses while_each_thread() which needs some changes. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Oleg Nesterov <[email protected]> Reviewed-by: Kees Cook <[email protected]> Cc: "Christian Brauner (Microsoft)" <[email protected]> Cc: Eric W. Biederman <[email protected]> Cc: Jiri Slaby <[email protected]> # tty/serial Signed-off-by: Andrew Morton <[email protected]>
1 parent cdaac8e commit 5ffd2c3

File tree

4 files changed

+6
-13
lines changed

4 files changed

+6
-13
lines changed

arch/ia64/kernel/mca.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,10 +1630,10 @@ default_monarch_init_process(struct notifier_block *self, unsigned long val, voi
16301630
}
16311631
printk("\n\n");
16321632
if (read_trylock(&tasklist_lock)) {
1633-
do_each_thread (g, t) {
1633+
for_each_process_thread(g, t) {
16341634
printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
16351635
show_stack(t, NULL, KERN_DEFAULT);
1636-
} while_each_thread (g, t);
1636+
}
16371637
read_unlock(&tasklist_lock);
16381638
}
16391639
/* FIXME: This will not restore zapped printk locks. */

drivers/tty/tty_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,7 @@ void __do_SAK(struct tty_struct *tty)
30313031
} while_each_pid_task(session, PIDTYPE_SID, p);
30323032

30333033
/* Now kill any processes that happen to have the tty open */
3034-
do_each_thread(g, p) {
3034+
for_each_process_thread(g, p) {
30353035
if (p->signal->tty == tty) {
30363036
tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n",
30373037
task_pid_nr(p), p->comm);
@@ -3048,7 +3048,7 @@ void __do_SAK(struct tty_struct *tty)
30483048
PIDTYPE_SID);
30493049
}
30503050
task_unlock(p);
3051-
} while_each_thread(g, p);
3051+
}
30523052
read_unlock(&tasklist_lock);
30533053
put_pid(session);
30543054
}

fs/fs_struct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
6262
int count = 0;
6363

6464
read_lock(&tasklist_lock);
65-
do_each_thread(g, p) {
65+
for_each_process_thread(g, p) {
6666
task_lock(p);
6767
fs = p->fs;
6868
if (fs) {
@@ -79,7 +79,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
7979
spin_unlock(&fs->lock);
8080
}
8181
task_unlock(p);
82-
} while_each_thread(g, p);
82+
}
8383
read_unlock(&tasklist_lock);
8484
while (count--)
8585
path_put(old_root);

include/linux/sched/signal.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,6 @@ extern void flush_itimer_signals(void);
648648

649649
extern bool current_is_single_threaded(void);
650650

651-
/*
652-
* Careful: do_each_thread/while_each_thread is a double loop so
653-
* 'break' will not work as expected - use goto instead.
654-
*/
655-
#define do_each_thread(g, t) \
656-
for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
657-
658651
#define while_each_thread(g, t) \
659652
while ((t = next_thread(t)) != g)
660653

0 commit comments

Comments
 (0)