From nobody Mon Feb 9 08:56:29 2026 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) (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 5719914EC73 for ; Sat, 24 Jan 2026 03:32:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769225529; cv=none; b=qisojwvhxYZD6BHudFf0SX/S+6L7ui8fmnvUec233J9rRJJ/cFdZ6HTCXfLhAeBQEqLeBxspsYRb/X2JlR+pibtz2W1oLxtLb/lUKGXzYUKfmS5R3pJJCtOYfbc9YFdo6E6FKGy79UltmV3n4aiXanqN2p0oKDUJS+EORd0Skh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769225529; c=relaxed/simple; bh=K9b/t9XXOnTLdqEXsxRrneyFY/nndVnsOJwQPHo9UMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m60bI52GFFBLvy0FTgVuGL1/wEvpTDYXqUV/gKhRdwasbcr2axsZig6DdyOpqSOrWI6ev0WkGEf3iiRHFGYazztGKM7FoL8751TbjPa3woc20R6+BZ1tXy3mQemDLvPkqGqzKrfWFKcW+oVOSPpdXUjey4jxaXC/8HL10N8+4Xc= 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=E/05hELD; arc=none smtp.client-ip=209.85.214.194 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="E/05hELD" Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-2a07fac8aa1so22316125ad.1 for ; Fri, 23 Jan 2026 19:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769225528; x=1769830328; 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=uaR31gnegNovKwQZUAOooLQs9UdrAAfPr7JJtoM3Rv0=; b=E/05hELDH2nfp1ornuzxqqyny93J4FwgM0+/ihJlm3s9bJtm0OwjTZHyrRYLoZC7U2 os0DAhLQrmxdUMBu/rrHanQ12534tVJS9WW+0wxiAChcQ2jadYn8fERL8zvG1Z1c+cVt bElHm+NMj+1rAAUusN5n/aWFqzc4FvJIVvJnEyZmYHFsXWlJr9zXMZXRunGnjU5cgQRS 0Xkrey+bxhzBxylCTvJphm2WnIo2xJWLcOarzXG2GJfYtOlDCmgmR2GMCoYzhPY58TYs ZJzcWhjkP8gzEBlaKzT6nDBroUIE61WpCvS+/5wEu8gvox7tkNVBY2lngIDWlaX0NbMF wclA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769225528; x=1769830328; 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=uaR31gnegNovKwQZUAOooLQs9UdrAAfPr7JJtoM3Rv0=; b=c46MpnOeaIBJ/acVRLeXQi80eJM3Jr0MRzhWNcz74vZqoBCd1iSjesjgeVV+ej1Wkc PQtgVqwqC/9vBC+eX+fMAKEAtm0aAdpGv+jgARzghmUuhy9qLnh9SAZpQO0paN8IJgAm PH+Jq425V/A8diDtNFmlZJt7mORS2Qj474ESnEf6MPDFFn7amWQi8j7yUtlMBUsKJmXf 9EnOhWARI4njtKuxHuVDglG3b9UWXtJUq6Dn8r/VV2/p5/RVfMl/t8lY9qt7XL0JP5S1 4z69/jwHJXeahyzS4sEF4VfrZGHRNOcEzVVtW+SPZ3MUZd+CZom34D8nJz+lZDV9x9+d 1mPg== X-Forwarded-Encrypted: i=1; AJvYcCW7W126y8kMtxiDbqVCHJe9k2UswUk5pe99rbUZcAruLkbb40QBor7iK9SMRzPTW4bjm/A/WvF6IVPVuyw=@vger.kernel.org X-Gm-Message-State: AOJu0Yzj1q6Hw9UkSPYRriAXe2KpEgbppO8JRQuujkX1hXd05iSGzPVh 7iJ3mHXUl1CXmIpi053mMNBJCbrkth2HSlInerSp9n7jvOJWLDa1d3xg X-Gm-Gg: AZuq6aKAQTZUFyf8zBKMNjrncdWNb5Hon/+8nrQ7ZA6ZVxkvQdtey3Y6sbITX2emEKX 4ESD/ZEzJR6Vl7K8cfzhFLMwSwqrG/VeGo1VUgavDMOrIgZrnh5f5E0womTSQK+od5bBDDenNk2 nQ9vMuQD/FfpsZgRYfbXMqRWiE8pf3lkT2M0/9NRlfdvNVE+zXUfM3HLuyp2Q4SQL+JWiCiM8Xu ZZpVqT+aJMgTTMrhHf46LFyV0OdNNtmPvv+0o0k96WseyWOiMeGJguFnnq1UrGo9mjJRlrvzWQz Cq9B6Fntly+BmU4txWNvBJ/0QwtZJ7H76W37uEFx3U5M+V4QNd87HK3Q0DmXFBvxq5mHlXzeJCw qLZ1hDANQdnUfqPrn4HrGE9NxRFX/gFgXwI5nyklk6xWnnisg9/T7WSWxNS8VoVmLbUqaiBKeZp HiiOaQFQxM X-Received: by 2002:a17:903:380d:b0:2a0:9028:11af with SMTP id d9443c01a7336-2a7fe75c647mr48658585ad.59.1769225527714; Fri, 23 Jan 2026 19:32:07 -0800 (PST) Received: from 7950hx ([103.173.155.241]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a802dcddb0sm32539805ad.38.2026.01.23.19.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jan 2026 19:32:07 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: andrii@kernel.org Cc: ast@kernel.org, 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 v12 04/13] bpf: support fsession for bpf_session_is_return Date: Sat, 24 Jan 2026 11:31:10 +0800 Message-ID: <20260124033119.28682-5-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260124033119.28682-1-dongml2@chinatelecom.cn> References: <20260124033119.28682-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_IS_RETURN_SHIFT) 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_IS_RETURN_SHIFT) & 1; } Signed-off-by: Menglong Dong Co-developed-by: Leon Hwang Signed-off-by: Leon Hwang --- v11: - rename BPF_TRAMP_SHIFT_IS_RETURN to BPF_TRAMP_IS_RETURN_SHIFT 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..29eecd79352e 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1229,6 +1229,8 @@ enum { #endif }; =20 +#define BPF_TRAMP_IS_RETURN_SHIFT 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 0fa73d56cb8b..d04aea235a12 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -23011,6 +23011,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_IS_RETURN_SHIFT) & 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_IS_RETURN_SH= IFT); + 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 13f0a2de33b7..f7baeb8278ca 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 * @@ -3341,34 +3349,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