Re: [PATCH v6 01/11] vhost: add vhost_worker pointer to vhost_virtqueue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 28, 2023 at 10:17 AM Mike Christie
<michael.christie@xxxxxxxxxx> wrote:
>
> This patchset allows userspace to map vqs to different workers. This
> patch adds a worker pointer to the vq so we can store that info.
>
> Signed-off-by: Mike Christie <michael.christie@xxxxxxxxxx>

Acked-by: Jason Wang <jasowang@xxxxxxxxxx>

Thanks

> ---
>  drivers/vhost/vhost.c | 24 +++++++++++++-----------
>  drivers/vhost/vhost.h |  1 +
>  2 files changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 4368ee9b999c..e041e116afee 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -486,6 +486,7 @@ void vhost_dev_init(struct vhost_dev *dev,
>                 vq->log = NULL;
>                 vq->indirect = NULL;
>                 vq->heads = NULL;
> +               vq->worker = NULL;
>                 vq->dev = dev;
>                 mutex_init(&vq->mutex);
>                 vhost_vq_reset(dev, vq);
> @@ -554,16 +555,15 @@ static void vhost_worker_free(struct vhost_dev *dev)
>         kfree(worker);
>  }
>
> -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_task *vtsk;
>         char name[TASK_COMM_LEN];
> -       int ret;
>
>         worker = kzalloc(sizeof(*worker), GFP_KERNEL_ACCOUNT);
>         if (!worker)
> -               return -ENOMEM;
> +               return NULL;
>
>         dev->worker = worker;
>         worker->kcov_handle = kcov_common_handle();
> @@ -571,25 +571,24 @@ static int vhost_worker_create(struct vhost_dev *dev)
>         snprintf(name, sizeof(name), "vhost-%d", current->pid);
>
>         vtsk = vhost_task_create(vhost_worker, worker, name);
> -       if (!vtsk) {
> -               ret = -ENOMEM;
> +       if (!vtsk)
>                 goto free_worker;
> -       }
>
>         worker->vtsk = vtsk;
>         vhost_task_start(vtsk);
> -       return 0;
> +       return worker;
>
>  free_worker:
>         kfree(worker);
>         dev->worker = NULL;
> -       return ret;
> +       return NULL;
>  }
>
>  /* Caller should have device mutex */
>  long vhost_dev_set_owner(struct vhost_dev *dev)
>  {
> -       int err;
> +       struct vhost_worker *worker;
> +       int err, i;
>
>         /* Is there an owner already? */
>         if (vhost_dev_has_owner(dev)) {
> @@ -600,9 +599,12 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
>         vhost_attach_mm(dev);
>
>         if (dev->use_worker) {
> -               err = vhost_worker_create(dev);
> -               if (err)
> +               worker = vhost_worker_create(dev);
> +               if (!worker)
>                         goto err_worker;
> +
> +               for (i = 0; i < dev->nvqs; i++)
> +                       dev->vqs[i]->worker = worker;
>         }
>
>         err = vhost_dev_alloc_iovecs(dev);
> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> index 0308638cdeee..e72b665ba3a5 100644
> --- a/drivers/vhost/vhost.h
> +++ b/drivers/vhost/vhost.h
> @@ -74,6 +74,7 @@ struct vhost_vring_call {
>  /* The virtqueue structure describes a queue attached to a device. */
>  struct vhost_virtqueue {
>         struct vhost_dev *dev;
> +       struct vhost_worker *worker;
>
>         /* The actual ring of buffers. */
>         struct mutex mutex;
> --
> 2.25.1
>

_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization




[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux