[PATCH vhost v2 1/4] virtio: find_vqs: pass struct instead of multi parameters
Eric Farman
farman at linux.ibm.com
Mon Mar 11 08:52:19 PDT 2024
On Mon, 2024-03-11 at 15:21 +0800, Xuan Zhuo wrote:
> Now, we pass multi parameters to find_vqs. These parameters
> may work for transport or work for vring.
>
> And find_vqs has multi implements in many places:
>
> arch/um/drivers/virtio_uml.c
> drivers/platform/mellanox/mlxbf-tmfifo.c
> drivers/remoteproc/remoteproc_virtio.c
> drivers/s390/virtio/virtio_ccw.c
> drivers/virtio/virtio_mmio.c
> drivers/virtio/virtio_pci_legacy.c
> drivers/virtio/virtio_pci_modern.c
> drivers/virtio/virtio_vdpa.c
>
> Every time, we try to add a new parameter, that is difficult.
> We must change every find_vqs implement.
>
> One the other side, if we want to pass a parameter to vring,
> we must change the call path from transport to vring.
> Too many functions need to be changed.
>
> So it is time to refactor the find_vqs. We pass a structure
> cfg to find_vqs(), that will be passed to vring by transport.
>
> Signed-off-by: Xuan Zhuo <xuanzhuo at linux.alibaba.com>
> Acked-by: Johannes Berg <johannes at sipsolutions.net>
> ---
> arch/um/drivers/virtio_uml.c | 23 +++----
> drivers/platform/mellanox/mlxbf-tmfifo.c | 13 ++--
> drivers/remoteproc/remoteproc_virtio.c | 28 ++++-----
> drivers/s390/virtio/virtio_ccw.c | 29 +++++----
> drivers/virtio/virtio_mmio.c | 26 ++++----
> drivers/virtio/virtio_pci_common.c | 60 +++++++++---------
> drivers/virtio/virtio_pci_common.h | 9 +--
> drivers/virtio/virtio_pci_legacy.c | 11 ++--
> drivers/virtio/virtio_pci_modern.c | 33 ++++++----
> drivers/virtio/virtio_vdpa.c | 36 +++++------
> include/linux/virtio_config.h | 77 +++++++++++++++++++---
> --
> 11 files changed, 192 insertions(+), 153 deletions(-)
>
>
...snip...
>
> diff --git a/drivers/virtio/virtio_pci_modern.c
> b/drivers/virtio/virtio_pci_modern.c
> index f62b530aa3b5..b2cdf5d3824d 100644
> --- a/drivers/virtio/virtio_pci_modern.c
> +++ b/drivers/virtio/virtio_pci_modern.c
> @@ -530,9 +530,7 @@ static bool vp_notify_with_data(struct virtqueue
> *vq)
> static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev,
> struct virtio_pci_vq_info *info,
> unsigned int index,
> - void (*callback)(struct virtqueue
> *vq),
> - const char *name,
> - bool ctx,
> + struct virtio_vq_config *cfg,
> u16 msix_vec)
> {
>
> @@ -563,8 +561,11 @@ static struct virtqueue *setup_vq(struct
> virtio_pci_device *vp_dev,
> /* create the vring */
> vq = vring_create_virtqueue(index, num,
> SMP_CACHE_BYTES, &vp_dev->vdev,
> - true, true, ctx,
> - notify, callback, name);
> + true, true,
> + cfg->ctx ? cfg->ctx[cfg-
> >cfg_idx] : false,
> + notify,
> + cfg->callbacks[cfg->cfg_idx],
> + cfg->names[cfg->cfg_idx]);
> if (!vq)
> return ERR_PTR(-ENOMEM);
>
> @@ -593,15 +594,11 @@ static struct virtqueue *setup_vq(struct
> virtio_pci_device *vp_dev,
> return ERR_PTR(err);
> }
>
> -static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned
> int nvqs,
> - struct virtqueue *vqs[],
> - vq_callback_t *callbacks[],
> - const char * const names[], const bool
> *ctx,
> - struct irq_affinity *desc)
> +static int vp_modern_find_vqs(struct virtio_device *vdev, struct
> virtio_vq_config *cfg)
> {
> struct virtio_pci_device *vp_dev = to_vp_device(vdev);
> struct virtqueue *vq;
> - int rc = vp_find_vqs(vdev, nvqs, vqs, callbacks, names, ctx,
> desc);
> + int rc = vp_find_vqs(vdev, cfg);
>
> if (rc)
> return rc;
> @@ -739,10 +736,17 @@ static bool vp_get_shm_region(struct
> virtio_device *vdev,
> static int vp_modern_create_avq(struct virtio_device *vdev)
> {
> struct virtio_pci_device *vp_dev = to_vp_device(vdev);
> + vq_callback_t *callbacks[] = { NULL };
> + struct virtio_vq_config cfg = {};
> struct virtio_pci_admin_vq *avq;
> struct virtqueue *vq;
> + const char *names[1];
> u16 admin_q_num;
>
> + cfg.nvqs = 1;
> + cfg.callbacks = callbacks;
> + cfg.names = names;
> +
> if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
> return 0;
>
> @@ -753,8 +757,11 @@ static int vp_modern_create_avq(struct
> virtio_device *vdev)
> avq = &vp_dev->admin_vq;
> avq->vq_index = vp_modern_avq_index(&vp_dev->mdev);
> sprintf(avq->name, "avq.%u", avq->vq_index);
> - vq = vp_dev->setup_vq(vp_dev, &vp_dev->admin_vq.info, avq-
> >vq_index, NULL,
> - avq->name, NULL,
> VIRTIO_MSI_NO_VECTOR);
> +
> + cfg.names[0] = avq->name;
While looking at the s390 changes, I observe that the above fails to
compile and is subsequently fixed in patch 2:
drivers/virtio/virtio_pci_modern.c: In function ‘vp_modern_create_avq’:
drivers/virtio/virtio_pci_modern.c:761:22: error: assignment of read-
only location ‘*cfg.names’
761 | cfg.names[0] = avq->name;
| ^
More information about the linux-um
mailing list