From nobody Thu Oct 31 00:19:08 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 1722282666977713.7516717741543; Mon, 29 Jul 2024 12:51:06 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B1ACC12B5; Mon, 29 Jul 2024 15:51:05 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0640B1373; Mon, 29 Jul 2024 15:49:47 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C97D6127F; Mon, 29 Jul 2024 15:49:41 -0400 (EDT) Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 049E81258 for ; Mon, 29 Jul 2024 15:49:41 -0400 (EDT) Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5af6a1afa7bso3526381a12.1 for ; Mon, 29 Jul 2024 12:49:40 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 12:49:39 -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=1722282580; x=1722887380; 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=s9oW95deZF+cVr/3fRi3p0VyrjEGRlnCPLHovdQXKS0=; b=zYYWYfPW+mkQC52VO56oBhAufrS07BoLNz6nIv6hCrzrr3wQB3wIO20GPf5eO15Xds S+Q2EmmFnikv2qge02VLPYMWAaPb9dEkvzo33ehdvMGMPvDy0tQgTScMIKQhpaFBn1LZ sXhG/jCZsc6pAeX+JAt3KkeVy3gIugCHsBH1a8Etd5WN15hVZJlNVldG9wMyYjtzzXKX 6/IOQ0dk509X18DvtYM9Q1WuefFx3AwWHj+saqmV0N9Et9wRC2fCXKxcCUZ2HSmsiF3R 0iVrUIkVV5Mwgf0Jwff+NQssI+Ibeq5rvTg7VmxodY9NK5LbLN61d3FyshsB/08aZ4a3 OQkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722282580; x=1722887380; 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=s9oW95deZF+cVr/3fRi3p0VyrjEGRlnCPLHovdQXKS0=; b=e48JCk/wUz16QIucgNFbENN3rvkKjRqPKkG4zK+36WLuPwEFrUpVRoaC1SvpUaGP2s ZaNF4KkBN2Zqr8cLG6M3Y3xK1OeYNcR+jIhDrVTjbI+tXsjqWFGwQtA2psz+nMN6kHrd WspfZr1tMkYwDyrdN3siEX9oD/TYPGC4c2mNipNxtovW8rGYDVw41gSYpcUwpVzqS1Te Dp/htDzuafS0nZyHIMhKYOHeV65WvZEwRYXx13e+KyZS55SpdlfGyKSpXh5XyDabuJBc GxN8wbdiVoi45mZ5Dew5bqF21IJD7QRu3PIXi9HWQABVqnQ5GilvcMHAzZcciT9Nd+wN 2DTA== X-Gm-Message-State: AOJu0YxZGMaA4J9M31GucIFZPgIWGGoSyg9+dV6cuoYAALVWeJazf7Eb MI9+3Oh+i/0dTBKD16ERlWl82nn61+n3cay+jX1Ir1cX9knHjkgEFm3QZUTo5jJOEWFiBnoSuUR Z X-Google-Smtp-Source: AGHT+IHfRIDY0aEdBvYM/CGHleR1/BlGMkWESTnqOo1fZp7kjl1SWO2Lcdn880hcibysr7dOIoJAuA== X-Received: by 2002:a50:c057:0:b0:5a1:e92b:acb5 with SMTP id 4fb4d7f45d1cf-5b0205d4d49mr5248999a12.11.1722282579672; Mon, 29 Jul 2024 12:49:39 -0700 (PDT) From: Andrew Melnychenko To: devel@lists.libvirt.org Subject: [RFC PATCH v4 3/5] qemu_interface: Added routine for loading the eBPF objects. Date: Mon, 29 Jul 2024 23:48:51 +0200 Message-ID: <20240729214853.458886-4-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: E36LOACFMXYXW76VXVIWUTSC5QF3WCM5 X-Message-ID-Hash: E36LOACFMXYXW76VXVIWUTSC5QF3WCM5 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: 1722282667399116600 Content-Type: text/plain; charset="utf-8" Also, added dependencies for libbpf with bpf option. Signed-off-by: Andrew Melnychenko --- libvirt.spec.in | 3 ++ meson.build | 7 ++++ meson_options.txt | 1 + src/qemu/meson.build | 1 + src/qemu/qemu_interface.c | 87 +++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_interface.h | 7 ++++ 6 files changed, 106 insertions(+) diff --git a/libvirt.spec.in b/libvirt.spec.in index 29101e74fe..9a27123487 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -366,6 +366,7 @@ BuildRequires: yajl-devel BuildRequires: sanlock-devel >=3D 2.4 %endif BuildRequires: libpcap-devel >=3D 1.5.0 +BuildRequires: libbpf-devel >=3D 1.1.0 BuildRequires: libnl3-devel BuildRequires: libselinux-devel # For modprobe @@ -1374,6 +1375,7 @@ export SOURCE_DATE_EPOCH=3D$(stat --printf=3D'%Y' %{_= specdir}/libvirt.spec) -Dlibpcap=3Denabled \ %{?arg_nbdkit} \ %{?arg_nbdkit_config_default} \ + -Dlibbpf=3Denabled \ -Dlibnl=3Denabled \ -Daudit=3Denabled \ -Ddtrace=3Denabled \ @@ -1444,6 +1446,7 @@ export SOURCE_DATE_EPOCH=3D$(stat --printf=3D'%Y' %{_= specdir}/libvirt.spec) -Dlibiscsi=3Ddisabled \ -Dnbdkit=3Ddisabled \ -Dnbdkit_config_default=3Ddisabled \ + -Dlibbpf=3Ddisabled \ -Dlibnl=3Ddisabled \ -Dlibpcap=3Ddisabled \ -Dlibssh2=3Ddisabled \ diff --git a/meson.build b/meson.build index 231470e2ee..0647fc74bf 100644 --- a/meson.build +++ b/meson.build @@ -1025,6 +1025,12 @@ else libkvm_dep =3D dependency('', required: false) endif =20 +libbpf_version =3D '1.1.0' +libbpf_dep =3D dependency('libbpf', version: '>=3D' + libbpf_version, requ= ired: get_option('libbpf')) +if libbpf_dep.found() + conf.set('WITH_BPF', 1) +endif + libiscsi_version =3D '1.18.0' libiscsi_dep =3D dependency('libiscsi', version: '>=3D' + libiscsi_version= , required: get_option('libiscsi')) =20 @@ -2339,6 +2345,7 @@ libs_summary =3D { 'dlopen': dlopen_dep.found(), 'fuse': fuse_dep.found(), 'glusterfs': glusterfs_dep.found(), + 'libbpf': libbpf_dep.found(), 'libiscsi': libiscsi_dep.found(), 'libkvm': libkvm_dep.found(), 'libnbd': libnbd_dep.found(), diff --git a/meson_options.txt b/meson_options.txt index 2d440c63d8..be1582186e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -51,6 +51,7 @@ option('udev', type: 'feature', value: 'auto', descriptio= n: 'udev support') option('wireshark_dissector', type: 'feature', value: 'auto', description:= 'wireshark support') option('wireshark_plugindir', type: 'string', value: '', description: 'wir= eshark plugins directory for use when installing wireshark plugin') option('yajl', type: 'feature', value: 'auto', description: 'yajl support') +option('libbpf', type: 'feature', value: 'auto', description: 'qemu libbpf= support') =20 =20 # build driver options diff --git a/src/qemu/meson.build b/src/qemu/meson.build index 57356451e4..60e7e02373 100644 --- a/src/qemu/meson.build +++ b/src/qemu/meson.build @@ -99,6 +99,7 @@ if conf.has('WITH_QEMU') access_dep, capng_dep, gnutls_dep, + libbpf_dep, libnbd_dep, libnl_dep, log_dep, diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index c2007c7043..3f141afd26 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -38,6 +38,10 @@ #include #include =20 +#ifdef WITH_BPF +# include +#endif + #define VIR_FROM_THIS VIR_FROM_QEMU =20 VIR_LOG_INIT("qemu.qemu_interface"); @@ -432,3 +436,86 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm, virDomainAuditNetDevice(vm->def, net, vhostnet_path, vhostfdSize); return 0; } + +#ifdef WITH_BPF + +int +qemuInterfaceLoadEbpf(const char *ebpfObject, + void **retLibbpfObj, + int *fds, + size_t nfds) +{ + int err =3D 0; + size_t i =3D 0; + struct bpf_program *prog; + struct bpf_map *map; + struct bpf_object *obj; + size_t ebpfSize =3D 0; + g_autofree void *ebpfRawData =3D NULL; + + ebpfRawData =3D g_base64_decode(ebpfObject, &ebpfSize); + if (ebpfRawData =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("can't decode the e= BPF from base64")); + return -1; + } + + obj =3D bpf_object__open_mem(ebpfRawData, ebpfSize, NULL); + if (!obj) { + virReportError(errno, "%s", _("can't open eBPF object")); + return -1; + } + + + err =3D bpf_object__load(obj); + if (err) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("can't load eBPF ob= ject")); + return -1; + } + + bpf_object__for_each_program(prog, obj) { + fds[i] =3D bpf_program__fd(prog); + ++i; + if (i > nfds) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("to much file d= escriptors in eBPF")); + return -1; + } + } + + bpf_object__for_each_map(map, obj) { + fds[i] =3D bpf_map__fd(map); + ++i; + if (i > nfds) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("to much file d= escriptors in eBPF")); + return -1; + } + } + + *retLibbpfObj =3D obj; + + return i - 1; +} + + +void +qemuInterfaceCloseEbpf(void *libbpfObj) +{ + if (libbpfObj) + bpf_object__close(libbpfObj); +} +#else + +int +qemuInterfaceLoadEbpf(const char *ebpfObject G_GNUC_UNUSED, + void **retLibbpfObj G_GNUC_UNUSED, + int *fds G_GNUC_UNUSED, + size_t nfds G_GNUC_UNUSED) +{ + return -2; +} + +void +qemuInterfaceCloseEbpf(void *libbpfObj G_GNUC_UNUSED) +{ +} + +#endif diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h index aee5f9efb0..8ce86b8769 100644 --- a/src/qemu/qemu_interface.h +++ b/src/qemu/qemu_interface.h @@ -44,3 +44,10 @@ int qemuInterfaceOpenVhostNet(virDomainObj *def, =20 int qemuInterfacePrepareSlirp(virQEMUDriver *driver, virDomainNetDef *net); + +int qemuInterfaceLoadEbpf(const char *ebpfObject, + void **retLibbpfObj, + int *fds, + size_t nfds); + +void qemuInterfaceCloseEbpf(void *libbpfObj); --=20 2.45.2