From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: virtualization@lists.linux.dev
Cc: "Richard Weinberger" <richard@nod.at>,
"Anton Ivanov" <anton.ivanov@cambridgegreys.com>,
"Johannes Berg" <johannes@sipsolutions.net>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Vadim Pasternak" <vadimp@nvidia.com>,
"Bjorn Andersson" <andersson@kernel.org>,
"Mathieu Poirier" <mathieu.poirier@linaro.org>,
"Cornelia Huck" <cohuck@redhat.com>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Eric Farman" <farman@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Sven Schnelle" <svens@linux.ibm.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
linux-um@lists.infradead.org, netdev@vger.kernel.org,
platform-driver-x86@vger.kernel.org,
linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org,
kvm@vger.kernel.org, bpf@vger.kernel.org
Subject: [PATCH vhost v3 09/19] virtio: vring_new_virtqueue(): pass struct instead of multi parameters
Date: Thu, 29 Feb 2024 15:20:34 +0800 [thread overview]
Message-ID: <20240229072044.77388-10-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <20240229072044.77388-1-xuanzhuo@linux.alibaba.com>
Just like find_vqs(), it is time to refactor the
vring_new_virtqueue(). We pass the similar struct to
vring_new_virtqueue.
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
drivers/platform/mellanox/mlxbf-tmfifo.c | 13 +++++---
drivers/remoteproc/remoteproc_virtio.c | 11 ++++---
drivers/virtio/virtio_ring.c | 29 +++++++++++-----
include/linux/virtio_ring.h | 42 +++++++++++++++++++-----
tools/virtio/virtio_test.c | 4 +--
tools/virtio/vringh_test.c | 28 ++++++++--------
6 files changed, 85 insertions(+), 42 deletions(-)
diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c b/drivers/platform/mellanox/mlxbf-tmfifo.c
index 4252388f52a2..36cfce5ba8cf 100644
--- a/drivers/platform/mellanox/mlxbf-tmfifo.c
+++ b/drivers/platform/mellanox/mlxbf-tmfifo.c
@@ -1059,6 +1059,7 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
struct virtio_vq_config *cfg)
{
struct mlxbf_tmfifo_vdev *tm_vdev = mlxbf_vdev_to_tmfifo(vdev);
+ struct vq_transport_config tp_cfg = {};
struct virtqueue **vqs = cfg->vqs;
struct mlxbf_tmfifo_vring *vring;
unsigned int nvqs = cfg->nvqs;
@@ -1078,10 +1079,14 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
/* zero vring */
size = vring_size(vring->num, vring->align);
memset(vring->va, 0, size);
- vq = vring_new_virtqueue(i, vring->num, vring->align, vdev,
- false, false, vring->va,
- mlxbf_tmfifo_virtio_notify,
- cfg->callbacks[i], cfg->names[i]);
+
+ tp_cfg.num = vring->num;
+ tp_cfg.vring_align = vring->align;
+ tp_cfg.weak_barriers = false;
+ tp_cfg.notify = mlxbf_tmfifo_virtio_notify;
+
+ cfg->cfg_idx = i;
+ vq = vring_new_virtqueue(vdev, i, vring->va, &tp_cfg, cfg);
if (!vq) {
dev_err(&vdev->dev, "vring_new_virtqueue failed\n");
ret = -ENOMEM;
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index 57d51c9c7b63..70c32837f9dc 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -106,6 +106,7 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,
{
struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
struct rproc *rproc = vdev_to_rproc(vdev);
+ struct vq_transport_config tp_cfg;
struct device *dev = &rproc->dev;
struct rproc_mem_entry *mem;
struct rproc_vring *rvring;
@@ -138,14 +139,16 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,
dev_dbg(dev, "vring%d: va %pK qsz %d notifyid %d\n",
id, addr, num, rvring->notifyid);
+ tp_cfg.num = num;
+ tp_cfg.vring_align = rvring->align;
+ tp_cfg.weak_barriers = false;
+ tp_cfg.notify = rproc_virtio_notify;
+
/*
* Create the new vq, and tell virtio we're not interested in
* the 'weak' smp barriers, since we're talking with a real device.
*/
- vq = vring_new_virtqueue(id, num, rvring->align, vdev, false,
- cfg->ctx ? cfg->ctx[cfg->cfg_idx] : false,
- addr, rproc_virtio_notify, cfg->callbacks[cfg->cfg_idx],
- cfg->names[cfg->cfg_idx]);
+ vq = vring_new_virtqueue(vdev, id, addr, &tp_cfg, cfg);
if (!vq) {
dev_err(dev, "vring_new_virtqueue %s failed\n", cfg->names[cfg->cfg_idx]);
rproc_free_vring(rvring);
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index b77ee139a5d9..e21d506d0f93 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -2909,18 +2909,29 @@ int virtqueue_reset(struct virtqueue *_vq,
EXPORT_SYMBOL_GPL(virtqueue_reset);
/* Only available for split ring */
-struct virtqueue *vring_new_virtqueue(unsigned int index,
- unsigned int num,
- unsigned int vring_align,
- struct virtio_device *vdev,
- bool weak_barriers,
- bool context,
+struct virtqueue *vring_new_virtqueue(struct virtio_device *vdev,
+ unsigned int index,
void *pages,
- bool (*notify)(struct virtqueue *vq),
- void (*callback)(struct virtqueue *vq),
- const char *name)
+ struct vq_transport_config *tp_cfg,
+ struct virtio_vq_config *cfg)
{
struct vring_virtqueue_split vring_split = {};
+ unsigned int num;
+ unsigned int vring_align;
+ bool weak_barriers;
+ bool context;
+ bool (*notify)(struct virtqueue *_);
+ void (*callback)(struct virtqueue *_);
+ const char *name;
+
+ num = tp_cfg->num;
+ vring_align = tp_cfg->vring_align;
+ weak_barriers = tp_cfg->weak_barriers;
+ notify = tp_cfg->notify;
+
+ name = cfg->names[cfg->cfg_idx];
+ callback = cfg->callbacks[cfg->cfg_idx];
+ context = cfg->ctx ? cfg->ctx[cfg->cfg_idx] : false;
if (virtio_has_feature(vdev, VIRTIO_F_RING_PACKED))
return NULL;
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
index cd8042c79814..616937780785 100644
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -85,16 +85,40 @@ struct virtqueue *vring_create_virtqueue(struct virtio_device *vdev,
* Creates a virtqueue with a standard layout but a caller-allocated
* ring.
*/
-struct virtqueue *vring_new_virtqueue(unsigned int index,
- unsigned int num,
- unsigned int vring_align,
- struct virtio_device *vdev,
- bool weak_barriers,
- bool ctx,
+struct virtqueue *vring_new_virtqueue(struct virtio_device *vdev,
+ unsigned int index,
void *pages,
- bool (*notify)(struct virtqueue *vq),
- void (*callback)(struct virtqueue *vq),
- const char *name);
+ struct vq_transport_config *tp_cfg,
+ struct virtio_vq_config *cfg);
+
+static inline struct virtqueue *vring_new_virtqueue_one(unsigned int index,
+ unsigned int num,
+ unsigned int vring_align,
+ struct virtio_device *vdev,
+ bool weak_barriers,
+ bool context,
+ void *pages,
+ bool (*notify)(struct virtqueue *vq),
+ void (*callback)(struct virtqueue *vq),
+ const char *name)
+{
+ struct vq_transport_config tp_cfg = {};
+ struct virtio_vq_config cfg = {};
+ vq_callback_t *callbacks[] = { callback };
+ const char *names[] = { name };
+
+ tp_cfg.num = num;
+ tp_cfg.vring_align = vring_align;
+ tp_cfg.weak_barriers = weak_barriers;
+ tp_cfg.notify = notify;
+
+ cfg.nvqs = 1;
+ cfg.callbacks = callbacks;
+ cfg.names = names;
+ cfg.ctx = &context;
+
+ return vring_new_virtqueue(vdev, index, pages, &tp_cfg, &cfg);
+}
/*
* Destroys a virtqueue. If created with vring_create_virtqueue, this
diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
index 028f54e6854a..e41300d71d5e 100644
--- a/tools/virtio/virtio_test.c
+++ b/tools/virtio/virtio_test.c
@@ -102,8 +102,8 @@ static void vq_reset(struct vq_info *info, int num, struct virtio_device *vdev)
memset(info->ring, 0, vring_size(num, 4096));
vring_init(&info->vring, num, info->ring, 4096);
- info->vq = vring_new_virtqueue(info->idx, num, 4096, vdev, true, false,
- info->ring, vq_notify, vq_callback, "test");
+ info->vq = vring_new_virtqueue_one(info->idx, num, 4096, vdev, true, false,
+ info->ring, vq_notify, vq_callback, "test");
assert(info->vq);
info->vq->priv = info;
}
diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c
index 98ff808d6f0c..040689111584 100644
--- a/tools/virtio/vringh_test.c
+++ b/tools/virtio/vringh_test.c
@@ -316,11 +316,11 @@ static int parallel_test(u64 features,
if (sched_setaffinity(getpid(), sizeof(cpu_set), &cpu_set))
err(1, "Could not set affinity to cpu %u", first_cpu);
- vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &gvdev.vdev, true,
- false, guest_map,
- fast_vringh ? no_notify_host
- : parallel_notify_host,
- never_callback_guest, "guest vq");
+ vq = vring_new_virtqueue_one(0, RINGSIZE, ALIGN, &gvdev.vdev, true,
+ false, guest_map,
+ fast_vringh ? no_notify_host
+ : parallel_notify_host,
+ never_callback_guest, "guest vq");
/* Don't kfree indirects. */
__kfree_ignore_start = indirects;
@@ -485,10 +485,10 @@ int main(int argc, char *argv[])
memset(__user_addr_min, 0, vring_size(RINGSIZE, ALIGN));
/* Set up guest side. */
- vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &vdev, true, false,
- __user_addr_min,
- never_notify_host, never_callback_guest,
- "guest vq");
+ vq = vring_new_virtqueue_one(0, RINGSIZE, ALIGN, &vdev, true, false,
+ __user_addr_min,
+ never_notify_host, never_callback_guest,
+ "guest vq");
/* Set up host side. */
vring_init(&vrh.vring, RINGSIZE, __user_addr_min, ALIGN);
@@ -668,11 +668,11 @@ int main(int argc, char *argv[])
/* Force creation of direct, which we modify. */
__virtio_clear_bit(&vdev, VIRTIO_RING_F_INDIRECT_DESC);
- vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &vdev, true,
- false, __user_addr_min,
- never_notify_host,
- never_callback_guest,
- "guest vq");
+ vq = vring_new_virtqueue_one(0, RINGSIZE, ALIGN, &vdev, true,
+ false, __user_addr_min,
+ never_notify_host,
+ never_callback_guest,
+ "guest vq");
sg_init_table(guest_sg, 4);
sg_set_buf(&guest_sg[0], d, sizeof(*d)*2);
--
2.32.0.3.g01195cf9f
next prev parent reply other threads:[~2024-02-29 7:21 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 7:20 [PATCH vhost v3 00/19] virtio: drivers maintain dma info for premapped vq Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 01/19] virtio_ring: introduce vring_need_unmap_buffer Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 02/19] virtio_ring: packed: remove double check of the unmap ops Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 03/19] virtio_ring: packed: structure the indirect desc table Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 04/19] virtio_ring: split: remove double check of the unmap ops Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 05/19] virtio_ring: split: structure the indirect desc table Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 06/19] virtio_ring: no store dma info when unmap is not needed Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 07/19] virtio: find_vqs: pass struct instead of multi parameters Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 08/19] virtio: vring_create_virtqueue: " Xuan Zhuo
2024-02-29 7:20 ` Xuan Zhuo [this message]
2024-02-29 7:20 ` [PATCH vhost v3 10/19] virtio_ring: simplify the parameters of the funcs related to vring_create/new_virtqueue() Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 11/19] virtio: find_vqs: add new parameter premapped Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 12/19] virtio_ring: export premapped to driver by struct virtqueue Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 13/19] virtio_net: set premapped mode by find_vqs() Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 14/19] virtio_ring: remove api of setting vq premapped Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 15/19] virtio_ring: introduce dma map api for page Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 16/19] virtio_ring: introduce virtqueue_dma_map_sg_attrs Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 17/19] virtio_net: unify the code for recycling the xmit ptr Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 18/19] virtio_net: rename free_old_xmit_skbs to free_old_xmit Xuan Zhuo
2024-02-29 7:20 ` [PATCH vhost v3 19/19] virtio_net: sq support premapped mode Xuan Zhuo
2024-02-29 8:21 ` [PATCH vhost v3 00/19] virtio: drivers maintain dma info for premapped vq Michael S. Tsirkin
2024-02-29 9:02 ` Xuan Zhuo
2024-02-29 9:34 ` Michael S. Tsirkin
2024-02-29 9:36 ` Xuan Zhuo
2024-02-29 9:41 ` Johannes Berg
2024-02-29 9:42 ` Xuan Zhuo
2024-03-06 9:54 ` Xuan Zhuo
2024-03-07 5:28 ` Jason Wang
2024-03-07 8:06 ` Xuan Zhuo
2024-03-08 6:03 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240229072044.77388-10-xuanzhuo@linux.alibaba.com \
--to=xuanzhuo@linux.alibaba.com \
--cc=agordeev@linux.ibm.com \
--cc=andersson@kernel.org \
--cc=anton.ivanov@cambridgegreys.com \
--cc=ast@kernel.org \
--cc=borntraeger@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=cohuck@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=farman@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hawk@kernel.org \
--cc=hca@linux.ibm.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jasowang@redhat.com \
--cc=johannes@sipsolutions.net \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=mathieu.poirier@linaro.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=richard@nod.at \
--cc=svens@linux.ibm.com \
--cc=vadimp@nvidia.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox