From nobody Sun May 10 06:27:23 2026 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 216541A840E 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Tested-by: Mike Christie --- 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 =3D byte_weight; dev->use_worker =3D use_worker; dev->msg_handler =3D msg_handler; + dev->inherit_owner =3D 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); }; --=20 2.45.0 From nobody Sun May 10 06:27:23 2026 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 946BA1B0416 for ; Mon, 30 Dec 2024 12:45:13 +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=1735562715; cv=none; b=AM0asiGVMuJuAtdrKHHv/8IKyu6oP9GvsKs0nQSoPMNwJOkmgEU4ttq9c3dyJ3s3BGbjpwZX0PhG0JQvbRjwkvEBYtiRhYS7T8I8wrzk0ZjLSjs8gE/WT8eoIvJWEBCIYX4b0ljfX+jCvIzCO1DxVLmkFGCBt8E/PDFmhvLbFQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562715; c=relaxed/simple; bh=zJ7gQ1kSqCdMUp9Tx832EuPhAuNPPcp41jJMW9X3QaE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P/QXo+1p8iNPj/+y+O8SxJSXH/EqnYzX8vn9KhaOY1xD1j+MzD3auTuGxzOStMitwCSZyfkTr35q5LznRAXMqLnpW42kDLWmWv9R2r9zrs5NKJe6IfNZuy3hIIG9O6QATySSsPw1MaG0/msXx6QvhXuTaFM/eep4Om5/1nbVmQY= 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=IKDMgT0W; 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="IKDMgT0W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562712; 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=IKDMgT0Wp3t4ukfkmg2pbhx/BxpDD2jYwPirOAWCJHgGByczwnrZJZdzAXwQvp9ws3NSY1 KB+PJOTSiLVe4h+Prha1aqDq4VNDRKEkG2+km/RTTUUsDRAso0BtAHmBP4wHvQgFzIlEFL qj5qK9WAuhhXlZo61nbPg3XNAz3i72k= 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Tested-by: Mike Christie --- 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); } =20 +static int vhost_run_work_kthread_list(void *data) +{ + struct vhost_worker *worker =3D data; + struct vhost_work *work, *work_next; + struct vhost_dev *dev =3D 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 =3D llist_del_all(&worker->work_list); + if (!node) + schedule(); + + node =3D 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 =3D data; --=20 2.45.0 From nobody Sun May 10 06:27:23 2026 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 AE2001A9B4C for ; Mon, 30 Dec 2024 12:45:18 +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=1735562720; cv=none; b=CbLVCHpbABykyb1lQruSB8kestR7D8r+OellW3VfboLvXWzZVSWvuZOmPrKKjJ2k2aBnc4LiUctrWNu/fdIv+0KTCOzIEpfrBQO78fFIdnacCFaQ27ejVKxor4inFkTkWjPtuc4GS3T4fNoVFDcFT6XZbhLifVGypXbs67Ywhnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562720; c=relaxed/simple; bh=C4GD7RVh/vxLlAuOqHzKJNvXqDyu3G+07lQPqd2fEic=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gadQF/ZSDLmVBux6aoJ76PNAHsEElkEBPpl8JUjmozS7VPBqhoTPeyoXmEfSab+2u13lEtqRESvB0Ci9WtfGBf2iZF8Rq+VjdmGiCvUSyozhgVA9rE+L7N06/y/gos+yQgLFxuFvbHUgR344DXya5mcoUFB+UqoqLCz8PDlJUsE= 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=Lx0md2K+; 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="Lx0md2K+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562717; 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=Lx0md2K+U1la8WY6jxd8LF8Lcx2Pdh/Ai0vVN5HH7pbsLNtBodsNgzyb9FXrkxh2rEODZJ 9IDvkcSc907oJiJHxxEYY/4ci4uL4sUbm36lhuiNZN9UXe/M3VaTeJHZJ688m5vjE91TgR fg4zRqMQXAKuNnwBP+iMnKer+TQyj1o= 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Tested-by: Mike Christie --- 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); =20 +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 =3D container_of(work, struct vhost_attach_cgroups_struct, work); + s->ret =3D 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 =3D 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) { --=20 2.45.0 From nobody Sun May 10 06:27:23 2026 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 D762A1AA1D2 for ; Mon, 30 Dec 2024 12:45:44 +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=1735562746; cv=none; b=gwq+5ZTcXBwb+7JuyIt/rIDAbevd+VctCPCkeueCLaIY9Q9DR/3OZidsuo429BbcnxXUwoVWash7cXrk13FiAIBAvv/0xsDb0XR5x2D4B8ux7RUvSjotS1jO6eMNuszOZC8jpyZJHaGEEwsTa8RM+0DyZGefbV3DaByp9AzSS20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562746; c=relaxed/simple; bh=merdHWDONAbu6sbJILjbIpHE9fjKrx85ebbEc61iUxQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CykrjopjuZ5HT2JNGN28OZp7KpizuBqISApJnAWXlTxh4xvFrxu/Dj7ZIQPn/yZ5oOC+e7KCtmmi0LviK47B+0QUQ6fBnH6KPgfKAOTPCqoTBGLSmTqwBAabtYZje7oxNt/EYvqVRLDhsbREMP/S1Wq7HPgDjmXpK/GV843pZE8= 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=QQuL4bIk; 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="QQuL4bIk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562743; 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=QQuL4bIkIT+NEK9cbjab+by1FHqC16zl2hLlKd6e23kmul9+Ez/HVHbWWW9az9mQqCfOAE yQsY5R3ypEn9MF62LzPLDSG9S4lmna9HWFQg6AuZKX8//3jNfuz+q63TJN4xmPUFRcEhsW kf0yncGUEsnVVr8oITGv5ilUSGYsmVk= 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Tested-by: Mike Christie --- 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 *wor= ker, * test_and_set_bit() implies a memory barrier. */ llist_add(&work->node, &worker->work_list); - vhost_task_wake(worker->vtsk); + worker->worker_wakeup(worker); } } =20 @@ -698,7 +698,7 @@ static void vhost_worker_destroy(struct vhost_dev *dev, =20 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); } =20 @@ -721,14 +721,36 @@ static void vhost_workers_free(struct vhost_dev *dev) xa_destroy(&dev->worker_xa); } =20 +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 =3D NULL; + struct task_struct *task =3D NULL; char name[TASK_COMM_LEN]; int ret; u32 id; =20 + /* Allocate resources for the worker */ worker =3D kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); if (!worker) return NULL; @@ -736,27 +758,57 @@ static struct vhost_worker *vhost_worker_create(struc= t vhost_dev *dev) worker->dev =3D dev; snprintf(name, sizeof(name), "vhost-%d", current->pid); =20 - vtsk =3D 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 =3D kcov_common_handle(); - worker->vtsk =3D 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 =3D vhost_task_create(vhost_run_work_list, + vhost_worker_killed, worker, name); + if (!vtsk) + goto free_worker; + + worker->vtsk =3D vtsk; + worker->worker_wakeup =3D vhost_task_wakeup_fn; + worker->worker_stop =3D vhost_task_stop_fn; + + vhost_task_start(vtsk); + ret =3D xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, + GFP_KERNEL); + if (ret < 0) + goto stop_worker; + } else { + task =3D kthread_create(vhost_run_work_kthread_list, worker, + "vhost-%d", current->pid); + if (IS_ERR(task)) { + ret =3D PTR_ERR(task); + goto free_worker; + } + worker->kthread_task =3D task; + worker->worker_wakeup =3D vhost_kthread_wakeup_fn; + worker->worker_stop =3D vhost_kthread_stop_fn; =20 - vhost_task_start(vtsk); + wake_up_process(task); + ret =3D xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, + GFP_KERNEL); + if (ret < 0) + goto stop_worker; =20 - ret =3D xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, GFP_KERNEL); - if (ret < 0) - goto stop_worker; - worker->id =3D id; + ret =3D vhost_attach_task_to_cgroups(worker); + if (ret) + goto stop_worker; + } =20 + worker->id =3D 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 { }; =20 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); }; =20 /* Poll a file (eventfd or socket) */ --=20 2.45.0 From nobody Sun May 10 06:27:23 2026 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 E14F11AAA11 for ; Mon, 30 Dec 2024 12:45:47 +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=1735562749; cv=none; b=uiwzSZxHILmDpYBfkDtTIQP/eopqSv4BRzpC2lsT+kY3oRshjQSWEMW2iBHMCSxjXULD/KV/Liujgbp/yWq4sLw80y9f5FMgmDWhKk5t1b0OzE55OWrO7v1vldG1+n8k+sDoG6e9ne7CGvNSUY5sd1Ys02mx/etRcqc5bTKT+RM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562749; c=relaxed/simple; bh=OGzW+SnQ3xR3XeDgv9+sPtHgQMdqMojO7S8Pp2pmps0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cb4KUAFKxBhx1cMOkAiPj1M71O5ozvQvbd0z6eXjLbl4bAgoX8t1aSH726DX+WDN2K8d/Q5mNwmxHAfhzy/Lg74KOf9KaQVjkhuzu5WLVFU66V13FgvgLVTt1SuAeIY33/OIGzwJflOvmacjh1901BeELjd+iBt+BoQjWzeGNDA= 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=cNWj83d8; 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="cNWj83d8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562746; 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=cNWj83d8iGxGOabgsCby2g8ttOB/LsM3TeHqiZeIXZM1Pl7cHaGFpLqeVhZCOV2cos55b6 SuPNcMMBfjjS8bUsg90/mpOzKqgvjcLryQG/E48yFdJ+14ap/QpkWGZ2e6pTk4v/AC+Oal rjIRVGfBpDd0gxv9WNPyLpbkoyKLCeI= 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Tested-by: Mike Christie --- 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 =3D 0; int i, fd; + u8 inherit_owner; =20 /* If you are not the owner, you can become one */ if (ioctl =3D=3D VHOST_SET_OWNER) { r =3D vhost_dev_set_owner(d); goto done; } + if (ioctl =3D=3D VHOST_SET_INHERIT_FROM_OWNER) { + /*inherit_owner can only be modified before owner is set*/ + if (vhost_dev_has_owner(d)) { + r =3D -EBUSY; + goto done; + } + if (copy_from_user(&inherit_owner, argp, sizeof(u8))) { + r =3D -EFAULT; + goto done; + } + /* Validate the inherit_owner value, ensuring it is either 0 or 1 */ + if (inherit_owner > 1) { + r =3D -EINVAL; + goto done; + } + + d->inherit_owner =3D (bool)inherit_owner; =20 + goto done; + } /* You must be the owner to do anything else */ r =3D 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 m= ode + * + * 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 (kt= hread) + * implementation, which may be preferred by older userspace applicati= ons that + * do not utilize the newer vhost_task concept. + */ + +#define VHOST_SET_INHERIT_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, __u8) + #endif --=20 2.45.0 From nobody Sun May 10 06:27:23 2026 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 C3F1F1B4243 for ; Mon, 30 Dec 2024 12:45:52 +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=1735562754; cv=none; b=r967fzBDJ5zoEprsJodBtC5HpNKH2cOWadYJi5fCcw6kcyGIMIQhACHEuVcpj+AqCZ0V8FytZ+yRdltwfq8sBvAxAEChPDKIiyrguK1NgjVOsBlQScASDeUaD2gSfl6tAqPdI7l4plK5zgrZGq5OFnZcObJOPC7FUPRzHbF+PUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735562754; c=relaxed/simple; bh=ya0jLzzyRV4JPRzvVhGgoWSL9yvZjTh8Fu2M3ibVj+k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S4bpvEvl8Tcn4xNdwPU+R24+jkxMkE7R3p1FTzczO2LNTUHLM3IgXq+ZM/qcCumKzj3+uE044xmX/dggHE7Hkm5vo+4ZTnF7Pdklpc7AiHwwXnErsokKbw8oM//Q08g0vt5rbLgilotGEztFqpZzZTWAnBKxXo0Pr9R1BYzl4kg= 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=bFviTDGK; 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="bFviTDGK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1735562751; 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=bFviTDGKNFXHtXTS898rC9hZYbrqpHL2Z9LxqiijUoVKk4G8MMlrcnYFL7octGGwVaUSTH TBUsc4UgA66dou2KnCF8yavonuFZKVBRpGoj9yogW31OOWYFxDB4nF7ZO67V891sA4sVsH /LdsgucjPT4w7EToBxCqzsTIMxMKNf0= 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lei Yang Tested-by: Mike Christie --- 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: --=20 2.45.0