bpf, riscv: Support riscv jit to provide bpf_line_info
authorPu Lehui <pulehui@huawei.com>
Mon, 30 May 2022 09:28:11 +0000 (17:28 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 2 Jun 2022 23:26:01 +0000 (16:26 -0700)
Add support for riscv jit to provide bpf_line_info. We need to
consider the prologue offset in ctx->offset, but unlike x86 and
arm64, ctx->offset of riscv does not provide an extra slot for
the prologue, so here we just calculate the len of prologue and
add it to ctx->offset at the end. Both RV64 and RV32 have been
tested.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220530092815.1112406-3-pulehui@huawei.com
arch/riscv/net/bpf_jit.h
arch/riscv/net/bpf_jit_core.c

index 2a3715b..d926e0f 100644 (file)
@@ -69,6 +69,7 @@ struct rv_jit_context {
        struct bpf_prog *prog;
        u16 *insns;             /* RV insns */
        int ninsns;
+       int body_len;
        int epilogue_offset;
        int *offset;            /* BPF to RV */
        int nexentries;
index be743d7..737baf8 100644 (file)
@@ -44,7 +44,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
        unsigned int prog_size = 0, extable_size = 0;
        bool tmp_blinded = false, extra_pass = false;
        struct bpf_prog *tmp, *orig_prog = prog;
-       int pass = 0, prev_ninsns = 0, i;
+       int pass = 0, prev_ninsns = 0, prologue_len, i;
        struct rv_jit_data *jit_data;
        struct rv_jit_context *ctx;
 
@@ -95,6 +95,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
                        prog = orig_prog;
                        goto out_offset;
                }
+               ctx->body_len = ctx->ninsns;
                bpf_jit_build_prologue(ctx);
                ctx->epilogue_offset = ctx->ninsns;
                bpf_jit_build_epilogue(ctx);
@@ -161,6 +162,11 @@ skip_init_ctx:
 
        if (!prog->is_func || extra_pass) {
                bpf_jit_binary_lock_ro(jit_data->header);
+               prologue_len = ctx->epilogue_offset - ctx->body_len;
+               for (i = 0; i < prog->len; i++)
+                       ctx->offset[i] = ninsns_rvoff(prologue_len +
+                                                     ctx->offset[i]);
+               bpf_prog_fill_jited_linfo(prog, ctx->offset);
 out_offset:
                kfree(ctx->offset);
                kfree(jit_data);