From nobody Sun Feb 8 05:35:07 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 5250915F319 for ; Mon, 19 Aug 2024 09:29: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=1724059751; cv=none; b=EtRVsEIOmEgwjmyb7qR0OdwugFUj47K8qNeraleVN/bC06vGK89cXBNFPFYL0sFxrutsoPj95Jc6AKyhwbJkG1TPWxvRwTkchQaoSgesxFV9vwrfsog3TYRmQvlwPvOuG1dpvr5ap3q4GiLvlefZaMhcFLBp446oETUaeCv00Yc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724059751; c=relaxed/simple; bh=T28RQRktjxNSpRXzjatTxI5HNr8v0aKmaJkUuNN6u0Q=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E/0YPfD/fBkAvr7GTNOB35MPUw9pWaqw8TFxp/Ilgej1vIrzePhSxQd5bCHv9ZhtPjWcwjAnYkESWSPMaDuE8v/4QdFotML67cKPVsEikzi9pJZ/EEvX/jNDsUjOv59+G+OKPPVqV4fC/qnpV6GBaJiYZeuYjAD6pdoge9GghKA= 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=OuIZmxLO; 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="OuIZmxLO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724059749; 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=m/kmoYqnstbKFrlYx9VIPQUYp5ncxzSL1je8L9dtZF4=; b=OuIZmxLO9+PAnwsEAngqOmrcz+H1ih0rvu6h7YfAFlBXUoWyWc40c/rIihM8ARy6YeRk9Z orWWeDQ4DOpZb8dHnYV1j0OyUztKTQzYoeJPH98Wp4zlLazPsBFwAlK9P2wUPm1c7xkWud d9lVPjSBtBsl6rSvjwQnxpKkS4KvZXo= Received: from mx-prod-mc-01.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-664-59nOVgyVNDa2gavH-v9Rrw-1; Mon, 19 Aug 2024 05:29:07 -0400 X-MC-Unique: 59nOVgyVNDa2gavH-v9Rrw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 64FA01954206; Mon, 19 Aug 2024 09:29:06 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 175AA1956054; Mon, 19 Aug 2024 09:29:02 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RFC 1/7] vhost: Add a new module_param for enable kthread Date: Mon, 19 Aug 2024 17:27:27 +0800 Message-ID: <20240819092851.441670-2-lulu@redhat.com> In-Reply-To: <20240819092851.441670-1-lulu@redhat.com> References: <20240819092851.441670-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.40 Content-Type: text/plain; charset="utf-8" Add a new module parameter to enable kthread while loading modules. This parameter will identify if the vhost will use kthread or a task. The default value will be true. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 9ac25d08f473..da701f6b3f2c 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -41,6 +41,9 @@ static int max_iotlb_entries =3D 2048; module_param(max_iotlb_entries, int, 0444); MODULE_PARM_DESC(max_iotlb_entries, "Maximum number of iotlb entries. (default: 2048)"); +bool use_kthread =3D true; +module_param(use_kthread, bool, 0444); +MODULE_PARM_DESC(use_kthread, "enable vhost to use kthread (default: Y)"); =20 enum { VHOST_MEMORY_F_LOG =3D 0x1, --=20 2.45.0 From nobody Sun Feb 8 05:35:07 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 1375F15FA6A for ; Mon, 19 Aug 2024 09:29:12 +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=1724059754; cv=none; b=ohmBFEjMyNdzyDyBiBTDqJGko93sP0g2zFrVeuKeL1NFncRixPLOnU7H9SusaxsqxFx6rswmCsg9VU8DL0Wh9p7KDLzYfpU556Zyg0PyCepN7Pd77olhH0IEf+Gvr+nYxPqA3Ss6ewy+NdqdiWvjBbB4zEUpzkKGRkW1B2V1wbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724059754; c=relaxed/simple; bh=bCcqpKiJI8aKiCcDeYVwFAl69XuQNef0FHW+n9EVc78=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=icBf+YXvMjeHUZT7u9K993wfBKQcMgI16MpFp9z1X+hQJBmQSoioVPQ7twMrH4ehvTaCidMopUGBXu3PEXT6uJD9o1Gjei0sK+RuFMgXs1bIp6RiDjDmO12VpdUP3cFGzFsl0kdnVm+KCKtKgi2YOh/0ePJes5F8s+uI9e+GiME= 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=I6wwNSOm; 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="I6wwNSOm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724059751; 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=uTiAXi97N+gpQpGCrSBfOxeh4bPxPDjSj8mY3XZdH4M=; b=I6wwNSOmU+4JYnKU0tSkDE9kVO3n7xLDXmtlJ9IdoquLIltCBRPpUzguOAKxnoxv675lOI b3QdXHj0JaSehza35Hz80NUDpq2WTG9NGLDzpIuKFSukL7ah97Msf6fVBX+dM208pwA1G4 KuesY0o/JGFNrrBjZ8+roRmLyqaDipg= Received: from mx-prod-mc-04.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-630-zo-vL0JBOyy-nQB-HA3CXg-1; Mon, 19 Aug 2024 05:29:10 -0400 X-MC-Unique: zo-vL0JBOyy-nQB-HA3CXg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EBBA51955D56; Mon, 19 Aug 2024 09:29:09 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE8611956054; Mon, 19 Aug 2024 09:29:06 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RFC 2/7] vhost: Add kthread support in function vhost_worker_queue() Date: Mon, 19 Aug 2024 17:27:28 +0800 Message-ID: <20240819092851.441670-3-lulu@redhat.com> In-Reply-To: <20240819092851.441670-1-lulu@redhat.com> References: <20240819092851.441670-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.40 Content-Type: text/plain; charset="utf-8" Added back the previously removed function vhost_worker_queue() and renamed it to vhost_worker_queue_khtread(). The new vhost_worker_queue() will select the different mode based on the value of the parameter. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 30 ++++++++++++++++++++++++++++-- drivers/vhost/vhost.h | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index da701f6b3f2c..6261c9df468e 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -236,8 +236,8 @@ void vhost_poll_stop(struct vhost_poll *poll) } EXPORT_SYMBOL_GPL(vhost_poll_stop); =20 -static void vhost_worker_queue(struct vhost_worker *worker, - struct vhost_work *work) +static void vhost_worker_queue_task(struct vhost_worker *worker, + struct vhost_work *work) { if (!test_and_set_bit(VHOST_WORK_QUEUED, &work->flags)) { /* We can only add the work to the list after we're @@ -249,6 +249,32 @@ static void vhost_worker_queue(struct vhost_worker *wo= rker, } } =20 +static void vhost_work_queue_kthread(struct vhost_worker *worker, + struct vhost_work *work) +{ + if (!worker) + return; + + if (!test_and_set_bit(VHOST_WORK_QUEUED, &work->flags)) { + /* We can only add the work to the list after we're + * sure it was not in the list. + * test_and_set_bit() implies a memory barrier. + */ + llist_add(&work->node, &worker->work_list); + + wake_up_process(worker->task); + } +} + +static void vhost_worker_queue(struct vhost_worker *worker, + struct vhost_work *work) +{ + if (use_kthread) { + vhost_work_queue_kthread(worker, work); + } else { + vhost_worker_queue_task(worker, work); + } +} bool vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *wo= rk) { struct vhost_worker *worker; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index bb75a292d50c..c7f126fd09e8 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 *task; struct vhost_task *vtsk; struct vhost_dev *dev; /* Used to serialize device wide flushing with worker swapping. */ --=20 2.45.0 From nobody Sun Feb 8 05:35:07 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 DA39315DBDD for ; Mon, 19 Aug 2024 09:29:18 +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=1724059760; cv=none; b=NJfkZMHX+pUHU5aeXfaKgEBaCkdcSWxuqhmGDZ0urYEbhPkCZHupZlczCK0edkXlNKNXdF9ibI2M91uknvRTkz5VgMzsoIwqFP9HidAsQFaK5nXHhfSk9Q8SZ6GP9jTnHrmDzvOpnbbzDJVdEH/YshgnKlU95MXdNM/JHFZObws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724059760; c=relaxed/simple; bh=hQzAsPpdGgSBnrUtnTIjrrebyHFjc0TTk3orQMkFSP0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D1TaGhM2TjpFgruQxsXFxsmMz8+cyBhPNJz9rzfmATBtdFrChjOLvla+3pVS+BmYdPnGYc55myQcizYrA0JvzQDVs6D6SXPb4SPYFyOPSCKFIVtSRhcoxUr/A7AK+PholIKzw9adMf+xkWgMfyXpBhm9jerH5hxxDzYdWmbqVaQ= 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=TNXJovvr; 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="TNXJovvr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724059758; 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=rudOnUhTj1NAei5RMGqP2l3kgXSLV5exml+muK1YojA=; b=TNXJovvr2hHgeEXn6P7Xs/4LAFrqXXc41DL8cNQjS/vBgHSASKWUy0n+BgaujEpbdHs4Sd bdgiI1B9wNOl9437gddxxVVnoh+yRLcrazFDFkz5tbDl0f/VHvKwkJNaAS+3X6ndR2Ivfy JWytfrCiTkImDnxIz0RagzCVd9GqolI= Received: from mx-prod-mc-01.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-283-tQ3K3C9KO76VYQ6srwQBGQ-1; Mon, 19 Aug 2024 05:29:14 -0400 X-MC-Unique: tQ3K3C9KO76VYQ6srwQBGQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 06EAC1955BF7; Mon, 19 Aug 2024 09:29:14 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BCE6B195605A; Mon, 19 Aug 2024 09:29:10 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RFC 3/7] vhost: Add kthread support in function vhost_workers_free() Date: Mon, 19 Aug 2024 17:27:29 +0800 Message-ID: <20240819092851.441670-4-lulu@redhat.com> In-Reply-To: <20240819092851.441670-1-lulu@redhat.com> References: <20240819092851.441670-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.40 Content-Type: text/plain; charset="utf-8" Added back the previously removed function vhost_workers_free() and renamed it to vhost_workers_free_khtread(). The new vhost_workers_free() will select the different mode based on the value of the parameter. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 52 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 6261c9df468e..77071def355c 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -647,8 +647,21 @@ static void vhost_detach_mm(struct vhost_dev *dev) dev->mm =3D NULL; } =20 -static void vhost_worker_destroy(struct vhost_dev *dev, - struct vhost_worker *worker) +static void vhost_worker_destroy_kthread(struct vhost_dev *dev, + struct vhost_worker *worker) +{ + if (!worker) + return; + + WARN_ON(!llist_empty(&worker->work_list)); + + xa_erase(&dev->worker_xa, worker->id); + kthread_stop(worker->task); + kfree(worker); +} + +static void vhost_worker_destroy_task(struct vhost_dev *dev, + struct vhost_worker *worker) { if (!worker) return; @@ -659,7 +672,7 @@ static void vhost_worker_destroy(struct vhost_dev *dev, kfree(worker); } =20 -static void vhost_workers_free(struct vhost_dev *dev) +static void vhost_workers_free_task(struct vhost_dev *dev) { struct vhost_worker *worker; unsigned long i; @@ -674,10 +687,36 @@ static void vhost_workers_free(struct vhost_dev *dev) * created but couldn't clean up (it forgot or crashed). */ xa_for_each(&dev->worker_xa, i, worker) - vhost_worker_destroy(dev, worker); + vhost_worker_destroy_task(dev, worker); xa_destroy(&dev->worker_xa); } =20 +static void vhost_workers_free_kthread(struct vhost_dev *dev) +{ + struct vhost_worker *worker; + unsigned long i; + + if (!dev->use_worker) + return; + + for (i =3D 0; i < dev->nvqs; i++) + rcu_assign_pointer(dev->vqs[i]->worker, NULL); + /* + * Free the default worker we created and cleanup workers userspace + * created but couldn't clean up (it forgot or crashed). + */ + xa_for_each(&dev->worker_xa, i, worker) + vhost_worker_destroy_kthread(dev, worker); + xa_destroy(&dev->worker_xa); +} + +static void vhost_workers_free(struct vhost_dev *dev) +{ + if (use_kthread) + vhost_workers_free_kthread(dev); + else + vhost_workers_free_task(dev); +} static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) { struct vhost_worker *worker; @@ -845,7 +884,10 @@ static int vhost_free_worker(struct vhost_dev *dev, __vhost_worker_flush(worker); mutex_unlock(&worker->mutex); =20 - vhost_worker_destroy(dev, worker); + if (use_kthread) + vhost_worker_destroy_kthread(dev, worker); + else + vhost_worker_destroy_task(dev, worker); return 0; } =20 --=20 2.45.0 From nobody Sun Feb 8 05:35:07 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 3CEF115C14A for ; Mon, 19 Aug 2024 09:29:45 +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=1724059786; cv=none; b=VgNsIdB1najOz3WyyoxIi+PhlxczGkGGyT3a9LKx5oVQLTk562Z0BXqUcdNWmlz8Qh0VXhjQOOp3ObhclNrGcEu5cio4/Bq2t9twyEOJEQO1Sl4PoGjQdS33jNtJLAbrwr33ig5xo3HosGns0GTZaVf4maDXd7B99xdq7U2g8Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724059786; c=relaxed/simple; bh=M+dU3ibVj7q+8DRRFffb7Kd3oOmzEvBP8a0XM44xMFA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qO9djMLV/jRoMAMKgzNPLFsVoTwQ0nXIra+7TkSUO0xxmVI5DNbxW5kyMviQrEnFUCXZRUKUBbC58ei/nNDfJFqXG9tWTEXLq8qwgPLjcEE4/Wi3T/yPNlUVl72/LaPFWfN4tKrYSas59B+N+uVpqbn1X32Ye36IrbLlHORDRi4= 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=aIULdlQW; 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="aIULdlQW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724059784; 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=TbN048JOymnb7G31Rvw0E2iKF8d+4Szk+FZ4EKSPjMU=; b=aIULdlQW5Pf1ui5WO4b3nai5nGMWmGPdrNIl7lyjbbiZMCp3T9pop4jhNfiHqLR9+9QBdx 2X5GS9ucGLRbr88rP7Lyln4q9p26IyXO/7XyUhOX79PWmYccimJLJQj0uFMhRQ73z2zBGu hkq1ZVMZSu6gSCD9L9qjemDUhPMcsg4= 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-63-S2RBoLtCNjKlvCS7RDgkIg-1; Mon, 19 Aug 2024 05:29:41 -0400 X-MC-Unique: S2RBoLtCNjKlvCS7RDgkIg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 527BA1955BEF; Mon, 19 Aug 2024 09:29:40 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B3713195605A; Mon, 19 Aug 2024 09:29:36 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RFC 4/7] vhost: Add the vhost_worker to support kthread Date: Mon, 19 Aug 2024 17:27:30 +0800 Message-ID: <20240819092851.441670-5-lulu@redhat.com> In-Reply-To: <20240819092851.441670-1-lulu@redhat.com> References: <20240819092851.441670-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.40 Content-Type: text/plain; charset="utf-8" Add back the previously removed vhost_worker function to support the kthread and rename it vhost_run_work_kthread_list. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 77071def355c..593f9521f51d 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -417,6 +417,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 Feb 8 05:35:07 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 E2E5315CD61 for ; Mon, 19 Aug 2024 09:29:46 +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=1724059788; cv=none; b=Ffk8RXTIr+k4DtBLGcRfgX55i2d/fsdHxZtL95lfbByODxV5QozwMzrhCuh1/Shpl/KK4t1hE/so/sf2N+8vSV8uHass9rs2EtZh/qqfdW5xh7nXKJx/h2s0K6C2uiVj8lCBMUiQmhiLLxmNGLWuok0iTikWopf+250Oc3tw0M4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724059788; c=relaxed/simple; bh=rKPlVLjhcIie/HzEaIKoKUFnl9YWoub0/1tLzlUDYw8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pTxdR0C4ccF+XwDXHE+JvxtPmeLGJviNB7MbRwg5rYJSE21DFTBj1uJxRXrq7Zf/pDvs5+ukXJtPEHmmD9GFU+dnwM9Gq3bUUnItZZShpnQZjzWgfYGkrylMSH6+oLNHYK0hG6g9+rrU4E7cc3lmWz2+8tnRkHTjwhwiq6tzp+E= 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=YNTh4/lq; 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="YNTh4/lq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724059786; 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=lzn2/qpEe9PAQb6Wft4arxClH7AS+j9JaAKqQeQEjbw=; b=YNTh4/lqv/45Ag5873cBRNSqdbbRN+vdY+/ScdCikWhUDfruIhmjoMyVAVnhQQLO/kp5sz KIw4g94sEkmKYJesVumv+BCGaSRsRUDHLqiR46MDtEYk53SfQVOK2f7B417TsCUZM7dQlD B9COXkYp9X6t2c/wI9KihQroA6yOPhk= 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-389-6r7lOoMRMzm6VKOwD4bUnA-1; Mon, 19 Aug 2024 05:29:44 -0400 X-MC-Unique: 6r7lOoMRMzm6VKOwD4bUnA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 EC74F1955BFE; Mon, 19 Aug 2024 09:29:43 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D7F0A1956054; Mon, 19 Aug 2024 09:29:40 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RFC 5/7] vhost: Add the cgroup related function Date: Mon, 19 Aug 2024 17:27:31 +0800 Message-ID: <20240819092851.441670-6-lulu@redhat.com> In-Reply-To: <20240819092851.441670-1-lulu@redhat.com> References: <20240819092851.441670-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.40 Content-Type: text/plain; charset="utf-8" Add back the previously removed cgroup function to support the kthread The biggest change for this part is in vhost_attach_cgroups() and vhost_worker_cgroups_kthread(). This is because of the change in struct dev->worker_xa. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 593f9521f51d..66ccda81f073 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -648,6 +649,57 @@ 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_worker_cgroups_kthread(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; +} + +static int vhost_attach_cgroups(struct vhost_dev *dev) +{ + struct vhost_worker *worker; + unsigned long i; + int ret; + + /* + * Free the default worker we created and cleanup workers userspace + * created but couldn't clean up (it forgot or crashed). + */ + + xa_for_each(&dev->worker_xa, i, worker) { + ret =3D vhost_worker_cgroups_kthread(worker); + if (ret) + return ret; + } + return ret; +} + /* Caller should have device mutex */ bool vhost_dev_has_owner(struct vhost_dev *dev) { --=20 2.45.0 From nobody Sun Feb 8 05:35:07 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 1F6E015CD6A for ; Mon, 19 Aug 2024 09:29:52 +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=1724059794; cv=none; b=DpJQOcwYlFrnX+jLGFLRryu9Ebi0aqLae8yctl/iWWtsGe84LO9rscXOR4fmJETV9PoM1KGj5r0vWBadESR673hE599R0TMePGyOdm8R2FsBuHWsjNRLn6NpMa7uE2SAJUt725WDyuYzaTGOrKCTDcBW4/4k4lYk9gG2Sys/cbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724059794; c=relaxed/simple; bh=efxH1sSMf2klEJ3PKsOaBGUtqvILrO2zUnw6BNzKIls=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=szf8uAxmTahcRiinvCz9Md56jbaBuGtDMCdpOECK8pL9jY11f+QD5aOq9VhFpupHcmO3WOFX8sIm87uOIm9ly3hjyNHfXnxq9jJIin71tu6em4jEkwJcNOMFDnpUaedSuJs75Ri1mc2xLZRcxsMrpSa0t9tRsqzaci9BHNo7umQ= 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=LHEJ4Yow; 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="LHEJ4Yow" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724059791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oI5nhMa1kRbv7aaOFKvTmUft8jmCwPzAMkkkRLDVCLg=; b=LHEJ4YowWiKqe0CF2eH4gmIO58r2mYYBViU7ymCbt21HjSTY8eWXZ+KG2so6k6Eo7kbd4G ZUraakRW+Ss4tkWG2pwjos7lMVe8r4LXbrTvT1nwPvAYIz4Uird8qFuFt8yoYTlfOo23pE UvdhoXYKf3m3GlhlfHgokVG3aA+XH6w= Received: from mx-prod-mc-04.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-246-GmO9l7eEPwuZiOAHHJ1JPQ-1; Mon, 19 Aug 2024 05:29:48 -0400 X-MC-Unique: GmO9l7eEPwuZiOAHHJ1JPQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 91BD21954B1A; Mon, 19 Aug 2024 09:29:47 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9F2191956054; Mon, 19 Aug 2024 09:29:44 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RFC 6/7] vhost: Add kthread support in function vhost_worker_create Date: Mon, 19 Aug 2024 17:27:32 +0800 Message-ID: <20240819092851.441670-7-lulu@redhat.com> In-Reply-To: <20240819092851.441670-1-lulu@redhat.com> References: <20240819092851.441670-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Split the function vhost_worker_create to support both task and kthread =C2=A0 =C2=A0 =C2=A0 =C2=A0 Added back the previous old function vhost_worker_create and rename it to vhost_worker_create_khtread to support the khtread. The new vhost_worker_queue will be selected which to use based on the value of the parameter. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 66ccda81f073..0a7b2999100f 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -807,7 +807,8 @@ static void vhost_workers_free(struct vhost_dev *dev) else vhost_workers_free_task(dev); } -static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) + +static struct vhost_worker *vhost_worker_create_task(struct vhost_dev *dev) { struct vhost_worker *worker; struct vhost_task *vtsk; @@ -848,6 +849,50 @@ static struct vhost_worker *vhost_worker_create(struct= vhost_dev *dev) return NULL; } =20 +static struct vhost_worker *vhost_worker_create_kthread(struct vhost_dev *= dev) +{ + struct vhost_worker *worker; + struct task_struct *task; + int ret; + u32 id; + + worker =3D kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); + if (!worker) + return NULL; + + worker->dev =3D dev; + worker->kcov_handle =3D kcov_common_handle(); + + mutex_init(&worker->mutex); + init_llist_head(&worker->work_list); + + 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->task =3D task; + wake_up_process(task); /* avoid contributing to loadavg */ + 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_cgroups(dev); + if (ret) + goto stop_worker; + + return worker; + +stop_worker: + kthread_stop(worker->task); +free_worker: + kfree(worker); + return NULL; +} + /* Caller must have device mutex */ static void __vhost_vq_attach_worker(struct vhost_virtqueue *vq, struct vhost_worker *worker) @@ -936,6 +981,14 @@ static int vhost_vq_attach_worker(struct vhost_virtque= ue *vq, return 0; } =20 +static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) +{ + if (use_kthread) + return vhost_worker_create_kthread(dev); + else + return vhost_worker_create_task(dev); +} + /* Caller must have device mutex */ static int vhost_new_worker(struct vhost_dev *dev, struct vhost_worker_state *info) --=20 2.45.0 From nobody Sun Feb 8 05:35:07 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 594DA1607BF for ; Mon, 19 Aug 2024 09:29:58 +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=1724059799; cv=none; b=TAkJbnrBzqbT1Z0I2mtLKXXPX5apj3oao/ufiNkWgram7Vi4KLOaTu8m+bi+LIHPZKIoCfbP/vWoNIoZSp+xSvHdHFlkSY7SUL3Pusxgvjf+yu+C7iGeIiYBXWEhn1tvU2oDH3QRtXai/xj1AISD0+0upe48P3csD4iB7vdKfoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724059799; c=relaxed/simple; bh=JqTw+gimEBK2T1Y5GytfqaF/hsyvkel0HokYkqbxXuI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qm/KOmyPyJpvjt5GaiAVPOyeuFfHDdatuCBuMDeuv0z8e55aDOmOH+1PoYBM6Yx2nQiBXvQtu4+/2slO26VTNWr+TUEROSlUk3SAXD7Wp/Re9CrtC9X2MHMT41D5gvdwXRnc5bdgJhYHomWPQhOl5Wm4s7Hylq4DI6AdVY4I9/8= 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=g2cGXP21; 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="g2cGXP21" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724059797; 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=ETsgpKbPtWULjBo2gaCD6rFNqT/vhyWhAo8UmZ8FOuk=; b=g2cGXP212QKb1wp53qHz5QLKBV96rZwfxpxpB5g4B2Avj+FPYM6HBBw/eUVHNOZh4jpn3x RWXaeVtXJn29IY/BeQf+sTlJJUynd+8us33nUR1d76fVkdloaUCkkZyZQQQUkfp1BJ4xym M/6cnqeqyDikVZJVE7dP5w+d89HcpIo= 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-584-WYpDt3yrM9eQ0kKKvQkc-w-1; Mon, 19 Aug 2024 05:29:52 -0400 X-MC-Unique: WYpDt3yrM9eQ0kKKvQkc-w-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 70FC71954128; Mon, 19 Aug 2024 09:29:51 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.11]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 648601956054; Mon, 19 Aug 2024 09:29:47 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RFC 7/7] vhost: Add new UAPI to support changing Kthread mode Date: Mon, 19 Aug 2024 17:27:33 +0800 Message-ID: <20240819092851.441670-8-lulu@redhat.com> In-Reply-To: <20240819092851.441670-1-lulu@redhat.com> References: <20240819092851.441670-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.40 Content-Type: text/plain; charset="utf-8" Add a new UAPI to support setting the vhost device to use kthread mode. The user space application needs to use VHOST_SET_USE_KTHREAD to set the mode. This setting must be set before VHOST_SET_OWNER is set. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 11 ++++++++++- include/uapi/linux/vhost.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 0a7b2999100f..d6b71bddc272 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2340,14 +2340,23 @@ 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; + bool kthread; =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_USE_KTHREAD) { + if (copy_from_user(&kthread, argp, sizeof(kthread))) { + r =3D -EFAULT; + goto done; + } + use_kthread =3D kthread; + goto done; + } =20 /* You must be the owner to do anything else */ r =3D vhost_dev_check_owner(d); diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index b95dd84eef2d..386fe735da63 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -235,4 +235,6 @@ */ #define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \ struct vhost_vring_state) + +#define VHOST_SET_USE_KTHREAD _IOW(VHOST_VIRTIO, 0x83, bool) #endif --=20 2.45.0