-
Notifications
You must be signed in to change notification settings - Fork 95
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
bpf: Support struct value argument for trampoline base progs #3392
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Master branch: d295daf |
Currently in funciton __get_type_size(), the corresponding btf_type is returned only in invalid cases. Let us always return btf_type regardless of valid or invalid cases. Such a new functionality will be used in subsequent patches. Signed-off-by: Yonghong Song <yhs@fb.com>
Add struct argument information in btf_func_model and such information will be used in arch specific function arch_prepare_bpf_trampoline() to prepare argument access properly in trampoline. Signed-off-by: Yonghong Song <yhs@fb.com>
Rename argument 'stack_size' to 'regs_off' in save_regs() and restore_regs() since in reality 'stack_size' represents a particular stack offset and 'regs_off' is the one in the caller argument. Leter, another stack offset will be added to these two functions for saving and restoring struct argument values. Signed-off-by: Yonghong Song <yhs@fb.com>
In C, struct value can be passed as a function argument. For small structs, struct value may be passed in one or more registers. For trampoline based bpf programs, This would cause complication since one-to-one mapping between function argument and arch argument register is not valid any more. To support struct value argument and make bpf programs easy to write, the bpf program function parameter is changed from struct type to a pointer to struct type. The following is a simplified example. In one of later selftests, we have a bpf_testmod function: struct bpf_testmod_struct_arg_2 { long a; long b; }; noinline void bpf_testmod_test_struct_arg_2(int a, struct bpf_testmod_struct_arg_2 b, int c) { bpf_testmod_test_struct_arg_result = a + b.a + b.b + c; } When a bpf program is attached to the bpf_testmod function bpf_testmod_test_struct_arg_2(), the bpf program may look like SEC("fentry/bpf_testmod_test_struct_arg_2") int BPF_PROG(test_struct_arg_2, int a, struct bpf_testmod_struct_arg_2 *b, int c) { t2_a = a; t2_b_a = b->a; t2_b_b = b->b; t2_c = c; return 0; } Basically struct value becomes a pointer to the struct. The trampoline stack will be increased to store the stack values and the pointer to these values will be saved in the stack slot corresponding to that argument. The main changes are in save_regs() and restore_regs(). The following illustrated the trampoline asm codes for save_regs() and restore_regs(). save_regs(): /* first argument */ mov DWORD PTR [rbp-0x18],edi /* second argument: struct, save actual values and put the pointer to the slot */ lea rax,[rbp-0x40] mov QWORD PTR [rbp-0x10],rax mov QWORD PTR [rbp-0x40],rsi mov QWORD PTR [rbp-0x38],rdx /* third argument */ mov DWORD PTR [rbp-0x8],esi restore_regs(): mov edi,DWORD PTR [rbp-0x18] mov rsi,QWORD PTR [rbp-0x40] mov rdx,QWORD PTR [rbp-0x38] mov esi,DWORD PTR [rbp-0x8] Signed-off-by: Yonghong Song <yhs@fb.com>
ARM64 does not support struct value argument for trampoline based bpf programs yet. Signed-off-by: Yonghong Song <yhs@fb.com>
Add struct value support in btf_ctx_access() and btf_distill_func_proto(). Reject if a struct argument size is greater than 16 as struct size greater than 16 likely passed in memory ([1], see function X86_64ABIInfo::postMerge()). [1] https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/TargetInfo.cpp Signed-off-by: Yonghong Song <yhs@fb.com>
Master branch: d295daf |
The fexit tests will be added later. Signed-off-by: Yonghong Song <yhs@fb.com>
kernel-patches-bot
force-pushed
the
series/663167=>bpf-next
branch
from
July 26, 2022 17:43
bd9a3e0
to
5a63634
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=663167 expired. Closing PR. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: bpf: Support struct value argument for trampoline base progs
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=663167