Skip to content

Commit

Permalink
virtqueue: fix invalidate wrong cache region
Browse files Browse the repository at this point in the history
The current code fetches the vring index before invalidating the cache.
This can lead to using an invalid index.
Fetch the index before invalidation to ensure a correct index.
Signed-off-by: Joshua Lin <jlin@petaio.com>
  • Loading branch information
joshualin-petaio authored and arnopo committed Feb 24, 2022
1 parent 837f078 commit b139a1f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/virtio/virtqueue.c
Expand Up @@ -271,10 +271,10 @@ void *virtqueue_get_available_buffer(struct virtqueue *vq, uint16_t *avail_idx,

VQUEUE_BUSY(vq);

head_idx = vq->vq_available_idx++ & (vq->vq_nentries - 1);

/* Avail.ring is updated by master, invalidate it */
VRING_INVALIDATE(vq->vq_ring.avail->ring[head_idx]);

head_idx = vq->vq_available_idx++ & (vq->vq_nentries - 1);
*avail_idx = vq->vq_ring.avail->ring[head_idx];

/* Invalidate the desc entry written by master before accessing it */
Expand Down Expand Up @@ -453,10 +453,10 @@ uint32_t virtqueue_get_desc_size(struct virtqueue *vq)

VQUEUE_BUSY(vq);

head_idx = vq->vq_available_idx & (vq->vq_nentries - 1);

/* Avail.ring is updated by master, invalidate it */
VRING_INVALIDATE(vq->vq_ring.avail->ring[head_idx]);

head_idx = vq->vq_available_idx & (vq->vq_nentries - 1);
avail_idx = vq->vq_ring.avail->ring[head_idx];

/* Invalidate the desc entry written by master before accessing it */
Expand Down

0 comments on commit b139a1f

Please sign in to comment.