From nobody Sat Nov 23 14:30:33 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; 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 1715545061095851.4353529110606; Sun, 12 May 2024 13:17:41 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0A96A1B4E; Sun, 12 May 2024 16:17:40 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AFE731AC3; Sun, 12 May 2024 16:13:06 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C38241A50; Sun, 12 May 2024 16:12:49 -0400 (EDT) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 7B4EB1A50 for ; Sun, 12 May 2024 16:12:48 -0400 (EDT) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-41ff5e3dc3bso15434075e9.1 for ; Sun, 12 May 2024 13:12:48 -0700 (PDT) Received: from localhost.localdomain ([162.213.65.233]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42014f563adsm22354735e9.38.2024.05.12.13.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 13:12:46 -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=-1.0 required=5.0 tests=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 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715544767; x=1716149567; 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=HVuEFToeT/ylAzFxGoDbx3d+uCW9U2IVrzuDM+/4/8g=; b=OdzCNbAM9bztgqVEydxegb042qalV9EAMvhhf5ho91ebq3N7CiMd5s7JwaJnlfljjd m1RJIe0Ep0gNt60ZDDK/NvZuQIcsvLEWXO+i3koMlFnFGIq7dWb96OAF8K+FVwlEHjno ET4UkI/2o3rjCeGnm9lnpkyN5x1n9IUyHWgqbOYhoZrb/AAkaQR0+05WlhH9p+5dFWmN TDSJxu91xt7wEnNQ5uq3R0aVn9m+k1yW3zy/L+TuPuWtaXSgHLqp5edA0UvUONCvjKUS 1tQPv7i2Ch6Do7DzPSdcEGd+qJOOzmYMBZI+QOwCM/GRFzRn9BPjP0FLf9yzFh9bWTOa HCdQ== X-Gm-Message-State: AOJu0YySXuE1wl1vEoUDLqRusfvIjSje3LYQ/aHsHa8DRjVIdtWDiYhg aui0xtFsrcgXN3mZFocdnqVhdVA4+tuTWr2nYNvK1LSCEmZehu+xQOYtN551AIf6hVj2jNcG/Cj 6 X-Google-Smtp-Source: AGHT+IEDMrWWGrzm2Q+kQ+6oOHXt13YXYYnbmhX7+aG5a2PkStrVG2hs4k+8qXdkuzaWVX3/qKsiyQ== X-Received: by 2002:a05:600c:45cc:b0:41f:f592:2fa3 with SMTP id 5b1f17b1804b1-41ff5922fb3mr47461755e9.11.1715544767351; Sun, 12 May 2024 13:12:47 -0700 (PDT) From: Andrew Melnychenko To: devel@lists.libvirt.org Subject: [RFC PATCH v3 4/6] qemu_command: Added "ebpf_rss_fds" support for virtio-net. Date: Sun, 12 May 2024 22:45:46 +0300 Message-ID: <20240512194550.5023-5-andrew@daynix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240512194550.5023-1-andrew@daynix.com> References: <20240512194550.5023-1-andrew@daynix.com> MIME-Version: 1.0 Message-ID-Hash: XBESCTI3B4NVTN4KZSZN77HVZCKNZDIC X-Message-ID-Hash: XBESCTI3B4NVTN4KZSZN77HVZCKNZDIC 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1715545062184100001 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 | 4 +++ src/qemu/qemu_capabilities.h | 3 ++ src/qemu/qemu_command.c | 61 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.c | 4 +++ src/qemu/qemu_domain.h | 3 ++ 5 files changed, 75 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 09bb6ca36e..bb6a587725 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -708,6 +708,9 @@ VIR_ENUM_IMPL(virQEMUCaps, "usb-mtp", /* QEMU_CAPS_DEVICE_USB_MTP */ "machine.virt.ras", /* QEMU_CAPS_MACHINE_VIRT_RAS */ "virtio-sound", /* QEMU_CAPS_DEVICE_VIRTIO_SOUND */ + + /* 460 */ + "virtio-net.ebpf_rss_fds", /* QEMU_CAPS_VIRTIO_NET_EBPF_RSS_= FDS */ ); =20 =20 @@ -1452,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 371ea19bd0..e4bb137b21 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -688,6 +688,9 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_MACHINE_VIRT_RAS, /* -machine virt,ras=3D */ QEMU_CAPS_DEVICE_VIRTIO_SOUND, /* -device virtio-sound-* */ =20 + /* 460 */ + QEMU_CAPS_VIRTIO_NET_EBPF_RSS_FDS, /* virtio-net ebpf_rss_fds feature = */ + QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; =20 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9859ea67a4..77715cf6fe 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3805,6 +3805,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) + 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, @@ -3813,6 +3832,7 @@ qemuBuildNicDevProps(virDomainDef *def, g_autoptr(virJSONValue) props =3D NULL; char macaddr[VIR_MAC_STRING_BUFLEN]; g_autofree char *netdev =3D g_strdup_printf("host%s", net->info.alias); + g_autoptr(virJSONValue) ebpffds =3D NULL; =20 if (virDomainNetIsVirtioModel(net)) { const char *tx =3D NULL; @@ -3863,6 +3883,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, @@ -3887,6 +3909,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 { @@ -4170,6 +4193,39 @@ 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); + + netpriv->libbpfRSSObject =3D NULL; + netpriv->ebpfrssfds =3D NULL; + + /* 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, 16); + + if (nfds > 0) { + for (i =3D 0; i < nfds; ++i) { + g_autofree char *name =3D g_strdup_printf("ebpfrssfd-%s-%z= u", net->info.alias, i); + + netpriv->ebpfrssfds =3D + g_slist_prepend(netpriv->ebpfrssfds, qemuFDPassDirectN= ew(name, fds + i)); + } + } + + netpriv->ebpfrssfds =3D g_slist_reverse(netpriv->ebpfrssfds); + } +} + + static int qemuBuildWatchdogCommandLine(virCommand *cmd, const virDomainDef *def, @@ -8725,6 +8781,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; @@ -8860,6 +8917,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 bda62f2e5c..894a6af348 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" @@ -1079,6 +1080,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 @@ -1090,6 +1092,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 a3089ea449..d15789f9ac 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -434,6 +434,9 @@ struct _qemuDomainNetworkPrivate { GSList *tapfds; /* qemuFDPassDirect */ GSList *vhostfds; /* qemuFDPassDirect */ qemuFDPass *vdpafd; + + void *libbpfRSSObject; + GSList *ebpfrssfds; /* qemuFDPassDirect eBPF RSS fds from helper */ }; =20 =20 --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org