From: "Eugenio Pérez" <eperezma@redhat.com>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>,
Parav Pandit <parav@mellanox.com>, Cindy Lu <lulu@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Gautam Dawar <gdawar@xilinx.com>,
Harpreet Singh Anand <hanand@xilinx.com>,
"Gonglei \(Arei\)" <arei.gonglei@huawei.com>,
Eli Cohen <eli@mellanox.com>,
Liuxiangdong <liuxiangdong5@huawei.com>,
Zhu Lingshan <lingshan.zhu@intel.com>
Subject: [RFC PATCH v7 23/25] vhost: Make possible to check for device exclusive vq group
Date: Wed, 13 Apr 2022 18:32:04 +0200 [thread overview]
Message-ID: <20220413163206.1958254-24-eperezma@redhat.com> (raw)
In-Reply-To: <20220413163206.1958254-1-eperezma@redhat.com>
CVQ needs to be in its own group, not shared with any data vq. Enable
the checking of it here, before introducing address space id concepts.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
include/hw/virtio/vhost.h | 2 +
hw/net/vhost_net.c | 4 +-
hw/virtio/vhost-vdpa.c | 79 ++++++++++++++++++++++++++++++++++++++-
hw/virtio/trace-events | 1 +
4 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 58a73e7b7a..034868fa9e 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -78,6 +78,8 @@ struct vhost_dev {
int vq_index_end;
/* if non-zero, minimum required value for max_queues */
int num_queues;
+ /* Must be a vq group different than any other vhost dev */
+ bool independent_vq_group;
uint64_t features;
uint64_t acked_features;
uint64_t backend_features;
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 44a105ec29..10480e19e5 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -343,14 +343,16 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
}
for (i = 0; i < nvhosts; i++) {
+ bool cvq_idx = i >= data_queue_pairs;
- if (i < data_queue_pairs) {
+ if (!cvq_idx) {
peer = qemu_get_peer(ncs, i);
} else { /* Control Virtqueue */
peer = qemu_get_peer(ncs, n->max_queue_pairs);
}
net = get_vhost_net(peer);
+ net->dev.independent_vq_group = !!cvq_idx;
vhost_net_set_vq_index(net, i * 2, index_end);
/* Suppress the masking guest notifiers on vhost user
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 1948c5ca7d..4096555242 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -678,7 +678,8 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev)
{
uint64_t features;
uint64_t f = 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 |
- 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH;
+ 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH |
+ 0x1ULL << VHOST_BACKEND_F_IOTLB_ASID;
int r;
if (vhost_vdpa_call(dev, VHOST_GET_BACKEND_FEATURES, &features)) {
@@ -1098,6 +1099,78 @@ static bool vhost_vdpa_svqs_stop(struct vhost_dev *dev)
return true;
}
+static int vhost_vdpa_get_vring_group(struct vhost_dev *dev,
+ struct vhost_vring_state *state)
+{
+ int ret = vhost_vdpa_call(dev, VHOST_VDPA_GET_VRING_GROUP, state);
+ trace_vhost_vdpa_get_vring_group(dev, state->index, state->num);
+ return ret;
+}
+
+static bool vhost_dev_is_independent_group(struct vhost_dev *dev)
+{
+ struct vhost_vdpa *v = dev->opaque;
+ struct vhost_vring_state this_vq_group = {
+ .index = dev->vq_index,
+ };
+ int ret;
+
+ if (!(dev->backend_cap & VHOST_BACKEND_F_IOTLB_ASID)) {
+ return true;
+ }
+
+ if (!v->shadow_vqs_enabled) {
+ return true;
+ }
+
+ ret = vhost_vdpa_get_vring_group(dev, &this_vq_group);
+ if (unlikely(ret)) {
+ goto call_err;
+ }
+
+ for (int i = 1; i < dev->nvqs; ++i) {
+ struct vhost_vring_state vq_group = {
+ .index = dev->vq_index + i,
+ };
+
+ ret = vhost_vdpa_get_vring_group(dev, &vq_group);
+ if (unlikely(ret)) {
+ goto call_err;
+ }
+ if (unlikely(vq_group.num != this_vq_group.num)) {
+ error_report("VQ %d group is different than VQ %d one",
+ this_vq_group.index, vq_group.index);
+ return false;
+ }
+ }
+
+ for (int i = 0; i < dev->vq_index_end; ++i) {
+ struct vhost_vring_state vq_group = {
+ .index = i,
+ };
+
+ if (dev->vq_index <= i && i < dev->vq_index + dev->nvqs) {
+ continue;
+ }
+
+ ret = vhost_vdpa_get_vring_group(dev, &vq_group);
+ if (unlikely(ret)) {
+ goto call_err;
+ }
+ if (unlikely(vq_group.num == this_vq_group.num)) {
+ error_report("VQ %d group is the same as VQ %d one",
+ this_vq_group.index, vq_group.index);
+ return false;
+ }
+ }
+
+ return true;
+
+call_err:
+ error_report("Can't read vq group, errno=%d (%s)", ret, g_strerror(-ret));
+ return false;
+}
+
static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
{
struct vhost_vdpa *v = dev->opaque;
@@ -1106,6 +1179,10 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
if (started) {
vhost_vdpa_host_notifiers_init(dev);
+ if (dev->independent_vq_group &&
+ !vhost_dev_is_independent_group(dev)) {
+ return -1;
+ }
ok = vhost_vdpa_svqs_start(dev);
if (unlikely(!ok)) {
return -1;
diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index 333348d9d5..e6fdc03514 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -43,6 +43,7 @@ vhost_vdpa_set_vring_ready(void *dev) "dev: %p"
vhost_vdpa_dump_config(void *dev, const char *line) "dev: %p %s"
vhost_vdpa_set_config(void *dev, uint32_t offset, uint32_t size, uint32_t flags) "dev: %p offset: %"PRIu32" size: %"PRIu32" flags: 0x%"PRIx32
vhost_vdpa_get_config(void *dev, void *config, uint32_t config_len) "dev: %p config: %p config_len: %"PRIu32
+vhost_vdpa_get_vring_group(void *dev, unsigned int index, unsigned int num) "dev: %p index: %u num: %u"
vhost_vdpa_dev_start(void *dev, bool started) "dev: %p started: %d"
vhost_vdpa_set_log_base(void *dev, uint64_t base, unsigned long long size, int refcnt, int fd, void *log) "dev: %p base: 0x%"PRIx64" size: %llu refcnt: %d fd: %d log: %p"
vhost_vdpa_set_vring_addr(void *dev, unsigned int index, unsigned int flags, uint64_t desc_user_addr, uint64_t used_user_addr, uint64_t avail_user_addr, uint64_t log_guest_addr) "dev: %p index: %u flags: 0x%x desc_user_addr: 0x%"PRIx64" used_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" log_guest_addr: 0x%"PRIx64
--
2.27.0
next prev parent reply other threads:[~2022-04-13 16:54 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-13 16:31 [RFC PATCH v7 00/25] Net Control VQ support with asid in vDPA SVQ Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 01/25] vhost: Track descriptor chain in private at SVQ Eugenio Pérez
2022-04-14 3:48 ` Jason Wang
2022-04-22 14:16 ` Eugenio Perez Martin
2022-04-13 16:31 ` [RFC PATCH v7 02/25] vdpa: Add missing tracing to batch mapping functions Eugenio Pérez
2022-04-14 3:49 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 03/25] vdpa: Fix bad index calculus at vhost_vdpa_get_vring_base Eugenio Pérez
2022-04-14 3:50 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 04/25] util: Return void on iova_tree_remove Eugenio Pérez
2022-04-14 3:50 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 05/25] hw/virtio: Replace g_memdup() by g_memdup2() Eugenio Pérez
2022-04-14 3:51 ` Jason Wang
2022-04-14 4:01 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 06/25] vdpa: Send all updates in memory listener commit Eugenio Pérez
2022-04-14 4:11 ` Jason Wang
2022-04-22 9:17 ` Eugenio Perez Martin
2022-04-13 16:31 ` [RFC PATCH v7 07/25] vhost: Add reference counting to vhost_iova_tree Eugenio Pérez
2022-04-14 5:30 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 08/25] vdpa: Add x-svq to NetdevVhostVDPAOptions Eugenio Pérez
2022-04-14 5:32 ` Jason Wang
2022-04-18 10:36 ` Eugenio Perez Martin
2022-04-13 16:31 ` [RFC PATCH v7 09/25] vhost: move descriptor translation to vhost_svq_vring_write_descs Eugenio Pérez
2022-04-14 5:48 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 10/25] vdpa: Fix index calculus at vhost_vdpa_svqs_start Eugenio Pérez
2022-04-14 5:59 ` Jason Wang
2022-04-13 16:31 ` [RFC PATCH v7 11/25] virtio-net: Expose ctrl virtqueue logic Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 12/25] vdpa: Extract get features part from vhost_vdpa_get_max_queue_pairs Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 13/25] virtio: Make virtqueue_alloc_element non-static Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 14/25] vhost: Add SVQElement Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 15/25] vhost: Add custom used buffer callback Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 16/25] vdpa: control virtqueue support on shadow virtqueue Eugenio Pérez
2022-04-14 9:10 ` Jason Wang
2022-04-18 10:55 ` Eugenio Perez Martin
2022-04-13 16:31 ` [RFC PATCH v7 17/25] vhost: Add vhost_iova_tree_find Eugenio Pérez
2022-04-13 16:31 ` [RFC PATCH v7 18/25] vdpa: Add map/unmap operation callback to SVQ Eugenio Pérez
2022-04-14 9:13 ` Jason Wang
2022-04-13 16:32 ` [RFC PATCH v7 19/25] vhost: Add vhost_svq_inject Eugenio Pérez
2022-04-14 9:09 ` Jason Wang
2022-04-18 13:58 ` Eugenio Perez Martin
2022-04-13 16:32 ` [RFC PATCH v7 20/25] vdpa: add NetClientState->start() callback Eugenio Pérez
2022-04-14 9:14 ` Jason Wang
2022-04-13 16:32 ` [RFC PATCH v7 21/25] vdpa: Add vhost_vdpa_start_control_svq Eugenio Pérez
2022-04-13 16:32 ` [RFC PATCH v7 22/25] vhost: Update kernel headers Eugenio Pérez
2022-04-13 16:32 ` Eugenio Pérez [this message]
2022-04-13 16:32 ` [RFC PATCH v7 24/25] vdpa: Add asid attribute to vdpa device Eugenio Pérez
2022-04-14 9:10 ` Jason Wang
2022-04-18 14:03 ` Eugenio Perez Martin
2022-04-13 16:32 ` [RFC PATCH v7 25/25] vdpa: Add x-cvq-svq Eugenio Pérez
2022-04-14 9:09 ` Jason Wang
2022-04-18 14:16 ` Eugenio Perez Martin
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=20220413163206.1958254-24-eperezma@redhat.com \
--to=eperezma@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=eli@mellanox.com \
--cc=gdawar@xilinx.com \
--cc=hanand@xilinx.com \
--cc=jasowang@redhat.com \
--cc=lingshan.zhu@intel.com \
--cc=liuxiangdong5@huawei.com \
--cc=lulu@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=parav@mellanox.com \
--cc=qemu-devel@nongnu.org \
/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;
as well as URLs for NNTP newsgroup(s).