From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@outlook.com,
fengli@smartx.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>, stable@dpdk.org
Subject: [PATCH v2 7/7] vhost: fix checking virtqueue access in stats API
Date: Fri, 20 Oct 2023 10:48:04 +0200 [thread overview]
Message-ID: <20231020084804.3625099-8-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20231020084804.3625099-1-maxime.coquelin@redhat.com>
Acquiring the access lock is not enough to ensure
virtqueue's metadata such as vring pointers are valid.
The access status must also be checked.
Fixes: be75dc99ea1f ("vhost: support per-virtqueue statistics")
Cc: stable@dpdk.org
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/vhost/vhost.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index d8d74623d4..b03e3b391d 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -2199,6 +2199,7 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
struct virtio_net *dev = get_device(vid);
struct vhost_virtqueue *vq;
unsigned int i;
+ int ret = VHOST_NB_VQ_STATS;
if (dev == NULL)
return -1;
@@ -2215,6 +2216,12 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
vq = dev->virtqueue[queue_id];
rte_rwlock_write_lock(&vq->access_lock);
+
+ if (unlikely(!vq->access_ok)) {
+ ret = -1;
+ goto out_unlock;
+ }
+
for (i = 0; i < VHOST_NB_VQ_STATS; i++) {
/*
* No need to the read atomic counters as such, due to the
@@ -2224,15 +2231,18 @@ rte_vhost_vring_stats_get(int vid, uint16_t queue_id,
*(uint64_t *)(((char *)vq) + vhost_vq_stat_strings[i].offset);
stats[i].id = i;
}
+
+out_unlock:
rte_rwlock_write_unlock(&vq->access_lock);
- return VHOST_NB_VQ_STATS;
+ return ret;
}
int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id)
{
struct virtio_net *dev = get_device(vid);
struct vhost_virtqueue *vq;
+ int ret = 0;
if (dev == NULL)
return -1;
@@ -2246,14 +2256,21 @@ int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id)
vq = dev->virtqueue[queue_id];
rte_rwlock_write_lock(&vq->access_lock);
+
+ if (unlikely(!vq->access_ok)) {
+ ret = -1;
+ goto out_unlock;
+ }
/*
* No need to the reset atomic counters as such, due to the
* above write access_lock preventing them to be updated.
*/
memset(&vq->stats, 0, sizeof(vq->stats));
+
+out_unlock:
rte_rwlock_write_unlock(&vq->access_lock);
- return 0;
+ return ret;
}
int
--
2.41.0
next prev parent reply other threads:[~2023-10-20 8:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 8:47 [PATCH v2 0/7] vhost: ensure virtqueue access status is checked Maxime Coquelin
2023-10-20 8:47 ` [PATCH v2 1/7] vhost: fix missing vring call check on virtqueue access Maxime Coquelin
2023-10-20 8:47 ` [PATCH v2 2/7] vhost: fix missing " Maxime Coquelin
2023-10-20 8:48 ` [PATCH v2 3/7] vhost: fix checking virtqueue access when notifying guest Maxime Coquelin
2023-10-20 8:48 ` [PATCH v2 4/7] vhost: fix check on virtqueue access in async registration Maxime Coquelin
2023-10-20 8:48 ` [PATCH v2 5/7] vhost: fix check on virtqueue access in in-flight getter Maxime Coquelin
2023-10-20 8:48 ` [PATCH v2 6/7] vhost: fix missing lock protection in power monitor API Maxime Coquelin
2023-10-20 8:48 ` Maxime Coquelin [this message]
2023-10-23 10:01 ` [PATCH v2 0/7] vhost: ensure virtqueue access status is checked David Marchand
2023-10-25 11:40 ` David Marchand
2023-10-25 12:22 ` Maxime Coquelin
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=20231020084804.3625099-8-maxime.coquelin@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=chenbo.xia@outlook.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=fengli@smartx.com \
--cc=stable@dpdk.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).