]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: change prototype of bpf_session_{cookie,is_return}
authorMenglong Dong <menglong8.dong@gmail.com>
Sat, 24 Jan 2026 06:19:58 +0000 (14:19 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 25 Jan 2026 02:49:35 +0000 (18:49 -0800)
Add the function argument of "void *ctx" to bpf_session_cookie() and
bpf_session_is_return(), which is a preparation of the next patch.

The two kfunc is seldom used now, so it will not introduce much effect
to change their function prototype.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20260124062008.8657-4-dongml2@chinatelecom.cn
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c
kernel/trace/bpf_trace.c
tools/testing/selftests/bpf/bpf_kfuncs.h
tools/testing/selftests/bpf/progs/kprobe_multi_session_cookie.c
tools/testing/selftests/bpf/progs/uprobe_multi_session.c
tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.c
tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c

index 2081343a848d78c9a5d009f65081c8662386cd33..0fa73d56cb8ba449ae62fb0a47ce8d2e89451388 100644 (file)
@@ -12484,6 +12484,7 @@ enum special_kfunc_type {
        KF_bpf_arena_alloc_pages,
        KF_bpf_arena_free_pages,
        KF_bpf_arena_reserve_pages,
+       KF_bpf_session_is_return,
 };
 
 BTF_ID_LIST(special_kfunc_list)
@@ -12561,6 +12562,7 @@ BTF_ID(func, bpf_task_work_schedule_resume)
 BTF_ID(func, bpf_arena_alloc_pages)
 BTF_ID(func, bpf_arena_free_pages)
 BTF_ID(func, bpf_arena_reserve_pages)
+BTF_ID(func, bpf_session_is_return)
 
 static bool is_task_work_add_kfunc(u32 func_id)
 {
@@ -12615,7 +12617,9 @@ get_kfunc_ptr_arg_type(struct bpf_verifier_env *env,
        struct bpf_reg_state *reg = &regs[regno];
        bool arg_mem_size = false;
 
-       if (meta->func_id == special_kfunc_list[KF_bpf_cast_to_kern_ctx])
+       if (meta->func_id == special_kfunc_list[KF_bpf_cast_to_kern_ctx] ||
+           meta->func_id == special_kfunc_list[KF_bpf_session_is_return] ||
+           meta->func_id == special_kfunc_list[KF_bpf_session_cookie])
                return KF_ARG_PTR_TO_CTX;
 
        if (argno + 1 < nargs &&
index d466a1503da310600576f075dcbab234df01dc93..13f0a2de33b72652caab983ef081834c73e91648 100644 (file)
@@ -3323,7 +3323,7 @@ static u64 bpf_uprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
 
 __bpf_kfunc_start_defs();
 
-__bpf_kfunc bool bpf_session_is_return(void)
+__bpf_kfunc bool bpf_session_is_return(void *ctx)
 {
        struct bpf_session_run_ctx *session_ctx;
 
@@ -3331,7 +3331,7 @@ __bpf_kfunc bool bpf_session_is_return(void)
        return session_ctx->is_return;
 }
 
-__bpf_kfunc __u64 *bpf_session_cookie(void)
+__bpf_kfunc __u64 *bpf_session_cookie(void *ctx)
 {
        struct bpf_session_run_ctx *session_ctx;
 
index e0189254bb6ed6758975ee4ab7f3be620d82bfb1..7dad01439391c1681d6e2e57721471207c1a86b9 100644 (file)
@@ -79,9 +79,6 @@ extern int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_ptr,
                                      struct bpf_dynptr *sig_ptr,
                                      struct bpf_key *trusted_keyring) __ksym;
 
-extern bool bpf_session_is_return(void) __ksym __weak;
-extern __u64 *bpf_session_cookie(void) __ksym __weak;
-
 struct dentry;
 /* Description
  *  Returns xattr of a dentry
index 0835b5edf6858a454274e7242829c36aa2904095..ad627016e3e5bfcdc0f806c0661e115bef6b8b39 100644 (file)
@@ -1,9 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 #include <stdbool.h>
-#include "bpf_kfuncs.h"
 
 char _license[] SEC("license") = "GPL";
 
@@ -23,16 +22,16 @@ int BPF_PROG(trigger)
        return 0;
 }
 
-static int check_cookie(__u64 val, __u64 *result)
+static int check_cookie(struct pt_regs *ctx, __u64 val, __u64 *result)
 {
        __u64 *cookie;
 
        if (bpf_get_current_pid_tgid() >> 32 != pid)
                return 1;
 
-       cookie = bpf_session_cookie();
+       cookie = bpf_session_cookie(ctx);
 
-       if (bpf_session_is_return())
+       if (bpf_session_is_return(ctx))
                *result = *cookie == val ? val : 0;
        else
                *cookie = val;
@@ -42,17 +41,17 @@ static int check_cookie(__u64 val, __u64 *result)
 SEC("kprobe.session/bpf_fentry_test1")
 int test_kprobe_1(struct pt_regs *ctx)
 {
-       return check_cookie(1, &test_kprobe_1_result);
+       return check_cookie(ctx, 1, &test_kprobe_1_result);
 }
 
 SEC("kprobe.session/bpf_fentry_test1")
 int test_kprobe_2(struct pt_regs *ctx)
 {
-       return check_cookie(2, &test_kprobe_2_result);
+       return check_cookie(ctx, 2, &test_kprobe_2_result);
 }
 
 SEC("kprobe.session/bpf_fentry_test1")
 int test_kprobe_3(struct pt_regs *ctx)
 {
-       return check_cookie(3, &test_kprobe_3_result);
+       return check_cookie(ctx, 3, &test_kprobe_3_result);
 }
index 30bff90b68dca893c291069346b0cdf154bb4727..6e46bb00ff58235de3a5c093894b579e6f28acef 100644 (file)
@@ -1,9 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 #include <stdbool.h>
-#include "bpf_kfuncs.h"
 #include "bpf_misc.h"
 
 char _license[] SEC("license") = "GPL";
@@ -51,7 +50,7 @@ static int uprobe_multi_check(void *ctx, bool is_return)
 SEC("uprobe.session//proc/self/exe:uprobe_multi_func_*")
 int uprobe(struct pt_regs *ctx)
 {
-       return uprobe_multi_check(ctx, bpf_session_is_return());
+       return uprobe_multi_check(ctx, bpf_session_is_return(ctx));
 }
 
 static __always_inline bool verify_sleepable_user_copy(void)
@@ -67,5 +66,5 @@ int uprobe_sleepable(struct pt_regs *ctx)
 {
        if (verify_sleepable_user_copy())
                uprobe_multi_sleep_result++;
-       return uprobe_multi_check(ctx, bpf_session_is_return());
+       return uprobe_multi_check(ctx, bpf_session_is_return(ctx));
 }
index 5befdf944dc6492063fac88abdc196991d663d5d..b5db196614a94a5e0af4e9d6f63891e8507f628c 100644 (file)
@@ -1,9 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 #include <stdbool.h>
-#include "bpf_kfuncs.h"
 
 char _license[] SEC("license") = "GPL";
 
@@ -13,16 +12,16 @@ __u64 test_uprobe_1_result = 0;
 __u64 test_uprobe_2_result = 0;
 __u64 test_uprobe_3_result = 0;
 
-static int check_cookie(__u64 val, __u64 *result)
+static int check_cookie(struct pt_regs *ctx, __u64 val, __u64 *result)
 {
        __u64 *cookie;
 
        if (bpf_get_current_pid_tgid() >> 32 != pid)
                return 1;
 
-       cookie = bpf_session_cookie();
+       cookie = bpf_session_cookie(ctx);
 
-       if (bpf_session_is_return())
+       if (bpf_session_is_return(ctx))
                *result = *cookie == val ? val : 0;
        else
                *cookie = val;
@@ -32,17 +31,17 @@ static int check_cookie(__u64 val, __u64 *result)
 SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1")
 int uprobe_1(struct pt_regs *ctx)
 {
-       return check_cookie(1, &test_uprobe_1_result);
+       return check_cookie(ctx, 1, &test_uprobe_1_result);
 }
 
 SEC("uprobe.session//proc/self/exe:uprobe_multi_func_2")
 int uprobe_2(struct pt_regs *ctx)
 {
-       return check_cookie(2, &test_uprobe_2_result);
+       return check_cookie(ctx, 2, &test_uprobe_2_result);
 }
 
 SEC("uprobe.session//proc/self/exe:uprobe_multi_func_3")
 int uprobe_3(struct pt_regs *ctx)
 {
-       return check_cookie(3, &test_uprobe_3_result);
+       return check_cookie(ctx, 3, &test_uprobe_3_result);
 }
index 8fbcd69fae2212c32dd0061b781c9a60cb3801c3..3ce309248a045b0f8713e938adc158d4b4543884 100644 (file)
@@ -1,9 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/bpf.h>
+#include <vmlinux.h>
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 #include <stdbool.h>
-#include "bpf_kfuncs.h"
 #include "bpf_misc.h"
 
 char _license[] SEC("license") = "GPL";
@@ -16,11 +15,11 @@ int idx_return = 0;
 __u64 test_uprobe_cookie_entry[6];
 __u64 test_uprobe_cookie_return[3];
 
-static int check_cookie(void)
+static int check_cookie(struct pt_regs *ctx)
 {
-       __u64 *cookie = bpf_session_cookie();
+       __u64 *cookie = bpf_session_cookie(ctx);
 
-       if (bpf_session_is_return()) {
+       if (bpf_session_is_return(ctx)) {
                if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return))
                        return 1;
                test_uprobe_cookie_return[idx_return++] = *cookie;
@@ -40,5 +39,5 @@ int uprobe_recursive(struct pt_regs *ctx)
        if (bpf_get_current_pid_tgid() >> 32 != pid)
                return 1;
 
-       return check_cookie();
+       return check_cookie(ctx);
 }