aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorLaurent Vivier <lvivier@redhat.com>2025-01-15 17:22:30 +0100
committerStefano Brivio <sbrivio@redhat.com>2025-01-15 23:05:31 +0100
commit1b95bd6fa1148f3609bebf7b2bcd6d47376e61a6 (patch)
tree43e954ce39bafb8f24c4893ecc60d56d1c09ef0c
parentf04b483d1509b852951fe1421ef6f6740c9f9a08 (diff)
downloadpasst-1b95bd6fa1148f3609bebf7b2bcd6d47376e61a6.tar
passt-1b95bd6fa1148f3609bebf7b2bcd6d47376e61a6.tar.gz
passt-1b95bd6fa1148f3609bebf7b2bcd6d47376e61a6.tar.bz2
passt-1b95bd6fa1148f3609bebf7b2bcd6d47376e61a6.tar.lz
passt-1b95bd6fa1148f3609bebf7b2bcd6d47376e61a6.tar.xz
passt-1b95bd6fa1148f3609bebf7b2bcd6d47376e61a6.tar.zst
passt-1b95bd6fa1148f3609bebf7b2bcd6d47376e61a6.zip
vhost_user: fix multibuffer from linux
Under some conditions, linux can provide several buffers in the same element (multiple entries in the iovec array). I didn't identify what changed between the kernel guest that provides one buffer and the one that provides several (doesn't seem to be a kernel change or a configuration change). Fix the following assert: ASSERTION FAILED in virtqueue_map_desc (virtio.c:402): num_sg < max_num_sg What I can see is the buffer can be splitted in two iovecs: - vnet header - packet data This change manages this special case but the real fix will be to allow tap_add_packet() to manage iovec array. Signed-off-by: Laurent Vivier <lvivier@redhat.com> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--vu_common.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/vu_common.c b/vu_common.c
index 6d365be..431fba6 100644
--- a/vu_common.c
+++ b/vu_common.c
@@ -18,6 +18,8 @@
#include "pcap.h"
#include "vu_common.h"
+#define VU_MAX_TX_BUFFER_NB 2
+
/**
* vu_packet_check_range() - Check if a given memory zone is contained in
* a mapped guest memory region
@@ -168,10 +170,15 @@ static void vu_handle_tx(struct vu_dev *vdev, int index,
count = 0;
out_sg_count = 0;
- while (count < VIRTQUEUE_MAX_SIZE) {
+ while (count < VIRTQUEUE_MAX_SIZE &&
+ out_sg_count + VU_MAX_TX_BUFFER_NB <= VIRTQUEUE_MAX_SIZE) {
int ret;
- vu_set_element(&elem[count], &out_sg[out_sg_count], NULL);
+ elem[count].out_num = VU_MAX_TX_BUFFER_NB;
+ elem[count].out_sg = &out_sg[out_sg_count];
+ elem[count].in_num = 0;
+ elem[count].in_sg = NULL;
+
ret = vu_queue_pop(vdev, vq, &elem[count]);
if (ret < 0)
break;
@@ -181,11 +188,20 @@ static void vu_handle_tx(struct vu_dev *vdev, int index,
warn("virtio-net transmit queue contains no out buffers");
break;
}
- ASSERT(elem[count].out_num == 1);
+ if (elem[count].out_num == 1) {
+ tap_add_packet(vdev->context,
+ elem[count].out_sg[0].iov_len - hdrlen,
+ (char *)elem[count].out_sg[0].iov_base +
+ hdrlen);
+ } else {
+ /* vnet header can be in a separate iovec */
+ ASSERT(elem[count].out_num == 2);
+ ASSERT(elem[count].out_sg[0].iov_len == (size_t)hdrlen);
+ tap_add_packet(vdev->context,
+ elem[count].out_sg[1].iov_len,
+ (char *)elem[count].out_sg[1].iov_base);
+ }
- tap_add_packet(vdev->context,
- elem[count].out_sg[0].iov_len - hdrlen,
- (char *)elem[count].out_sg[0].iov_base + hdrlen);
count++;
}
tap_handler(vdev->context, now);