Currently the way to pass result from BPF helper to BPF program is to provide memory area defined by pointer and size: func(void *, size_t). It works great for generic use-case, but for simple types, such as int, it's overkill and consumes two arguments when it could use just one. Introduce new argument types ARG_PTR_TO_INT and ARG_PTR_TO_LONG to be able to pass result from helper to program via pointer to int and long correspondingly: func(int *) or func(long *). New argument types are similar to ARG_PTR_TO_MEM with the following differences: * they don't require corresponding ARG_CONST_SIZE argument, predefined access sizes are used instead (32bit for int, 64bit for long); * it's possible to use more than one such an argument in a helper; * provided pointers have to be aligned. It's easy to introduce similar ARG_PTR_TO_CHAR and ARG_PTR_TO_SHORT argument types. It's not done due to lack of use-case though.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -202,6 +202,8 @@ enum bpf_arg_type { · 201 unmodified lines | |||
| 202 | ARG_ANYTHING, /* any (initialized) argument is ok */ | 202 | ARG_ANYTHING, /* any (initialized) argument is ok */ |
| 203 | ARG_PTR_TO_SPIN_LOCK, /* pointer to bpf_spin_lock */ | 203 | ARG_PTR_TO_SPIN_LOCK, /* pointer to bpf_spin_lock */ |
| 204 | ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */ | 204 | ARG_PTR_TO_SOCK_COMMON, /* pointer to sock_common */ |
| 205 | ARG_PTR_TO_INT, /* pointer to int */ | ||
| 206 | ARG_PTR_TO_LONG, /* pointer to long */ | ||
| 205 | }; | 207 | }; |
| 206 | 208 | ||
| 207 | /* type of values returned from helper functions */ | 209 | /* type of values returned from helper functions */ |