Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp371920pxa; Wed, 19 Aug 2020 03:53:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsRIYsF7Goi5HzuT/kr6JciM00OBl1QBGR+EOpExREXB6qqiMOXcR1PRQWAt1r6F0ejwoL X-Received: by 2002:aa7:c983:: with SMTP id c3mr23621002edt.383.1597834435078; Wed, 19 Aug 2020 03:53:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597834435; cv=none; d=google.com; s=arc-20160816; b=r1RE9UQVcAuX6pbCWWqMUeXyN0L/fWHT0vLr0S+UomW8enXQ3LtATQqYBwuMDgJvmu 5gExZLhrFzKYWIL7+wbtE0T58cvzewCQjstWnhtfG9olitutxGd37HDskoATkknRIxe3 CLXX4bxDNhPFq5Z/T3mWXlhPC1Z575nZDf3Mu7WgFD2qqwnt1y2tI/GhENdytOj6ed8w VcbggCLl/zGpDGddrQPSLoGnyEvdqTf2TwMaxwebjeYotXkUfcnPrBRyabbrhqqUFQF5 NFMjdZNt9h1G6ozK8OekT9vbbIDD+eZpaAJ1hRVNtLvJjJ9fqMk5vq27NDqwcO8rE4pg Tptw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/x0JNQaU7GbFCdIGlD9ebtPhlJ42Ij+S9ofYz96BbKc=; b=LZUYPuX1YVawMN1y6TolMPTQB6pzDMSjgK/EyLuIaMCmtEboKihkI7UgsgChsjS9Zh N2sbZ39k1zQJyUZRLoV54fcZpzskFs2pJnitfMZOXOC8ahdC6etZ8v4668WLwWU5sCh8 AcU6gvGLwQZCPUs3xXOmYyAEym7NssulGLYcdNp3YrokOW0IcbycpZk0zqzaWeTVPFK1 QFsfzh4LQksAwQJgMV/ErRuypM0uaZqvgXByElirQhomtU/Isvtxgg2pKcx3DTn+zSoZ 823OJmF68W/Iwzhm7PRe6sBvNx9ik7931MWz5YvSVJV9ZlxINgdTT8jWdlUjCexQiuj7 2guA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si15084625eja.112.2020.08.19.03.53.31; Wed, 19 Aug 2020 03:53:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728219AbgHSKu2 (ORCPT + 99 others); Wed, 19 Aug 2020 06:50:28 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53971 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726642AbgHSKra (ORCPT ); Wed, 19 Aug 2020 06:47:30 -0400 Received: from ip5f5af70b.dynamic.kabel-deutschland.de ([95.90.247.11] helo=wittgenstein.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k8Lcq-0006IE-KO; Wed, 19 Aug 2020 10:47:24 +0000 From: Christian Brauner To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Corbet , Yoshinori Sato , Tony Luck , Fenghua Yu , Geert Uytterhoeven , Ley Foon Tan , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Arnd Bergmann , Steven Rostedt , Stafford Horne , Peter Zijlstra , Kars de Jong , Kees Cook , Greentime Hu , "Eric W. Biederman" , Mauro Carvalho Chehab , Alexandre Chartre , Masami Hiramatsu , Tom Zanussi , Xiao Yang , linux-doc@vger.kernel.org, uclinux-h8-devel@lists.sourceforge.jp, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, sparclinux@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, linux-kselftest@vger.kernel.org, Linus Torvalds , Christoph Hewllig , Matthew Wilcox , Christian Brauner , Ingo Molnar Subject: [PATCH v2 01/11] fork: introduce kernel_clone() Date: Wed, 19 Aug 2020 12:46:45 +0200 Message-Id: <20200819104655.436656-2-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200819104655.436656-1-christian.brauner@ubuntu.com> References: <20200819104655.436656-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The old _do_fork() helper doesn't follow naming conventions of in-kernel helpers for syscalls. The process creation cleanup in [1] didn't change the name to something more reasonable mainly because _do_fork() was used in quite a few places. So sending this as a separate series seemed the better strategy. This commit does two things: 1. renames _do_fork() to kernel_clone() but keeps _do_fork() as a simple static inline wrapper around kernel_clone(). 2. Changes the return type from long to pid_t. This aligns kernel_thread() and kernel_clone(). Also, the return value from kernel_clone that is surfaced in fork(), vfork(), clone(), and clone3() is taken from pid_vrn() which returns a pid_t too. Follow-up patches will switch each caller of _do_fork() and each place where it is referenced over to kernel_clone(). After all these changes are done, we can remove _do_fork() completely and will only be left with kernel_clone(). [1]: 9ba27414f2ec ("Merge tag 'fork-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux") Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Matthew Wilcox (Oracle) Cc: "Peter Zijlstra (Intel)" Signed-off-by: Christian Brauner --- /* v2 */ - Matthew Wilcox (Oracle) : - make kernel_clone() return pid_t --- include/linux/sched/task.h | 6 +++++- kernel/fork.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index a98965007eef..d4428039c3c1 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -83,7 +83,11 @@ extern void do_group_exit(int); extern void exit_files(struct task_struct *); extern void exit_itimers(struct signal_struct *); -extern long _do_fork(struct kernel_clone_args *kargs); +extern pid_t kernel_clone(struct kernel_clone_args *kargs); +static inline long _do_fork(struct kernel_clone_args *kargs) +{ + return kernel_clone(kargs); +} 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 flags); diff --git a/kernel/fork.c b/kernel/fork.c index 4d32190861bd..d822c7a4b9c4 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2384,14 +2384,14 @@ struct mm_struct *copy_init_mm(void) * * args->exit_signal is expected to be checked for sanity by the caller. */ -long _do_fork(struct kernel_clone_args *args) +pid_t kernel_clone(struct kernel_clone_args *args) { u64 clone_flags = args->flags; struct completion vfork; struct pid *pid; struct task_struct *p; int trace = 0; - long nr; + pid_t nr; /* * For legacy clone() calls, CLONE_PIDFD uses the parent_tid argument @@ -2477,7 +2477,7 @@ pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags) .stack_size = (unsigned long)arg, }; - return _do_fork(&args); + return kernel_clone(&args); } #ifdef __ARCH_WANT_SYS_FORK @@ -2488,7 +2488,7 @@ SYSCALL_DEFINE0(fork) .exit_signal = SIGCHLD, }; - return _do_fork(&args); + return kernel_clone(&args); #else /* can not support in nommu mode */ return -EINVAL; @@ -2504,7 +2504,7 @@ SYSCALL_DEFINE0(vfork) .exit_signal = SIGCHLD, }; - return _do_fork(&args); + return kernel_clone(&args); } #endif @@ -2542,7 +2542,7 @@ SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp, .tls = tls, }; - return _do_fork(&args); + return kernel_clone(&args); } #endif @@ -2700,7 +2700,7 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size) if (!clone3_args_valid(&kargs)) return -EINVAL; - return _do_fork(&kargs); + return kernel_clone(&kargs); } #endif @@ -2863,7 +2863,7 @@ int unshare_fd(unsigned long unshare_flags, unsigned int max_fds, /* * unshare allows a process to 'unshare' part of the process * context which was originally shared using clone. copy_* - * functions used by _do_fork() cannot be used here directly + * functions used by kernel_clone() cannot be used here directly * because they modify an inactive task_struct that is being * constructed. Here we are modifying the current, active, * task_struct. -- 2.28.0