From nobody Sat Nov 23 14:33:44 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 171554494637594.1959275137491; Sun, 12 May 2024 13:15:46 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4381A181C; Sun, 12 May 2024 16:15:45 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C7D0A1B8C; Sun, 12 May 2024 16:12:57 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1C36B1A57; Sun, 12 May 2024 16:12:49 -0400 (EDT) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 002AF1A79 for ; Sun, 12 May 2024 16:12:47 -0400 (EDT) Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-350513d2c6aso1782916f8f.2 for ; Sun, 12 May 2024 13:12:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 13:12:45 -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=1715544766; x=1716149566; 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=6ldlONHaq/aoqQD1qXKQARSsiWk1NRsba60/4dhX7A4=; b=eqfw4RmNWrHw10bkyDpnTrwQDGIhacRguWeMfM+wffZo+ml9qdL3sVAtSqmvHjVdVD rAL0lWlJRFPaRo7dD0SjoiVjsJmepxEaKy4HxZpg6TmMx1OWXTseVbE4gWiWIPI4kZLX D+IKc2D0BaM9+U+NGLDQqAL2OBCRaNHsBUdXOWRed7Ygl3+VgIPrvtLvjiqa5WHjxGzK sI9Dz2E7RPgVpd3B2y5W3BFwNUTRm7kPZEMucXQ7GAt8gz21+YDO/IuaEJviqqu6rhvz RtcfS4MY2Q/DLVrfQ70v9G0ErwD4wR9KqPcb42qeQFqGZLnqjwq8pfrfOYEJFzGNqjwL bEAQ== X-Gm-Message-State: AOJu0YzjIlMODonk7pxnLVJt+mfdqPzh3hAWdApd4+9it/b0E+7CfGAl PAOuOSlu9Vaa9bbc3l+Rf4ASOlLhw10UO2hqIl8ybLwLqNnoary7V5/+WhV4qUtgiE1/UPFSMMf 3 X-Google-Smtp-Source: AGHT+IEWFLYBlk1pQz5V0anuuXNZ2Rk0d/yxfew4Jx27xXni6ZY5J0gKAw3qaWetL+AQ3ZXEk80Muw== X-Received: by 2002:a05:6000:114c:b0:34d:8239:8dd0 with SMTP id ffacd0b85a97d-3504a10f827mr5807544f8f.0.1715544766133; Sun, 12 May 2024 13:12:46 -0700 (PDT) From: Andrew Melnychenko To: devel@lists.libvirt.org Subject: [RFC PATCH v3 3/6] qemu_interface: Added routine for loading the eBPF objects. Date: Sun, 12 May 2024 22:45:45 +0300 Message-ID: <20240512194550.5023-4-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: ZM7AVKZIPMZMAOCLWRHHH4DUPNEKONTD X-Message-ID-Hash: ZM7AVKZIPMZMAOCLWRHHH4DUPNEKONTD 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: 1715544947980100001 Also, added dependencies for libbpf with bpf option. Signed-off-by: Andrew Melnychenko --- meson.build | 7 ++++ meson_options.txt | 1 + src/qemu/meson.build | 1 + src/qemu/qemu_interface.c | 83 +++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_interface.h | 4 ++ 5 files changed, 96 insertions(+) diff --git a/meson.build b/meson.build index e8b0094b91..e12a703a4d 100644 --- a/meson.build +++ b/meson.build @@ -998,6 +998,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 @@ -2283,6 +2289,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 9d729b3e1f..9b7bd9d1f8 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -48,6 +48,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 907893d431..de7ae87d5b 100644 --- a/src/qemu/meson.build +++ b/src/qemu/meson.build @@ -105,6 +105,7 @@ if conf.has('WITH_QEMU') selinux_dep, src_dep, xdr_dep, + libbpf_dep, ], include_directories: [ conf_inc_dir, diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index c2007c7043..ec8cf18d86 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,82 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm, virDomainAuditNetDevice(vm->def, net, vhostnet_path, vhostfdSize); return 0; } + +#ifdef WITH_BPF + +int +qemuInterfaceLoadEbpf(const char *ebpfObject, void **retLibbpfObj, int *fd= s, 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); + err =3D libbpf_get_error(obj); + if (err) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("can't open eBPF ob= ject")); + 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 **retLibb= pfObj G_GNUC_UNUSED, + int *fds G_GNUC_UNUSED, size_t nfds G_GNUC_UNUSED) +{ + return -1; +} + +void +qemuInterfaceCloseEbpf(void *libbpfObj G_GNUC_UNUSED) +{ +} + +#endif diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h index aee5f9efb0..b6f39550cd 100644 --- a/src/qemu/qemu_interface.h +++ b/src/qemu/qemu_interface.h @@ -44,3 +44,7 @@ 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.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org