From: Andrew Melnychenko <andrew@daynix.com>
To: jasowang@redhat.com, mst@redhat.com, armbru@redhat.com,
eblake@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com
Cc: yuri.benditovich@daynix.com, yan@daynix.com
Subject: [PATCH v2 4/6] ebpf: Added declaration/initialization routines.
Date: Fri, 12 May 2023 15:29:00 +0300 [thread overview]
Message-ID: <20230512122902.34345-5-andrew@daynix.com> (raw)
In-Reply-To: <20230512122902.34345-1-andrew@daynix.com>
Now, the binary objects may be retrieved by id.
It would require for future qmp commands that may require specific
eBPF blob.
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
ebpf/ebpf.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
ebpf/ebpf.h | 31 +++++++++++++++++++++++++++
| 5 +++++
ebpf/meson.build | 1 +
4 files changed, 91 insertions(+)
create mode 100644 ebpf/ebpf.c
create mode 100644 ebpf/ebpf.h
diff --git a/ebpf/ebpf.c b/ebpf/ebpf.c
new file mode 100644
index 00000000000..8870a9b3f50
--- /dev/null
+++ b/ebpf/ebpf.c
@@ -0,0 +1,54 @@
+/*
+ * QEMU eBPF binary declaration routine.
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Andrew Melnychenko <andrew@daynix.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later. See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/queue.h"
+#include "qapi/error.h"
+#include "ebpf/ebpf.h"
+
+struct ElfBinaryDataEntry {
+ int id;
+ const void *data;
+ size_t datalen;
+
+ QSLIST_ENTRY(ElfBinaryDataEntry) node;
+};
+
+static QSLIST_HEAD(, ElfBinaryDataEntry) ebpf_elf_obj_list =
+ QSLIST_HEAD_INITIALIZER();
+
+void ebpf_register_binary_data(int id, const void *data, size_t datalen)
+{
+ struct ElfBinaryDataEntry *dataentry = NULL;
+
+ dataentry = g_new0(struct ElfBinaryDataEntry, 1);
+ dataentry->data = data;
+ dataentry->datalen = datalen;
+ dataentry->id = id;
+
+ QSLIST_INSERT_HEAD(&ebpf_elf_obj_list, dataentry, node);
+}
+
+const void *ebpf_find_binary_by_id(int id, size_t *sz, Error **errp)
+{
+ struct ElfBinaryDataEntry *it = NULL;
+ QSLIST_FOREACH(it, &ebpf_elf_obj_list, node) {
+ if (id == it->id) {
+ *sz = it->datalen;
+ return it->data;
+ }
+ }
+
+ error_setg(errp, "can't find eBPF object with id: %d", id);
+
+ return NULL;
+}
diff --git a/ebpf/ebpf.h b/ebpf/ebpf.h
new file mode 100644
index 00000000000..b6266b28b8c
--- /dev/null
+++ b/ebpf/ebpf.h
@@ -0,0 +1,31 @@
+/*
+ * QEMU eBPF binary declaration routine.
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Andrew Melnychenko <andrew@daynix.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later. See the COPYING file in the top-level directory.
+ */
+
+#ifndef EBPF_H
+#define EBPF_H
+
+struct Error;
+
+void ebpf_register_binary_data(int id, const void *data,
+ size_t datalen);
+const void *ebpf_find_binary_by_id(int id, size_t *sz,
+ struct Error **errp);
+
+#define ebpf_binary_init(id, fn) \
+static void __attribute__((constructor)) ebpf_binary_init_ ## fn(void) \
+{ \
+ size_t datalen = 0; \
+ const void *data = fn(&datalen); \
+ ebpf_register_binary_data(id, data, datalen); \
+}
+
+#endif /* EBPF_H */
--git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c
index 24bc6cc409e..213a8ac79ad 100644
--- a/ebpf/ebpf_rss.c
+++ b/ebpf/ebpf_rss.c
@@ -13,6 +13,7 @@
#include "qemu/osdep.h"
#include "qemu/error-report.h"
+#include "qapi/qapi-types-misc.h"
#include <bpf/libbpf.h>
#include <bpf/bpf.h>
@@ -21,6 +22,8 @@
#include "ebpf/ebpf_rss.h"
#include "ebpf/rss.bpf.skeleton.h"
+#include "ebpf/ebpf.h"
+
#include "trace.h"
void ebpf_rss_init(struct EBPFRSSContext *ctx)
@@ -261,3 +264,5 @@ void ebpf_rss_unload(struct EBPFRSSContext *ctx)
ctx->map_toeplitz_key = -1;
ctx->map_indirections_table = -1;
}
+
+ebpf_binary_init(EBPF_PROGRAMID_RSS, rss_bpf__elf_bytes)
diff --git a/ebpf/meson.build b/ebpf/meson.build
index 2dd0fd89480..67c3f53aa9d 100644
--- a/ebpf/meson.build
+++ b/ebpf/meson.build
@@ -1 +1,2 @@
+softmmu_ss.add(files('ebpf.c'))
softmmu_ss.add(when: libbpf, if_true: files('ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))
--
2.39.1
next prev parent reply other threads:[~2023-05-12 12:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-12 12:28 [PATCH v2 0/6] eBPF RSS through QMP support Andrew Melnychenko
2023-05-12 12:28 ` [PATCH v2 1/6] ebpf: Added eBPF map update through mmap Andrew Melnychenko
2023-05-15 9:34 ` Daniel P. Berrangé
2023-05-12 12:28 ` [PATCH v2 2/6] ebpf: Added eBPF initialization by fds Andrew Melnychenko
2023-05-15 9:35 ` Daniel P. Berrangé
2023-05-12 12:28 ` [PATCH v2 3/6] virtio-net: Added property to load eBPF RSS with fds Andrew Melnychenko
2023-05-15 9:38 ` Daniel P. Berrangé
2023-05-15 10:53 ` Andrew Melnichenko
2023-05-16 21:21 ` Eric Blake
2023-05-12 12:29 ` Andrew Melnychenko [this message]
2023-05-15 9:44 ` [PATCH v2 4/6] ebpf: Added declaration/initialization routines Daniel P. Berrangé
2023-05-12 12:29 ` [PATCH v2 5/6] qmp: Added new command to retrieve eBPF blob Andrew Melnychenko
2023-05-15 9:50 ` Daniel P. Berrangé
2023-05-16 8:47 ` Markus Armbruster
2023-05-16 8:54 ` Daniel P. Berrangé
2023-05-16 10:23 ` Markus Armbruster
2023-05-16 10:29 ` Daniel P. Berrangé
2023-05-16 14:04 ` Markus Armbruster
2023-05-16 14:35 ` Daniel P. Berrangé
2023-05-16 15:06 ` Markus Armbruster
2023-05-16 15:18 ` Daniel P. Berrangé
2023-05-22 10:50 ` Markus Armbruster
2023-05-12 12:29 ` [PATCH v2 6/6] ebpf: Updated eBPF program and skeleton Andrew Melnychenko
2023-05-15 9:53 ` Daniel P. Berrangé
2023-05-16 21:29 ` Eric Blake
2023-05-12 12:31 ` [PATCH v2 0/6] eBPF RSS through QMP support Andrew Melnichenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230512122902.34345-5-andrew@daynix.com \
--to=andrew@daynix.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yan@daynix.com \
--cc=yuri.benditovich@daynix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).