Commit 737bdb64 authored by Mike Christie's avatar Mike Christie Committed by Michael S. Tsirkin

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: default avatarMike Christie <michael.christie@oracle.com>
Message-Id: <20230626232307.97930-4-michael.christie@oracle.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent c011bb66
...@@ -333,6 +333,7 @@ static void vhost_vq_reset(struct vhost_dev *dev, ...@@ -333,6 +333,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
vq->busyloop_timeout = 0; vq->busyloop_timeout = 0;
vq->umem = NULL; vq->umem = NULL;
vq->iotlb = NULL; vq->iotlb = NULL;
vq->worker = NULL;
vhost_vring_call_reset(&vq->call_ctx); vhost_vring_call_reset(&vq->call_ctx);
__vhost_vq_meta_reset(vq); __vhost_vq_meta_reset(vq);
} }
...@@ -545,7 +546,7 @@ static void vhost_worker_free(struct vhost_dev *dev) ...@@ -545,7 +546,7 @@ static void vhost_worker_free(struct vhost_dev *dev)
dev->worker = NULL; dev->worker = NULL;
} }
static int vhost_worker_create(struct vhost_dev *dev) static struct vhost_worker *vhost_worker_create(struct vhost_dev *dev)
{ {
struct vhost_worker *worker; struct vhost_worker *worker;
struct vhost_task *vtsk; struct vhost_task *vtsk;
...@@ -553,7 +554,7 @@ static int vhost_worker_create(struct vhost_dev *dev) ...@@ -553,7 +554,7 @@ static int vhost_worker_create(struct vhost_dev *dev)
worker = kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT); worker = kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT);
if (!worker) if (!worker)
return -ENOMEM; return NULL;
snprintf(name, sizeof(name), "vhost-%d", current->pid); snprintf(name, sizeof(name), "vhost-%d", current->pid);
...@@ -572,17 +573,18 @@ static int vhost_worker_create(struct vhost_dev *dev) ...@@ -572,17 +573,18 @@ static int vhost_worker_create(struct vhost_dev *dev)
dev->worker = worker; dev->worker = worker;
vhost_task_start(vtsk); vhost_task_start(vtsk);
return 0; return worker;
free_worker: free_worker:
kfree(worker); kfree(worker);
return -ENOMEM; return NULL;
} }
/* Caller should have device mutex */ /* Caller should have device mutex */
long vhost_dev_set_owner(struct vhost_dev *dev) long vhost_dev_set_owner(struct vhost_dev *dev)
{ {
int err; struct vhost_worker *worker;
int err, i;
/* Is there an owner already? */ /* Is there an owner already? */
if (vhost_dev_has_owner(dev)) { if (vhost_dev_has_owner(dev)) {
...@@ -603,9 +605,14 @@ long vhost_dev_set_owner(struct vhost_dev *dev) ...@@ -603,9 +605,14 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
* below since we don't have to worry about vsock queueing * below since we don't have to worry about vsock queueing
* while we free the worker. * while we free the worker.
*/ */
err = vhost_worker_create(dev); worker = vhost_worker_create(dev);
if (err) if (!worker) {
err = -ENOMEM;
goto err_worker; goto err_worker;
}
for (i = 0; i < dev->nvqs; i++)
dev->vqs[i]->worker = worker;
} }
return 0; return 0;
......
...@@ -74,6 +74,7 @@ struct vhost_vring_call { ...@@ -74,6 +74,7 @@ struct vhost_vring_call {
/* The virtqueue structure describes a queue attached to a device. */ /* The virtqueue structure describes a queue attached to a device. */
struct vhost_virtqueue { struct vhost_virtqueue {
struct vhost_dev *dev; struct vhost_dev *dev;
struct vhost_worker *worker;
/* The actual ring of buffers. */ /* The actual ring of buffers. */
struct mutex mutex; struct mutex mutex;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment