Skip to content

Commit 737bdb6

Browse files
mikechristiemstsirkin
authored andcommitted
vhost: add vhost_worker pointer to vhost_virtqueue
This patchset allows userspace to map vqs to different workers. This patch adds a worker pointer to the vq so in later patches in this set we can queue/flush specific vqs and their workers. Signed-off-by: Mike Christie <michael.christie@oracle.com> Message-Id: <20230626232307.97930-4-michael.christie@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent c011bb6 commit 737bdb6

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

drivers/vhost/vhost.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
333333
vq->busyloop_timeout = 0;
334334
vq->umem = NULL;
335335
vq->iotlb = NULL;
336+
vq->worker = NULL;
336337
vhost_vring_call_reset(&vq->call_ctx);
337338
__vhost_vq_meta_reset(vq);
338339
}
@@ -545,15 +546,15 @@ static void vhost_worker_free(struct vhost_dev *dev)
545546
dev->worker = NULL;
546547
}
547548

548-
static int vhost_worker_create(struct vhost_dev *dev)
549+
static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev)
549550
{
550551
struct vhost_worker *worker;
551552
struct vhost_task *vtsk;
552553
char name[TASK_COMM_LEN];
553554

554555
worker = kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT);
555556
if (!worker)
556-
return -ENOMEM;
557+
return NULL;
557558

558559
snprintf(name, sizeof(name), "vhost-%d", current->pid);
559560

@@ -572,17 +573,18 @@ static int vhost_worker_create(struct vhost_dev *dev)
572573
dev->worker = worker;
573574

574575
vhost_task_start(vtsk);
575-
return 0;
576+
return worker;
576577

577578
free_worker:
578579
kfree(worker);
579-
return -ENOMEM;
580+
return NULL;
580581
}
581582

582583
/* Caller should have device mutex */
583584
long vhost_dev_set_owner(struct vhost_dev *dev)
584585
{
585-
int err;
586+
struct vhost_worker *worker;
587+
int err, i;
586588

587589
/* Is there an owner already? */
588590
if (vhost_dev_has_owner(dev)) {
@@ -603,9 +605,14 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
603605
* below since we don't have to worry about vsock queueing
604606
* while we free the worker.
605607
*/
606-
err = vhost_worker_create(dev);
607-
if (err)
608+
worker = vhost_worker_create(dev);
609+
if (!worker) {
610+
err = -ENOMEM;
608611
goto err_worker;
612+
}
613+
614+
for (i = 0; i < dev->nvqs; i++)
615+
dev->vqs[i]->worker = worker;
609616
}
610617

611618
return 0;

drivers/vhost/vhost.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct vhost_vring_call {
7474
/* The virtqueue structure describes a queue attached to a device. */
7575
struct vhost_virtqueue {
7676
struct vhost_dev *dev;
77+
struct vhost_worker *worker;
7778

7879
/* The actual ring of buffers. */
7980
struct mutex mutex;

0 commit comments

Comments
 (0)