exit/kthread: Move the exit code for kernel threads into struct kthread
authorEric W. Biederman <ebiederm@xmission.com>
Fri, 3 Dec 2021 17:42:49 +0000 (11:42 -0600)
committerEric W. Biederman <ebiederm@xmission.com>
Mon, 13 Dec 2021 18:04:46 +0000 (12:04 -0600)
The exit code of kernel threads has different semantics than the
exit_code of userspace tasks.  To avoid confusion and allow
the userspace implementation to change as needed move
the kernel thread exit code into struct kthread.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
kernel/kthread.c

index 8e5f44bed02739d4334443ce482ea399742d6d85..9c6c532047c4f2886ab12a2a9ec5ff47ebd20c4e 100644 (file)
@@ -52,6 +52,7 @@ struct kthread_create_info
 struct kthread {
        unsigned long flags;
        unsigned int cpu;
+       int result;
        int (*threadfn)(void *);
        void *data;
        mm_segment_t oldfs;
@@ -287,7 +288,9 @@ EXPORT_SYMBOL_GPL(kthread_parkme);
  */
 void __noreturn kthread_exit(long result)
 {
-       do_exit(result);
+       struct kthread *kthread = to_kthread(current);
+       kthread->result = result;
+       do_exit(0);
 }
 
 /**
@@ -679,7 +682,7 @@ int kthread_stop(struct task_struct *k)
        kthread_unpark(k);
        wake_up_process(k);
        wait_for_completion(&kthread->exited);
-       ret = k->exit_code;
+       ret = kthread->result;
        put_task_struct(k);
 
        trace_sched_kthread_stop_ret(ret);