From nobody Mon Feb 9 14:14:50 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 8BBC33246FD for ; Thu, 15 Jan 2026 11:23:41 +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=1768476222; cv=none; b=rv7Bg9buBlme9uiyrQwT0C+5iSaagFqEwQZ849epJ0F3vX4egHiLOvJmeEtC23F36Yoka0JRI8nlkbBLpMcCIrmVhDvJhg/+WceBZoJPOseD9AI73y9OtNOUxFo6yotb7ykpyHfVpV3RO9P2deOVLCAl5yatFemzzn6U5EbKdW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768476222; c=relaxed/simple; bh=h2POPUrCWHpMV2zB1+yXcWrLuXsEUmU/TGPNd3nPd+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rUt2IoUbEwyO5t51udPCzU72ji6kO6h1ak0A4pQtzyroFKMdzGl6KufUsDeMuuNZ6WCxFWUvHS1r/+aFHOg0JoXKpQ7GlyH8dPQzE0S225vs6n1/CQckZRebiGVZITGdf09eggXgVWo6bYqfjg6LesOgaP6GfPQnUQbmZ4fvIaE= 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=ZFGYVBnd; 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="ZFGYVBnd" Received: by mail-pl1-f195.google.com with SMTP id d9443c01a7336-2a137692691so5086105ad.0 for ; Thu, 15 Jan 2026 03:23:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768476221; x=1769081021; 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=8YOIKFh1qLe1Kphs2bcVuIDAoYDYGha3UsNg4tIIDho=; b=ZFGYVBndCFkxIwpg+wzCMybLlzf1tY0pUNqnwOBkBJPxyY4/DXul94brIJCKpi0QKP 1fdhc/JTsKue+raqYwPSP0q88BebwWrE6RNdCdWPDFkuEu96wdP7q1JbQxUT8iHuC+d/ oFn5XjgLBflLMeZK6d+WGBTgiWs7CZ0zJXCxL7+lW5mnX+OjUrm4EAaPBjkt6RK2yllJ uCqG7jKg1Lq8Vk9BTpiBYtj0tdrmW7LItJ4Sze6L3RRgscEs2dxBBuVWmQ0FIpOOlk2p M5wp/A73+zLRhPkliMmzCnA9x5CPFNnbWd553OYqcogbBR5uGSQFQtlH0xO0xuo2Y7Ca nb+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768476221; x=1769081021; 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=8YOIKFh1qLe1Kphs2bcVuIDAoYDYGha3UsNg4tIIDho=; b=U6ZhVKIkXpHfU+KvsC8nrniyRQYD3w2KecbHFX5Xk0QDfu+HDEsP/roIQl1UmpDhO9 qDU+/60F3WDgjCw72ZAgdza4zFsOtBrkbvopRMAxrgczQnPDue2yObI/0wxyNaCrZoyL eZhEVyOm4bLo/rmZa7uvskDdTBMunustRc3jFYnk4zXFG1xOxI4cigeB1iiBN/cvYmP/ 8u/1debVp8tG2vWslYxO0aUsIa5TWUxBOM70WgU/dtoNNhrBteiXSdSc9VynRVLCa8W6 sfhh72FPgKoodeXEc0V07Mc600LteL1giHImgPwdWpzde3H7+yuYukWfrNgyIvE8sSp2 Qi+Q== X-Forwarded-Encrypted: i=1; AJvYcCXzPIUM1b2jZDB9Rr1TQlsO5aQjcdFj+7EHY5ZWd1Cl/daIs65jkGSrVCQw4zW8JbTC4RHO16UIhBo34lE=@vger.kernel.org X-Gm-Message-State: AOJu0YynVwldXM1h9A+zKdQ7R6z1RlejzdL4oEo5tWcSLj/aecfaLXR9 IKiVIUGWyaap2sg8n2cjuxVW8BFGO4mWCgzX1rzybVpWTYFTfBrnuKeN X-Gm-Gg: AY/fxX6ESjJOK6W4Z3xe4vgdFX/8z6LuPrjZY2uPUMKq6OqVmNe7z6Nqvh10F6VG8Ez ZhhdNsrZ8t7GOLxCBdgMGYdda+MeXNbYKprfIi3pqu4pwg9u5dW/yn9Hqa42DZJFjEt2wMeYYde kIIsY8EAzmEgXvxhnHIGZLZIBvEGtkbSq33fnPx29s1WROVWfAbrqADs4DRrG8GxZtcxpXdqJl+ d5XETuqGKpr7VZYnPwkHKned7UmyXvSLhLmNUWkhIJatIamBYuEQhhNPMYt8Ti46PSuXipbmOmD //YyLvWi9RagmeFaM80kY6zvRpo+79V9JmyzRZQAaxgwo2HLOUTkMUXjegW+Fltgjcoi7EHTFLG E6q0Kh2AU+gAhJGkaN2D84Mg7eMlvT1R03risCzhJdtPQFbGraAW3bb0bru+z4qphrld1qaIrBZ 26unM0IMA= X-Received: by 2002:a17:903:2f8a:b0:295:59ef:809e with SMTP id d9443c01a7336-2a59bb37a31mr53429035ad.24.1768476220937; Thu, 15 Jan 2026 03:23:40 -0800 (PST) Received: from 7940hx ([160.187.0.149]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3ba03f9sm248523225ad.0.2026.01.15.03.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 03:23:40 -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 04/12] bpf: support fsession for bpf_session_is_return Date: Thu, 15 Jan 2026 19:22:38 +0800 Message-ID: <20260115112246.221082-5-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" If fsession exists, we will use the bit (1 << BPF_TRAMP_SHIFT_IS_RETURN) in ((u64 *)ctx)[-1] to store the "is_return" flag. The logic of bpf_session_is_return() for fsession is implemented in the verifier by inline following code: bool bpf_session_is_return(void *ctx) { return (((u64 *)ctx)[-1] >> BPF_TRAMP_SHIFT_IS_RETURN) & 1; } Signed-off-by: Menglong Dong Co-developed-by: Leon Hwang Signed-off-by: Leon Hwang --- v10: - fix the wrong description of bpf_session_is_return() in commit log and comment - rename the prefix from BPF_TRAMP_M_ tp BPF_TRAMP_SHIFT_ - remove the definition of BPF_TRAMP_M_NR_ARGS - use 63 for the shift of BPF_TRAMP_SHIFT_IS_RETURN - check the program type in bpf_session_filter() v9: - remove the definition of bpf_fsession_is_return() v7: - reuse the kfunc bpf_session_is_return() instead of introduce new kfunc v4: - split out the bpf_fsession_cookie() to another patch v3: - merge the bpf_tracing_is_exit and bpf_fsession_cookie into a single patch v2: - store the session flags after return value, instead of before nr_args - inline the bpf_tracing_is_exit, as Jiri suggested --- include/linux/bpf.h | 2 ++ kernel/bpf/verifier.c | 13 +++++++++++++ kernel/trace/bpf_trace.c | 39 ++++++++++++++++++++++++++------------- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 41228b0add52..4f72d553f52b 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1229,6 +1229,8 @@ enum { #endif }; =20 +#define BPF_TRAMP_SHIFT_IS_RETURN 63 + struct bpf_tramp_links { struct bpf_tramp_link *links[BPF_MAX_TRAMP_LINKS]; int nr_links; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 1ed41ba8b54c..2efe458f9bad 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -22604,6 +22604,19 @@ static int fixup_kfunc_call(struct bpf_verifier_en= v *env, struct bpf_insn *insn, desc->func_id =3D=3D special_kfunc_list[KF_bpf_rdonly_cast]) { insn_buf[0] =3D BPF_MOV64_REG(BPF_REG_0, BPF_REG_1); *cnt =3D 1; + } else if (desc->func_id =3D=3D special_kfunc_list[KF_bpf_session_is_retu= rn] && + env->prog->expected_attach_type =3D=3D BPF_TRACE_FSESSION) { + /* + * inline the bpf_session_is_return() for fsession: + * bool bpf_session_is_return(void *ctx) + * { + * return (((u64 *)ctx)[-1] >> BPF_TRAMP_SHIFT_IS_RETURN) & 1; + * } + */ + insn_buf[0] =3D BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8); + insn_buf[1] =3D BPF_ALU64_IMM(BPF_RSH, BPF_REG_0, BPF_TRAMP_SHIFT_IS_RET= URN); + insn_buf[2] =3D BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 1); + *cnt =3D 3; } =20 if (env->insn_aux_data[insn_idx].arg_prog) { diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 297dcafb2c55..3f5460a6da47 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1286,7 +1286,8 @@ static bool is_kprobe_multi(const struct bpf_prog *pr= og) =20 static inline bool is_kprobe_session(const struct bpf_prog *prog) { - return prog->expected_attach_type =3D=3D BPF_TRACE_KPROBE_SESSION; + return prog->type =3D=3D BPF_PROG_TYPE_KPROBE && + prog->expected_attach_type =3D=3D BPF_TRACE_KPROBE_SESSION; } =20 static inline bool is_uprobe_multi(const struct bpf_prog *prog) @@ -1297,7 +1298,14 @@ static inline bool is_uprobe_multi(const struct bpf_= prog *prog) =20 static inline bool is_uprobe_session(const struct bpf_prog *prog) { - return prog->expected_attach_type =3D=3D BPF_TRACE_UPROBE_SESSION; + return prog->type =3D=3D BPF_PROG_TYPE_KPROBE && + prog->expected_attach_type =3D=3D BPF_TRACE_UPROBE_SESSION; +} + +static inline bool is_trace_fsession(const struct bpf_prog *prog) +{ + return prog->type =3D=3D BPF_PROG_TYPE_TRACING && + prog->expected_attach_type =3D=3D BPF_TRACE_FSESSION; } =20 static const struct bpf_func_proto * @@ -3334,34 +3342,39 @@ __bpf_kfunc __u64 *bpf_session_cookie(void *ctx) =20 __bpf_kfunc_end_defs(); =20 -BTF_KFUNCS_START(kprobe_multi_kfunc_set_ids) +BTF_KFUNCS_START(session_kfunc_set_ids) BTF_ID_FLAGS(func, bpf_session_is_return) BTF_ID_FLAGS(func, bpf_session_cookie) -BTF_KFUNCS_END(kprobe_multi_kfunc_set_ids) +BTF_KFUNCS_END(session_kfunc_set_ids) =20 -static int bpf_kprobe_multi_filter(const struct bpf_prog *prog, u32 kfunc_= id) +static int bpf_session_filter(const struct bpf_prog *prog, u32 kfunc_id) { - if (!btf_id_set8_contains(&kprobe_multi_kfunc_set_ids, kfunc_id)) + if (!btf_id_set8_contains(&session_kfunc_set_ids, kfunc_id)) return 0; =20 - if (!is_kprobe_session(prog) && !is_uprobe_session(prog)) + if (!is_kprobe_session(prog) && !is_uprobe_session(prog) && !is_trace_fse= ssion(prog)) return -EACCES; =20 return 0; } =20 -static const struct btf_kfunc_id_set bpf_kprobe_multi_kfunc_set =3D { +static const struct btf_kfunc_id_set bpf_session_kfunc_set =3D { .owner =3D THIS_MODULE, - .set =3D &kprobe_multi_kfunc_set_ids, - .filter =3D bpf_kprobe_multi_filter, + .set =3D &session_kfunc_set_ids, + .filter =3D bpf_session_filter, }; =20 -static int __init bpf_kprobe_multi_kfuncs_init(void) +static int __init bpf_trace_kfuncs_init(void) { - return register_btf_kfunc_id_set(BPF_PROG_TYPE_KPROBE, &bpf_kprobe_multi_= kfunc_set); + int err =3D 0; + + err =3D err ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_KPROBE, &bpf_sessi= on_kfunc_set); + err =3D err ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &bpf_sess= ion_kfunc_set); + + return err; } =20 -late_initcall(bpf_kprobe_multi_kfuncs_init); +late_initcall(bpf_trace_kfuncs_init); =20 typedef int (*copy_fn_t)(void *dst, const void *src, u32 size, struct task= _struct *tsk); =20 --=20 2.52.0