Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCD1EC433EF for ; Fri, 17 Dec 2021 19:02:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240491AbhLQTCC (ORCPT ); Fri, 17 Dec 2021 14:02:02 -0500 Received: from out01.mta.xmission.com ([166.70.13.231]:43396 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235807AbhLQTCB (ORCPT ); Fri, 17 Dec 2021 14:02:01 -0500 Received: from in01.mta.xmission.com ([166.70.13.51]:58054) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1myIUR-00FfBf-I2; Fri, 17 Dec 2021 12:01:59 -0700 Received: from ip68-227-161-49.om.om.cox.net ([68.227.161.49]:42796 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1myIUQ-004HxV-4I; Fri, 17 Dec 2021 12:01:59 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Mike Christie Cc: geert@linux-m68k.org, vverma@digitalocean.com, hdanton@sina.com, hch@infradead.org, stefanha@redhat.com, jasowang@redhat.com, mst@redhat.com, sgarzare@redhat.com, virtualization@lists.linux-foundation.org, christian.brauner@ubuntu.com, axboe@kernel.dk, linux-kernel@vger.kernel.org, Christoph Hellwig References: <20211129194707.5863-1-michael.christie@oracle.com> <20211129194707.5863-11-michael.christie@oracle.com> Date: Fri, 17 Dec 2021 13:01:51 -0600 In-Reply-To: <20211129194707.5863-11-michael.christie@oracle.com> (Mike Christie's message of "Mon, 29 Nov 2021 13:47:07 -0600") Message-ID: <87bl1fcaxs.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1myIUQ-004HxV-4I;;;mid=<87bl1fcaxs.fsf@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.161.49;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19b9elxsYumUcbq/GZ1o040CaaHOg07k30= X-SA-Exim-Connect-IP: 68.227.161.49 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH V6 10/10] vhost: use user_worker to check RLIMITs X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Mike Christie writes: > For vhost workers we use the kthread API which inherit's its values from > and checks against the kthreadd thread. This results in the wrong RLIMITs > being checked. This patch has us use the user_worker helpers which will > inherit its values/checks from the thread that owns the device similar to > if we did a clone in userspace. > > Signed-off-by: Mike Christie > Acked-by: Michael S. Tsirkin > Reviewed-by: Christoph Hellwig > --- > drivers/vhost/vhost.c | 65 +++++++++++++++---------------------------- > drivers/vhost/vhost.h | 7 ++++- > 2 files changed, 28 insertions(+), 44 deletions(-) > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index c9a1f706989c..8cf259d798c0 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -22,7 +22,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -344,17 +343,14 @@ static void vhost_vq_reset(struct vhost_dev *dev, > static int vhost_worker(void *data) > { > struct vhost_worker *worker = data; > - struct vhost_dev *dev = worker->dev; > struct vhost_work *work, *work_next; > struct llist_node *node; > > - kthread_use_mm(dev->mm); > - > for (;;) { > /* mb paired w/ kthread_stop */ > set_current_state(TASK_INTERRUPTIBLE); > > - if (kthread_should_stop()) { > + if (test_bit(VHOST_WORKER_FLAG_STOP, &worker->flags)) { > __set_current_state(TASK_RUNNING); > break; > } > @@ -376,8 +372,9 @@ static int vhost_worker(void *data) > schedule(); > } > } > - kthread_unuse_mm(dev->mm); > - return 0; > + > + complete(worker->exit_done); > + do_exit(0); This code worries me. It has the potential for a caller to do: vhost_worker_stop() module_put(); Then the exiting work thread tries to do: do_exit() Except the code that calls do_exit has already been removed from the kernel. Maybe the vhost code can never be removed from the kernel but otherwise I expect that is possible. Eric