From nobody Sun Nov 24 14:10:07 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 635231FE10F for ; Tue, 5 Nov 2024 07:27:09 +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=1730791631; cv=none; b=o35fe5IgEnyvt/xnzaTDfK2T/DQwTK8aXa+bRqqGIKcfEJ8EtH4lvO8BkrKjK60uipdmJz5d5HqGpzij7VyUn827m7Uh/b/6GMhixAQj5YNgu8+sG0g2O2OjlCY84kVCkLno1VCoNhfFYyAT7OFlObyAVrbTHuFujO06r5YsjYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791631; c=relaxed/simple; bh=l9RbpjgxGo9MDgdsXYvwzNMY7RifCS985yCLpV8udPU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r11BzDYmpufzg/4Y7OgjGddJIJ8XBcMsTgqYIeQhuJLqwdPy8gT7bjuQAmQK8MN/pEKcPjp7fGo7nIgbDlHizvw4Fk7Od2ZkW8AJ1ER9eUqXP+v1M31XN4fGJPo6Swy2bDf+DOWnvuxJ4YBPG672nog4jEsX87S7LT2XKIh+SkY= 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=EOc9oYKd; 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="EOc9oYKd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791628; 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=YrN25r/0W16IYmHHoUR1xxPmflO4UlfZvP9MJNNbpL4=; b=EOc9oYKdoDNOvbYSm6Lx1+zJYrdqeLiCA6TTSXYSjkKyLaZvshQX5Z6foUK1LyUAUjopbc flFSHfJUMBMQfHW+1uzSVVWuqNxBqFABHH6y36zHMLHXsP/sKK2XJU4o8y39LCl3mahbD9 d+T/cS2rXCIb0eUMIe7QdFocs17PG+U= 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-25-jAnLrO4_OO-yjG_WIvM1-g-1; Tue, 05 Nov 2024 02:27:06 -0500 X-MC-Unique: jAnLrO4_OO-yjG_WIvM1-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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCD631956083; Tue, 5 Nov 2024 07:27:05 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6BA081955F42; Tue, 5 Nov 2024 07:27:01 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 1/9] vhost: Add a new parameter to allow user select kthread Date: Tue, 5 Nov 2024 15:25:20 +0800 Message-ID: <20241105072642.898710-2-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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" The vhost now uses vhost_task and workers as a child of the owner thread. While this aligns with containerization principles,it confuses some legacy userspace app, Therefore, we are reintroducing kthread API support. Introduce a new parameter to enable users to choose between kthread and task mode. This will be exposed by module_param() later. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 2 ++ drivers/vhost/vhost.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 9ac25d08f473..eff6acbbb63b 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -41,6 +41,7 @@ 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)"); +static bool inherit_owner_default =3D true; =20 enum { VHOST_MEMORY_F_LOG =3D 0x1, @@ -552,6 +553,7 @@ void vhost_dev_init(struct vhost_dev *dev, dev->byte_weight =3D byte_weight; dev->use_worker =3D use_worker; dev->msg_handler =3D msg_handler; + dev->inherit_owner =3D inherit_owner_default; init_waitqueue_head(&dev->wait); INIT_LIST_HEAD(&dev->read_list); INIT_LIST_HEAD(&dev->pending_list); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index bb75a292d50c..c650c4506c70 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -176,6 +176,7 @@ struct vhost_dev { int byte_weight; struct xarray worker_xa; bool use_worker; + bool inherit_owner; int (*msg_handler)(struct vhost_dev *dev, u32 asid, struct vhost_iotlb_msg *msg); }; --=20 2.45.0 From nobody Sun Nov 24 14:10:07 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 93DB21FDFA0 for ; Tue, 5 Nov 2024 07:27: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=1730791637; cv=none; b=YwMij73coDEeDpjzLHJXI2WOlXkTWLpDybeFsuPXxIUekWj/JbHitYR+GTBpOJdZANlCkYnLSyQ9Enqyh1XOXE1Pw1+Ojoobm8yNlswxfD2il614ERtcJW8AQ1RwjOZf0pVxU0op5z+UfEFHRN4NApU7HFrfi0z6l5sgm4stp8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791637; c=relaxed/simple; bh=THdCA1jm90rs4duE7RiNf95OSIxka9SsAUBHQ2Ghxko=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eUeIv6yX3swdaql9EF2E/xU9eajLCpwDmSQtFX/yirOpb3VStYFnKfcP6a39nb3JNoYtv4Xb5OJa49tJj5r2ucMlHXDoKn7w36Olajb9Wo29Kh11Kr7iHBLHdFUTPZS02LZ2HGmlty1666j2g6RN4RaTzM/q6C6BVVMmO/XiPdo= 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=BbH/5zJG; 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="BbH/5zJG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791633; 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=jtnVyGCllOzCsvYTHj412veayAw36T4Mk750trb6Njs=; b=BbH/5zJGi2AoTj1WJXPSVRvnEKll5A5tyj/pA/Ki/J6bFrUkMfxtF/nlFBUxJwDuVg6UZ+ 4KedPwNT3ZmLhifkN/6rVpvaIpTT1oWMt5VDwuKImnb+1/7Tj3jWFKP855jf8hjl8DCzYp 7lMajxLB9cbYEYJTIYaMO4To2jgnf9k= 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-325-HPKtw0OaP6mHrdqRF2XsXA-1; Tue, 05 Nov 2024 02:27:12 -0500 X-MC-Unique: HPKtw0OaP6mHrdqRF2XsXA-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 8D8D01955F43; Tue, 5 Nov 2024 07:27:11 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 90EAA195607C; Tue, 5 Nov 2024 07:27:06 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 2/9] vhost: Add the vhost_worker to support kthread Date: Tue, 5 Nov 2024 15:25:21 +0800 Message-ID: <20241105072642.898710-3-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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 the previously removed function vhost_worker() back to support the kthread and rename it to vhost_run_work_kthread_list. The old function vhost_worker was 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 eff6acbbb63b..65fda810b96e 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -389,6 +389,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 Nov 24 14:10:07 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 A488F1FDFA0 for ; Tue, 5 Nov 2024 07:27:21 +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=1730791643; cv=none; b=ispWI5rJ+mvx6PAJZDHVXAKiu6GlMNzB2r3Mil5zRZTmYd51JgWZltbY3n+7gEEl/3nc5ZrHEE3RtJGEeD5SgCvGs2MrgxiS6UaDvsnr3Y3k3j0qz4Wy6c5xLkK0ecc38uwU909goXiMSycFQFU4NQ21ho/GNulpD0D0fuRTnO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791643; c=relaxed/simple; bh=4BZv/MSpj7iSNmvTqGiuUDrWylQi+HmCE3W6Csgy4G4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VOKRCsdlPrbtp3W86OdQfoLRslWn2LSYt295jWzqAk2t9Q/J5gBz5nrtMdMvGM35XAW1L/9gMhfkxdAaeq8UtcRrChKKmC5SEDoZw4lVPEkJcD7luqnzmGP2DQWaKiJusXdbBIcfP4eYuU8l4aJPf5qu+LHfKZkCS/X6ca2XRdU= 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=OjarV/8U; 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="OjarV/8U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791640; 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=Er4Ja48W1bnY3o91mhLUdl719OPZOQTArQmrqwY2GbM=; b=OjarV/8U8wWv+fDcdRGDU7PrM+liV0hpZ2dCI0CTQoDa0yjkcN6jBxT4m0EsWpoxKSPZtA w2JkxDYX4DhfwigoD1awlpyNx360cIW4wkLc3CWY4VMWYOHkwKZ7a90hWSD0GzbCKnAkYx kA9mkKVGt8YbMyQbWlPQ0nldCCEZeak= 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-81-u8xPnHuIN3K3aXI64mQ62g-1; Tue, 05 Nov 2024 02:27:17 -0500 X-MC-Unique: u8xPnHuIN3K3aXI64mQ62g-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 D5EBC1955EA7; Tue, 5 Nov 2024 07:27:16 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 623591956086; Tue, 5 Nov 2024 07:27:11 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 3/9] vhost: Add the cgroup related function Date: Tue, 5 Nov 2024 15:25:22 +0800 Message-ID: <20241105072642.898710-4-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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 65fda810b96e..e40cef3a1fa5 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -621,6 +622,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 Nov 24 14:10:07 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 D05AF1FE109 for ; Tue, 5 Nov 2024 07:27:49 +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=1730791671; cv=none; b=J1Y0Oy4iBmrD9673lGIxoGANnZLG5YCvXZpMjs+Ievb2khUe1gXf1UcxpN54G7KHdSzmQ6v/7A+7yFUyzIQuGiCGwmWvAZ+tdGwUIugM14oHGYTzL0wSoDTii6freSJqweJyvezrTgLSWB8/sc7sZ70vcC0I8rUYxLedKC4OVEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791671; c=relaxed/simple; bh=px/d7GxNDVWjUeXbE2siNdRGmuGHmt+Dj/2C3sOfk6E=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hxa0N4zKoJrSjgy++RE98XQJJMfRBvu4r6Yx6FGYc+UH00Yp/WDQbt3TXQnM0rSnXE3QcG7W8HOkaAuJJQ1hMmguiRldnnL3s2H/KbVkV9Nu6WsuN3Wqr+CcRBpM4Ibu1cAznXKEUEjhj4htkhVzdeCbZLOsKDgL70RMxhppAoQ= 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=YtL1grVs; 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="YtL1grVs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791669; 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=SZXrpm6Hjv9R5RedbyYefAVChV5g9ZLlA5EfzIRNc4s=; b=YtL1grVsRHSeSR05hpsJiTjtXVNMdHVJkPjfxBmoo8XlrLC3rHrxYDVXUNcZ+S2JiQK+Ya Mf/kgt0cDSVQlQ+T/q7QRD/FrLGoXf/WZVC58+L8IKRWteWoV/6eexyx+/Or+xU0yi8359 U9IyjOwxME3eJW6HB19T07Du/hPrArg= 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-441-irnbstHlPvKijBtIh1Pthg-1; Tue, 05 Nov 2024 02:27:45 -0500 X-MC-Unique: irnbstHlPvKijBtIh1Pthg-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 928681956048; Tue, 5 Nov 2024 07:27:44 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DDEEE1956086; Tue, 5 Nov 2024 07:27:39 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 4/9] vhost: Add kthread support in function vhost_worker_create Date: Tue, 5 Nov 2024 15:25:23 +0800 Message-ID: <20241105072642.898710-5-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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" Restored the previous functions kthread_wakeup and kthread_stop. Also add a new structure, vhost_task_fn. The function vhost_worker_create Will initializes this structure based on the value of inherit_owner. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 71 ++++++++++++++++++++++++++++++++++++------- drivers/vhost/vhost.h | 6 ++++ 2 files changed, 66 insertions(+), 11 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index e40cef3a1fa5..603b146fccc1 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -741,43 +741,92 @@ static void vhost_workers_free(struct vhost_dev *dev) xa_destroy(&dev->worker_xa); } =20 +static int vhost_task_wakeup_fn(void *vtsk) +{ + vhost_task_wake((struct vhost_task *)vtsk); + return 0; +} +static int vhost_kthread_wakeup_fn(void *p) +{ + return wake_up_process((struct task_struct *)p); +} +static int vhost_task_stop_fn(void *vtsk) +{ + vhost_task_stop((struct vhost_task *)vtsk); + return 0; +} +static int vhost_kthread_stop_fn(void *k) +{ + return kthread_stop((struct task_struct *)k); +} + static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) { struct vhost_worker *worker; - struct vhost_task *vtsk; + struct vhost_task *vtsk =3D NULL; + struct task_struct *task =3D NULL; char name[TASK_COMM_LEN]; int ret; u32 id; =20 + /* Allocate resources for the worker */ worker =3D kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); if (!worker) return NULL; =20 + worker->fn =3D kzalloc(sizeof(struct vhost_task_fn), GFP_KERNEL_ACCOUNT); + if (!worker->fn) { + kfree(worker); + return NULL; + } + worker->dev =3D dev; snprintf(name, sizeof(name), "vhost-%d", current->pid); =20 - vtsk =3D vhost_task_create(vhost_run_work_list, vhost_worker_killed, - worker, name); - if (!vtsk) - goto free_worker; - mutex_init(&worker->mutex); init_llist_head(&worker->work_list); worker->kcov_handle =3D kcov_common_handle(); - worker->vtsk =3D vtsk; =20 - vhost_task_start(vtsk); + if (dev->inherit_owner) { + /* Create and start a vhost task */ + vtsk =3D vhost_task_create(vhost_run_work_list, + vhost_worker_killed, worker, name); + if (!vtsk) + goto free_worker; + + worker->vtsk =3D vtsk; + worker->fn->wakeup =3D vhost_task_wakeup_fn; + worker->fn->stop =3D vhost_task_stop_fn; + + vhost_task_start(vtsk); + } else { + /* Create and start a kernel thread */ + 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; + worker->fn->wakeup =3D vhost_kthread_wakeup_fn; + worker->fn->stop =3D vhost_kthread_stop_fn; + + wake_up_process(task); + /* Attach to the vhost cgroup */ + ret =3D vhost_attach_cgroups(dev); + if (ret) + goto stop_worker; + } =20 ret =3D xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, GFP_KERNEL); if (ret < 0) goto stop_worker; worker->id =3D id; - return worker; - stop_worker: - vhost_task_stop(vtsk); + worker->fn->stop(dev->inherit_owner ? (void *)vtsk : (void *)task); free_worker: + kfree(worker->fn); kfree(worker); return NULL; } diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index c650c4506c70..ebababa4e340 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -25,8 +25,13 @@ struct vhost_work { vhost_work_fn_t fn; unsigned long flags; }; +struct vhost_task_fn { + int (*wakeup)(void *task); + int (*stop)(void *task); +}; =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. */ @@ -36,6 +41,7 @@ struct vhost_worker { u32 id; int attachment_cnt; bool killed; + struct vhost_task_fn *fn; }; =20 /* Poll a file (eventfd or socket) */ --=20 2.45.0 From nobody Sun Nov 24 14:10:07 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 411A41FF7A1 for ; Tue, 5 Nov 2024 07:27: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=1730791676; cv=none; b=Yb/bamvwzlIYxAj+gy63J90MEtgHtg8Uc+tVYiRdoi/7vzykUG+NGqz92OU5g3orDZ/UDYCoPuleFs8gnh47ZBjKYWcYr9OQjplRvyDTpaWVGPqNGWsVIR3rDQ6LuStoYauZyFrvVGfFPuyimQUFwzWU+mdhJG8HpWC6vHL7mVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791676; c=relaxed/simple; bh=+38GjQ5iNed2+14XtChEVV9Ul7oBJUOLzQdRTNmOgpQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jp2zaDQJqQ0Z9UeOu8Iy2nZmjyIBFXJOmHaoiKv6Oyq0gwdt8KKWIS1GD6wBlCodiXgajYxd5cgiER0wFKTreEEuf2xo+aqDfCEHY9fVT5puZzRblHer3C+U88dMYd6GkW7A7dbywxHZwXrPU0+P31uq4nV/g9/eOPVzN5Od1dg= 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=TYXsOIvx; 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="TYXsOIvx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791674; 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=pPknO6DVyO1LjLhZHYo5oROtWHiUqkzRt9HMN0ycP2A=; b=TYXsOIvxwmu9XSPwwwHW6oMO3Qgo+ocWSyfXLwzLf7AfpPshRRy4/Hg2tWZFAP08mxoB0P tFlCE1q9OvH4++ghtAS5orLLLhD2IRkhrdjdrblOiuIPWYrf+ufKuZUse+JY7oLrpMuKC8 0I/1271BTwE0rJ9BJIZfh2pZeQuwwyw= 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-17-18RcnFfyPAuvZxSF-A6PBg-1; Tue, 05 Nov 2024 02:27:50 -0500 X-MC-Unique: 18RcnFfyPAuvZxSF-A6PBg-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 B6BC719560A2; Tue, 5 Nov 2024 07:27:49 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 64CC91956086; Tue, 5 Nov 2024 07:27:44 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 5/9] vhost: Add kthread support in function vhost_worker_queue() Date: Tue, 5 Nov 2024 15:25:24 +0800 Message-ID: <20241105072642.898710-6-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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" The function vhost_worker_queue() uses vhost_task_fn and selects the different mode based on the value of inherit_owner. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 603b146fccc1..8b7ddfb33c61 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -238,13 +238,18 @@ EXPORT_SYMBOL_GPL(vhost_poll_stop); static void vhost_worker_queue(struct vhost_worker *worker, struct vhost_work *work) { + if (!worker && !worker->fn) + 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); - vhost_task_wake(worker->vtsk); + worker->fn->wakeup(worker->dev->inherit_owner ? + (void *)worker->vtsk : + (void *)worker->task); } } =20 --=20 2.45.0 From nobody Sun Nov 24 14:10:07 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 E7EE81FF7CB for ; Tue, 5 Nov 2024 07:27: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=1730791680; cv=none; b=UzHWlxSP/MiIu8WAeWHWl3eS+OuC5A8XYUr6Ym7P4FN1tgVram68ULmSXwZy8ZXgATEfzIvQcj6oeWDhAiNHa5TUHzPozFtSS+XR1P0m4l+MWPFkr0T2Ckmm4s40YRhDuEIR63esrL8TRIpk/YRfMTFZD2nU74NTnQbo1LoxBPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791680; c=relaxed/simple; bh=M49i9Z80LvRN1KH00nCqmQiLAV5d1TcbHzx3zh4khGU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T6UgN93pF4+LE2HfmAtaWx3GZMtPD/bK0bYGTPNJw9qYuWwGqmaAqkM4ZMoWoZTYm8a0tOUscO/T2LJkwL3QvW9qboVKhzZauXHrziVOEWpqgMKsY4s9V3HQOq+EhS6o9491vVxEthLZdMQWNgQH+AM1DXusybhurJ7UTMoP0FE= 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=Voto5gTr; 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="Voto5gTr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791677; 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=1m4NUSQOwh8h3S2yfP06X/nb4pg21Jt9eMtwUyyXqBQ=; b=Voto5gTrBd9tol/whxXwvflJsNrxZHI7Kd8otQQzltpD6h8OueKKjwNTQPdZLZXt1mcyZg MSrU/4u/UP+gwvQzEpp8zjHsjd2gQX9iZJHRbea1mZZgUf4JHFsPIHUVnq7h7epYXzio1q l2wXogtNWEK18uDTbO1zPe6JiDo6q6M= 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-608-p_ZQeHAjNgOwXe-RNXUbxQ-1; Tue, 05 Nov 2024 02:27:56 -0500 X-MC-Unique: p_ZQeHAjNgOwXe-RNXUbxQ-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 DCC5519560AB; Tue, 5 Nov 2024 07:27:54 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8B52F1956086; Tue, 5 Nov 2024 07:27:50 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 6/9] vhost: Add kthread support in function vhost_worker_destroy() Date: Tue, 5 Nov 2024 15:25:25 +0800 Message-ID: <20241105072642.898710-7-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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" The function vhost_worker_destroy() will use struct vhost_task_fn and selects the different mode based on the value of inherit_owner. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 8b7ddfb33c61..c17dc01febcc 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -718,12 +718,14 @@ static void vhost_detach_mm(struct vhost_dev *dev) static void vhost_worker_destroy(struct vhost_dev *dev, struct vhost_worker *worker) { - if (!worker) + if (!worker && !worker->fn) return; =20 WARN_ON(!llist_empty(&worker->work_list)); xa_erase(&dev->worker_xa, worker->id); - vhost_task_stop(worker->vtsk); + worker->fn->stop(dev->inherit_owner ? (void *)worker->vtsk : + (void *)worker->task); + kfree(worker->fn); kfree(worker); } =20 --=20 2.45.0 From nobody Sun Nov 24 14:10:07 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 5E725200121 for ; Tue, 5 Nov 2024 07:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791686; cv=none; b=Az3KY0MpSlut+KtLnxtnHy+f7uuVwl6k0OZ22DNk0fbqDL6ykACrkXFjb1FkjOJN0kgSb2ayTI/ZR1GGIqUKFwIBLnK25X/7D4X05kL5b591SF6S/f2LGIplRblturA2SVMN35BgqPJ9ExnTAtb8MSBXBORkir/5/iNZDBBW6Bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791686; c=relaxed/simple; bh=0QdkBtKjMzdIS7SqrchG9JRhfPNterDTSKj/TM/P8mg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=psTAaWRllf6JvvrJYDmL9TKkbXzefPUSVmC69lTmGn2zkFxRziBxzaU05lCd76zUB+WagwU9H4T0P0tL/i+9FGz+1YKeE8JDh06GZ8VBUG3n+INxtgZjGuvSPC/XQCpwMajv6ih4QBHPfXV4lJuJJhg6D9V31potgpyB/KSHjrE= 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=ayY8RUKT; 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="ayY8RUKT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791684; 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=b9eokZY2fqQ9vuKBZvQW4V7mmsdAb7yocXzqh175Di8=; b=ayY8RUKT8mF+IIp0It0WzOI9U35OLMtXFgJH6juAM+d0M0iRwc/boj5gDBIAbohTl5bjmJ oFaTf5v25/aicAKPzUrnvhx4GOwbBHOr6H6EqmQpxDYlPC88NbJNvAEGzNqMq2Kp0RYtkY jE5rqoZBZ37JFgUl7Yskp5/xXOMWHSM= 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-632-drmJyLkFOAOKSnWYvp1LDA-1; Tue, 05 Nov 2024 02:28:01 -0500 X-MC-Unique: drmJyLkFOAOKSnWYvp1LDA-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 2C58C1955EE6; Tue, 5 Nov 2024 07:28:00 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B15971956086; Tue, 5 Nov 2024 07:27:55 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 7/9] vhost: Add new UAPI to support change to task mode Date: Tue, 5 Nov 2024 15:25:26 +0800 Message-ID: <20241105072642.898710-8-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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 enable setting the vhost device to task mode. The userspace application can use VHOST_SET_INHERIT_FROM_OWNER to configure the mode if necessary. This setting must be applied before VHOST_SET_OWNER, as the worker will be created in the VHOST_SET_OWNER function Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 15 ++++++++++++++- include/uapi/linux/vhost.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index c17dc01febcc..70c793b63905 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2274,8 +2274,9 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned in= t ioctl, void __user *argp) { struct eventfd_ctx *ctx; u64 p; - long r; + long r =3D 0; int i, fd; + bool inherit_owner; =20 /* If you are not the owner, you can become one */ if (ioctl =3D=3D VHOST_SET_OWNER) { @@ -2332,6 +2333,18 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned i= nt ioctl, void __user *argp) if (ctx) eventfd_ctx_put(ctx); break; + case VHOST_SET_INHERIT_FROM_OWNER: + /*inherit_owner can only be modified before owner is set*/ + if (vhost_dev_has_owner(d)) + break; + + if (copy_from_user(&inherit_owner, argp, + sizeof(inherit_owner))) { + r =3D -EFAULT; + break; + } + d->inherit_owner =3D inherit_owner; + break; default: r =3D -ENOIOCTLCMD; break; 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 From nobody Sun Nov 24 14:10:07 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 E087F1FE105 for ; Tue, 5 Nov 2024 07:28:32 +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=1730791714; cv=none; b=k+8EKPseQjlR+7Kq1w+Xvq0MxOb8/SWDTsi7XvaoW+U7ZETwPsDoC1ALj2m3d1k9pw9Ht+9cSdOhX5Elcm4tUOan9SeeRahco4W2Ufm7DzWxSIpm+vG8bA0/xM5C4m4HiP1AOWvUWlKSElSkPFbAMfMrQ5eIiPsN8h4HXSQT2/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791714; c=relaxed/simple; bh=MX5FZQA4EmsLL2pOoIXNJm9EOZkEs7x6Q7BAjrZW4D4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dHJ6ofPku7JR/sKmBI9QM/RD2HubrJJt93DnLx+g9n+WVBaLwAAWC5tbWCKRNcnC6z8XQdhHkP+/ofLhf16Diup2QqDtiTHgpdDmjek+KNbj3E0yagpFZd8ipukuQfxlWpBD1JUFAgFzei/mHfn9wMzdFQJcRAk9xA2f7ZHhOh0= 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=UW+mkX5g; 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="UW+mkX5g" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791711; 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=waOIJYR/uf8lM72gcE+nfFRZp8HYpeFxyDV384TmS5E=; b=UW+mkX5gKp13qtB//km6gwi1pl/sXu8tZITIZ3Pchm5Ctk8+9/rsh5o2/+4bXBveoN+C61 rNKljNknM5GSWbDtWcIpygHBdQVBnusrv4lXF12znJj/neMo1qcxhZl1Ju/hBkv9qkGd1d p9IjsrolyikmSrSvI6LP2vBFc/OaYuc= 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-455-JVDKDcsiOTSUpOOxeo5f5g-1; Tue, 05 Nov 2024 02:28:28 -0500 X-MC-Unique: JVDKDcsiOTSUpOOxeo5f5g-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 A897C1955EAA; Tue, 5 Nov 2024 07:28:27 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 00BD119560A3; Tue, 5 Nov 2024 07:28:22 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 8/9] vhost_scsi: Add check for inherit_owner status Date: Tue, 5 Nov 2024 15:25:27 +0800 Message-ID: <20241105072642.898710-9-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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_scsi VHOST_NEW_WORKER requires the inherit_owner setting to be true. So we need to implement a check for this. Signed-off-by: Cindy Lu --- drivers/vhost/scsi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 006ffacf1c56..05290298b5ab 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -2083,6 +2083,11 @@ vhost_scsi_ioctl(struct file *f, return -EFAULT; return vhost_scsi_set_features(vs, features); case VHOST_NEW_WORKER: + /*vhost-scsi VHOST_NEW_WORKER requires inherit_owner to be true*/ + if (vs->dev.inherit_owner !=3D true) + return -EFAULT; + + fallthrough; case VHOST_FREE_WORKER: case VHOST_ATTACH_VRING_WORKER: case VHOST_GET_VRING_WORKER: --=20 2.45.0 From nobody Sun Nov 24 14:10:07 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 CD7FA1FE105 for ; Tue, 5 Nov 2024 07:28:37 +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=1730791719; cv=none; b=VHo07rG2CQNZ8ZiuI6fTuU9ajYp0IOuL0NeP0nfatLn/PXFXtt/DD+nT7An5r3XCygfwo/k0fl79+Jr2TmqPAEJUQ47mYHAUbv0maB8zZrvtbW91xMjw8xBSIwoNJbgK5Uu+3m4IuuBXzNul2onXRLMT2nHs9lrnTnBZmFiBzhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730791719; c=relaxed/simple; bh=vJGsOnLSVbNs9zEE3Y9TV4PsmII2ryUMx1W/w1V1sgo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rSvLDGxrVM9x9Oe6+eoSlBUCnJGPZ4JTZaA09D1LPGtfaTGclxvRZWcNvDMUzlnaMuUV2F/DOSC3DTCCxMYIHiTxcydy/zv8qgwD1ITb92ZQrRbZqhK7H5vlEzAClk4GxEyZ+ENUrm7vqmgxm/D0swBO86mUkhg2D0El5WRNqcY= 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=KroNaPbJ; 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="KroNaPbJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730791717; 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=taXN/BByVA3oeUwccMMIwwKlQcWqxPtqO9YY/m4NEgM=; b=KroNaPbJ/0vNf4plqZ2pDVdHFRBzemiEjZBj2NMl1dHq/d/ISd/xjEGAgbGQtT0Yxm5l5C FBsYs2ztAmO2dMej9B5eyHf/RWCdgHs9IdfjyLc0NOiz8v8sa/Gb6txi6BwGdXWkaRZQ0h EfGtJLXUSb47He8MsRjr58oXGjm4DY0= 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-435-AAOEehLKPrGIGDel1AAU2Q-1; Tue, 05 Nov 2024 02:28:33 -0500 X-MC-Unique: AAOEehLKPrGIGDel1AAU2Q-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 C46FB1955EAB; Tue, 5 Nov 2024 07:28:32 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.50]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7D39019560A3; Tue, 5 Nov 2024 07:28:28 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, michael.christie@oracle.com, sgarzare@redhat.com, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [PATCH v3 9/9] vhost: Expose the modparam inherit_owner_default Date: Tue, 5 Nov 2024 15:25:28 +0800 Message-ID: <20241105072642.898710-10-lulu@redhat.com> In-Reply-To: <20241105072642.898710-1-lulu@redhat.com> References: <20241105072642.898710-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" Expose the inherit_owner_default modparam by module_param(). 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 70c793b63905..1a4ccf4f7316 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -43,6 +43,9 @@ module_param(max_iotlb_entries, int, 0444); MODULE_PARM_DESC(max_iotlb_entries, "Maximum number of iotlb entries. (default: 2048)"); static bool inherit_owner_default =3D true; +module_param(inherit_owner_default, bool, 0444); +MODULE_PARM_DESC(inherit_owner_default, + "Set vhost_task mode as the default(default: Y)"); =20 enum { VHOST_MEMORY_F_LOG =3D 0x1, --=20 2.45.0