[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 06/12] ebpf/uBPF: Add qemu_ubpf_run_once excute real ebpf pro
From: |
Zhang Chen |
Subject: |
[RFC PATCH 06/12] ebpf/uBPF: Add qemu_ubpf_run_once excute real ebpf program |
Date: |
Fri, 17 Jun 2022 15:36:24 +0800 |
Before running this function, we need to ensure that the
userspace ebpf program has been loaded correctly.
Signed-off-by: Zhang Chen <chen.zhang@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
- Re: [RFC PATCH 01/12] configure: Add iovisor/ubpf project as a submodule for QEMU, (continued)
- Re: [RFC PATCH 01/12] configure: Add iovisor/ubpf project as a submodule for QEMU, Daniel P . Berrangé, 2022/06/17
- RE: [RFC PATCH 01/12] configure: Add iovisor/ubpf project as a submodule for QEMU, Zhang, Chen, 2022/06/20
- Re: [RFC PATCH 01/12] configure: Add iovisor/ubpf project as a submodule for QEMU, Daniel P . Berrangé, 2022/06/20
- Re: [RFC PATCH 01/12] configure: Add iovisor/ubpf project as a submodule for QEMU, Thomas Huth, 2022/06/20
- RE: [RFC PATCH 01/12] configure: Add iovisor/ubpf project as a submodule for QEMU, Zhang, Chen, 2022/06/20
- Re: [RFC PATCH 01/12] configure: Add iovisor/ubpf project as a submodule for QEMU, Thomas Huth, 2022/06/20
[RFC PATCH 02/12] meson: Add ubpf build config and misc, Zhang Chen, 2022/06/17
[RFC PATCH 03/12] ebpf/uBPF: Introduce userspace ebpf data structure, Zhang Chen, 2022/06/17
[RFC PATCH 05/12] ebpf/uBPF: Add qemu_prepare_ubpf to load ebpf binary, Zhang Chen, 2022/06/17
[RFC PATCH 04/12] ebpf/uBPF: Introduce ubpf initialize functions, Zhang Chen, 2022/06/17
[RFC PATCH 06/12] ebpf/uBPF: Add qemu_ubpf_run_once excute real ebpf program,
Zhang Chen <=
[RFC PATCH 07/12] net/filter: Introduce filter-ubpf module, Zhang Chen, 2022/06/17
[RFC PATCH 09/12] softmmu/vl.c: Add filter-ubpf for netdev as other netfilters, Zhang Chen, 2022/06/17
[RFC PATCH 08/12] qapi: Add FilterUbpfProperties and qemu-options, Zhang Chen, 2022/06/17
[RFC PATCH 10/12] net/filter-ubpf.c: run the ubpf program to handle network packet, Zhang Chen, 2022/06/17
[RFC PATCH 11/12] docs/devel: Add userspace-ebpf.rst, Zhang Chen, 2022/06/17
[RFC PATCH 12/12] test/qtest: Add ubpf basic test case, Zhang Chen, 2022/06/17