feat: add RISC-V 64-bit JIT backend for eBPF#146
Closed
CN-TangLin wants to merge 1 commit into
Closed
Conversation
Add jit_riscv64.rs with complete eBPF-to-RISC-V instruction translation: - Register mapping: r0-r10 → A0-A5, S1-S5 - Full ALU/ALU64 operations with 32-bit zero extension - JMP/JMP32 conditional jumps with backfill - LD/ST/LDX/STX memory operations with BPF stack adjustment - LD_DW_IMM 64-bit immediate loading (LUI+ADDIW+SLLI+LUI+ADDIW+ADD) - Helper function calls via indirect JALR - BE/LE endianness conversion - DIV/MOD zero-division protection - Prologue/Epilogue with callee-saved register save/restore Architecture selection via #[cfg(target_arch)] in JitMemory::new(). x86_64 JIT tests (131) all pass, no regressions. Signed-off-by: CN-TangLin <2242120212@qq.com>
2fb1cc0 to
4e8cf99
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
在现有 x86_64 手写 JIT 后端基础上,添加 RISC-V 64 位 JIT 后端,使 rbpf 支持多架构 JIT 编译。
背景
rbpf 目前仅支持 x86_64 架构的手写 JIT 编译(
src/jit.rs),以及基于 Cranelift 的通用 JIT。本 PR 添加 RISC-V 64 位的手写 JIT 后端,为 RISC-V 平台提供高性能 eBPF 执行能力。变更内容
src/jit_riscv64.rs(~850 行,新增)寄存器映射(与 RV64 ABI 自然对齐):
支持的 eBPF 指令:
load_imm + JALR间接调用Prologue/Epilogue:
ADDI SP,-560+ 保存 RA/S1-S5(6 个 callee-saved × 8 = 48 字节)ADDI SP,+560+JALR x0, ra, 0跳转实现:
src/jit.rs(修改)JitMemory::new()添加#[cfg(target_arch)]条件编译,在 riscv64 上使用RiscV64Compiler#[cfg(target_arch = "riscv64")] mod jit_riscv64;设计决策
jit模块的子模块(mod jit_riscv64),通过#[cfg(target_arch)]选择编译器,不影响 x86_64 后端JitMemory(页对齐可执行内存分配),仅替换编译逻辑验证
cargo build:x86_64 编译通过cargo test --test ubpf_jit_x86_64:131/131 x86_64 JIT 测试通过,无回归cargo test:全部测试通过后续工作
qmonnet/rbpf提交 PR