From nobody Mon Feb 9 04:14:01 2026 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) (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 0F5A23009C3 for ; Fri, 23 Jan 2026 07:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769153771; cv=none; b=JW1ykCCBOAs+LPQXQyohuYS8r/lQypbGs6HPt5KTfOd5vksJR70pEjMxZ6y5ZgTk7hvZM3xfJ8JpI5VOZYLdgJMT/XnM7c+2YTF0xuZ2NXlb6PkAZYa5lb2Nx7+lts891drmVX/3ZWRo7iWJiSM4t5QEaGk/hthnuOZCUHCWNlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769153771; c=relaxed/simple; bh=0ekXT3EqW+uWzRM1O4jaZEPlNn0dCZagrrwqgF91I9w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oWa1+t2Qr7Xq9Dz55snBIEYqFS3EnIBrnbYpNw6pcA67oQt4bltcnTB899WEEbWdTxPgr8Chr7TrSUpdNxPZG7mX3Y9v4ChoAaVN9qQRDf/+9x2jD6Lk5QNzLH6qjCSpSSpy1dVYNyXGfayDfultIzRJGYicYIbYf9JcQN1r6Lg= 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=PtbV7Wie; arc=none smtp.client-ip=209.85.216.66 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="PtbV7Wie" Received: by mail-pj1-f66.google.com with SMTP id 98e67ed59e1d1-34c2f335681so995193a91.1 for ; Thu, 22 Jan 2026 23:36:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769153769; x=1769758569; 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=M1/pgjh0eqe93B8yUS81C1/8Nmv3LHN4Xj0ukdoUHo0=; b=PtbV7WieOxyQBcuj0naF5cnCh81BcSYesvL0Z1j8RIQUTw9J0+v/YhuSn/3cb3a+N3 XbIwmYT0ik13dhMR13ZrCqFUnuWMkgUPspvALAt4mCPeCQNl3S6Auc4DzN97AgIUXOVW ekr3IZWKn4axxnoUCHGlfeOERCgHi4jlwLAJFxCOYASlNLJlGs0RdoEd1ywDfiCqG+L6 xEwLy0at4gwzm5I8bEXmHAp9qe2nPkgec9+fPB3L+sYHTYmDWkrtt0A9ClIXjlDh9Muw 3c5qPDDuxwQo9HIeypLahUI+APRig3M3VmugjWbxJbyas3lDgeC5tawoM3pOYfHZsk4F Zzbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769153769; x=1769758569; 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=M1/pgjh0eqe93B8yUS81C1/8Nmv3LHN4Xj0ukdoUHo0=; b=MlYgERL0gZ+Atmw8jkw749iLovtImuK3sPsC6gkAaPAyZNJMTaQ0PFSgJ23Nc7M0Np GBIOoqVTd0ghy0plUBSXIfPVGu5e6hKqbMHErcM6nKhTcEFQEhGxGcx7gWEBS1baBh/3 fSr5zPOe+pZ9Gwfpj6fjNB8V2qnk8frMH2sq/DenKqZ9gD2fJLIt6Tez0IRjerrw0r0s 7W16MRSeWkJfWCWtfOHmD5sSAmOLrQDUwCKjtBxJZwV2C5nYXqCIBEFSx3488XnX0WOf uEoWjIDtiZuVD+6BnrZn34NzoBXzYWzF+AAjdYwe27qOC0KcQamXsWxMuqLlVqiz9L4P qh/g== X-Forwarded-Encrypted: i=1; AJvYcCWE9nNiLR5b3t3re0NBSSoiYbzxiL4/Ha8xKKoPOQkBzKb/HkkNvSd9HsFVgjEtKqTfql19oQc0wPU1cr8=@vger.kernel.org X-Gm-Message-State: AOJu0YzhV/nC27d4HwR/1McMpO79nNW5VkJXp/B3PmTBdpO2AkcKW2P7 DaFVkNXhHYuR6OgqOmeEtFdxS7aJklILJpMJeQZNwfSnvRs+pyh5kb56 X-Gm-Gg: AZuq6aKHMzkPTp4w7JFLQc3WBxIWpQ2LVp5/HylY3DKNFj/NPjzCPZwCgrZmdnMofLP upWh/7YAzdTnHTfn5Q3snQDj8jivLvSiXeTk+PXsSkh6Zws1zq0J+GBipJGYpmk+CTnV3MrYN+e aprCYdiurSewYQlWc62Td6Q+/0sji3RrddxA2lvEFyGhEYSRmHxCRNu8PlpaqWiSuuEY9gVCrnZ uTFfM4r+aaTOzKh9J6BBh35L8yxgWHRhPZL3fxdCdMxapn1DmYbfuixHNBSZWiOCzuOk/qffe6K 6oBBjjgiXywvS5ExYt6jB99Kur11CJproOfSmjzb9zZ9FEnbdstDwYvaMO/Nv3hj8Dw6zI7CHOW E+4rzBI4JHl+DkutBMSn3SZy1HiH0TN1lkMS+9qiHz6xxROBMXTidxqMLZkGtUuwY11TuIWdoWz ygCorf4xVR X-Received: by 2002:a17:90b:35cf:b0:340:25f0:a9b with SMTP id 98e67ed59e1d1-35368f2a554mr1731481a91.33.1769153769249; Thu, 22 Jan 2026 23:36:09 -0800 (PST) Received: from 7940hx ([103.173.155.241]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8231876fd1fsm1334205b3a.69.2026.01.22.23.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 23:36:08 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: 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 v11 03/12] bpf: change prototype of bpf_session_{cookie,is_return} Date: Fri, 23 Jan 2026 15:35:23 +0800 Message-ID: <20260123073532.238985-4-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260123073532.238985-1-dongml2@chinatelecom.cn> References: <20260123073532.238985-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 b3f912ad18ba..19fd16697262 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -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, }; =20 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) =20 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 =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 d466a1503da3..13f0a2de33b7 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -3323,7 +3323,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 @@ -3331,7 +3331,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