Skip to contentSkip to conversation

virtio-net: live-TAP local migration

PATCH Superseded Vladimir Sementsov-Ogievskiy 7 participants 46 messages Jul 14 – Jul 21

Subsystems (4)

v19 of 21 Superseded Latest is v21 →

lore
Share & tools
lore
#0 lore raw

v19 cover virtio-net: live-TAP local migration

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

v19:

02: add r-b by Markus
03: pass parameter name to improve error message; info str: "no" -> "" 09: better documentation wording, keep a-b marks
10: new
13: - better wording
- keep new property false by default
- better error message
- move to errp-variants of pre/post _load functions

v19 is pushed to

https://gitlab.com/vsementsov/qemu.git
tag: up-tap-fd-migration-with-bk-opt-v19

To run the test, use sudo, as test needs to configure TAP device:

    sudo PYTHONPATH=python:tests/functional \
    QEMU_TEST_QEMU_BINARY=$PWD/build/qemu-system-x86_64 \
    MESON_BUILD_ROOT=$PWD/build \
    ./build/pyvenv/bin/python3 tests/functional/x86_64/test_tap_migration.py

Or, to test the feature by hand, you may follow the instruction.

The walkthrough uses four terminals:

  source-cmd  -- source VM console (serial output, guest login)
  source-qmp  -- QMP connection to the source QEMU
  target-cmd  -- target VM console (serial output, guest login after migration)
  target-qmp  -- QMP connection to the target QEMU

1. Prerequisites
----------------

    QEMU=/path/to/your/build/qemu-system-x86_64
# download same image as in test
    wget -O /tmp/alpine.iso "https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/x86_64/alpine-standard-3.22.1-x86_64.iso"
# prepare tap device (be careful to not break your own networks)

sudo ip tuntap add dev tap0 mode tap multi_queue sudo ip addr add 192.168.100.1/24 dev tap0 sudo ip link set tap0 up

2. Start source VM
------------------

In source-cmd, run:

    $QEMU \
        -name source \
        -machine q35 \
        -accel kvm \
        -m 1G \
        -object memory-backend-file,id=ram0,size=1G,mem-path=/dev/shm/qemu_migration_test,share=on \
        -machine memory-backend=ram0 \
        -drive file=/tmp/alpine.iso,media=cdrom,format=raw \
        -device pcie-pci-bridge,id=pci.1,bus=pcie.0 \
        -serial stdio \
        -nographic \
        -S \
        -qmp unix:/tmp/qmp-source.sock,server=on,wait=off

Note: the netdev and virtio-net device are added via QMP below for symmetry with the target. On the source you could also pass them on the command line (with local-migration-supported=on).

In source-qmp, connect and add the TAP netdev and virtio-net device:

    socat - UNIX-CONNECT:/tmp/qmp-source.sock

    {"execute": "qmp_capabilities"}

    {"execute": "netdev_add", "arguments": {
        "id": "netdev.1",
        "type": "tap",
        "ifname": "tap0",
        "queues": 4,
        "vnet_hdr": true,
        "script": "no",
        "downscript": "no",
        "local-migration-supported": true
    }}

    {"execute": "device_add", "arguments": {
        "driver": "virtio-net-pci",
        "id": "vnet.1",
        "netdev": "netdev.1",
        "bus": "pci.1",
        "mq": true,
        "vectors": 18,
        "romfile": "",
        "disable-legacy": "off"
    }}

    {"execute": "cont"}

Wait for Alpine to boot in source-cmd. When you see the login prompt, log in as root (no password):

localhost login: root

Configure the guest network:

ip addr add 192.168.100.2/24 dev eth0
ip link set eth0 up

Verify connectivity from the guest:

    ping -c 3 192.168.100.1

And from the host (in any spare terminal):

    ping -c 3 192.168.100.2

3. Start target VM
------------------

The TAP netdev must be created via QMP after enabling the "local" migration parameter — the target will not open tap0 itself; instead it will receive the TAP file descriptors from the source over the migration channel.

In target-cmd, run:

    $QEMU \
        -name target \
        -machine q35 \
        -accel kvm \
        -m 1G \
        -object memory-backend-file,id=ram0,size=1G,mem-path=/dev/shm/qemu_migration_test,share=on \
        -machine memory-backend=ram0 \
        -drive file=/tmp/alpine.iso,media=cdrom,format=raw \
        -device pcie-pci-bridge,id=pci.1,bus=pcie.0 \
        -serial stdio \
        -nographic \
        -qmp unix:/tmp/qmp-target.sock,server=on,wait=off \
        -incoming defer

In target-qmp, connect, enable local migration, and add the TAP netdev and virtio-net device. The "local" parameter must be set before creating the TAP. Do not pass ifname/fd — the fd will arrive via the migration channel:

    socat - UNIX-CONNECT:/tmp/qmp-target.sock

    {"execute": "qmp_capabilities"}

    {"execute": "migrate-set-capabilities", "arguments": {
        "capabilities": [
            {"capability": "events",          "state": true},
            {"capability": "x-ignore-shared", "state": true}
        ]
    }}

    {"execute": "migrate-set-parameters", "arguments": {"local": true}}

    {"execute": "netdev_add", "arguments": {
        "id": "netdev.1",
        "type": "tap",
        "queues": 4,
        "script": "",
        "downscript": "",
        "local-migration-supported": true
    }}

    {"execute": "device_add", "arguments": {
        "driver": "virtio-net-pci",
        "id": "vnet.1",
        "netdev": "netdev.1",
        "bus": "pci.1",
        "mq": true,
        "vectors": 18,
        "romfile": "",
        "disable-legacy": "off"
    }}

4. Start migration
------------------

In target-qmp, tell the target to listen for the incoming migration:

    {"execute": "migrate-incoming",
     "arguments": {"uri": "unix:/tmp/migration.sock"}}

In source-qmp, configure migration capabilities and parameters:

    {"execute": "migrate-set-capabilities", "arguments": {
        "capabilities": [
            {"capability": "events",          "state": true},
            {"capability": "x-ignore-shared", "state": true}
        ]
    }}

    {"execute": "migrate-set-parameters", "arguments": {"local": true}}

In source-qmp, trigger the migration:

    {"execute": "migrate",
     "arguments": {"uri": "unix:/tmp/migration.sock"}}

Poll migration status until it completes (source-qmp):

    {"execute": "query-migrate"}
    # repeat until "status" == "completed"

Or just wait for the MIGRATION event that QEMU emits automatically:

    # {"event": "MIGRATION", "data": {"status": "completed"}, ...}

Once the source reports "completed", resume the target VM (target-qmp):

    {"execute": "cont"}

The target VM is now running with the migrated state and the TAP file descriptors that were passed from the source. Still, target console (in target-cmd) may still be empty, until you at least press Enter in it.

Verify that the guest is still reachable from the host:

    ping -c 3 192.168.100.2

And from inside the guest in target-cmd:

    ping -c 3 192.168.100.1

5. Cleanup
----------

Shut down the target VM (target-qmp):

    {"execute": "quit"}

Shut down the source VM (source-qmp):

    {"execute": "quit"}

Remove the TAP device:

sudo ip tuntap del tap0 mode tap multi_queue

Remove the shared memory file:

rm /dev/shm/qemu_migration_test

Remove leftover sockets if they still exist:

rm -f /tmp/migration.sock /tmp/qmp-source.sock /tmp/qmp-target.sock

Vladimir Sementsov-Ogievskiy (15):
net/tap: rework tap_parse_script
net/tap: improve script/downscript options documentation net/tap: deprecate "no" as special value for script/downscript net/tap: move vhost-net open() calls to tap_parse_vhost_fds() net/tap: move vhost initialization to tap_setup_vhost() net/tap: use container_of instead of DO_UPCAST
net/tap: QOMify tap backend
net/tap: add TYPE_VMSTATE_IF interface
qapi: add local migration parameter
migration/channel: check that transfer is UNIX socket when "local" set
virtio-net: support local migration of backend
net/tap: disable read polling for stopped VM
net/tap: support local migration with virtio-net tests/functional: add skipWithoutSudo() decorator tests/functional: add test_tap_migration

 docs/about/deprecated.rst                     |  18 +
 docs/system/i386/microvm.rst                  |   4 +-
 docs/system/i386/xenpvh.rst                   |   2 +-
 docs/system/ppc/ppce500.rst                   |   4 +-
 docs/system/riscv/microchip-icicle-kit.rst    |   2 +-
 docs/system/riscv/sifive_u.rst                |   2 +-
 hw/net/virtio-net.c                           |  89 +++-
 include/hw/virtio/virtio-net.h                |   1 +
 include/migration/misc.h                      |   2 +
 include/migration/vmstate.h                   |   2 +
 include/net/net.h                             |   9 +
 include/net/tap.h                             |   2 +
 migration/channel.c                           |  17 +
 migration/options.c                           |  18 +-
 net/net.c                                     |  14 +-
 net/tap.c                                     | 441 +++++++++++++----
 qapi/migration.json                           |  15 +-
 qapi/net.json                                 |  38 +-
 qemu-options.hx                               |  12 +-
 tests/functional/qemu_test/decorators.py      |  16 +
 tests/functional/x86_64/meson.build           |   1 +
 tests/functional/x86_64/test_tap_migration.py | 455 ++++++++++++++++++
 22 files changed, 1057 insertions(+), 107 deletions(-)
 create mode 100755 tests/functional/x86_64/test_tap_migration.py
Signature · 1 line
2.43.0
#1 lore raw

PATCH v19 1/15 net/tap: rework tap_parse_script

Factor out tap_is_explicit_no_script() helper, to simplify further changes.

---
 net/tap.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
net/tap.c +21 -6
index 57ffb09885c..fedd48c48d2 100644
@@ -92,19 +92,34 @@ static void launch_script(const char *setup_script, const char *ifname,
 static void tap_send(void *opaque);
 static void tap_writable(void *opaque);
 
-static char *tap_parse_script(const char *script_arg, const char *default_path)
+static bool tap_is_explicit_no_script(const char *script_arg)
 {
-    g_autofree char *res = g_strdup(script_arg);
+    if (!script_arg) {
+        return false;
+    }
 
-    if (!res) {
-        res = get_relocated_path(default_path);
+    if (script_arg[0] == '\0') {
+        return true;
+    }
+
+    if (strcmp(script_arg, "no") == 0) {
+        return true;
     }
 
-    if (res[0] == '\0' || strcmp(res, "no") == 0) {
+    return false;
+}
+
+static char *tap_parse_script(const char *script_arg, const char *default_path)
+{
+    if (tap_is_explicit_no_script(script_arg)) {
         return NULL;
     }
 
-    return g_steal_pointer(&res);
+    if (!script_arg) {
+        return get_relocated_path(default_path);
+    }
+
+    return g_strdup(script_arg);
 }
 
 static void tap_update_fd_handler(TAPState *s)
Signature · 1 line
2.43.0
Reviewed-by on v19 1/15
#2 lore raw

Re: [PATCH v19 01/15] net/tap: rework tap_parse_script

Quoted 43 lines · Vladimir Sementsov-Ogievskiy

Factor out tap_is_explicit_no_script() helper, to simplify further changes.

---
 net/tap.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
net/tap.c +16 -5
index 57ffb09885c..fedd48c48d2 100644
@@ -92,19 +92,34 @@ static void launch_script(const char *setup_script, const char *ifname,
 static void tap_send(void *opaque);
 static void tap_writable(void *opaque);
 
-static char *tap_parse_script(const char *script_arg, const char *default_path)
+static bool tap_is_explicit_no_script(const char *script_arg)
 {
-    g_autofree char *res = g_strdup(script_arg);
+    if (!script_arg) {
+        return false;
+    }
 
-    if (!res) {
-        res = get_relocated_path(default_path);
+    if (script_arg[0] == '\0') {
+        return true;
+    }
+
+    if (strcmp(script_arg, "no") == 0) {
+        return true;
     }
 
-    if (res[0] == '\0' || strcmp(res, "no") == 0) {
+    return false;
+}
+
+static char *tap_parse_script(const char *script_arg, const char *default_path)
+{
+    if (tap_is_explicit_no_script(script_arg)) {
         return NULL;
     }

net/tap.c static void launch_script(const char *setup_script, const char *ifname, · line 125

Quoted 10 lines
net/tap.c +5 -1
 
-    return g_steal_pointer(&res);
+    if (!script_arg) {
+        return get_relocated_path(default_path);
+    }
+
+    return g_strdup(script_arg);
 }
 
 static void tap_update_fd_handler(TAPState *s)

Before the patch, we default @script_arg to get_relocated_path(default) first, then check for "" or "no". After the patch, we do it the other way round. Works, because get_relocated_path() never returns "" or "no". Worth mentioning in the commit message?

The new order feels slightly clearer to me.

#3 lore raw

Re: [PATCH v19 01/15] net/tap: rework tap_parse_script

Quoted 54 lines · Markus Armbruster
Quoted 52 lines · Vladimir Sementsov-Ogievskiy

Factor out tap_is_explicit_no_script() helper, to simplify further changes.

---
  net/tap.c | 27 +++++++++++++++++++++------
  1 file changed, 21 insertions(+), 6 deletions(-)
net/tap.c +21 -6
index 57ffb09885c..fedd48c48d2 100644
@@ -92,19 +92,34 @@ static void launch_script(const char *setup_script, const char *ifname,
  static void tap_send(void *opaque);
  static void tap_writable(void *opaque);
 
-static char *tap_parse_script(const char *script_arg, const char *default_path)
+static bool tap_is_explicit_no_script(const char *script_arg)
  {
-    g_autofree char *res = g_strdup(script_arg);
+    if (!script_arg) {
+        return false;
+    }
 
-    if (!res) {
-        res = get_relocated_path(default_path);
+    if (script_arg[0] == '\0') {
+        return true;
+    }
+
+    if (strcmp(script_arg, "no") == 0) {
+        return true;
      }
 
-    if (res[0] == '\0' || strcmp(res, "no") == 0) {
+    return false;
+}
+
+static char *tap_parse_script(const char *script_arg, const char *default_path)
+{
+    if (tap_is_explicit_no_script(script_arg)) {
          return NULL;
      }
 
-    return g_steal_pointer(&res);
+    if (!script_arg) {
+        return get_relocated_path(default_path);
+    }
+
+    return g_strdup(script_arg);
  }
 
Quoted 6 lines

net/tap.c static void launch_script(const char *setup_script, const char *ifname, · line 125

Quoted 1 line
net/tap.c +0 -0
  static void tap_update_fd_handler(TAPState *s)

Before the patch, we default @script_arg to get_relocated_path(default) first, then check for "" or "no". After the patch, we do it the other way round. Works, because get_relocated_path() never returns "" or "no". Worth mentioning in the commit message?

Will mention it

Quoted 5 lines

The new order feels slightly clearer to me.

Thanks!

Signature · 2 lines
Best regards,
Vladimir
#4 lore raw

PATCH v19 2/15 net/tap: improve script/downscript options documentation

In reply to Vladimir Sementsov-Ogievskiy

Properly document defaults and special values of "" and "no".

---
 qapi/net.json   | 12 +++++++++---
 qemu-options.hx |  9 +++++----
 2 files changed, 14 insertions(+), 7 deletions(-)
qapi/net.json +9 -3
index 1a6382825c5..8f0915c4d86 100644
@@ -399,9 +399,15 @@
 # @fds: multiple file descriptors of already opened multiqueue capable
 #     tap
 #
-# @script: script to initialize the interface
-#
-# @downscript: script to shut down the interface
+# @script: script to initialize the interface.  An empty string or
+#     "no" disables script execution.  Defaults to
+#     ``<sysconfdir>/qemu-ifup``, where ``<sysconfdir>`` is the
+#     system configuration directory at build time (typically /etc).
+#
+# @downscript: script to shut down the interface.  An empty string or
+#     "no" disables script execution.  Defaults to
+#     ``<sysconfdir>/qemu-ifdown``, where ``<sysconfdir>`` is the
+#     system configuration directory at build time (typically /etc).
 #
 # @br: bridge name (since 2.8)
 #
qemu-options.hx +5 -4
index 34970fffc94..200949655ea 100644
@@ -3014,7 +3014,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
     "                use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n"
     "                to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
     "                to deconfigure it\n"
-    "                use '[down]script=no' to disable script execution\n"
+    "                use '[down]script=no' or '[down]script=' to disable script execution\n"
     "                use network helper 'helper' (default=" DEFAULT_BRIDGE_HELPER ") to\n"
     "                configure it\n"
     "                use 'fd=h' to connect to an already opened TAP interface\n"
@@ -3550,9 +3550,10 @@ SRST
     Use the network script file to configure it and the network script
     dfile to deconfigure it. If name is not provided, the OS
     automatically provides one. The default network configure script is
-    ``/etc/qemu-ifup`` and the default network deconfigure script is
-    ``/etc/qemu-ifdown``. Use ``script=no`` or ``downscript=no`` to
-    disable script execution.
+    ``<sysconfdir>/qemu-ifup`` and the default network deconfigure script is
+    ``<sysconfdir>/qemu-ifdown``, where ``<sysconfdir>`` is the system
+    configuration directory at build time (typically ``/etc``).
+    Use ``[down]script=no`` or ``[down]script=`` to disable script execution.
 
     If running QEMU as an unprivileged user, use the network helper
     to configure the TAP interface and attach it to the bridge.
Signature · 1 line
2.43.0
#5 lore raw

PATCH v19 3/15 net/tap: deprecate "no" as special value for script/downscript

In reply to Vladimir Sementsov-Ogievskiy

The interface is ambiguous, as "no" is valid file name. So, using "no" as a special value to disable script is deprecated. Use an empty string ("script=" / "downscript=") instead.

In a future version, "no" will be treated as a plain file name, just like any other non-empty value.

Document the deprecation in docs/about/deprecated.rst, qapi/net.json, and qemu-options.hx. Update other docs to use empty string instead of "no". Add a warning.

---
 docs/about/deprecated.rst                  | 18 ++++++++++++++
 docs/system/i386/microvm.rst               |  4 +--
 docs/system/i386/xenpvh.rst                |  2 +-
 docs/system/ppc/ppce500.rst                |  4 +--
 docs/system/riscv/microchip-icicle-kit.rst |  2 +-
 docs/system/riscv/sifive_u.rst             |  2 +-
 net/tap.c                                  | 29 ++++++++++++++--------
 qapi/net.json                              | 12 ++++++---
 qemu-options.hx                            |  7 ++++--
 9 files changed, 56 insertions(+), 24 deletions(-)
docs/about/deprecated.rst +18 -0
index 0c656a968fc..c4929317e3a 100644
@@ -71,6 +71,15 @@ flexible enough. The monitor objects have been converted to QOM, so
 ``-mon mode=control`` is replaced by ``-object monitor-qmp``. The
 short convenience options are not deprecated, only ``-mon``.
 
+``script=no`` and ``downscript=no`` for ``-netdev tap`` (since 11.2)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The special value ``"no"`` for the ``script`` and ``downscript``
+parameters of ``-netdev tap`` disables script execution.  This special
+treatment of ``"no"`` is deprecated.  Use an empty string (``script=``
+or ``downscript=``) to disable script execution instead.  In a future
+version, ``"no"`` will be treated as a plain file name.
+
 QEMU Machine Protocol (QMP) commands
 ------------------------------------
 
@@ -164,6 +173,15 @@ Use ``job-finalize`` instead.
 
 Use ``query-accelerators`` instead.
 
+``"no"`` as value of ``script``/``downscript`` for tap in ``netdev_add`` (since 11.2)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The special value ``"no"`` for the ``script`` and ``downscript``
+parameters of ``netdev_add`` with ``type=tap`` disables script
+execution.  This special treatment of ``"no"`` is deprecated.  Use an
+empty string instead.  In a future version, ``"no"`` will be treated as
+a plain file name.
+
 Human Machine Protocol (HMP) commands
 -------------------------------------
 
docs/system/i386/microvm.rst +2 -2
index 1675e37d3e7..077ea15751e 100644
@@ -79,7 +79,7 @@ legacy ``ISA serial`` device as console::
      -serial stdio \
      -drive id=test,file=test.img,format=raw,if=none \
      -device virtio-blk-device,drive=test \
-     -netdev tap,id=tap0,script=no,downscript=no \
+     -netdev tap,id=tap0,script=,downscript= \
      -device virtio-net-device,netdev=tap0
 
 While the example above works, you might be interested in reducing the
@@ -103,7 +103,7 @@ disabled::
      -device virtconsole,chardev=virtiocon0 \
      -drive id=test,file=test.img,format=raw,if=none \
      -device virtio-blk-device,drive=test \
-     -netdev tap,id=tap0,script=no,downscript=no \
+     -netdev tap,id=tap0,script=,downscript= \
      -device virtio-net-device,netdev=tap0
 
 
docs/system/i386/xenpvh.rst +1 -1
index 904778e3f5c..862f38830b1 100644
@@ -42,7 +42,7 @@ case you need to construct one manually:
       -vnc none                                       \
       -display none                                   \
       -device virtio-net-pci,id=nic0,netdev=net0,mac=00:16:3e:5c:81:78 \
-      -netdev type=tap,id=net0,ifname=vif3.0-emu,br=xenbr0,script=no,downscript=no \
+      -netdev type=tap,id=net0,ifname=vif3.0-emu,br=xenbr0,script=,downscript= \
       -smp 4,maxcpus=4                                \
       -nographic                                      \
       -machine xenpvh,ram-low-base=0,ram-low-size=2147483648,ram-high-base=4294967296,ram-high-size=2147483648,pci-ecam-base=824633720832,pci-ecam-size=268435456,pci-mmio-base=4026531840,pci-mmio-size=33554432,pci-mmio-high-base=824902156288,pci-mmio-high-size=68719476736 \
docs/system/ppc/ppce500.rst +2 -2
index c9fe0915dc5..ec5aaf14fd9 100644
@@ -158,14 +158,14 @@ interface at PCI address 0.1.0, but we can switch that to an e1000 NIC by:
   $ qemu-system-ppc64 -M ppce500 -smp 4 -m 2G \
                       -display none -serial stdio \
                       -bios u-boot \
-                      -nic tap,ifname=tap0,script=no,downscript=no,model=e1000
+                      -nic tap,ifname=tap0,script=,downscript=,model=e1000
 
 The QEMU ``ppce500`` machine can also dynamically instantiate an eTSEC device
 if “-device eTSEC” is given to QEMU:
 
 .. code-block:: bash
 
-  -netdev tap,ifname=tap0,script=no,downscript=no,id=net0 -device eTSEC,netdev=net0
+  -netdev tap,ifname=tap0,script=,downscript=,id=net0 -device eTSEC,netdev=net0
 
 Root file system on flash drive
 -------------------------------
docs/system/riscv/microchip-icicle-kit.rst +1 -1
index 9809e94b84b..7fdb96601ad 100644
@@ -84,7 +84,7 @@ Then we can boot the machine by:
   $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 -m 2G \
       -sd path/to/sdcard.img \
       -nic user,model=cadence_gem \
-      -nic tap,ifname=tap,model=cadence_gem,script=no \
+      -nic tap,ifname=tap,model=cadence_gem,script= \
       -display none -serial stdio \
       -kernel path/to/u-boot/build/dir/u-boot.bin \
       -dtb path/to/u-boot/build/dir/u-boot.dtb
docs/system/riscv/sifive_u.rst +1 -1
index 8f55ae8e313..0e4dcf3e70c 100644
@@ -199,7 +199,7 @@ To boot the VxWorks kernel in QEMU with the ``sifive_u`` machine, use:
 
   $ qemu-system-riscv64 -M sifive_u -smp 5 -m 2G \
       -display none -serial stdio \
-      -nic tap,ifname=tap0,script=no,downscript=no \
+      -nic tap,ifname=tap0,script=,downscript= \
       -kernel /path/to/vxWorks \
       -append "gem(0,0)host:vxWorks h=192.168.200.1 e=192.168.200.2:ffffff00 u=target pw=vxTarget f=0x01"
 
net/tap.c +18 -11
index fedd48c48d2..2e94b4015f6 100644
@@ -92,34 +92,40 @@ static void launch_script(const char *setup_script, const char *ifname,
 static void tap_send(void *opaque);
 static void tap_writable(void *opaque);
 
-static bool tap_is_explicit_no_script(const char *script_arg)
+static bool tap_is_explicit_no_script(const char *script_arg_name,
+                                      const char *script_arg_value)
 {
-    if (!script_arg) {
+    if (!script_arg_value) {
         return false;
     }
 
-    if (script_arg[0] == '\0') {
+    if (script_arg_value[0] == '\0') {
         return true;
     }
 
-    if (strcmp(script_arg, "no") == 0) {
+    if (strcmp(script_arg_value, "no") == 0) {
+        warn_report("%s=no is deprecated; use %s= instead "
+                    "(empty string instead of 'no')",
+                    script_arg_name, script_arg_name);
         return true;
     }
 
     return false;
 }
 
-static char *tap_parse_script(const char *script_arg, const char *default_path)
+static char *tap_parse_script(const char *script_arg_name,
+                              const char *script_arg_value,
+                              const char *default_path)
 {
-    if (tap_is_explicit_no_script(script_arg)) {
+    if (tap_is_explicit_no_script(script_arg_name, script_arg_value)) {
         return NULL;
     }
 
-    if (!script_arg) {
+    if (!script_arg_value) {
         return get_relocated_path(default_path);
     }
 
-    return g_strdup(script_arg);
+    return g_strdup(script_arg_value);
 }
 
 static void tap_update_fd_handler(TAPState *s)
@@ -740,7 +746,7 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
         qemu_set_info_str(&s->nc, "helper=%s", tap->helper);
     } else {
         qemu_set_info_str(&s->nc, "ifname=%s,script=%s,downscript=%s", ifname,
-                          script ?: "no", downscript ?: "no");
+                          script ?: "", downscript ?: "");
 
         if (downscript) {
             snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
@@ -946,9 +952,10 @@ int net_init_tap(const Netdev *netdev, const char *name,
         }
     } else {
         g_autofree char *script =
-            tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT);
+            tap_parse_script("script", tap->script, DEFAULT_NETWORK_SCRIPT);
         g_autofree char *downscript =
-            tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT);
+            tap_parse_script("downscript", tap->downscript,
+                             DEFAULT_NETWORK_DOWN_SCRIPT);
 
         if (tap->ifname) {
             pstrcpy(ifname, sizeof ifname, tap->ifname);
qapi/net.json +8 -4
index 8f0915c4d86..ada0329ef9d 100644
@@ -399,15 +399,19 @@
 # @fds: multiple file descriptors of already opened multiqueue capable
 #     tap
 #
-# @script: script to initialize the interface.  An empty string or
-#     "no" disables script execution.  Defaults to
+# @script: script to initialize the interface.  An empty string
+#     disables script execution.  Defaults to
 #     ``<sysconfdir>/qemu-ifup``, where ``<sysconfdir>`` is the
 #     system configuration directory at build time (typically /etc).
+#     Using "no" to disable script execution is deprecated (since
+#     11.2); use an empty string instead.
 #
-# @downscript: script to shut down the interface.  An empty string or
-#     "no" disables script execution.  Defaults to
+# @downscript: script to shut down the interface.  An empty string
+#     disables script execution.  Defaults to
 #     ``<sysconfdir>/qemu-ifdown``, where ``<sysconfdir>`` is the
 #     system configuration directory at build time (typically /etc).
+#     Using "no" to disable script execution is deprecated (since
+#     11.2); use an empty string instead.
 #
 # @br: bridge name (since 2.8)
 #
qemu-options.hx +5 -2
index 200949655ea..7b9a14f5b38 100644
@@ -3014,7 +3014,8 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
     "                use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n"
     "                to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
     "                to deconfigure it\n"
-    "                use '[down]script=no' or '[down]script=' to disable script execution\n"
+    "                use '[down]script=' to disable script execution\n"
+    "                ('[down]script=no' is deprecated and will be treated as a file name in future)\n"
     "                use network helper 'helper' (default=" DEFAULT_BRIDGE_HELPER ") to\n"
     "                configure it\n"
     "                use 'fd=h' to connect to an already opened TAP interface\n"
@@ -3553,7 +3554,9 @@ SRST
     ``<sysconfdir>/qemu-ifup`` and the default network deconfigure script is
     ``<sysconfdir>/qemu-ifdown``, where ``<sysconfdir>`` is the system
     configuration directory at build time (typically ``/etc``).
-    Use ``[down]script=no`` or ``[down]script=`` to disable script execution.
+    Use ``[down]script=`` to disable script execution.
+    Using ``[down]script=no`` is deprecated; in a future version it will
+    be treated as a plain file name.
 
     If running QEMU as an unprivileged user, use the network helper
     to configure the TAP interface and attach it to the bridge.
Signature · 1 line
2.43.0
Reviewed-by on v19 3/15
#6 lore raw

Re: [PATCH v19 03/15] net/tap: deprecate "no" as special value for script/downscript

Quoted 157 lines · Vladimir Sementsov-Ogievskiy

The interface is ambiguous, as "no" is valid file name. So, using "no" as a special value to disable script is deprecated. Use an empty string ("script=" / "downscript=") instead.

In a future version, "no" will be treated as a plain file name, just like any other non-empty value.

Document the deprecation in docs/about/deprecated.rst, qapi/net.json, and qemu-options.hx. Update other docs to use empty string instead of "no". Add a warning.

---
 docs/about/deprecated.rst                  | 18 ++++++++++++++
 docs/system/i386/microvm.rst               |  4 +--
 docs/system/i386/xenpvh.rst                |  2 +-
 docs/system/ppc/ppce500.rst                |  4 +--
 docs/system/riscv/microchip-icicle-kit.rst |  2 +-
 docs/system/riscv/sifive_u.rst             |  2 +-
 net/tap.c                                  | 29 ++++++++++++++--------
 qapi/net.json                              | 12 ++++++---
 qemu-options.hx                            |  7 ++++--
 9 files changed, 56 insertions(+), 24 deletions(-)
docs/about/deprecated.rst +18 -0
index 0c656a968fc..c4929317e3a 100644
@@ -71,6 +71,15 @@ flexible enough. The monitor objects have been converted to QOM, so
 ``-mon mode=control`` is replaced by ``-object monitor-qmp``. The
 short convenience options are not deprecated, only ``-mon``.
 
+``script=no`` and ``downscript=no`` for ``-netdev tap`` (since 11.2)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The special value ``"no"`` for the ``script`` and ``downscript``
+parameters of ``-netdev tap`` disables script execution.  This special
+treatment of ``"no"`` is deprecated.  Use an empty string (``script=``
+or ``downscript=``) to disable script execution instead.  In a future
+version, ``"no"`` will be treated as a plain file name.
+
 QEMU Machine Protocol (QMP) commands
 ------------------------------------
 
@@ -164,6 +173,15 @@ Use ``job-finalize`` instead.
 
 Use ``query-accelerators`` instead.
 
+``"no"`` as value of ``script``/``downscript`` for tap in ``netdev_add`` (since 11.2)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The special value ``"no"`` for the ``script`` and ``downscript``
+parameters of ``netdev_add`` with ``type=tap`` disables script
+execution.  This special treatment of ``"no"`` is deprecated.  Use an
+empty string instead.  In a future version, ``"no"`` will be treated as
+a plain file name.
+
 Human Machine Protocol (HMP) commands
 -------------------------------------
 
docs/system/i386/microvm.rst +2 -2
index 1675e37d3e7..077ea15751e 100644
@@ -79,7 +79,7 @@ legacy ``ISA serial`` device as console::
      -serial stdio \
      -drive id=test,file=test.img,format=raw,if=none \
      -device virtio-blk-device,drive=test \
-     -netdev tap,id=tap0,script=no,downscript=no \
+     -netdev tap,id=tap0,script=,downscript= \
      -device virtio-net-device,netdev=tap0
 
 While the example above works, you might be interested in reducing the
@@ -103,7 +103,7 @@ disabled::
      -device virtconsole,chardev=virtiocon0 \
      -drive id=test,file=test.img,format=raw,if=none \
      -device virtio-blk-device,drive=test \
-     -netdev tap,id=tap0,script=no,downscript=no \
+     -netdev tap,id=tap0,script=,downscript= \
      -device virtio-net-device,netdev=tap0
 
 
docs/system/i386/xenpvh.rst +1 -1
index 904778e3f5c..862f38830b1 100644
@@ -42,7 +42,7 @@ case you need to construct one manually:
       -vnc none                                       \
       -display none                                   \
       -device virtio-net-pci,id=nic0,netdev=net0,mac=00:16:3e:5c:81:78 \
-      -netdev type=tap,id=net0,ifname=vif3.0-emu,br=xenbr0,script=no,downscript=no \
+      -netdev type=tap,id=net0,ifname=vif3.0-emu,br=xenbr0,script=,downscript= \
       -smp 4,maxcpus=4                                \
       -nographic                                      \
       -machine xenpvh,ram-low-base=0,ram-low-size=2147483648,ram-high-base=4294967296,ram-high-size=2147483648,pci-ecam-base=824633720832,pci-ecam-size=268435456,pci-mmio-base=4026531840,pci-mmio-size=33554432,pci-mmio-high-base=824902156288,pci-mmio-high-size=68719476736 \
docs/system/ppc/ppce500.rst +2 -2
index c9fe0915dc5..ec5aaf14fd9 100644
@@ -158,14 +158,14 @@ interface at PCI address 0.1.0, but we can switch that to an e1000 NIC by:
   $ qemu-system-ppc64 -M ppce500 -smp 4 -m 2G \
                       -display none -serial stdio \
                       -bios u-boot \
-                      -nic tap,ifname=tap0,script=no,downscript=no,model=e1000
+                      -nic tap,ifname=tap0,script=,downscript=,model=e1000
 
 The QEMU ``ppce500`` machine can also dynamically instantiate an eTSEC device
 if “-device eTSEC” is given to QEMU:
 
 .. code-block:: bash
 
-  -netdev tap,ifname=tap0,script=no,downscript=no,id=net0 -device eTSEC,netdev=net0
+  -netdev tap,ifname=tap0,script=,downscript=,id=net0 -device eTSEC,netdev=net0
 
 Root file system on flash drive
 -------------------------------
docs/system/riscv/microchip-icicle-kit.rst +1 -1
index 9809e94b84b..7fdb96601ad 100644
@@ -84,7 +84,7 @@ Then we can boot the machine by:
   $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 -m 2G \
       -sd path/to/sdcard.img \
       -nic user,model=cadence_gem \
-      -nic tap,ifname=tap,model=cadence_gem,script=no \
+      -nic tap,ifname=tap,model=cadence_gem,script= \
       -display none -serial stdio \
       -kernel path/to/u-boot/build/dir/u-boot.bin \
       -dtb path/to/u-boot/build/dir/u-boot.dtb
docs/system/riscv/sifive_u.rst +1 -1
index 8f55ae8e313..0e4dcf3e70c 100644
@@ -199,7 +199,7 @@ To boot the VxWorks kernel in QEMU with the ``sifive_u`` machine, use:
 
   $ qemu-system-riscv64 -M sifive_u -smp 5 -m 2G \
       -display none -serial stdio \
-      -nic tap,ifname=tap0,script=no,downscript=no \
+      -nic tap,ifname=tap0,script=,downscript= \
       -kernel /path/to/vxWorks \
       -append "gem(0,0)host:vxWorks h=192.168.200.1 e=192.168.200.2:ffffff00 u=target pw=vxTarget f=0x01"
 
net/tap.c +3 -2
index fedd48c48d2..2e94b4015f6 100644
@@ -92,34 +92,40 @@ static void launch_script(const char *setup_script, const char *ifname,
 static void tap_send(void *opaque);
 static void tap_writable(void *opaque);
 
-static bool tap_is_explicit_no_script(const char *script_arg)
+static bool tap_is_explicit_no_script(const char *script_arg_name,
+                                      const char *script_arg_value)
 {
-    if (!script_arg) {
+    if (!script_arg_value) {
         return false;

net/tap.c static void launch_script(const char *setup_script, const char *ifname, · line 107

Quoted 10 lines
net/tap.c +3 -2
     }
 
-    if (script_arg[0] == '\0') {
+    if (script_arg_value[0] == '\0') {
         return true;
     }
 
-    if (strcmp(script_arg, "no") == 0) {
+    if (strcmp(script_arg_value, "no") == 0) {
+        warn_report("%s=no is deprecated; use %s= instead "

Maybe "'%s=no' is deprecated; use '%s=' instead ".

net/tap.c static void launch_script(const char *setup_script, const char *ifname, · line 108

Quoted 1 line
net/tap.c +1 -0
+                    "(empty string instead of 'no')",

Not sure this is needed.

net/tap.c static void launch_script(const char *setup_script, const char *ifname, · line 114

Quoted 6 lines
net/tap.c +1 -0
+                    script_arg_name, script_arg_name);
         return true;
     }
 
     return false;
 }

Less churn if you name the argument @script_arg_value in PATCH 01.

Quoted 86 lines
net/tap.c +10 -7
-static char *tap_parse_script(const char *script_arg, const char *default_path)
+static char *tap_parse_script(const char *script_arg_name,
+                              const char *script_arg_value,
+                              const char *default_path)
 {
-    if (tap_is_explicit_no_script(script_arg)) {
+    if (tap_is_explicit_no_script(script_arg_name, script_arg_value)) {
         return NULL;
     }
 
-    if (!script_arg) {
+    if (!script_arg_value) {
         return get_relocated_path(default_path);
     }
 
-    return g_strdup(script_arg);
+    return g_strdup(script_arg_value);
 }
 
 static void tap_update_fd_handler(TAPState *s)
@@ -740,7 +746,7 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
         qemu_set_info_str(&s->nc, "helper=%s", tap->helper);
     } else {
         qemu_set_info_str(&s->nc, "ifname=%s,script=%s,downscript=%s", ifname,
-                          script ?: "no", downscript ?: "no");
+                          script ?: "", downscript ?: "");
 
         if (downscript) {
             snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
@@ -946,9 +952,10 @@ int net_init_tap(const Netdev *netdev, const char *name,
         }
     } else {
         g_autofree char *script =
-            tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT);
+            tap_parse_script("script", tap->script, DEFAULT_NETWORK_SCRIPT);
         g_autofree char *downscript =
-            tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT);
+            tap_parse_script("downscript", tap->downscript,
+                             DEFAULT_NETWORK_DOWN_SCRIPT);
 
         if (tap->ifname) {
             pstrcpy(ifname, sizeof ifname, tap->ifname);
qapi/net.json +8 -4
index 8f0915c4d86..ada0329ef9d 100644
@@ -399,15 +399,19 @@
 # @fds: multiple file descriptors of already opened multiqueue capable
 #     tap
 #
-# @script: script to initialize the interface.  An empty string or
-#     "no" disables script execution.  Defaults to
+# @script: script to initialize the interface.  An empty string
+#     disables script execution.  Defaults to
 #     ``<sysconfdir>/qemu-ifup``, where ``<sysconfdir>`` is the
 #     system configuration directory at build time (typically /etc).
+#     Using "no" to disable script execution is deprecated (since
+#     11.2); use an empty string instead.
 #
-# @downscript: script to shut down the interface.  An empty string or
-#     "no" disables script execution.  Defaults to
+# @downscript: script to shut down the interface.  An empty string
+#     disables script execution.  Defaults to
 #     ``<sysconfdir>/qemu-ifdown``, where ``<sysconfdir>`` is the
 #     system configuration directory at build time (typically /etc).
+#     Using "no" to disable script execution is deprecated (since
+#     11.2); use an empty string instead.
 #
 # @br: bridge name (since 2.8)
 #
qemu-options.hx +2 -1
index 200949655ea..7b9a14f5b38 100644
@@ -3014,7 +3014,8 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
     "                use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n"
     "                to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
     "                to deconfigure it\n"
-    "                use '[down]script=no' or '[down]script=' to disable script execution\n"
+    "                use '[down]script=' to disable script execution\n"
+    "                ('[down]script=no' is deprecated and will be treated as a file name in future)\n"
     "                use network helper 'helper' (default=" DEFAULT_BRIDGE_HELPER ") to\n"
     "                configure it\n"
     "                use 'fd=h' to connect to an already opened TAP interface\n"

qemu-options.hx SRST · line 3562

Quoted 10 lines
qemu-options.hx +3 -1
@@ -3553,7 +3554,9 @@ SRST
     ``<sysconfdir>/qemu-ifup`` and the default network deconfigure script is
     ``<sysconfdir>/qemu-ifdown``, where ``<sysconfdir>`` is the system
     configuration directory at build time (typically ``/etc``).
-    Use ``[down]script=no`` or ``[down]script=`` to disable script execution.
+    Use ``[down]script=`` to disable script execution.
+    Using ``[down]script=no`` is deprecated; in a future version it will
+    be treated as a plain file name.
 
     If running QEMU as an unprivileged user, use the network helper
     to configure the TAP interface and attach it to the bridge.

You mention what "no" does only in QMP documentation.

You mention what "no" will do in a future version only in CLI documentation.

If information is useful enough to justify the space in one place, it's likely useful enough in the other place, too.

Up to you.

#7 lore raw

Re: [PATCH v19 03/15] net/tap: deprecate "no" as special value for script/downscript

Quoted 166 lines · Markus Armbruster
Quoted 164 lines · Vladimir Sementsov-Ogievskiy

The interface is ambiguous, as "no" is valid file name. So, using "no" as a special value to disable script is deprecated. Use an empty string ("script=" / "downscript=") instead.

In a future version, "no" will be treated as a plain file name, just like any other non-empty value.

Document the deprecation in docs/about/deprecated.rst, qapi/net.json, and qemu-options.hx. Update other docs to use empty string instead of "no". Add a warning.

---
  docs/about/deprecated.rst                  | 18 ++++++++++++++
  docs/system/i386/microvm.rst               |  4 +--
  docs/system/i386/xenpvh.rst                |  2 +-
  docs/system/ppc/ppce500.rst                |  4 +--
  docs/system/riscv/microchip-icicle-kit.rst |  2 +-
  docs/system/riscv/sifive_u.rst             |  2 +-
  net/tap.c                                  | 29 ++++++++++++++--------
  qapi/net.json                              | 12 ++++++---
  qemu-options.hx                            |  7 ++++--
  9 files changed, 56 insertions(+), 24 deletions(-)
docs/about/deprecated.rst +18 -0
index 0c656a968fc..c4929317e3a 100644
@@ -71,6 +71,15 @@ flexible enough. The monitor objects have been converted to QOM, so
  ``-mon mode=control`` is replaced by ``-object monitor-qmp``. The
  short convenience options are not deprecated, only ``-mon``.
 
+``script=no`` and ``downscript=no`` for ``-netdev tap`` (since 11.2)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The special value ``"no"`` for the ``script`` and ``downscript``
+parameters of ``-netdev tap`` disables script execution.  This special
+treatment of ``"no"`` is deprecated.  Use an empty string (``script=``
+or ``downscript=``) to disable script execution instead.  In a future
+version, ``"no"`` will be treated as a plain file name.
+
  QEMU Machine Protocol (QMP) commands
  ------------------------------------
 
@@ -164,6 +173,15 @@ Use ``job-finalize`` instead.
 
  Use ``query-accelerators`` instead.
 
+``"no"`` as value of ``script``/``downscript`` for tap in ``netdev_add`` (since 11.2)
+'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+
+The special value ``"no"`` for the ``script`` and ``downscript``
+parameters of ``netdev_add`` with ``type=tap`` disables script
+execution.  This special treatment of ``"no"`` is deprecated.  Use an
+empty string instead.  In a future version, ``"no"`` will be treated as
+a plain file name.
+
  Human Machine Protocol (HMP) commands
  -------------------------------------
 
docs/system/i386/microvm.rst +2 -2
index 1675e37d3e7..077ea15751e 100644
@@ -79,7 +79,7 @@ legacy ``ISA serial`` device as console::
       -serial stdio \
       -drive id=test,file=test.img,format=raw,if=none \
       -device virtio-blk-device,drive=test \
-     -netdev tap,id=tap0,script=no,downscript=no \
+     -netdev tap,id=tap0,script=,downscript= \
       -device virtio-net-device,netdev=tap0
 
  While the example above works, you might be interested in reducing the
@@ -103,7 +103,7 @@ disabled::
       -device virtconsole,chardev=virtiocon0 \
       -drive id=test,file=test.img,format=raw,if=none \
       -device virtio-blk-device,drive=test \
-     -netdev tap,id=tap0,script=no,downscript=no \
+     -netdev tap,id=tap0,script=,downscript= \
       -device virtio-net-device,netdev=tap0
 
 
docs/system/i386/xenpvh.rst +1 -1
index 904778e3f5c..862f38830b1 100644
@@ -42,7 +42,7 @@ case you need to construct one manually:
        -vnc none                                       \
        -display none                                   \
        -device virtio-net-pci,id=nic0,netdev=net0,mac=00:16:3e:5c:81:78 \
-      -netdev type=tap,id=net0,ifname=vif3.0-emu,br=xenbr0,script=no,downscript=no \
+      -netdev type=tap,id=net0,ifname=vif3.0-emu,br=xenbr0,script=,downscript= \
        -smp 4,maxcpus=4                                \
        -nographic                                      \
        -machine xenpvh,ram-low-base=0,ram-low-size=2147483648,ram-high-base=4294967296,ram-high-size=2147483648,pci-ecam-base=824633720832,pci-ecam-size=268435456,pci-mmio-base=4026531840,pci-mmio-size=33554432,pci-mmio-high-base=824902156288,pci-mmio-high-size=68719476736 \
docs/system/ppc/ppce500.rst +2 -2
index c9fe0915dc5..ec5aaf14fd9 100644
@@ -158,14 +158,14 @@ interface at PCI address 0.1.0, but we can switch that to an e1000 NIC by:
    $ qemu-system-ppc64 -M ppce500 -smp 4 -m 2G \
                        -display none -serial stdio \
                        -bios u-boot \
-                      -nic tap,ifname=tap0,script=no,downscript=no,model=e1000
+                      -nic tap,ifname=tap0,script=,downscript=,model=e1000
 
  The QEMU ``ppce500`` machine can also dynamically instantiate an eTSEC device
  if “-device eTSEC” is given to QEMU:
 
  .. code-block:: bash
 
-  -netdev tap,ifname=tap0,script=no,downscript=no,id=net0 -device eTSEC,netdev=net0
+  -netdev tap,ifname=tap0,script=,downscript=,id=net0 -device eTSEC,netdev=net0
 
  Root file system on flash drive
  -------------------------------
docs/system/riscv/microchip-icicle-kit.rst +1 -1
index 9809e94b84b..7fdb96601ad 100644
@@ -84,7 +84,7 @@ Then we can boot the machine by:
    $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 -m 2G \
        -sd path/to/sdcard.img \
        -nic user,model=cadence_gem \
-      -nic tap,ifname=tap,model=cadence_gem,script=no \
+      -nic tap,ifname=tap,model=cadence_gem,script= \
        -display none -serial stdio \
        -kernel path/to/u-boot/build/dir/u-boot.bin \
        -dtb path/to/u-boot/build/dir/u-boot.dtb
docs/system/riscv/sifive_u.rst +1 -1
index 8f55ae8e313..0e4dcf3e70c 100644
@@ -199,7 +199,7 @@ To boot the VxWorks kernel in QEMU with the ``sifive_u`` machine, use:
 
    $ qemu-system-riscv64 -M sifive_u -smp 5 -m 2G \
        -display none -serial stdio \
-      -nic tap,ifname=tap0,script=no,downscript=no \
+      -nic tap,ifname=tap0,script=,downscript= \
        -kernel /path/to/vxWorks \
        -append "gem(0,0)host:vxWorks h=192.168.200.1 e=192.168.200.2:ffffff00 u=target pw=vxTarget f=0x01"
 
net/tap.c +4 -3
index fedd48c48d2..2e94b4015f6 100644
@@ -92,34 +92,40 @@ static void launch_script(const char *setup_script, const char *ifname,
  static void tap_send(void *opaque);
  static void tap_writable(void *opaque);
 
-static bool tap_is_explicit_no_script(const char *script_arg)
+static bool tap_is_explicit_no_script(const char *script_arg_name,
+                                      const char *script_arg_value)
  {
-    if (!script_arg) {
+    if (!script_arg_value) {
          return false;
      }
 
-    if (script_arg[0] == '\0') {
+    if (script_arg_value[0] == '\0') {
          return true;
      }
 
Quoted 5 lines

net/tap.c static void launch_script(const char *setup_script, const char *ifname, · line 107

Quoted 3 lines
net/tap.c +2 -1
-    if (strcmp(script_arg, "no") == 0) {
+    if (strcmp(script_arg_value, "no") == 0) {
+        warn_report("%s=no is deprecated; use %s= instead "

Maybe "'%s=no' is deprecated; use '%s=' instead ".

Ok

Quoted 4 lines

net/tap.c static void launch_script(const char *setup_script, const char *ifname, · line 108

Quoted 2 lines
net/tap.c +1 -0
+                    "(empty string instead of 'no')",

Not sure this is needed.

With you single quotes, agree, everything is clear without this note.

Quoted 9 lines

net/tap.c static void launch_script(const char *setup_script, const char *ifname, · line 114

Quoted 7 lines
net/tap.c +1 -0
+                    script_arg_name, script_arg_name);
          return true;
      }
 
      return false;
  }

Less churn if you name the argument @script_arg_value in PATCH 01.

Right, will move.

Quoted 95 lines
Quoted 95 lines
net/tap.c +10 -7
-static char *tap_parse_script(const char *script_arg, const char *default_path)
+static char *tap_parse_script(const char *script_arg_name,
+                              const char *script_arg_value,
+                              const char *default_path)
  {
-    if (tap_is_explicit_no_script(script_arg)) {
+    if (tap_is_explicit_no_script(script_arg_name, script_arg_value)) {
          return NULL;
      }
 
-    if (!script_arg) {
+    if (!script_arg_value) {
          return get_relocated_path(default_path);
      }
 
-    return g_strdup(script_arg);
+    return g_strdup(script_arg_value);
  }
 
  static void tap_update_fd_handler(TAPState *s)
@@ -740,7 +746,7 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
          qemu_set_info_str(&s->nc, "helper=%s", tap->helper);
      } else {
          qemu_set_info_str(&s->nc, "ifname=%s,script=%s,downscript=%s", ifname,
-                          script ?: "no", downscript ?: "no");
+                          script ?: "", downscript ?: "");
 
          if (downscript) {
              snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
@@ -946,9 +952,10 @@ int net_init_tap(const Netdev *netdev, const char *name,
          }
      } else {
          g_autofree char *script =
-            tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT);
+            tap_parse_script("script", tap->script, DEFAULT_NETWORK_SCRIPT);
          g_autofree char *downscript =
-            tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT);
+            tap_parse_script("downscript", tap->downscript,
+                             DEFAULT_NETWORK_DOWN_SCRIPT);
 
          if (tap->ifname) {
              pstrcpy(ifname, sizeof ifname, tap->ifname);
qapi/net.json +8 -4
index 8f0915c4d86..ada0329ef9d 100644
@@ -399,15 +399,19 @@
  # @fds: multiple file descriptors of already opened multiqueue capable
  #     tap
  #
-# @script: script to initialize the interface.  An empty string or
-#     "no" disables script execution.  Defaults to
+# @script: script to initialize the interface.  An empty string
+#     disables script execution.  Defaults to
  #     ``<sysconfdir>/qemu-ifup``, where ``<sysconfdir>`` is the
  #     system configuration directory at build time (typically /etc).
+#     Using "no" to disable script execution is deprecated (since
+#     11.2); use an empty string instead.
  #
-# @downscript: script to shut down the interface.  An empty string or
-#     "no" disables script execution.  Defaults to
+# @downscript: script to shut down the interface.  An empty string
+#     disables script execution.  Defaults to
  #     ``<sysconfdir>/qemu-ifdown``, where ``<sysconfdir>`` is the
  #     system configuration directory at build time (typically /etc).
+#     Using "no" to disable script execution is deprecated (since
+#     11.2); use an empty string instead.
  #
  # @br: bridge name (since 2.8)
  #
qemu-options.hx +5 -2
index 200949655ea..7b9a14f5b38 100644
@@ -3014,7 +3014,8 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
      "                use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n"
      "                to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
      "                to deconfigure it\n"
-    "                use '[down]script=no' or '[down]script=' to disable script execution\n"
+    "                use '[down]script=' to disable script execution\n"
+    "                ('[down]script=no' is deprecated and will be treated as a file name in future)\n"
      "                use network helper 'helper' (default=" DEFAULT_BRIDGE_HELPER ") to\n"
      "                configure it\n"
      "                use 'fd=h' to connect to an already opened TAP interface\n"
@@ -3553,7 +3554,9 @@ SRST
      ``<sysconfdir>/qemu-ifup`` and the default network deconfigure script is
      ``<sysconfdir>/qemu-ifdown``, where ``<sysconfdir>`` is the system
      configuration directory at build time (typically ``/etc``).
-    Use ``[down]script=no`` or ``[down]script=`` to disable script execution.
+    Use ``[down]script=`` to disable script execution.
+    Using ``[down]script=no`` is deprecated; in a future version it will
+    be treated as a plain file name.
 
Quoted 7 lines

qemu-options.hx SRST · line 3562

Quoted 2 lines
qemu-options.hx +0 -0
      If running QEMU as an unprivileged user, use the network helper
      to configure the TAP interface and attach it to the bridge.

You mention what "no" does only in QMP documentation.

You mention what "no" will do in a future version only in CLI documentation.

Inconsistent, right.. Will touch up.

Quoted 8 lines

If information is useful enough to justify the space in one place, it's likely useful enough in the other place, too.

Up to you.

Signature · 2 lines
Best regards,
Vladimir
#8 lore raw

PATCH v19 4/15 net/tap: move vhost-net open() calls to tap_parse_vhost_fds()

In reply to Vladimir Sementsov-Ogievskiy

1. Simplify code path: get vhostfds for all cases in one function.

2. Prepare for further tap-fd-migraton feature, when we'll need to postpone vhost initialization up to post-load stage.

---
 net/tap.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
net/tap.c +22 -17
index 2e94b4015f6..dcc914ffdf2 100644
@@ -757,8 +757,7 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
         }
     }
 
-    if (tap->has_vhost ? tap->vhost :
-        (vhostfd != -1) || (tap->has_vhostforce && tap->vhostforce)) {
+    if (vhostfd != -1) {
         VhostNetOptions options;
 
         options.backend_type = VHOST_BACKEND_TYPE_KERNEL;
@@ -768,17 +767,6 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
         } else {
             options.busyloop_timeout = 0;
         }
-
-        if (vhostfd == -1) {
-            vhostfd = open("/dev/vhost-net", O_RDWR);
-            if (vhostfd < 0) {
-                error_setg_file_open(errp, errno, "/dev/vhost-net");
-                goto failed;
-            }
-            if (!qemu_set_blocking(vhostfd, false, errp)) {
-                goto failed;
-            }
-        }
         options.opaque = (void *)(uintptr_t)vhostfd;
         options.nvqs = 2;
         options.feature_bits = kernel_feature_bits;
@@ -864,14 +852,31 @@ static int tap_parse_fds_and_queues(const NetdevTapOptions *tap, int **fds,
 static bool tap_parse_vhost_fds(const NetdevTapOptions *tap, int **vhost_fds,
                                 int queues, Error **errp)
 {
-    if (!(tap->vhostfd || tap->vhostfds)) {
+    bool need_vhost = tap->has_vhost ? tap->vhost :
+        ((tap->vhostfd || tap->vhostfds) ||
+         (tap->has_vhostforce && tap->vhostforce));
+
+    if (!need_vhost) {
         *vhost_fds = NULL;
         return true;
     }
 
-    if (net_parse_fds(tap->vhostfd ?: tap->vhostfds,
-                      vhost_fds, queues, errp) < 0) {
-        return false;
+    if (tap->vhostfd || tap->vhostfds) {
+        if (net_parse_fds(tap->vhostfd ?: tap->vhostfds,
+                          vhost_fds, queues, errp) < 0) {
+            return false;
+        }
+    } else {
+        *vhost_fds = g_new(int, queues);
+        for (int i = 0; i < queues; i++) {
+            int vhostfd = open("/dev/vhost-net", O_RDWR);
+            if (vhostfd < 0) {
+                error_setg_file_open(errp, errno, "/dev/vhost-net");
+                net_free_fds(*vhost_fds, i);
+                return false;
+            }
+            (*vhost_fds)[i] = vhostfd;
+        }
     }
 
     if (!unblock_fds(*vhost_fds, queues, errp)) {
Signature · 1 line
2.43.0
#9 lore raw

PATCH v19 5/15 net/tap: move vhost initialization to tap_setup_vhost()

In reply to Vladimir Sementsov-Ogievskiy

Make a new helper function in a way it can be reused later for TAP fd-migration feature: we'll need to initialize vhost in a later point when we doesn't have access to QAPI parameters.

---
 net/tap.c | 62 ++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 24 deletions(-)
net/tap.c +38 -24
index dcc914ffdf2..3a0a7a9f2ab 100644
@@ -71,6 +71,8 @@ static const int kernel_feature_bits[] = {
 typedef struct TAPState {
     NetClientState nc;
     int fd;
+    int vhostfd;
+    uint32_t vhost_busyloop_timeout;
     char down_script[1024];
     char down_script_arg[128];
     uint8_t buf[NET_BUFSIZE];
@@ -723,6 +725,38 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,
     return fd;
 }
 
+static bool tap_setup_vhost(TAPState *s, Error **errp)
+{
+    VhostNetOptions options;
+
+    if (s->vhostfd == -1) {
+        return true;
+    }
+
+    options.backend_type = VHOST_BACKEND_TYPE_KERNEL;
+    options.net_backend = &s->nc;
+    options.busyloop_timeout = s->vhost_busyloop_timeout;
+    options.opaque = (void *)(uintptr_t)s->vhostfd;
+    options.nvqs = 2;
+    options.feature_bits = kernel_feature_bits;
+    options.get_acked_features = NULL;
+    options.save_acked_features = NULL;
+    options.max_tx_queue_size = 0;
+    options.is_vhost_user = false;
+
+    s->vhost_net = vhost_net_init(&options);
+    if (!s->vhost_net) {
+        error_setg(errp,
+                   "vhost-net requested but could not be initialized");
+        return false;
+    }
+
+    /* vhostfd ownership is passed to s->vhost_net */
+    s->vhostfd = -1;
+
+    return true;
+}
+
 static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
                              const char *name,
                              const char *ifname, const char *script,
@@ -757,30 +791,10 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
         }
     }
 
-    if (vhostfd != -1) {
-        VhostNetOptions options;
-
-        options.backend_type = VHOST_BACKEND_TYPE_KERNEL;
-        options.net_backend = &s->nc;
-        if (tap->has_poll_us) {
-            options.busyloop_timeout = tap->poll_us;
-        } else {
-            options.busyloop_timeout = 0;
-        }
-        options.opaque = (void *)(uintptr_t)vhostfd;
-        options.nvqs = 2;
-        options.feature_bits = kernel_feature_bits;
-        options.get_acked_features = NULL;
-        options.save_acked_features = NULL;
-        options.max_tx_queue_size = 0;
-        options.is_vhost_user = false;
-
-        s->vhost_net = vhost_net_init(&options);
-        if (!s->vhost_net) {
-            error_setg(errp,
-                       "vhost-net requested but could not be initialized");
-            goto failed;
-        }
+    s->vhostfd = vhostfd;
+    s->vhost_busyloop_timeout = tap->has_poll_us ? tap->poll_us : 0;
+    if (!tap_setup_vhost(s, errp)) {
+        return false;
     }
 
     return true;
Signature · 1 line
2.43.0
#10 lore raw

PATCH v19 6/15 net/tap: use container_of instead of DO_UPCAST

In reply to Vladimir Sementsov-Ogievskiy

We are going to QOMify tap backend, which includes deriving TAPState from Object. So "NetClientState nc" will not be a first member. Let's parepare for this change, and use container_of(), which will work regardless position of "nc" field.

---
 net/tap.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
net/tap.c +18 -18
index 3a0a7a9f2ab..0679580fcaf 100644
@@ -176,7 +176,7 @@ static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt
 static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov,
                                int iovcnt)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     const struct iovec *iovp = iov;
     g_autofree struct iovec *iov_copy = NULL;
     struct virtio_net_hdr hdr = { };
@@ -212,7 +212,7 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
 
 static void tap_send_completed(NetClientState *nc, ssize_t len)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     tap_read_poll(s, true);
 }
 
@@ -272,7 +272,7 @@ static void tap_send(void *opaque)
 
 static bool tap_has_ufo(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
 
     assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
 
@@ -281,7 +281,7 @@ static bool tap_has_ufo(NetClientState *nc)
 
 static bool tap_has_uso(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
 
     assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
 
@@ -290,7 +290,7 @@ static bool tap_has_uso(NetClientState *nc)
 
 static bool tap_has_tunnel(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
 
     assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
     return s->has_tunnel;
@@ -298,7 +298,7 @@ static bool tap_has_tunnel(NetClientState *nc)
 
 static bool tap_has_vnet_hdr(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
 
     assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
 
@@ -312,7 +312,7 @@ static bool tap_has_vnet_hdr_len(NetClientState *nc, int len)
 
 static void tap_set_vnet_hdr_len(NetClientState *nc, int len)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
 
     assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
 
@@ -323,21 +323,21 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len)
 
 static int tap_set_vnet_le(NetClientState *nc, bool is_le)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
 
     return tap_fd_set_vnet_le(s->fd, is_le);
 }
 
 static int tap_set_vnet_be(NetClientState *nc, bool is_be)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
 
     return tap_fd_set_vnet_be(s->fd, is_be);
 }
 
 static void tap_set_offload(NetClientState *nc, const NetOffloads *ol)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     if (s->fd < 0) {
         return;
     }
@@ -358,7 +358,7 @@ static void tap_exit_notify(Notifier *notifier, void *data)
 
 static void tap_cleanup(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
 
     if (s->vhost_net) {
         vhost_net_cleanup(s->vhost_net);
@@ -382,14 +382,14 @@ static void tap_cleanup(NetClientState *nc)
 
 static void tap_poll(NetClientState *nc, bool enable)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     tap_read_poll(s, enable);
     tap_write_poll(s, enable);
 }
 
 static bool tap_set_steering_ebpf(NetClientState *nc, int prog_fd)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
 
     return tap_fd_set_steering_ebpf(s->fd, prog_fd) == 0;
@@ -397,7 +397,7 @@ static bool tap_set_steering_ebpf(NetClientState *nc, int prog_fd)
 
 int tap_get_fd(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
     return s->fd;
 }
@@ -409,7 +409,7 @@ int tap_get_fd(NetClientState *nc)
  */
 static VHostNetState *tap_get_vhost_net(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
     return s->vhost_net;
 }
@@ -448,7 +448,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
 
     nc = qemu_new_net_client(&net_tap_info, peer, model, name);
 
-    s = DO_UPCAST(TAPState, nc, nc);
+    s = container_of(nc, TAPState, nc);
 
     s->fd = fd;
     s->host_vnet_hdr_len = vnet_hdr ? sizeof(struct virtio_net_hdr) : 0;
@@ -1017,7 +1017,7 @@ fail:
 
 int tap_enable(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     int ret;
 
     if (s->enabled) {
@@ -1034,7 +1034,7 @@ int tap_enable(NetClientState *nc)
 
 int tap_disable(NetClientState *nc)
 {
-    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+    TAPState *s = container_of(nc, TAPState, nc);
     int ret;
 
     if (s->enabled == 0) {
Signature · 1 line
2.43.0
#11 lore raw

PATCH v19 7/15 net/tap: QOMify tap backend

In reply to Vladimir Sementsov-Ogievskiy

We prepare for being able to migrate TAP backend. We'll need a user change-able property for it, which can be set from machine type. So, let's QOMify it first.

---
 include/net/net.h |  7 +++++++
 include/net/tap.h |  2 ++
 net/net.c         | 14 +++++++-------
 net/tap.c         | 48 +++++++++++++++++++++++++++++++++++++++--------
 4 files changed, 56 insertions(+), 15 deletions(-)
include/net/net.h +7 -0
index 45bc86fc86b..bdf16bb3e64 100644
@@ -160,6 +160,13 @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr);
 NetClientState *qemu_find_netdev(const char *id);
 int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                  NetClientDriver type, int max);
+void qemu_net_client_setup(NetClientState *nc,
+                           NetClientInfo *info,
+                           NetClientState *peer,
+                           const char *model,
+                           const char *name,
+                           NetClientDestructor *destructor,
+                           bool is_datapath);
 NetClientState *qemu_new_net_client(NetClientInfo *info,
                                     NetClientState *peer,
                                     const char *model,
include/net/tap.h +2 -0
index 6f34f13eae4..268570571f4 100644
@@ -28,6 +28,8 @@
 
 #include "standard-headers/linux/virtio_net.h"
 
+#define TYPE_TAP_NETDEV "tap-netdev"
+
 int tap_enable(NetClientState *nc);
 int tap_disable(NetClientState *nc);
 
net/net.c +7 -7
index 2892f1730d1..a06558b75bf 100644
@@ -261,13 +261,13 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender,
                                        int iovcnt,
                                        void *opaque);
 
-static void qemu_net_client_setup(NetClientState *nc,
-                                  NetClientInfo *info,
-                                  NetClientState *peer,
-                                  const char *model,
-                                  const char *name,
-                                  NetClientDestructor *destructor,
-                                  bool is_datapath)
+void qemu_net_client_setup(NetClientState *nc,
+                           NetClientInfo *info,
+                           NetClientState *peer,
+                           const char *model,
+                           const char *name,
+                           NetClientDestructor *destructor,
+                           bool is_datapath)
 {
     nc->info = info;
     nc->model = g_strdup(model);
net/tap.c +40 -8

87 lines not on this page · raw message

Signature · 1 line
2.43.0
#12 lore raw

PATCH v19 8/15 net/tap: add TYPE_VMSTATE_IF interface

In reply to Vladimir Sementsov-Ogievskiy

We'll need it to implement TAP backend live migration.

---
 net/tap.c | 43 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 9 deletions(-)
net/tap.c +34 -9
index 8ba48180b01..95bcfaaf1ea 100644
@@ -43,7 +43,6 @@
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "hw/virtio/vhost.h"
-#include "qom/object.h"
 
 #include "net/tap.h"
 #include "net/util.h"
@@ -91,6 +90,8 @@ struct TAPState {
     VHostNetState *vhost_net;
     unsigned host_vnet_hdr_len;
     Notifier exit;
+
+    int queue_index;
 };
 
 static void launch_script(const char *setup_script, const char *ifname,
@@ -420,10 +421,29 @@ static VHostNetState *tap_get_vhost_net(NetClientState *nc)
 }
 
 
+static char *tap_vmstate_if_get_id(VMStateIf *obj)
+{
+    TAPState *s = TAP_NETDEV(obj);
+    char *res = g_strdup_printf("%s/%d", s->nc.name, s->queue_index);
+    return res;
+}
+
+static void tap_class_init(ObjectClass *klass, const void *data)
+{
+    VMStateIfClass *vc = VMSTATE_IF_CLASS(klass);
+
+    vc->get_id = tap_vmstate_if_get_id;
+}
+
 static const TypeInfo tap_netdev_info = {
     .name = TYPE_TAP_NETDEV,
     .parent = TYPE_OBJECT,
     .instance_size = sizeof(TAPState),
+    .class_init = tap_class_init,
+    .interfaces = (const InterfaceInfo[]) {
+        { TYPE_VMSTATE_IF },
+        { }
+    },
 };
 
 static void tap_net_client_destructor(NetClientState *nc)
@@ -456,13 +476,16 @@ static NetClientInfo net_tap_info = {
 
 static TAPState *new_tap(NetClientState *peer,
                          const char *model,
-                         const char *name)
+                         const char *name,
+                         int queue_index)
 {
     TAPState *s = TAP_NETDEV(object_new(TYPE_TAP_NETDEV));
 
     qemu_net_client_setup(&s->nc, &net_tap_info, peer, model, name,
                           tap_net_client_destructor, true);
 
+    s->queue_index = queue_index;
+
     return s;
 }
 
@@ -470,10 +493,11 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
                                  const char *model,
                                  const char *name,
                                  int fd,
-                                 int vnet_hdr)
+                                 int vnet_hdr,
+                                 int queue_index)
 {
     NetOffloads ol = {};
-    TAPState *s = new_tap(peer, model, name);
+    TAPState *s = new_tap(peer, model, name, queue_index);
 
     s->fd = fd;
     s->host_vnet_hdr_len = vnet_hdr ? sizeof(struct virtio_net_hdr) : 0;
@@ -710,7 +734,7 @@ int net_init_bridge(const Netdev *netdev, const char *name,
         close(fd);
         return -1;
     }
-    s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr);
+    s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr, 0);
 
     qemu_set_info_str(&s->nc, "helper=%s,br=%s", helper, br);
 
@@ -786,10 +810,11 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
                              const char *name,
                              const char *ifname, const char *script,
                              const char *downscript, int vhostfd,
-                             int vnet_hdr, int fd, Error **errp)
+                             int vnet_hdr, int fd, int queue_index,
+                             Error **errp)
 {
     TAPState *s = net_tap_fd_init(peer, tap->helper ? "bridge" : "tap",
-                                  name, fd, vnet_hdr);
+                                  name, fd, vnet_hdr, queue_index);
     bool sndbuf_required = tap->has_sndbuf;
     int sndbuf =
         (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT_MAX;
@@ -990,7 +1015,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
             if (!net_init_tap_one(tap, peer, name, ifname,
                                   NULL, NULL,
                                   vhost_fds ? vhost_fds[i] : -1,
-                                  vnet_hdr, fds[i], errp)) {
+                                  vnet_hdr, fds[i], i, errp)) {
                 goto fail;
             }
         }
@@ -1025,7 +1050,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
                                   i >= 1 ? NULL : script,
                                   i >= 1 ? NULL : downscript,
                                   vhost_fds ? vhost_fds[i] : -1,
-                                  vnet_hdr, fd, errp)) {
+                                  vnet_hdr, fd, i, errp)) {
                 goto fail;
             }
         }
Signature · 1 line
2.43.0
#13 lore raw

PATCH v19 9/15 qapi: add local migration parameter

In reply to Vladimir Sementsov-Ogievskiy

We are going to implement local-migration feature: some devices will be able to transfer open file descriptors through migration stream (which must UNIX domain socket for that purpose). This allows to transfer the whole backend state without reconnecting and restarting the backend service. For example, virtio-net will migrate its attached TAP netdev, together with its connected file descriptors.

In this commit we introduce a migration parameter, which enables the feature for devices that support it (none at the moment).

---
 include/migration/misc.h |  2 ++
 migration/options.c      | 18 +++++++++++++++++-
 qapi/migration.json      | 15 +++++++++++++--
 3 files changed, 32 insertions(+), 3 deletions(-)
include/migration/misc.h +2 -0
index 2b2fbb59a40..019717f4cda 100644
@@ -161,4 +161,6 @@ bool multifd_join_device_state_save_threads(void);
 
 void migration_request_switchover_ack_legacy(const char *requester);
 
+bool migrate_local(void);
+
 #endif
migration/options.c +17 -1
index dfce19405d4..5c439f6d724 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
 #include "qemu/units.h"
+#include "qapi/util.h"
 #include "exec/target_page.h"
 #include "qapi/clone-visitor.h"
 #include "qapi/error.h"
@@ -25,6 +26,7 @@
 #include "migration/colo.h"
 #include "migration/cpr.h"
 #include "migration/misc.h"
+#include "migration/options.h"
 #include "migration.h"
 #include "migration-stats.h"
 #include "qemu-file.h"
@@ -350,6 +352,12 @@ bool migrate_mapped_ram(void)
     return s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM];
 }
 
+bool migrate_local(void)
+{
+    MigrationState *s = migrate_get_current();
+    return s->parameters.local;
+}
+
 bool migrate_ignore_shared(void)
 {
     MigrationState *s = migrate_get_current();
@@ -1085,7 +1093,7 @@ static void migrate_mark_all_params_present(MigrationParameters *p)
         &p->has_announce_step, &p->has_block_bitmap_mapping,
         &p->has_x_vcpu_dirty_limit_period, &p->has_vcpu_dirty_limit,
         &p->has_mode, &p->has_zero_page_detection, &p->has_direct_io,
-        &p->has_x_rdma_chunk_size, &p->has_cpr_exec_command,
+        &p->has_x_rdma_chunk_size, &p->has_cpr_exec_command, &p->has_local,
     };
 
     len = ARRAY_SIZE(has_fields);
@@ -1433,6 +1441,10 @@ static void migrate_params_test_apply(MigrationParameters *params,
         qapi_free_strList(dest->cpr_exec_command);
         dest->cpr_exec_command = QAPI_CLONE(strList, params->cpr_exec_command);
     }
+
+    if (params->has_local) {
+        dest->local = params->local;
+    }
 }
 
 static void migrate_params_apply(MigrationParameters *params)
@@ -1565,6 +1577,10 @@ static void migrate_params_apply(MigrationParameters *params)
         s->parameters.cpr_exec_command =
             QAPI_CLONE(strList, params->cpr_exec_command);
     }
+
+    if (params->has_local) {
+        s->parameters.local = params->local;
+    }
 }
 
 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
qapi/migration.json +13 -2
index 66bd900465a..813c1f76e46 100644
@@ -830,7 +830,8 @@
            'zero-page-detection',
            'direct-io',
            { 'name': 'x-rdma-chunk-size', 'features': [ 'unstable' ] },
-           'cpr-exec-command'] }
+           'cpr-exec-command',
+           'local'] }
 
 ##
 # @migrate-set-parameters:
@@ -1012,6 +1013,15 @@
 #     Must be set to the same value on both source and destination
 #     before migration starts.  (Since 11.1)
 #
+# @local: Permit the use of optimizations for local migration.
+#     This must only be set when both the source and destination
+#     QEMU processes are on the same OS and directly connected
+#     with a UNIX domain socket as the migration channel to enable
+#     use of file descriptor passing.  Individual device backends
+#     may need additional configuration flags set  to enable local
+#     migration optimizations.  This will be documented against the
+#     device backends where it applies.  (Since 11.2)
+#
 # Features:
 #
 # @unstable: Members @x-checkpoint-delay, @x-rdma-chunk-size, and
@@ -1053,7 +1063,8 @@
             '*direct-io': 'bool',
             '*x-rdma-chunk-size': { 'type': 'uint64',
                                     'features': [ 'unstable' ] },
-            '*cpr-exec-command': [ 'str' ]} }
+            '*cpr-exec-command': [ 'str' ],
+            '*local': 'bool' } }
 
 ##
 # @query-migrate-parameters:
Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH v19 09/15] qapi: add local migration parameter

Quoted 14 lines · Vladimir Sementsov-Ogievskiy

We are going to implement local-migration feature: some devices will be able to transfer open file descriptors through migration stream (which must UNIX domain socket for that purpose). This allows to transfer the whole backend state without reconnecting and restarting the backend service. For example, virtio-net will migrate its attached TAP netdev, together with its connected file descriptors.

In this commit we introduce a migration parameter, which enables the feature for devices that support it (none at the moment).

[...]

Quoted 15 lines
qapi/migration.json +2 -1
index 66bd900465a..813c1f76e46 100644
@@ -830,7 +830,8 @@
            'zero-page-detection',
            'direct-io',
            { 'name': 'x-rdma-chunk-size', 'features': [ 'unstable' ] },
-           'cpr-exec-command'] }
+           'cpr-exec-command',
+           'local'] }
 
 ##
 # @migrate-set-parameters:

qapi/migration.json line 1018

Quoted 6 lines
qapi/migration.json +3 -0
@@ -1012,6 +1013,15 @@
 #     Must be set to the same value on both source and destination
 #     before migration starts.  (Since 11.1)
 #
+# @local: Permit the use of optimizations for local migration.
+#     This must only be set when both the source and destination
+#     QEMU processes are on the same OS and directly connected

I think "on the same OS" is less than clear. Does it mean both ends run Linux, or both ends run Windows? That doesn't make sense. Recommend to scratch it, because what matters is the UNIX domain socket.

With that, my Acked-by stands.

Ignorant question you may well have covered before: could we forgo @local and simply use "is a UNIX domain socket"?

Quoted 19 lines
qapi/migration.json +8 -1
+#     with a UNIX domain socket as the migration channel to enable
+#     use of file descriptor passing.  Individual device backends
+#     may need additional configuration flags set  to enable local
+#     migration optimizations.  This will be documented against the
+#     device backends where it applies.  (Since 11.2)
+#
 # Features:
 #
 # @unstable: Members @x-checkpoint-delay, @x-rdma-chunk-size, and
@@ -1053,7 +1063,8 @@
             '*direct-io': 'bool',
             '*x-rdma-chunk-size': { 'type': 'uint64',
                                     'features': [ 'unstable' ] },
-            '*cpr-exec-command': [ 'str' ]} }
+            '*cpr-exec-command': [ 'str' ],
+            '*local': 'bool' } }
 
 ##
 # @query-migrate-parameters:
#15 lore raw

Re: [PATCH v19 09/15] qapi: add local migration parameter

Quoted 31 lines · Markus Armbruster
Quoted 14 lines · Vladimir Sementsov-Ogievskiy

We are going to implement local-migration feature: some devices will be able to transfer open file descriptors through migration stream (which must UNIX domain socket for that purpose). This allows to transfer the whole backend state without reconnecting and restarting the backend service. For example, virtio-net will migrate its attached TAP netdev, together with its connected file descriptors.

In this commit we introduce a migration parameter, which enables the feature for devices that support it (none at the moment).

[...]

Quoted 12 lines
qapi/migration.json +2 -1
index 66bd900465a..813c1f76e46 100644
@@ -830,7 +830,8 @@
             'zero-page-detection',
             'direct-io',
             { 'name': 'x-rdma-chunk-size', 'features': [ 'unstable' ] },
-           'cpr-exec-command'] }
+           'cpr-exec-command',
+           'local'] }
 
Quoted 13 lines

qapi/migration.json line 1018

Quoted 9 lines
qapi/migration.json +3 -0
  ##
  # @migrate-set-parameters:
@@ -1012,6 +1013,15 @@
  #     Must be set to the same value on both source and destination
  #     before migration starts.  (Since 11.1)
  #
+# @local: Permit the use of optimizations for local migration.
+#     This must only be set when both the source and destination
+#     QEMU processes are on the same OS and directly connected

I think "on the same OS" is less than clear. Does it mean both ends run Linux, or both ends run Windows? That doesn't make sense. Recommend to scratch it, because what matters is the UNIX domain socket.

Agree.

Quoted 5 lines

With that, my Acked-by stands.

Ignorant question you may well have covered before: could we forgo @local and simply use "is a UNIX domain socket"?

My mistake is still not having the answer in commit message.

We can't because, UNIX socket may be only a first part of transfer channel to the remote target.

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

Quoted 21 lines
Quoted 20 lines
qapi/migration.json +8 -1
+#     with a UNIX domain socket as the migration channel to enable
+#     use of file descriptor passing.  Individual device backends
+#     may need additional configuration flags set  to enable local
+#     migration optimizations.  This will be documented against the
+#     device backends where it applies.  (Since 11.2)
+#
  # Features:
  #
  # @unstable: Members @x-checkpoint-delay, @x-rdma-chunk-size, and
@@ -1053,7 +1063,8 @@
              '*direct-io': 'bool',
              '*x-rdma-chunk-size': { 'type': 'uint64',
                                      'features': [ 'unstable' ] },
-            '*cpr-exec-command': [ 'str' ]} }
+            '*cpr-exec-command': [ 'str' ],
+            '*local': 'bool' } }
 
  ##
  # @query-migrate-parameters:
