Skip to contentSkip to conversation

vhost-user-bridge housekeeping and test

PATCH Superseded Yodel Eldar 1 participant 4 messages Jan 20 Arm/Amlogic Meson SoC support

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover vhost-user-bridge housekeeping and test

This series (1) moves vhost-user-bridge (vubr) from tests/ to contrib/vhost-user-bridge/, (2) introduces a basic functional test of vubr, and (3) adds UDP receive packet logging to vubr:

Patch 1: Moving vhost-user-bridge
---------------------------------
After the introduction of vhost-user-bridge and libvhost-user, new vhost-user backend daemons were placed in dedicated subdirectories of contrib/. An F: line under the vhost section in MAINTAINERS grants these daemons coverage; in tests/, however, vhost-user-bridge lacks coverage and appears orphaned there. So, let's give it a home with the rest of the vhost-user backend family.

As part of the move, vhost-user-bridge also gains a section in the vhost-user-contrib document. More can be said about vubr there, like its client mode feature added in aef8486ede8b by Marc-André, but for now a short description and usage example will help folks interested in using the daemon to expand vhost-user support in QEMU.

Lastly, Patch 1 makes the necessary changes to the meson build files in tests/ and root, and the new one in contrib/vhost-user-bridge/.

Patch 2: Introducing a functional test
--------------------------------------
This test was inspired by discussions with Cédric regarding build errors from recent glibc const changes and was the subject of the first RFC.

The functional test introduced in the second patch starts vubr as a subprocess, then launches a single QEMU instance that provides a slirp stack and serves as the frontend of the vhost-user protocol, much like the testing setup described in vhost-user-bridge's initial commit in 3595e2eb0a23.

For additional details about the test, please see Patch 2's commit message and/or the test's header; in short: the host serves a file to the guest via tftp, then the guest serves a file to the host via http.

The guest's kernel image was built with Buildroot in a Containerfile that is based on a snapshot Debian container image, so that the kernel image remains bit-for-bit reproducible indefinitely. For the image and its build files, please see:
https://github.com/yodel/vhost-user-bridge-test
The repo will be placed in archive (read-only) mode if/when the series lands.

Patch 3: Adding UDP RX logging
------------------------------
An existing transmit hexdump of UDP packets provides valuable data; adding a receive hexdump to complement TX doubles the fun (read:
visibility). Like TX, the RX hexdump is gated behind a currently hardcoded-on macro. Another new debug print separates transmit blocks from receives.

Changes since RFCv2:
--------------------
- Promoted to PATCH
- Collect R-b's (thanks to Marc-André and Thomas)
- Add test to .../x86_64/meson.build thorough suite (Marc-André)
- Add encoding= args to open() (Thomas)
- Add pylint disable=unbalanced-tuple-unpacking on find_free_ports()
- Minor commit message rewording

Changes since RFCv1:
--------------------
- Remove external host dependency (Marc-André)
- Use user netdev tftp feature (Thomas)
- Use check_http_download (Thomas)
- Remove wget
- Inherit from LinuxKernelTest instead of QemuSystemTest
- Use hardcoded UUIDs in files on the guest and host for data transfer
- Use a Popen context manager to terminate and wait on vubr
- Add test to MAINTAINERS under the vhost section (Michael)
- New patch to move from tests/ to contrib/vhost-user-bridge/ and add docs section
- New patch to add RX debug logging in vhost-user-bridge.c

Links
-----
RFCv2:
https://lore.kernel.org/qemu-devel/[email protected]/
RFCv1:
https://lore.kernel.org/qemu-devel/[email protected]/

Yodel Eldar (3):
tests/vhost-user-bridge: Move to contrib/vhost-user-bridge/ tests/functional/x86_64: Add vhost-user-bridge test contrib/vhost-user-bridge: Add UDP receive hexdump

 MAINTAINERS                                   |   1 +
 contrib/vhost-user-bridge/meson.build         |   4 +
 .../vhost-user-bridge}/vhost-user-bridge.c    |   7 +
 .../devices/virtio/vhost-user-contrib.rst     |  39 +++++
 meson.build                                   |   1 +
 tests/functional/x86_64/meson.build           |   1 +
 .../x86_64/test_vhost_user_bridge.py          | 147 ++++++++++++++++++
 tests/meson.build                             |   6 -
 8 files changed, 200 insertions(+), 6 deletions(-)
 create mode 100644 contrib/vhost-user-bridge/meson.build
 rename {tests => contrib/vhost-user-bridge}/vhost-user-bridge.c (98%)
 create mode 100755 tests/functional/x86_64/test_vhost_user_bridge.py
Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/3 tests/vhost-user-bridge: Move to contrib/vhost-user-bridge/

