Skip to content

Commit

Permalink
vhost: fix missing lock protection in power monitor API
Browse files Browse the repository at this point in the history
[ upstream commit b4c4e5675c85a9b471c252305811d15f6a6d2aa6 ]

The power monitor get API is missing both access lock
protection and access status check.

Fixes: 34fd437 ("vhost: add power monitor API")

Signed-off-by: Maxime Coquelin <[email protected]>
Acked-by: David Marchand <[email protected]>
Signed-off-by: Maxime Coquelin <[email protected]>
  • Loading branch information
mcoquelin authored and kevintraynor committed Nov 23, 2023
1 parent 9b63dd4 commit 45cef81
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/vhost/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 45cef81

Please sign in to comment.