BPF syscall is a multiplexor for a range of different operations on eBPF. This patch introduces syscall with single command to create a map. Next patch adds commands to access maps. 'maps' is a generic storage of different types for sharing data between kernel and userspace. Userspace example: /* this syscall wrapper creates a map with given type and attributes * and returns map_fd on success. * use close(map_fd) to delete the map */ int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, int max_entries) { union bpf_attr attr = { .map_type = map_type, .key_size = key_size, .value_size = value_size, .max_entries = max_entries }; return bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); } 'union bpf_attr' is backwards compatible with future extensions. More details in Documentation/networking/filter.txt and in manpage
Showing the changes to include/uapi/linux (1 of 5 files). Show all
Unified · Split
| @@ -62,4 +62,27 @@ struct bpf_insn { · 61 unmodified lines | |||
| 62 | __s32 imm; /* signed immediate constant */ | 62 | __s32 imm; /* signed immediate constant */ |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | /* BPF syscall commands */ | ||
| 66 | enum bpf_cmd { | ||
| 67 | /* create a map with given type and attributes | ||
| 68 | * fd = bpf(BPF_MAP_CREATE, union bpf_attr *, u32 size) | ||
| 69 | * returns fd or negative error | ||
| 70 | * map is deleted when fd is closed | ||
| 71 | */ | ||
| 72 | BPF_MAP_CREATE, | ||
| 73 | }; | ||
| 74 | |||
| 75 | enum bpf_map_type { | ||
| 76 | BPF_MAP_TYPE_UNSPEC, | ||
| 77 | }; | ||
| 78 | |||
| 79 | union bpf_attr { | ||
| 80 | struct { /* anonymous struct used by BPF_MAP_CREATE command */ | ||
| 81 | __u32 map_type; /* one of enum bpf_map_type */ | ||
| 82 | __u32 key_size; /* size of key in bytes */ | ||
| 83 | __u32 value_size; /* size of value in bytes */ | ||
| 84 | __u32 max_entries; /* max number of entries in a map */ | ||
| 85 | }; | ||
| 86 | } __attribute__((aligned(8))); | ||
| 87 | |||
| 65 | #endif /* _UAPI__LINUX_BPF_H__ */ | 88 | #endif /* _UAPI__LINUX_BPF_H__ */ |