From: Andrew Melnychenko <andrew@daynix.com>
To: jasowang@redhat.com, mst@redhat.com, pbonzini@redhat.com,
marcandre.lureau@redhat.com, berrange@redhat.com,
thuth@redhat.com, philmd@linaro.org, armbru@redhat.com,
eblake@redhat.com, qemu-devel@nongnu.org, toke@redhat.com,
mprivozn@redhat.com
Cc: yuri.benditovich@daynix.com, yan@daynix.com
Subject: [RFC PATCH 3/5] ebpf: Added declaration/initialization routines.
Date: Thu, 30 Mar 2023 03:15:20 +0300 [thread overview]
Message-ID: <20230330001522.120774-4-andrew@daynix.com> (raw)
In-Reply-To: <20230330001522.120774-1-andrew@daynix.com>
Now, the binary objects may be retrieved by id/name.
It would require for future qmp commands that may require specific
eBPF blob.
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
ebpf/ebpf.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
ebpf/ebpf.h | 25 +++++++++++++++++++++++++
| 4 ++++
ebpf/meson.build | 1 +
4 files changed, 78 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 0000000000..86320d72f5
--- /dev/null
+++ b/ebpf/ebpf.c
@@ -0,0 +1,48 @@
+/*
+ * 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 "ebpf/ebpf.h"
+
+struct ElfBinaryDataEntry {
+ const char *id;
+ const void * (*fn)(size_t *);
+
+ QSLIST_ENTRY(ElfBinaryDataEntry) node;
+};
+
+static QSLIST_HEAD(, ElfBinaryDataEntry) ebpf_elf_obj_list =
+ QSLIST_HEAD_INITIALIZER();
+
+void ebpf_register_binary_data(const char *id, const void * (*fn)(size_t *))
+{
+ struct ElfBinaryDataEntry *data = NULL;
+
+ data = g_malloc0(sizeof(*data));
+ data->fn = fn;
+ data->id = id;
+
+ QSLIST_INSERT_HEAD(&ebpf_elf_obj_list, data, node);
+}
+
+const void *ebpf_find_binary_by_id(const char *id, size_t *sz)
+{
+ struct ElfBinaryDataEntry *it = NULL;
+ QSLIST_FOREACH(it, &ebpf_elf_obj_list, node) {
+ if (strcmp(id, it->id) == 0) {
+ return it->fn(sz);
+ }
+ }
+
+ return NULL;
+}
diff --git a/ebpf/ebpf.h b/ebpf/ebpf.h
new file mode 100644
index 0000000000..fd705cb73e
--- /dev/null
+++ b/ebpf/ebpf.h
@@ -0,0 +1,25 @@
+/*
+ * 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
+
+void ebpf_register_binary_data(const char *id, const void * (*fn)(size_t *));
+const void *ebpf_find_binary_by_id(const char *id, size_t *sz);
+
+#define ebpf_binary_init(id, fn) \
+static void __attribute__((constructor)) ebpf_binary_init_ ## fn(void) \
+{ \
+ ebpf_register_binary_data(id, fn); \
+}
+
+#endif /* EBPF_H */
--git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c
index 08015fecb1..b4038725f2 100644
--- a/ebpf/ebpf_rss.c
+++ b/ebpf/ebpf_rss.c
@@ -21,6 +21,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)
@@ -237,3 +239,5 @@ void ebpf_rss_unload(struct EBPFRSSContext *ctx)
ctx->obj = NULL;
ctx->program_fd = -1;
}
+
+ebpf_binary_init("rss", rss_bpf__elf_bytes)
diff --git a/ebpf/meson.build b/ebpf/meson.build
index 2dd0fd8948..67c3f53aa9 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-03-30 0:33 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-30 0:15 [RFC PATCH 0/4] eBPF RSS through QMP support Andrew Melnychenko
2023-03-30 0:15 ` [RFC PATCH 1/5] ebpf: Added eBPF initialization by fds and map update Andrew Melnychenko
2023-03-30 6:53 ` Jason Wang
2023-03-30 6:56 ` Jason Wang
2023-03-30 7:10 ` Daniel P. Berrangé
2023-03-30 11:13 ` Andrew Melnichenko
2023-03-30 0:15 ` [RFC PATCH 2/5] virtio-net: Added property to load eBPF RSS with fds Andrew Melnychenko
2023-03-30 8:52 ` Daniel P. Berrangé
2023-03-30 0:15 ` Andrew Melnychenko [this message]
2023-03-30 6:54 ` [RFC PATCH 3/5] ebpf: Added declaration/initialization routines Jason Wang
2023-03-30 8:34 ` Daniel P. Berrangé
2023-03-31 7:48 ` Jason Wang
2023-03-31 7:59 ` Daniel P. Berrangé
2023-03-31 8:03 ` Jason Wang
2023-03-31 8:13 ` Daniel P. Berrangé
2023-03-31 8:21 ` Jason Wang
2023-03-30 8:33 ` Daniel P. Berrangé
2023-03-30 11:02 ` Andrew Melnichenko
2023-03-30 0:15 ` [RFC PATCH 4/5] qmp: Added new command to retrieve eBPF blob Andrew Melnychenko
2023-03-30 8:39 ` Daniel P. Berrangé
2023-03-30 10:42 ` Andrew Melnichenko
2023-03-30 0:15 ` [RFC PATCH 5/5] ebpf: Updated eBPF program and skeleton Andrew Melnychenko
2023-03-30 6:57 ` [RFC PATCH 0/4] eBPF RSS through QMP support Jason Wang
2023-03-30 10:48 ` 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=20230330001522.120774-4-andrew@daynix.com \
--to=andrew@daynix.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=jasowang@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mprivozn@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=toke@redhat.com \
--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).