diff options
Diffstat (limited to 'tools/lib/bpf')
| -rw-r--r-- | tools/lib/bpf/.gitignore | 1 | ||||
| -rw-r--r-- | tools/lib/bpf/README.rst | 14 | ||||
| -rw-r--r-- | tools/lib/bpf/bpf.c | 19 |
3 files changed, 30 insertions, 4 deletions
diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore index f81e549ddfdb..4db74758c674 100644 --- a/tools/lib/bpf/.gitignore +++ b/tools/lib/bpf/.gitignore | |||
| @@ -1,2 +1,3 @@ | |||
| 1 | libbpf_version.h | 1 | libbpf_version.h |
| 2 | FEATURE-DUMP.libbpf | 2 | FEATURE-DUMP.libbpf |
| 3 | test_libbpf | ||
diff --git a/tools/lib/bpf/README.rst b/tools/lib/bpf/README.rst index 056f38310722..607aae40f4ed 100644 --- a/tools/lib/bpf/README.rst +++ b/tools/lib/bpf/README.rst | |||
| @@ -132,6 +132,20 @@ For example, if current state of ``libbpf.map`` is: | |||
| 132 | Format of version script and ways to handle ABI changes, including | 132 | Format of version script and ways to handle ABI changes, including |
| 133 | incompatible ones, described in details in [1]. | 133 | incompatible ones, described in details in [1]. |
| 134 | 134 | ||
| 135 | Stand-alone build | ||
| 136 | ================= | ||
| 137 | |||
| 138 | Under https://github.com/libbpf/libbpf there is a (semi-)automated | ||
| 139 | mirror of the mainline's version of libbpf for a stand-alone build. | ||
| 140 | |||
| 141 | However, all changes to libbpf's code base must be upstreamed through | ||
| 142 | the mainline kernel tree. | ||
| 143 | |||
| 144 | License | ||
| 145 | ======= | ||
| 146 | |||
| 147 | libbpf is dual-licensed under LGPL 2.1 and BSD 2-Clause. | ||
| 148 | |||
| 135 | Links | 149 | Links |
| 136 | ===== | 150 | ===== |
| 137 | 151 | ||
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 3caaa3428774..88cbd110ae58 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
| @@ -65,6 +65,17 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, | |||
| 65 | return syscall(__NR_bpf, cmd, attr, size); | 65 | return syscall(__NR_bpf, cmd, attr, size); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | static inline int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size) | ||
| 69 | { | ||
| 70 | int fd; | ||
| 71 | |||
| 72 | do { | ||
| 73 | fd = sys_bpf(BPF_PROG_LOAD, attr, size); | ||
| 74 | } while (fd < 0 && errno == EAGAIN); | ||
| 75 | |||
| 76 | return fd; | ||
| 77 | } | ||
| 78 | |||
| 68 | int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr) | 79 | int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr) |
| 69 | { | 80 | { |
| 70 | __u32 name_len = create_attr->name ? strlen(create_attr->name) : 0; | 81 | __u32 name_len = create_attr->name ? strlen(create_attr->name) : 0; |
| @@ -232,7 +243,7 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr, | |||
| 232 | memcpy(attr.prog_name, load_attr->name, | 243 | memcpy(attr.prog_name, load_attr->name, |
| 233 | min(name_len, BPF_OBJ_NAME_LEN - 1)); | 244 | min(name_len, BPF_OBJ_NAME_LEN - 1)); |
| 234 | 245 | ||
| 235 | fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); | 246 | fd = sys_bpf_prog_load(&attr, sizeof(attr)); |
| 236 | if (fd >= 0) | 247 | if (fd >= 0) |
| 237 | return fd; | 248 | return fd; |
| 238 | 249 | ||
| @@ -269,7 +280,7 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr, | |||
| 269 | break; | 280 | break; |
| 270 | } | 281 | } |
| 271 | 282 | ||
| 272 | fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); | 283 | fd = sys_bpf_prog_load(&attr, sizeof(attr)); |
| 273 | 284 | ||
| 274 | if (fd >= 0) | 285 | if (fd >= 0) |
| 275 | goto done; | 286 | goto done; |
| @@ -283,7 +294,7 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr, | |||
| 283 | attr.log_size = log_buf_sz; | 294 | attr.log_size = log_buf_sz; |
| 284 | attr.log_level = 1; | 295 | attr.log_level = 1; |
| 285 | log_buf[0] = 0; | 296 | log_buf[0] = 0; |
| 286 | fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); | 297 | fd = sys_bpf_prog_load(&attr, sizeof(attr)); |
| 287 | done: | 298 | done: |
| 288 | free(finfo); | 299 | free(finfo); |
| 289 | free(linfo); | 300 | free(linfo); |
| @@ -328,7 +339,7 @@ int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, | |||
| 328 | attr.kern_version = kern_version; | 339 | attr.kern_version = kern_version; |
| 329 | attr.prog_flags = prog_flags; | 340 | attr.prog_flags = prog_flags; |
| 330 | 341 | ||
| 331 | return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); | 342 | return sys_bpf_prog_load(&attr, sizeof(attr)); |
| 332 | } | 343 | } |
| 333 | 344 | ||
| 334 | int bpf_map_update_elem(int fd, const void *key, const void *value, | 345 | int bpf_map_update_elem(int fd, const void *key, const void *value, |