Signature · 2 lines
Best regards,
Vladimir
#16 lore raw

PATCH v19 10/15 migration/channel: check that transfer is UNIX socket when "local" set

In reply to Vladimir Sementsov-Ogievskiy

As documented, for "local", the migration channel must be direct UNIX socket connection from source to target. We can't check for it being "direct", but let's at least check that we deal with UNIX socket (fd-passing supported).

---
 migration/channel.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
migration/channel.c +17 -0
index 1e2935f926b..ba00dd1931d 100644
@@ -214,6 +214,13 @@ void migration_channel_process_incoming(QIOChannel *ioc)
     trace_migration_set_incoming_channel(
         ioc, object_get_typename(OBJECT(ioc)));
 
+    if (migrate_local() &&
+        !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_FD_PASS)) {
+        error_setg(&local_err,
+                   "local migration requires a UNIX domain socket channel");
+        goto out;
+    }
+
     if (migrate_channel_requires_tls_upgrade(ioc)) {
         migration_tls_channel_process_incoming(ioc, &local_err);
     } else {
@@ -241,6 +248,16 @@ void migration_channel_connect_outgoing(MigrationState *s, QIOChannel *ioc)
 {
     trace_migration_set_outgoing_channel(ioc, object_get_typename(OBJECT(ioc)));
 
+    if (migrate_local() &&
+        !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_FD_PASS)) {
+        Error *local_err = NULL;
+
+        error_setg(&local_err,
+                   "local migration requires a UNIX domain socket channel");
+        migration_connect_error_propagate(s, local_err);
+        return;
+    }
+
     if (migrate_channel_requires_tls_upgrade(ioc)) {
         Error *local_err = NULL;
 
Signature · 1 line
2.43.0
#17 lore raw

PATCH v19 11/15 virtio-net: support local migration of backend

In reply to Vladimir Sementsov-Ogievskiy

Next commit will introduce live-migration (with fd-passing) for TAP net backend. So, now we prepare virtio-net for it
Add virtio-net option local-migration, which is true by default, but false for older machine types, which doesn't support the feature.

We introduce interface for live-migrating backends:

1. ->is_wait_incoming() handler, so that virtio-net knows, that backend is not fully intialized, as it waits for incoming migration stream.

2. MIG_PRI_BACKEND priority: backends should migrate with higher priority than virtio-net, so that we can do final preparations here in post-load handlers and be sure, that backends are already prepared.

---
 hw/net/virtio-net.c            | 89 +++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-net.h |  1 +
 include/migration/vmstate.h    |  2 +
 include/net/net.h              |  2 +
 4 files changed, 93 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +88 -1
index f0e3beb2903..c6e7f7a370f 100644
@@ -40,6 +40,7 @@
 #include "migration/misc.h"
 #include "standard-headers/linux/ethtool.h"
 #include "system/system.h"
+#include "system/runstate.h"
 #include "system/replay.h"
 #include "trace.h"
 #include "monitor/qdev.h"
@@ -3060,7 +3061,17 @@ static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue)
     n->multiqueue = multiqueue;
     virtio_net_change_num_queues(n, max * 2 + 1);
 
-    virtio_net_set_queue_pairs(n);
+    /*
+     * virtio_net_set_multiqueue() called from set_features(0) on early
+     * reset, when peer may wait for incoming (and is not initialized
+     * yet).
+     * Don't worry about it: virtio_net_set_queue_pairs() will be called
+     * later from virtio_net_post_load_device(), and anyway will be
+     * no-op for local incoming migration with live backend passing.
+     */
+    if (!n->peers_wait_incoming) {
+        virtio_net_set_queue_pairs(n);
+    }
 }
 
 static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n)
