diff options
Diffstat (limited to 'contrib/libvhost-user/libvhost-user.c')
-rw-r--r-- | contrib/libvhost-user/libvhost-user.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c index 61e1657e41..9efb9dac0e 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -1031,6 +1031,11 @@ vu_queue_get_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int *in_bytes, idx = vq->last_avail_idx; total_bufs = in_total = out_total = 0; + if (unlikely(dev->broken) || + unlikely(!vq->vring.avail)) { + goto done; + } + while ((rc = virtqueue_num_heads(dev, vq, idx)) > 0) { unsigned int max, num_bufs, indirect = 0; struct vring_desc *desc; @@ -1121,11 +1126,16 @@ vu_queue_avail_bytes(VuDev *dev, VuVirtq *vq, unsigned int in_bytes, /* Fetch avail_idx from VQ memory only when we really need to know if * guest has added some buffers. */ -int +bool vu_queue_empty(VuDev *dev, VuVirtq *vq) { + if (unlikely(dev->broken) || + unlikely(!vq->vring.avail)) { + return true; + } + if (vq->shadow_avail_idx != vq->last_avail_idx) { - return 0; + return false; } return vring_avail_idx(vq) == vq->last_avail_idx; @@ -1174,7 +1184,8 @@ vring_notify(VuDev *dev, VuVirtq *vq) void vu_queue_notify(VuDev *dev, VuVirtq *vq) { - if (unlikely(dev->broken)) { + if (unlikely(dev->broken) || + unlikely(!vq->vring.avail)) { return; } @@ -1291,7 +1302,8 @@ vu_queue_pop(VuDev *dev, VuVirtq *vq, size_t sz) struct vring_desc *desc; int rc; - if (unlikely(dev->broken)) { + if (unlikely(dev->broken) || + unlikely(!vq->vring.avail)) { return NULL; } @@ -1445,7 +1457,8 @@ vu_queue_fill(VuDev *dev, VuVirtq *vq, { struct vring_used_elem uelem; - if (unlikely(dev->broken)) { + if (unlikely(dev->broken) || + unlikely(!vq->vring.avail)) { return; } @@ -1474,7 +1487,8 @@ vu_queue_flush(VuDev *dev, VuVirtq *vq, unsigned int count) { uint16_t old, new; - if (unlikely(dev->broken)) { + if (unlikely(dev->broken) || + unlikely(!vq->vring.avail)) { return; } |