fork.c (a7d24d9582f8cc24fabd11c458950ac94710566a) fork.c (cc440e8738e5c875297ac0e90316745093be7e28)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/kernel/fork.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 */
7
8/*

--- 82 unchanged lines hidden (view full) ---

91#include <linux/sysctl.h>
92#include <linux/kcov.h>
93#include <linux/livepatch.h>
94#include <linux/thread_info.h>
95#include <linux/stackleak.h>
96#include <linux/kasan.h>
97#include <linux/scs.h>
98#include <linux/io_uring.h>
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * linux/kernel/fork.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 */
7
8/*

--- 82 unchanged lines hidden (view full) ---

91#include <linux/sysctl.h>
92#include <linux/kcov.h>
93#include <linux/livepatch.h>
94#include <linux/thread_info.h>
95#include <linux/stackleak.h>
96#include <linux/kasan.h>
97#include <linux/scs.h>
98#include <linux/io_uring.h>
99#include <linux/bpf.h>
100
101#include <asm/pgalloc.h>
102#include <linux/uaccess.h>
103#include <asm/mmu_context.h>
104#include <asm/cacheflush.h>
105#include <asm/tlbflush.h>
106
107#include <trace/events/sched.h>

--- 622 unchanged lines hidden (view full) ---

730 WARN_ON(!tsk->exit_state);
731 WARN_ON(refcount_read(&tsk->usage));
732 WARN_ON(tsk == current);
733
734 io_uring_free(tsk);
735 cgroup_free(tsk);
736 task_numa_free(tsk, true);
737 security_task_free(tsk);
99
100#include <asm/pgalloc.h>
101#include <linux/uaccess.h>
102#include <asm/mmu_context.h>
103#include <asm/cacheflush.h>
104#include <asm/tlbflush.h>
105
106#include <trace/events/sched.h>

--- 622 unchanged lines hidden (view full) ---

729 WARN_ON(!tsk->exit_state);
730 WARN_ON(refcount_read(&tsk->usage));
731 WARN_ON(tsk == current);
732
733 io_uring_free(tsk);
734 cgroup_free(tsk);
735 task_numa_free(tsk, true);
736 security_task_free(tsk);
738 bpf_task_storage_free(tsk);
739 exit_creds(tsk);
740 delayacct_tsk_free(tsk);
741 put_signal_struct(tsk->signal);
742
743 if (!profile_handoff_task(tsk))
744 free_task(tsk);
745}
746EXPORT_SYMBOL_GPL(__put_task_struct);

--- 1190 unchanged lines hidden (view full) ---

1937 retval = -ERESTARTNOINTR;
1938 if (signal_pending(current))
1939 goto fork_out;
1940
1941 retval = -ENOMEM;
1942 p = dup_task_struct(current, node);
1943 if (!p)
1944 goto fork_out;
737 exit_creds(tsk);
738 delayacct_tsk_free(tsk);
739 put_signal_struct(tsk->signal);
740
741 if (!profile_handoff_task(tsk))
742 free_task(tsk);
743}
744EXPORT_SYMBOL_GPL(__put_task_struct);

--- 1190 unchanged lines hidden (view full) ---

1935 retval = -ERESTARTNOINTR;
1936 if (signal_pending(current))
1937 goto fork_out;
1938
1939 retval = -ENOMEM;
1940 p = dup_task_struct(current, node);
1941 if (!p)
1942 goto fork_out;
1943 if (args->io_thread)
1944 p->flags |= PF_IO_WORKER;
1945
1946 /*
1947 * This _must_ happen before we call free_task(), i.e. before we jump
1948 * to any of the bad_fork_* labels. This is to avoid freeing
1949 * p->set_child_tid which is (ab)used as a kthread's data pointer for
1950 * kernel threads (PF_KTHREAD).
1951 */
1952 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? args->child_tid : NULL;

--- 106 unchanged lines hidden (view full) ---