After the introduction of vhost-user-bridge and libvhost-user, we formed the convention of placing vhost-user daemons in eponymous subdirs of contrib/. Follow this convention.

Create a contrib/vhost-user-bridge/ directory and move vhost-user-bridge into it. Extract its build target definition from tests/meson.build into the new directory, and include its subdir in the root-level meson.build.

Add a section about it in the "vhost-user daemons in contrib" document.

---
 contrib/vhost-user-bridge/meson.build         |  4 ++
 .../vhost-user-bridge}/vhost-user-bridge.c    |  0
 .../devices/virtio/vhost-user-contrib.rst     | 39 +++++++++++++++++++
 meson.build                                   |  1 +
 tests/meson.build                             |  6 ---
 5 files changed, 44 insertions(+), 6 deletions(-)
 create mode 100644 contrib/vhost-user-bridge/meson.build
 rename {tests => contrib/vhost-user-bridge}/vhost-user-bridge.c (100%)
contrib/vhost-user-bridge/meson.build new file +4 -0
new file mode 100644
index 0000000000..aa58c1df20
@@ -0,0 +1,4 @@
+if have_tools and have_vhost_user and host_os == 'linux'
+  executable('vhost-user-bridge', files('vhost-user-bridge.c'),
+             dependencies: [qemuutil, vhost_user], install: false)
+endif
contrib/vhost-user-bridge/vhost-user-bridge.c renamed from tests/vhost-user-bridge.c +0 -0
similarity index 100%
rename from tests/vhost-user-bridge.c
rename to contrib/vhost-user-bridge/vhost-user-bridge.c
docs/system/devices/virtio/vhost-user-contrib.rst +39 -0
index 48d04d2ade..660d29a700 100644
@@ -85,3 +85,42 @@ vhost-user-scsi - SCSI controller
 
 The vhost-user-scsi daemon can proxy iSCSI devices onto a virtualized
 SCSI controller.
+
+.. _vhost_user_bridge:
+
+vhost-user-bridge - Network bridge
+==================================
+
+The vhost-user-bridge daemon serves as a development tool for testing real
+internet traffic by providing a networking backend, i.e. server, for the
+vhost-user protocol.
+
+Example
+-------
+For a single QEMU instance that both runs the user-mode net stack (slirp) and
+serves as a vhost-user protocol frontend, i.e. client, simultaneously:
+
+First, start vhost-user-bridge:
+
+::
+
+  $ vhost-user-bridge -u /tmp/vubr.sock \
+                      -l 127.0.0.1:4444 \
+                      -r 127.0.0.1:5555
+
+Then, invoke QEMU:
+
+::
+
+  $ qemu-system-x86_64 \
+        -m 4G \
+        -object memory-backend-memfd,id=mem0,size=4G,share=on,prealloc=on \
+        -numa node,memdev=mem0 \
+        -chardev socket,id=char0,path=/tmp/vubr.sock \
+        -netdev vhost-user,id=vhost0,chardev=char0,vhostforce=on \
+        -device virtio-net-pci,netdev=vhost0 \
+        -netdev socket,id=udp0,udp=localhost:4444,localaddr=localhost:5555 \
+        -netdev user,id=user0 \
+        -netdev hubport,id=hub0,hubid=0,netdev=udp0 \
+        -netdev hubport,id=hub1,hubid=0,netdev=user0 \
+        ...
meson.build +1 -0
index 3108f01e88..adfb0a9a89 100644
@@ -4491,6 +4491,7 @@ if have_tools
 
   if have_vhost_user
     subdir('contrib/vhost-user-blk')
+    subdir('contrib/vhost-user-bridge')
     subdir('contrib/vhost-user-gpu')
     subdir('contrib/vhost-user-input')
     subdir('contrib/vhost-user-scsi')
