History

bpf: Introduce ARG_PTR_TO_{INT,LONG} arg types

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.

Andrey Ignatov committed 7 years ago

Commit 57c3bb71 parent 9a1027e2 files · +31 −0Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/bpf.h+2−0
@@ -202,6 +202,8 @@ enum bpf_arg_type { · 201 unmodified lines
202202 ARG_ANYTHING, /* any (initialized) argument is ok */
203203 ARG_PTR_TO_SPIN_LOCK, /* pointer to bpf_spin_lock */
204204 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 */
205207 };
206208
207209 /* type of values returned from helper functions */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t