From nobody Sun Feb 8 11:17:03 2026 Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) (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 24CD7202F65 for ; Tue, 3 Feb 2026 05:52:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770097980; cv=none; b=Ez3RDhmczFbtSCbEVNJZeqMJrKg9smVTe/0WdD3I7epP6IVRGFt7+tRT1274F0AyFJNCqFpRshBCVXg4zl6IR7PhVJB1kNihYorHXnHQ594gRtGOHaGuYY7mXhb6eV30Z2H0A+uKzWPgehQDCuCy8vkdnv6oOkW00NN4FtNdNmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770097980; c=relaxed/simple; bh=070F55rMJkahswIvT4jf6jx3vQtTz2wLV+jQ3NAeigI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t30dbRCCaVkw52r+O01k5+E6zIxOQfRKKOTxOjpYDqhJwJvwnTt7ucqmhCBcCQA06db0VfcNFj4UQJWbSDLRJhV1gVhTMEYg4J5LQk12Bg/OoLNPckVUBjJELXrTcNrNuf0aNLDsy+rC7CCnWU7ZRsMWDUR/oPEOI3o/mpCX2XU= 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=IbDqcrEq; arc=none smtp.client-ip=209.85.219.65 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="IbDqcrEq" Received: by mail-qv1-f65.google.com with SMTP id 6a1803df08f44-88888c41a13so67497996d6.3 for ; Mon, 02 Feb 2026 21:52:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770097978; x=1770702778; 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=PzVkfCKgUCL7plixo/BQ6/TFm6BL7pd9AJ8r1pM28SI=; b=IbDqcrEq+9tiqyfkS40tPk90jEukTVjGONCcb/6W1iwcBDlkHoZkpxzT08KzMsqjUA Qla1cOx/U5BI9YgsAsLur2zUYvcgEfXaRdugWzrDa/F4DPa3g4lbmTpEYZvTfVsxXLHv 3LxXwy6B0jQ0EgXgZogYYMKh2gsEBmDPStRUzYm8IYeOF+iRQ1MXzbQJ0K20ik9fQfFX jiq7WFWWkySrixU9ycDjsk6eEbEBsmDGggdAIC0MzW7hzm2u/6h99C4qfeIi0lpTfl14 KlfNO2GSE06mm6vcDDx/nxm2qrsH+gch8I4H1BAkxpcHfy7z7MuGwMD95LrfB9qqWkpK DmUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770097978; x=1770702778; 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=PzVkfCKgUCL7plixo/BQ6/TFm6BL7pd9AJ8r1pM28SI=; b=qdj1Tz/CiUaKN6ULaU8ULZG2OjuIhwKDuR6iotIOpE49aQrf0hEEHiRf0slEa5MNNC 8Ng4pRSl5y7VKFPzjqz6cbKu2ZTe9KT0Q+rSI3w6doojnlAmVPh57BcArjzgGt/aIexZ NvOLJYfr5f1FW6RUFcHWdEccCUADPEpmzwVOxKM8nEsRXs5v+Uh6oapqB18P10MwoU1H XHuCTiaUGMyNk9ONwu7ngfc5g1fESWh09JpbQWial5/fXKvp1mLwkugeMuda8oAvZ7C8 Wc39UjN3mAOBWmYffGuV4xeuJJ6WHUhrhvGvV6jhAu8mPi3RV9Mi5WkhlJm4f3s0/c4B JG7Q== X-Forwarded-Encrypted: i=1; AJvYcCWML7kcyahguJ7j92GTNx3NmX9CiKLYjJqVaHbJSR1+nKmlK28kf9IXzHqyqhoCMgvTgx2WpGWtsJrYdEg=@vger.kernel.org X-Gm-Message-State: AOJu0YyMVaM5Qeashk1i5ecsAzUXQx4EI/dtUFpd5VlZyuQY7MnvoEmq IlObQtPwctDayVyOeJj2rpRiopGGzuWdBZ60n++hh2hGV/8xFZwoxhPC X-Gm-Gg: AZuq6aL5hMVcCdY8DLmuXXKnCrnO9sqqvwd4fDMBu8AGWVCCEBzLoBBukJhFuqturEi 6Q3FwYmf7V5537bJM0GR+aT9g8nIZISmnrrIg+gCgOPK5nViHC3oehHGDMpvC0dQf53rQHzTEYk N5I5OaJTQJZu5xlzaDXBzwUnK1RBh/90mzl3G84sxLlXLe1v03smZdMtjOfcNheti1+/FDntIrK L9kqmwUga3ZkKhCSbr87rwSDCECGyG5qMHaMHQHxOk1DA8Qd4sPKWPRJ5YuenPo6lr1qGgRsYsR Idgokl9oUFg/votb1jVkERtwdrcqwd1dU0LlBXwW2WS03MlQY1HwwvyXO+P3XLMicLSefK2MgWF pH0yQ6H2wr6peUoF0/Mzr/wcU8d4L6ZZmaK/QpFKHwA/oTxrib1DPUpGEoeB8B0+Kq/K43oJPhS 9/WlUGVmE= X-Received: by 2002:ac8:5a0d:0:b0:4f4:e15d:f220 with SMTP id d75a77b69052e-505d2183d83mr151199911cf.25.1770097978028; Mon, 02 Feb 2026 21:52:58 -0800 (PST) Received: from 7940hx ([23.94.188.235]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-894d376e65bsm129844996d6.55.2026.02.02.21.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 21:52:57 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@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, bjorn@kernel.org, pulehui@huawei.com, puranjay@kernel.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, jiang.biao@linux.dev, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 1/3] bpf, riscv: introduce emit_store_stack_imm64() for trampoline Date: Tue, 3 Feb 2026 13:52:29 +0800 Message-ID: <20260203055231.1088479-2-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260203055231.1088479-1-dongml2@chinatelecom.cn> References: <20260203055231.1088479-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" Introduce a helper to store 64-bit immediate on the trampoline stack with a help of a register. Signed-off-by: Menglong Dong Acked-by: Bj=C3=B6rn T=C3=B6pel Tested-by: Bj=C3=B6rn T=C3=B6pel # QEMU/RVA23/DT --- 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.52.0 From nobody Sun Feb 8 11:17:03 2026 Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) (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 F0D3D366DB1 for ; Tue, 3 Feb 2026 05:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.67 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770097989; cv=none; b=XXpg15Tp9bURUplKDk64VCgX98sdY1UctqtXzEcvOLYiI7CwJTk9gZ0r4pOOoU47F75RbZ1NQGbBdEM87pnPf9lxES62PahYxSIu4ZfYAzcqjWSqCeA4XDaCkNOr0TN3qmrRnweC2MeAhYYZy8PCWu4rPG69vj8WQZwMKHhIPac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770097989; c=relaxed/simple; bh=TyHw5ip8J9ZAZ/E83UrWMPtW7dVE94KjxJUkg16mWxQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tmp/J6ACP55Ssuwok/3xdIuPIuTB0FFZy8ytdZREF84MG7uK7UgVZMWpTHMCm5RlnaNg4eUIdPr4dBxba4Y1HGXJd7jkXqPNyAdOIZhwGJwCE4z9VtSldEO/OMG2uMipnCCWpILmhgdf/f5+4Ts6PfYfcUa7Ahi+G0wdQ35oN/0= 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=jdMBh2rE; arc=none smtp.client-ip=209.85.219.67 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="jdMBh2rE" Received: by mail-qv1-f67.google.com with SMTP id 6a1803df08f44-8947ddce09fso42765876d6.3 for ; Mon, 02 Feb 2026 21:53:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770097987; x=1770702787; 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=6uxGWuC9y0ak4TPgoWK6c0g9IlENP1gQKqGkKB74Ees=; b=jdMBh2rE6yUuw1UDd8xXDKb474JO1VECATxb0k2oEOS1nei5mzI0MoNzReTlpstjbq C+Pc0yAQyK/xC1Elm/hssrOVt0WfM5E1v16MKokoW1S33HWtxivxQMgJAynJcSTBjyNN jq7a8YoPcRlM3cYT2hUXtArqN34wtOjGRaLF7MQ5CXQ36Vhv3P/0WNre5FHv+e0biyuc Nuh0HqjpYSb1OUxDD6JtcKWNZP3kifa99id3Yn608p9vC1HEeKGurF58BnQ75QHyqBCl ANhhxqsdYlZzmvQ0YI0427TXnz0Smwp9DuETC5cPDv2p6SXkFhKmfZJULdPZBtqA5Q1A ECvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770097987; x=1770702787; 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=6uxGWuC9y0ak4TPgoWK6c0g9IlENP1gQKqGkKB74Ees=; b=t174bnGy1MOcFY9pvFINKo740t6r0NEjces0wa9hTHssx5+JuS6A4v+GT0KtyRNQHS C8NfjaFG08YQsa6BUxgnDud+BCn7BRy1nn6vNzAGq/zl+5VNB62QrIOALYGqNmI0bW/8 /TiX2IAPeNuQm99Eib6tNPUUz2KAhh1cHgH6AUp+ceYQjAP19Yb61p8Vr+8xeqk+uHEB aW8MkQSjSzaT40Ew5BXfSphLl+g3/nCz5KIwLRL9Obf9rY5g3RDpX+IYfkYmsmeC1ST9 6UitIy+Z5s6zBdHVL6NNcnGrwi+lEAocgceesYAYwV+tBaLgMoIkQjTbwmodpu9ra7Xf WdCg== X-Forwarded-Encrypted: i=1; AJvYcCUr8OylwKukuY8MyHAisjyeOS7Z5cdX4a6mdAE6pCBD3OcsCm7q/F2j7trFuSJOSgOAuQyfiuNWWBurbbU=@vger.kernel.org X-Gm-Message-State: AOJu0YyyoR05uh2xtYK7VgMDBxdGnAZYYm77pzOaPrgpP9x+1WzM7wir XN5A3eMZl3ZlgLEhx7FFKGZFqeDZyccvpeJ/0loOEPebgZIwDbOQo2M5 X-Gm-Gg: AZuq6aLLL0tIg4NSCZYPdIfNtjU1tjLg4LeliGcxb73LYDyyhbysxiE4kGPTaa5d1gW Khsw0klW9W1WIlS6EISpPzZGw4zgluEfItqt3TfPpYhHXqIKFGnoHMLhcMi+JMuy9MGiLHlGWR+ r7UJXhL+RDTdbkXS/eFgX7NXlJZNvWc/6ca8qeVFbb+0m1/aVwkuIdI777Q6jH/UoAHsKFEp4i0 M4TTSEhnJIrajjs6mD/mDD4Hs6hixpO05lRZZ2JIThuf0H/zIr2K1T1U7p/i7GqiYr40+hYozQF Td7hVWUzinKDHZeynlAU+snBr4GBS1jGT/0gxR+l1+yPwje92d2AEGajnzLUGUjvjDrYzOEEwol bDbEiSd+zFhMc5f9vLnWdLtxtslUl/5wHIi/heP9Qd6bkKf+MKihe1C3QkaEJ69jQcBzr/9oIbC vQ2Rtl5lCV1ekOg5jD7Q== X-Received: by 2002:a05:6214:1c0f:b0:888:7ba5:6b35 with SMTP id 6a1803df08f44-894e9f818e5mr209940796d6.19.1770097986889; Mon, 02 Feb 2026 21:53:06 -0800 (PST) Received: from 7940hx ([23.94.188.235]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-894d376e65bsm129844996d6.55.2026.02.02.21.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 21:53:06 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@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, bjorn@kernel.org, pulehui@huawei.com, puranjay@kernel.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, jiang.biao@linux.dev, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/3] bpf, riscv: add fsession support for trampolines Date: Tue, 3 Feb 2026 13:52:30 +0800 Message-ID: <20260203055231.1088479-3-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260203055231.1088479-1-dongml2@chinatelecom.cn> References: <20260203055231.1088479-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" 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 Acked-by: Bj=C3=B6rn T=C3=B6pel Tested-by: Bj=C3=B6rn T=C3=B6pel # QEMU/RVA23/DT --- 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..f10418ff6a9b 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 (tl->links[i]->link.prog->call_session_cookie) { + 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 ] always * * 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.52.0 From nobody Sun Feb 8 11:17:03 2026 Received: from mail-qv1-f66.google.com (mail-qv1-f66.google.com [209.85.219.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 82B63368288 for ; Tue, 3 Feb 2026 05:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770097998; cv=none; b=fO+761lD+pUJXDxQN4+wriySYYsWhtLukOyU+3RD+v+NOg1PCYX9a7sHP8SjNhBqAxtrLd7ainUrIKY4QMX6ALYVOqkv20SxX/D3WcnNr+4fz2uQ9OlwesCexJhmkKO287iG6BPFzbaitGakz34epUhQ5QOnsWfA5Ar0yYTpeiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770097998; c=relaxed/simple; bh=hHiF3nksI8lsJC2F4SsmOkBpvT4ZyZWbPKJh6PP3/fQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O16a1SE5lIgLMX2+hiE7VmxTgkz3dQZhNLebsJfhCwrrD8UMUpCSpuuSF+T39H7MIW55s+IHB6Ym+EkdyQ/Wo3LWtKk/VA/P8Hv2HDgHpaHgYRzQRkLyHuPj4gU/KXjjp9YHwEdR3T37hMbIn+ENI43+IwZsDT5xY+nGdx2YyYE= 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=ehiDrojD; arc=none smtp.client-ip=209.85.219.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="ehiDrojD" Received: by mail-qv1-f66.google.com with SMTP id 6a1803df08f44-88ffcb14e11so73100536d6.0 for ; Mon, 02 Feb 2026 21:53:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770097997; x=1770702797; 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=wxSsUMeT8Os/CYFJWOVT+HQkubqBYSe/TOEbnpWLzSM=; b=ehiDrojDS1Quzdq4sdtcFBp1C1XV0+C8q1EjuF8QAhtm59slgkt45fsQhv2F7MooEs 2zrJ5SCi9FHIxsYqsYldB3YUc6h4Lykmbn12YAqvyGCX8GB60WnsG66rrsd0MlcNcrNU 8II5ZAoblz78Z7zOgeaG3xvWNDabTkCR0pG154VCYnd1GB3X9kUpCx9b0YVV3SMnEvDI 5A18uN3DR4vUQI3YUjatde4p1kaUzT1Zt9ZxqYtxalasyPEJ8whyc+zi/SRE4MzsfZeI s9FS4AkeWakrmeYZ4K/OB+uumxZw5PgM7QW5SII1iMQUuqGqW/wlIUT1v/xOM8x1+f8B DCPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770097997; x=1770702797; 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=wxSsUMeT8Os/CYFJWOVT+HQkubqBYSe/TOEbnpWLzSM=; b=ARliyf+vtBbLOeYXBRQcSwOwHJaAfWZeJmjcWupfSlZDSlne0n9AlE///0bSRzPKWO rtdERKiMNlcb/qDIqHEqZVKVXosT/VoPxSUWwcup4nx/9c4AVcYWq7sjaHuBPhJcSSAl 4t7y5O0WoojJAG09yvGVcx9rgZv63/4Gb3tJ+T5Xu8QkXFcYDy+lgJbnOLA0fTQywYp+ ChC/iKIwEbs2H9BC9XkH9UhEC5zGtu/fboKM/PRwj97JxcWqUSIncgBuJ80PRoM9AuQj ldXzGl74nWubNZnQy5cpwUT+TRmb9zRtsgXyC+FO9bQOsr3VBBbgEVxbdMks6XIAAbGc APoA== X-Forwarded-Encrypted: i=1; AJvYcCXyNVXmc+xoBUHayc1SLLZx3zLvbLKLvxGokLB8Y3YkDnJ9/901wBq3OyPMjwMPSW1Ak1rtpbvHyEREJWk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9H+7tT49TKWO6bzyqEgCvcfFA00DwuIT0PB0IsZw8i+K3siWc Z5uovL0wtMMOx+cHsz7rEFRHlSoNCEHg+eMIxc6p/Ch//d7cB6PTF7mJ X-Gm-Gg: AZuq6aKesOTaA5g8k4NZ8GKeJ0mfPYFtzwqqdNs1VhIQttG7zRz0ECnli+JWKFAFqrJ /+QriA6Tps9mygSJiaAweTCYq8lSAvoR8WeuXtKZVot9gfmfiAX92l1BnSCs257Hu/DjIJdPTPW qs6D2G9ubHxJTHhLhRoEEqPYU5SKUpT5dep4oZDQmui/3pOIKWGedJyBERaXKJ+3NKG6oVlFIne oZgBWMrAKulbn1yj33V2ihdfA+Vi/UgFM5SGx4vc63RhCO2SWwXoFzDn9TbgZ8wNB/BrksZW9SL KAtG+ZWdBB9WLO/bAUvQ9S6k+iTbBtY+47vKb61a7Uedw/hf+pfYZpn9sqeLE1saFZZbOG0s8D2 6WztUN692nYtenQlMHX+/bdcvvFQaFLzcQaOW3pRJhGbPLLX4e9D5YmkQXGMAf9RoB3CYEP5KuC 3aWMe7jww= X-Received: by 2002:a05:6214:e8c:b0:882:5078:8da1 with SMTP id 6a1803df08f44-894ea0e654fmr202391646d6.64.1770097996666; Mon, 02 Feb 2026 21:53:16 -0800 (PST) Received: from 7940hx ([23.94.188.235]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-894d376e65bsm129844996d6.55.2026.02.02.21.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 21:53:16 -0800 (PST) From: Menglong Dong X-Google-Original-From: Menglong Dong To: ast@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, bjorn@kernel.org, pulehui@huawei.com, puranjay@kernel.org, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, jiang.biao@linux.dev, bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 3/3] selftests/bpf: enable fsession_test on riscv64 Date: Tue, 3 Feb 2026 13:52:31 +0800 Message-ID: <20260203055231.1088479-4-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260203055231.1088479-1-dongml2@chinatelecom.cn> References: <20260203055231.1088479-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" 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 Acked-by: Bj=C3=B6rn T=C3=B6pel Tested-by: Bj=C3=B6rn T=C3=B6pel # QEMU/RVA23/DT --- 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.52.0