@@ -3089,6 +3100,17 @@ static void virtio_net_get_features(VirtIODevice *vdev, uint64_t *features,
 
     virtio_add_feature_ex(features, VIRTIO_NET_F_MAC);
 
+    if (n->peers_wait_incoming) {
+        /*
+         * Excessive feature set is OK for early initialization when
+         * we wait for local incoming migration: actual guest-negotiated
+         * features will come with migration stream anyway. And we are sure
+         * that we support same host-features as source, because the backend
+         * is the same (the same TAP device, for example).
+         */
+        return;
+    }
+
     if (!peer_has_vnet_hdr(n)) {
         virtio_clear_feature_ex(features, VIRTIO_NET_F_CSUM);
         virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_TSO4);
@@ -3185,6 +3207,7 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
     VirtIODevice *vdev = VIRTIO_DEVICE(n);
     int i, link_down;
     bool has_tunnel_hdr = virtio_has_tunnel_hdr(vdev->guest_features_ex);
+    Error *local_err = NULL;
 
     trace_virtio_net_post_load_device();
     virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs,
@@ -3242,6 +3265,20 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
     }
 
     virtio_net_commit_rss_config(n);
+
+    /*
+     * If live-migration is enabled for some backend, than backend
+     * has already been migrated at higher priority (MIG_PRI_BACKEND)
+     * and virtio_net_vnet_post_load() has already called
+     * peer_test_vnet_hdr().  Recompute host_features so that virtio-net
+     * reflects the capabilities of the restored backend.
+     */
+    virtio_net_get_features(vdev, &vdev->host_features, &local_err);
+    if (local_err) {
+        error_report_err(local_err);
+        return -EINVAL;
+    }
+
     return 0;
 }
 
