From nobody Mon Feb 9 12:25:09 2026 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 289CB2D94BA for ; Thu, 15 Jan 2026 11:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768476213; cv=none; b=q8OB+/EHPsDJzEMiJ+FnOwYNHuaTy0V3JnjfBKeBt4KUXdZ5DUS77Wj9BHQlq3wDWEBrqssD/B/lrtGJwdaJ+BLCDM8xSW+JV86hSivlPma+f3hRoP7TqgQ8MNlMv+Ddlq/iEyHX29v008l+RmNtjwXYCZRMROyqbbb1mQH/OQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768476213; c=relaxed/simple; bh=JKCHfq/RfD0Iu7xpNMldqPQCwqMrsRWsliZhXQHUBMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PBR1rxsxluYeDiAj/wtDD48UuXlG7msExhvleQ+mXRQRsVtERgn7TFYo3NDFNKYI6aGOKy3pJzAzFxJ9VrRy33bYr61NW9t37bfKhXIv+gI0Iu/hS1F4R0mhoPXouGpdTRRYfygKufNEch2V3eGxTdQ5y+iLG1K9wDNnGiTunm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NGuap/zh; arc=none smtp.client-ip=209.85.214.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NGuap/zh" Received: by mail-pl1-f195.google.com with SMTP id d9443c01a7336-29f2676bb21so7572845ad.0 for ; Thu, 15 Jan 2026 03:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768476211; x=1769081011; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zknBPP+RIEO6/XhrUklVV0uXdmqx/DuLBRgSks+XejI=; b=NGuap/zhPJYPOM0DxyNmT9ytXECN1+mwQl+XCix3NTk7sgtEQhhWwhg8AR7uSZa2EF ayebdT2ZwVq4tRjJHh4ULijzrutB1Gwf+1M6EO4QNIXesB9YWY482dnIAhzMw+pSbfqn CyWQ7GPcKbWH1WAzghr+Q74286UppqPGuE9mDBDHFt6e/D4JLfjo3btj5NRGHrhv30pt UyI3e1gl4ugA1/ou2lCbdKstYSb8vA42Wg3bXCnlJ2KXLq1PIA2dXI0qDigXAZXrxw2Z UoVHTO45C3dncHlb0FIaWZBztVl/HrqmQ25TeJfQNq9dOnjbh3wUb/no7lt7XPJ/PvJa Ldtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768476211; x=1769081011; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zknBPP+RIEO6/XhrUklVV0uXdmqx/DuLBRgSks+XejI=; b=ocahANmZUsm3lAGjOh8EJNd35wFgHdaE4WQX51r2LBwPyTYxHmFo/xBnT9BiSxqBb/ Zf6DZPWBH1EDfW0NWFUQVNKZckahpz/OPYeGccaQ5eRAsZ8n2jSC0La/sEX8ll+d1s+z ZWiZUW1VfVnp5+uwCw0Qoxns1WMGeNpb18+1ruUUQwMghXu0YI2PdDnYVyml2Qi9jNeL 2K96SvjZ0VH5X0+hakgF1RC0HAnoKeGeIBgL7unyl5jdT+GKlxiURZuMXfBu6S+df1PE dFmaAnxGP12M7r6COSuYgPmHvrGtBzlrN1R9CbP/6MxQgp0CHRiqMr8D55CgZUzdiQqA XRCw== X-Forwarded-Encrypted: i=1; AJvYcCVnBaH9w6lFAiQ/KU9C8D8nyGTVjBgphUG8XasYQzrGHbBXhX36H8orUQjhQIyV4Yvn6QGu0oOzLmtCD98=@vger.kernel.org X-Gm-Message-State: AOJu0Yxz/i/vvEF+vUWXc9DX6Q0IXt1yrx23r3Tf2nOctV0Q87ucVnmX CpmNgaicpcvl5fvHFF0IIM5E+Ixp4AW0fYkkFYlJhIrof6J1erhEJACz X-Gm-Gg: AY/fxX4BzZE2+H1QA71IVSCq9Rf28sutIKIKv+oxD/CBXV+rCuGPHQ0PL+zoGR+zsuB BD3mLxUb1dD2Kz4Cv/6HZk0khe3n9TfayNZkwiex4/UmzCjQuj/psfHpGziFjaPXghPcyQkrBmQ JiuvH5y2TOW4zTjAPooDCBkTcEh14J2ujBZob0cVMV6bH2vHi+JXDEbrjDe4dziLcj1lkaboPYD igmZJybi6+qOraKCi4rdWJEVgo2pgi1JRMCjlLc+YfqkjuhuhLEY0l0geoSGVaiXBx80HFLNd2q 65+s9K9rDyTvqZ02zt+cajwrMYTTcP/YHRAc2jLp89Rpj78J2nUmdToHPEza93juXjRwCUkhdKf 9+P2Iafi2jmvDpBVQ6iaWObR0Sq8dmP2ebEvRn6WsOjbRAe6BRB21BCHz4bE/3NzZSKrJPQXnMd PNRlcY6GPpvWUxpfkE1g== X-Received: by 2002:a17:903:f86:b0:2a0:de4f:cad with SMTP id d9443c01a7336-2a599e719e7mr53720365ad.60.1768476211241; Thu, 15 Jan 2026 03:23:31 -0800 (PST) Received: from 7940hx ([160.187.0.149]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3ba03f9sm248523225ad.0.2026.01.15.03.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 03:23:30 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@kernel.org, andrii@kernel.org Cc: daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, dsahern@kernel.org, tglx@linutronix.de, mingo@redhat.com, jiang.biao@linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v10 03/12] bpf: change prototype of bpf_session_{cookie,is_return} Date: Thu, 15 Jan 2026 19:22:37 +0800 Message-ID: <20260115112246.221082-4-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115112246.221082-1-dongml2@chinatelecom.cn> References: <20260115112246.221082-1-dongml2@chinatelecom.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Andrii Nakryiko --- v10: - drop the declaration of bpf_session_is_return() and bpf_session_cookie() --- kernel/bpf/verifier.c | 6 +++++- kernel/trace/bpf_trace.c | 4 ++-- tools/testing/selftests/bpf/bpf_kfuncs.h | 3 --- .../bpf/progs/kprobe_multi_session_cookie.c | 15 +++++++-------- .../selftests/bpf/progs/uprobe_multi_session.c | 7 +++---- .../bpf/progs/uprobe_multi_session_cookie.c | 15 +++++++-------- .../bpf/progs/uprobe_multi_session_recursive.c | 11 +++++------ 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index f7eec19df803..1ed41ba8b54c 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -12370,6 +12370,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, }; =20 BTF_ID_LIST(special_kfunc_list) @@ -12447,6 +12448,7 @@ BTF_ID(func, bpf_task_work_schedule_resume_impl) 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) =20 static bool is_task_work_add_kfunc(u32 func_id) { @@ -12501,7 +12503,9 @@ get_kfunc_ptr_arg_type(struct bpf_verifier_env *env, struct bpf_reg_state *reg =3D ®s[regno]; bool arg_mem_size =3D false; =20 - if (meta->func_id =3D=3D special_kfunc_list[KF_bpf_cast_to_kern_ctx]) + if (meta->func_id =3D=3D special_kfunc_list[KF_bpf_cast_to_kern_ctx] || + meta->func_id =3D=3D special_kfunc_list[KF_bpf_session_is_return] || + meta->func_id =3D=3D special_kfunc_list[KF_bpf_session_cookie]) return KF_ARG_PTR_TO_CTX; =20 if (argno + 1 < nargs && diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 5f621f0403f8..297dcafb2c55 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3316,7 +3316,7 @@ static u64 bpf_uprobe_multi_entry_ip(struct bpf_run_c= tx *ctx) =20 __bpf_kfunc_start_defs(); =20 -__bpf_kfunc bool bpf_session_is_return(void) +__bpf_kfunc bool bpf_session_is_return(void *ctx) { struct bpf_session_run_ctx *session_ctx; =20 @@ -3324,7 +3324,7 @@ __bpf_kfunc bool bpf_session_is_return(void) return session_ctx->is_return; } =20 -__bpf_kfunc __u64 *bpf_session_cookie(void) +__bpf_kfunc __u64 *bpf_session_cookie(void *ctx) { struct bpf_session_run_ctx *session_ctx; =20 diff --git a/tools/testing/selftests/bpf/bpf_kfuncs.h b/tools/testing/selft= ests/bpf/bpf_kfuncs.h index e0189254bb6e..7dad01439391 100644 --- a/tools/testing/selftests/bpf/bpf_kfuncs.h +++ b/tools/testing/selftests/bpf/bpf_kfuncs.h @@ -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; =20 -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 diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_session_cookie.= c b/tools/testing/selftests/bpf/progs/kprobe_multi_session_cookie.c index 0835b5edf685..ad627016e3e5 100644 --- a/tools/testing/selftests/bpf/progs/kprobe_multi_session_cookie.c +++ b/tools/testing/selftests/bpf/progs/kprobe_multi_session_cookie.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -#include +#include #include #include #include -#include "bpf_kfuncs.h" =20 char _license[] SEC("license") =3D "GPL"; =20 @@ -23,16 +22,16 @@ int BPF_PROG(trigger) return 0; } =20 -static int check_cookie(__u64 val, __u64 *result) +static int check_cookie(struct pt_regs *ctx, __u64 val, __u64 *result) { __u64 *cookie; =20 if (bpf_get_current_pid_tgid() >> 32 !=3D pid) return 1; =20 - cookie =3D bpf_session_cookie(); + cookie =3D bpf_session_cookie(ctx); =20 - if (bpf_session_is_return()) + if (bpf_session_is_return(ctx)) *result =3D *cookie =3D=3D val ? val : 0; else *cookie =3D 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); } =20 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); } =20 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); } diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_session.c b/too= ls/testing/selftests/bpf/progs/uprobe_multi_session.c index 30bff90b68dc..6e46bb00ff58 100644 --- a/tools/testing/selftests/bpf/progs/uprobe_multi_session.c +++ b/tools/testing/selftests/bpf/progs/uprobe_multi_session.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -#include +#include #include #include #include -#include "bpf_kfuncs.h" #include "bpf_misc.h" =20 char _license[] SEC("license") =3D "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)); } =20 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)); } diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.= c b/tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.c index 5befdf944dc6..b5db196614a9 100644 --- a/tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.c +++ b/tools/testing/selftests/bpf/progs/uprobe_multi_session_cookie.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -#include +#include #include #include #include -#include "bpf_kfuncs.h" =20 char _license[] SEC("license") =3D "GPL"; =20 @@ -13,16 +12,16 @@ __u64 test_uprobe_1_result =3D 0; __u64 test_uprobe_2_result =3D 0; __u64 test_uprobe_3_result =3D 0; =20 -static int check_cookie(__u64 val, __u64 *result) +static int check_cookie(struct pt_regs *ctx, __u64 val, __u64 *result) { __u64 *cookie; =20 if (bpf_get_current_pid_tgid() >> 32 !=3D pid) return 1; =20 - cookie =3D bpf_session_cookie(); + cookie =3D bpf_session_cookie(ctx); =20 - if (bpf_session_is_return()) + if (bpf_session_is_return(ctx)) *result =3D *cookie =3D=3D val ? val : 0; else *cookie =3D 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); } =20 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); } =20 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); } diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursi= ve.c b/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c index 8fbcd69fae22..3ce309248a04 100644 --- a/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c +++ b/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c @@ -1,9 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 -#include +#include #include #include #include -#include "bpf_kfuncs.h" #include "bpf_misc.h" =20 char _license[] SEC("license") =3D "GPL"; @@ -16,11 +15,11 @@ int idx_return =3D 0; __u64 test_uprobe_cookie_entry[6]; __u64 test_uprobe_cookie_return[3]; =20 -static int check_cookie(void) +static int check_cookie(struct pt_regs *ctx) { - __u64 *cookie =3D bpf_session_cookie(); + __u64 *cookie =3D bpf_session_cookie(ctx); =20 - if (bpf_session_is_return()) { + if (bpf_session_is_return(ctx)) { if (idx_return >=3D ARRAY_SIZE(test_uprobe_cookie_return)) return 1; test_uprobe_cookie_return[idx_return++] =3D *cookie; @@ -40,5 +39,5 @@ int uprobe_recursive(struct pt_regs *ctx) if (bpf_get_current_pid_tgid() >> 32 !=3D pid) return 1; =20 - return check_cookie(); + return check_cookie(ctx); } --=20 2.52.0