From nobody Mon Feb 9 20:31:15 2026 Received: from mail-yw1-f195.google.com (mail-yw1-f195.google.com [209.85.128.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 561B227A92E for ; Wed, 7 Jan 2026 06:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767768323; cv=none; b=tE+NOm4IjzEljB7F9ZT8n+WlimsBoRj5lBvKbl/Y9VxKV4Ra3cyGDfdVhCir8lqWxVyi6KmEC1bkVlyhFI/PO/m0kPq7t1IUTZEbnSd9ZNh6MUK6kBXPVuVlWYznCpYnYpGkkG0TSZ3cg+BUAKNbJzXyISuVSU6KgAR0s3DbMZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767768323; c=relaxed/simple; bh=XHarCaGaxO4UOuhsLfcJy1QlrtGM5hU6MX1y6/kQaWI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AO+WyZVdSrBWI5LFTtryuj7VnbRMccLVuq+UQS+QpwQ1WpIhqpeqRIPdtyGeJcaYo2/Z9ncQBjKRRT3Zz6ENRa9ju66AIk3ihl1m3aczII9juaCd5UnAaYCHgET8ENILSzymP148dMRB4U/Mm33Rigi8TXWvz8c9jq+2zFxdneM= 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=CQlbokat; arc=none smtp.client-ip=209.85.128.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="CQlbokat" Received: by mail-yw1-f195.google.com with SMTP id 00721157ae682-78fb6c7874cso21289787b3.0 for ; Tue, 06 Jan 2026 22:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767768321; x=1768373121; 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=ngssSFUNq6ZVeh2IW9d/LUmz0anO5RIn1dRAez89M0E=; b=CQlbokat5/UVYYMK4IsMfRWSdQl3A2/rbIEzQiKT8rTYqaG/PlMKn58qBZHMJqY6PG pUgWkrQh6YERUCSBtfhEVNBVzGvPTramctImvSD1ANKCLpXA7dGPjRl4VOM3HpoorRlY 9XvyjwpRBtitHXWBghhzpFDsr8D3xnCHdvlkLdP7fo/OQgr0xSICPACCb0KM2geTLDSb MVJg2ffZWfFJ2CsD8N7TgV7jsQhMwews0/cH4mTk53Et0rCZXha7VKaVrKHsJ/dBZBZE 2KqBEpoZ8XborpJ5h1gRAG8W0N21iTMFbBDe5MjhP5/8YeA+SnF/DEviNzulB1+JN7qL /o5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767768321; x=1768373121; 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=ngssSFUNq6ZVeh2IW9d/LUmz0anO5RIn1dRAez89M0E=; b=mkEG18V9810BOiGqthkrGaGaK9dJ4d2OvVLX1J/uPbCZQ4NYJHuQ7wI8UBsstv1OVV /jkBPt964rIZq56rBF+amcNXER/eofQX/fivr78FMQ7mC3Uv6x0+zW2MHzUheuyP1u0W LfCTor7tWvpLASWVl6EUkNeYTyAEkaKATfgLCZtYIMQGpYeCX0Yc3eiLkdDT2QAj5MnT SIB49qEIwepWYmqKH8fDAZTtOqjaBkPlnusjDNoIHKkFy4xrigi+mXOSA/WtNs7xzdgC EO8VXR0cNLBQrIt0rYSnKqxZR2qLNXgIhUlU2niUXjb9vhVJOjPpNKzamiZPjpOSNRR2 NuBw== X-Forwarded-Encrypted: i=1; AJvYcCUZMPSHtZ9nl/3DNzARILDvE1BzN5NQhVCz8Sqhzt6Yw2j4inytZUhcUJbcQj4Xg2vnO9xSileA/oyn1ls=@vger.kernel.org X-Gm-Message-State: AOJu0YyUuA9WUueuR2D5UHyQvw+hBzQjeSE+q/qH6tQnAQz0rde2kD31 30jK8WquI4JJLlXJky98t8zdXnVT/U17F3V3AVLPatmbx+Nb3b0+f839 X-Gm-Gg: AY/fxX6rXVyZUvniOzUNay6m5AyoGWQvczl7Qb3oQ2tUl5BbZDzoNes+LXBOyqvVubh dU9fryLztiTEc1aTYe1opjk3C7LhrGTAiLBKV3YMjTJIFjlUedY8lcHsKlF8v1R5eCz2/cU72mg GSu+GCTLNd2CCouJnNOoLvpIirWD0DFO78dVQsqCLvnmP/21Rv2h73+Thw3z1zTVcfXfqgf0asJ rnu15EMe6TN66zI50r/KFDdLRfk3ZQCetlzrF+t44MomIhxnkBpBc2Ghn0bRfrbdFjQFxjF7FhN +Nr6t2kXNKwfo7VzlldDObOz8tBrt6Up326nMUItOcEadqSKq1ddOelcHRR8O/cv9gzL3NMcuDo gatCCDHoTTRZo/Zb5eT/6RI0OWoRCCKRq5HtvaAN9s2n0aaLofjaWuA3WHRo7e7JMQRYZrRHMWd J6p9/88vq2NzmOjndxfA== X-Google-Smtp-Source: AGHT+IFQwZ8JqUgzAhI97yEdL+gAVwRf+HPm2jxhPz+VXVx31xofYms+tNraAMtA1CL3y+eUpP+gmA== X-Received: by 2002:a05:690c:c85:b0:784:aec5:7042 with SMTP id 00721157ae682-790b567cc26mr18001097b3.38.1767768321214; Tue, 06 Jan 2026 22:45:21 -0800 (PST) Received: from 7940hx ([23.94.188.235]) by smtp.gmail.com with ESMTPSA id 00721157ae682-790b1be88dcsm9635047b3.47.2026.01.06.22.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 22:45:20 -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 v7 07/11] bpf,x86: add fsession support for x86_64 Date: Wed, 7 Jan 2026 14:43:48 +0800 Message-ID: <20260107064352.291069-8-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260107064352.291069-1-dongml2@chinatelecom.cn> References: <20260107064352.291069-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 BPF_TRACE_FSESSION supporting to x86_64, including: 1. clear the return value in the stack before fentry to make the fentry of the fsession can only get 0 with bpf_get_func_ret(). 2. clear all the session cookies' value in the stack. 2. store the index of the cookie to ctx[-1] before the calling to fsession 3. store the "is_return" flag to ctx[-1] before the calling to fexit of the fsession. Signed-off-by: Menglong Dong Co-developed-by: Leon Hwang Signed-off-by: Leon Hwang --- v5: - add the variable "func_meta" - define cookie_off in a new line v4: - some adjustment to the 1st patch, such as we get the fsession prog from fentry and fexit hlist - remove the supporting of skipping fexit with fentry return non-zero v2: - add session cookie support - add the session stuff after return value, instead of before nr_args --- arch/x86/net/bpf_jit_comp.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index a87304161d45..32c13175bc65 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -3094,12 +3094,17 @@ static int emit_cond_near_jump(u8 **pprog, void *fu= nc, void *ip, u8 jmp_cond) static int invoke_bpf(const struct btf_func_model *m, u8 **pprog, struct bpf_tramp_links *tl, int stack_size, int run_ctx_off, bool save_ret, - void *image, void *rw_image) + void *image, void *rw_image, u64 func_meta) { int i; u8 *prog =3D *pprog; =20 for (i =3D 0; i < tl->nr_links; i++) { + if (tl->links[i]->link.prog->call_session_cookie) { + /* 'stack_size + 8' is the offset of func_md in stack */ + emit_st_r0_imm64(&prog, func_meta, stack_size + 8); + func_meta -=3D (1 << BPF_TRAMP_M_COOKIE); + } if (invoke_bpf_prog(m, &prog, tl->links[i], stack_size, run_ctx_off, save_ret, image, rw_image)) return -EINVAL; @@ -3222,7 +3227,9 @@ static int __arch_prepare_bpf_trampoline(struct bpf_t= ramp_image *im, void *rw_im struct bpf_tramp_links *fexit =3D &tlinks[BPF_TRAMP_FEXIT]; struct bpf_tramp_links *fmod_ret =3D &tlinks[BPF_TRAMP_MODIFY_RETURN]; void *orig_call =3D func_addr; + int cookie_off, cookie_cnt; u8 **branches =3D NULL; + u64 func_meta; u8 *prog; bool save_ret; =20 @@ -3290,6 +3297,11 @@ static int __arch_prepare_bpf_trampoline(struct bpf_= tramp_image *im, void *rw_im =20 ip_off =3D stack_size; =20 + cookie_cnt =3D bpf_fsession_cookie_cnt(tlinks); + /* room for session cookies */ + stack_size +=3D cookie_cnt * 8; + cookie_off =3D stack_size; + stack_size +=3D 8; rbx_off =3D stack_size; =20 @@ -3383,9 +3395,19 @@ static int __arch_prepare_bpf_trampoline(struct bpf_= tramp_image *im, void *rw_im } } =20 + if (bpf_fsession_cnt(tlinks)) { + /* clear all the session cookies' value */ + for (int i =3D 0; i < cookie_cnt; i++) + emit_st_r0_imm64(&prog, 0, cookie_off - 8 * i); + /* clear the return value to make sure fentry always get 0 */ + emit_st_r0_imm64(&prog, 0, 8); + } + func_meta =3D nr_regs + (((cookie_off - regs_off) / 8) << BPF_TRAMP_M_COO= KIE); + if (fentry->nr_links) { if (invoke_bpf(m, &prog, fentry, regs_off, run_ctx_off, - flags & BPF_TRAMP_F_RET_FENTRY_RET, image, rw_image)) + flags & BPF_TRAMP_F_RET_FENTRY_RET, image, rw_image, + func_meta)) return -EINVAL; } =20 @@ -3445,9 +3467,14 @@ static int __arch_prepare_bpf_trampoline(struct bpf_= tramp_image *im, void *rw_im } } =20 + /* set the "is_return" flag for fsession */ + func_meta +=3D (1 << BPF_TRAMP_M_IS_RETURN); + if (bpf_fsession_cnt(tlinks)) + emit_st_r0_imm64(&prog, func_meta, nregs_off); + if (fexit->nr_links) { if (invoke_bpf(m, &prog, fexit, regs_off, run_ctx_off, - false, image, rw_image)) { + false, image, rw_image, func_meta)) { ret =3D -EINVAL; goto cleanup; } --=20 2.52.0