Skip to content

Commit

Permalink
virtio: Use virtqueue_get_buffer() helpers
Browse files Browse the repository at this point in the history
Length was being read without first invalidating. There are functions that
handle invalidating and reading from vq_ring members. Use those here.

Signed-off-by: Andrew Davis <[email protected]>
  • Loading branch information
glneo committed Mar 15, 2024
1 parent 79b795e commit eeae9c5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/virtio/virtqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,15 @@ void *virtqueue_get_buffer(struct virtqueue *vq, uint32_t *len, uint16_t *idx)

uint32_t virtqueue_get_buffer_length(struct virtqueue *vq, uint16_t idx)
{
/* Invalidate the desc entry written by driver before accessing it */
VRING_INVALIDATE(&vq->vq_ring.desc[idx].len,
sizeof(vq->vq_ring.desc[idx].len));
return vq->vq_ring.desc[idx].len;
}

void *virtqueue_get_buffer_addr(struct virtqueue *vq, uint16_t idx)
{
/* Invalidate the desc entry written by driver before accessing it */
VRING_INVALIDATE(&vq->vq_ring.desc[idx].addr,
sizeof(vq->vq_ring.desc[idx].addr));
return virtqueue_phys_to_virt(vq, vq->vq_ring.desc[idx].addr);
Expand Down Expand Up @@ -225,11 +227,8 @@ void *virtqueue_get_available_buffer(struct virtqueue *vq, uint16_t *avail_idx,
sizeof(vq->vq_ring.avail->ring[head_idx]));
*avail_idx = vq->vq_ring.avail->ring[head_idx];

/* Invalidate the desc entry written by driver before accessing it */
VRING_INVALIDATE(&vq->vq_ring.desc[*avail_idx],
sizeof(vq->vq_ring.desc[*avail_idx]));
buffer = virtqueue_phys_to_virt(vq, vq->vq_ring.desc[*avail_idx].addr);
*len = vq->vq_ring.desc[*avail_idx].len;
buffer = virtqueue_get_buffer_addr(vq, *avail_idx);
*len = virtqueue_get_buffer_length(vq, *avail_idx);

VQUEUE_IDLE(vq);

Expand Down

0 comments on commit eeae9c5

Please sign in to comment.