mirror of
https://github.com/qemu/qemu.git
synced 2024-11-24 11:23:43 +08:00
e88899fa90
Now, the binary objects may be retrieved by id. It would require for future qmp commands that may require specific eBPF blob. Added command "request-ebpf". This command returns eBPF program encoded base64. The program taken from the skeleton and essentially is an ELF object that can be loaded in the future with libbpf. The reason to use the command to provide the eBPF object instead of a separate artifact was to avoid issues related to finding the eBPF itself. eBPF object is an ELF binary that contains the eBPF program and eBPF map description(BTF). Overall, eBPF object should contain the program and enough metadata to create/load eBPF with libbpf. As the eBPF maps/program should correspond to QEMU, the eBPF can't be used from different QEMU build. The first solution was a helper that comes with QEMU and loads appropriate eBPF objects. And the issue is to find a proper helper if the system has several different QEMUs installed and/or built from the source, which helpers may not be compatible. Another issue is QEMU updating while there is a running QEMU instance. With an updated helper, it may not be possible to hotplug virtio-net device to the already running QEMU. Overall, requesting the eBPF object from QEMU itself solves possible failures with acceptable effort. Links: [PATCH 3/5] qmp: Added the helper stamp check. https://lore.kernel.org/all/20230219162100.174318-4-andrew@daynix.com/ Signed-off-by: Andrew Melnychenko <andrew@daynix.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
70 lines
1.6 KiB
C
70 lines
1.6 KiB
C
/*
|
|
* QEMU eBPF binary declaration routine.
|
|
*
|
|
* Developed by Daynix Computing LTD (http://www.daynix.com)
|
|
*
|
|
* Authors:
|
|
* Andrew Melnychenko <andrew@daynix.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/queue.h"
|
|
#include "qapi/error.h"
|
|
#include "qapi/qapi-commands-ebpf.h"
|
|
#include "ebpf/ebpf.h"
|
|
|
|
typedef struct ElfBinaryDataEntry {
|
|
int id;
|
|
const void *data;
|
|
size_t datalen;
|
|
|
|
QSLIST_ENTRY(ElfBinaryDataEntry) node;
|
|
} ElfBinaryDataEntry;
|
|
|
|
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;
|
|
}
|
|
|
|
EbpfObject *qmp_request_ebpf(EbpfProgramID id, Error **errp)
|
|
{
|
|
EbpfObject *ret = NULL;
|
|
size_t size = 0;
|
|
const void *data = ebpf_find_binary_by_id(id, &size, errp);
|
|
if (!data) {
|
|
return NULL;
|
|
}
|
|
|
|
ret = g_new0(EbpfObject, 1);
|
|
ret->object = g_base64_encode(data, size);
|
|
|
|
return ret;
|
|
}
|