From nobody Thu Oct 31 00:18:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1722282699681696.4566172501438; Mon, 29 Jul 2024 12:51:39 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7E43793A; Mon, 29 Jul 2024 15:51:38 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BC334137B; Mon, 29 Jul 2024 15:49:48 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DD6C61258; Mon, 29 Jul 2024 15:49:42 -0400 (EDT) Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 05D681231 for ; Mon, 29 Jul 2024 15:49:42 -0400 (EDT) Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5af6a1afa63so3437204a12.0 for ; Mon, 29 Jul 2024 12:49:41 -0700 (PDT) Received: from localhost.localdomain ([2001:4bb8:181:247f:e288:8f76:5999:3]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac6339bcb3sm6121862a12.5.2024.07.29.12.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 12:49:40 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1722282581; x=1722887381; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MbspqfRAMni4ZrOVX2T2bpeKTR5VPEboLHWzVhpTUu4=; b=UuY4Oq3krrkaUOHHKcK8c3KpMHFaxzLC/tugyrJbWNvPUGUNQUE0LxXJ6GtPt/kEzk xXlvYOvQT6lpD7IRNz5lGnhy1wlF/VPWbVRjl/EZZvNSa9bfLBC1wWUN7w3GsSY58iLH wKO5sSTiEATiN3PzcdCeL2KQb6HCrDJmRMxtmrXIMVugzXoKFzwx6drIs+XZJwasZh9w 2Eh/fnMmRnMpHZgUxVyB+fQn8/wCiEmTCZsiLVLF9zEReYVhG3IIS2GNlaRAepipZAr5 7fEZsRCUnYl9jLoM6UXsu7iByTudpXzc4XVF5DrEzo1l7NUfr2B5oZTDziGza2q8Br0O yafQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722282581; x=1722887381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MbspqfRAMni4ZrOVX2T2bpeKTR5VPEboLHWzVhpTUu4=; b=l9Ksg7usWuzRNFDeoMUU55gNGjBLa/hCS3zwsKAfOnQzzVzIom/IHfk91lYi5Go8gh j2Bssb+f8T/STMJcfLNHFYywOatSpCGNQzgdCdZpm03n0jwdwjTXNxh/fyN5E2lE1k3G z44I4aiyB7h7qX05DceP6lpAbU1qpe2D5e4UHM0TwTCy94LzWcSV6xZKqwMPTxbxIoD6 Rn8kIUVEi61VQkz4NcdBhr2YWbE7C1HvMDLw4PCNOlNgse+um4XMko3F0Y2kjJ8mO3sX JLP/mBVYbngBmVtlPIVxEVQNbLL1kP2tSpts1u1+hOkghZ+Fz697G5dR8QfO2fjfHZUO T6FA== X-Gm-Message-State: AOJu0Yxf6jAcYR7550tNxm7Y35CslVPc0Sm6dmwAXTPm7nVUYTz207uy CA7GmFT1JidDX8eMMswGJrNvIjQnw8v5lLNLw6auuJb/HpL9v9jeVBvPU6Qo/fq8yb2pzhB+Kpg p X-Google-Smtp-Source: AGHT+IGObliuCMAp1g8YrvFEtUad1pAWZd9wKeU8uo+LrjCChoZ9RoEVX6rZWJwDi0VbZX3ldxFYXw== X-Received: by 2002:a50:d5c5:0:b0:5a2:4d19:4c08 with SMTP id 4fb4d7f45d1cf-5b021756bcdmr5104480a12.11.1722282580596; Mon, 29 Jul 2024 12:49:40 -0700 (PDT) From: Andrew Melnychenko To: devel@lists.libvirt.org Subject: [RFC PATCH v4 4/5] qemu_command: Added "ebpf_rss_fds" support for virtio-net. Date: Mon, 29 Jul 2024 23:48:52 +0200 Message-ID: <20240729214853.458886-5-andrew@daynix.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240729214853.458886-1-andrew@daynix.com> References: <20240729214853.458886-1-andrew@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4762WCMSUQ5DTQPPKBZDUWXQCA5MEHZO X-Message-ID-Hash: 4762WCMSUQ5DTQPPKBZDUWXQCA5MEHZO X-MailFrom: andrew@daynix.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: yuri.benditovich@daynix.com, yan@daynix.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1722282701500116600 Content-Type: text/plain; charset="utf-8" Added new capability ebpf_rss_fds for QEMU. Added logic for loading the "RSS" eBPF program. eBPF file descriptors passed to the QEMU. Signed-off-by: Andrew Melnychenko --- src/qemu/qemu_capabilities.c | 2 + src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 60 +++++++++++++++++++ src/qemu/qemu_domain.c | 4 ++ src/qemu/qemu_domain.h | 3 + .../caps_9.0.0_x86_64.xml | 1 + .../caps_9.1.0_x86_64.xml | 1 + 7 files changed, 72 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2d2603e519..1191f96bec 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -713,6 +713,7 @@ VIR_ENUM_IMPL(virQEMUCaps, "sev-snp-guest", /* QEMU_CAPS_SEV_SNP_GUEST */ "netdev.user", /* QEMU_CAPS_NETDEV_USER */ "acpi-erst", /* QEMU_CAPS_DEVICE_ACPI_ERST */ + "virtio-net.ebpf_rss_fds", /* QEMU_CAPS_VIRTIO_NET_EBPF_RSS_= FDS */ ); =20 =20 @@ -1454,6 +1455,7 @@ static struct virQEMUCapsDevicePropsFlags virQEMUCaps= DevicePropsVirtioBlk[] =3D { static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioNet[= ] =3D { { "acpi-index", QEMU_CAPS_ACPI_INDEX, NULL }, { "rss", QEMU_CAPS_VIRTIO_NET_RSS, NULL }, + { "ebpf-rss-fds", QEMU_CAPS_VIRTIO_NET_EBPF_RSS_FDS, NULL }, }; =20 static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsPCIeRootPo= rt[] =3D { diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 2c53236132..4af5e657e4 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -692,6 +692,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_SEV_SNP_GUEST, /* -object sev-snp-guest */ QEMU_CAPS_NETDEV_USER, /* -netdev user */ QEMU_CAPS_DEVICE_ACPI_ERST, /* -device acpi-erst */ + QEMU_CAPS_VIRTIO_NET_EBPF_RSS_FDS, /* virtio-net ebpf_rss_fds feature = */ =20 QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f15e6bda1e..570bc9d1e6 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3806,6 +3806,25 @@ qemuBuildLegacyNicStr(virDomainNetDef *net) } =20 =20 +static virJSONValue * +qemuBuildEbpfRssArg(virDomainNetDef *net) +{ + qemuDomainNetworkPrivate *netpriv =3D QEMU_DOMAIN_NETWORK_PRIVATE(net); + g_autoptr(virJSONValue) props =3D NULL; + GSList *n; + + if (!netpriv->ebpfrssfds) + return NULL; + + props =3D virJSONValueNewArray(); + for (n =3D netpriv->ebpfrssfds; n; n =3D n->next) { + virJSONValueArrayAppendString(props, qemuFDPassDirectGetPath(n->da= ta)); + } + + return g_steal_pointer(&props); +} + + virJSONValue * qemuBuildNicDevProps(virDomainDef *def, virDomainNetDef *net, @@ -3820,6 +3839,7 @@ qemuBuildNicDevProps(virDomainDef *def, virTristateSwitch mq =3D VIR_TRISTATE_SWITCH_ABSENT; unsigned long long vectors =3D 0; virTristateSwitch failover =3D VIR_TRISTATE_SWITCH_ABSENT; + g_autoptr(virJSONValue) ebpffds =3D NULL; =20 switch (net->driver.virtio.txmode) { case VIR_DOMAIN_NET_VIRTIO_TX_MODE_IOTHREAD: @@ -3864,6 +3884,8 @@ qemuBuildNicDevProps(virDomainDef *def, if (!(props =3D qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_NET, net= , qemuCaps))) return NULL; =20 + ebpffds =3D qemuBuildEbpfRssArg(net); + if (virJSONValueObjectAdd(&props, "S:tx", tx, "T:ioeventfd", net->driver.virtio.ioeven= tfd, @@ -3888,6 +3910,7 @@ qemuBuildNicDevProps(virDomainDef *def, "T:hash", net->driver.virtio.rss_hash_re= port, "p:host_mtu", net->mtu, "T:failover", failover, + "A:ebpf-rss-fds", &ebpffds, NULL) < 0) return NULL; } else { @@ -4171,6 +4194,38 @@ qemuBuildWatchdogDevProps(const virDomainDef *def, } =20 =20 +static void +qemuOpenEbpfRssFds(virDomainNetDef *net, + virQEMUCaps *qemuCaps) +{ + const char *ebpfRSSObject =3D NULL; + int fds[16]; + int nfds =3D 0; + size_t i =3D 0; + qemuDomainNetworkPrivate *netpriv =3D QEMU_DOMAIN_NETWORK_PRIVATE(net); + + /* Add ebpf values */ + if (net->driver.virtio.rss =3D=3D VIR_TRISTATE_SWITCH_ON + && net->driver.virtio.rss_hash_report !=3D VIR_TRISTATE_SWITCH_ON + && virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_EBPF_RSS_FDS)) { + ebpfRSSObject =3D virQEMUCapsGetEbpf(qemuCaps, "rss"); + nfds =3D qemuInterfaceLoadEbpf(ebpfRSSObject, &netpriv->libbpfRSSO= bject, fds, G_N_ELEMENTS(fds)); + + if (nfds <=3D 0) + return; + + for (i =3D 0; i < nfds; ++i) { + g_autofree char *name =3D g_strdup_printf("ebpfrssfd-%s-%zu", = net->info.alias, i); + + netpriv->ebpfrssfds =3D + g_slist_prepend(netpriv->ebpfrssfds, qemuFDPassDirectNew(n= ame, fds + i)); + } + + netpriv->ebpfrssfds =3D g_slist_reverse(netpriv->ebpfrssfds); + } +} + + static int qemuBuildWatchdogCommandLine(virCommand *cmd, const virDomainDef *def, @@ -8729,6 +8784,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver, g_autoptr(virJSONValue) hostnetprops =3D NULL; qemuDomainNetworkPrivate *netpriv =3D QEMU_DOMAIN_NETWORK_PRIVATE(net); GSList *n; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); =20 if (qemuDomainValidateActualNetDef(net, qemuCaps) < 0) return -1; @@ -8864,6 +8920,10 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver, qemuFDPassDirectTransferCommand(netpriv->slirpfd, cmd); qemuFDPassTransferCommand(netpriv->vdpafd, cmd); =20 + qemuOpenEbpfRssFds(net, qemuCaps); + for (n =3D netpriv->ebpfrssfds; n; n =3D n->next) + qemuFDPassDirectTransferCommand(n->data, cmd); + if (!(hostnetprops =3D qemuBuildHostNetProps(vm, net))) goto cleanup; =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 298f4bfb9e..a73f62fb44 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -38,6 +38,7 @@ #include "qemu_checkpoint.h" #include "qemu_validate.h" #include "qemu_namespace.h" +#include "qemu_interface.h" #include "viralloc.h" #include "virlog.h" #include "virerror.h" @@ -1085,6 +1086,7 @@ qemuDomainNetworkPrivateClearFDs(qemuDomainNetworkPri= vate *priv) g_clear_pointer(&priv->vdpafd, qemuFDPassFree); g_slist_free_full(g_steal_pointer(&priv->vhostfds), (GDestroyNotify) q= emuFDPassDirectFree); g_slist_free_full(g_steal_pointer(&priv->tapfds), (GDestroyNotify) qem= uFDPassDirectFree); + g_slist_free_full(g_steal_pointer(&priv->ebpfrssfds), (GDestroyNotify)= qemuFDPassDirectFree); } =20 =20 @@ -1096,6 +1098,8 @@ qemuDomainNetworkPrivateDispose(void *obj G_GNUC_UNUS= ED) qemuSlirpFree(priv->slirp); =20 qemuDomainNetworkPrivateClearFDs(priv); + + qemuInterfaceCloseEbpf(priv->libbpfRSSObject); } =20 =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index a5092dd7f0..3e0345c29d 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -435,6 +435,9 @@ struct _qemuDomainNetworkPrivate { GSList *tapfds; /* qemuFDPassDirect */ GSList *vhostfds; /* qemuFDPassDirect */ qemuFDPass *vdpafd; + + void *libbpfRSSObject; + GSList *ebpfrssfds; /* qemuFDPassDirect eBPF RSS fds from helper */ }; =20 =20 diff --git a/tests/qemucapabilitiesdata/caps_9.0.0_x86_64.xml b/tests/qemuc= apabilitiesdata/caps_9.0.0_x86_64.xml index dbe015d287..689402b472 100644 --- a/tests/qemucapabilitiesdata/caps_9.0.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_9.0.0_x86_64.xml @@ -207,6 +207,7 @@ + 9000000 43100245 v9.0.0 diff --git a/tests/qemucapabilitiesdata/caps_9.1.0_x86_64.xml b/tests/qemuc= apabilitiesdata/caps_9.1.0_x86_64.xml index b0c16a0440..74cf1db19c 100644 --- a/tests/qemucapabilitiesdata/caps_9.1.0_x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_9.1.0_x86_64.xml @@ -205,6 +205,7 @@ + 9000050 43100246 v9.0.0-1388-g80e8f06021-dirty --=20 2.45.2