Skip to content

Commit

Permalink
virtqueue: fix invalidate wrong cache region
Browse files Browse the repository at this point in the history
It always invalidates the avail ring index 0.
It must get the right vring index before incalidating it.
Signed-off-by: Joshua Lin <[email protected]>
  • Loading branch information
joshualin-petaio committed Feb 2, 2022
1 parent 792d269 commit 02f8ec8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/virtio/virtqueue.c
Original file line number Diff line number Diff line change
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 02f8ec8

Please sign in to comment.