From nobody Sun Feb 8 19:41:30 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 AA51417BAF for ; Mon, 9 Sep 2024 02:02:02 +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=1725847324; cv=none; b=hB0qE1kfETY8Yhtr8vo4zUbC9GX+cibkg91Wx58zetRlg64JZNwFIVYW0fzOypHvILYwPiViyiFiYxbshXowPfPsg4xhQ4sydttbSfi0QcFKJwh79KaWjwJe4eqoPawtbvnSFP93lBQsFlhex9TozF2InjZEmG655U2Yj+DuyxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725847324; c=relaxed/simple; bh=Ak4RUYn1eA5rfEtC6UaT2NAXVhW2XNZwTEkhokuf7aA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h7i6o/I68uYL+qj9Oog3DmtZbE+GUVyDQW0CZ8e6btnQnzRknSVSEu6kpn59SVgzGUNsNsirx/AkuLnsdl6D9CBqYi+4odXxWZpuP1Kd15pE07eNSWyHeBtFe8+QgM3irm2hmrex5sZXpJMFmZVAvSXn5GAqlxuexVIghbjFs9s= 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=ZynIk91k; 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="ZynIk91k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725847321; 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=zkgZukq1NH7xZqgst5PAi/0pE3TPAwASepcK6DYlOEo=; b=ZynIk91kqr4z8ZV3ho+lJNxw5TEFt5nWNOXGR0eqqtjCtcsVUL582VmPTXBAlLvhzKXW1r x7cNBIGO/D4AsaeNRJDemhsAa87egQ+fG1dj5Tmmeer97kZmp84PhzWZ6VoCel3MXijpkJ bRAM4LbphZGmH/fByKxuaGhduCAbgLI= 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-381-kwgtn3btOuilcuSSm7lDBw-1; Sun, 08 Sep 2024 22:01:59 -0400 X-MC-Unique: kwgtn3btOuilcuSSm7lDBw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 5EDBD1956080; Mon, 9 Sep 2024 02:01:58 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2BF21956086; Mon, 9 Sep 2024 02:01:53 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RESEND PATCH v1 1/7] vhost: Add a new module_param for enable kthread Date: Mon, 9 Sep 2024 10:00:39 +0800 Message-ID: <20240909020138.1245873-2-lulu@redhat.com> In-Reply-To: <20240909020138.1245873-1-lulu@redhat.com> References: <20240909020138.1245873-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.15 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..be43181af659 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 enforce_kthread =3D true; +module_param(enforce_kthread, bool, 0444); +MODULE_PARM_DESC(enforce_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 19:41:30 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 5F23D1C69D for ; Mon, 9 Sep 2024 02:02:08 +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=1725847330; cv=none; b=g9WWsXdgxv/hzmjI0OGUTwTC6P+dLNV0rMy9++4bfwbHWnaiGoIkFEymKPrLG9tglFxUIbCEaGihkYVB1pqifVymGuTJyXIMWu2zUN/nbgtC/j8ebVyB8dOa/GAm1xgiccWqXUQ7dZg6JxYvzhz4xX7ftT83WvRdFuZSjsGN2Ng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725847330; c=relaxed/simple; bh=1jyVcSPfekZqM9Yp6FkpCVLNycaGSQ/72IfGmPj7gDs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oPFfpqWxQHWuhDM/3iKPBCPWlJBX1LtsQNPPxwYsBkgViMD9m3/7GGqTkst7TXqWxoowBAXA8ye9VknySP2ujsHkx2DBbBhqUx6dTkQjEyWeQ9EGTPlktzU9cOl7BM7IH4kJfwkLO1YdGB/b3/3W7p6QhGbvjoapLYoJIGAN8fo= 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=ICVT6Pet; 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="ICVT6Pet" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725847327; 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=16JoM8Mgvw7U3L3TUK8QhKHLZmzZfWIlUgzLKKumFcc=; b=ICVT6PetJif1xn90xfmqUDTsJ96Fyaq/S2MPkyY4NbJ8D8SB0fg1v/mR90BJkagEOtKmTm Y/BmTcsFTZa02nhegba6a/vxPNJShKSJaU5y2Axc5Hu7rouy5DWNEK5sdKd7BhgvhYwcqp Zoc/bI3IS+7httUm5uutNyVQHiEzG50= 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-191-yAVCFQQIMTmmWZ1b1D7XxQ-1; Sun, 08 Sep 2024 22:02:03 -0400 X-MC-Unique: yAVCFQQIMTmmWZ1b1D7XxQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 BB6961956057; Mon, 9 Sep 2024 02:02:02 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0433A1956086; Mon, 9 Sep 2024 02:01:58 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RESEND PATCH v1 2/7] vhost: Add kthread support in function vhost_worker_queue() Date: Mon, 9 Sep 2024 10:00:40 +0800 Message-ID: <20240909020138.1245873-3-lulu@redhat.com> In-Reply-To: <20240909020138.1245873-1-lulu@redhat.com> References: <20240909020138.1245873-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.15 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. The old function vhost_work_queue() was change to support task in commit 6e890c5d5021 ('vhost: use vhost_tasks for worker threads') changed in commit f9010dbdc ('fork, vhost: Use CLONE_THREAD to fix freezer/ps regressi= on') and also was change the name of function to vhost_worker_queue() in commit 0921dddcb5 (vhost: take worker or vq instead of dev for queueing) 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 be43181af659..ab4608fcf86b 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 (enforce_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 19:41:30 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 F01F51CD16 for ; Mon, 9 Sep 2024 02:02:12 +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=1725847334; cv=none; b=f5+on1OSbMy+Qtu1yQeYnSL6qr7Yf+rXFrvnRVcG3+/N0h3OS05BFBjO5s9ZnKjTZX2mRdJh8S7qhuQH5puVMrWauCRwlnupEU471/fYEy8ntnPHQ2zo8J/Qtd7qCbDy7YdB3uTIfrJ0b+dP/rwfGJT8YguyfuU2yee0Thiih5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725847334; c=relaxed/simple; bh=EkRHJb5RZNeNBEkKpyo5YbQvL6WrbchVnkZM21iwMJQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OWGumCHCUJAZCsRTQJjgv4ehWgv2b8IjwzrIRFjhu4Fam8zlZhdA+2f7oqeLlpS5a5WklQNorE7vVdea9mkoH1S0X0TJA2PBCGfXT6iZj4GCiVnxvLLWW+mR5EQyCPIJGGZ50KLf4IRjQe7RqRoV7zZYO1ZBRrbUG6jfSp0rQhk= 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=XNEfMboT; 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="XNEfMboT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725847331; 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=Sdl4Ti7H8Zn8CJdFokcfn4yA/bPmnyZMHZeexqaTaMc=; b=XNEfMboTAryhTfLsMp27iTrZ0I+sOXzFL/9Surn9R4QTthtbi4iTosCzojEzK9oWK+aToo PQt+sdIaoHnU7uFas9x+JtnxeOJtu2ZU8CovmrRoi3dg8wCYWtV6EhIst1hulIxK7iEXk2 JNYEVwLyKbv/wWm2qAH1LFPcZmgFrXo= 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-499-8vsL1yYvNqGWjVgFrfAi-g-1; Sun, 08 Sep 2024 22:02:08 -0400 X-MC-Unique: 8vsL1yYvNqGWjVgFrfAi-g-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 82CB719560AD; Mon, 9 Sep 2024 02:02:07 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8B8601956086; Mon, 9 Sep 2024 02:02:03 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RESEND PATCH v1 3/7] vhost: Add kthread support in function vhost_workers_free() Date: Mon, 9 Sep 2024 10:00:41 +0800 Message-ID: <20240909020138.1245873-4-lulu@redhat.com> In-Reply-To: <20240909020138.1245873-1-lulu@redhat.com> References: <20240909020138.1245873-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.15 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. The old function vhost_workers_free was change to support task in commit 6e890c5d5021 ('vhost: use vhost_tasks for worker threads') also changed in commit a284f09effe ('vhost: Fix crash during early vhost_transport_send_pkt= calls') change to xarray in commit 1cdaafa1b8b ('vhost: replace single worker pointer with xarray') 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 ab4608fcf86b..da4482efd2cb 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 (enforce_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 (enforce_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 19:41:30 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 49F8517C95 for ; Mon, 9 Sep 2024 02:02:40 +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=1725847361; cv=none; b=aMtvcGHCsMXCe+KYPkgtz12AInanNP5vEHBZyqdToX3P1V+10hyapd7KSD5Khrvyu1/Yvrf2xS1lymy3a7sobod6m85RvrCpbhGDwCkBKirWx+xYWpuihX4V182j/8jGlHWZkthj5BDBl3cQ7Z1aIq6I+5+aPEUqDaPaIolMsC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725847361; c=relaxed/simple; bh=qJaMvTfh6TlK9PsGkrOaVC6lyH5ftHzX/zP7cLpr7w0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=daCrjdI1F6wt+HmVHIN2pA6qTGcbW+0AuWdVw/MiPAW5rMjpVJTPFa38aT8n8kkBNlQS8DKFYC9jKxrF/DWnPr71+ec+3ojlLN+TI80esnKZTNBFbrKBHvmqKqpxVfZGSoSoIKjljWYvjxotMSndI5Y/G1YqXvZ4I3/0wk5tcU8= 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=ERgxjGQM; 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="ERgxjGQM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725847359; 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=lUQmJjvpDINXxGUYt1mwnxhgx7/iglTBT4EZYawdvpk=; b=ERgxjGQM6hxql4RDRe+Zu/GOp41c5pZ01deVld2KXOZVL7ff3rtXu9KXdj2V2thlKrn7yr I/Pfi5dBwqS/hr0hMviUs8mhXogcBWugVWQdj0uFu8gWCxk9LTt/w4Tc+VZvHFPYzcSKwU Mw382QPR0Nahk41+HbCYq5AUMMn5haU= 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-584-_75fothjNR6kdV0OTdeI8A-1; Sun, 08 Sep 2024 22:02:36 -0400 X-MC-Unique: _75fothjNR6kdV0OTdeI8A-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 1761F19560B8; Mon, 9 Sep 2024 02:02:35 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BE8331956086; Mon, 9 Sep 2024 02:02:30 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RESEND PATCH v1 4/7] vhost: Add the vhost_worker to support kthread Date: Mon, 9 Sep 2024 10:00:42 +0800 Message-ID: <20240909020138.1245873-5-lulu@redhat.com> In-Reply-To: <20240909020138.1245873-1-lulu@redhat.com> References: <20240909020138.1245873-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.15 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. The old function vhost_worker was change to support task in commit 6e890c5d5021 ('vhost: use vhost_tasks for worker threads') change to xarray in commit 1cdaafa1b8b ('vhost: replace single worker pointer with xarray') 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 da4482efd2cb..0bc4f75ae1b9 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 19:41:30 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 2CDC31B285 for ; Mon, 9 Sep 2024 02:02: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=1725847367; cv=none; b=SOIFOaRtu+IqCJpdKLos+LXtqgMl/yAJnGkoPmNkCMw6lSGSBN1KHyHI0AceTDSN0dN7rJwoa1kpWcastDx9zWZw+Mlr66/FbfoBbQmbHQCdHcaxVkzaK3ss3YIbiy3Xsw2NSiFkbZJVSzYncRThSDFX3ltW9PRTYsoDyzSbS6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725847367; c=relaxed/simple; bh=zqlaRlnd05SD5oB9AsO/uvrsBJ0II+JX0ru8cmar6Gs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KY53YZOFgU16jH1NVCQjkKWpb7gWdu38MFQc7bKhbF1sQrqeCNiE87sUXDPCUoUgQaDS0qK+CZaidVykzpqrlLv+DkNnt7u6Bh/zE5hSXRkBg/YKE8Tcc7s+QpqiaKs08CCSgIT2kc9uuQSedyjpXuAcTvzfo8Odl9LM+N3GRyY= 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=HMsJEB6w; 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="HMsJEB6w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725847364; 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=6tabn+YpAyhcfuddzHNvGrDvZ0pmns8bGlBy77mmbWM=; b=HMsJEB6wHofy9QaVAbCge4kiwjvnGfexOwJJej+PvUAtR7CUcvxqUkxlMp4p86HPVMKleO LFfjX/R3RQz7u56ilpX3XZEU6HkWPm8hVGvVC4WCCkkcq1pXHoZuYE4bsnlF6Wxmpg1gxS NDdTS6TlMl4g+duB8Xas2EFewcOtkPg= 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-649-nJYzlgIRN5qc9smty4H8sA-1; Sun, 08 Sep 2024 22:02:41 -0400 X-MC-Unique: nJYzlgIRN5qc9smty4H8sA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 87DB41955F10; Mon, 9 Sep 2024 02:02:40 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C39001956086; Mon, 9 Sep 2024 02:02:35 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RESEND PATCH v1 5/7] vhost: Add the cgroup related function Date: Mon, 9 Sep 2024 10:00:43 +0800 Message-ID: <20240909020138.1245873-6-lulu@redhat.com> In-Reply-To: <20240909020138.1245873-1-lulu@redhat.com> References: <20240909020138.1245873-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.15 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. The old function was remove in commit 6e890c5d5021 ('vhost: use vhost_tasks for worker threads') 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 0bc4f75ae1b9..46b15e9c0693 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 19:41:30 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 74BC318C3B for ; Mon, 9 Sep 2024 02:02:54 +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=1725847376; cv=none; b=c79IuIk3YSmx8Tuh12UtArNOtsj+UfBYr3SfEQ56cJbVqGXiXdKp5o4t8ER61EObUPNMoe20ARhGnDV53pjedF0hOpene3sfb/JCfnNUDNMoEqjJomrmBtt+6UTih+tTWaAqwk82+h9ltGCfqDSXI6vzmHXQ/H6lEHnprrTgphw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725847376; c=relaxed/simple; bh=QQqC0BM8LdyqKa0sPlX1xLwT8vY7erzuIjQMScwcQNQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WZtzn4w+W1ypB76K1jTrbqIIeWdhXOvmPe/fpz68UVruTMZYl7s+Fk5xPQ2BG8d19em7iQpG1d/NmzEgMk+5qPhpJUyT101ujyvchuvAnx0ta8wWDubm1g5Akx42mTXSuCeqXbA3pfSY6rbDHzyVGsogRrXtzopmHiscXvMBs74= 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=VpdmUaNL; 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="VpdmUaNL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725847372; 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=mhyb1S7F4CzbTneG1JPeiJSHHBElEO8SQAMRCi7GVgg=; b=VpdmUaNLO1dHBVzsn2AbcAtgDLHW+wa73f82VQ+jT4xArGBcFHCCdUEVYRnIFJcUUl7Dix eqy6/CdzdmyEpToxNwokyrZBRCtZcQGAM+zi8xp8vcvO0wD87be3O81/nKed3UmKhMipI+ Vy6tzpK+zF82RhT0wv6wu6F76+Uqop8= 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-350-oStbUJyrPlmf1wn8XgX1bA-1; Sun, 08 Sep 2024 22:02:46 -0400 X-MC-Unique: oStbUJyrPlmf1wn8XgX1bA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 6C9EC1955F41; Mon, 9 Sep 2024 02:02:45 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5DE981956086; Mon, 9 Sep 2024 02:02:40 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RESEND PATCH v1 6/7] vhost: Add kthread support in function vhost_worker_create Date: Mon, 9 Sep 2024 10:00:44 +0800 Message-ID: <20240909020138.1245873-7-lulu@redhat.com> In-Reply-To: <20240909020138.1245873-1-lulu@redhat.com> References: <20240909020138.1245873-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.15 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_create will be selected which to use based on the value of the parameter. the old function vhost_worker_create was change to support task in commit 6e890c5d5021 ('vhost: use vhost_tasks for worker threads') also changed in commit 1cdaafa1b8b ('vhost: replace single worker pointer with xarray') commit c011bb669dd ('vhost: dynamically allocate vhost_worker') 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 46b15e9c0693..838bce29a98b 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 (enforce_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 19:41:30 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 A67A11CAA4 for ; Mon, 9 Sep 2024 02:02:55 +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=1725847378; cv=none; b=mP46iElrD8j82P0M+n1Wmo4cPEgKzt/GqYxIrOluwHKQNkjts+sRllt49SYz7iDqzWLHirnuhQA5X6KhCwLjcNAad5sZKHHEDuCjBHnk/Q1L6SgtVfwxBIqSNAU9PETCL/I0PapqzIca4Wka/xZCqsJPCPM4CooFHJhz9but+mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725847378; c=relaxed/simple; bh=7/6gyxcweF78Fjvy/O/QlpRmVVa60Z+0o2DI85aQcUo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tI54ohe0KyDlKlBHIkDWt/YBEQ3l0QXDhmNr0jN2jZ73aGwUw0gix/mLVz5wCwzEf9faUAqRWBAYSe9lHY7mLBQuYAeFE3zKHkOnVItEy3IRvtN7y1DrHMRi5CtfkjLxYVKm+UKe+eMQ3NTUy835bTFD3tQMNFfWEn7hEEHqkSE= 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=EhRTLLsU; 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="EhRTLLsU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725847374; 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=HUQqKbxzWXipVdkbA2+5Zzkiohl4zLF2jPmYXNJwL9s=; b=EhRTLLsUR2UMVy0E62Ug0TjXy/rlPA3I7f0E1kr+6TWT066ZyUe9cF5CNFA1WOm0/8VgR3 p6fiehAei3SYQj7At3l8ND+3GY4p6+TooXE/dJQxfOL8oi5hI/VGSqzGKwVm4ZYuqqUxW0 mS2BfoJty4tcavZQozbMTzGpagnodbU= 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-358-dbXyhr2mNs2jntQsUSC6Xw-1; Sun, 08 Sep 2024 22:02:52 -0400 X-MC-Unique: dbXyhr2mNs2jntQsUSC6Xw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 53BBB19560BC; Mon, 9 Sep 2024 02:02:50 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 321CE1956086; Mon, 9 Sep 2024 02:02:45 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [RESEND PATCH v1 7/7] vhost: Add new UAPI to support change to task mode Date: Mon, 9 Sep 2024 10:00:45 +0800 Message-ID: <20240909020138.1245873-8-lulu@redhat.com> In-Reply-To: <20240909020138.1245873-1-lulu@redhat.com> References: <20240909020138.1245873-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.15 Content-Type: text/plain; charset="utf-8" Add a new UAPI to support setting the vhost device to use task mode. The user space application needs to use VHOST_SET_ENFORCE_TASK to set the mode. This setting must be set before VHOST_SET_OWNER is set. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 16 +++++++++++++++- include/uapi/linux/vhost.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 838bce29a98b..8fd19a1489e0 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2340,14 +2340,28 @@ 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 enforce_task; =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_ENFORCE_TASK) { + /* Is there an owner already? */ + if (vhost_dev_has_owner(d)) { + r =3D -EBUSY; + goto done; + } + if (copy_from_user(&enforce_task, argp, sizeof(enforce_task))) { + r =3D -EFAULT; + goto done; + } + enforce_kthread =3D !enforce_task; + 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..9853d62d2d34 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_ENFORCE_TASK _IOW(VHOST_VIRTIO, 0x83, bool) #endif --=20 2.45.0