-
Notifications
You must be signed in to change notification settings - Fork 608
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
Dumping BPF map files (Issue #777) #1044
Conversation
Hi @abhishekvijeev! Let's start with small nits on how you do a pr to criu:
|
e5703e6
to
f41a705
Compare
Hi @Snorch , Thank you very much for the feedback. I have made the necessary changes to the commits (will keep this in mind henceforth). Kindly let me know if I can explain any of the commit messages more clearly. Also, the reason that majority of tests were failing was because I had implemented incomplete boiler-plate code for testing c/r of BPF maps. I have removed the test from the PR for now, and will add it once it is complete (I have described below my thoughts on creating tests for BPF maps). criu/proc_parse.c: In function 'parse_bpfmap': I tried changing the format specifier to %llu, but the code didn't compile on my PC (x86_64). Does this test fail because compilers view the data type 'uint64_t' differently for ARM64 and x86_64? If this is the case, how should I resolve this issue? Currently, this PR accomplishes 2 tasks: However, a significant part of the problem remains unsolved. BPF map files typically contain data in the form of key value pairs. CRIU must therefore checkpoint and restore this data as well. According to my current understanding, the data contained within BPF maps is not made available via the proc Also, BPF maps can be persisted on /sys/fs/bpf/ using the BPF_PIN_FD command argument. In this case, during restoration, instead of creating a new map with the same parameters (the way this PR currently works), CRIU must be able to open the map on the sys filesystem. This is another problem I will solve. Once I have accomplished this, I will create 2 ZDTM tests that accomplish the following: a) - Checkpoint a process that has a BPF map with data b) - Checkpoint a process that has a BPF map persisted on sysfs Thank you, |
PRIu64 should help to print unit64_t https://en.cppreference.com/w/c/types/integer
You may also consider protobuf repeated key-value pair entry. Thanks, |
Thanks! |
Could you rebase this PR? |
Sure @avagin , it's done. |
I see that the following RPC test is failing: I tried reproducing the error on my PC by executing the following command: 'test-c' fails with the following output (obtained from test/others/rpc/build/output_c): "build/imgs_c The socket connection was failing. I therefore re-ran the test as the root user, and it passed. Am I correct in assuming that instructing Travis to execute the test as root user is the correct solution to this problem? If so, how can I ensure that Travis passes it? Thank you. |
Could you push the test too? It will help to review these changes. |
The template test I had created earlier for BPF maps? |
I don't think it's possible to checkpoint a BPF map file's data, as Linux's BPF system call API doesn't provide a means to duplicate BPF map data (like 'tee' for pipes). I have explained the problem in this email: It's meaningless to continue work on BPF map files (#777) unless Linux's BPF API evolves to support dumping map data. I mean, I don't see the point in only reading info from the proc filesystem and restoring an identical map without its data. Do let me know if you think otherwise (i.e if you think there is value in only dumping and restoring a map without its data). Else, I shall close this PR. Thank you. |
@abhishekvijeev This is not a dead end, you hit a new challenge of extending linux API-s. While we were developing CRIU, we met similar problems a few time. Now, you need to discuss a new API for dumping BPF files with the kernel community and implement it. |
Thank you for the response @avagin |
fca68f1
to
b94b87e
Compare
ea4eed6
to
bc0db39
Compare
527d926
to
b615e71
Compare
Hi, Travis tests pass now. The Fedora rawhide tests fail, but I see that this has been occurring across CRIU builds over that past couple of days - I therefore assume that this is a temporary problem independent of this PR. I have not added a CentOS 8 test or upgraded the docker base images because there was no need to. I will be glad to do these if necessary. Please let me know if I can improve this PR in any way before it's merged. Thank you. |
This commit adds protobuf definitions needed to checkpoint and restore BPF map files along with the data they contain Source files added: * bpfmap-file.proto - Stores the meta-data about BPF maps * bpfmap-data.proto - Stores the data (key-value pairs) contained in BPF maps Source files modified: * fdinfo.proto - Added BPF map as a new kind of file descriptor. 'message file_entry' can now hold information about BPF map file descriptors * Makefile - Now generates build artifacts for bpfmap-file.proto and bpfmap-data.proto Signed-off-by: Abhishek Vijeev <[email protected]>
This commit defines constants and includes necessary headers to c/r BPF maps Source files modified: * magic.h - Defining BPFMAP_FILE_MAGIC and BPFMAP_DATA_MAGIC * image-desc.h - Defining CR_FD_BPFMAP_FILE and CR_FD_BPFMAP_DATA * image-desc.c - Create new entries for bpfmap-file and bpfmap-data in CRIU's file descriptor set * protobuf-desc.h - Defining PB_BPFMAP_FILE and PB_BPFMAP_DATA * protobuf-desc.c - Including headers for BPF map protobuf images Signed-off-by: Abhishek Vijeev <[email protected]>
Source files modified: * Makefile.config - Checks whether libbpf is installed on the system. If so, we add -lbpf to LIBS_FEATURES, -DCONFIG_HAS_LIBBPF to FEATURE_DEFINES and set CONFIG_HAS_LIBBPF. This allows us to check for the presence of libbpf before compiling or executing BPF c/r code and ZDTM tests. * Makefile - Set CONFIG_HAS_LIBBPF to clean all files. Signed-off-by: Abhishek Vijeev <[email protected]>
This commit enables CRIU to: (a) identify an anonymous inode as being a BPF map (b) parse information about BPF maps from procfs Source files modified: * files.c - Checks anonymous inodes to see whether they are BPF maps. If so, sets struct fdtype_ops *ops to a structure that knows how to dump BPF maps * proc_parse.c - Function parse_fdinfo_pid_s() now checks whether the current file being processed is a BPF map. If so, it calls a newly defined function parse_bpfmap() which knows how to parse information about BPF maps from procfs Signed-off-by: Abhishek Vijeev <[email protected]>
This commit enables CRIU to dump meta-data about BPF maps files by prividing the structures and functions needed by other parts of the code-base. Source files added: * bpfmap.c - defines new structures and functions: (a) struct fdtype_ops bpfmap_dump_ops: sets up the function handler to dump BPF maps (b) is_bpfmap_link(): checks whether an anonymous inode is a BPF map file (c) dump_one_bpfmap(): parses information for a BPF map file from procfs and dumps it * include/bpfmap.h - structure and function declarations Source files modified: * Makefile.crtools - generates build artifacts for bpfmap.c Signed-off-by: Abhishek Vijeev <[email protected]>
This commit enables CRIU to dump data(key-value) pairs stored in BPF maps Source files modified: * bpfmap.c - Function dump_one_bpfmap_data() reads the map's keys and values into two buffers using bpf_map_lookup_batch() and then writes them out to a protobuf image along with the number of key-value pairs read - Function dump_one_bpfmap() now dumps the data as well before returning * include/bpfmap.h - Includes headers and declares functions needed to dump BPF map data Signed-off-by: Abhishek Vijeev <[email protected]>
This commit enables CRIT to decode the contents of a protobuf image that stores information related to BPF map Signed-off-by: Abhishek Vijeev <[email protected]>
This commit enables CRIU to restore a process' BPF map file descriptors. Source files modified: * bpfmap.c - Structure and function definitions needed to: (a) collect a BPF map's information from its protobuf image (b) create and open a BPF map with the same parameters as when it was dumped (c) add the newly opened BPF map to the process' file descriptor list * include/bpfmap.h - Structure declarations for restoring BPF maps * files.c - Collects a BPF map's file entry during the restoration phase Signed-off-by: Abhishek Vijeev <[email protected]>
This commit restores the data of BPF maps. A hash table (indexed by the map's id) is used to store data objects for multiple BPF map files that a process may have opened. Collisions are resolved with chaining using a linked list. Source files modified: * bpfmap.c - Structure and function definitions needed to: (a) collect the protobuf image containing BPF map data (b) read the BPF map's data from the image and store it in the hash table (c) restore the map's data using bpf_map_update_batch() * include/bpfmap.h - Defines the size of the hash table and maks to be used while indexing into it - Structure and function declarations that are used while restoring BPF map data * cr-restore.c - Collects the protobuf image containing BPF map data during the restoration phase Signed-off-by: Abhishek Vijeev <[email protected]>
This commit adds ZDTM tests for c/r of processes with BPF maps as open files Source files added: * zdtm/static/bpf_hash.c - Tests for c/r of the data and meta-data of BPF map type BPF_MAP_TYPE_HASH * zdtm/static/bpf_array.c - Tests for c/r of the data and meta-data of BPF map type BPF_MAP_TYPE_ARRAY Source files modified: * zdtm/static/Makefile - Generating build artifacts for BPF tests Signed-off-by: Abhishek Vijeev <[email protected]>
Source files modified: * travis/vagrant.sh - Adding libbpf-devel Signed-off-by: Abhishek Vijeev <[email protected]>
This change fixes the error: error: 'security_context_t' is deprecated [-Werror=deprecated-declarations] Source files modified: * lsm.c * net.c Please refer to: SELinuxProject/selinux@9eb9c9327 Signed-off-by: Abhishek Vijeev <[email protected]>
b615e71
to
fb7c634
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done!
Thank you! |
Applied. Thanks a lot! |
That's great! Thanks so much to the community for helping me work towards getting this PR merged! |
Hi,
I have implemented functionality to dump information about BPF map files and also created a template ZDTM static test file for BPF maps. The test currently fails because restore functionality has not yet been implemented. I am currently working on this.
My first goal is to get checkpoint and restore fully working for simple BPF map files, after which I will enhance CRIU to deal with other kinds of BPF files. Kindly let me know whether you would prefer me to prioritize something else.
I await your kind feedback.
Thank you.