linux-ia64.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kill do_each_thread()
@ 2023-08-17 16:37 Oleg Nesterov
  2023-08-17 16:53 ` Kees Cook
  2023-08-18  6:04 ` Jiri Slaby
  0 siblings, 2 replies; 5+ messages in thread
From: Oleg Nesterov @ 2023-08-17 16:37 UTC (permalink / raw)
  To: Andrew Morton, Eric W. Biederman
  Cc: Jiri Slaby, Christian Brauner, Kees Cook, linux-ia64,
	linux-kernel

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.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 arch/ia64/kernel/mca.c       | 4 ++--
 drivers/tty/tty_io.c         | 4 ++--
 fs/fs_struct.c               | 4 ++--
 include/linux/sched/signal.h | 7 -------
 4 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
index 92ede80d17fe..2671688d349a 100644
--- a/arch/ia64/kernel/mca.c
+++ b/arch/ia64/kernel/mca.c
@@ -1630,10 +1630,10 @@ default_monarch_init_process(struct notifier_block *self, unsigned long val, voi
 	}
 	printk("\n\n");
 	if (read_trylock(&tasklist_lock)) {
-		do_each_thread (g, t) {
+		for_each_process_thread(g, t) {
 			printk("\nBacktrace of pid %d (%s)\n", t->pid, t->comm);
 			show_stack(t, NULL, KERN_DEFAULT);
-		} while_each_thread (g, t);
+		}
 		read_unlock(&tasklist_lock);
 	}
 	/* FIXME: This will not restore zapped printk locks. */
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 63db04b9113a..27d8e3a1aace 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3031,7 +3031,7 @@ void __do_SAK(struct tty_struct *tty)
 	} while_each_pid_task(session, PIDTYPE_SID, p);
 
 	/* Now kill any processes that happen to have the tty open */
-	do_each_thread(g, p) {
+	for_each_process_thread(g, p) {
 		if (p->signal->tty == tty) {
 			tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n",
 				   task_pid_nr(p), p->comm);
@@ -3048,7 +3048,7 @@ void __do_SAK(struct tty_struct *tty)
 					PIDTYPE_SID);
 		}
 		task_unlock(p);
-	} while_each_thread(g, p);
+	}
 	read_unlock(&tasklist_lock);
 	put_pid(session);
 }
diff --git a/fs/fs_struct.c b/fs/fs_struct.c
index 04b3f5b9c629..64c2d0814ed6 100644
--- a/fs/fs_struct.c
+++ b/fs/fs_struct.c
@@ -62,7 +62,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
 	int count = 0;
 
 	read_lock(&tasklist_lock);
-	do_each_thread(g, p) {
+	for_each_process_thread(g, p) {
 		task_lock(p);
 		fs = p->fs;
 		if (fs) {
@@ -79,7 +79,7 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
 			spin_unlock(&fs->lock);
 		}
 		task_unlock(p);
-	} while_each_thread(g, p);
+	}
 	read_unlock(&tasklist_lock);
 	while (count--)
 		path_put(old_root);
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 669e8cff40c7..0deebe2ab07d 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -648,13 +648,6 @@ extern void flush_itimer_signals(void);
 
 extern bool current_is_single_threaded(void);
 
-/*
- * Careful: do_each_thread/while_each_thread is a double loop so
- *          'break' will not work as expected - use goto instead.
- */
-#define do_each_thread(g, t) \
-	for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
-
 #define while_each_thread(g, t) \
 	while ((t = next_thread(t)) != g)
 
-- 
2.25.1.362.g51ebf55



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] kill do_each_thread()
  2023-08-17 16:37 [PATCH] kill do_each_thread() Oleg Nesterov
@ 2023-08-17 16:53 ` Kees Cook
  2023-08-18  6:04 ` Jiri Slaby
  1 sibling, 0 replies; 5+ messages in thread
From: Kees Cook @ 2023-08-17 16:53 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andrew Morton, Eric W. Biederman, Jiri Slaby, Christian Brauner,
	linux-ia64, linux-kernel

On Thu, Aug 17, 2023 at 06:37:08PM +0200, Oleg Nesterov wrote:
> 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.
> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kill do_each_thread()
  2023-08-17 16:37 [PATCH] kill do_each_thread() Oleg Nesterov
  2023-08-17 16:53 ` Kees Cook
@ 2023-08-18  6:04 ` Jiri Slaby
  2023-08-18  8:16   ` Oleg Nesterov
  1 sibling, 1 reply; 5+ messages in thread
From: Jiri Slaby @ 2023-08-18  6:04 UTC (permalink / raw)
  To: Oleg Nesterov, Andrew Morton, Eric W. Biederman
  Cc: Christian Brauner, Kees Cook, linux-ia64, linux-kernel

On 17. 08. 23, 18:37, Oleg Nesterov wrote:
> 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.

Is there any change in behavior? Why is for_each_process_thread() better 
than do_each_thread()?

thanks,
-- 
js
suse labs


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kill do_each_thread()
  2023-08-18  6:04 ` Jiri Slaby
@ 2023-08-18  8:16   ` Oleg Nesterov
  2023-08-18  8:25     ` Jiri Slaby
  0 siblings, 1 reply; 5+ messages in thread
From: Oleg Nesterov @ 2023-08-18  8:16 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Andrew Morton, Eric W. Biederman, Christian Brauner, Kees Cook,
	linux-ia64, linux-kernel

On 08/18, Jiri Slaby wrote:
>
> On 17. 08. 23, 18:37, Oleg Nesterov wrote:
> >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.
>
> Is there any change in behavior?

No.

Well, 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.

Oleg.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kill do_each_thread()
  2023-08-18  8:16   ` Oleg Nesterov
@ 2023-08-18  8:25     ` Jiri Slaby
  0 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby @ 2023-08-18  8:25 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andrew Morton, Eric W. Biederman, Christian Brauner, Kees Cook,
	linux-ia64, linux-kernel

On 18. 08. 23, 10:16, Oleg Nesterov wrote:
> On 08/18, Jiri Slaby wrote:
>>
>> On 17. 08. 23, 18:37, Oleg Nesterov wrote:
>>> 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.
>>
>> Is there any change in behavior?
> 
> No.
> 
> Well, 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.

Sounds like a perfect commit log now... Unless squashed to the patch, it 
will be Linked at least. Thanks for explanation.

-- 
js
suse labs


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-18  8:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-17 16:37 [PATCH] kill do_each_thread() Oleg Nesterov
2023-08-17 16:53 ` Kees Cook
2023-08-18  6:04 ` Jiri Slaby
2023-08-18  8:16   ` Oleg Nesterov
2023-08-18  8:25     ` Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).