From nobody Sun Apr 19 21:59:09 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 F3801C43334 for ; Sun, 26 Jun 2022 19:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232014AbiFZTP7 (ORCPT ); Sun, 26 Jun 2022 15:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231843AbiFZTP5 (ORCPT ); Sun, 26 Jun 2022 15:15:57 -0400 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18126DF35 for ; Sun, 26 Jun 2022 12:15:57 -0700 (PDT) Received: from in02.mta.xmission.com ([166.70.13.52]:46222) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5Xjg-000is3-3J; Sun, 26 Jun 2022 13:15:56 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:57740 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5Xje-008aeQ-UP; Sun, 26 Jun 2022 13:15:55 -0600 From: "Eric W. Biederman" To: Linus Torvalds Cc: Christian Brauner , Tejun Heo , Petr Mladek , Lai Jiangshan , Michal Hocko , Linux Kernel Mailing List , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Andrew Morton , Oleg Nesterov References: <20220622140853.31383-1-pmladek@suse.com> <874k0863x8.fsf@email.froward.int.ebiederm.org> <87pmiw1fy6.fsf@email.froward.int.ebiederm.org> <87ilonuti2.fsf_-_@email.froward.int.ebiederm.org> Date: Sun, 26 Jun 2022 14:15:48 -0500 In-Reply-To: <87ilonuti2.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Sun, 26 Jun 2022 14:14:45 -0500") Message-ID: <87czevutgb.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1o5Xje-008aeQ-UP;;;mid=<87czevutgb.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX19g9L/lkXLANuRQ/Dfu1tqYwAH8IrGXz6Q= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: [PATCH 1/3] kthread: Remove the flags argument from kernel_thread X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are only two callers of kernel_thread remaining. The calling in init/main.c that creates kthreadd, and the caller in kernel/kthread.c Both callers pass CLONE_FS|CLONE_FILES. The argument SIGCHLD causes terminate to exit with the oridnary process SIGCHLD semantics. As kthreadd never exists it simply does not matter what kind of exit it has. So for simplicity make it look like everything else and use SIGCHLD. Signed-off-by: "Eric W. Biederman" --- include/linux/sched/task.h | 2 +- init/main.c | 2 +- kernel/fork.c | 3 ++- kernel/kthread.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 505aaf9fe477..d95930e220da 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -91,7 +91,7 @@ extern pid_t kernel_clone(struct kernel_clone_args *kargs= ); struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int nod= e); struct task_struct *fork_idle(int); struct mm_struct *copy_init_mm(void); -extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long fla= gs); +extern pid_t kernel_thread(int (*fn)(void *), void *arg); extern pid_t user_mode_thread(int (*fn)(void *), void *arg, unsigned long = flags); extern long kernel_wait4(pid_t, int __user *, int, struct rusage *); int kernel_wait(pid_t pid, int *stat); diff --git a/init/main.c b/init/main.c index 0ee39cdcfcac..211d38db0d16 100644 --- a/init/main.c +++ b/init/main.c @@ -701,7 +701,7 @@ noinline void __ref rest_init(void) rcu_read_unlock(); =20 numa_default_policy(); - pid =3D kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES); + pid =3D kernel_thread(kthreadd, NULL); rcu_read_lock(); kthreadd_task =3D find_task_by_pid_ns(pid, &init_pid_ns); rcu_read_unlock(); diff --git a/kernel/fork.c b/kernel/fork.c index 9d44f2d46c69..65909ded0ea7 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2694,8 +2694,9 @@ pid_t kernel_clone(struct kernel_clone_args *args) /* * Create a kernel thread. */ -pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) +pid_t kernel_thread(int (*fn)(void *), void *arg) { + unsigned long flags =3D CLONE_FS | CLONE_FILES | SIGCHLD; struct kernel_clone_args args =3D { .flags =3D ((lower_32_bits(flags) | CLONE_VM | CLONE_UNTRACED) & ~CSIGNAL), diff --git a/kernel/kthread.c b/kernel/kthread.c index 544fd4097406..c0505e6b7142 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -396,7 +396,7 @@ static void create_kthread(struct kthread_create_info *= create) current->pref_node_fork =3D create->node; #endif /* We want our own signal handler (we take no signals by default). */ - pid =3D kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD); + pid =3D kernel_thread(kthread, create); if (pid < 0) { /* If user was SIGKILLed, I release the structure. */ struct completion *done =3D xchg(&create->done, NULL); --=20 2.35.3 From nobody Sun Apr 19 21:59:09 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 3A6E0C433EF for ; Sun, 26 Jun 2022 19:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232046AbiFZTQW (ORCPT ); Sun, 26 Jun 2022 15:16:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232020AbiFZTQV (ORCPT ); Sun, 26 Jun 2022 15:16:21 -0400 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0A54DF35 for ; Sun, 26 Jun 2022 12:16:20 -0700 (PDT) Received: from in02.mta.xmission.com ([166.70.13.52]:43804) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5Xk3-00Cq77-RR; Sun, 26 Jun 2022 13:16:19 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:57744 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5Xk2-008ahI-S9; Sun, 26 Jun 2022 13:16:19 -0600 From: "Eric W. Biederman" To: Linus Torvalds Cc: Christian Brauner , Tejun Heo , Petr Mladek , Lai Jiangshan , Michal Hocko , Linux Kernel Mailing List , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Andrew Morton , Oleg Nesterov References: <20220622140853.31383-1-pmladek@suse.com> <874k0863x8.fsf@email.froward.int.ebiederm.org> <87pmiw1fy6.fsf@email.froward.int.ebiederm.org> <87ilonuti2.fsf_-_@email.froward.int.ebiederm.org> Date: Sun, 26 Jun 2022 14:16:12 -0500 In-Reply-To: <87ilonuti2.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Sun, 26 Jun 2022 14:14:45 -0500") Message-ID: <877d53utfn.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1o5Xk2-008ahI-S9;;;mid=<877d53utfn.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX190SQdd+8R3p3eCZ3mGtEfgajVYGJGF7/E= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: [PATCH 2/3] kthread: Replace kernel_thread with new_kthread X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is desriable to be able to perform all of the kthread setup before the kernel thread is awaked for the first time. To make that possible replace kernel_thread with new_kthread that does all of the same work except it does not call wake_up_new_task. Replace the two uses of kernel_threadd with new_kthread and a call to wake_up_new_task. Signed-off-by: "Eric W. Biederman" --- include/linux/sched/task.h | 2 +- init/main.c | 6 ++---- kernel/fork.c | 4 ++-- kernel/kthread.c | 10 ++++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index d95930e220da..c4c7a0118553 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -91,7 +91,7 @@ extern pid_t kernel_clone(struct kernel_clone_args *kargs= ); struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int nod= e); struct task_struct *fork_idle(int); struct mm_struct *copy_init_mm(void); -extern pid_t kernel_thread(int (*fn)(void *), void *arg); +extern struct task_struct *new_kthread(int (*fn)(void *), void *arg, int n= ode); extern pid_t user_mode_thread(int (*fn)(void *), void *arg, unsigned long = flags); extern long kernel_wait4(pid_t, int __user *, int, struct rusage *); int kernel_wait(pid_t pid, int *stat); diff --git a/init/main.c b/init/main.c index 211d38db0d16..b437581f8001 100644 --- a/init/main.c +++ b/init/main.c @@ -701,10 +701,8 @@ noinline void __ref rest_init(void) rcu_read_unlock(); =20 numa_default_policy(); - pid =3D kernel_thread(kthreadd, NULL); - rcu_read_lock(); - kthreadd_task =3D find_task_by_pid_ns(pid, &init_pid_ns); - rcu_read_unlock(); + kthreadd_task =3D new_kthread(kthreadd, NULL, NUMA_NO_NODE); + wake_up_new_task(kthreadd_task); =20 /* * Enable might_sleep() and smp_processor_id() checks. diff --git a/kernel/fork.c b/kernel/fork.c index 65909ded0ea7..794d9f9c78bc 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2694,7 +2694,7 @@ pid_t kernel_clone(struct kernel_clone_args *args) /* * Create a kernel thread. */ -pid_t kernel_thread(int (*fn)(void *), void *arg) +struct task_struct *new_kthread(int (*fn)(void *), void *arg, int node) { unsigned long flags =3D CLONE_FS | CLONE_FILES | SIGCHLD; struct kernel_clone_args args =3D { @@ -2706,7 +2706,7 @@ pid_t kernel_thread(int (*fn)(void *), void *arg) .kthread =3D 1, }; =20 - return kernel_clone(&args); + return copy_process(NULL, 0, node, &args); } =20 /* diff --git a/kernel/kthread.c b/kernel/kthread.c index c0505e6b7142..8529f6b1582b 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -390,14 +390,14 @@ int tsk_fork_get_node(struct task_struct *tsk) =20 static void create_kthread(struct kthread_create_info *create) { - int pid; + struct task_struct *new; =20 #ifdef CONFIG_NUMA current->pref_node_fork =3D create->node; #endif /* We want our own signal handler (we take no signals by default). */ - pid =3D kernel_thread(kthread, create); - if (pid < 0) { + new =3D new_kthread(kthread, create, NUMA_NO_NODE); + if (IS_ERR(new)) { /* If user was SIGKILLed, I release the structure. */ struct completion *done =3D xchg(&create->done, NULL); =20 @@ -405,8 +405,10 @@ static void create_kthread(struct kthread_create_info = *create) kfree(create); return; } - create->result =3D ERR_PTR(pid); + create->result =3D ERR_CAST(new); complete(done); + } else { + wake_up_new_task(new); } } =20 --=20 2.35.3 From nobody Sun Apr 19 21:59:09 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 F3C57C433EF for ; Sun, 26 Jun 2022 19:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232116AbiFZTQt (ORCPT ); Sun, 26 Jun 2022 15:16:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232055AbiFZTQs (ORCPT ); Sun, 26 Jun 2022 15:16:48 -0400 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44819DF6D for ; Sun, 26 Jun 2022 12:16:47 -0700 (PDT) Received: from in01.mta.xmission.com ([166.70.13.51]:32966) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5XkU-000iu2-92; Sun, 26 Jun 2022 13:16:46 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:57748 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5XkS-00CB82-O0; Sun, 26 Jun 2022 13:16:45 -0600 From: "Eric W. Biederman" To: Linus Torvalds Cc: Christian Brauner , Tejun Heo , Petr Mladek , Lai Jiangshan , Michal Hocko , Linux Kernel Mailing List , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Andrew Morton , Oleg Nesterov References: <20220622140853.31383-1-pmladek@suse.com> <874k0863x8.fsf@email.froward.int.ebiederm.org> <87pmiw1fy6.fsf@email.froward.int.ebiederm.org> <87ilonuti2.fsf_-_@email.froward.int.ebiederm.org> Date: Sun, 26 Jun 2022 14:16:38 -0500 In-Reply-To: <87ilonuti2.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Sun, 26 Jun 2022 14:14:45 -0500") Message-ID: <871qvbutex.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1o5XkS-00CB82-O0;;;mid=<871qvbutex.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX1/Z7b8ZiIIYOiV+Qf5NfLuK0eGYCDcOn/A= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: [PATCH 3/3] kthread: Stop abusing TASK_UNINTERRUPTIBLE (INCOMPLETE) X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead leave the task as a new unscheduled task and require the caller to call wake_up_new_task. Signed-off-by: "Eric W. Biederman" Reported-by: kernel test robot --- arch/arm/common/bL_switcher.c | 2 +- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 4 +- drivers/block/mtip32xx/mtip32xx.c | 2 +- drivers/firmware/psci/psci_checker.c | 2 +- drivers/firmware/stratix10-svc.c | 4 +- drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 2 +- drivers/scsi/bnx2i/bnx2i_init.c | 2 +- drivers/scsi/qedi/qedi_main.c | 2 +- include/linux/kthread.h | 4 +- kernel/bpf/cpumap.c | 2 +- kernel/dma/map_benchmark.c | 2 +- kernel/kthread.c | 114 ++++++++++------------ kernel/smpboot.c | 1 + kernel/workqueue.c | 2 +- net/core/pktgen.c | 2 +- net/sunrpc/svc.c | 2 +- 16 files changed, 72 insertions(+), 77 deletions(-) diff --git a/arch/arm/common/bL_switcher.c b/arch/arm/common/bL_switcher.c index 9a9aa53547a6..15c9841c3c15 100644 --- a/arch/arm/common/bL_switcher.c +++ b/arch/arm/common/bL_switcher.c @@ -311,7 +311,7 @@ static struct task_struct *bL_switcher_thread_create(in= t cpu, void *arg) cpu_to_node(cpu), "kswitcher_%d", cpu); if (!IS_ERR(task)) { kthread_bind(task, cpu); - wake_up_process(task); + wake_up_new_task(task); } else pr_err("%s failed for CPU %d\n", __func__, cpu); return task; diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index db813f819ad6..ba09f5cf1773 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -1206,7 +1206,7 @@ static int pseudo_lock_measure_cycles(struct rdtgroup= *rdtgrp, int sel) goto out; } kthread_bind(thread, cpu); - wake_up_process(thread); + wake_up_new_task(thread); =20 ret =3D wait_event_interruptible(plr->lock_thread_wq, plr->thread_done =3D=3D 1); @@ -1304,7 +1304,7 @@ int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtg= rp) } =20 kthread_bind(thread, plr->cpu); - wake_up_process(thread); + wake_up_new_task(thread); =20 ret =3D wait_event_interruptible(plr->lock_thread_wq, plr->thread_done =3D=3D 1); diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mti= p32xx.c index 27386a572ba4..b2f5b30a27aa 100644 --- a/drivers/block/mtip32xx/mtip32xx.c +++ b/drivers/block/mtip32xx/mtip32xx.c @@ -3649,7 +3649,7 @@ static int mtip_block_initialize(struct driver_data *= dd) rv =3D -EFAULT; goto kthread_run_error; } - wake_up_process(dd->mtip_svc_handler); + wake_up_new_task(dd->mtip_svc_handler); if (wait_for_rebuild =3D=3D MTIP_FTL_REBUILD_MAGIC) rv =3D wait_for_rebuild; =20 diff --git a/drivers/firmware/psci/psci_checker.c b/drivers/firmware/psci/p= sci_checker.c index 116eb465cdb4..52fcd122e2b6 100644 --- a/drivers/firmware/psci/psci_checker.c +++ b/drivers/firmware/psci/psci_checker.c @@ -418,7 +418,7 @@ static int suspend_tests(void) * wait for the completion of suspend_threads_started. */ for (i =3D 0; i < nb_threads; ++i) - wake_up_process(threads[i]); + wake_up_new_task(threads[i]); complete_all(&suspend_threads_started); =20 wait_for_completion(&suspend_threads_done); diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-= svc.c index 14663f671323..64d07aaa68bf 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -581,7 +581,7 @@ static int svc_get_sh_memory(struct platform_device *pd= ev, return -EINVAL; } =20 - wake_up_process(sh_memory_task); + wake_up_new_task(sh_memory_task); =20 if (!wait_for_completion_timeout(&sh_memory->sync_complete, 10 * HZ)) { dev_err(dev, @@ -834,7 +834,7 @@ int stratix10_svc_send(struct stratix10_svc_chan *chan,= void *msg) return -EINVAL; } kthread_bind(chan->ctrl->task, cpu); - wake_up_process(chan->ctrl->task); + wake_up_new_task(chan->ctrl->task); } =20 pr_debug("%s: sent P-va=3D%p, P-com=3D%x, P-size=3D%u\n", __func__, diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc= _fcoe.c index 05ddbb9bb7d8..1b3af0e01d67 100644 --- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c +++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c @@ -2622,7 +2622,7 @@ static int bnx2fc_cpu_online(unsigned int cpu) /* bind thread to the cpu */ kthread_bind(thread, cpu); p->iothread =3D thread; - wake_up_process(thread); + wake_up_new_task(thread); return 0; } =20 diff --git a/drivers/scsi/bnx2i/bnx2i_init.c b/drivers/scsi/bnx2i/bnx2i_ini= t.c index 2b3f0c10478e..cd4976bb86fc 100644 --- a/drivers/scsi/bnx2i/bnx2i_init.c +++ b/drivers/scsi/bnx2i/bnx2i_init.c @@ -424,7 +424,7 @@ static int bnx2i_cpu_online(unsigned int cpu) /* bind thread to the cpu */ kthread_bind(thread, cpu); p->iothread =3D thread; - wake_up_process(thread); + wake_up_new_task(thread); return 0; } =20 diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c index 83ffba7f51da..97ced4f12d6e 100644 --- a/drivers/scsi/qedi/qedi_main.c +++ b/drivers/scsi/qedi/qedi_main.c @@ -1967,7 +1967,7 @@ static int qedi_cpu_online(unsigned int cpu) =20 kthread_bind(thread, cpu); p->iothread =3D thread; - wake_up_process(thread); + wake_up_new_task(thread); return 0; } =20 diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 30e5bec81d2b..fa5e24df84bf 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -53,7 +53,7 @@ bool kthread_is_per_cpu(struct task_struct *k); struct task_struct *__k \ =3D kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ if (!IS_ERR(__k)) \ - wake_up_process(__k); \ + wake_up_new_task(__k); \ __k; \ }) =20 @@ -77,7 +77,7 @@ kthread_run_on_cpu(int (*threadfn)(void *data), void *dat= a, =20 p =3D kthread_create_on_cpu(threadfn, data, cpu, namefmt); if (!IS_ERR(p)) - wake_up_process(p); + wake_up_new_task(p); =20 return p; } diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index f4860ac756cd..e72bbb766f01 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -475,7 +475,7 @@ __cpu_map_entry_alloc(struct bpf_map *map, struct bpf_c= pumap_val *value, =20 /* Make sure kthread runs on a single CPU */ kthread_bind(rcpu->kthread, cpu); - wake_up_process(rcpu->kthread); + wake_up_new_task(rcpu->kthread); =20 return rcpu; =20 diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c index 0520a8f4fb1d..b28e33c07c92 100644 --- a/kernel/dma/map_benchmark.c +++ b/kernel/dma/map_benchmark.c @@ -134,7 +134,7 @@ static int do_map_benchmark(struct map_benchmark_data *= map) =20 for (i =3D 0; i < threads; i++) { get_task_struct(tsk[i]); - wake_up_process(tsk[i]); + wake_up_new_task(tsk[i]); } =20 msleep_interruptible(map->bparam.seconds * 1000); diff --git a/kernel/kthread.c b/kernel/kthread.c index 8529f6b1582b..1769b5118694 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -329,51 +329,12 @@ EXPORT_SYMBOL(kthread_complete_and_exit); =20 static int kthread(void *_create) { - static const struct sched_param param =3D { .sched_priority =3D 0 }; - /* Copy data: it's on kthread's stack */ - struct kthread_create_info *create =3D _create; - int (*threadfn)(void *data) =3D create->threadfn; - void *data =3D create->data; - struct completion *done; - struct kthread *self; - int ret; - - self =3D to_kthread(current); + struct kthread *self =3D to_kthread(current); + int ret =3D -EINTR; =20 - /* If user was SIGKILLed, I release the structure. */ - done =3D xchg(&create->done, NULL); - if (!done) { - kfree(create); - kthread_exit(-EINTR); - } - - self->threadfn =3D threadfn; - self->data =3D data; - - /* - * The new thread inherited kthreadd's priority and CPU mask. Reset - * back to default in case they have been changed. - */ - sched_setscheduler_nocheck(current, SCHED_NORMAL, ¶m); - set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_TYPE_KTHREAD)); - - /* OK, tell user we're spawned, wait for stop or wakeup */ - __set_current_state(TASK_UNINTERRUPTIBLE); - create->result =3D current; - /* - * Thread is going to call schedule(), do not preempt it, - * or the creator may spend more time in wait_task_inactive(). - */ - preempt_disable(); - complete(done); - schedule_preempt_disabled(); - preempt_enable(); - - ret =3D -EINTR; if (!test_bit(KTHREAD_SHOULD_STOP, &self->flags)) { cgroup_kthread_ready(); - __kthread_parkme(self); - ret =3D threadfn(data); + ret =3D self->threadfn(self->data); } kthread_exit(ret); } @@ -391,25 +352,41 @@ int tsk_fork_get_node(struct task_struct *tsk) static void create_kthread(struct kthread_create_info *create) { struct task_struct *new; + struct completion *done; =20 #ifdef CONFIG_NUMA current->pref_node_fork =3D create->node; #endif /* We want our own signal handler (we take no signals by default). */ new =3D new_kthread(kthread, create, NUMA_NO_NODE); + create->result =3D new; + /* Claim the completion */ + done =3D xchg(&create->done, NULL); if (IS_ERR(new)) { - /* If user was SIGKILLed, I release the structure. */ - struct completion *done =3D xchg(&create->done, NULL); + if (done) + complete(done); + } else if (done) { + static const struct sched_param param =3D { .sched_priority =3D 0 }; + struct kthread *kthread =3D to_kthread(new); =20 - if (!done) { - kfree(create); - return; - } - create->result =3D ERR_CAST(new); - complete(done); - } else { - wake_up_new_task(new); + kthread->threadfn =3D create->threadfn; + kthread->data =3D create->data; + + /* + * The new thread inherited kthreadd's priority and CPU mask. Reset + * back to default in case they have been changed. + */ + sched_setscheduler_nocheck(new, SCHED_NORMAL, ¶m); + set_cpus_allowed_ptr(new, housekeeping_cpumask(HK_TYPE_KTHREAD)); + + /* OK, tell user we're spawned, wait for stop or wakeup */ + //wake_up_new_task(new); } + /* If user was SIGKILLed, release the structure. */ + if (!done) + kfree(create); + else + complete(done); } =20 static __printf(4, 0) @@ -518,11 +495,11 @@ struct task_struct *kthread_create_on_node(int (*thre= adfn)(void *data), } EXPORT_SYMBOL(kthread_create_on_node); =20 -static void __kthread_bind_mask(struct task_struct *p, const struct cpumas= k *mask, unsigned int state) +static void kthread_bind_mask_parked(struct task_struct *p, const struct c= pumask *mask) { unsigned long flags; =20 - if (!wait_task_inactive(p, state)) { + if (!wait_task_inactive(p, TASK_PARKED)) { WARN_ON(1); return; } @@ -534,14 +511,31 @@ static void __kthread_bind_mask(struct task_struct *p= , const struct cpumask *mas raw_spin_unlock_irqrestore(&p->pi_lock, flags); } =20 -static void __kthread_bind(struct task_struct *p, unsigned int cpu, unsign= ed int state) +static void kthread_bind_mask_new(struct task_struct *new, const struct cp= umask *mask) +{ + unsigned long flags; + + /* + * FIXME: verify that p is a new task that + * has not yet been passed through + * wake_up_new_task + */ + + /* It's safe because new has never been scheduled. */ + raw_spin_lock_irqsave(&new->pi_lock, flags); + do_set_cpus_allowed(new, mask); + new->flags |=3D PF_NO_SETAFFINITY; + raw_spin_unlock_irqrestore(&new->pi_lock, flags); +} + +static void __kthread_bind(struct task_struct *p, unsigned int cpu) { - __kthread_bind_mask(p, cpumask_of(cpu), state); + kthread_bind_mask_new(p, cpumask_of(cpu)); } =20 void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask) { - __kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE); + kthread_bind_mask_new(p, mask); } =20 /** @@ -555,7 +549,7 @@ void kthread_bind_mask(struct task_struct *p, const str= uct cpumask *mask) */ void kthread_bind(struct task_struct *p, unsigned int cpu) { - __kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE); + __kthread_bind(p, cpu); } EXPORT_SYMBOL(kthread_bind); =20 @@ -629,7 +623,7 @@ void kthread_unpark(struct task_struct *k) * The binding was lost and we need to set it again. */ if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags)) - __kthread_bind(k, kthread->cpu, TASK_PARKED); + kthread_bind_mask_parked(k, cpumask_of(kthread->cpu)); =20 clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags); /* @@ -863,7 +857,7 @@ __kthread_create_worker(int cpu, unsigned int flags, =20 worker->flags =3D flags; worker->task =3D task; - wake_up_process(task); + wake_up_new_task(task); return worker; =20 fail_task: diff --git a/kernel/smpboot.c b/kernel/smpboot.c index b9f54544e749..79b8d05164d6 100644 --- a/kernel/smpboot.c +++ b/kernel/smpboot.c @@ -192,6 +192,7 @@ __smpboot_create_thread(struct smp_hotplug_thread *ht, = unsigned int cpu) * Park the thread so that it could start right on the CPU * when it is available. */ + wake_up_new_task(tsk); kthread_park(tsk); get_task_struct(tsk); *per_cpu_ptr(ht->store, cpu) =3D tsk; diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 1ea50f6be843..2d16a933f452 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1961,7 +1961,7 @@ static struct worker *create_worker(struct worker_poo= l *pool) raw_spin_lock_irq(&pool->lock); worker->pool->nr_workers++; worker_enter_idle(worker); - wake_up_process(worker->task); + wake_up_new_task(worker->task); raw_spin_unlock_irq(&pool->lock); =20 return worker; diff --git a/net/core/pktgen.c b/net/core/pktgen.c index 84b62cd7bc57..40efd9b678fa 100644 --- a/net/core/pktgen.c +++ b/net/core/pktgen.c @@ -3864,7 +3864,7 @@ static int __net_init pktgen_create_thread(int cpu, s= truct pktgen_net *pn) =20 t->net =3D pn; get_task_struct(p); - wake_up_process(p); + wake_up_new_task(p); wait_for_completion(&t->start_done); =20 return 0; diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 7c9a0d0b1230..addbba323b9c 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -769,7 +769,7 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_po= ol *pool, int nrservs) svc_pool_map_set_cpumask(task, chosen_pool->sp_id); =20 svc_sock_update_bufs(serv); - wake_up_process(task); + wake_up_new_task(task); } while (nrservs > 0); =20 return 0; --=20 2.35.3