tests/meson.build +0 -6
index cbe7916241..87861b2857 100644
@@ -70,12 +70,6 @@ test_deps = {
   'test-qht-par': qht_bench,
 }
 
-if have_tools and have_vhost_user and host_os == 'linux'
-  executable('vhost-user-bridge',
-             sources: files('vhost-user-bridge.c'),
-             dependencies: [qemuutil, vhost_user])
-endif
-
 subdir('decode')
 
 if 'CONFIG_TCG' in config_all_accel
Signature · 1 line
2.52.0
#2 lore raw

PATCH v3 2/3 tests/functional/x86_64: Add vhost-user-bridge test

In reply to Yodel Eldar

Introduce a functional test of vhost-user-bridge and enter it into MAINTAINERS under the vhost section.

The test runs vhost-user-bridge as a subprocess, then launches a guest with four backends: a unix domain socket for vhost-user, a UDP socket, a user-mode net, and a hubport to hub the UDP and user backends; only the vhost-user backend is exposed, the rest are deviceless. This configuration mimics the testing setup described in the initial commit of vhost-user-bridge in 3595e2eb0a23.

The test creates a scratch file containing a hardcoded UUID on the host and exposes it to the the guest via the tftp parameter of the user netdev. After the guest invokes tftp to request the file, the test verifies the transfer by hashsum.

Similarly, the test creates a file with another hardcoded UUID in the guest. A call to check_http_download() serves the file to the host via http, whereupon a check of the file hashsum occurs on the host.

Lastly, add the test to the thorough tests suite in meson.build.

---
 MAINTAINERS                                   |   1 +
 tests/functional/x86_64/meson.build           |   1 +
 .../x86_64/test_vhost_user_bridge.py          | 147 ++++++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100755 tests/functional/x86_64/test_vhost_user_bridge.py
MAINTAINERS +1 -0
index c1e586c58f..343493ae21 100644
@@ -2388,6 +2388,7 @@ F: subprojects/libvhost-user/
 F: block/export/vhost-user*
 F: util/vhost-user-server.c
 F: net/vhost*
+F: tests/functional/x86_64/test_vhost_user_bridge.py
 
 vhost-shadow-virtqueue
 R: Eugenio Pérez <[email protected]>
tests/functional/x86_64/meson.build +1 -0
index f78eec5e6c..beab4f304b 100644
@@ -34,6 +34,7 @@ tests_x86_64_system_thorough = [
   'reverse_debug',
   'tuxrun',
   'vfio_user_client',
+  'vhost_user_bridge',
   'virtio_balloon',
   'virtio_gpu',
 ]
tests/functional/x86_64/test_vhost_user_bridge.py new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.52.0
#3 lore raw

PATCH v3 3/3 contrib/vhost-user-bridge: Add UDP receive hexdump

In reply to Yodel Eldar

vhost-user-bridge debug prints UDP TX hexdumps in its transmit handler, but does not for receives, even though they are beneficial for testing. Add an RX hexdump in the receive callback.

To delineate between transmits and receives, also add a debug print indicating that the program is in the transmit handler.

---
 contrib/vhost-user-bridge/vhost-user-bridge.c | 7 +++++++
 1 file changed, 7 insertions(+)
contrib/vhost-user-bridge/vhost-user-bridge.c +7 -0
index ce4c3426d3..3f0fd0fa49 100644
@@ -179,6 +179,9 @@ vubr_handle_tx(VuDev *dev, int qidx)
 
     assert(qidx % 2);
 
+    DPRINT("\n\n   ***   IN UDP TRANSMIT HANDLER    ***\n\n");
+    DPRINT("    hdrlen = %d\n", hdrlen);
+
     for (;;) {
         ssize_t ret;
         unsigned int out_num;
@@ -333,6 +336,10 @@ vubr_backend_recv_cb(int sock, void *ctx)
         };
         ret = RETRY_ON_EINTR(recvmsg(vubr->backend_udp_sock, &msg, 0));
 
+        if (ret > 0 && VHOST_USER_BRIDGE_DEBUG) {
+            iov_hexdump(sg, num, stderr, "RX:", ret);
+        }
+
         if (i == 0) {
             iov_restore_front(elem->in_sg, sg, hdrlen);
         }
Signature · 1 line
2.52.0