Hi Eugenio, > Although I'm ok with the proposed patch as hardening or optimization, > this sounds more like a bug in get_rx_bufs. Where are the memory > addresses for these pieces stored if there are no more buffers in the > virtqueue? Or is it able to loop through the vq?
Yes — get_rx_bufs() loops around the same virtqueue when a non-conforming guest advances avail->idx while earlier descriptors are still in flight. handle_rx() passes quota = UIO_MAXIOV (1024) for mergeable RX, and each vhost_get_vq_desc_n() call appends the translated buffer addresses into vq->iov (also sized to UIO_MAXIOV). Because vhost_get_avail_idx() compares avail_idx against vq->last_avail_idx rather than vq->last_used_idx, it rejects only when (u16)(avail_idx - vq->last_avail_idx) > vq->num so the guest can reuse the 32 ring slots mid-packet and get_rx_bufs() appends those addresses again into vq->iov[32..63], returning headcount = 64. Bounding get_rx_bufs() (e.g. capping its quota against vq->num, or checking in-flight descriptors more broadly) is certainly worth looking at separately, while keeping the mask in vhost_add_used_n_in_order() keeps the dirty-logging cursor consistent with the publishing loop from commit e244725e86be. If you think a follow-up check in get_rx_bufs() makes sense, I'm happy to look into that as a separate patch. > Can you post the reproducer? Even better if it is integrated in > tools/virtio/vhost_net_test.c. I just posted the standalone C reproducer in my reply to Jiaming in this thread. Note that tools/virtio/vhost_net_test.c drives the ring through the conforming vring_new_virtqueue() / virtqueue_add_inbuf() API, whereas reproducing this requires a raw vring advancing avail->idx past last_used_idx + vq->num with VIRTIO_F_IN_ORDER | VIRTIO_NET_F_MRG_RXBUF | VHOST_F_LOG_ALL and VHOST_VRING_F_LOG set in VHOST_SET_VRING_ADDR. If you'd still like a raw-vring test case added under tools/virtio/, I'm happy to include it in a v2 (along with fixing the minor 262 -> 260 byte used-ring size typo in the commit message). Thanks, YanXin
publickey - [email protected] - 0x99485AA3.asc
Description: application/pgp-keys
signature.asc
Description: OpenPGP digital signature
