diff options
author | Alexei Starovoitov <ast@plumgrid.com> | 2014-09-26 03:16:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-09-26 15:05:14 -0400 |
commit | 99c55f7d47c0dc6fc64729f37bf435abf43f4c60 (patch) | |
tree | 12f09f26bee9813ae33cfc195582c41e94b2e4e9 /Documentation | |
parent | 4a8e320c929991c9480a7b936512c57ea02d87b2 (diff) |
bpf: introduce BPF syscall and maps
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
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/networking/filter.txt | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Documentation/networking/filter.txt b/Documentation/networking/filter.txt index 014e0319a5c4..4a01d71785e9 100644 --- a/Documentation/networking/filter.txt +++ b/Documentation/networking/filter.txt | |||
@@ -1001,6 +1001,45 @@ instruction that loads 64-bit immediate value into a dst_reg. | |||
1001 | Classic BPF has similar instruction: BPF_LD | BPF_W | BPF_IMM which loads | 1001 | Classic BPF has similar instruction: BPF_LD | BPF_W | BPF_IMM which loads |
1002 | 32-bit immediate value into a register. | 1002 | 32-bit immediate value into a register. |
1003 | 1003 | ||
1004 | eBPF maps | ||
1005 | --------- | ||
1006 | 'maps' is a generic storage of different types for sharing data between kernel | ||
1007 | and userspace. | ||
1008 | |||
1009 | The maps are accessed from user space via BPF syscall, which has commands: | ||
1010 | - create a map with given type and attributes | ||
1011 | map_fd = bpf(BPF_MAP_CREATE, union bpf_attr *attr, u32 size) | ||
1012 | using attr->map_type, attr->key_size, attr->value_size, attr->max_entries | ||
1013 | returns process-local file descriptor or negative error | ||
1014 | |||
1015 | - lookup key in a given map | ||
1016 | err = bpf(BPF_MAP_LOOKUP_ELEM, union bpf_attr *attr, u32 size) | ||
1017 | using attr->map_fd, attr->key, attr->value | ||
1018 | returns zero and stores found elem into value or negative error | ||
1019 | |||
1020 | - create or update key/value pair in a given map | ||
1021 | err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size) | ||
1022 | using attr->map_fd, attr->key, attr->value | ||
1023 | returns zero or negative error | ||
1024 | |||
1025 | - find and delete element by key in a given map | ||
1026 | err = bpf(BPF_MAP_DELETE_ELEM, union bpf_attr *attr, u32 size) | ||
1027 | using attr->map_fd, attr->key | ||
1028 | |||
1029 | - to delete map: close(fd) | ||
1030 | Exiting process will delete maps automatically | ||
1031 | |||
1032 | userspace programs use this syscall to create/access maps that eBPF programs | ||
1033 | are concurrently updating. | ||
1034 | |||
1035 | maps can have different types: hash, array, bloom filter, radix-tree, etc. | ||
1036 | |||
1037 | The map is defined by: | ||
1038 | . type | ||
1039 | . max number of elements | ||
1040 | . key size in bytes | ||
1041 | . value size in bytes | ||
1042 | |||
1004 | Testing | 1043 | Testing |
1005 | ------- | 1044 | ------- |
1006 | 1045 | ||