From nobody Sun Feb 8 13:53:20 2026 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 843BB2C11F9 for ; Sun, 8 Feb 2026 05:33:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770528819; cv=none; b=nL3rL9p7evst4m3BISQEBhejGS18gRJW+5rqR+YVPu5dlhWIj+hS8ifZQ2Sbzp/LVYsjVc5jqtmidYrLFNA+ZUcrxI8SvDoijQkGdwHgXTFthlxETw2lEA3Y1Mbf2FjFrMN5vg+XQBStiDMc28rgFqfSurBnIcpNEBIvMzv9VmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770528819; c=relaxed/simple; bh=w5NGJ74MU5R3R7DpzqJ2S6IYEkng2ht1IhcPzlGqqV0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o2SDchJSOhAtbu97HRZnP1gg+Cga3bT7ZlYWC44l0NwmAgVMeq9l4F7wEvtO9vuxeZiQrLcMs3BTP444vD61Zj7mw7yTaNi+mlRvzV35ffjyMe9f1H2SOGPv0ResPBmLMo6YyV6o1fjNIraC7FvVUX8GUCBBecIhlNaQiVSnPqY= 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=EHUyP4NB; arc=none smtp.client-ip=209.85.210.196 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="EHUyP4NB" Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-8230c33f477so1511246b3a.2 for ; Sat, 07 Feb 2026 21:33:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770528819; x=1771133619; 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=n5ZW0Lp2uS+rJ6cqos6DM9CIgCyO+gQDhoGFyA1Jyks=; b=EHUyP4NBoGN4+XwzfP5woCcMdB9jBrh8cpVos3rrhvHMorS6Ke4mgh9UzE8+RwBJkl V0rIz/slOaF3Gguyetsx+dJor55wlQbzKd+CANNPtPzNzFrs9c5Ym6sFHhbvbpOTaooh vNuyzPMbzB9Gg+lCEVxmM7duuYUWQ+GK3TZb4qAtotRMWu7Pxi3YumI9lv8a8A3rQY0o yJGxhnNFjrsbWOuxMwRKHY/nkTOty0iHmxnrzTbmslqTxC3gWXReg3pKHvzF2FGDaUEu jBner1dvUQLaG21c6A9yyeTEkpjxq2hcpx1SthWkgUBy1FbpJV8FDPaz35Cz/VoQX7aK md4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770528819; x=1771133619; 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=n5ZW0Lp2uS+rJ6cqos6DM9CIgCyO+gQDhoGFyA1Jyks=; b=PYN4OJWbvoEFzlkxfYUK6FzdjbTMJnSw3lGheZQYI480SmtfQ0f8AuKjL5Hqj+1xHr mBez1OSh3Tt+kyC0xQl00cqQOeMh7+DNeQSk/n93rXNWSjBwNwUfYRmPBHhtM3wuVuL+ dfLSisIUjw4D0o2rp2dq1UMtOWtEiZ6VJyruF3MC7FGyrCGigDzqxeeSvbZTLMRrOlvJ Jn9Kv9t/q/dMcvXLgiqLORTZPeajmOZUYuj8NSCMiQyB5P/NmhRbydCM8jWw+/uVsuI4 U1VGKsz5Q85LjHmBmVs1wybYTFDzI1j0Q5c80NnNF3YBh0xyhussADE8e+1j2Yj9TCo4 iCWA== X-Forwarded-Encrypted: i=1; AJvYcCXgYB/uvaXBInge0Nhs3W8bXDWpGwq8F1pOV2JoycUXBfYqzQi0pj4r9Qrqwq6PL1Go6P1mRsHhpdNbLrs=@vger.kernel.org X-Gm-Message-State: AOJu0Yyl6C0H//vrkIgGMp/Os4/u5vATeZv7H0A28bJfhQBZq5gVGFaf djE/gQ7NGLe/0u4+etYbD0mX+dSBMTz+tYW1cI5pzwm0p9YYiG/BeNVb X-Gm-Gg: AZuq6aILxVNe+p5UdPwVPOqTSTcZJ28u9fZjsXIXM7rqCRnVMQUDTQNnl7u1gwg9GSV ptcWfhbb+nuyhBA7hcoAR/H383RVjttIvndOtM/uRUICxvsB0TyENOSxHUhGRM4eEo0Sp2nKu47 EyF5fIcNgZMyiMP0vj/a2UQtYcz76FW7zEJWNAOP15r6KNg1FQ5eqQ2br50YfK6RgAsAOeb7GLb 1gPT8zYCFnwbKhBXwvAB1LpT+G5qnEcChjAjyRTeNLbhXtj2Zw0KyakIRhoCOLM1RcBOLmj/+Sh i6M5BIu+FkzUkQlhe6IuxHKAuPT1g/CV4bUjgQF2PfUeCvgaS6oFmyL4Fj9QY/RmfD9Q5ussZ45 ZvRXzkikfFoj6JSH7gYKTjNd3k2mw5E0mYwA02bzIUJQAo7JgVK3vjwL2ENg2qFs5DOnqiLshs/ 4U8UlL8kOB X-Received: by 2002:a05:6a00:bb88:b0:81f:8084:7ea0 with SMTP id d2e1a72fcca58-824416005d3mr7456957b3a.7.1770528818761; Sat, 07 Feb 2026 21:33:38 -0800 (PST) Received: from 7950hx ([103.173.155.241]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-824418de80dsm6067700b3a.62.2026.02.07.21.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Feb 2026 21:33:38 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@kernel.org, bjorn@kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, 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, pulehui@huawei.com, puranjay@kernel.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, jiang.biao@linux.dev Subject: [PATCH bpf-next v4 1/3] bpf, riscv: introduce emit_store_stack_imm64() for trampoline Date: Sun, 8 Feb 2026 13:33:09 +0800 Message-ID: <20260208053311.698352-2-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260208053311.698352-1-dongml2@chinatelecom.cn> References: <20260208053311.698352-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Introduce a helper to store 64-bit immediate on the trampoline stack with a help of a register. Signed-off-by: Menglong Dong Tested-by: Bj=C3=B6rn T=C3=B6pel Acked-by: Bj=C3=B6rn T=C3=B6pel --- arch/riscv/net/bpf_jit_comp64.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp6= 4.c index 37888abee70c..e4f45e2e7e2f 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -926,6 +926,14 @@ static void restore_stack_args(int nr_stack_args, int = args_off, int stk_arg_off, } } =20 +static void emit_store_stack_imm64(u8 reg, int stack_off, u64 imm64, + struct rv_jit_context *ctx) +{ + /* Load imm64 into reg and store it at [FP + stack_off]. */ + emit_imm(reg, (s64)imm64, ctx); + emit_sd(RV_REG_FP, stack_off, reg, ctx); +} + static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int ret= val_off, int run_ctx_off, bool save_ret, struct rv_jit_context *ctx) { @@ -933,12 +941,10 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, = int args_off, int retval_of struct bpf_prog *p =3D l->link.prog; int cookie_off =3D offsetof(struct bpf_tramp_run_ctx, bpf_cookie); =20 - if (l->cookie) { - emit_imm(RV_REG_T1, l->cookie, ctx); - emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_T1, ctx); - } else { + if (l->cookie) + emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, = ctx); + else emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_ZERO, ctx); - } =20 /* arg1: prog */ emit_imm(RV_REG_A0, (const s64)p, ctx); @@ -1123,13 +1129,10 @@ static int __arch_prepare_bpf_trampoline(struct bpf= _tramp_image *im, emit_sd(RV_REG_FP, -sreg_off, RV_REG_S1, ctx); =20 /* store ip address of the traced function */ - if (flags & BPF_TRAMP_F_IP_ARG) { - emit_imm(RV_REG_T1, (const s64)func_addr, ctx); - emit_sd(RV_REG_FP, -ip_off, RV_REG_T1, ctx); - } + if (flags & BPF_TRAMP_F_IP_ARG) + emit_store_stack_imm64(RV_REG_T1, -ip_off, (u64)func_addr, ctx); =20 - emit_li(RV_REG_T1, nr_arg_slots, ctx); - emit_sd(RV_REG_FP, -nregs_off, RV_REG_T1, ctx); + emit_store_stack_imm64(RV_REG_T1, -nregs_off, nr_arg_slots, ctx); =20 store_args(nr_arg_slots, args_off, ctx); =20 --=20 2.53.0 From nobody Sun Feb 8 13:53:20 2026 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.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 CCB4713E02A for ; Sun, 8 Feb 2026 05:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770528831; cv=none; b=koYTMI+wGBNfL1S4bPsrkhRnw/pNhIOc4aog7cJpGXp6rrkjiCHOuXpI7p0rI5/BXNXowE+s4vEHkFNM7d/VeCdvxyWBfVVzHrovGrSulWOhnM4CIraU29w6Lq1yHPYpSLKLnXFZcsnE0cPo12dCrfxnOTLcOUMTqRZLmNhNc9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770528831; c=relaxed/simple; bh=NdJfE6UGkldmnYF5SJP0QfORXRuqGjkBEOg/jafjqns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K6g38i0FqUrvROviewTf0Sx5p1HtpwB1i9nqLv5ulKR5QAspJakP2vLF1Dw7xV0GO/XGpIa/7KbNoOCSziB0iLza2f/oVdIIODrOk68EEDq5Y6BPuW5gPk/vl4JExoTaK9xklc+eP4WTKW9jl3Xe1sdQ4gPIz5Jby2Qvx7+idsw= 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=JwreA6id; arc=none smtp.client-ip=209.85.210.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="JwreA6id" Received: by mail-pf1-f194.google.com with SMTP id d2e1a72fcca58-81f4ba336b4so2746869b3a.1 for ; Sat, 07 Feb 2026 21:33:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770528831; x=1771133631; 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=uauA93iGE6XFs9gPgdNEdhBRsdXEO6OJ0ct51+bwGaI=; b=JwreA6idY1BlNaV5d+8ayDx3Z2DRsxd4NpIUri49PJTyMbzxJh+aDksR/gMhX6JAjE Pv18FNuStEo10nJ/01A34V9CsM7XPd3Jo+5LYgDf/ZJiWEdXApyRWZO7z9nqNCFspLOL I7rZr9NK5yodI5/tZ7IY8wwC480AtIHMxxYrR7PaxFsHrRSObP0/orloqz4iwQUzKx0M Fz4h+SQS3e0HEsWdwphh2BdINkenVgpYLiGTY/mUwTgPJ+lckt1w5Dw4Qdp94ygmA5T6 7ppKGV+mjZqKMxtfYR3MBXOmGm5MZSq0qDRWR+Uc19XiHIaaB9LFvXXld1Z5EHoyZNrI rFww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770528831; x=1771133631; 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=uauA93iGE6XFs9gPgdNEdhBRsdXEO6OJ0ct51+bwGaI=; b=WqqmTyALGlj1V3ayJfAYBV/OqDsDRv56LusEKU+dCfZ6D3mbhvj4GDa3KLO2JSrpGk WE3N0KJbvFzw/ZG93wh48apKABO/S8zffiCWhSYryEpgZ+uoBhf+dIGS8w3OrgVSDuqN KoW4lCqJfEUObfPUhkthUc/W3nATO/2MBdWP7ArRhBuUJIZ+97k4SksAA3QkrjnIMKbH ICAwC4FaMtxn8/hQ8wlx3qMHS8Y8agpuXJtEbRD+STW0FgMBhCcrZ62rATXSBa8c1MIz 6zIweM7bZ6duu0tlUAYP3EqguOVSi0LzAU1xDG7nCRvJTc8XvnKpgssC8Y8rvaZkiGGY cqQw== X-Forwarded-Encrypted: i=1; AJvYcCVn0q1YFD52cNC+SwjaCFr6ZEGfrmehOzCualclLbDr2snLpJmP+Va3K05s9G8MSm1PvS0eb/sugF28O+s=@vger.kernel.org X-Gm-Message-State: AOJu0YzC1p3nb2z0NaVbxCAWmdW8apUA4T9+iRNIW4WjUYQ5tMaS4sNR wp1ThZnfDIeQ6XUQI7GcSCRdJYw+/2mf0+yMpPiyAYIKd+phZ7i1txbt X-Gm-Gg: AZuq6aJcI7q58/bXKXB0byuPSg2JFS1ixpZXaqdTMOjE7N7DAL1aDieriznvAN/oal6 o0FpHN/SnRa615cW5gQ2EOBsSxewFZ3SbKX68soqCUmqxCT6RAJtpqAfXS51AxJgaaCDOzvUMBZ N/THaybckdPxOC6KKpv7KbCII2GNqlLcTJMjPEb2S/zwn/OxFA2v7iwBZIP+HKZFfnzsfes0Nkr t9GmInfpmQCoOVPSSTYzM9FhLGaz9yualR/KppX0XpaPqqJNSH4yFQHn77E0lTTFPzjj3Xuxo3/ UgxQdDQU4blcZVcFQoBoYcwet6no7RLaoTZ5sCzC0xWA9nqW8lNq1YcDZAnEIrek/r2ThzdTjv1 BXs+6SghxVpscd55WS/x+KEZQ5ht4UMCYKalH9jLCbdVjRKg/xtWh0IXwINNJXO16CsXXC4XMYx v/z9TIVnnhNKuP0EqZ0KU= X-Received: by 2002:a05:6a00:3981:b0:81f:517a:56e7 with SMTP id d2e1a72fcca58-82441655315mr6790986b3a.30.1770528831225; Sat, 07 Feb 2026 21:33:51 -0800 (PST) Received: from 7950hx ([103.173.155.241]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-824418de80dsm6067700b3a.62.2026.02.07.21.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Feb 2026 21:33:50 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@kernel.org, bjorn@kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, 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, pulehui@huawei.com, puranjay@kernel.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, jiang.biao@linux.dev Subject: [PATCH bpf-next v4 2/3] bpf, riscv: add fsession support for trampolines Date: Sun, 8 Feb 2026 13:33:10 +0800 Message-ID: <20260208053311.698352-3-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260208053311.698352-1-dongml2@chinatelecom.cn> References: <20260208053311.698352-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Implement BPF_TRACE_FSESSION support in the RISC-V trampoline JIT. The logic here is similar to what we did in x86_64. In order to simply the logic, we factor out the function invoke_bpf() for fentry and fexit. Signed-off-by: Menglong Dong Tested-by: Bj=C3=B6rn T=C3=B6pel Acked-by: Bj=C3=B6rn T=C3=B6pel --- v4: - fix the build error v3: - remove the "always" from the comment v2: - use bpf_prog_calls_session_cookie() in invoke_bpf() --- arch/riscv/net/bpf_jit_comp64.c | 74 ++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp6= 4.c index e4f45e2e7e2f..f065b45e8d8f 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -996,6 +996,29 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, i= nt args_off, int retval_of return ret; } =20 +static int invoke_bpf(struct bpf_tramp_links *tl, int args_off, int retval= _off, + int run_ctx_off, int func_meta_off, bool save_ret, u64 func_meta, + int cookie_off, struct rv_jit_context *ctx) +{ + int i, cur_cookie =3D (cookie_off - args_off) / 8; + + for (i =3D 0; i < tl->nr_links; i++) { + int err; + + if (bpf_prog_calls_session_cookie(tl->links[i])) { + u64 meta =3D func_meta | ((u64)cur_cookie << BPF_TRAMP_COOKIE_INDEX_SHI= FT); + + emit_store_stack_imm64(RV_REG_T1, -func_meta_off, meta, ctx); + cur_cookie--; + } + err =3D invoke_bpf_prog(tl->links[i], args_off, retval_off, run_ctx_off, + save_ret, ctx); + if (err) + return err; + } + return 0; +} + static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, const struct btf_func_model *m, struct bpf_tramp_links *tlinks, @@ -1005,13 +1028,15 @@ static int __arch_prepare_bpf_trampoline(struct bpf= _tramp_image *im, int i, ret, offset; int *branches_off =3D NULL; int stack_size =3D 0, nr_arg_slots =3D 0; - int retval_off, args_off, nregs_off, ip_off, run_ctx_off, sreg_off, stk_a= rg_off; + int retval_off, args_off, func_meta_off, ip_off, run_ctx_off, sreg_off, s= tk_arg_off; + int cookie_off, cookie_cnt; struct bpf_tramp_links *fentry =3D &tlinks[BPF_TRAMP_FENTRY]; struct bpf_tramp_links *fexit =3D &tlinks[BPF_TRAMP_FEXIT]; struct bpf_tramp_links *fmod_ret =3D &tlinks[BPF_TRAMP_MODIFY_RETURN]; bool is_struct_ops =3D flags & BPF_TRAMP_F_INDIRECT; void *orig_call =3D func_addr; bool save_ret; + u64 func_meta; u32 insn; =20 /* Two types of generated trampoline stack layout: @@ -1042,10 +1067,14 @@ static int __arch_prepare_bpf_trampoline(struct bpf= _tramp_image *im, * [ ... ] * FP - args_off [ arg1 ] * - * FP - nregs_off [ regs count ] + * FP - func_meta_off [ regs count, etc ] * * FP - ip_off [ traced func ] BPF_TRAMP_F_IP_ARG * + * [ stack cookie N ] + * [ ... ] + * FP - cookie_off [ stack cookie 1 ] + * * FP - run_ctx_off [ bpf_tramp_run_ctx ] * * FP - sreg_off [ callee saved reg ] @@ -1077,14 +1106,20 @@ static int __arch_prepare_bpf_trampoline(struct bpf= _tramp_image *im, stack_size +=3D nr_arg_slots * 8; args_off =3D stack_size; =20 + /* function metadata, such as regs count */ stack_size +=3D 8; - nregs_off =3D stack_size; + func_meta_off =3D stack_size; =20 if (flags & BPF_TRAMP_F_IP_ARG) { stack_size +=3D 8; 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 round_up(sizeof(struct bpf_tramp_run_ctx), 8); run_ctx_off =3D stack_size; =20 @@ -1132,10 +1167,19 @@ static int __arch_prepare_bpf_trampoline(struct bpf= _tramp_image *im, if (flags & BPF_TRAMP_F_IP_ARG) emit_store_stack_imm64(RV_REG_T1, -ip_off, (u64)func_addr, ctx); =20 - emit_store_stack_imm64(RV_REG_T1, -nregs_off, nr_arg_slots, ctx); + func_meta =3D nr_arg_slots; + emit_store_stack_imm64(RV_REG_T1, -func_meta_off, func_meta, ctx); =20 store_args(nr_arg_slots, args_off, ctx); =20 + if (bpf_fsession_cnt(tlinks)) { + /* clear all session cookies' value */ + for (i =3D 0; i < cookie_cnt; i++) + emit_sd(RV_REG_FP, -cookie_off + 8 * i, RV_REG_ZERO, ctx); + /* clear return value to make sure fentry always get 0 */ + emit_sd(RV_REG_FP, -retval_off, RV_REG_ZERO, ctx); + } + if (flags & BPF_TRAMP_F_CALL_ORIG) { emit_imm(RV_REG_A0, ctx->insns ? (const s64)im : RV_MAX_COUNT_IMM, ctx); ret =3D emit_call((const u64)__bpf_tramp_enter, true, ctx); @@ -1143,9 +1187,9 @@ static int __arch_prepare_bpf_trampoline(struct bpf_t= ramp_image *im, return ret; } =20 - for (i =3D 0; i < fentry->nr_links; i++) { - ret =3D invoke_bpf_prog(fentry->links[i], args_off, retval_off, run_ctx_= off, - flags & BPF_TRAMP_F_RET_FENTRY_RET, ctx); + if (fentry->nr_links) { + ret =3D invoke_bpf(fentry, args_off, retval_off, run_ctx_off, func_meta_= off, + flags & BPF_TRAMP_F_RET_FENTRY_RET, func_meta, cookie_off, ctx); if (ret) return ret; } @@ -1192,9 +1236,14 @@ static int __arch_prepare_bpf_trampoline(struct bpf_= tramp_image *im, *(u32 *)(ctx->insns + branches_off[i]) =3D insn; } =20 - for (i =3D 0; i < fexit->nr_links; i++) { - ret =3D invoke_bpf_prog(fexit->links[i], args_off, retval_off, - run_ctx_off, false, ctx); + /* set "is_return" flag for fsession */ + func_meta |=3D (1ULL << BPF_TRAMP_IS_RETURN_SHIFT); + if (bpf_fsession_cnt(tlinks)) + emit_store_stack_imm64(RV_REG_T1, -func_meta_off, func_meta, ctx); + + if (fexit->nr_links) { + ret =3D invoke_bpf(fexit, args_off, retval_off, run_ctx_off, func_meta_o= ff, + false, func_meta, cookie_off, ctx); if (ret) goto out; } @@ -2094,3 +2143,8 @@ bool bpf_jit_inlines_helper_call(s32 imm) return false; } } + +bool bpf_jit_supports_fsession(void) +{ + return true; +} --=20 2.53.0 From nobody Sun Feb 8 13:53:20 2026 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 01CAD2C11F9 for ; Sun, 8 Feb 2026 05:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770528844; cv=none; b=XjR4aPokyTNj0N7JsTf25CaCVO9MxADx/NeGX7Z5NHChlB7VhS+vRJzKrkYA4KXjYD8soYP07qVzEeGLnZBPKXuoVPmIU9vhGk/jAvxbc+cTolfSItz48wZhb7UIXJBOEFQvtuVzeD64FI6Kgn3iW/NlSI7fKgChDLSU+3Dkdyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770528844; c=relaxed/simple; bh=WNVhyOL7okSH5jtf5uSAFPq08ifRlHDbQ+0d6p9ancM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oivl8YoxhcDxNKYUt5ywMnfGAgFxVC/UH6f4d80D7BLDb/8WOy58wsjy1+rqtyMStCcpG4psPvTZIq6162v0vyDuvzLLoLYpmm63UXCZ1dqZqlZ1k3/B1cZsaymlgNG4JbI8XzJpx7WkH0+CVwi9FJH8WCRaociGFg15uF8gBFY= 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=mP2is8cB; arc=none smtp.client-ip=209.85.210.196 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="mP2is8cB" Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-81f47610542so2292494b3a.0 for ; Sat, 07 Feb 2026 21:34:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770528843; x=1771133643; 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=GOZtDu7jSNri6wkbo2wj70FyVnPCcpHXFtiLHwbu29Y=; b=mP2is8cB482Fi8ookoOfYRTB3jFGSxz2q58KDrH3YdLXEykyps0DZrEcuTrK3T8Bd/ I32h5CafwCda5zSKD5MDjyO/fp3i7Mwp4V0CWmOeITFCTIHEYsrvQ7e7MqhzsKfX3PM4 xgdGC44y7/MnfZtAwwQkeLLB6+I15uCl+FooGQO9mGOFtXuBT+bcpBQ9gFnRl3DbealL p7xRzxdxJVKqSl+fE/0JwTrCjEle8cKauQBG2uDGWuy3hw815wntoEUyAHsw2hGX4/n/ ECaEFW5w3S0CY1243TIxGptrgG8X3e+UGYh/w39iN3tIG5ryS27zZ9Hb/qcvTPWXgPka Q/wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770528843; x=1771133643; 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=GOZtDu7jSNri6wkbo2wj70FyVnPCcpHXFtiLHwbu29Y=; b=poTVZBXk9SJ8V9tvBA9V9D0QlkG+wpH17T9H/6B4gGtX2cTGht/sPxMbyf6jMYsZ4I tiY+SZNTS0M0iNShg6Ro2mzNZu/3vLkKjPpgtQ/cE4bOx/GEzkLX+266Fv58cE9bwbsp iQuo+bvha9jsW3notS9kmKa3bg0zSaJdVmNK28LJN1qKj9CD2uz2K8ifgZ7zv7tmVyMV Rwj/NtqHA3dRIcMGc14f1Bvp9xIWg5pJqusLoYlJRBxg+nIk7jMspx/dxf7y9TTtYFHH eca5KaO5y/DQk/3ZYujtkNnN+83GeJ882EHkI1Hmw2IUVBWYf8rF8Lqop2kXL3Ldc0va DMKQ== X-Forwarded-Encrypted: i=1; AJvYcCWj22xHGoE39bleGs1SQsaCVNHRbXv6QldKfTNyj2IhACImIt8J+1gStovINZC6R/lBkcwhg73YaWKnAy8=@vger.kernel.org X-Gm-Message-State: AOJu0YxkiNYOnt+5r3KM3KCmw1OUPXqh4aWIe3FH1S/RxQnrSWYf9WKh xWvhnSW7pNvRdd0J56zyIiKLLIj0cU/CoPyBP+N6bqXy8r/c8fOhp++m X-Gm-Gg: AZuq6aJnlJdaLgoMgFj3avOvg1UoKkE47iLvj2bQI3TOzdj6PK3czAaj8q/8k6Oe1Tt 4rbYM/eRkFkDXAfgC6VvuHZ0TEintazY5PZOm750emaiGpimGZ+YVqQndmnkAgGwrsOdAZVDPbL 71o3J08YKdj/4t65FIbojbGkqKudFPmsrfeKqO612DV8MdXx1G8eNkaKmuRuiXaNPLEXVVLGnF0 67YHSZDtWEzywRD4Z0qiJ9+fXWUIjQ6PA3Q04J9bGrzbSvhOTFyCdHjNjNBkf88ppmKFBtUsnZb ApstM964HCSlev4b1gzCOjut0GC6kVY1VY9V8be8uEqdDh94HqSw0BxDXsy1xzscy89Khy2yKeW GAefDjA3Hfjp6NVh76rvzCMj/eihEnk/vmxG1o6vcKelxVQ3zn+YmKPAHnWRm5tK6eIbrXA1Xc+ SVbK5Bzilz+1V/uWzXpY0= X-Received: by 2002:a05:6a00:4b01:b0:824:3cae:54b5 with SMTP id d2e1a72fcca58-824416002fbmr6625757b3a.14.1770528843309; Sat, 07 Feb 2026 21:34:03 -0800 (PST) Received: from 7950hx ([103.173.155.241]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-824418de80dsm6067700b3a.62.2026.02.07.21.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Feb 2026 21:34:03 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@kernel.org, bjorn@kernel.org Cc: daniel@iogearbox.net, andrii@kernel.org, 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, pulehui@huawei.com, puranjay@kernel.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, jiang.biao@linux.dev Subject: [PATCH bpf-next v4 3/3] selftests/bpf: enable fsession_test on riscv64 Date: Sun, 8 Feb 2026 13:33:11 +0800 Message-ID: <20260208053311.698352-4-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260208053311.698352-1-dongml2@chinatelecom.cn> References: <20260208053311.698352-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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Now that the RISC-V trampoline JIT supports BPF_TRACE_FSESSION, run the fsession selftest on riscv64 as well as x86_64. Signed-off-by: Menglong Dong Tested-by: Bj=C3=B6rn T=C3=B6pel Acked-by: Bj=C3=B6rn T=C3=B6pel --- tools/testing/selftests/bpf/progs/get_func_args_test.c | 2 +- tools/testing/selftests/bpf/progs/get_func_ip_test.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/get_func_args_test.c b/tools= /testing/selftests/bpf/progs/get_func_args_test.c index 180ba5098ca1..075a1180ec26 100644 --- a/tools/testing/selftests/bpf/progs/get_func_args_test.c +++ b/tools/testing/selftests/bpf/progs/get_func_args_test.c @@ -167,7 +167,7 @@ int BPF_PROG(tp_test2) } =20 __u64 test7_result =3D 0; -#if defined(bpf_target_x86) || defined(bpf_target_arm64) +#if defined(bpf_target_x86) || defined(bpf_target_arm64) || defined(bpf_ta= rget_riscv) SEC("fsession/bpf_fentry_test1") int BPF_PROG(test7) { diff --git a/tools/testing/selftests/bpf/progs/get_func_ip_test.c b/tools/t= esting/selftests/bpf/progs/get_func_ip_test.c index 43ff836a8ed8..45eaa54d1ac7 100644 --- a/tools/testing/selftests/bpf/progs/get_func_ip_test.c +++ b/tools/testing/selftests/bpf/progs/get_func_ip_test.c @@ -106,7 +106,7 @@ int BPF_URETPROBE(test8, int ret) =20 __u64 test9_entry_result =3D 0; __u64 test9_exit_result =3D 0; -#if defined(bpf_target_x86) || defined(bpf_target_arm64) +#if defined(bpf_target_x86) || defined(bpf_target_arm64) || defined(bpf_ta= rget_riscv) SEC("fsession/bpf_fentry_test1") int BPF_PROG(test9, int a) { --=20 2.53.0