1. 30 May, 2023 1 commit
  2. 29 May, 2023 2 commits
  3. 27 May, 2023 1 commit
  4. 26 May, 2023 4 commits
  5. 24 May, 2023 8 commits
  6. 23 May, 2023 1 commit
  7. 22 May, 2023 8 commits
  8. 19 May, 2023 1 commit
    • Hawkins Jiawei's avatar
      vhost: fix possible wrap in SVQ descriptor ring · a9144eed
      Hawkins Jiawei authored
      QEMU invokes vhost_svq_add() when adding a guest's element
      into SVQ. In vhost_svq_add(), it uses vhost_svq_available_slots()
      to check whether QEMU can add the element into SVQ. If there is
      enough space, then QEMU combines some out descriptors and some
      in descriptors into one descriptor chain, and adds it into
      `svq->vring.desc` by vhost_svq_vring_write_descs().
      
      Yet the problem is that, `svq->shadow_avail_idx - svq->shadow_used_idx`
      in vhost_svq_available_slots() returns the number of occupied elements,
      or the number of descriptor chains, instead of the number of occupied
      descriptors, which may cause wrapping in SVQ descriptor ring.
      
      Here is an example. In vhost_handle_guest_kick(), QEMU forwards
      as many available buffers to device by virtqueue_pop() and
      vhost_svq_add_element(). virtqueue_pop() returns a guest's element,
      and then this element is added into SVQ by vhost_svq_add_element(),
      a wrapper to vhost_svq_add(). If QEMU invokes virtqueue_pop() and
      vhost_svq_add_element() `svq->vring.num` times,
      vhost_svq_available_slots() thinks QEMU just ran out of slots and
      everything should work fine. But in fact, virtqueue_pop() returns
      `svq->vring.num` elements or descriptor chains, more than
      `svq->vring.num` descriptors due to guest memory fragmentation,
      and this causes wrapping in SVQ descriptor ring.
      
      This bug is valid even before marking the descriptors used.
      If the guest memory is fragmented, SVQ must add chains
      so it can try to add more descriptors than possible.
      
      This patch solves it by adding `num_free` field in
      VhostShadowVirtqueue structure and updating this field
      in vhost_svq_add() and vhost_svq_get_buf(), to record
      the number of free descriptors.
      
      Fixes: 100890f7
      
       ("vhost: Shadow virtqueue buffers forwarding")
      Signed-off-by: default avatarHawkins Jiawei <yin31149@gmail.com>
      Acked-by: default avatarEugenio Pérez <eperezma@redhat.com>
      Message-Id: <20230509084817.3973-1-yin31149@gmail.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Tested-by: default avatarLei Yang <leiyang@redhat.com>
      (cherry picked from commit 5d410557
      
      )
      Signed-off-by: default avatarMichael Tokarev <mjt@tls.msk.ru>
      a9144eed
  9. 18 May, 2023 10 commits
  10. 17 May, 2023 4 commits