This allows a worker to handle multiple device's vqs. TODO: - How to handle if the devices are in different cgroups/VMs. Signed-off-by: Mike Christie <michael.christie@xxxxxxxxxx> --- drivers/vhost/vhost.c | 18 +++++++----------- drivers/vhost/vhost.h | 1 - 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 7ba0c303bb98..b2d567a4cd53 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -387,12 +387,10 @@ static void vhost_vq_reset(struct vhost_dev *dev, static int vhost_worker(void *data) { struct vhost_worker *worker = data; - struct vhost_dev *dev = worker->dev; struct vhost_work *work, *work_next; + struct vhost_dev *dev; struct llist_node *node; - kthread_use_mm(dev->mm); - for (;;) { /* mb paired w/ kthread_stop */ set_current_state(TASK_INTERRUPTIBLE); @@ -411,15 +409,20 @@ static int vhost_worker(void *data) smp_wmb(); llist_for_each_entry_safe(work, work_next, node, node) { clear_bit(VHOST_WORK_QUEUED, &work->flags); + dev = work->dev; + + kthread_use_mm(dev->mm); + __set_current_state(TASK_RUNNING); kcov_remote_start_common(dev->kcov_handle); work->fn(work); kcov_remote_stop(); if (need_resched()) schedule(); + + kthread_unuse_mm(dev->mm); } } - kthread_unuse_mm(dev->mm); return 0; } @@ -665,7 +668,6 @@ static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev) return NULL; worker->id = dev->num_workers; - worker->dev = dev; init_llist_head(&worker->work_list); INIT_LIST_HEAD(&worker->list); refcount_set(&worker->refcount, 1); @@ -703,12 +705,6 @@ static struct vhost_worker *vhost_worker_find(struct vhost_dev *dev, pid_t pid) if (worker->task->pid != pid) continue; - /* tmp - next patch allows sharing across devs */ - if (worker->dev != dev) { - spin_unlock(&vhost_workers_lock); - return NULL; - } - refcount_inc(&worker->refcount); spin_unlock(&vhost_workers_lock); return worker; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 051dea4e3ab6..6d97fdf231c2 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -32,7 +32,6 @@ struct vhost_worker { struct llist_head work_list; struct list_head list; refcount_t refcount; - struct vhost_dev *dev; int id; }; -- 2.25.1 _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization