From nobody Sat Nov 30 16:21:46 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 7AED2BA42 for ; Mon, 9 Sep 2024 01:35:59 +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=1725845764; cv=none; b=NKjGtUx8l6coPGVFGPHtc3glbApNum7kK4yLPUuawGAQdz1lnQn1sJx0WDnwBb0n6A83TtQKhrtjmC0F1DSPa220XPuYEQg6vGy6pZjTgpY93P9h4zyTklzW38CVzbtxFaYju9J1uZMThd2Cjn6nBK6iJ8c037pHJCuyRvs1rRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845764; c=relaxed/simple; bh=b1TL6VfkMSGelSbZuz3i/ovmXnm6fRU5ZpQUCeqKGzw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uF/ivlNzvXyF8MDhCZvAMiUC+B+jR7a5qE4F3F9QPqmnCm2w69PDLaWvmlYQjEw46fG0Kfhwde0bLkDO0+kbTFCl3GsCJzIx/DQoH2qh57+FGYpml3WNOHKyUA+2eK1dplYUKDIFtNUd0RNfoJp8CPHemvFr2APP746/c9R6fS4= 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=YO+ZlE/N; 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="YO+ZlE/N" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725845757; 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=78yJ0rrxnE6exhPYiyoiwtUEzl2VKCruczkggBJ6zeM=; b=YO+ZlE/NTbr+FdpRN3DBm9asus44ylQDRqhc16HcseU98pFeV1+D8+blLbJaew0XUVYVHC 1X6ncxE0PO4mLuKmOpwaUI/X36SRg3eL3QK6zKJtvrREojGgdYj+ql6nPbsMNwsJTwTTgP KvV11N675g926+ewJV8CLypD2uaPThM= 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-262-pq-bCRioPZSzoE9Y_jFsBw-1; Sun, 08 Sep 2024 21:35:54 -0400 X-MC-Unique: pq-bCRioPZSzoE9Y_jFsBw-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 3027E1955DC3; Mon, 9 Sep 2024 01:35:51 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0EA871956086; Mon, 9 Sep 2024 01:35:46 +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 v1 1/7] vhost: Add a new module_param for enable kthread Date: Mon, 9 Sep 2024 09:33:40 +0800 Message-ID: <20240909013531.1243525-2-lulu@redhat.com> In-Reply-To: <20240909013531.1243525-1-lulu@redhat.com> References: <20240909013531.1243525-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Type: text/plain; charset="utf-8" Add a new module parameter to enable kthread while loading modules. This parameter will identify if the vhost will use kthread or a task. The default value will be true. Signed-off-by: Cindy Lu module_param --- drivers/vhost/vhost.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 9ac25d08f473..be43181af659 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -41,6 +41,9 @@ static int max_iotlb_entries =3D 2048; module_param(max_iotlb_entries, int, 0444); MODULE_PARM_DESC(max_iotlb_entries, "Maximum number of iotlb entries. (default: 2048)"); +bool enforce_kthread =3D true; +module_param(enforce_kthread, bool, 0444); +MODULE_PARM_DESC(enforce_kthread, "enable vhost to use kthread (default: Y= )"); =20 enum { VHOST_MEMORY_F_LOG =3D 0x1, --=20 2.45.0 From nobody Sat Nov 30 16:21:46 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 239AD17999 for ; Mon, 9 Sep 2024 01:36: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=1725845767; cv=none; b=muXUhJcL3j5vt3dgauedg+HF6wEjt2M/iK+8lrdCvdM0W0wcrd5iOs0ik6XfoYp2F9nkjTr8aAUCTIBKzJ0Iz/xaG9r6RvemLYiPGoprdTo3Xa94tm/0iwxaFCkKCC51evFLD1UlaAZjXTDu5orQWdO6P80UxOlWGY7jcATz3pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845767; c=relaxed/simple; bh=XuAV28beZBB9pt7L44fG41MVE4koHWkMzXmu/XBq26g=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UHYF81AEQnEaNvnyRkvCYOEVzQ+KXjBlB1nF8gYB36ktjOHed9AjK3i+eUVArqX1DOUFXyvxi9TpSF8PPSm6DBe9QMcPFiuR82yVTyCZIYed/Da3f78Nzh1dK5fGPidtP+uX1uI0GeQNjQYrmWA3tLPgrvVQ3AtBDiAqNc9wBdw= 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=Yvf4b3V2; 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="Yvf4b3V2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725845764; 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=0Qa3eHGZmJGnjogDLrYYH+LddmdunfgoRAOyAvGD2Vs=; b=Yvf4b3V2EeiGaNCH7kNThaqnuAmjHg9FemDqpZt66Hygf2h+n45eqouZzw71361RiqKbRN xb0xiWhfZkNa0HBNz0PYq6YEPTZObAu/4MKkVrANexguqTA/muPoK/PulDB16K3d1p2eeG jG0WDkDTafUoF11RTmCLwdzxIZ1eNk4= 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-102-w4GiHKBHPVC_EVVCAQsBeA-1; Sun, 08 Sep 2024 21:35:58 -0400 X-MC-Unique: w4GiHKBHPVC_EVVCAQsBeA-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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D8EB1196CDF4; Mon, 9 Sep 2024 01:35:55 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EBB6A195608A; Mon, 9 Sep 2024 01:35:51 +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 v1 2/7] vhost: Add kthread support in function vhost_worker_queue() Date: Mon, 9 Sep 2024 09:33:41 +0800 Message-ID: <20240909013531.1243525-3-lulu@redhat.com> In-Reply-To: <20240909013531.1243525-1-lulu@redhat.com> References: <20240909013531.1243525-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Type: text/plain; charset="utf-8" Added back the previously removed function vhost_worker_queue() and renamed it to vhost_worker_queue_khtread(). The new vhost_worker_queue() will select the different mode based on the value of the parameter. The old function vhost_work_queue() was change to support task in commit 6e890c5d5021 ('vhost: use vhost_tasks for worker threads') changed in commit f9010dbdc ('fork, vhost: Use CLONE_THREAD to fix freezer/ps regressi= on') and also was change the name of function to vhost_worker_queue() in commit 0921dddcb5 (vhost: take worker or vq instead of dev for queueing) Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 30 ++++++++++++++++++++++++++++-- drivers/vhost/vhost.h | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index be43181af659..6198c165ab15 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -236,8 +236,8 @@ void vhost_poll_stop(struct vhost_poll *poll) } EXPORT_SYMBOL_GPL(vhost_poll_stop); =20 -static void vhost_worker_queue(struct vhost_worker *worker, - struct vhost_work *work) +static void vhost_worker_queue_task(struct vhost_worker *worker, + struct vhost_work *work) { if (!test_and_set_bit(VHOST_WORK_QUEUED, &work->flags)) { /* We can only add the work to the list after we're @@ -249,6 +249,32 @@ static void vhost_worker_queue(struct vhost_worker *wo= rker, } } =20 +static void vhost_work_queue_kthread(struct vhost_worker *worker, + struct vhost_work *work) +{ + if (!worker) + return; + + if (!test_and_set_bit(VHOST_WORK_QUEUED, &work->flags)) { + /* We can only add the work to the list after we're + * sure it was not in the list. + * test_and_set_bit() implies a memory barrier. + */ + llist_add(&work->node, &worker->work_list); + + wake_up_process(worker->task); + } +} + +static void vhost_worker_queue(struct vhost_worker *worker, + struct vhost_work *work) +{ + if (use_kthread) { + vhost_work_queue_kthread(worker, work); + } else { + vhost_worker_queue_task(worker, work); + } +} bool vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *wo= rk) { struct vhost_worker *worker; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index bb75a292d50c..c7f126fd09e8 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -27,6 +27,7 @@ struct vhost_work { }; =20 struct vhost_worker { + struct task_struct *task; struct vhost_task *vtsk; struct vhost_dev *dev; /* Used to serialize device wide flushing with worker swapping. */ --=20 2.45.0 From nobody Sat Nov 30 16:21:46 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 8B08917C9E for ; Mon, 9 Sep 2024 01:36:06 +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=1725845768; cv=none; b=n5IM6EbUhtHOEKvcxt2URhYnkkAddDGz2XsvdA3N2Uc46St3bDhnJa9dKUGXhR0pErbn4oIqxPNOq2E6OpwUO9PdHKrQQxhtlb4aOZnsHSwj03PLYNa5YaGt7NTZmJNHeXFK+vn3XQFZIYh4MbQ/nbQ7A6+n68ykeLgY/xKgdVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845768; c=relaxed/simple; bh=1pQYSVQ05pRenwCfIRIlQbmmJntgrvPfEVVFvpU5lOA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=baw7WQef5nh8AyG3vLoBli+Z2pGncOLkS7v0WHNDdWwlRcWXZdzJJEHUi/8CbTzTIvPdcLXmtRZ8vpTg5dyhOV20IfoBfka6ekla2PdyK6ly6jmXDL9g2sReWMLuyLxcpE5zJb9a3xjP0XJ4vZ5EMlyQoTZYopkhggSwHW8Fr1Q= 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=O9hA8H1j; 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="O9hA8H1j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725845765; 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=yyzWZkYitAKw0qInqxUPaOkmkxHh1NGFvAqmvdgzGAs=; b=O9hA8H1jaVME1xjqt/+DY561qKamoRSN6HxMoHHwv4+YsX1uiD+wVJCKRAarHN52tjEQmP z4vo+lsB5fqpFjBFUyDGIwPjKZ0EsJbdC7F99MVVQ3CbtJBqkbRMnWkNwRwGE7yZLXUfln dyVfDX7vEMpRamXg57YLniltdD08xzI= 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-623-inPuApwzPCSEM7r8GuOZxA-1; Sun, 08 Sep 2024 21:36:01 -0400 X-MC-Unique: inPuApwzPCSEM7r8GuOZxA-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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A2BDB193E8CE; Mon, 9 Sep 2024 01:36:00 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E6EC1956086; Mon, 9 Sep 2024 01:35:56 +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 v1 3/7] vhost: Add kthread support in function vhost_workers_free() Date: Mon, 9 Sep 2024 09:33:42 +0800 Message-ID: <20240909013531.1243525-4-lulu@redhat.com> In-Reply-To: <20240909013531.1243525-1-lulu@redhat.com> References: <20240909013531.1243525-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Type: text/plain; charset="utf-8" Added back the previously removed function vhost_workers_free() and renamed it to vhost_workers_free_khtread(). The new vhost_workers_free() will select the different mode based on the value of the parameter. The old function vhost_workers_free was change to support task in commit 6e890c5d5021 ('vhost: use vhost_tasks for worker threads') also changed in commit a284f09effe ('vhost: Fix crash during early vhost_transport_send_pkt= calls') change to xarray in commit 1cdaafa1b8b ('vhost: replace single worker pointer with xarray') Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 52 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 6198c165ab15..411e81a2925a 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -647,8 +647,21 @@ static void vhost_detach_mm(struct vhost_dev *dev) dev->mm =3D NULL; } =20 -static void vhost_worker_destroy(struct vhost_dev *dev, - struct vhost_worker *worker) +static void vhost_worker_destroy_kthread(struct vhost_dev *dev, + struct vhost_worker *worker) +{ + if (!worker) + return; + + WARN_ON(!llist_empty(&worker->work_list)); + + xa_erase(&dev->worker_xa, worker->id); + kthread_stop(worker->task); + kfree(worker); +} + +static void vhost_worker_destroy_task(struct vhost_dev *dev, + struct vhost_worker *worker) { if (!worker) return; @@ -659,7 +672,7 @@ static void vhost_worker_destroy(struct vhost_dev *dev, kfree(worker); } =20 -static void vhost_workers_free(struct vhost_dev *dev) +static void vhost_workers_free_task(struct vhost_dev *dev) { struct vhost_worker *worker; unsigned long i; @@ -674,10 +687,36 @@ static void vhost_workers_free(struct vhost_dev *dev) * created but couldn't clean up (it forgot or crashed). */ xa_for_each(&dev->worker_xa, i, worker) - vhost_worker_destroy(dev, worker); + vhost_worker_destroy_task(dev, worker); xa_destroy(&dev->worker_xa); } =20 +static void vhost_workers_free_kthread(struct vhost_dev *dev) +{ + struct vhost_worker *worker; + unsigned long i; + + if (!dev->use_worker) + return; + + for (i =3D 0; i < dev->nvqs; i++) + rcu_assign_pointer(dev->vqs[i]->worker, NULL); + /* + * Free the default worker we created and cleanup workers userspace + * created but couldn't clean up (it forgot or crashed). + */ + xa_for_each(&dev->worker_xa, i, worker) + vhost_worker_destroy_kthread(dev, worker); + xa_destroy(&dev->worker_xa); +} + +static void vhost_workers_free(struct vhost_dev *dev) +{ + if (use_kthread) + vhost_workers_free_kthread(dev); + else + vhost_workers_free_task(dev); +} static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) { struct vhost_worker *worker; @@ -845,7 +884,10 @@ static int vhost_free_worker(struct vhost_dev *dev, __vhost_worker_flush(worker); mutex_unlock(&worker->mutex); =20 - vhost_worker_destroy(dev, worker); + if (use_kthread) + vhost_worker_destroy_kthread(dev, worker); + else + vhost_worker_destroy_task(dev, worker); return 0; } =20 --=20 2.45.0 From nobody Sat Nov 30 16:21:46 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 EDCBA101C8 for ; Mon, 9 Sep 2024 01:36: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=1725845794; cv=none; b=uMnDJ8JvaB/Ik5+Bve89JLlZT1nhhMVxXrnl/0qC0nTJAkr6IrlrTK8buBXhTY/Hxge7Agt29+1tfUvEv4sOnPcYklEwWm5h2gX5a4f5uGZJqrL/RlvMS9sOkmdzcfSyE0nTLXuHY0J8EeRryaswDqNF+gREFtvBYZ17eNzCvZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845794; c=relaxed/simple; bh=cm2TyX/vTFhD074ECWVul2vR6hFqTuaB0GDPZY2e81k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EB1/K4kha2u4Adv8xWuigvrH3eAoXHtKm70s+ebdG9X1DIliu6tu/Zs29uzJRRB88YDLgx7UHtu2EBw61ge9g1m+scMutWeuPS5ZDAG2B1E0oexlg63QGYuX6vFnQflVY80Qqb1AXL4zU7u9Xzvn1NScddxHFZsGeZ4vv+FOG3w= 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=iFgZ5nB/; 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="iFgZ5nB/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725845791; 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=teKlXY2sHeFZGse/27TN1az22vWISOa32I6qBXU1tDs=; b=iFgZ5nB/Ismi+sxzUej8p5xBIjmLZwjCyik5FXGW/WF9QxK2HjC2oWdIxWA1Fd9ySYq1Zg qNAgNyNWNcZ2O35GXliwM3qZTzj9bwHXUtliuK4Tyj0ljIXskJorYvGAmsCkdgcLbU+caA gq14EacALWYST/D1nufa5JW7yly/Z1s= 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-529-bnih4yzrP9S8EJQDWf7RqQ-1; Sun, 08 Sep 2024 21:36:30 -0400 X-MC-Unique: bnih4yzrP9S8EJQDWf7RqQ-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 659931977024; Mon, 9 Sep 2024 01:36:29 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CCCB919560AA; Mon, 9 Sep 2024 01:36:23 +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 v1 4/7] vhost: Add the vhost_worker to support kthread Date: Mon, 9 Sep 2024 09:33:43 +0800 Message-ID: <20240909013531.1243525-5-lulu@redhat.com> In-Reply-To: <20240909013531.1243525-1-lulu@redhat.com> References: <20240909013531.1243525-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 1cdaafa1b8b ('vhost: replace single worker pointer with xarray') Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 411e81a2925a..fd54ee323fb1 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -417,6 +417,44 @@ static void vhost_vq_reset(struct vhost_dev *dev, __vhost_vq_meta_reset(vq); } =20 +static int vhost_run_work_kthread_list(void *data) +{ + struct vhost_worker *worker =3D data; + struct vhost_work *work, *work_next; + struct vhost_dev *dev =3D worker->dev; + struct llist_node *node; + + kthread_use_mm(dev->mm); + + for (;;) { + /* mb paired w/ kthread_stop */ + set_current_state(TASK_INTERRUPTIBLE); + + if (kthread_should_stop()) { + __set_current_state(TASK_RUNNING); + break; + } + node =3D llist_del_all(&worker->work_list); + if (!node) + schedule(); + + node =3D llist_reverse_order(node); + /* make sure flag is seen after deletion */ + smp_wmb(); + llist_for_each_entry_safe(work, work_next, node, node) { + clear_bit(VHOST_WORK_QUEUED, &work->flags); + __set_current_state(TASK_RUNNING); + kcov_remote_start_common(worker->kcov_handle); + work->fn(work); + kcov_remote_stop(); + cond_resched(); + } + } + kthread_unuse_mm(dev->mm); + + return 0; +} + static bool vhost_run_work_list(void *data) { struct vhost_worker *worker =3D data; --=20 2.45.0 From nobody Sat Nov 30 16:21:46 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 4982A168BD for ; Mon, 9 Sep 2024 01:36: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=1725845798; cv=none; b=qjV4Rhw4+BOwO+u/aNOoC12hv0eeWQIDn6Ets+O/oOEAeZYT18aY7l/SgOdzAiZajRNnp6ZF27ME01aSQA7e82jRz8HSEZQ3GOF9wqAGO3X1ScygUZ0mdgUHRtG/4Yd/p5qOSC8aw4HWMI6JReqqO8dPeS/2niDllNwpngtiSR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845798; c=relaxed/simple; bh=Zj52ujkm+R0tviSIHLkmWRXg5f1ITFTOrXGxPxViqoU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W9fq8EJaG62OgahM7JMUynHDgkVdoOY+FcNqpXUXzyPQ4Mcgeg6M2DqbdRt/QpIXo5lqkAGsp3P9ukSuxRErUcUTQCQQvfChIdzsHUZENQKdoBDg5IIz4NdHQltXtlhFj7hKtmN3p/GQtekXw6fG8CzQBvZqqxACWwaqthOt5Hw= 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=J3dVkDVZ; 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="J3dVkDVZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725845796; 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=ZUK21wL5JOX0cOtdsK1MpB8tVQltsuArPMxS2cXskDc=; b=J3dVkDVZJC+QdQf7t9oJybu6DN5kE437qvetPkEjniJA7fdzzizxiQjbqx+Dsk5XJcd3Sa /TXzGe673nJa73lDlenTY80A5NpynyrmiCYHBY9S24aiIsj8hZRXcx67pVJEAZoqdl/fUv stnav5ofMbZaruwn8zxq1XazjaqfAXU= 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-621-JKqYP9TlNfipfu_MaouYig-1; Sun, 08 Sep 2024 21:36:35 -0400 X-MC-Unique: JKqYP9TlNfipfu_MaouYig-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 275F31977027; Mon, 9 Sep 2024 01:36:34 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1776A19560AA; Mon, 9 Sep 2024 01:36: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 v1 5/7] vhost: Add the cgroup related function Date: Mon, 9 Sep 2024 09:33:44 +0800 Message-ID: <20240909013531.1243525-6-lulu@redhat.com> In-Reply-To: <20240909013531.1243525-1-lulu@redhat.com> References: <20240909013531.1243525-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 fd54ee323fb1..f05545b125f0 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -648,6 +649,57 @@ long vhost_dev_check_owner(struct vhost_dev *dev) } EXPORT_SYMBOL_GPL(vhost_dev_check_owner); =20 +struct vhost_attach_cgroups_struct { + struct vhost_work work; + struct task_struct *owner; + int ret; +}; + +static void vhost_attach_cgroups_work(struct vhost_work *work) +{ + struct vhost_attach_cgroups_struct *s; + + s =3D container_of(work, struct vhost_attach_cgroups_struct, work); + s->ret =3D cgroup_attach_task_all(s->owner, current); +} + +static int vhost_worker_cgroups_kthread(struct vhost_worker *worker) +{ + struct vhost_flush_struct flush; + struct vhost_attach_cgroups_struct attach; + + attach.owner =3D current; + + vhost_work_init(&attach.work, vhost_attach_cgroups_work); + vhost_worker_queue(worker, &attach.work); + + init_completion(&flush.wait_event); + vhost_work_init(&flush.work, vhost_flush_work); + vhost_worker_queue(worker, &flush.work); + wait_for_completion(&flush.wait_event); + + return attach.ret; +} + +static int vhost_attach_cgroups(struct vhost_dev *dev) +{ + struct vhost_worker *worker; + unsigned long i; + int ret; + + /* + * Free the default worker we created and cleanup workers userspace + * created but couldn't clean up (it forgot or crashed). + */ + + xa_for_each(&dev->worker_xa, i, worker) { + ret =3D vhost_worker_cgroups_kthread(worker); + if (ret) + return ret; + } + return ret; +} + /* Caller should have device mutex */ bool vhost_dev_has_owner(struct vhost_dev *dev) { --=20 2.45.0 From nobody Sat Nov 30 16:21:46 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 7F0581BC40 for ; Mon, 9 Sep 2024 01:36:42 +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=1725845804; cv=none; b=k6bHnWGWUy0qMy4wiT8e2Gh0zFwbWsQV5vRgtm9QbzdXJV0uxcq2s87zqVIIWNaf/hh3i4/baCLP2SC+nBSFyIX9eFklwqRMA/0TtTK5Ql0hKIocsaXS6ORjo+zdMKeQxHn1aVSEvDWMXjcLGjZGSwPIOrdzYk6FSQkOZW4xKus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845804; c=relaxed/simple; bh=q60zYy1/Faf6jVVm6utx8YjJpmwhDSnklipNz1Xc/VQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=op3itm8SFiKvgRI2qlRrUppkJ4OCBPs5B2NszszBXYFitbZfknOnmQWCqI5Lic+P2FYfDa+gufTfpTuaGWZF8wFoz8IrBdQ047RYz/s/2+fZ1TRbZ7/CgfxRl1+cWLfvEDKU5xXnf9comfvrVMkCX4DqiAXsplNftaSFNBBOc5U= 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=ZMBEF+WA; 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="ZMBEF+WA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725845801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4kaz4nYOPB8CgQNt7ZV4Ttw3NVtlnR/6nzex43AvYrI=; b=ZMBEF+WAsP+US/RqxII87iuqkOQr+61voqFJbw/QBaVODb/kB6OOdWHQYPF9bAFB7S0SLG jyBeA2/MFm36YGVpQG706CuqMIhjoEbSm9oRJW77PZeDUfzzpbx2GqQmPj/Ijb09Ptl3dX jd9zGsmVQuIQW3vH2ttEXDgR0tiq+es= 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-637-1JVi5RVQNTOLgcDQ6raXIA-1; Sun, 08 Sep 2024 21:36:40 -0400 X-MC-Unique: 1JVi5RVQNTOLgcDQ6raXIA-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 1C8BE1953963; Mon, 9 Sep 2024 01:36:39 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F085619560AF; Mon, 9 Sep 2024 01:36:34 +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 v1 6/7] vhost: Add kthread support in function vhost_worker_create Date: Mon, 9 Sep 2024 09:33:45 +0800 Message-ID: <20240909013531.1243525-7-lulu@redhat.com> In-Reply-To: <20240909013531.1243525-1-lulu@redhat.com> References: <20240909013531.1243525-1-lulu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Split the function vhost_worker_create to support both task and kthread =C2=A0 =C2=A0 =C2=A0 =C2=A0 Added back the previous old function vhost_worker_create and rename it to vhost_worker_create_khtread to support the khtread. The new vhost_worker_create will be selected which to use based on the value of the parameter. the old function vhost_worker_create was change to support task in commit 6e890c5d5021 ('vhost: use vhost_tasks for worker threads') also changed in commit 1cdaafa1b8b ('vhost: replace single worker pointer with xarray') commit c011bb669dd ('vhost: dynamically allocate vhost_worker') Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index f05545b125f0..bf1e971cb06f 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -807,7 +807,8 @@ static void vhost_workers_free(struct vhost_dev *dev) else vhost_workers_free_task(dev); } -static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) + +static struct vhost_worker *vhost_worker_create_task(struct vhost_dev *dev) { struct vhost_worker *worker; struct vhost_task *vtsk; @@ -848,6 +849,50 @@ static struct vhost_worker *vhost_worker_create(struct= vhost_dev *dev) return NULL; } =20 +static struct vhost_worker *vhost_worker_create_kthread(struct vhost_dev *= dev) +{ + struct vhost_worker *worker; + struct task_struct *task; + int ret; + u32 id; + + worker =3D kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); + if (!worker) + return NULL; + + worker->dev =3D dev; + worker->kcov_handle =3D kcov_common_handle(); + + mutex_init(&worker->mutex); + init_llist_head(&worker->work_list); + + task =3D kthread_create(vhost_run_work_kthread_list, worker, "vhost-%d", + current->pid); + if (IS_ERR(task)) { + ret =3D PTR_ERR(task); + goto free_worker; + } + + worker->task =3D task; + wake_up_process(task); /* avoid contributing to loadavg */ + ret =3D xa_alloc(&dev->worker_xa, &id, worker, xa_limit_32b, GFP_KERNEL); + if (ret < 0) + goto stop_worker; + worker->id =3D id; + + ret =3D vhost_attach_cgroups(dev); + if (ret) + goto stop_worker; + + return worker; + +stop_worker: + kthread_stop(worker->task); +free_worker: + kfree(worker); + return NULL; +} + /* Caller must have device mutex */ static void __vhost_vq_attach_worker(struct vhost_virtqueue *vq, struct vhost_worker *worker) @@ -936,6 +981,14 @@ static int vhost_vq_attach_worker(struct vhost_virtque= ue *vq, return 0; } =20 +static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) +{ + if (use_kthread) + return vhost_worker_create_kthread(dev); + else + return vhost_worker_create_task(dev); +} + /* Caller must have device mutex */ static int vhost_new_worker(struct vhost_dev *dev, struct vhost_worker_state *info) --=20 2.45.0 From nobody Sat Nov 30 16:21:46 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 6C3102263A for ; Mon, 9 Sep 2024 01:36:50 +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=1725845812; cv=none; b=GZ7/4Kvl4c1hdGQ3RiWi90Qt5H6La4+6cKLGRwXepL+AqWVJuX/Kj5pn983pOcc9zbSei37zf/LJWUdTEpuk6EGOYxxWcsgEyLHEnxx8ULZOvRAK5Ygd2scxEtJi+0dH7vh1EN4rarogCEmGHHqn5nrlAfkFd5CG1s3hPZpBtMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725845812; c=relaxed/simple; bh=oE3m8E6nH9UMyhDIkgGxy8s79NH/H0CVrWS1/6DOtq4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=StaNph4LfeVqPh0gJdbIubML7D59T+Z5AY5uY3zNOnbtnawPYfvo0JZ7cMKOBWnAViuHoI2bPpKayy/oIHWBUN/YhLft8BIq9QTzQnBfER2khWx8cRLbrQbnZde35OA86SOn5Qt1i+yr6jHlwy9w9YHoGeG83P3YWhCIT6+MdAg= 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=bs1+pRh+; 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="bs1+pRh+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725845809; 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=QC3M+l8iJWZEevnljOoIIP4I/7torTZh9gwIfyPDAYw=; b=bs1+pRh+wiSlhAVf2zcDgypysy8Yv5Re76tsQvtqDqpmQifZtaEkhb265vsb1+CBK1dqkv uqKN53fqKFPgYUvn+QrAIRxxgjpfk6jfXvbr0TmmXWh0JPer187aT5t5OiWJMFFpyOU7BD Q1/P+D4R52ElpoY6OGEjphriNRHn8mc= 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-153-FWjPIzHgOE2K4k17QLnMUw-1; Sun, 08 Sep 2024 21:36:45 -0400 X-MC-Unique: FWjPIzHgOE2K4k17QLnMUw-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B2F641977009; Mon, 9 Sep 2024 01:36:44 +0000 (UTC) Received: from server.redhat.com (unknown [10.72.112.25]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C482819560AA; Mon, 9 Sep 2024 01:36:39 +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 v1 7/7] vhost: Add new UAPI to support change to task mode Date: Mon, 9 Sep 2024 09:33:46 +0800 Message-ID: <20240909013531.1243525-8-lulu@redhat.com> In-Reply-To: <20240909013531.1243525-1-lulu@redhat.com> References: <20240909013531.1243525-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_ENFORCE_TASK to set the mode. This setting must be set before VHOST_SET_OWNER is set. Signed-off-by: Cindy Lu --- drivers/vhost/vhost.c | 16 +++++++++++++++- include/uapi/linux/vhost.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index bf1e971cb06f..8ed6b3a947a9 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2340,14 +2340,28 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned = int ioctl, void __user *argp) { struct eventfd_ctx *ctx; u64 p; - long r; + long r =3D 0; int i, fd; + bool enforce_task; =20 /* If you are not the owner, you can become one */ if (ioctl =3D=3D VHOST_SET_OWNER) { r =3D vhost_dev_set_owner(d); goto done; } + if (ioctl =3D=3D VHOST_SET_ENFORCE_TASK) { + /* Is there an owner already? */ + if (vhost_dev_has_owner(d)) { + r =3D -EBUSY; + goto done; + } + if (copy_from_user(&kthread, argp, sizeof(enforce_task))) { + r =3D -EFAULT; + goto done; + } + use_kthread =3D enforce_task; + goto done; + } =20 /* You must be the owner to do anything else */ r =3D vhost_dev_check_owner(d); diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index b95dd84eef2d..9853d62d2d34 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -235,4 +235,6 @@ */ #define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \ struct vhost_vring_state) + +#define VHOST_SET_ENFORCE_TASK _IOW(VHOST_VIRTIO, 0x83, bool) #endif --=20 2.45.0