Commit 8fe4dc4f authored by Menglong Dong's avatar Menglong Dong Committed by Alexei Starovoitov
Browse files

bpf: change prototype of bpf_session_{cookie,is_return}



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: default avatarMenglong Dong <dongml2@chinatelecom.cn>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20260124062008.8657-4-dongml2@chinatelecom.cn


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent f1b56b3c
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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 &&
+2 −2
Original line number Diff line number Diff line
@@ -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;

+0 −3
Original line number Diff line number Diff line
@@ -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
+7 −8
Original line number Diff line number Diff line
// 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);
}
+3 −4
Original line number Diff line number Diff line
// 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));
}
Loading