From: Zhang Chen <chen.zhang@intel.com>
To: "Jason Wang" <jasowang@redhat.com>,
qemu-dev <qemu-devel@nongnu.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Eric Blake" <eblake@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>
Cc: Zhang Chen <chen.zhang@intel.com>,
Peter Maydell <peter.maydell@linaro.org>,
Thomas Huth <thuth@redhat.com>,
Laurent Vivier <lvivier@redhat.com>,
Yuri Benditovich <yuri.benditovich@daynix.com>,
Andrew Melnychenko <andrew@daynix.com>
Subject: [RFC PATCH 11/12] docs/devel: Add userspace-ebpf.rst
Date: Fri, 17 Jun 2022 15:36:29 +0800 [thread overview]
Message-ID: <20220617073630.535914-12-chen.zhang@intel.com> (raw)
In-Reply-To: <20220617073630.535914-1-chen.zhang@intel.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 4278 bytes --]
Introduce userspace ebpf basic knowledge.
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
docs/devel/userspace-ebpf.rst | 106 ++++++++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
create mode 100644 docs/devel/userspace-ebpf.rst
diff --git a/docs/devel/userspace-ebpf.rst b/docs/devel/userspace-ebpf.rst
new file mode 100644
index 0000000000..41eb9b04d6
--- /dev/null
+++ b/docs/devel/userspace-ebpf.rst
@@ -0,0 +1,106 @@
+===========================
+Userspace eBPF support
+===========================
+
+eBPF is a revolutionary technology with origins in the Linux kernel that
+can run sandboxed programs in an operating system kernel. It is used to
+safely and efficiently extend the capabilities of the kernel without
+requiring to change kernel source code or load kernel
+modules.(from https://ebpf.io/)
+
+Recently, I worked on QEMU net filter related jobs, like netfilter/iptables
+in kernel. We noticed kernel extend the netfilter original cBPF to eBPF,
+
+It make Linux kernel have the ability to load code dynamically. Why not
+enable user space eBPF in QEMU? It can load binary eBPF program even
+when VM running. Add some hooks in QEMU as the user space eBPF load point.
+Do the things on different layers. The original idea from Jason Wang.
+
+
+That’s the advantages of kernel eBPF. Most of the functions can be
+implemented in QEMU. The Power of Programmability.
+
+ 1). Safety:
+
+ Building on the foundation of seeing and understanding all system
+ calls and combining that with a packet and socket-level view of all
+ networking operations allows for revolutionary new approaches to
+ securing systems.
+
+ 2). Tracing & Profiling:
+
+ The ability to attach eBPF programs to trace points as well as kernel
+ and user application probe points allows unprecedented visibility into
+ the runtime behavior of applications and the system itself.
+
+ 3). Networking:
+
+ The combination of programmability and efficiency makes eBPF a natural
+ fit for all packet processing requirements of networking solutions.
+
+ 4). Observability & Monitoring:
+
+ Instead of relying on static counters and gauges exposed by the
+ perating system, eBPF enables the collection & in-kernel aggregation
+ of custom metrics and generation of visibility events based on a wide
+ range of possible sources.
+
+ Qemu userspace ebpf design based on ubpf project (https://github.com/iovisor/ubpf).
+ The most mature userspace ebpf implementation. This project officially
+ support by iovisor(Like BCC and bpftrace). Qemu userspace ebpf make
+ the ubpf project as the git submodule.
+
+ Current implementation support load ebpf program and run it in
+ filter-ubpf module, developer can easy reuse the ubpf function in
+ Qemu's other modules from the function in /ebpf/ubpf.c, And it support JIT.
+ For the uBPF License is Apache License 2.0, It's OK to compatible
+ with QEMU’s GPLv2 LICENSE same as mason.
+
+ How to use it:
+ 1. Write your ebpf C program. For example filter dst IP:
+
+ bpf_filter.c
+
+#include <arpa/inet.h>
+#include <stdint.h>
+
+#define ONE_ONE_ONE_ONE 0x01010101
+
+struct ipv4_header {
+ uint8_t ver_ihl;
+ uint8_t tos;
+ uint16_t total_length;
+ uint16_t id;
+ uint16_t frag;
+ uint8_t ttl;
+ uint8_t proto;
+ uint16_t csum;
+ uint32_t src;
+ uint32_t dst;
+};
+
+int is_dst_one_one_one_one(void *opaque) {
+ struct ipv4_header *ipv4_header = (struct ipv4_header*)opaque;
+
+ if (ntohl(ipv4_header->dst) == ONE_ONE_ONE_ONE) {
+ return 1;
+ }
+
+ return 0;
+}
+
+ 2. Build it with clang:
+ clang -O2 -target bpf -c bpf_filter.c -o ip_dst.o
+
+ 3. Load it with Qemu filter-ubpf:
+ -object filter-ubpf,netdev=hn0,id=ubpf1,queue=tx,ip-mode=on,
+ ubpf-handler=ip_dst.o
+
+ 4. Boot the VM and it will filt IP dst 1.1.1.1 packet.
+
+
+TODO: Need to add more comments and test-case for ubpf, current
+ implementation not include ebpf verifier. Qemu is a userspace
+ program, not like kernel ebpf run code in kernel space, I think
+ if the someone want to hack Qemu code no need to load a malicious
+ ubpf program, he can hack Qemu code directly.
--
2.25.1
next prev parent reply other threads:[~2022-06-17 8:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-17 7:36 [RFC PATCH 00/12] Introduce QEMU userspace ebpf support Zhang Chen
2022-06-17 7:36 ` [RFC PATCH 01/12] configure: Add iovisor/ubpf project as a submodule for QEMU Zhang Chen
2022-06-17 8:05 ` Daniel P. Berrangé
2022-06-20 5:59 ` Zhang, Chen
2022-06-20 8:11 ` Daniel P. Berrangé
2022-06-20 8:46 ` Thomas Huth
2022-06-20 9:29 ` Zhang, Chen
2022-06-20 9:43 ` Thomas Huth
2022-06-20 10:29 ` Zhang, Chen
2022-06-20 10:37 ` Daniel P. Berrangé
2022-06-22 9:21 ` Zhang, Chen
2022-06-20 10:00 ` Daniel P. Berrangé
2022-06-20 10:22 ` Zhang, Chen
2022-06-17 7:36 ` [RFC PATCH 02/12] meson: Add ubpf build config and misc Zhang Chen
2022-06-17 7:36 ` [RFC PATCH 03/12] ebpf/uBPF: Introduce userspace ebpf data structure Zhang Chen
2022-06-17 7:36 ` [RFC PATCH 04/12] ebpf/uBPF: Introduce ubpf initialize functions Zhang Chen
2022-06-17 7:36 ` [RFC PATCH 05/12] ebpf/uBPF: Add qemu_prepare_ubpf to load ebpf binary Zhang Chen
2022-06-17 7:36 ` [RFC PATCH 06/12] ebpf/uBPF: Add qemu_ubpf_run_once excute real ebpf program Zhang Chen
2022-06-17 7:36 ` [RFC PATCH 07/12] net/filter: Introduce filter-ubpf module Zhang Chen
2022-06-17 7:36 ` [RFC PATCH 08/12] qapi: Add FilterUbpfProperties and qemu-options Zhang Chen
2022-06-20 7:45 ` Markus Armbruster
2022-06-20 9:40 ` Zhang, Chen
2022-06-17 7:36 ` [RFC PATCH 09/12] softmmu/vl.c: Add filter-ubpf for netdev as other netfilters Zhang Chen
2022-06-17 7:36 ` [RFC PATCH 10/12] net/filter-ubpf.c: run the ubpf program to handle network packet Zhang Chen
2022-06-17 7:36 ` Zhang Chen [this message]
2022-06-17 7:36 ` [RFC PATCH 12/12] test/qtest: Add ubpf basic test case Zhang Chen
2022-06-17 9:34 ` Thomas Huth
2022-06-20 9:31 ` Zhang, Chen
2022-06-20 9:51 ` Thomas Huth
2022-06-29 10:43 ` [RFC PATCH 00/12] Introduce QEMU userspace ebpf support Andrew Melnichenko
2022-07-01 6:14 ` Zhang, Chen
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=20220617073630.535914-12-chen.zhang@intel.com \
--to=chen.zhang@intel.com \
--cc=andrew@daynix.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=jasowang@redhat.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.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).