From 69e3381626106b08b907ddd33ce3eee6bb26bad3 Mon Sep 17 00:00:00 2001 From: Patrick Magauran Date: Sat, 8 Aug 2020 09:59:13 -0400 Subject: [PATCH] qemu: Add e1000e/vmxnet3 IFF_VNET_HDR support Setting IFF_VNET_HDR for a tap device passes the whole packet to the host, reducing emulation overhead and improving performance. Libvirt bases its decision about applying IFF_VNET_HDR to the tap interface on whether or not the model of the emulated network device is virtio. Originally, virtio was the only model to support IFF_VNET_HDR in QEMU; however, the e1000e & vmxnet3 adapters have also supported it since their introductions - QEMU commit 786fd2b0f87 for vmxnet3, and QEMU commit 6f3fbe4ed0 for e1000e, so it should be set for those models too. Signed-off-by: Patrick Magauran Reviewed-by: Daniel Henrique Barboza Reviewed-by: Laine Stump --- src/qemu/qemu_interface.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index ffec992596..10a87a2528 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -231,6 +231,15 @@ qemuInterfaceStopDevices(virDomainDefPtr def) } +static bool +qemuInterfaceIsVnetCompatModel(const virDomainNetDef *net) +{ + return (virDomainNetIsVirtioModel(net) || + net->model == VIR_DOMAIN_NET_MODEL_E1000E || + net->model == VIR_DOMAIN_NET_MODEL_VMXNET3); +} + + /** * qemuInterfaceDirectConnect: * @def: the definition of the VM (needed by 802.1Qbh and audit) @@ -255,7 +264,7 @@ qemuInterfaceDirectConnect(virDomainDefPtr def, virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP; - if (virDomainNetIsVirtioModel(net)) + if (qemuInterfaceIsVnetCompatModel(net)) macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR; if (virNetDevMacVLanCreateWithVPortProfile(net->ifname, @@ -417,7 +426,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, } } - if (virDomainNetIsVirtioModel(net)) + if (qemuInterfaceIsVnetCompatModel(net)) tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR; if (net->managed_tap == VIR_TRISTATE_BOOL_NO) { @@ -436,7 +445,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, if (virNetDevMacVLanTapOpen(net->ifname, tapfd, tapfdSize) < 0) goto cleanup; if (virNetDevMacVLanTapSetup(tapfd, tapfdSize, - virDomainNetIsVirtioModel(net)) < 0) { + qemuInterfaceIsVnetCompatModel(net)) < 0) { goto cleanup; } } else { @@ -559,7 +568,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, template_ifname = true; } - if (virDomainNetIsVirtioModel(net)) + if (qemuInterfaceIsVnetCompatModel(net)) tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR; if (driver->privileged) {