@@ -3392,6 +3429,14 @@ static int virtio_net_vnet_post_load(void *opaque, int version_id)
 {
     struct VirtIONetMigTmp *tmp = opaque;
 
+    /*
+     * If live-migration is enabled for some backend, than backend
+     * has already been migrated at higher priority (MIG_PRI_BACKEND),
+     * so n->has_vnet_hdr can be refreshed from the live backend right
+     * here.
+     */
+    peer_test_vnet_hdr(tmp->parent);
+
     if (tmp->has_vnet_hdr && !peer_has_vnet_hdr(tmp->parent)) {
         error_report("virtio-net: saved image requires vnet_hdr=on");
         return -EINVAL;
@@ -3871,6 +3916,42 @@ static bool failover_hide_primary_device(DeviceListener *listener,
     return qatomic_read(&n->failover_primary_hidden);
 }
 
+static bool virtio_net_check_peers_wait_incoming(VirtIONet *n, bool *waiting,
+                                                 Error **errp)
+{
+    bool has_waiting = false;
+    bool has_not_waiting = false;
+
+    for (int i = 0; i < n->max_queue_pairs; i++) {
+        NetClientState *peer = n->nic->ncs[i].peer;
+        if (!peer) {
+            continue;
+        }
+
+        if (peer->info->is_wait_incoming &&
+            peer->info->is_wait_incoming(peer)) {
+            has_waiting = true;
+        } else {
+            has_not_waiting = true;
+        }
+
+        if (has_waiting && has_not_waiting) {
+            error_setg(errp, "Mixed peer states: some peers wait for incoming "
+                       "migration while others don't");
+            return false;
+        }
+    }
+
+    if (has_waiting && !runstate_check(RUN_STATE_INMIGRATE)) {
+        error_setg(errp, "Peers wait for incoming, but it's not an incoming "
+                   "migration.");
+        return false;
+    }
+
+    *waiting = has_waiting;
+    return true;
+}
+
 static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -4008,6 +4089,12 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
         n->nic->ncs[i].do_not_pad = true;
     }
 
+    if (!virtio_net_check_peers_wait_incoming(n, &n->peers_wait_incoming,
+                                              errp)) {
+        virtio_cleanup(vdev);
+        return;
+    }
+
     peer_test_vnet_hdr(n);
     if (peer_has_vnet_hdr(n)) {
         n->host_hdr_len = sizeof(struct virtio_net_hdr);
include/hw/virtio/virtio-net.h +1 -0
index 371e3764282..8c967760c2a 100644
@@ -230,6 +230,7 @@ struct VirtIONet {
     struct EBPFRSSContext ebpf_rss;
     uint32_t nr_ebpf_rss_fds;
     char **ebpf_rss_fds;
+    bool peers_wait_incoming;
 };
 
 size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev,
include/migration/vmstate.h +2 -0
index 1b7f295417e..bbc569adc52 100644
@@ -178,6 +178,8 @@ typedef enum {
 
     MIG_PRI_LOW,                /* Must happen after default */
     MIG_PRI_DEFAULT,
+    MIG_PRI_BACKEND,            /* Must happen before emulated devices, */
+                                /* e.g. virtio-net */
     MIG_PRI_IOMMU,              /* Must happen before PCI devices */
     MIG_PRI_PCI_BUS,            /* Must happen before IOMMU */
     MIG_PRI_VIRTIO_MEM,         /* Must happen before IOMMU */
include/net/net.h +2 -0
index bdf16bb3e64..658b0d0aaf1 100644
@@ -81,6 +81,7 @@ typedef void (SocketReadStateFinalize)(SocketReadState *rs);
 typedef void (NetAnnounce)(NetClientState *);
 typedef bool (SetSteeringEBPF)(NetClientState *, int);
 typedef bool (NetCheckPeerType)(NetClientState *, ObjectClass *, Error **);
+typedef bool (IsWaitIncoming)(NetClientState *);
 typedef struct vhost_net *(GetVHostNet)(NetClientState *nc);
 
 typedef struct NetClientInfo {
@@ -109,6 +110,7 @@ typedef struct NetClientInfo {
     NetAnnounce *announce;
     SetSteeringEBPF *set_steering_ebpf;
     NetCheckPeerType *check_peer_type;
+    IsWaitIncoming *is_wait_incoming;
     GetVHostNet *get_vhost_net;
 } NetClientInfo;
 
Signature · 1 line
2.43.0
#18 lore raw

PATCH v19 12/15 net/tap: disable read polling for stopped VM

In reply to Vladimir Sementsov-Ogievskiy

Polling when VM is stopped doesn't make real sense, as stopped VM can't handle incoming traffic anyway.

And it's critical for introduction of local TAP migration feature in the next commit: the TAP device will be transferred to the target (open fd will be passed through migration channel), and if we continue polling on source, we may get a package, which we'll never handle on source (already stopped), it will be lost. Better is save this package for target VM to handle.

---
 net/tap.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
net/tap.c +28 -0
index 95bcfaaf1ea..2bd4b089573 100644
@@ -36,6 +36,7 @@
 #include "net/net.h"
 #include "clients.h"
 #include "monitor/monitor.h"
+#include "system/runstate.h"
 #include "system/system.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
@@ -92,6 +93,8 @@ struct TAPState {
     Notifier exit;
 
     int queue_index;
+    bool read_poll_detached;
+    VMChangeStateEntry *vmstate;
 };
 
 static void launch_script(const char *setup_script, const char *ifname,
@@ -150,6 +153,23 @@ static void tap_read_poll(TAPState *s, bool enable)
     tap_update_fd_handler(s);
 }
 
+static void tap_vm_state_change(void *opaque, bool running, RunState state)
+{
+    TAPState *s = opaque;
+
+    if (running) {
+        if (s->read_poll_detached) {
+            tap_read_poll(s, true);
+            s->read_poll_detached = false;
+        }
+    } else if (state == RUN_STATE_FINISH_MIGRATE) {
+        if (s->read_poll) {
+            s->read_poll_detached = true;
+            tap_read_poll(s, false);
+        }
+    }
+}
+
 static void tap_write_poll(TAPState *s, bool enable)
 {
     s->write_poll = enable;
@@ -380,6 +400,11 @@ static void tap_cleanup(NetClientState *nc)
         s->exit.notify = NULL;
     }
 
+    if (s->vmstate) {
+        qemu_del_vm_change_state_handler(s->vmstate);
+        s->vmstate = NULL;
+    }
+
     tap_read_poll(s, false);
     tap_write_poll(s, false);
     close(s->fd);
@@ -819,6 +844,9 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
     int sndbuf =
         (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT_MAX;
 
+    s->read_poll_detached = false;
+    s->vmstate = qemu_add_vm_change_state_handler(tap_vm_state_change, s);
+
     if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) &&
         sndbuf_required) {
         goto failed;
Signature · 1 line
2.43.0
#19 lore raw

Re: [PATCH v19 12/15] net/tap: disable read polling for stopped VM

Quoted 7 lines · On 7/14/26, 11:44 AM, "Vladimir Sementsov-Ogievskiy"…
net/tap.c +7 -0
+static void tap_vm_state_change(void *opaque, bool running, RunState state)
+{
+ TAPState *s = opaque;
+
+ if (running) {
+ if (s->read_poll_detached) {
+ tap_read_poll(s, true);

net/tap.c static void tap_read_poll(TAPState *s, bool enable) · line 172

Quoted 10 lines
net/tap.c +10 -0
+ s->read_poll_detached = false;
+ }
+ } else if (state == RUN_STATE_FINISH_MIGRATE) {
+ if (s->read_poll) {
+ s->read_poll_detached = true;
+ tap_read_poll(s, false);
+ }
+ }
+}
+

tap_read_poll is called in a few other places. Is it necessary to update read_poll_detached there as well?

I'm not sure that it is, I'm trying to wrap my head around any possible ordering issues and it isn't obvious to me one way or the other.

Thanks,
Ben

#20 lore raw

Re: [PATCH v19 12/15] net/tap: disable read polling for stopped VM

Quoted 24 lines · Ben
Quoted 7 lines · On 7/14/26, 11:44 AM, "Vladimir Sementsov-Ogievskiy"…
(quoted diff) +7 -0
+static void tap_vm_state_change(void *opaque, bool running, RunState state)
+{
+ TAPState *s = opaque;
+
+ if (running) {
+ if (s->read_poll_detached) {
+ tap_read_poll(s, true);

Review

Quoted 10 lines
(quoted diff) +10 -0
+ s->read_poll_detached = false;
+ }
+ } else if (state == RUN_STATE_FINISH_MIGRATE) {
+ if (s->read_poll) {
+ s->read_poll_detached = true;
+ tap_read_poll(s, false);
+ }
+ }
+}
+

tap_read_poll is called in a few other places. Is it necessary to update read_poll_detached there as well?

Quoted 2 lines

I'm not sure that it is, I'm trying to wrap my head around any possible ordering issues and it isn't obvious to me one way or the other.

Good question!

Hm. The whole patch is about source QEMU process, to not poll, when we expect that target is already handle packets in TAP.

Let's go through calls to tap_read_poll (except for tap_vm_state_change):

1. tap_send_completed() -> tap_read_poll(true). Called asynchronously from packet sending (to guest) code. Actually, that may be a problem. If callback comes when we are alredy switched to FINISH_MIGRATE, it breaks the logic, need to fix.

2. tap_send() -> tap_read_poll(false). It's safe. But it may break "if (s->read_poll)" of this patch, if somehow interleave with sate change (not sure it possible, but better to fix)

3. tap_cleanup() -> tap_read_poll(false) - safe

4. tap_post_load() -> tap_read_poll(true) - safe, it's not about source QEMU

5. net_tap_fd_init() -> tap_read_poll(true) - safe, it's on tap creation

6. through tap_poll() from frontend code, when transfer control to vhost.

--

I'll remake this patch. Better idea: modify tap_read_poll() itself:

net/tap.c +9 -5
@@ -100,7 +100,7 @@ struct TAPState {
     Notifier exit;
 
     int queue_index;
-    bool read_poll_detached;
+    bool enable_poll_on_resume;
     VMChangeStateEntry *vmstate;
     bool local_migration_supported;
 };
@@ -157,6 +157,10 @@ static void tap_update_fd_handler(TAPState *s)
 
 static void tap_read_poll(TAPState *s, bool enable)
 {
+    if (enable && runstate_check(RUN_STATE_FINISH_MIGRATE)) {
+        s->enable_poll_on_resume = true;
+        return;
+    }
     s->read_poll = enable;
     tap_update_fd_handler(s);
 }
@@ -166,13 +170,13 @@ static void tap_vm_state_change(void *opaque, bool running, RunState state)
     TAPState *s = opaque;
 
     if (running) {
-        if (s->read_poll_detached) {
+        if (s->enable_poll_on_resume) {
             tap_read_poll(s, true);
-            s->read_poll_detached = false;
+            s->enable_poll_on_resume = false;
         }
     } else if (state == RUN_STATE_FINISH_MIGRATE) {
         if (s->read_poll) {
-            s->read_poll_detached = true;
+            s->enable_poll_on_resume = true;
             tap_read_poll(s, false);
         }
     }
@@ -964,7 +968,7 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
     int sndbuf =
         (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT_MAX;
 
-    s->read_poll_detached = false;
+    s->enable_poll_on_resume = false;
     s->vmstate = qemu_add_vm_change_state_handler(tap_vm_state_change, s);
 
     if (!tap_set_sndbuf(fd, sndbuf, sndbuf_required ? errp : NULL) &&
Signature · 2 lines
Best regards,
Vladimir
#21 lore raw

PATCH v19 13/15 net/tap: support local migration with virtio-net

In reply to Vladimir Sementsov-Ogievskiy

Support transferring of TAP state (including open fd).

Add new property "local-migration-supported", which defines whether local-migration is actually supported for this TAP device. Starting from 11.2 QEMU Machine Types it's enabled by default.

Note that local-migration (including migrating opened FDs through migration channel, which must be UNIX socket) is enabled by global "local" migration parameters. But individual devices may have additional options to enable/disable it per device.

The tricky thing is that we need to know whether to call open/connect in TAP initialization code, i.e. we need to know the value of migration parameter "local" when creating the TAP device. For incoming migration, we can know only for TAP devices created with QMP after setting the migration parameter with QMP.

So the full picture is:

On source, to start outgoing "local" migration you need:

- migration parameter "local" set to true
- "local-migration-supported" TAP option set to true (the default, starting from 11.2 QEMU Machine Types)

If at least one of these options is not set, TAP backend doesn't participate in migration.

On target, things are more difficult:

Same, you need both "local" and "local-migration-supported" be set. And same, if one of them is not set, TAP backend is initialized as usual, and doesn't accept any incoming state.

Additionally, if you are going to set "local", it must be set before creating the TAP device. If TAP device created with "local" unset, it initializes as usual. If you enable "local" after it and start incoming migration, it will fail in .pre_load handler of TAP backend.

Moreover, there are interface restrictions: if you create TAP device when QEMU is in INCOMING state, and both "local" and "local-migration-supported" set, most of TAP options are not allowed, and script/downscript are required to be explicitly unset (set to "" or "no").

---
 net/tap.c     | 165 ++++++++++++++++++++++++++++++++++++++++++++++++--
 qapi/net.json |  22 ++++++-
 2 files changed, 180 insertions(+), 7 deletions(-)
net/tap.c +159 -6
index 2bd4b089573..4162820bcee 100644
@@ -38,12 +38,17 @@
 #include "monitor/monitor.h"
 #include "system/runstate.h"
 #include "system/system.h"
+#include "migration/misc.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "hw/virtio/vhost.h"
+#include "hw/core/vmstate-if.h"
+#include "migration/vmstate.h"
+#include "qom/object.h"
+#include "qom/compat-properties.h"
 
 #include "net/tap.h"
 #include "net/util.h"
@@ -71,6 +76,8 @@ static const int kernel_feature_bits[] = {
 
 OBJECT_DECLARE_SIMPLE_TYPE(TAPState, TAP_NETDEV)
 
+static const VMStateDescription vmstate_tap;
+
 struct TAPState {
     Object parent_obj;
 
@@ -95,6 +102,7 @@ struct TAPState {
     int queue_index;
     bool read_poll_detached;
     VMChangeStateEntry *vmstate;
+    bool local_migration_supported;
 };
 
 static void launch_script(const char *setup_script, const char *ifname,
@@ -409,6 +417,8 @@ static void tap_cleanup(NetClientState *nc)
     tap_write_poll(s, false);
     close(s->fd);
     s->fd = -1;
+
+    vmstate_unregister(VMSTATE_IF(s), &vmstate_tap, s);
 }
 
 static void tap_poll(NetClientState *nc, bool enable)
@@ -445,6 +455,76 @@ static VHostNetState *tap_get_vhost_net(NetClientState *nc)
     return s->vhost_net;
 }
 
+static bool tap_is_wait_incoming(NetClientState *nc)
+{
+    TAPState *s = container_of(nc, TAPState, nc);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
+    return s->fd == -1;
+}
+
+static bool tap_pre_load(void *opaque, Error **errp)
+{
+    TAPState *s = opaque;
+
+    if (s->fd != -1) {
+        error_setg(errp,
+                   "TAP is already initialized and cannot receive "
+                   "incoming fd.  For local migration, 'local' "
+                   "migration parameter must be set _before_ "
+                   "creating TAP device.");
+        return false;
+    }
+
+    return true;
+}
+
+static bool tap_setup_vhost(TAPState *s, Error **errp);
+
+static bool tap_post_load(void *opaque, int version_id, Error **errp)
+{
+    ERRP_GUARD();
+    TAPState *s = opaque;
+
+    tap_read_poll(s, true);
+
+    if (s->fd < 0) {
+        error_setg(errp, "FD was not loaded during incoming migration");
+        return false;
+    }
+
+    if (!tap_setup_vhost(s, errp)) {
+        error_prepend(errp,
+                      "Failed to setup vhost during TAP post-load: ");
+        return false;
+    }
+
+    return true;
+}
+
+static bool tap_needed(void *opaque)
+{
+    TAPState *s = opaque;
+
+    return s->local_migration_supported && migrate_local();
+}
+
+static const VMStateDescription vmstate_tap = {
+    .name = "net-tap",
+    .priority = MIG_PRI_BACKEND,
+    .pre_load_errp = tap_pre_load,
+    .post_load_errp = tap_post_load,
+    .needed = tap_needed,
+    .fields = (const VMStateField[]) {
+        VMSTATE_FD(fd, TAPState),
+        VMSTATE_BOOL(using_vnet_hdr, TAPState),
+        VMSTATE_BOOL(has_ufo, TAPState),
+        VMSTATE_BOOL(has_uso, TAPState),
+        VMSTATE_BOOL(has_tunnel, TAPState),
+        VMSTATE_BOOL(enabled, TAPState),
+        VMSTATE_UINT32(host_vnet_hdr_len, TAPState),
+        VMSTATE_END_OF_LIST()
+    }
+};
 
 static char *tap_vmstate_if_get_id(VMStateIf *obj)
 {
@@ -453,17 +533,42 @@ static char *tap_vmstate_if_get_id(VMStateIf *obj)
     return res;
 }
 
+static bool tap_get_local_migration_supported_prop(Object *obj, Error **errp)
+{
+    TAPState *s = TAP_NETDEV(obj);
+    return s->local_migration_supported;
+}
+
+static void tap_set_local_migration_supported_prop(Object *obj, bool value,
+                                                   Error **errp)
+{
+    TAPState *s = TAP_NETDEV(obj);
+    s->local_migration_supported = value;
+}
+
+static void tap_instance_init(Object *obj)
+{
+    TAPState *s = TAP_NETDEV(obj);
+    s->local_migration_supported = false;
+}
+
 static void tap_class_init(ObjectClass *klass, const void *data)
 {
     VMStateIfClass *vc = VMSTATE_IF_CLASS(klass);
 
     vc->get_id = tap_vmstate_if_get_id;
+
+    object_class_property_add_bool(klass, "local-migration-supported",
+                                   tap_get_local_migration_supported_prop,
+                                   tap_set_local_migration_supported_prop);
 }
 
 static const TypeInfo tap_netdev_info = {
     .name = TYPE_TAP_NETDEV,
     .parent = TYPE_OBJECT,
     .instance_size = sizeof(TAPState),
+    .instance_init = tap_instance_init,
+    .instance_post_init = object_apply_compat_props,
     .class_init = tap_class_init,
     .interfaces = (const InterfaceInfo[]) {
         { TYPE_VMSTATE_IF },
@@ -496,13 +601,16 @@ static NetClientInfo net_tap_info = {
     .set_vnet_le = tap_set_vnet_le,
     .set_vnet_be = tap_set_vnet_be,
     .set_steering_ebpf = tap_set_steering_ebpf,
+    .is_wait_incoming = tap_is_wait_incoming,
     .get_vhost_net = tap_get_vhost_net,
 };
 
 static TAPState *new_tap(NetClientState *peer,
                          const char *model,
                          const char *name,
-                         int queue_index)
+                         int queue_index,
+                         bool has_local_migration_supported,
+                         bool local_migration_supported)
 {
     TAPState *s = TAP_NETDEV(object_new(TYPE_TAP_NETDEV));
 
@@ -511,6 +619,12 @@ static TAPState *new_tap(NetClientState *peer,
 
     s->queue_index = queue_index;
 
+    if (has_local_migration_supported) {
+        s->local_migration_supported = local_migration_supported;
+    }
+
+    vmstate_register(VMSTATE_IF(s), VMSTATE_INSTANCE_ID_ANY, &vmstate_tap, s);
+
     return s;
 }
 
@@ -519,10 +633,14 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
                                  const char *name,
                                  int fd,
                                  int vnet_hdr,
-                                 int queue_index)
+                                 int queue_index,
+                                 bool has_local_migration_supported,
+                                 bool local_migration_supported)
 {
     NetOffloads ol = {};
-    TAPState *s = new_tap(peer, model, name, queue_index);
+    TAPState *s = new_tap(peer, model, name, queue_index,
+                          has_local_migration_supported,
+                          local_migration_supported);
 
     s->fd = fd;
     s->host_vnet_hdr_len = vnet_hdr ? sizeof(struct virtio_net_hdr) : 0;
@@ -759,7 +877,7 @@ int net_init_bridge(const Netdev *netdev, const char *name,
         close(fd);
         return -1;
     }
-    s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr, 0);
+    s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr, 0, true, false);
 
     qemu_set_info_str(&s->nc, "helper=%s,br=%s", helper, br);
 
@@ -839,7 +957,9 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
                              Error **errp)
 {
     TAPState *s = net_tap_fd_init(peer, tap->helper ? "bridge" : "tap",
-                                  name, fd, vnet_hdr, queue_index);
+                                  name, fd, vnet_hdr, queue_index,
+                                  tap->has_local_migration_supported,
+                                  tap->local_migration_supported);
     bool sndbuf_required = tap->has_sndbuf;
     int sndbuf =
         (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT_MAX;
@@ -987,6 +1107,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
     /* for the no-fd, no-helper case */
     char ifname[128];
     int *fds = NULL, *vhost_fds = NULL;
+    bool incoming_fds;
 
     assert(netdev->type == NET_CLIENT_DRIVER_TAP);
     tap = &netdev->u.tap;
@@ -1009,6 +1130,23 @@ int net_init_tap(const Netdev *netdev, const char *name,
         return -1;
     }
 
+    incoming_fds = tap->local_migration_supported && migrate_local() &&
+                   runstate_check(RUN_STATE_INMIGRATE);
+
+    if (incoming_fds &&
+        (tap->fd || tap->fds || tap->helper || tap->br || tap->ifname ||
+         tap->has_sndbuf || tap->has_vnet_hdr ||
+         !tap_is_explicit_no_script("script", tap->script) ||
+         !tap_is_explicit_no_script("downscript", tap->downscript))) {
+        error_setg(errp, "Local incoming migration of TAP device (-incoming, "
+                   "migration parameter @local is set, "
+                   "TAP parameter @local-migration-supported is set) "
+                   "is incompatible with "
+                   "fd=, fds=, helper=, br=, ifname=, sndbuf= and vnet_hdr=, "
+                   "and requires explicit empty script= and downscript=");
+        return -1;
+    }
+
     queues = tap_parse_fds_and_queues(tap, &fds, errp);
     if (queues < 0) {
         return -1;
@@ -1027,7 +1165,22 @@ int net_init_tap(const Netdev *netdev, const char *name,
         goto fail;
     }
 
-    if (fds) {
+    if (incoming_fds) {
+        for (i = 0; i < queues; i++) {
+            TAPState *s = new_tap(peer, "tap", name, i,
+                                  tap->has_local_migration_supported,
+                                  tap->local_migration_supported);
+            qemu_set_info_str(&s->nc, "incoming");
+
+            s->fd = -1;
+            if (vhost_fds) {
+                s->vhostfd = vhost_fds[i];
+                s->vhost_busyloop_timeout = tap->has_poll_us ? tap->poll_us : 0;
+            } else {
+                s->vhostfd = -1;
+            }
+        }
+    } else if (fds) {
         for (i = 0; i < queues; i++) {
             if (i == 0) {
                 vnet_hdr = tap_probe_vnet_hdr(fds[i], errp);
qapi/net.json +21 -1
index ada0329ef9d..d0d6e303b0d 100644
@@ -435,6 +435,25 @@
 # @poll-us: maximum number of microseconds that could be spent on busy
 #     polling for tap (since 2.7)
 #
+# @local-migration-supported: enable local migration for this TAP
+#     backend.  When set, local migration is enabled/disabled by
+#     migration parameter @local for this TAP backend.  When unset,
+#     migration parameter @local is ignored for this TAP backend.
+#     To be able to do incoming local migration of a TAP backend,
+#     migration parameter @local must be set _before_ creating the
+#     TAP backend.  Otherwise, TAP backend is initialized as usual,
+#     opening/creating TAP devices in kernel.  In this case further
+#     local incoming migration (with migration parameter @local set
+#     after creating TAP backend with @local-migration-supporeted
+#     parameter set) will simply fail.
+#     Moreover, when QEMU is in incoming migration state, migration
+#     parameter @local is set and @local-migration-supported is set,
+#     the following options are not supported and must not be set:
+#     @fd, @fds, @helper, @br, @ifname, @sndbuf, @vnet_hdr.
+#     Additionally in this case @script and @downscipt must be
+#     explicitly disabled (empty strings or "no").
+#     (Since 11.2)
+#
 # Since: 1.2
 ##
 { 'struct': 'NetdevTapOptions',
@@ -453,7 +472,8 @@
     '*vhostfds':   'str',
     '*vhostforce': 'bool',
     '*queues':     'uint32',
-    '*poll-us':    'uint32'} }
+    '*poll-us':    'uint32',
+    '*local-migration-supported': 'bool' } }
 
 ##
 # @NetdevSocketOptions:
Signature · 1 line
2.43.0
#22 lore raw

Re: [PATCH v19 13/15] net/tap: support local migration with virtio-net

Quoted 48 lines · Vladimir Sementsov-Ogievskiy

Support transferring of TAP state (including open fd).

Add new property "local-migration-supported", which defines whether local-migration is actually supported for this TAP device. Starting from 11.2 QEMU Machine Types it's enabled by default.

Note that local-migration (including migrating opened FDs through migration channel, which must be UNIX socket) is enabled by global "local" migration parameters. But individual devices may have additional options to enable/disable it per device.

The tricky thing is that we need to know whether to call open/connect in TAP initialization code, i.e. we need to know the value of migration parameter "local" when creating the TAP device. For incoming migration, we can know only for TAP devices created with QMP after setting the migration parameter with QMP.

So the full picture is:

On source, to start outgoing "local" migration you need:

- migration parameter "local" set to true
- "local-migration-supported" TAP option set to true (the default, starting from 11.2 QEMU Machine Types)

If at least one of these options is not set, TAP backend doesn't participate in migration.

On target, things are more difficult:

Same, you need both "local" and "local-migration-supported" be set. And same, if one of them is not set, TAP backend is initialized as usual, and doesn't accept any incoming state.

Additionally, if you are going to set "local", it must be set before creating the TAP device. If TAP device created with "local" unset, it initializes as usual. If you enable "local" after it and start incoming migration, it will fail in .pre_load handler of TAP backend.

Moreover, there are interface restrictions: if you create TAP device when QEMU is in INCOMING state, and both "local" and "local-migration-supported" set, most of TAP options are not allowed, and script/downscript are required to be explicitly unset (set to "" or "no").

Quoted 5 lines
---
  net/tap.c     | 165 ++++++++++++++++++++++++++++++++++++++++++++++++--
  qapi/net.json |  22 ++++++-
  2 files changed, 180 insertions(+), 7 deletions(-)

squash in, to mark it unstable:

net/tap.c +7 -7
index 4162820bcee..250ae15acb7 100644
@@ -558,7 +558,7 @@ static void tap_class_init(ObjectClass *klass, const void *data)
 
     vc->get_id = tap_vmstate_if_get_id;
 
-    object_class_property_add_bool(klass, "local-migration-supported",
+    object_class_property_add_bool(klass, "x-local-migration-supported",
                                    tap_get_local_migration_supported_prop,
                                    tap_set_local_migration_supported_prop);
 }
@@ -958,8 +958,8 @@ static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
 {
     TAPState *s = net_tap_fd_init(peer, tap->helper ? "bridge" : "tap",
                                   name, fd, vnet_hdr, queue_index,
-                                  tap->has_local_migration_supported,
-                                  tap->local_migration_supported);
+                                  tap->has_x_local_migration_supported,
+                                  tap->x_local_migration_supported);
     bool sndbuf_required = tap->has_sndbuf;
     int sndbuf =
         (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT_MAX;
@@ -1130,7 +1130,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
         return -1;
     }
 
-    incoming_fds = tap->local_migration_supported && migrate_local() &&
+    incoming_fds = tap->x_local_migration_supported && migrate_local() &&
                    runstate_check(RUN_STATE_INMIGRATE);
 
     if (incoming_fds &&
@@ -1140,7 +1140,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
          !tap_is_explicit_no_script("downscript", tap->downscript))) {
         error_setg(errp, "Local incoming migration of TAP device (-incoming, "
                    "migration parameter @local is set, "
-                   "TAP parameter @local-migration-supported is set) "
+                   "TAP parameter @x-local-migration-supported is set) "
                    "is incompatible with "
                    "fd=, fds=, helper=, br=, ifname=, sndbuf= and vnet_hdr=, "
                    "and requires explicit empty script= and downscript=");
@@ -1168,8 +1168,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
     if (incoming_fds) {
         for (i = 0; i < queues; i++) {
             TAPState *s = new_tap(peer, "tap", name, i,
-                                  tap->has_local_migration_supported,
-                                  tap->local_migration_supported);
+                                  tap->has_x_local_migration_supported,
+                                  tap->x_local_migration_supported);
             qemu_set_info_str(&s->nc, "incoming");
 
             s->fd = -1;
qapi/net.json +8 -3
index d0d6e303b0d..e244cc62658 100644
@@ -435,7 +435,7 @@
 # @poll-us: maximum number of microseconds that could be spent on busy
 #     polling for tap (since 2.7)
 #
-# @local-migration-supported: enable local migration for this TAP
+# @x-local-migration-supported: enable local migration for this TAP
 #     backend.  When set, local migration is enabled/disabled by
 #     migration parameter @local for this TAP backend.  When unset,
 #     migration parameter @local is ignored for this TAP backend.
@@ -447,13 +447,17 @@
 #     after creating TAP backend with @local-migration-supporeted
 #     parameter set) will simply fail.
 #     Moreover, when QEMU is in incoming migration state, migration
-#     parameter @local is set and @local-migration-supported is set,
+#     parameter @local is set and @x-local-migration-supported is set,
 #     the following options are not supported and must not be set:
 #     @fd, @fds, @helper, @br, @ifname, @sndbuf, @vnet_hdr.
 #     Additionally in this case @script and @downscipt must be
 #     explicitly disabled (empty strings or "no").
 #     (Since 11.2)
 #
+# Features:
+#
+# @unstable: Member @x-local-migration-supported is experimental.
+#
 # Since: 1.2
 ##
 { 'struct': 'NetdevTapOptions',
@@ -473,7 +477,8 @@
     '*vhostforce': 'bool',
     '*queues':     'uint32',
     '*poll-us':    'uint32',
-    '*local-migration-supported': 'bool' } }
+    '*x-local-migration-supported': {
+      'type': 'bool', 'features' : [ 'unstable'] } } }
 
 ##
 # @NetdevSocketOptions:
tests/functional/x86_64/test_tap_migration.py +1 -1
index bcc0a60dfe9..5edf3f0fee2 100755
@@ -329,7 +329,7 @@ def add_virtio_net(
             "queues": 4,
             "script": "no",
             "downscript": "no",
-            "local-migration-supported": local,
+            "x-local-migration-supported": local,
         }
 
         if not (local and incoming):
Signature · 2 lines
Best regards,
Vladimir
#23 lore raw

Re: [PATCH v19 13/15] net/tap: support local migration with virtio-net

In reply to Vladimir Sementsov-Ogievskiy
Quoted 8 lines · On 7/14/26, 11:44 AM, "Vladimir Sementsov-Ogievskiy"…

+ if (has_local_migration_supported) {
+ s->local_migration_supported = local_migration_supported;
+ }

net/tap.c +3 -0
+
+ vmstate_register(VMSTATE_IF(s), VMSTATE_INSTANCE_ID_ANY, &vmstate_tap, s);
+

return s;
}

A comment on vmstate_register says:

Quoted 2 lines

* New code shouldn't be using this function as QOM-ified devices have
* dc->vmsd to store the serialisation description.

Is it possible to use that interface here?

#24 lore raw

Re: [PATCH v19 13/15] net/tap: support local migration with virtio-net

Quoted 15 lines · Ben
Quoted 8 lines · On 7/14/26, 11:44 AM, "Vladimir Sementsov-Ogievskiy"…

+ if (has_local_migration_supported) {
+ s->local_migration_supported = local_migration_supported;
+ }

net/tap.c +3 -0
+
+ vmstate_register(VMSTATE_IF(s), VMSTATE_INSTANCE_ID_ANY, &vmstate_tap, s);
+

return s;
}

A comment on vmstate_register says:

Quoted 5 lines
Quoted 2 lines

* New code shouldn't be using this function as QOM-ified devices have
* dc->vmsd to store the serialisation description.

Is it possible to use that interface here?

I'm afraid not. TAP is "QOM-ified", but it's not a device, and don't participate in generic device migration code.

Signature · 2 lines
Best regards,
Vladimir
#25 lore raw

Re: [PATCH v19 13/15] net/tap: support local migration with virtio-net

In reply to Vladimir Sementsov-Ogievskiy
Quoted 113 lines · Vladimir Sementsov-Ogievskiy

Support transferring of TAP state (including open fd).

Add new property "local-migration-supported", which defines whether local-migration is actually supported for this TAP device. Starting from 11.2 QEMU Machine Types it's enabled by default.

Note that local-migration (including migrating opened FDs through migration channel, which must be UNIX socket) is enabled by global "local" migration parameters. But individual devices may have additional options to enable/disable it per device.

The tricky thing is that we need to know whether to call open/connect in TAP initialization code, i.e. we need to know the value of migration parameter "local" when creating the TAP device. For incoming migration, we can know only for TAP devices created with QMP after setting the migration parameter with QMP.

So the full picture is:

On source, to start outgoing "local" migration you need:

- migration parameter "local" set to true
- "local-migration-supported" TAP option set to true (the default, starting from 11.2 QEMU Machine Types)

If at least one of these options is not set, TAP backend doesn't participate in migration.

On target, things are more difficult:

Same, you need both "local" and "local-migration-supported" be set. And same, if one of them is not set, TAP backend is initialized as usual, and doesn't accept any incoming state.

Additionally, if you are going to set "local", it must be set before creating the TAP device. If TAP device created with "local" unset, it initializes as usual. If you enable "local" after it and start incoming migration, it will fail in .pre_load handler of TAP backend.

Moreover, there are interface restrictions: if you create TAP device when QEMU is in INCOMING state, and both "local" and "local-migration-supported" set, most of TAP options are not allowed, and script/downscript are required to be explicitly unset (set to "" or "no").

---
 net/tap.c     | 165 ++++++++++++++++++++++++++++++++++++++++++++++++--
 qapi/net.json |  22 ++++++-
 2 files changed, 180 insertions(+), 7 deletions(-)
net/tap.c +17 -0
index 2bd4b089573..4162820bcee 100644
@@ -38,12 +38,17 @@
 #include "monitor/monitor.h"
 #include "system/runstate.h"
 #include "system/system.h"
+#include "migration/misc.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "hw/virtio/vhost.h"
+#include "hw/core/vmstate-if.h"
+#include "migration/vmstate.h"
+#include "qom/object.h"
+#include "qom/compat-properties.h"
 
 #include "net/tap.h"
 #include "net/util.h"
@@ -71,6 +76,8 @@ static const int kernel_feature_bits[] = {
 
 OBJECT_DECLARE_SIMPLE_TYPE(TAPState, TAP_NETDEV)
 
+static const VMStateDescription vmstate_tap;
+
 struct TAPState {
     Object parent_obj;
 
@@ -95,6 +102,7 @@ struct TAPState {
     int queue_index;
     bool read_poll_detached;
     VMChangeStateEntry *vmstate;
+    bool local_migration_supported;
 };
 
 static void launch_script(const char *setup_script, const char *ifname,
@@ -409,6 +417,8 @@ static void tap_cleanup(NetClientState *nc)
     tap_write_poll(s, false);
     close(s->fd);
     s->fd = -1;
+
+    vmstate_unregister(VMSTATE_IF(s), &vmstate_tap, s);
 }
 
 static void tap_poll(NetClientState *nc, bool enable)
@@ -445,6 +455,76 @@ static VHostNetState *tap_get_vhost_net(NetClientState *nc)
     return s->vhost_net;
 }
 
+static bool tap_is_wait_incoming(NetClientState *nc)
+{
+    TAPState *s = container_of(nc, TAPState, nc);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
+    return s->fd == -1;
+}
+

net/tap.c static VHostNetState *tap_get_vhost_net(NetClientState *nc) · line 474

Quoted 10 lines
net/tap.c +10 -0
+static bool tap_pre_load(void *opaque, Error **errp)
+{
+    TAPState *s = opaque;
+
+    if (s->fd != -1) {
+        error_setg(errp,
+                   "TAP is already initialized and cannot receive "
+                   "incoming fd.  For local migration, 'local' "
+                   "migration parameter must be set _before_ "
+                   "creating TAP device.");

From error_setg()'s contract:

* The resulting message should be a single phrase, with no newline or
* trailing punctuation.

Suggest something like

error_setg(errp,
"TAP is already initialized and cannot receive " "incoming fd");
error_append_hint(errp,
"Migration parameter 'local' must be set" " _before_ creating the TAP device.");

Requires ERRP_GUARD().

Quoted 5 lines
net/tap.c +5 -0
+        return false;
+    }
+
+    return true;
+}

[...]

Quoted 16 lines
qapi/net.json +8 -0
index ada0329ef9d..d0d6e303b0d 100644
@@ -435,6 +435,25 @@
 # @poll-us: maximum number of microseconds that could be spent on busy
 #     polling for tap (since 2.7)
 #
+# @local-migration-supported: enable local migration for this TAP
+#     backend.  When set, local migration is enabled/disabled by
+#     migration parameter @local for this TAP backend.  When unset,
+#     migration parameter @local is ignored for this TAP backend.
+#     To be able to do incoming local migration of a TAP backend,
+#     migration parameter @local must be set _before_ creating the
+#     TAP backend.  Otherwise, TAP backend is initialized as usual,
+#     opening/creating TAP devices in kernel.  In this case further

qapi/net.json line 455

Quoted 10 lines
qapi/net.json +10 -0
+#     local incoming migration (with migration parameter @local set
+#     after creating TAP backend with @local-migration-supporeted
+#     parameter set) will simply fail.
+#     Moreover, when QEMU is in incoming migration state, migration
+#     parameter @local is set and @local-migration-supported is set,
+#     the following options are not supported and must not be set:
+#     @fd, @fds, @helper, @br, @ifname, @sndbuf, @vnet_hdr.
+#     Additionally in this case @script and @downscipt must be
+#     explicitly disabled (empty strings or "no").
+#     (Since 11.2)

Default?

Quoted 14 lines
qapi/net.json +3 -1
+#
 # Since: 1.2
 ##
 { 'struct': 'NetdevTapOptions',
@@ -453,7 +472,8 @@
     '*vhostfds':   'str',
     '*vhostforce': 'bool',
     '*queues':     'uint32',
-    '*poll-us':    'uint32'} }
+    '*poll-us':    'uint32',
+    '*local-migration-supported': 'bool' } }
 
 ##
 # @NetdevSocketOptions:
#26 lore raw

Re: [PATCH v19 13/15] net/tap: support local migration with virtio-net

Quoted 133 lines · Markus Armbruster
Quoted 113 lines · Vladimir Sementsov-Ogievskiy

Support transferring of TAP state (including open fd).

Add new property "local-migration-supported", which defines whether local-migration is actually supported for this TAP device. Starting from 11.2 QEMU Machine Types it's enabled by default.

Note that local-migration (including migrating opened FDs through migration channel, which must be UNIX socket) is enabled by global "local" migration parameters. But individual devices may have additional options to enable/disable it per device.

The tricky thing is that we need to know whether to call open/connect in TAP initialization code, i.e. we need to know the value of migration parameter "local" when creating the TAP device. For incoming migration, we can know only for TAP devices created with QMP after setting the migration parameter with QMP.

So the full picture is:

On source, to start outgoing "local" migration you need:

- migration parameter "local" set to true
- "local-migration-supported" TAP option set to true (the default, starting from 11.2 QEMU Machine Types)

If at least one of these options is not set, TAP backend doesn't participate in migration.

On target, things are more difficult:

Same, you need both "local" and "local-migration-supported" be set. And same, if one of them is not set, TAP backend is initialized as usual, and doesn't accept any incoming state.

Additionally, if you are going to set "local", it must be set before creating the TAP device. If TAP device created with "local" unset, it initializes as usual. If you enable "local" after it and start incoming migration, it will fail in .pre_load handler of TAP backend.

Moreover, there are interface restrictions: if you create TAP device when QEMU is in INCOMING state, and both "local" and "local-migration-supported" set, most of TAP options are not allowed, and script/downscript are required to be explicitly unset (set to "" or "no").

---
  net/tap.c     | 165 ++++++++++++++++++++++++++++++++++++++++++++++++--
  qapi/net.json |  22 ++++++-
  2 files changed, 180 insertions(+), 7 deletions(-)
net/tap.c +17 -0
index 2bd4b089573..4162820bcee 100644
@@ -38,12 +38,17 @@
  #include "monitor/monitor.h"
  #include "system/runstate.h"
  #include "system/system.h"
+#include "migration/misc.h"
  #include "qapi/error.h"
  #include "qemu/cutils.h"
  #include "qemu/error-report.h"
  #include "qemu/main-loop.h"
  #include "qemu/sockets.h"
  #include "hw/virtio/vhost.h"
+#include "hw/core/vmstate-if.h"
+#include "migration/vmstate.h"
+#include "qom/object.h"
+#include "qom/compat-properties.h"
 
  #include "net/tap.h"
  #include "net/util.h"
@@ -71,6 +76,8 @@ static const int kernel_feature_bits[] = {
 
  OBJECT_DECLARE_SIMPLE_TYPE(TAPState, TAP_NETDEV)
 
+static const VMStateDescription vmstate_tap;
+
  struct TAPState {
      Object parent_obj;
 
@@ -95,6 +102,7 @@ struct TAPState {
      int queue_index;
      bool read_poll_detached;
      VMChangeStateEntry *vmstate;
+    bool local_migration_supported;
  };
 
  static void launch_script(const char *setup_script, const char *ifname,
@@ -409,6 +417,8 @@ static void tap_cleanup(NetClientState *nc)
      tap_write_poll(s, false);
      close(s->fd);
      s->fd = -1;
+
+    vmstate_unregister(VMSTATE_IF(s), &vmstate_tap, s);
  }
 
  static void tap_poll(NetClientState *nc, bool enable)
@@ -445,6 +455,76 @@ static VHostNetState *tap_get_vhost_net(NetClientState *nc)
      return s->vhost_net;
  }
 
+static bool tap_is_wait_incoming(NetClientState *nc)
+{
+    TAPState *s = container_of(nc, TAPState, nc);
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
+    return s->fd == -1;
+}
+

net/tap.c static VHostNetState *tap_get_vhost_net(NetClientState *nc) · line 474

Quoted 10 lines
net/tap.c +10 -0
+static bool tap_pre_load(void *opaque, Error **errp)
+{
+    TAPState *s = opaque;
+
+    if (s->fd != -1) {
+        error_setg(errp,
+                   "TAP is already initialized and cannot receive "
+                   "incoming fd.  For local migration, 'local' "
+                   "migration parameter must be set _before_ "
+                   "creating TAP device.");

From error_setg()'s contract:

* The resulting message should be a single phrase, with no newline or
* trailing punctuation.

Suggest something like

Quoted 8 lines

error_setg(errp,
"TAP is already initialized and cannot receive " "incoming fd");
error_append_hint(errp,
"Migration parameter 'local' must be set" " _before_ creating the TAP device.");

Requires ERRP_GUARD().

Will follow this, thanks

Quoted 29 lines
Quoted 6 lines
net/tap.c +5 -0
+        return false;
+    }
+
+    return true;
+}

[...]

Quoted 20 lines
qapi/net.json +12 -0
index ada0329ef9d..d0d6e303b0d 100644
@@ -435,6 +435,25 @@
  # @poll-us: maximum number of microseconds that could be spent on busy
  #     polling for tap (since 2.7)
  #
+# @local-migration-supported: enable local migration for this TAP
+#     backend.  When set, local migration is enabled/disabled by
+#     migration parameter @local for this TAP backend.  When unset,
+#     migration parameter @local is ignored for this TAP backend.
+#     To be able to do incoming local migration of a TAP backend,
+#     migration parameter @local must be set _before_ creating the
+#     TAP backend.  Otherwise, TAP backend is initialized as usual,
+#     opening/creating TAP devices in kernel.  In this case further
+#     local incoming migration (with migration parameter @local set
+#     after creating TAP backend with @local-migration-supporeted
+#     parameter set) will simply fail.
+#     Moreover, when QEMU is in incoming migration state, migration
Quoted 9 lines

qapi/net.json line 455

Quoted 6 lines
qapi/net.json +6 -0
+#     parameter @local is set and @local-migration-supported is set,
+#     the following options are not supported and must not be set:
+#     @fd, @fds, @helper, @br, @ifname, @sndbuf, @vnet_hdr.
+#     Additionally in this case @script and @downscipt must be
+#     explicitly disabled (empty strings or "no").
+#     (Since 11.2)

Default?

Default is false now, no tricks with Machine Types. Will add.

Quoted 15 lines
Quoted 14 lines
qapi/net.json +3 -1
+#
  # Since: 1.2
  ##
  { 'struct': 'NetdevTapOptions',
@@ -453,7 +472,8 @@
      '*vhostfds':   'str',
      '*vhostforce': 'bool',
      '*queues':     'uint32',
-    '*poll-us':    'uint32'} }
+    '*poll-us':    'uint32',
+    '*local-migration-supported': 'bool' } }
 
  ##
  # @NetdevSocketOptions:
Signature · 2 lines
Best regards,
Vladimir
#27 lore raw

PATCH v19 14/15 tests/functional: add skipWithoutSudo() decorator

In reply to Vladimir Sementsov-Ogievskiy

To be used in the next commit: that would be a test for TAP networking, and it will need to setup TAP device.

---
 tests/functional/qemu_test/decorators.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tests/functional/qemu_test/decorators.py +16 -0
index fcf236ecfdf..aa135acc785 100644
@@ -6,6 +6,7 @@
 import os
 import platform
 import resource
+import subprocess
 from unittest import skipIf, skipUnless
 
 from .cmd import which
@@ -177,3 +178,18 @@ def skipLockedMemoryTest(locked_memory):
         ulimit_memory == resource.RLIM_INFINITY or ulimit_memory >= locked_memory * 1024,
         f'Test required {locked_memory} kB of available locked memory',
     )
