aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/linux/bpf.h
diff options
context:
space:
mode:
authorYonghong Song <yonghong.song@linux.dev>2024-11-12 08:39:22 -0800
committerAlexei Starovoitov <ast@kernel.org>2024-11-12 16:26:24 -0800
commit7d1cd70d4b16ff0216a5f6c2ae7d0fa9fa978c07 (patch)
tree772fbcbc6b3be0d76d2625399776a2e048e8e8c0 /include/linux/bpf.h
parentbpf, x86: Avoid repeated usage of bpf_prog->aux->stack_depth (diff)
downloadwireguard-linux-7d1cd70d4b16ff0216a5f6c2ae7d0fa9fa978c07.tar.xz
wireguard-linux-7d1cd70d4b16ff0216a5f6c2ae7d0fa9fa978c07.zip
bpf, x86: Support private stack in jit
Private stack is allocated in function bpf_int_jit_compile() with alignment 8. Private stack allocation size includes the stack size determined by verifier and additional space to protect stack overflow and underflow. See below an illustration: ---> memory address increasing [8 bytes to protect overflow] [normal stack] [8 bytes to protect underflow] If overflow/underflow is detected, kernel messages will be emited in dmesg like BPF private stack overflow/underflow detected for prog Fx BPF Private stack overflow/underflow detected for prog bpf_prog_a41699c234a1567a_subprog1x Those messages are generated when I made some changes to jitted code to intentially cause overflow for some progs. For the jited prog, The x86 register 9 (X86_REG_R9) is used to replace bpf frame register (BPF_REG_10). The private stack is used per subprog per cpu. The X86_REG_R9 is saved and restored around every func call (not including tailcall) to maintain correctness of X86_REG_R9. Signed-off-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20241112163922.2224385-1-yonghong.song@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include/linux/bpf.h')
-rw-r--r--include/linux/bpf.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 129b29e85cec..d32cc373dfd1 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1507,6 +1507,7 @@ struct bpf_prog_aux {
u32 max_rdwr_access;
struct btf *attach_btf;
const struct bpf_ctx_arg_aux *ctx_arg_info;
+ void __percpu *priv_stack_ptr;
struct mutex dst_mutex; /* protects dst_* pointers below, *after* prog becomes visible */
struct bpf_prog *dst_prog;
struct bpf_trampoline *dst_trampoline;