From nobody Thu Nov 28 04:40:17 2024 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 582CF1CAAF for ; Fri, 4 Oct 2024 01:59:55 +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=1728007196; cv=none; b=lK/9rlzHDSUXwEguFaPayOrhd5EDrlyHAxcWdtfzbi485VJ0peO/EHBtXrtVXwJMg+z5TF0a+Mu4xY+k4rpgjKaYDQrQ+JwE3+vucrmAKHCUS0k5B8TBGeTc/ClAeTrgPCdeCmKAWt9NbDepbd4H6a0aFkQV3tb75vRJx+Wpdq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728007196; c=relaxed/simple; bh=zrQT/I2PK5lAcMS9tlIOjHCcoibHU9rgFnqoXsDWCX0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g21uvgXmDR/FM7nOwn1EteggtD5cIb6TxfZLmPPQnBmYAmBJ9Rd8hVaRsNvo4cQ7fP8O2GKqOuEH1r8U3O+7xgdG9JjUFjBbrULaaoxj8wv2R0lpixgaQ4OIzA+velMK21Y9s6P0BgX+2grIpZXMSbDRpX3QhOf5je62rsWHhGI= 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=FkKwrb2k; 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="FkKwrb2k" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728007194; 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=8qQE2RJORatJZ4HbSL1fxpt77UC2FjfgZSgKiByM6mc=; b=FkKwrb2knDABJnxWNVN/AJWMW0gC28Cv6PiCNHTeGoyVAQ1FnFYQqtDn4tox5yB5tamzwe 0EoPlEkNF9duReUoUwTGru42/1hsGMjZPuVvE7Jkl1XB22TtUkJENam9hpTg/bnnOEXhq6 bzHm20rq+qRM4Wlb/yp7SBux5b2mDiQ= 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-571-NvTDSUtvPEOnbRzjKMyEXw-1; Thu, 03 Oct 2024 21:59:51 -0400 X-MC-Unique: NvTDSUtvPEOnbRzjKMyEXw-1 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CCF0519560AB; Fri, 4 Oct 2024 01:59:49 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.45]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 15DF319560A3; Fri, 4 Oct 2024 01:59: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: [PATCH v2 1/7] vhost: Add a new modparam to allow userspace select vhost_task Date: Fri, 4 Oct 2024 09:58:15 +0800 Message-ID: <20241004015937.2286459-2-lulu@redhat.com> In-Reply-To: <20241004015937.2286459-1-lulu@redhat.com> References: <20241004015937.2286459-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 is now using vhost_task and working as a child of the owner threa= d. While this makes sense from containerization POV, some old userspace is confused, as previously vhost not and so was allowed to steal cpu resources from outside the container. So we add the kthread API support back Add a new module parameter to allow userspace to select behaviour between using kthread and task Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 9ac25d08f473..a4a0bc34f59b 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -41,6 +41,10 @@ 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_inherit_owner =3D true; +module_param(enforce_inherit_owner, bool, 0444); +MODULE_PARM_DESC(enforce_inherit_owner, + "enforce vhost use vhost_task(default: Y)"); =20 enum { VHOST_MEMORY_F_LOG =3D 0x1, --=20 2.45.0 From nobody Thu Nov 28 04:40:17 2024 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 66DFF288B5 for ; Fri, 4 Oct 2024 01:59:59 +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=1728007201; cv=none; b=sbkFL8QMxuONegZ8XugSnkyo76IUsiINMUzUAxWVNKDTLj0oALzcd73ej3tAfdnJPigBdFrctjZfkDFpkWP+19QJK4HB1PE9okOKuXxw1bqu0OKlp0Rpus6z3+ZXv0tZRwbC5h5YyTMYW8U5yq3eP5fEzpzqcsJ1bNmQcpll5zA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728007201; c=relaxed/simple; bh=/dwRUtLQMuNrkI7BnDhn0e9yx3Htk8dRbVux8u/QHfc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TlFqv3Yo2JC+lnASJhEFs16cFiW598ZkycuVv4Kkm3AT7R5vTTVdkvNDvSCJccqDw0iCrTv8/rLROkSLWG4/uKNyVrQKTqe0dyfyPfFP6o/dAB5IkHj2uivRgYxccWEcGH0bFsHH2E3a4EPxUBn80jiwPimgegQptWL2M/X1OB8= 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=bt6RELeH; 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="bt6RELeH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728007198; 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=ULQjL8SAWvac/iPOoiJqTiPvXj5aDYtkhU+eRT8XVsk=; b=bt6RELeHLnwFrTczdoHH1AY/GzCUQ6wgFHQb05SExGRkUPo0YnbrWSLipiSr+bh/5SZUPB poMb+hEQe0Fg8fEjp/uewMJdmIcYujp4ZiX3aZPnc24mQPcHz6igRgzV1TLrbv0S9kCjkP rhI5j4jClpwnbmuxVOh/0lQbKH7jFhc= 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-593-niA-mfUOPLq5XAbh04mlew-1; Thu, 03 Oct 2024 21:59:55 -0400 X-MC-Unique: niA-mfUOPLq5XAbh04mlew-1 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 2A7831955D95; Fri, 4 Oct 2024 01:59:54 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.45]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E5D519560A3; Fri, 4 Oct 2024 01:59:50 +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: [PATCH v2 2/7] vhost: Add kthread support in function vhost_worker_queue() Date: Fri, 4 Oct 2024 09:58:16 +0800 Message-ID: <20241004015937.2286459-3-lulu@redhat.com> In-Reply-To: <20241004015937.2286459-1-lulu@redhat.com> References: <20241004015937.2286459-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" 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 f9010dbdce91 ("fork, vhost: Use CLONE_THREAD to fix freezer/ps regre= ssion") and also was change the name of function to vhost_worker_queue() in commit 0921dddcb589 ("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 a4a0bc34f59b..ad359d4b725f 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -237,8 +237,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 @@ -250,6 +250,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_inherit_owner) { + vhost_worker_queue_task(worker, work); + } else { + vhost_work_queue_kthread(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 Thu Nov 28 04:40:17 2024 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 E39B41B7E9 for ; Fri, 4 Oct 2024 02:00:14 +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=1728007216; cv=none; b=NU00xOKveTra4IS+qYKqDvTGCUtFQow+9nOrPMsXW8K8sPdZTpL4gXp/BV/yW5sCRnmMiWXdkb20Dcm2OhUQNGmciUT/+vP1+eat+nANSfhFNN5f276XaNXNFY5wl4CK49Zf7F5h60B2hVplyoaCKj4DsCzBg9E4umDwuyzrMlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728007216; c=relaxed/simple; bh=BjJr59mp9uuv2YmTKWyzhnhDDsNGKnGb+2hQDETXr2M=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p3y0FfwhNWp6x0vL7SxrL0pED/7/h8SEceIYyGjDa5xCm8Ln09EaDWS4ENeHOJ6O6zm69beniYh3BkXnS+G6ymAR/V94KH3cvNkCz3BsePzsE/ax/h2s+Ito3TPUB2JGSh5edasXku8+HUeya4QeDKY4ZGxRlU4Z2JBI6nBSlBo= 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=WacstYPt; 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="WacstYPt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728007213; 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=ocgoI1lOofS6GZhyj4LGKPzfRZFIHFLkb07SAt9nUao=; b=WacstYPte6ixydlaBOTXIlkPYPwtjoMAYqGTxa40WPD9MCZSreTQlIIFpRmhTNiNIbh/VY Q6ix1gvG0pAmiKitNh12QEOkpPjRR4O3fDOzuT5Yo/RfsYa+M2C0Tigt1hCrUvkNrfHFZF Yw7Rl3RKW4/5HqM+qXzr+73dMG7y6hk= 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-629-311buRSkN1GuMCITReGcrQ-1; Thu, 03 Oct 2024 21:59:59 -0400 X-MC-Unique: 311buRSkN1GuMCITReGcrQ-1 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 44F0719560B2; Fri, 4 Oct 2024 01:59:58 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.45]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2BF219560A3; Fri, 4 Oct 2024 01:59:54 +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: [PATCH v2 3/7] vhost: Add kthread support in function vhost_workers_free() Date: Fri, 4 Oct 2024 09:58:17 +0800 Message-ID: <20241004015937.2286459-4-lulu@redhat.com> In-Reply-To: <20241004015937.2286459-1-lulu@redhat.com> References: <20241004015937.2286459-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" 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 a284f09effea ("vhost: Fix crash during early vhost_transport_send_pk= t calls") change to xarray in commit 1cdaafa1b8b4 ("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 ad359d4b725f..fed6671c1ffb 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -648,8 +648,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; @@ -660,7 +673,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; @@ -675,10 +688,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_inherit_owner) + vhost_workers_free_task(dev); + else + vhost_workers_free_kthread(dev); +} static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) { struct vhost_worker *worker; @@ -846,7 +885,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_inherit_owner) + vhost_worker_destroy_task(dev, worker); + else + vhost_worker_destroy_kthread(dev, worker); return 0; } =20 --=20 2.45.0 From nobody Thu Nov 28 04:40:17 2024 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 07EF93D55D for ; Fri, 4 Oct 2024 02:00:28 +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=1728007230; cv=none; b=nwDC2qHFYXxPS6n2VFByYiPgmgWeXSbNKU/cs+KogcIooh55oCnDM111H//6HCJKKGoIon2vFOqbDbt7mpsV4cPq2wkKtsSRCDA27y0rnzbMY+xpORf/ntHvLBZfrYZ3B+VF2RGTgKmHgxtrOKt8y3h0wzJ8Ua0IQ0DKEcQQg2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728007230; c=relaxed/simple; bh=8AVf/hwze/5baY+1Gra15GOYyq2bi/jH2hqtiFjGc7A=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rZ38YiFdPNhDS5PMktxXkhSxFnnEHI7pazeZ0hD/ePfqJVBLfg2MSbW25/n6Vu4bUIXLpMmTsQWH6EtO9uIJMgZJifbgTmzaei9sin2a0p6aZN4rIVfoaWesFJL+t1hzlA88v1bWktBTJYJUY5ZWDqZidT68U7YjFKMj0HLrQh0= 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=GzG08dOc; 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="GzG08dOc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728007227; 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=ka5Cv+MBxLJO+Sw188++gI12rAdTxumDlQnEmXZkrew=; b=GzG08dOcOaAY3YKskWXVXoGSMVikkylZZCnZWrzmYVBSQ1kTNaN1VFy85qz55cYYUgtPs0 WYu6h2qayE1mCA4O1EBpIVtSRd7u/1OMNQYfBEpuEV9t4YTfa/kBDgrqTDftnFPg6uYvLm C7cf7GDqwqHVI5FtlloUNjSNb3rxU4E= 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-656-mTfJqz24M36r-R9G0ieiXg-1; Thu, 03 Oct 2024 22:00:26 -0400 X-MC-Unique: mTfJqz24M36r-R9G0ieiXg-1 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 2CE7B1955F42; Fri, 4 Oct 2024 02:00:25 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.45]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2F79F19560A2; Fri, 4 Oct 2024 02:00:20 +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: [PATCH v2 4/7] vhost: Add the vhost_worker to support kthread Date: Fri, 4 Oct 2024 09:58:18 +0800 Message-ID: <20241004015937.2286459-5-lulu@redhat.com> In-Reply-To: <20241004015937.2286459-1-lulu@redhat.com> References: <20241004015937.2286459-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 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 1cdaafa1b8b4 ("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 fed6671c1ffb..349499139f4f 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -418,6 +418,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 Thu Nov 28 04:40:17 2024 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 A82282AE8A for ; Fri, 4 Oct 2024 02:00:32 +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=1728007234; cv=none; b=hPDL95Kb0Lh1PrS6//QtXmRNJoxgNy2QBQHfK+dTj4I96gc+LH93ahlJ2IzjF3NZI+QaKkCA+jVPKLFJHmLjomv4K/Yv1Z7nvpNmvPZK5xofVleSlEUKcz1EQpDuM89OU18gwXvUoUWvh4pGq/ewHBEFzN5ZmEHV6OCIj+N4in8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728007234; c=relaxed/simple; bh=zjxmZ7yCPNr5FzfI9m9RlLaaV2g+LOs0OuJz7URLIhk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uAEZYyJ0BiWKA35LN03CR4qObx0w20PhSL3pqzNOZkYISp3DotX8dq3+S8kjcuUzOUqj/8EfrVMcUfRMrGFJQNayG6DUS3T1Z6AcDRNcK4uLbAIhigpSU9qfY8vfmG/vsXhTnwXYD2+89qjcTeTUlzgsiIrfy10pE9vJoKjdNWM= 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=DseNto1G; 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="DseNto1G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728007231; 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=rfPS8HLRSnQ9qcVq5kX+4iK0JJXiQpbCvSzpkaatVBQ=; b=DseNto1G/0+t7C5yJMrX359iqPYd2Gdl2rBhfUBR2OtjsEPygPAOE4Tlnu/yZ7ofbbIYbo 4/egrmrErILYLt94NEEAc0tP/oNWSpmzXJGdKW+45DlJvL+sBERRmrb7CcehWL14EwyDOd NbED4R/U1WoZYCqPfGZNJOGA6wOLi0A= 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-86-nOzjp9psOfOSnJS2uSGBNg-1; Thu, 03 Oct 2024 22:00:30 -0400 X-MC-Unique: nOzjp9psOfOSnJS2uSGBNg-1 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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 778CB1955F65; Fri, 4 Oct 2024 02:00:29 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.45]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D63D519560A2; Fri, 4 Oct 2024 02:00:25 +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: [PATCH v2 5/7] vhost: Add the cgroup related function Date: Fri, 4 Oct 2024 09:58:19 +0800 Message-ID: <20241004015937.2286459-6-lulu@redhat.com> In-Reply-To: <20241004015937.2286459-1-lulu@redhat.com> References: <20241004015937.2286459-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 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 349499139f4f..eb30da658bfe 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -649,6 +650,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 Thu Nov 28 04:40:17 2024 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 A71F345957 for ; Fri, 4 Oct 2024 02:00:36 +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=1728007238; cv=none; b=nbXfY8kUAe0+G9+KHFvPcZOv7CEv8ooCYnuLIPMC0nkke7FG0YwE2iVWUE9XxqF2QXl1xIplumhMnnmQpXABxNRyQ7a7BsxJZWOpod8e2xId/S4rSpn9v6W/bylFW4GQuOYTVWy4rzKCMg2G/gYdJ4lACHLrYfyhj0G0evk7QmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728007238; c=relaxed/simple; bh=ibksF1L5VO/D2Z/M7Fh0x+Uf1O1C2b7zoljoOkEL24Y=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wt01DENCYX2fpDkE7hkW/03bv8mn121o+5QWgrII64/xN6AEXpkoJ33T6MWmgM1JJ+7KxRoFOghUesQkl9UBgjS9N8FtTJ/8FsW08Pebr5KEfiLZMKmqimYTK59bMiRHTvDc1gZTzJMxx4ShYAQ4TWRD9U9uqJiiiPt6tB4w/SA= 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=feKVUXzD; 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="feKVUXzD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728007235; 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=QVlMkQ4oKYM9gBEztNWU+WNNZQwcLrOt4Z9NJVDjOHE=; b=feKVUXzD8QSm3KHgvBWH+DnUl1rn43zHwp+PU/vMgZZsBHIVTLz+CH0x0tRuqW/NSMdOlH BTRg8eluOrWA3Rs7JHlH9yijK2oqUw3AvKtFWn7ar5GqTC0YcBIRzV0EVXmne6VbmumIOw rItdAXK5dyXZnZpPFzMx9om0RjkrNW8= 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-104-90JBbasfNli1cM-4pjlN_w-1; Thu, 03 Oct 2024 22:00:34 -0400 X-MC-Unique: 90JBbasfNli1cM-4pjlN_w-1 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 6CF7619560A3; Fri, 4 Oct 2024 02:00:33 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.45]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 10A5A19560A2; Fri, 4 Oct 2024 02:00:29 +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: [PATCH v2 6/7] vhost: Add kthread support in function vhost_worker_create Date: Fri, 4 Oct 2024 09:58:20 +0800 Message-ID: <20241004015937.2286459-7-lulu@redhat.com> In-Reply-To: <20241004015937.2286459-1-lulu@redhat.com> References: <20241004015937.2286459-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" Split the function vhost_worker_create to support both task and kthread 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 1cdaafa1b8b4 ("vhost: replace single worker pointer with xarray") commit c011bb669ddc ("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 eb30da658bfe..08c9e77916ca 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -808,7 +808,8 @@ static void vhost_workers_free(struct vhost_dev *dev) else vhost_workers_free_kthread(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; @@ -849,6 +850,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) @@ -937,6 +982,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_inherit_owner) + return vhost_worker_create_task(dev); + else + return vhost_worker_create_kthread(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 Thu Nov 28 04:40:17 2024 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 DF2214AECE for ; Fri, 4 Oct 2024 02:00: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=1728007242; cv=none; b=luMnQfee+TY7Yk5He0exLFzQPUD3UVnromUg8UvWs2NuS2G0H/iJZsz+B7jmklrfXo0lNf/+DR26ocCeNZi46HWbTm1QM5ZRmGSJkv4lXNGxt83sKf2o8x01wGKj5ciFTwtKdUxlv9wKDPM2OdRqPwgSy7xjeLcbML5v/tbAb2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728007242; c=relaxed/simple; bh=gM+UhBnXUXjuBqKMUIBkJEkaZoSzsbYH910Eh3g1cjY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aFNGvPOnvYNPXA6RSLY4xuWjC8Vul5G5P/JWaBZnGyW35qvWDNMxbryeLsrjwcIKhR8HBh9SfjBI6ycgEE1Sjax0PAC3CZ1eZBG8JzGe8menQ2Amng2i61e/+UeXTZZ1T7tsVsHiyfdqkuTHjVlGBaCHMfiUY8qPB8cUcMvmvHo= 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=KHj/ZjC3; 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="KHj/ZjC3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728007239; 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=ubHS+/4Up+CXlv+MFQxp5V5OJdlnjpJuzakK52oVNZ0=; b=KHj/ZjC32BxaHbiD5FBjK55Ra4doDi+5yZO1oW0U0jK6K1NdOSveFAXSGiC2SxaLikrJ6f STNcVUrv5vZDGm87QSrf7L/fd781cTXI4WVgJTP63MqlPgHRmhEyAQD2pg3S3YcZHpW6U7 v1htb8fLBQva3jHDPBj0QFHQhgH5dHc= 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-498-jfNAovzgPhyIIdrDehespw-1; Thu, 03 Oct 2024 22:00:38 -0400 X-MC-Unique: jfNAovzgPhyIIdrDehespw-1 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 99D9A195608A; Fri, 4 Oct 2024 02:00:37 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.45]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3EC3C19560A2; Fri, 4 Oct 2024 02:00:33 +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: [PATCH v2 7/7] vhost: Add new UAPI to support change to task mode Date: Fri, 4 Oct 2024 09:58:21 +0800 Message-ID: <20241004015937.2286459-8-lulu@redhat.com> In-Reply-To: <20241004015937.2286459-1-lulu@redhat.com> References: <20241004015937.2286459-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 support setting the vhost device to use task mode. The user space application needs to use VHOST_SET_INHERIT_FROM_OWNER to set the mode. This setting must be set before VHOST_SET_OWNER is set. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 18 +++++++++++++++++- include/uapi/linux/vhost.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 08c9e77916ca..0e5c81026acd 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2341,8 +2341,24 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned i= nt ioctl, void __user *argp) { struct eventfd_ctx *ctx; u64 p; - long r; + long r =3D 0; int i, fd; + bool inherit_owner; + + if (ioctl =3D=3D VHOST_SET_INHERIT_FROM_OWNER) { + /* Is there an owner already? */ + if (vhost_dev_has_owner(d)) { + r =3D -EBUSY; + goto done; + } + if (copy_from_user(&inherit_owner, argp, + sizeof(inherit_owner))) { + r =3D -EFAULT; + goto done; + } + enforce_inherit_owner =3D inherit_owner; + goto done; + } =20 /* If you are not the owner, you can become one */ if (ioctl =3D=3D VHOST_SET_OWNER) { diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index b95dd84eef2d..1e192038633d 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_INHERIT_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, bool) #endif --=20 2.45.0