Re: [PATCH v5 2/5] LoongArch: BPF: Update the code to rename validate_code to validate_ctx

From: Hengqi Chen
Date: Wed Jul 30 2025 - 21:44:49 EST


On Wed, Jul 30, 2025 at 9:13 PM Chenghao Duan <duanchenghao@xxxxxxxxxx> wrote:
>
> Rename the existing validate_code() to validate_ctx()
> Factor out the code validation handling into a new helper validate_code()
>
> * validate_code is used to check the validity of code.
> * validate_ctx is used to check both code validity and table entry
> correctness.
>
> The new validate_code() will be used in subsequent changes.
>

I still feel uncomfortable about the subject line.
Hope Huacai can rephrase it when apply.
other than that,

Reviewed-by: Hengqi Chen <hengqi.chen@xxxxxxxxx>

> Co-developed-by: George Guo <guodongtai@xxxxxxxxxx>
> Signed-off-by: George Guo <guodongtai@xxxxxxxxxx>
> Signed-off-by: Chenghao Duan <duanchenghao@xxxxxxxxxx>
> ---
> arch/loongarch/net/bpf_jit.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index fa1500d4a..7032f11d3 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
> @@ -1180,6 +1180,14 @@ static int validate_code(struct jit_ctx *ctx)
> return -1;
> }
>
> + return 0;
> +}
> +
> +static int validate_ctx(struct jit_ctx *ctx)
> +{
> + if (validate_code(ctx))
> + return -1;
> +
> if (WARN_ON_ONCE(ctx->num_exentries != ctx->prog->aux->num_exentries))
> return -1;
>
> @@ -1288,7 +1296,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
> build_epilogue(&ctx);
>
> /* 3. Extra pass to validate JITed code */
> - if (validate_code(&ctx)) {
> + if (validate_ctx(&ctx)) {
> bpf_jit_binary_free(header);
> prog = orig_prog;
> goto out_offset;
> --
> 2.25.1
>