diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 8a20efa7c4..95940d542c 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1949,6 +1949,7 @@ rte_vhost_get_monitor_addr(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; @@ -1959,6 +1960,13 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id, if (vq == NULL) return -1; + rte_spinlock_lock(&vq->access_lock); + + if (unlikely(!vq->access_ok)) { + ret = -1; + goto out_unlock; + } + if (vq_is_packed(dev)) { struct vring_packed_desc *desc; desc = vq->desc_packed; @@ -1978,7 +1986,10 @@ rte_vhost_get_monitor_addr(int vid, uint16_t queue_id, pmc->match = 0; } - return 0; +out_unlock: + rte_spinlock_unlock(&vq->access_lock); + + return ret; } RTE_LOG_REGISTER_SUFFIX(vhost_config_log_level, config, INFO);