[Devel] [PATCH RHEL9 COMMIT] Revert "drivers/vhost: rework worker creation"

Konstantin Khorenko khorenko at virtuozzo.com
Wed Nov 16 17:03:17 MSK 2022


The commit is pushed to "branch-rh9-5.14.0-70.22.1.vz9.17.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-70.22.1.vz9.17.9
------>
commit f7e09006317559dd8a0874f83f540f6030d3d6d9
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Wed Nov 16 15:56:12 2022 +0300

    Revert "drivers/vhost: rework worker creation"
    
    This reverts commit c4284dad02c76eb6e28a6776700258b92e529d61.
    
    Will apply v5 of the patchset.
    https://jira.sw.ru/browse/PSBM-139414
    
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 drivers/vhost/vhost.c | 64 +++++++++++++++++++++------------------------------
 1 file changed, 26 insertions(+), 38 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 0542eab1e815..5199495d948a 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -625,65 +625,53 @@ static void vhost_detach_mm(struct vhost_dev *dev)
 	dev->mm = NULL;
 }
 
-static int vhost_add_worker(struct vhost_dev *dev)
-{
-	struct vhost_worker *w = &dev->workers[dev->nworkers];
-	struct task_struct *worker;
-	int err;
-
-	if (dev->nworkers == VHOST_MAX_WORKERS)
-		return -E2BIG;
-
-	worker = kthread_create(vhost_worker, w,
-				"vhost-%d-%d", current->pid, dev->nworkers);
-	if (IS_ERR(worker))
-		return PTR_ERR(worker);
-
-	w->worker = worker;
-	wake_up_process(worker); /* avoid contributing to loadavg */
-
-	err = vhost_worker_attach_cgroups(w);
-	if (err)
-		goto cleanup;
-
-	dev->nworkers++;
-	return 0;
-
-cleanup:
-	kthread_stop(worker);
-	w->worker = NULL;
-
-	return err;
-}
-
 /* Caller should have device mutex */
 long vhost_dev_set_owner(struct vhost_dev *dev)
 {
+	struct task_struct *worker;
 	int err;
 
 	/* Is there an owner already? */
-	if (vhost_dev_has_owner(dev))
-		return -EBUSY;
+	if (vhost_dev_has_owner(dev)) {
+		err = -EBUSY;
+		goto err_mm;
+	}
 
 	vhost_attach_mm(dev);
 
 	dev->kcov_handle = kcov_common_handle();
 	if (dev->use_worker) {
-		err = vhost_add_worker(dev);
+		worker = kthread_create(vhost_worker, dev,
+					"vhost-%d", current->pid);
+		if (IS_ERR(worker)) {
+			err = PTR_ERR(worker);
+			goto err_worker;
+		}
+
+		dev->workers[0].worker = worker;
+		dev->nworkers = 1;
+		wake_up_process(worker); /* avoid contributing to loadavg */
+
+		err = vhost_worker_attach_cgroups(&dev->workers[0]);
 		if (err)
-			goto err_mm;
+			goto err_cgroup;
 	}
 
 	err = vhost_dev_alloc_iovecs(dev);
 	if (err)
-		goto err_worker;
+		goto err_cgroup;
 
 	return 0;
+err_cgroup:
+	dev->nworkers = 0;
+	if (dev->workers[0].worker) {
+		kthread_stop(dev->workers[0].worker);
+		dev->workers[0].worker = NULL;
+	}
 err_worker:
-	vhost_cleanup_workers(dev);
-err_mm:
 	vhost_detach_mm(dev);
 	dev->kcov_handle = 0;
+err_mm:
 	return err;
 }
 EXPORT_SYMBOL_GPL(vhost_dev_set_owner);


More information about the Devel mailing list