提交 3344c359 编写于 作者: M Mao Minkai 提交者: guzitao

sw64: bpf: fix insn_offset

Sunway inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5PNHA

--------------------------------

Since ctx->idx is the index of the next jited instruction, value of
insn_offset should be set before build_insn().

Allocate 1 more entry for insn_offset[], and give epilogue_offset to
it, so the correct jump offset can be calculated if the last
instruction is BPF_JMP.
Signed-off-by: NMao Minkai <maominkai@wxiat.com>
Signed-off-by: NGu Zitao <guzitao@wxiat.com>
上级 3158e725
......@@ -516,8 +516,8 @@ static void jit_fill_hole(void *area, unsigned int size)
static int bpf2sw64_offset(int bpf_idx, s32 off, const struct jit_ctx *ctx)
{
int from = ctx->insn_offset[bpf_idx];
int to = ctx->insn_offset[bpf_idx + off];
int from = ctx->insn_offset[bpf_idx + 1];
int to = ctx->insn_offset[bpf_idx + 1 + off];
if (ctx->image == NULL)
return 0;
......@@ -1226,15 +1226,15 @@ static int build_body(struct jit_ctx *ctx)
const struct bpf_insn *insn = &prog->insnsi[i];
int ret;
if (ctx->image == NULL)
ctx->insn_offset[i] = ctx->idx;
ret = build_insn(insn, ctx);
if (ret < 0)
return ret;
if (ctx->image == NULL)
ctx->insn_offset[i] = ctx->idx;
while (ret > 0) {
i++;
if (ctx->image == NULL)
ctx->insn_offset[i] = ctx->idx;
ctx->insn_offset[i] = ctx->insn_offset[i - 1];
ret--;
}
}
......@@ -1305,7 +1305,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
memset(&ctx, 0, sizeof(ctx));
ctx.prog = prog;
ctx.insn_offset = kcalloc(prog->len, sizeof(int), GFP_KERNEL);
ctx.insn_offset = kcalloc(prog->len + 1, sizeof(int), GFP_KERNEL);
if (ctx.insn_offset == NULL) {
prog = orig_prog;
goto out_off;
......@@ -1321,7 +1321,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
goto out_off;
}
ctx.epilogue_offset = ctx.idx;
ctx.insn_offset[prog->len] = ctx.epilogue_offset = ctx.idx;
build_epilogue(&ctx);
/* Now we know the actual image size. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册