[PATCH] qemu: command: Don't attempt to set backend MTU for networks which don't use host backend directly

Peter Krempa via Devel posted 1 patch 3 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/c23621672e084ae8c13923cf76f8d3be6d8e8e0a.1748876430.git.pkrempa@redhat.com
src/qemu/qemu_command.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] qemu: command: Don't attempt to set backend MTU for networks which don't use host backend directly
Posted by Peter Krempa via Devel 3 months, 1 week ago
From: Peter Krempa <pkrempa@redhat.com>

Attempting to set MTU for network types which don't actually use the
network device on the host results in a failure. The 'mtu' property is
also used e.g. for the 'host_mtu' property of e.g. 'virtio-net-pci'
which is applied even in vhost-user mode.

Use the existing switch which selects devices without a network device
backend on the host side and skip setting the MTU.

Tested by running 'passt' in vhost-user mode manually:

 passt -f --vhost-user -s /tmp/vh.sock

and the following XML:

 <interface type="vhostuser">
   <mac address="52:54:00:3d:91:97"/>
   <source type="unix" path="/tmp/vh.sock" mode="client"/>
   <model type="virtio"/>
   <mtu size="9999"/>
   <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
 </interface>

The OS in the guest reports MTU 9999.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/717
Closes: https://gitlab.com/libvirt/libvirt/-/issues/192
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_command.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index fec48edfc1..edafe1588c 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8713,6 +8713,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
     bool requireNicdev = false;
     g_autoptr(virJSONValue) hostnetprops = NULL;
     qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
+    bool setBackendMTU = true;
     GSList *n;

     if (qemuDomainValidateActualNetDef(net, qemuCaps) < 0)
@@ -8802,6 +8803,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
     case VIR_DOMAIN_NET_TYPE_NULL:
     case VIR_DOMAIN_NET_TYPE_VDS:
     case VIR_DOMAIN_NET_TYPE_LAST:
+        setBackendMTU = false;
        /* These types don't use a network device on the host, but
         * instead use some other type of connection to the emulated
         * device in the qemu process.
@@ -8842,7 +8844,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
         }
     }

-    if (net->mtu && net->managed_tap != VIR_TRISTATE_BOOL_NO &&
+    if (net->mtu && setBackendMTU && net->managed_tap != VIR_TRISTATE_BOOL_NO &&
         virNetDevSetMTU(net->ifname, net->mtu) < 0)
         goto cleanup;

-- 
2.49.0
Re: [PATCH] qemu: command: Don't attempt to set backend MTU for networks which don't use host backend directly
Posted by Laine Stump 3 months ago
On 6/2/25 11:00 AM, Peter Krempa via Devel wrote:
> From: Peter Krempa <pkrempa@redhat.com>
> 
> Attempting to set MTU for network types which don't actually use the
> network device on the host results in a failure. The 'mtu' property is
> also used e.g. for the 'host_mtu' property of e.g. 'virtio-net-pci'
> which is applied even in vhost-user mode.
> 
> Use the existing switch which selects devices without a network device
> backend on the host side and skip setting the MTU.

It's disturbing that this points out I had added the necessary code to 
add "--mtu" to the passt commandline when <mtu size='blah'/> was 
specified, but apparently had never tested it (because it would have 
failed) :-/

Anyway, on the upside, according to Stefano it's always best to leave 
mtu unspecified for passt interfaces, because it then defaults to some 
gigantic number that gives the best performance :-)

(Oh, BTW I built with and without your patch, with the expected results :-)
Re: [PATCH] qemu: command: Don't attempt to set backend MTU for networks which don't use host backend directly
Posted by Ján Tomko via Devel 3 months, 1 week ago
On a Monday in 2025, Peter Krempa via Devel wrote:
>From: Peter Krempa <pkrempa@redhat.com>
>
>Attempting to set MTU for network types which don't actually use the
>network device on the host results in a failure. The 'mtu' property is
>also used e.g. for the 'host_mtu' property of e.g. 'virtio-net-pci'
>which is applied even in vhost-user mode.
>
>Use the existing switch which selects devices without a network device
>backend on the host side and skip setting the MTU.
>
>Tested by running 'passt' in vhost-user mode manually:
>
> passt -f --vhost-user -s /tmp/vh.sock
>
>and the following XML:
>
> <interface type="vhostuser">
>   <mac address="52:54:00:3d:91:97"/>
>   <source type="unix" path="/tmp/vh.sock" mode="client"/>
>   <model type="virtio"/>
>   <mtu size="9999"/>
>   <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
> </interface>
>
>The OS in the guest reports MTU 9999.
>
>Closes: https://gitlab.com/libvirt/libvirt/-/issues/717
>Closes: https://gitlab.com/libvirt/libvirt/-/issues/192
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/qemu/qemu_command.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano