Before running this function, we need to ensure that the userspace ebpf program has been loaded correctly.
Signed-off-by: Zhang Chen <chen.zh...@intel.com> --- ebpf/ubpf-stub.c | 6 ++++++ ebpf/ubpf.c | 16 ++++++++++++++++ ebpf/ubpf.h | 2 ++ 3 files changed, 24 insertions(+) diff --git a/ebpf/ubpf-stub.c b/ebpf/ubpf-stub.c index 885bd954b7..70da421629 100644 --- a/ebpf/ubpf-stub.c +++ b/ebpf/ubpf-stub.c @@ -27,3 +27,9 @@ int qemu_ubpf_prepare(UbpfState *u_ebpf, char *code_path) { return 0; } + +uint64_t qemu_ubpf_run_once(UbpfState *u_ebpf, void *target, + size_t target_len) +{ + return 0; +} diff --git a/ebpf/ubpf.c b/ebpf/ubpf.c index d65fffeda3..8ac513c7ed 100644 --- a/ebpf/ubpf.c +++ b/ebpf/ubpf.c @@ -199,3 +199,19 @@ int qemu_ubpf_prepare(UbpfState *u_ebpf, char *code_path) return 0; } + +uint64_t qemu_ubpf_run_once(UbpfState *u_ebpf, void *target, + size_t target_len) +{ + uint64_t result; + + if (u_ebpf->jit) { + result = u_ebpf->fn(target, target_len); + } else { + if (ubpf_exec(u_ebpf->vm, target, target_len, &result) < 0) { + result = UINT64_MAX; + } + } + + return result; +} diff --git a/ebpf/ubpf.h b/ebpf/ubpf.h index 9a35efbeb6..fc40e84e51 100644 --- a/ebpf/ubpf.h +++ b/ebpf/ubpf.h @@ -38,5 +38,7 @@ bool qemu_ubpf_read_code(UbpfState *u_ebpf, char *path); bool qemu_ubpf_read_target(UbpfState *u_ebpf, char *path); void qemu_ubpf_init_jit(UbpfState *u_ebpf, bool jit); int qemu_ubpf_prepare(UbpfState *u_ebpf, char *code_path); +uint64_t qemu_ubpf_run_once(UbpfState *u_ebpf, void *target, + size_t target_len); #endif /* QEMU_UBPF_H */ -- 2.25.1