+
+'''
+Decorator to skip execution of a test if passwordless
+sudo command is not available.
+'''
+def skipWithoutSudo():
+    proc = subprocess.run(["sudo", "-n", "/bin/true"],
+                          stdin=subprocess.PIPE,
+                          stdout=subprocess.PIPE,
+                          stderr=subprocess.STDOUT,
+                          universal_newlines=True,
+                          check=False)
+
+    return skipUnless(proc.returncode == 0,
+                      f'requires password-less sudo access: {proc.stdout}')
Signature · 1 line
2.43.0
#28 lore raw

PATCH v19 15/15 tests/functional: add test_tap_migration

In reply to Vladimir Sementsov-Ogievskiy

Add test for a new local-migration migration of virtio-net/tap, with fd passing through UNIX socket.

---
 tests/functional/x86_64/meson.build           |   1 +
 tests/functional/x86_64/test_tap_migration.py | 455 ++++++++++++++++++
 2 files changed, 456 insertions(+)
 create mode 100755 tests/functional/x86_64/test_tap_migration.py
tests/functional/x86_64/meson.build +1 -0
index 27b31f2e966..eaf2ec0005a 100644
@@ -47,4 +47,5 @@ tests_x86_64_system_thorough = [
   'virtio_balloon',
   'virtio_gpu',
   'rebuild_vmfd',
+  'tap_migration',
 ]
tests/functional/x86_64/test_tap_migration.py new file +455 -0

455 lines not on this page · raw message

Signature · 1 line
2.43.0
#30 lore raw
Quoted 10 lines · Ben
Quoted 5 lines · On 7/14/26, 11:43 AM, "Vladimir Sementsov-Ogievskiy"…

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

Quoted 7 lines

I've gone through this patch set again. I had a few minor questions that I'll send inline, but overall LGTM!

Thanks,
Ben

Thanks!

Signature · 2 lines
Best regards,
Vladimir
#31 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

/mjt

#32 lore raw
Quoted 22 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

Quoted 5 lines

I wonder what's the use for this at yandex?

Thanks,

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

#33 lore raw
Quoted 23 lines · Michael S. Tsirkin
Quoted 22 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

Quoted 8 lines
Quoted 5 lines

I wonder what's the use for this at yandex?

Thanks,

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#34 lore raw
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

Right, IIUC all similar single-host migrations like this series or CPR (or anything else...) should always need to enable x-ignore-shared in the first place. That's almost always the starting point of optimizing local migrations.. no matter how the memory will be shared (by the same pool of page cache, or persisted over kexec, etc.).

Thanks,

Signature · 1 line
Peter Xu
#35 lore raw
Quoted 38 lines · Peter Xu
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

Quoted 6 lines

Right, IIUC all similar single-host migrations like this series or CPR (or anything else...) should always need to enable x-ignore-shared in the first place. That's almost always the starting point of optimizing local migrations.. no matter how the memory will be shared (by the same pool of page cache, or persisted over kexec, etc.).

Yes, sharing RAM between source and target + enabling x-ignore-shared is a first thing to do.

This series optimizes TAP recreating. Not only skip recreating but also allow to exclude cloud-networking component form live-update entirely, making the process simpler (less components involved), and as I already said, reducing corresponding downtime.

Signature · 2 lines
Best regards,
Vladimir
#36 lore raw
Quoted 46 lines · Vladimir Sementsov-Ogievskiy
Quoted 38 lines · Peter Xu
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

Quoted 6 lines

Right, IIUC all similar single-host migrations like this series or CPR (or anything else...) should always need to enable x-ignore-shared in the first place. That's almost always the starting point of optimizing local migrations.. no matter how the memory will be shared (by the same pool of page cache, or persisted over kexec, etc.).

Quoted 10 lines

Yes, sharing RAM between source and target + enabling x-ignore-shared is a first thing to do.

This series optimizes TAP recreating. Not only skip recreating but also allow to exclude cloud-networking component form live-update entirely, making the process simpler (less components involved), and as I already said, reducing corresponding downtime.

Signature · 2 lines
Best regards,
Vladimir

So can you explain, how is this better than
1. a persistent tap
2. a non persistent tap that some server gets a hold of

IOW why does qemu need to bother.

Signature · 1 line
MST
#37 lore raw
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Vladimir Sementsov-Ogievskiy
Quoted 38 lines · Peter Xu
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

Quoted 6 lines

Right, IIUC all similar single-host migrations like this series or CPR (or anything else...) should always need to enable x-ignore-shared in the first place. That's almost always the starting point of optimizing local migrations.. no matter how the memory will be shared (by the same pool of page cache, or persisted over kexec, etc.).

Yes, sharing RAM between source and target + enabling x-ignore-shared is a first thing to do.

This series optimizes TAP recreating. Not only skip recreating but also allow to exclude cloud-networking component form live-update entirely, making the process simpler (less components involved), and as I already said, reducing corresponding downtime.

Quoted 6 lines
Quoted 3 lines
Signature · 2 lines
Best regards,
Vladimir

So can you explain, how is this better than
1. a persistent tap

You mean open same tap device both on source and target?

This will require some additional steps anyway, to avoid packet loss, like keeping queues disabled on target until post_load.

Another thing is MAX_TAP_QUEUES=256 in kernel: this is a problem, if you have more than 128 queues already opened on source. Seems cleaner just pass already opened queues to the target.

And finally, on hosts with many CPUs, TAP queue allocate noticeable amount of RAM, so having x2 queues during migration would be an overhead.

Quoted 1 line

2. a non persistent tap that some server gets a hold of

You mean, just pass FDs externally, instead of using QEMUs migration stream? That's possible. But requires mgmt tool to store (or get from source) and pass these FDs. Requires mgmt to even know about these FDs. But why? QEMU already can pass FDs through migration for vfio devices (CPR), why is TAP worse?

Like with persistent tap, it will require some changes in Qemu anyway, to avoid packet loss (like patch 12/15 here).

Quoted 2 lines

IOW why does qemu need to bother.

QEMU owns the TAP fd and has full knowledge of its state. Pushing this responsibility to an external tool means the tool needs to understand QEMU internals just to pass an fd that QEMU already has. I think, that's a worse separation of concerns.

Of course, there are other ways to do TAP local migration. But looking at wider picture, where we want to migrate not only TAP, but also vfio devices (already implemented as CPR migration, but may be updated to use similar approach as in this series, to use one migration channel), vhost-user-blk (my another series in flight) and vhost-user-fs (not yet published), vhost-vsock migration ("[PATCH v3 0/7] migration/cpr: support vhost-vsock devices" in flight series), it seems a good generic approach: simply pass backends (including open FDs) to the target, not involving mgmt. Qemu has full knowledge about these FDs and owns the whole state. Migrating them in QEMU looks correct for me.

Signature · 2 lines
Best regards,
Vladimir
#38 lore raw
Quoted 67 lines · Vladimir Sementsov-Ogievskiy
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Vladimir Sementsov-Ogievskiy
Quoted 38 lines · Peter Xu
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

Quoted 6 lines

Right, IIUC all similar single-host migrations like this series or CPR (or anything else...) should always need to enable x-ignore-shared in the first place. That's almost always the starting point of optimizing local migrations.. no matter how the memory will be shared (by the same pool of page cache, or persisted over kexec, etc.).

Yes, sharing RAM between source and target + enabling x-ignore-shared is a first thing to do.

This series optimizes TAP recreating. Not only skip recreating but also allow to exclude cloud-networking component form live-update entirely, making the process simpler (less components involved), and as I already said, reducing corresponding downtime.

Quoted 6 lines
Quoted 3 lines
Signature · 2 lines
Best regards,
Vladimir

So can you explain, how is this better than
1. a persistent tap

You mean open same tap device both on source and target?

This will require some additional steps anyway, to avoid packet loss, like keeping queues disabled on target until post_load.

Quoted 6 lines

Another thing is MAX_TAP_QUEUES=256 in kernel: this is a problem, if you have more than 128 queues already opened on source. Seems cleaner just pass already opened queues to the target.

And finally, on hosts with many CPUs, TAP queue allocate noticeable amount of RAM, so having x2 queues during migration would be an overhead.

ah I forgot. yes queues do get

Quoted 5 lines
Quoted 1 line

2. a non persistent tap that some server gets a hold of

You mean, just pass FDs externally, instead of using QEMUs migration stream? That's possible. But requires mgmt tool to store (or get from source) and pass these FDs. Requires mgmt to even know about these FDs.

e.g. libvirt already does, right? it creates them?

Quoted 2 lines

But why? QEMU already
can pass FDs through migration for vfio devices (CPR), why is TAP worse?

it's not that it's worse. it's that we are growing bespoke mechanisms so far. so if qemu gets tap fd on command line then what? how does that interact?

Quoted 2 lines

Like with persistent tap, it will require some changes in Qemu anyway, to avoid packet loss (like patch 12/15 here).

that one is more like a bugfix.

Quoted 7 lines
Quoted 2 lines

IOW why does qemu need to bother.

QEMU owns the TAP fd and has full knowledge of its state. Pushing this responsibility to an external tool means the tool needs to understand QEMU internals just to pass an fd that QEMU already has. I think, that's a worse separation of concerns.

Quoted 9 lines

Of course, there are other ways to do TAP local migration. But looking at wider picture, where we want to migrate not only TAP, but also vfio devices (already implemented as CPR migration, but may be updated to use similar approach as in this series, to use one migration channel), vhost-user-blk (my another series in flight) and vhost-user-fs (not yet published), vhost-vsock migration ("[PATCH v3 0/7] migration/cpr: support vhost-vsock devices" in flight series), it seems a good generic approach: simply pass backends (including open FDs) to the target, not involving mgmt. Qemu has full knowledge about these FDs and owns the whole state. Migrating them in QEMU looks correct for me.

if you find a way to generalize things and reuse them for your purposes without intrusive changes all over qemu, fine.

But this one is poking as far as frontend code even.

Quoted 3 lines
Signature · 2 lines
Best regards,
Vladimir
#39 lore raw
Quoted 77 lines · Michael S. Tsirkin
Quoted 67 lines · Vladimir Sementsov-Ogievskiy
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Vladimir Sementsov-Ogievskiy
Quoted 38 lines · Peter Xu
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

Quoted 6 lines

Right, IIUC all similar single-host migrations like this series or CPR (or anything else...) should always need to enable x-ignore-shared in the first place. That's almost always the starting point of optimizing local migrations.. no matter how the memory will be shared (by the same pool of page cache, or persisted over kexec, etc.).

Yes, sharing RAM between source and target + enabling x-ignore-shared is a first thing to do.

This series optimizes TAP recreating. Not only skip recreating but also allow to exclude cloud-networking component form live-update entirely, making the process simpler (less components involved), and as I already said, reducing corresponding downtime.

Quoted 6 lines
Quoted 3 lines
Signature · 2 lines
Best regards,
Vladimir

So can you explain, how is this better than
1. a persistent tap

You mean open same tap device both on source and target?

This will require some additional steps anyway, to avoid packet loss, like keeping queues disabled on target until post_load.

Quoted 6 lines

Another thing is MAX_TAP_QUEUES=256 in kernel: this is a problem, if you have more than 128 queues already opened on source. Seems cleaner just pass already opened queues to the target.

