From patchwork Mon Dec 30 12:43:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13923250 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37A881A8F6B for ; Mon, 30 Dec 2024 12:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562711; cv=none; b=UeU9sxUy354TplgLRYtyGHVCC8sraphotAGFojM++iwTFeJLFiN0CZtKEKacof+A5EB0kCJ1ltQ1haM5QtECXlaTXQ4X9/ga9s7mUvNwEBv/Xe2F6qfyl6/4ZO+mnRldMRyp+DfT9uOu73b08WjpQ3xNoP47uBX+ILnujd/VJNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562711; c=relaxed/simple; bh=jeWjZGyVq++I2IUyvncBX3PW15I/qkhjeCkZYe2n4iM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GbyRAqWzDr7cpB1FbeGb1BzRlEbvjUOIvmTwQKxkWHdKCXHDsvodoKVgCLnv1FEEmrOEpr544XE+bblJJw1otdHugD9BWDr8cx73FzaiAQTkjRzapSS4rX/9qHi6Wr4Yjz1zHcYi7ABUHl7xSrMtQkbPqDwvEuyZNpcDmQKhZnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TBk5lw4C; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TBk5lw4C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562709; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UMBEQFgZfioBrCNsFkZVI/KneYN1UfIwkiutolEo20E=; b=TBk5lw4CUc3E0mmZUEJuthRJWT5Egmd3V4ZR7sZHHz2DYZN2/H9FZBSAHvt6lFVXgdKOhB KjKsVQ/vtO6hBc++7ipW2DDI+msysvQ/J7u7K2V8WIv2JYPqwqTHIJ9ga6PpEJhNoIwiXy uouAfR26HmMvP14bKSk4x8NKfsJTGoY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-484-ziJisQehMaCGzvhRWamPew-1; Mon, 30 Dec 2024 07:45:04 -0500 X-MC-Unique: ziJisQehMaCGzvhRWamPew-1 X-Mimecast-MFC-AGG-ID: ziJisQehMaCGzvhRWamPew Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 83CF01956064; Mon, 30 Dec 2024 12:45:03 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 93C4D1956053; Mon, 30 Dec 2024 12:44:59 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v5 1/6] vhost: Add a new parameter in vhost_dev to allow user select kthread Date: Mon, 30 Dec 2024 20:43:48 +0800 Message-ID: <20241230124445.1850997-2-lulu@redhat.com> In-Reply-To: <20241230124445.1850997-1-lulu@redhat.com> References: <20241230124445.1850997-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 The vhost now uses vhost_task and workers as a child of the owner thread. While this aligns with containerization principles, it confuses some legacy userspace applications. Therefore, we are reintroducing support for the kthread API. Introduce a new parameter to enable users to choose between kthread and task mode. Signed-off-by: Cindy Lu Acked-by: Jason Wang --- drivers/vhost/vhost.c | 1 + drivers/vhost/vhost.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 9ac25d08f473..eaddbd39c29b 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -552,6 +552,7 @@ void vhost_dev_init(struct vhost_dev *dev, dev->byte_weight = byte_weight; dev->use_worker = use_worker; dev->msg_handler = msg_handler; + dev->inherit_owner = true; init_waitqueue_head(&dev->wait); INIT_LIST_HEAD(&dev->read_list); INIT_LIST_HEAD(&dev->pending_list); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index bb75a292d50c..c650c4506c70 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -176,6 +176,7 @@ struct vhost_dev { int byte_weight; struct xarray worker_xa; bool use_worker; + bool inherit_owner; int (*msg_handler)(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg); }; From patchwork Mon Dec 30 12:43:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13923255 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 902211A2C0E for ; Mon, 30 Dec 2024 12:47:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562828; cv=none; b=VbDAEwr/6NDDFnNrinHokX4CuzQmKD/gHZ2Yh4iR+ltxVNFXrQIpyvGavhlXfEW43h/jSXhPeFb/VkXzYcBE3yuN0Ptvr071ezRxvwtkW4y2yQ5xl65rEuhdPZUKuPqgdN3kMQTFxLS49+tyohMh9iCe5vzjpnvmipdTwCWkMtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562828; c=relaxed/simple; bh=zJ7gQ1kSqCdMUp9Tx832EuPhAuNPPcp41jJMW9X3QaE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VvIFp8NjS5wTGOHebqaUdmHFx3m9rEiQoQ3q3jjI2/6mE1qfdXuJF+n42MMGyEmJa/iMIqnlnuFya7EVraMjjcQFO2+tDQu8Y2jehota51dWa+sKscpVbXy+0FoUXOsG4J+avCT40aAdi577Fjr7xFe8X3S3NeXO1fIAYzYWotg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EVMgUTO0; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EVMgUTO0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562824; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QDGpQBYYbqEvdCGufJQtc26EbONqPNkQa5s9LCtzmcU=; b=EVMgUTO0VTpPwaKU9NvrcVPfDQcwfYG5CPcdejgwNOHVKheYVvpZzs3HfLR+7EdL9rBx/0 aGmR28eBy/KTIKtA+yrX8wC/iqenH/NQW0KldxtdCIsvD1iCJtDlAWs4cTrHphd1dhhKbV c1kwrNZQKxJToT+z0tPIqT8rGrdxdkg= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-_PZL29MePRm7ojIGFhQoiQ-1; Mon, 30 Dec 2024 07:45:09 -0500 X-MC-Unique: _PZL29MePRm7ojIGFhQoiQ-1 X-Mimecast-MFC-AGG-ID: _PZL29MePRm7ojIGFhQoiQ Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2CE7319560BE; Mon, 30 Dec 2024 12:45:08 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 46C361956053; Mon, 30 Dec 2024 12:45:03 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v5 2/6] vhost: Add the vhost_worker to support kthread Date: Mon, 30 Dec 2024 20:43:49 +0800 Message-ID: <20241230124445.1850997-3-lulu@redhat.com> In-Reply-To: <20241230124445.1850997-1-lulu@redhat.com> References: <20241230124445.1850997-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Add the previously removed function vhost_worker() back to support the kthread and rename it to vhost_run_work_kthread_list. The old function vhost_worker() was changed to support tasks in commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads") and to support multiple workers per device using xarray in commit 1cdaafa1b8b4 ("vhost: replace single worker pointer with xarray"). Signed-off-by: Cindy Lu Acked-by: Jason Wang --- drivers/vhost/vhost.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index eaddbd39c29b..1feba29abf95 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -388,6 +388,44 @@ static void vhost_vq_reset(struct vhost_dev *dev, __vhost_vq_meta_reset(vq); } +static int vhost_run_work_kthread_list(void *data) +{ + struct vhost_worker *worker = data; + struct vhost_work *work, *work_next; + struct vhost_dev *dev = worker->dev; + struct llist_node *node; + + kthread_use_mm(dev->mm); + + for (;;) { + /* mb paired w/ kthread_stop */ + set_current_state(TASK_INTERRUPTIBLE); + + if (kthread_should_stop()) { + __set_current_state(TASK_RUNNING); + break; + } + node = llist_del_all(&worker->work_list); + if (!node) + schedule(); + + node = llist_reverse_order(node); + /* make sure flag is seen after deletion */ + smp_wmb(); + llist_for_each_entry_safe(work, work_next, node, node) { + clear_bit(VHOST_WORK_QUEUED, &work->flags); + __set_current_state(TASK_RUNNING); + kcov_remote_start_common(worker->kcov_handle); + work->fn(work); + kcov_remote_stop(); + cond_resched(); + } + } + kthread_unuse_mm(dev->mm); + + return 0; +} + static bool vhost_run_work_list(void *data) { struct vhost_worker *worker = data; From patchwork Mon Dec 30 12:43:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13923251 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F13D41B0F2C for ; Mon, 30 Dec 2024 12:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562718; cv=none; b=Yrrd5yF3+O5BVO6s+5rk42GASC4/R1xKLDsxQUQcqVY2HnzZvJzQDZ1RJiR02ACMX1iXfWhQWx7M65sXfsVPGowJc8RqKBeisEnRcv3nIYlBhFlzIHTqpKubF1nM3dgSdSPOrejnIunaVeDjOXiQgP6UpxUHugML/8eGRvW9rkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562718; c=relaxed/simple; bh=C4GD7RVh/vxLlAuOqHzKJNvXqDyu3G+07lQPqd2fEic=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H/4cF7VIq2FgacP6qhQBPNRXyWAmw24dyo3vC1G9N4yWimE7RA+PAYABZJdc1GiStV89Txi7mZjirkdwxC5Fzl9u/fPJQP0n5Zlag/YSw3ERGISHDb/D02WdY65Dn6MPOMbHOiZFDg10BQsLVW8634jYpalrOWkE8nBYGN10S6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GQdFv+vR; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GQdFv+vR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZNhKJ0c4+OPvS+8sgCm6iOkshVGfikTW1g2insQ4mn8=; b=GQdFv+vRNr9uTqNNtjKlVASm397krza+ZPuBakApWrkNEaHGp8jMRY2ShwnXmvT11ouaHK Xa8CTnsCradRK5Ag+HR66LdfizOLChXQceUkEZ5OETtsFWJ8GF9b5iTobwZg5+qjjT3qF5 PzEkm8771ZkvVIO/oTgDzi1bqaXjaAU= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-5v5RAxXjPjCvWzjKhCltKg-1; Mon, 30 Dec 2024 07:45:14 -0500 X-MC-Unique: 5v5RAxXjPjCvWzjKhCltKg-1 X-Mimecast-MFC-AGG-ID: 5v5RAxXjPjCvWzjKhCltKg Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 024031956089; Mon, 30 Dec 2024 12:45:13 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E50CE1956053; Mon, 30 Dec 2024 12:45:08 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v5 3/6] vhost: Add the cgroup related function Date: Mon, 30 Dec 2024 20:43:50 +0800 Message-ID: <20241230124445.1850997-4-lulu@redhat.com> In-Reply-To: <20241230124445.1850997-1-lulu@redhat.com> References: <20241230124445.1850997-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Reintroduce the previously removed functions vhost_attach_cgroups_work() and vhost_attach_cgroups() to support kthread mode. Rename vhost_attach_cgroups() to vhost_attach_task_to_cgroups(), and include the implementation of the old function vhost_dev_flush() in this new function. These function was removed in commit 6e890c5d5021 ("vhost: use vhost_tasks for worker threads") Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 1feba29abf95..812dfd218bc2 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -620,6 +621,38 @@ long vhost_dev_check_owner(struct vhost_dev *dev) } EXPORT_SYMBOL_GPL(vhost_dev_check_owner); +struct vhost_attach_cgroups_struct { + struct vhost_work work; + struct task_struct *owner; + int ret; +}; + +static void vhost_attach_cgroups_work(struct vhost_work *work) +{ + struct vhost_attach_cgroups_struct *s; + + s = container_of(work, struct vhost_attach_cgroups_struct, work); + s->ret = cgroup_attach_task_all(s->owner, current); +} + +static int vhost_attach_task_to_cgroups(struct vhost_worker *worker) +{ + struct vhost_flush_struct flush; + struct vhost_attach_cgroups_struct attach; + + attach.owner = current; + + vhost_work_init(&attach.work, vhost_attach_cgroups_work); + vhost_worker_queue(worker, &attach.work); + + init_completion(&flush.wait_event); + vhost_work_init(&flush.work, vhost_flush_work); + vhost_worker_queue(worker, &flush.work); + wait_for_completion(&flush.wait_event); + + return attach.ret; +} + /* Caller should have device mutex */ bool vhost_dev_has_owner(struct vhost_dev *dev) { From patchwork Mon Dec 30 12:43:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13923252 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB6091AA781 for ; Mon, 30 Dec 2024 12:45:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562744; cv=none; b=SHArPmFNeRJk0tYh2jpfP6lMHLf5M8vqBAovxx8Y7rzmlFI1QaZigvpIdI6P2IYJZe48u02tKzy91q8I+Ut8r38/o9cDL9vIyHqg1mtM8bCYP8hzj6ga170JqaSfMZbyrFn5HfXbAEtBJygmRaAnMMI0CMI9z+Q+q00F32FBz2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562744; c=relaxed/simple; bh=merdHWDONAbu6sbJILjbIpHE9fjKrx85ebbEc61iUxQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dfzQawlekU1UK3yX/Yyv9rtoa3tx0ORxQR2xK2XR1366lQVF+MyFBnsnJQao0zgQC8TPITWAFJGWpGnbPTfm4cY1d70Ykk9s2eZumpl1HChxfR7hJarITygDq9I+a/Jl86BkbRad8F4MaftB51LBPie95fYIFxryXF7w5Ji55ag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JdQD0aNN; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JdQD0aNN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zWfiK+MXrYcFg+E5mVFexunT6ykM6I0gV5eHLwqgzag=; b=JdQD0aNN0NLijdMnyj0789T39BAxsduaShPO2klWDYP8NCkycs7h42X41RabFjilUisCPi AyWAKiWEpC52PuiaEdhxZ8PPVGZOCZ07+p6lpzKpvUlho5kDHocMmLE7E9BFUVqG4Thls3 raew3aWR8eYl9UBe4RGaNxlPMpAkc68= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-693-aelkPqn7MMOTV9yEka2DzQ-1; Mon, 30 Dec 2024 07:45:40 -0500 X-MC-Unique: aelkPqn7MMOTV9yEka2DzQ-1 X-Mimecast-MFC-AGG-ID: aelkPqn7MMOTV9yEka2DzQ Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B243019560AB; Mon, 30 Dec 2024 12:45:39 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9F67619560A2; Mon, 30 Dec 2024 12:45:35 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v5 4/6] vhost: Add worker related functions to support kthread Date: Mon, 30 Dec 2024 20:43:51 +0800 Message-ID: <20241230124445.1850997-5-lulu@redhat.com> In-Reply-To: <20241230124445.1850997-1-lulu@redhat.com> References: <20241230124445.1850997-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Restore the previously removed functions kthread_wakeup and kthread_stop, and add two new function pointers to wake up and stop the workers. The function vhost_worker_create will initialize these pointers based on the value of inherit_owner. The functions vhost_worker_queue() and vhost_worker_destroy() will use the function pointer in vhost_worker, which is initialized according to the inherit_owner value. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 84 ++++++++++++++++++++++++++++++++++--------- drivers/vhost/vhost.h | 3 ++ 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 812dfd218bc2..ff17c42e2d1a 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -243,7 +243,7 @@ static void vhost_worker_queue(struct vhost_worker *worker, * test_and_set_bit() implies a memory barrier. */ llist_add(&work->node, &worker->work_list); - vhost_task_wake(worker->vtsk); + worker->worker_wakeup(worker); } } @@ -698,7 +698,7 @@ static void vhost_worker_destroy(struct vhost_dev *dev, WARN_ON(!llist_empty(&worker->work_list)); xa_erase(&dev->worker_xa, worker->id); - vhost_task_stop(worker->vtsk); + worker->worker_stop(worker); kfree(worker); } @@ -721,14 +721,36 @@ static void vhost_workers_free(struct vhost_dev *dev) xa_destroy(&dev->worker_xa); } +static void vhost_task_wakeup_fn(struct vhost_worker *worker) +{ + return vhost_task_wake(worker->vtsk); +} + +static void vhost_kthread_wakeup_fn(struct vhost_worker *worker) +{ + wake_up_process(worker->kthread_task); +} + +static void vhost_task_stop_fn(struct vhost_worker *worker) +{ + return vhost_task_stop(worker->vtsk); +} + +static void vhost_kthread_stop_fn(struct vhost_worker *worker) +{ + kthread_stop(worker->kthread_task); +} + static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) { struct vhost_worker *worker; - struct vhost_task *vtsk; + struct vhost_task *vtsk = NULL; + struct task_struct *task = NULL; char name[TASK_COMM_LEN]; int ret; u32 id; + /* Allocate resources for the worker */ worker = kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); if (!worker) return NULL; @@ -736,27 +758,57 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) worker->dev = dev; snprintf(name, sizeof(name), "vhost-%d", current->pid); - vtsk = vhost_task_create(vhost_run_work_list, vhost_worker_killed, - worker, name); - if (!vtsk) - goto free_worker; - mutex_init(&worker->mutex); init_llist_head(&worker->work_list); worker->kcov_handle = kcov_common_handle(); - worker->vtsk = vtsk; + /* + * If inherit_owner is true we use vhost_tasks to create + * the worker so all settings/limits like cgroups, NPROC, + * scheduler, etc are inherited from the owner. + * If false,we use kthreads and only attach to the same + * cgroups as the owner for compat with older kernels. + */ + if (dev->inherit_owner) { + vtsk = vhost_task_create(vhost_run_work_list, + vhost_worker_killed, worker, name); + if (!vtsk) + goto free_worker; + + worker->vtsk = vtsk; + worker->worker_wakeup = vhost_task_wakeup_fn; + worker->worker_stop = vhost_task_stop_fn; + + vhost_task_start(vtsk); + ret = xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, + GFP_KERNEL); + if (ret < 0) + goto stop_worker; + } else { + task = kthread_create(vhost_run_work_kthread_list, worker, + "vhost-%d", current->pid); + if (IS_ERR(task)) { + ret = PTR_ERR(task); + goto free_worker; + } + worker->kthread_task = task; + worker->worker_wakeup = vhost_kthread_wakeup_fn; + worker->worker_stop = vhost_kthread_stop_fn; - vhost_task_start(vtsk); + wake_up_process(task); + ret = xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, + GFP_KERNEL); + if (ret < 0) + goto stop_worker; - ret = xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, GFP_KERNEL); - if (ret < 0) - goto stop_worker; - worker->id = id; + ret = vhost_attach_task_to_cgroups(worker); + if (ret) + goto stop_worker; + } + worker->id = id; return worker; - stop_worker: - vhost_task_stop(vtsk); + worker->worker_stop(worker); free_worker: kfree(worker); return NULL; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index c650c4506c70..63b1da08a2b0 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -27,6 +27,7 @@ struct vhost_work { }; struct vhost_worker { + struct task_struct *kthread_task; struct vhost_task *vtsk; struct vhost_dev *dev; /* Used to serialize device wide flushing with worker swapping. */ @@ -36,6 +37,8 @@ struct vhost_worker { u32 id; int attachment_cnt; bool killed; + void (*worker_wakeup)(struct vhost_worker *worker); + void (*worker_stop)(struct vhost_worker *worker); }; /* Poll a file (eventfd or socket) */ From patchwork Mon Dec 30 12:43:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13923253 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E34A31B4226 for ; Mon, 30 Dec 2024 12:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562751; cv=none; b=m7LZ2Y349QqxSbg5W1m6q+0XT0SgXHae941fsn+mcdZ+1Z7OhR715L8ZlJUslK36wzdXhWaOQ5M28Z1iUVnaDUkZlCKMr0YmECoaNOuMGJYRTcL3DVd3mkwmKcCbTQTm4l57aDflfSssCgyG/QD9RBNpldcHd7C5907VcPfYa8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562751; c=relaxed/simple; bh=OGzW+SnQ3xR3XeDgv9+sPtHgQMdqMojO7S8Pp2pmps0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I4rOtSjRKwiAppVgEbbL7TCpfnD3eb2JGVc6KDrVoM5slnMny3G0n5KbQ1EP6+zicT0FlulCwEhs0ZtbaRT5BElyM++MoDh0nSWefzWazOhSl+CnNg86iXAc19pqzx2OPImmeyegVlXDZiPIRvlBIbZBiLGcbgt1/3FN1HZgr9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NQoVXVMS; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NQoVXVMS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562748; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SOLNm7RgGjm+/oknkrmt1JKCoXNQL051GSrtvQZUvKg=; b=NQoVXVMSdODBuR0NJqlxTpS/G5livfgNiWFz+jruPGEMF7ArHIhYh/gdF4Sy5xJWiAbkPS 6jVfBN4Ua3GDn5JpWSyNIHXnzfchuOxkD8zSZ7I5fD5VexpX3dXoYWynygdI+i9jZIDycW tq70KHySV/ZLtGvz8i+4usrxfiXnpqA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-Bsm6_zAdMOCXSGDiO3J0Jw-1; Mon, 30 Dec 2024 07:45:45 -0500 X-MC-Unique: Bsm6_zAdMOCXSGDiO3J0Jw-1 X-Mimecast-MFC-AGG-ID: Bsm6_zAdMOCXSGDiO3J0Jw Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7977519560B1; Mon, 30 Dec 2024 12:45:44 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 759C419560A2; Mon, 30 Dec 2024 12:45:40 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v5 5/6] vhost: Add new UAPI to support change to task mode Date: Mon, 30 Dec 2024 20:43:52 +0800 Message-ID: <20241230124445.1850997-6-lulu@redhat.com> In-Reply-To: <20241230124445.1850997-1-lulu@redhat.com> References: <20241230124445.1850997-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Add a new UAPI to enable setting the vhost device to task mode. The userspace application can use VHOST_SET_INHERIT_FROM_OWNER to configure the mode if necessary. This setting must be applied before VHOST_SET_OWNER, as the worker will be created in the VHOST_SET_OWNER function Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 22 +++++++++++++++++++++- include/uapi/linux/vhost.h | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index ff17c42e2d1a..47c1329360ac 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2250,15 +2250,35 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) { struct eventfd_ctx *ctx; u64 p; - long r; + long r = 0; int i, fd; + u8 inherit_owner; /* If you are not the owner, you can become one */ if (ioctl == VHOST_SET_OWNER) { r = vhost_dev_set_owner(d); goto done; } + if (ioctl == VHOST_SET_INHERIT_FROM_OWNER) { + /*inherit_owner can only be modified before owner is set*/ + if (vhost_dev_has_owner(d)) { + r = -EBUSY; + goto done; + } + if (copy_from_user(&inherit_owner, argp, sizeof(u8))) { + r = -EFAULT; + goto done; + } + /* Validate the inherit_owner value, ensuring it is either 0 or 1 */ + if (inherit_owner > 1) { + r = -EINVAL; + goto done; + } + + d->inherit_owner = (bool)inherit_owner; + goto done; + } /* You must be the owner to do anything else */ r = vhost_dev_check_owner(d); if (r) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index b95dd84eef2d..f5fcf0b25736 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -235,4 +235,23 @@ */ #define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \ struct vhost_vring_state) + +/** + * VHOST_SET_INHERIT_FROM_OWNER - Set the inherit_owner flag for the vhost device + * + * @param inherit_owner: An 8-bit value that determines the vhost thread mode + * + * When inherit_owner is set to 1 (default behavior): + * - The VHOST worker threads inherit their values/checks from + * the thread that owns the VHOST device. The vhost threads will + * be counted in the nproc rlimits. + * + * When inherit_owner is set to 0: + * - The VHOST worker threads will use the traditional kernel thread (kthread) + * implementation, which may be preferred by older userspace applications that + * do not utilize the newer vhost_task concept. + */ + +#define VHOST_SET_INHERIT_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, __u8) + #endif From patchwork Mon Dec 30 12:43:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 13923254 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8E671B4226 for ; Mon, 30 Dec 2024 12:45:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562756; cv=none; b=qQJJKXHKWJplnF1/m596ZuEUJ6XSd3mBxn1Z26YA2f6vCT3wjsSrVQMTLTyNhINbWSzFDDxvpG+UHI2IqnJDCINYeCUi0vmOV0FSctQEiild9j/eb0Wn37fzJvQYBLlVluCXHQwoHl3iYQX6KZYiIOMkR8fzyslL13l0J83uBxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562756; c=relaxed/simple; bh=ya0jLzzyRV4JPRzvVhGgoWSL9yvZjTh8Fu2M3ibVj+k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+QH6q0aKOGyTaOQTcJZixQy3UVph1+K3EaigX/bVilvGbkaKDOjH+qX5qt9kpaFu92/fOUQuoo4JEEjlUEGXQwIOKxXk2xq0eCLB9UVS4bC/u92ResDQj9YGfSoFGk2a1GWeWyO9L9oKISRH1WX16u+ur95TEi3Uyj1mPYMjvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hEVdY35s; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hEVdY35s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7xX4qyypEHsNe4ER87SJ3OZmlnLp0lW0wrG4GS+lDAg=; b=hEVdY35s3g+5YngV62wKR8yXz9L6kDnRdoCUDveRnP468IWFbGyubsDQKxwHcSERtSlB4g wdgjUDxKQKIWHQFY0Y5jojbA161QRYJhKD46EyrfckdguW5WLn7Duazqos94CQThRC21qy zVvIuGUNf+MpEQVC+LXw730lLj8b92Y= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-I1gdlmexNoqjr8Xbbmryxw-1; Mon, 30 Dec 2024 07:45:50 -0500 X-MC-Unique: I1gdlmexNoqjr8Xbbmryxw-1 X-Mimecast-MFC-AGG-ID: I1gdlmexNoqjr8Xbbmryxw Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3B5361956055; Mon, 30 Dec 2024 12:45:49 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3DC3C19560A2; Mon, 30 Dec 2024 12:45:44 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v5 6/6] vhost_scsi: Add check for inherit_owner status Date: Mon, 30 Dec 2024 20:43:53 +0800 Message-ID: <20241230124445.1850997-7-lulu@redhat.com> In-Reply-To: <20241230124445.1850997-1-lulu@redhat.com> References: <20241230124445.1850997-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 The vhost_scsi VHOST_NEW_WORKER requires the inherit_owner setting to be true. So we need to implement a check for this. Signed-off-by: Cindy Lu --- drivers/vhost/scsi.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 718fa4e0b31e..0d63b6b5c852 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -2086,6 +2086,14 @@ vhost_scsi_ioctl(struct file *f, return -EFAULT; return vhost_scsi_set_features(vs, features); case VHOST_NEW_WORKER: + /* + * vhost_tasks will account for worker threads under the parent's + * NPROC value but kthreads do not. To avoid userspace overflowing + * the system with worker threads inherit_owner must be true. + */ + if (!vs->dev.inherit_owner) + return -EFAULT; + fallthrough; case VHOST_FREE_WORKER: case VHOST_ATTACH_VRING_WORKER: case VHOST_GET_VRING_WORKER: