From nobody Mon Feb 9 04:04:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85B04EB64DC for ; Thu, 15 Jun 2023 12:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241353AbjFOMKl (ORCPT ); Thu, 15 Jun 2023 08:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238157AbjFOMKi (ORCPT ); Thu, 15 Jun 2023 08:10:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B09E8194 for ; Thu, 15 Jun 2023 05:10:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4817360A05 for ; Thu, 15 Jun 2023 12:10:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97596C433C8; Thu, 15 Jun 2023 12:10:33 +0000 (UTC) From: Huacai Chen To: Luis Chamberlain , Andrew Morton , "Eric W . Biederman" Cc: Kees Cook , chenhuacai@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huacai Chen Subject: [PATCH] kthread: Rename user_mode_thread() to kmuser_thread() Date: Thu, 15 Jun 2023 20:10:16 +0800 Message-Id: <20230615121016.3731983-1-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Commit 343f4c49f2438d8 ("kthread: Don't allocate kthread_struct for init and umh") introduces a new function user_mode_thread() for init and umh. init and umh are different from typical kernel threads since the don't need a "kthread" struct and they will finally become user processes by calling kernel_execve(), but on the other hand, they are also different from typical user mode threads (they have no "mm" structs at creation time, which is traditionally used to distinguish a user thread and a kernel thread). In a former patch I treat init and umh as "special kernel threads" and unify kernel_thread() and user_mode_thread() to kernel_thread() again. However, the patch has been nacked because init and umh are essentially "special user threads". Nevertheless, I still agree with Andrews' comment "But the naming isn't very good anyway. They should have been usermode_thread/kernel_thread or user_thread/kernel_thread.". Since Eric describes init and umh as "user threads run in kernel mode", in this patch I rename user_mode_thread() as kmuser_thread(), which is a little better than just user_thread(). Signed-off-by: Huacai Chen --- include/linux/sched/task.h | 2 +- init/main.c | 2 +- kernel/fork.c | 4 ++-- kernel/umh.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index e0f5ac90a228..c774d604b0a3 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -98,7 +98,7 @@ struct task_struct *create_io_thread(int (*fn)(void *), v= oid *arg, int node); struct task_struct *fork_idle(int); extern pid_t kernel_thread(int (*fn)(void *), void *arg, const char *name, unsigned long flags); -extern pid_t user_mode_thread(int (*fn)(void *), void *arg, unsigned long = flags); +extern pid_t kmuser_thread(int (*fn)(void *), void *arg, unsigned long fla= gs); extern long kernel_wait4(pid_t, int __user *, int, struct rusage *); int kernel_wait(pid_t pid, int *stat); =20 diff --git a/init/main.c b/init/main.c index af50044deed5..362ba90d6f73 100644 --- a/init/main.c +++ b/init/main.c @@ -697,7 +697,7 @@ noinline void __ref __noreturn rest_init(void) * the init task will end up wanting to create kthreads, which, if * we schedule it before we create kthreadd, will OOPS. */ - pid =3D user_mode_thread(kernel_init, NULL, CLONE_FS); + pid =3D kmuser_thread(kernel_init, NULL, CLONE_FS); /* * Pin init on the boot CPU. Task migration is not properly working * until sched_init_smp() has been run. It will set the allowed diff --git a/kernel/fork.c b/kernel/fork.c index 41c964104b58..57d5c8c1766e 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2978,9 +2978,9 @@ pid_t kernel_thread(int (*fn)(void *), void *arg, con= st char *name, } =20 /* - * Create a user mode thread. + * Create a kernel mode user thread. */ -pid_t user_mode_thread(int (*fn)(void *), void *arg, unsigned long flags) +pid_t kmuser_thread(int (*fn)(void *), void *arg, unsigned long flags) { struct kernel_clone_args args =3D { .flags =3D ((lower_32_bits(flags) | CLONE_VM | diff --git a/kernel/umh.c b/kernel/umh.c index 60aa9e764a38..28c0cf0da7be 100644 --- a/kernel/umh.c +++ b/kernel/umh.c @@ -130,7 +130,7 @@ static void call_usermodehelper_exec_sync(struct subpro= cess_info *sub_info) =20 /* If SIGCLD is ignored do_wait won't populate the status. */ kernel_sigaction(SIGCHLD, SIG_DFL); - pid =3D user_mode_thread(call_usermodehelper_exec_async, sub_info, SIGCHL= D); + pid =3D kmuser_thread(call_usermodehelper_exec_async, sub_info, SIGCHLD); if (pid < 0) sub_info->retval =3D pid; else @@ -169,7 +169,7 @@ static void call_usermodehelper_exec_work(struct work_s= truct *work) * want to pollute current->children, and we need a parent * that always ignores SIGCHLD to ensure auto-reaping. */ - pid =3D user_mode_thread(call_usermodehelper_exec_async, sub_info, + pid =3D kmuser_thread(call_usermodehelper_exec_async, sub_info, CLONE_PARENT | SIGCHLD); if (pid < 0) { sub_info->retval =3D pid; --=20 2.39.3