And finally, on hosts with many CPUs, TAP queue allocate noticeable amount of RAM, so having x2 queues during migration would be an overhead.

ah I forgot. yes queues do get

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

2. a non persistent tap that some server gets a hold of

You mean, just pass FDs externally, instead of using QEMUs migration stream? That's possible. But requires mgmt tool to store (or get from source) and pass these FDs. Requires mgmt to even know about these FDs.

e.g. libvirt already does, right? it creates them?

Not sure. But even if it creates and passes them to QEMU. Does it store them? Libvirt may restart, and it shouldn't break further migration.

So, we'll need also an API to get FDs from QEMU. To get FDs from QEMU just to pass them to target QEMU - I don't think it's more clear solution.

Quoted 7 lines
Quoted 3 lines

But why? QEMU already
can pass FDs through migration for vfio devices (CPR), why is TAP worse?

it's not that it's worse. it's that we are growing bespoke mechanisms so far. so if qemu gets tap fd on command line then what? how does that interact?

Do you mean how this series handles that case? No problem: given on source from command line FDs will migrate to the target the same way. Or I don't understand the question.

Quoted 23 lines
Quoted 3 lines

Like with persistent tap, it will require some changes in Qemu anyway, to avoid packet loss (like patch 12/15 here).

that one is more like a bugfix.

Quoted 7 lines
Quoted 2 lines

IOW why does qemu need to bother.

QEMU owns the TAP fd and has full knowledge of its state. Pushing this responsibility to an external tool means the tool needs to understand QEMU internals just to pass an fd that QEMU already has. I think, that's a worse separation of concerns.

Quoted 9 lines

Of course, there are other ways to do TAP local migration. But looking at wider picture, where we want to migrate not only TAP, but also vfio devices (already implemented as CPR migration, but may be updated to use similar approach as in this series, to use one migration channel), vhost-user-blk (my another series in flight) and vhost-user-fs (not yet published), vhost-vsock migration ("[PATCH v3 0/7] migration/cpr: support vhost-vsock devices" in flight series), it seems a good generic approach: simply pass backends (including open FDs) to the target, not involving mgmt. Qemu has full knowledge about these FDs and owns the whole state. Migrating them in QEMU looks correct for me.

Quoted 2 lines

if you find a way to generalize things and reuse them for your purposes without intrusive changes all over qemu, fine.

That's not only my purposes (i.e., as I understand, not only Yandex use case). Originally the work was started by Oracle (CPR), and I see interest from other companies too.

Quoted 3 lines

But this one is poking as far as frontend code even.

You mean "[PATCH v19 11/15] virtio-net: support local migration of backend" ?

CPR-approach avoids it, because FDs are passed _before_ any devices created on target. Is that better? In this way I don't really like the fact that we start to use (call some ioctls) in target QEMU the FDs, which are still actively used in running source QEMU . I don't like it, but that works, and I started working on live-migration on TAP from CPR tap series by Steve. Still, such approach doesn't work with vhost-user-blk, as trying to share (even for initialization) the fd between source and running target may just break things. So I decided to move to similar approach for both net and storage. Do you think it's better to return to CPR-approach for TAP (accepting that it won't generalize to vhost-user) like in
"[PATCH v4 0/8] Live update: tap and vhost" -
https://lore.kernel.org/qemu-devel/[email protected]/ - where both approaches were compared and mine was preferred?

Signature · 2 lines
Best regards,
Vladimir
#40 lore raw
Quoted 96 lines · Vladimir Sementsov-Ogievskiy
Quoted 77 lines · Michael S. Tsirkin
Quoted 67 lines · Vladimir Sementsov-Ogievskiy
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Vladimir Sementsov-Ogievskiy
Quoted 38 lines · Peter Xu
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

Quoted 6 lines

Right, IIUC all similar single-host migrations like this series or CPR (or anything else...) should always need to enable x-ignore-shared in the first place. That's almost always the starting point of optimizing local migrations.. no matter how the memory will be shared (by the same pool of page cache, or persisted over kexec, etc.).

Yes, sharing RAM between source and target + enabling x-ignore-shared is a first thing to do.

This series optimizes TAP recreating. Not only skip recreating but also allow to exclude cloud-networking component form live-update entirely, making the process simpler (less components involved), and as I already said, reducing corresponding downtime.

Quoted 6 lines
Quoted 3 lines
Signature · 2 lines
Best regards,
Vladimir

So can you explain, how is this better than
1. a persistent tap

You mean open same tap device both on source and target?

This will require some additional steps anyway, to avoid packet loss, like keeping queues disabled on target until post_load.

Quoted 6 lines

Another thing is MAX_TAP_QUEUES=256 in kernel: this is a problem, if you have more than 128 queues already opened on source. Seems cleaner just pass already opened queues to the target.

And finally, on hosts with many CPUs, TAP queue allocate noticeable amount of RAM, so having x2 queues during migration would be an overhead.

ah I forgot. yes queues do get

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

2. a non persistent tap that some server gets a hold of

You mean, just pass FDs externally, instead of using QEMUs migration stream? That's possible. But requires mgmt tool to store (or get from source) and pass these FDs. Requires mgmt to even know about these FDs.

e.g. libvirt already does, right? it creates them?

Not sure. But even if it creates and passes them to QEMU. Does it store them? Libvirt may restart, and it shouldn't break further migration.

So, we'll need also an API to get FDs from QEMU. To get FDs from QEMU just to pass them to target QEMU - I don't think it's more clear solution.

Quoted 4 lines
Quoted 3 lines

But why? QEMU already
can pass FDs through migration for vfio devices (CPR), why is TAP worse?

Quoted 6 lines
Quoted 3 lines

it's not that it's worse. it's that we are growing bespoke mechanisms so far. so if qemu gets tap fd on command line then what? how does that interact?

Do you mean how this series handles that case? No problem: given on source from command line FDs will migrate to the target the same way. Or I don't understand the question.

But right now target gives its own FDs.

Quoted 36 lines
Quoted 23 lines
Quoted 3 lines

Like with persistent tap, it will require some changes in Qemu anyway, to avoid packet loss (like patch 12/15 here).

that one is more like a bugfix.

Quoted 7 lines
Quoted 2 lines

IOW why does qemu need to bother.

QEMU owns the TAP fd and has full knowledge of its state. Pushing this responsibility to an external tool means the tool needs to understand QEMU internals just to pass an fd that QEMU already has. I think, that's a worse separation of concerns.

Quoted 9 lines

Of course, there are other ways to do TAP local migration. But looking at wider picture, where we want to migrate not only TAP, but also vfio devices (already implemented as CPR migration, but may be updated to use similar approach as in this series, to use one migration channel), vhost-user-blk (my another series in flight) and vhost-user-fs (not yet published), vhost-vsock migration ("[PATCH v3 0/7] migration/cpr: support vhost-vsock devices" in flight series), it seems a good generic approach: simply pass backends (including open FDs) to the target, not involving mgmt. Qemu has full knowledge about these FDs and owns the whole state. Migrating them in QEMU looks correct for me.

Quoted 2 lines

if you find a way to generalize things and reuse them for your purposes without intrusive changes all over qemu, fine.

That's not only my purposes (i.e., as I understand, not only Yandex use case). Originally the work was started by Oracle (CPR), and I see interest from other companies too.

Quoted 3 lines

But this one is poking as far as frontend code even.

You mean "[PATCH v19 11/15] virtio-net: support local migration of backend" ?

Quoted 13 lines

CPR-approach avoids it, because FDs are passed _before_ any devices created on target. Is that better? In this way I don't really like the fact that we start to use (call some ioctls) in target QEMU the FDs, which are still actively used in running source QEMU . I don't like it, but that works, and I started working on live-migration on TAP from CPR tap series by Steve. Still, such approach doesn't work with vhost-user-blk, as trying to share (even for initialization) the fd between source and running target may just break things. So I decided to move to similar approach for both net and storage. Do you think it's better to return to CPR-approach for TAP (accepting that it won't generalize to vhost-user) like in
"[PATCH v4 0/8] Live update: tap and vhost" -
https://lore.kernel.org/qemu-devel/[email protected]/ - where both approaches were compared and mine was preferred?

Hmm. Can CPR use yours?

Quoted 4 lines
Signature · 3 lines
-- 
Best regards,
Vladimir
#41 lore raw
Quoted 97 lines · Michael S. Tsirkin
Quoted 96 lines · Vladimir Sementsov-Ogievskiy
Quoted 77 lines · Michael S. Tsirkin
Quoted 67 lines · Vladimir Sementsov-Ogievskiy
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Vladimir Sementsov-Ogievskiy
Quoted 38 lines · Peter Xu
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Michael S. Tsirkin
Quoted 26 lines · Michael Tokarev
Quoted 11 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set, - is this really worth the effort to do all this just for *local* migration? What's the possible use case for this in real, - am I right this is just about upgrading the host qemu? And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

Thanks,

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

/mjt

Well just theoretically, imagine a big VM, reserving twice the amount of memory just to migrate is not nice at all.

Don't we already have the ability to skip memory transfer by setting the "x-ignore-shared" capability, assuming the VM RAM has a shared memory backing.

Quoted 6 lines

Right, IIUC all similar single-host migrations like this series or CPR (or anything else...) should always need to enable x-ignore-shared in the first place. That's almost always the starting point of optimizing local migrations.. no matter how the memory will be shared (by the same pool of page cache, or persisted over kexec, etc.).

Yes, sharing RAM between source and target + enabling x-ignore-shared is a first thing to do.

This series optimizes TAP recreating. Not only skip recreating but also allow to exclude cloud-networking component form live-update entirely, making the process simpler (less components involved), and as I already said, reducing corresponding downtime.

Quoted 6 lines
Quoted 3 lines
Signature · 2 lines
Best regards,
Vladimir

So can you explain, how is this better than
1. a persistent tap

You mean open same tap device both on source and target?

This will require some additional steps anyway, to avoid packet loss, like keeping queues disabled on target until post_load.

Quoted 6 lines

Another thing is MAX_TAP_QUEUES=256 in kernel: this is a problem, if you have more than 128 queues already opened on source. Seems cleaner just pass already opened queues to the target.

And finally, on hosts with many CPUs, TAP queue allocate noticeable amount of RAM, so having x2 queues during migration would be an overhead.

ah I forgot. yes queues do get

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

2. a non persistent tap that some server gets a hold of

You mean, just pass FDs externally, instead of using QEMUs migration stream? That's possible. But requires mgmt tool to store (or get from source) and pass these FDs. Requires mgmt to even know about these FDs.

e.g. libvirt already does, right? it creates them?

Not sure. But even if it creates and passes them to QEMU. Does it store them? Libvirt may restart, and it shouldn't break further migration.

So, we'll need also an API to get FDs from QEMU. To get FDs from QEMU just to pass them to target QEMU - I don't think it's more clear solution.

Quoted 4 lines
Quoted 3 lines

But why? QEMU already
can pass FDs through migration for vfio devices (CPR), why is TAP worse?

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

it's not that it's worse. it's that we are growing bespoke mechanisms so far. so if qemu gets tap fd on command line then what? how does that interact?

Do you mean how this series handles that case? No problem: given on source from command line FDs will migrate to the target the same way. Or I don't understand the question.

But right now target gives its own FDs.

You can't start local incoming migration of TAP and also pass FDs (by fd= or fds=), that's checked in 13/15.

Quoted 51 lines
Quoted 37 lines
Quoted 24 lines
Quoted 4 lines

Like with persistent tap, it will require some changes in Qemu anyway, to avoid packet loss (like patch 12/15 here).

that one is more like a bugfix.

Quoted 7 lines
Quoted 2 lines

IOW why does qemu need to bother.

QEMU owns the TAP fd and has full knowledge of its state. Pushing this responsibility to an external tool means the tool needs to understand QEMU internals just to pass an fd that QEMU already has. I think, that's a worse separation of concerns.

Quoted 9 lines

Of course, there are other ways to do TAP local migration. But looking at wider picture, where we want to migrate not only TAP, but also vfio devices (already implemented as CPR migration, but may be updated to use similar approach as in this series, to use one migration channel), vhost-user-blk (my another series in flight) and vhost-user-fs (not yet published), vhost-vsock migration ("[PATCH v3 0/7] migration/cpr: support vhost-vsock devices" in flight series), it seems a good generic approach: simply pass backends (including open FDs) to the target, not involving mgmt. Qemu has full knowledge about these FDs and owns the whole state. Migrating them in QEMU looks correct for me.

Quoted 2 lines

if you find a way to generalize things and reuse them for your purposes without intrusive changes all over qemu, fine.

That's not only my purposes (i.e., as I understand, not only Yandex use case). Originally the work was started by Oracle (CPR), and I see interest from other companies too.

Quoted 3 lines

But this one is poking as far as frontend code even.

You mean "[PATCH v19 11/15] virtio-net: support local migration of backend" ?

Quoted 13 lines

CPR-approach avoids it, because FDs are passed _before_ any devices created on target. Is that better? In this way I don't really like the fact that we start to use (call some ioctls) in target QEMU the FDs, which are still actively used in running source QEMU . I don't like it, but that works, and I started working on live-migration on TAP from CPR tap series by Steve. Still, such approach doesn't work with vhost-user-blk, as trying to share (even for initialization) the fd between source and running target may just break things. So I decided to move to similar approach for both net and storage. Do you think it's better to return to CPR-approach for TAP (accepting that it won't generalize to vhost-user) like in
"[PATCH v4 0/8] Live update: tap and vhost" -
https://lore.kernel.org/qemu-devel/[email protected]/ - where both approaches were compared and mine was preferred?

Quoted 2 lines

Hmm. Can CPR use yours?

Yes. For cpr-transfer, TAP will just migrate through main migration channel, like other (non-CPR) devices. For cpr-exec, Peter noted [1] that cpr-exec removes FD_CLOEXEC for passed fds. But for TAP FDs we don't set this flag, so it should work as is. And this series uses the same core mechanism to pass FDs as CPR (see load_fd() / save_fd() in migration/vmstate-types.c), which in the case of CPR_EXEC passes FDs simply as integers.

[1] https://lore.kernel.org/qemu-devel/[email protected]/

Signature · 2 lines
Best regards,
Vladimir
#42 lore raw
In reply to Michael Tokarev
Quoted 6 lines · Michael Tokarev
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

Quoted 8 lines
Quoted 6 lines

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set,

You probably haven't been following Steve's work (about 5 years) on CPR Live Update :) My patch set is small.

Quoted 3 lines

- is this really worth the effort to do
all this just for *local* migration?  What's the possible use case for this in real, - am I right this is just about upgrading the host qemu?

Exactly. You say "just for", but actually local migration is a lot more "massive" operation for us. Remote migrations are done mostly to release the physical server for service/redeploy (you should first migrate all the vms to other servers). That's a relatively seldom operation.

On the contrary, when updating to new QEMU version, you migrate _all_ vms on _all_ servers. These (minimal) downtimes affects all the customers, some are sensitive to freezes.

Quoted 8 lines

And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

I wonder what's the use for this at yandex?

This series together with similar about vhost-user-blk local migration gives several times win in freeze-time. It's significant for us.

Signature · 2 lines
Best regards,
Vladimir
#43 lore raw
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 6 lines · Michael Tokarev
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

Quoted 8 lines
Quoted 6 lines

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set,

You probably haven't been following Steve's work (about 5 years) on CPR Live Update :) My patch set is small.

Quoted 3 lines

- is this really worth the effort to do
all this just for *local* migration?  What's the possible use case for this in real, - am I right this is just about upgrading the host qemu?

Exactly. You say "just for", but actually local migration is a lot more "massive" operation for us. Remote migrations are done mostly to release the physical server for service/redeploy (you should first migrate all the vms to other servers). That's a relatively seldom operation.

On the contrary, when updating to new QEMU version, you migrate _all_ vms on _all_ servers. These (minimal) downtimes affects all the customers, some are sensitive to freezes.

Quoted 6 lines

And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

Quoted 9 lines
Quoted 2 lines

I wonder what's the use for this at yandex?

This series together with similar about vhost-user-blk local migration gives several times win in freeze-time. It's significant for us.

Signature · 2 lines
Best regards,
Vladimir

I believe it is.
But let's focus on what exactly are we saving here. It is not that clear.

Is it the overhead of tap losing state such as bridge forgetting the tap mac. Or what?

Signature · 1 line
MST
#44 lore raw
Quoted 50 lines · Michael S. Tsirkin
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 6 lines · Michael Tokarev
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

Quoted 8 lines
Quoted 6 lines

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set,

You probably haven't been following Steve's work (about 5 years) on CPR Live Update :) My patch set is small.

Quoted 3 lines

- is this really worth the effort to do
all this just for *local* migration?  What's the possible use case for this in real, - am I right this is just about upgrading the host qemu?

Exactly. You say "just for", but actually local migration is a lot more "massive" operation for us. Remote migrations are done mostly to release the physical server for service/redeploy (you should first migrate all the vms to other servers). That's a relatively seldom operation.

On the contrary, when updating to new QEMU version, you migrate _all_ vms on _all_ servers. These (minimal) downtimes affects all the customers, some are sensitive to freezes.

Quoted 6 lines

And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

Quoted 9 lines
Quoted 2 lines

I wonder what's the use for this at yandex?

This series together with similar about vhost-user-blk local migration gives several times win in freeze-time. It's significant for us.

Signature · 2 lines
Best regards,
Vladimir
Quoted 7 lines

I believe it is.
But let's focus on what exactly are we saving here. It is not that clear.

Is it the overhead of tap losing state such as bridge forgetting the tap mac. Or what?

I don't have a full expertize here, but the overhead is in switching to a new TAP in our cloud virtual networking component. Could this switching be optimized, to always work very fast? That's a good question that I don't have an answer to. Probably yes.

We decided to go another way: drop extra components from the process, and avoid any extra switching at all. Both cloud networking component, and storage (with vhost-usr-blk live-udpate series) don't even know, that QEMU is migrating. That seems to be a clear design for local migration, and shows good results.

Signature · 2 lines
Best regards,
Vladimir
#45 lore raw
Quoted 55 lines · Vladimir Sementsov-Ogievskiy
Quoted 54 lines · Michael S. Tsirkin
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 6 lines · Michael Tokarev
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Hi all!

Here is a migration for TAP net backend, including its properties and open fds.

Quoted 8 lines
Quoted 6 lines

With this new feature, management software doesn't need to initialize new TAP and do a switch to it. Nothing should be done around virtio-net in local migration: it just migrates and continues to use same TAP device. So we avoid extra logic in management software, extra allocations in kernel (for new TAP), and corresponding extra delay in migration downtime.

This is quite a big patch set,

You probably haven't been following Steve's work (about 5 years) on CPR Live Update :) My patch set is small.

Quoted 3 lines

- is this really worth the effort to do
all this just for *local* migration?  What's the possible use case for this in real, - am I right this is just about upgrading the host qemu?

Exactly. You say "just for", but actually local migration is a lot more "massive" operation for us. Remote migrations are done mostly to release the physical server for service/redeploy (you should first migrate all the vms to other servers). That's a relatively seldom operation.

On the contrary, when updating to new QEMU version, you migrate _all_ vms on _all_ servers. These (minimal) downtimes affects all the customers, some are sensitive to freezes.

Quoted 6 lines

And with that in mind, isn't it sufficient to use what we already have (namely, create new tap, start new qemu instance, and migrate the usual way), and tolerate some very minor downtime while the networking code learns the new network topology (isn't it happening almost instantly anyway, and if not, the management can help by sending gratitious ARP)?

Quoted 9 lines
Quoted 2 lines

I wonder what's the use for this at yandex?

This series together with similar about vhost-user-blk local migration gives several times win in freeze-time. It's significant for us.

Signature · 2 lines
Best regards,
Vladimir

I believe it is.
But let's focus on what exactly are we saving here. It is not that clear.

Quoted 6 lines
Quoted 3 lines

Is it the overhead of tap losing state such as bridge forgetting the tap mac. Or what?

I don't have a full expertize here, but the overhead is in switching to a new TAP in our cloud virtual networking component.

So what is wrong with
1. using a persistent TAP
or
2. starting a server and handing out these FDs?

Quoted 13 lines

Could this
switching be optimized, to always work very fast? That's a good question that I don't have an answer to. Probably yes.

We decided to go another way: drop extra components from the process, and avoid any extra switching at all. Both cloud networking component, and storage (with vhost-usr-blk live-udpate series) don't even know, that QEMU is migrating. That seems to be a clear design for local migration, and shows good results.

Signature · 2 lines
Best regards,
Vladimir