Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

exit: Implement kthread_exit

The way the per task_struct exit_code is used by kernel threads is not
quite compatible how it is used by userspace applications. The low
byte of the userspace exit_code value encodes the exit signal. While
kthreads just use the value as an int holding ordinary kernel function
exit status like -EPERM.

Add kthread_exit to clearly separate the two kinds of uses.

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

+21 -4
+1
include/linux/kthread.h
··· 70 70 int kthread_park(struct task_struct *k); 71 71 void kthread_unpark(struct task_struct *k); 72 72 void kthread_parkme(void); 73 + void kthread_exit(long result) __noreturn; 73 74 74 75 int kthreadd(void *unused); 75 76 extern struct task_struct *kthreadd_task;
+19 -4
kernel/kthread.c
··· 268 268 } 269 269 EXPORT_SYMBOL_GPL(kthread_parkme); 270 270 271 + /** 272 + * kthread_exit - Cause the current kthread return @result to kthread_stop(). 273 + * @result: The integer value to return to kthread_stop(). 274 + * 275 + * While kthread_exit can be called directly, it exists so that 276 + * functions which do some additional work in non-modular code such as 277 + * module_put_and_kthread_exit can be implemented. 278 + * 279 + * Does not return. 280 + */ 281 + void __noreturn kthread_exit(long result) 282 + { 283 + do_exit(result); 284 + } 285 + 271 286 static int kthread(void *_create) 272 287 { 273 288 static const struct sched_param param = { .sched_priority = 0 }; ··· 301 286 done = xchg(&create->done, NULL); 302 287 if (!done) { 303 288 kfree(create); 304 - do_exit(-EINTR); 289 + kthread_exit(-EINTR); 305 290 } 306 291 307 292 if (!self) { 308 293 create->result = ERR_PTR(-ENOMEM); 309 294 complete(done); 310 - do_exit(-ENOMEM); 295 + kthread_exit(-ENOMEM); 311 296 } 312 297 313 298 self->threadfn = threadfn; ··· 341 326 __kthread_parkme(self); 342 327 ret = threadfn(data); 343 328 } 344 - do_exit(ret); 329 + kthread_exit(ret); 345 330 } 346 331 347 332 /* called from kernel_clone() to get node information for about to be created task */ ··· 642 627 * instead of calling wake_up_process(): the thread will exit without 643 628 * calling threadfn(). 644 629 * 645 - * If threadfn() may call do_exit() itself, the caller must ensure 630 + * If threadfn() may call kthread_exit() itself, the caller must ensure 646 631 * task_struct can't go away. 647 632 * 648 633 * Returns the result of threadfn(), or %-EINTR if wake_up_process()
+1
tools/objtool/check.c
··· 168 168 "panic", 169 169 "do_exit", 170 170 "do_task_dead", 171 + "kthread_exit", 171 172 "make_task_dead", 172 173 "__module_put_and_exit", 173 174 "complete_and_exit",