2059
2060#ifdef CONFIG_DEBUG_MUTEXES
2061 p->blocked_on = NULL; /* not blocked yet */
2062#endif
2063#ifdef CONFIG_BCACHE
2064 p->sequential_io = 0;
2065 p->sequential_io_avg = 0;
2066#endif
1945
1946 /*
1947 * This _must_ happen before we call free_task(), i.e. before we jump
1948 * to any of the bad_fork_* labels. This is to avoid freeing
1949 * p->set_child_tid which is (ab)used as a kthread's data pointer for
1950 * kernel threads (PF_KTHREAD).
1951 */
1952 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? args->child_tid : NULL;

--- 106 unchanged lines hidden (view full) ---

2059
2060#ifdef CONFIG_DEBUG_MUTEXES
2061 p->blocked_on = NULL; /* not blocked yet */
2062#endif
2063#ifdef CONFIG_BCACHE
2064 p->sequential_io = 0;
2065 p->sequential_io_avg = 0;
2066#endif
2067#ifdef CONFIG_BPF_SYSCALL
2068 RCU_INIT_POINTER(p->bpf_storage, NULL);
2069#endif
2070
2071 /* Perform scheduler related setup. Assign this task to a CPU. */
2072 retval = sched_fork(clone_flags, p);
2073 if (retval)
2074 goto bad_fork_cleanup_policy;
2075
2076 retval = perf_event_init_task(p);
2077 if (retval)

--- 333 unchanged lines hidden (view full) ---

2411}
2412
2413struct mm_struct *copy_init_mm(void)
2414{
2415 return dup_mm(NULL, &init_mm);
2416}
2417
2418/*
2067
2068 /* Perform scheduler related setup. Assign this task to a CPU. */
2069 retval = sched_fork(clone_flags, p);
2070 if (retval)
2071 goto bad_fork_cleanup_policy;
2072
2073 retval = perf_event_init_task(p);
2074 if (retval)

--- 333 unchanged lines hidden (view full) ---

2408}
2409
2410struct mm_struct *copy_init_mm(void)
2411{
2412 return dup_mm(NULL, &init_mm);
2413}
2414
2415/*
2416 * This is like kernel_clone(), but shaved down and tailored to just
2417 * creating io_uring workers. It returns a created task, or an error pointer.
2418 * The returned task is inactive, and the caller must fire it up through
2419 * wake_up_new_task(p). All signals are blocked in the created task.
2420 */
2421struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node)
2422{
2423 unsigned long flags = CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|
2424 CLONE_IO;
2425 struct kernel_clone_args args = {
2426 .flags = ((lower_32_bits(flags) | CLONE_VM |
2427 CLONE_UNTRACED) & ~CSIGNAL),
2428 .exit_signal = (lower_32_bits(flags) & CSIGNAL),
2429 .stack = (unsigned long)fn,
2430 .stack_size = (unsigned long)arg,
2431 .io_thread = 1,
2432 };
2433 struct task_struct *tsk;
2434
2435 tsk = copy_process(NULL, 0, node, &args);
2436 if (!IS_ERR(tsk)) {
2437 sigfillset(&tsk->blocked);
2438 sigdelsetmask(&tsk->blocked, sigmask(SIGKILL));
2439 }
2440 return tsk;
2441}
2442
2443/*
2419 * Ok, this is the main fork-routine.
2420 *
2421 * It copies the process, and if successful kick-starts
2422 * it and waits for it to finish using the VM if required.
2423 *
2424 * args->exit_signal is expected to be checked for sanity by the caller.
2425 */
2426pid_t kernel_clone(struct kernel_clone_args *args)

--- 650 unchanged lines hidden ---
2444 * Ok, this is the main fork-routine.
2445 *
2446 * It copies the process, and if successful kick-starts
2447 * it and waits for it to finish using the VM if required.
2448 *
2449 * args->exit_signal is expected to be checked for sanity by the caller.
2450 */
2451pid_t kernel_clone(struct kernel_clone_args *args)

--- 650 unchanged lines hidden ---