Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2282706pxb; Fri, 17 Sep 2021 06:28:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzn9s5UouNVUyKt651WGh2+i7QHsYPwVBLjQmYcNxbhf2PZHgN/R+7NRMv5iPjrh3fnTGd X-Received: by 2002:a05:600c:4154:: with SMTP id h20mr15013900wmm.172.1631885298870; Fri, 17 Sep 2021 06:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631885298; cv=none; d=google.com; s=arc-20160816; b=h07evpEGHn+oXXJSHuYRZENzqjDVAt5qkfPLTmbU9DptaPKlX5/qPf+WmN8ncWVY79 6r7PO6C9GDVQDDLyEl2WnYzY+nEHu8TOjxebP+XzPnXYakxDY0GEfhHm6QnlYPP3rSpu gfZFPsdxi7SVHeb+1RkmDe8gw9cg2uvYLmtq8yqx0ZPG+5rdU2Zch5nFiO/FUgMhAtoy 3xC6F9NoN3e2Vq6hBjrm7S3qs0zgfUuaXFf5Ei4kSA4Fj98uJ787477g+hoticC4ljhI fxNk08G/DIXkZSQKGfJMjum1+ulN0axlX6h6E0rmI20g05iKxH+9wCf7icVaYucbWa3K BofA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=INod6AcrKuqAMeSED7TErShibq808t51j6RGCJf3PKM=; b=HOR8AbfXlX1HfUf1m7GmQBBd3JBK18ulKsp03b4lXHi0bHyv4TTQ3+GHDbPNwZkXKJ bSYCVoRqHRiq9wNN6MVQh/TJN7OKKt+pSbHyMyhMyb1J34arBLSyiJ9MqL4oyBzkhX2/ AaTRyxTIwPaxf3N0NgXv+Wcek6IMpwfYn2Mfk7hWvyIxB/9toBhxv3FCc7S40mXm14ro /9qu6147yIkEBYJcG0DVBpriLvlsvFJ6m3+ScSgq5WEe8PITGblz6dDwKaSUHwYXx20y AugjCsp/RiZ6RNZwS1x9bjz884meo17rt0GDGEsuv6qRJQtQ7+VzXEHy6jNXAJl6GVsI bfqA== 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 z9si7351979edp.633.2021.09.17.06.27.54; Fri, 17 Sep 2021 06:28:18 -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 S245505AbhIQItl (ORCPT + 99 others); Fri, 17 Sep 2021 04:49:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:54510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235322AbhIQItk (ORCPT ); Fri, 17 Sep 2021 04:49:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 66B796112E; Fri, 17 Sep 2021 08:48:17 +0000 (UTC) Date: Fri, 17 Sep 2021 10:48:15 +0200 From: Christian Brauner To: Mike Christie Cc: stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, axboe@kernel.dk, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/8] fork: add helper to clone a process Message-ID: <20210917084815.audgjc4q6wcbirwp@wittgenstein> References: <20210916212051.6918-1-michael.christie@oracle.com> <20210916212051.6918-2-michael.christie@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210916212051.6918-2-michael.christie@oracle.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 16, 2021 at 04:20:44PM -0500, Mike Christie wrote: > The vhost layer has similar requirements as io_uring where its worker > threads need to access the userspace thread's memory, want to inherit the > parents's cgroups and namespaces, and be checked against the parent's > RLIMITs. Right now, the vhost layer uses the kthread API which has > kthread_use_mm for mem access, and those threads can use > cgroup_attach_task_all for v1 cgroups, but there are no helpers for the > other items. > > This adds a helper to clone a process so we can inherit everything we > want in one call. It's a more generic version of create_io_thread which > will be used by the vhost layer and io_uring in later patches in this set. > > This patch also exports __set_task_comm and wake_up_new_task which is > needed by modules to use the new helper. io_uring calls these functions > already but its always built into the kernel so was not needed before. > > Signed-off-by: Mike Christie > --- > fs/exec.c | 7 +++++++ > include/linux/sched/task.h | 3 +++ > kernel/fork.c | 29 +++++++++++++++++++++++++++++ > kernel/sched/core.c | 4 +++- > 4 files changed, 42 insertions(+), 1 deletion(-) > > diff --git a/fs/exec.c b/fs/exec.c > index a098c133d8d7..9fc4bb0c5c7e 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -1220,6 +1220,12 @@ EXPORT_SYMBOL_GPL(__get_task_comm); > * so that a new one can be started > */ > > +/** > + * __set_task_comm - set the task's executable name > + * @tsk: task_struct to modify > + * @buf: executable name > + * @exec: true if called during a process exec. false for name changes. > + */ > void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) > { > task_lock(tsk); > @@ -1228,6 +1234,7 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec) > task_unlock(tsk); > perf_event_comm(tsk, exec); > } > +EXPORT_SYMBOL_GPL(__set_task_comm); > > /* > * Calling this is the point of no return. None of the failures will be > diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h > index ef02be869cf2..c55f1eb69d41 100644 > --- a/include/linux/sched/task.h > +++ b/include/linux/sched/task.h > @@ -84,6 +84,9 @@ extern void exit_itimers(struct signal_struct *); > > extern pid_t kernel_clone(struct kernel_clone_args *kargs); > struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node); > +struct task_struct *kernel_copy_process(int (*fn)(void *), void *arg, int node, > + unsigned long clone_flags, > + int io_thread); > 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 38681ad44c76..cec7b6011beb 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -2532,6 +2532,35 @@ struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node) > return copy_process(NULL, 0, node, &args); > } > > +/** > + * kernel_copy_process - create a copy of a process to be used by the kernel > + * @fn: thread stack > + * @arg: data to be passed to fn > + * @node: numa node to allocate task from > + * @clone_flags: CLONE flags > + * @io_thread: 1 if this will be a PF_IO_WORKER else 0. > + * > + * This returns a created task, or an error pointer. The returned task is > + * inactive, and the caller must fire it up through wake_up_new_task(p). If > + * this is an PF_IO_WORKER all singals but KILL and STOP are blocked. > + */ > +struct task_struct *kernel_copy_process(int (*fn)(void *), void *arg, int node, > + unsigned long clone_flags, > + int io_thread) Hm, not excited about the name. I think kernel_worker_create() or simply kernel_worker() is better.