-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ubpf needs to support maps #45
Comments
I think this would be great to have! Having these maps also implies that we'll want to have helpers for each map, so I guess we'll need to provide a "kernel-compatible" |
I think it might make more sense to provide a function like:
This would do the following:
x64 instruction then is just a load of the immediate value. Any helpers that use maps then get passed the address of the map (this is similar to what Linux jitter does, AFAIK) |
What about hash maps (and other non-contiguous data structures)? We'd still need special helpers to process them. Also, contiguous array access is usually done first via helper (to get the address of the element passed), so to support programs generated by tools focused on the Linux kernel's implementation, we'd need these helpers available. |
See BPF syscall, maps, verifier, samples, llvm I am proposing we adopt something similar to the process that Alexi describes in the email thread, but with ubpf_load_elf replacing the instruction with a lddw with the address directly. In the design listed, bpf_lookup_elem kernel helper function accepts the address of the map, not a FD. So we need the jitter to emit code with the address. |
After researching this, eBPF it appears as if the Linux kernel implements this via a BPF_LD_MAP_FD pseudo instruction, where the jitter replaces imm value with the address of the map. |
Just a comment I think if we support maps in ubpf, it's worth to think about how we implement the map it self, especially about the concurrency. Of course, it depends on the execution environment, but I guess it would be more generic if it support multi threading environment. In Linux-kernel implementation, there are various form of concurrency for maps. For example, array map basically doesn't perform any locking during lookup/update for performance. On the other hand, hash map takes lock when update/delete. And the most notable stuff is the eBPF program in kernel is basically running under RCU (e.g. https://elixir.bootlin.com/linux/latest/source/drivers/net/veth.c#L580). This strong assumption makes possible to do the operation like below.
It is possible that another thread deletes the map element between lookup and in-place update, but thanks to the RCU, the memory for the element will never released before this program finish running. So nothing will be broken. There is a project which implements RCU-like feature in user space (https://liburcu.org). However, this is LGPL so, not compatible with ubpf. Concurrency-kit is a good candidate I think, it's 2-clause-BSD (http://concurrencykit.org). "epoch" feature of it can be used like RCU. For implementation, notice both of them requires to register some context per thread, means maybe we need to enforce users to register it or intercept pthread_create or something... Actually, I tried to do the same thing for generic-ebpf project (https://github.com/generic-ebpf/generic-ebpf). This was the pitfall I've met. Good luck :) |
I think it make sense to decouple the maps part from the jitter part of ubpf. Taking a look at the docs here eBPF maps it seems like it would make sense to implement this as follows:
The consumer of the ubpf can then provide their own map implementation as they see fit via the map_create callback and the bpf_map_* helper functions. |
Going to build this on top of this PR as I need the code to lookup sections by name. |
Adding support for maps to ubpf.
As near as I can tell from examining dumps of ELF eBPF programs it looks like:
Proposed behavior is then:
Maps appear to have relocation type R_BPF_64_64 / 1
The text was updated successfully, but these errors were encountered: