Message ID | 20250318143318.656785-14-aspsk@isovalent.com (mailing list archive) |
---|---|
State | RFC |
Delegated to: | BPF |
Headers | show |
Series | instruction sets and static keys | expand |
Context | Check | Description |
---|---|---|
bpf/vmtest-bpf-next-VM_Test-0 | success | Logs for Lint |
bpf/vmtest-bpf-next-VM_Test-1 | success | Logs for ShellCheck |
bpf/vmtest-bpf-next-VM_Test-3 | success | Logs for Validate matrix.py |
bpf/vmtest-bpf-next-VM_Test-2 | success | Logs for Unittests |
bpf/vmtest-bpf-next-PR | fail | PR summary |
bpf/vmtest-bpf-next-VM_Test-6 | success | Logs for aarch64-gcc / build-release |
bpf/vmtest-bpf-next-VM_Test-7 | success | Logs for aarch64-gcc / veristat-kernel |
bpf/vmtest-bpf-next-VM_Test-8 | success | Logs for aarch64-gcc / veristat-meta |
bpf/vmtest-bpf-next-VM_Test-9 | success | Logs for s390x-gcc / GCC BPF |
bpf/vmtest-bpf-next-VM_Test-10 | fail | Logs for s390x-gcc / build / build for s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-11 | success | Logs for s390x-gcc / build-release |
bpf/vmtest-bpf-next-VM_Test-12 | success | Logs for s390x-gcc / veristat-kernel |
bpf/vmtest-bpf-next-VM_Test-4 | success | Logs for aarch64-gcc / GCC BPF |
bpf/vmtest-bpf-next-VM_Test-5 | fail | Logs for aarch64-gcc / build / build for aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-13 | success | Logs for s390x-gcc / veristat-meta |
bpf/vmtest-bpf-next-VM_Test-14 | success | Logs for set-matrix |
bpf/vmtest-bpf-next-VM_Test-15 | success | Logs for test |
bpf/vmtest-bpf-next-VM_Test-16 | success | Logs for test |
bpf/vmtest-bpf-next-VM_Test-17 | success | Logs for test |
bpf/vmtest-bpf-next-VM_Test-18 | success | Logs for test |
bpf/vmtest-bpf-next-VM_Test-19 | success | Logs for test |
bpf/vmtest-bpf-next-VM_Test-20 | success | Logs for x86_64-gcc / GCC BPF |
bpf/vmtest-bpf-next-VM_Test-21 | fail | Logs for x86_64-gcc / build / build for x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-22 | success | Logs for x86_64-gcc / build-release |
bpf/vmtest-bpf-next-VM_Test-23 | success | Logs for x86_64-gcc / veristat-kernel |
bpf/vmtest-bpf-next-VM_Test-24 | success | Logs for x86_64-gcc / veristat-meta |
bpf/vmtest-bpf-next-VM_Test-25 | success | Logs for x86_64-llvm-17 / GCC BPF |
bpf/vmtest-bpf-next-VM_Test-26 | fail | Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17 |
bpf/vmtest-bpf-next-VM_Test-27 | fail | Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2 |
bpf/vmtest-bpf-next-VM_Test-28 | success | Logs for x86_64-llvm-17 / veristat-kernel |
bpf/vmtest-bpf-next-VM_Test-29 | success | Logs for x86_64-llvm-17 / veristat-meta |
bpf/vmtest-bpf-next-VM_Test-30 | success | Logs for x86_64-llvm-18 / GCC BPF |
bpf/vmtest-bpf-next-VM_Test-31 | fail | Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18 |
bpf/vmtest-bpf-next-VM_Test-32 | fail | Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2 |
bpf/vmtest-bpf-next-VM_Test-33 | success | Logs for x86_64-llvm-18 / veristat-kernel |
bpf/vmtest-bpf-next-VM_Test-34 | success | Logs for x86_64-llvm-18 / veristat-meta |
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index a9c3e33d0f8a..330d9523fc2b 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -1331,3 +1331,20 @@ int bpf_token_create(int bpffs_fd, struct bpf_token_create_opts *opts) fd = sys_bpf_fd(BPF_TOKEN_CREATE, &attr, attr_sz); return libbpf_err_errno(fd); } + +int bpf_static_key_update(int map_fd, struct bpf_static_key_update_opts *opts) +{ + const size_t attr_sz = offsetofend(union bpf_attr, static_key); + union bpf_attr attr; + int ret; + + if (!OPTS_VALID(opts, bpf_static_key_update_opts)) + return libbpf_err(-EINVAL); + + memset(&attr, 0, attr_sz); + attr.static_key.map_fd = map_fd; + attr.static_key.on = OPTS_GET(opts, on, 0); + + ret = sys_bpf(BPF_STATIC_KEY_UPDATE, &attr, attr_sz); + return libbpf_err_errno(ret); +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 777627d33d25..c76abfda85f8 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -704,6 +704,25 @@ struct bpf_token_create_opts { LIBBPF_API int bpf_token_create(int bpffs_fd, struct bpf_token_create_opts *opts); +struct bpf_static_key_update_opts { + size_t sz; /* size of this struct for forward/backward compatibility */ + __u32 on; + size_t :0; +}; +#define bpf_static_key_update_opts__last_field on + +/** + * @brief **bpf_static_key_update()** updates the value of a static key + * + * @param map_fd FD for the static key. + * @param opts optional BPF token creation options, can be NULL + * + * @return 0 on success; negative error code, otherwise (errno + * is also set to the error code) + */ +LIBBPF_API int bpf_static_key_update(int map_fd, + struct bpf_static_key_update_opts *opts); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index d8b71f22f197..fc8f01d5804a 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -439,4 +439,5 @@ LIBBPF_1.6.0 { bpf_object__prepare; btf__add_decl_attr; btf__add_type_attr; + bpf_static_key_update; } LIBBPF_1.5.0;
Add low-level wrapper API for BPF_STATIC_KEY_UPDATE command in bpf() syscall. Signed-off-by: Anton Protopopov <aspsk@isovalent.com> --- tools/lib/bpf/bpf.c | 17 +++++++++++++++++ tools/lib/bpf/bpf.h | 19 +++++++++++++++++++ tools/lib/bpf/libbpf.map | 1 + 3 files changed, 37 insertions(+)