lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQL_eiqFPp5CvhnOYbrbyxXpwGBbhOqwh2JC-EioHbxMag@mail.gmail.com>
Date: Wed, 2 Oct 2024 08:37:44 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Tao Chen <chen.dylane@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>, 
	John Fastabend <john.fastabend@...il.com>, Andrii Nakryiko <andrii@...nel.org>, 
	Martin KaFai Lau <martin.lau@...ux.dev>, Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>, 
	Yonghong Song <yonghong.song@...ux.dev>, Jiri Olsa <jolsa@...nel.org>, 
	Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>, 
	Dave Hansen <dave.hansen@...ux.intel.com>, X86 ML <x86@...nel.org>, 
	"H . Peter Anvin" <hpa@...or.com>, bpf <bpf@...r.kernel.org>, LKML <linux-kernel@...r.kernel.org>, 
	sparclinux@...r.kernel.org
Subject: Re: [PATCH bpf-next 2/2 v2] bpf: Add BPF_CALL_FUNC to simplify code

On Wed, Oct 2, 2024 at 8:23 AM Tao Chen <chen.dylane@...il.com> wrote:
>
> No logic changed, like macro BPF_CALL_IMM, add BPF_CALL_FUNC
> to simplify code.
>
> Signed-off-by: Tao Chen <chen.dylane@...il.com>
> ---
>  arch/sparc/net/bpf_jit_comp_64.c | 2 +-
>  arch/x86/net/bpf_jit_comp.c      | 2 +-
>  arch/x86/net/bpf_jit_comp32.c    | 5 ++---
>  include/linux/filter.h           | 2 ++
>  kernel/bpf/core.c                | 2 +-
>  5 files changed, 7 insertions(+), 6 deletions(-)
>
> Change list:
> - v2 -> v1:
>     - fix compile error reported by kernel test robot
>
> diff --git a/arch/sparc/net/bpf_jit_comp_64.c b/arch/sparc/net/bpf_jit_comp_64.c
> index 73bf0aea8baf..076b1f216360 100644
> --- a/arch/sparc/net/bpf_jit_comp_64.c
> +++ b/arch/sparc/net/bpf_jit_comp_64.c
> @@ -1213,7 +1213,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx)
>         /* function call */
>         case BPF_JMP | BPF_CALL:
>         {
> -               u8 *func = ((u8 *)__bpf_call_base) + imm;
> +               u8 *func = BPF_CALL_FUNC(imm);
>
>                 ctx->saw_call = true;
>
> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index 06b080b61aa5..052e5cc65fc0 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -2126,7 +2126,7 @@ st:                       if (is_imm8(insn->off))
>                 case BPF_JMP | BPF_CALL: {
>                         u8 *ip = image + addrs[i - 1];
>
> -                       func = (u8 *) __bpf_call_base + imm32;
> +                       func = BPF_CALL_FUNC(imm32);
>                         if (tail_call_reachable) {
>                                 LOAD_TAIL_CALL_CNT_PTR(bpf_prog->aux->stack_depth);
>                                 ip += 7;
> diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c
> index de0f9e5f9f73..f7277639bd2c 100644
> --- a/arch/x86/net/bpf_jit_comp32.c
> +++ b/arch/x86/net/bpf_jit_comp32.c
> @@ -1627,8 +1627,7 @@ static int emit_kfunc_call(const struct bpf_prog *bpf_prog, u8 *end_addr,
>         /* mov dword ptr [ebp+off],eax */
>         if (fm->ret_size)
>                 end_addr -= 3;
> -
> -       jmp_offset = (u8 *)__bpf_call_base + insn->imm - end_addr;
> +       jmp_offset = BPF_CALL_FUNC(insn->imm) - end_addr;
>         if (!is_simm32(jmp_offset)) {
>                 pr_err("unsupported BPF kernel function jmp_offset:%lld\n",
>                        jmp_offset);
> @@ -2103,7 +2102,7 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
>                                 break;
>                         }
>
> -                       func = (u8 *) __bpf_call_base + imm32;
> +                       func = BPF_CALL_FUNC(imm32);
>                         jmp_offset = func - (image + addrs[i]);
>
>                         if (!imm32 || !is_simm32(jmp_offset)) {
> diff --git a/include/linux/filter.h b/include/linux/filter.h
> index 99b6fc83825b..9924b581aa71 100644
> --- a/include/linux/filter.h
> +++ b/include/linux/filter.h
> @@ -461,6 +461,8 @@ static inline bool insn_is_cast_user(const struct bpf_insn *insn)
>
>  #define BPF_CALL_IMM(x)        ((void *)(x) - (void *)__bpf_call_base)
>
> +#define BPF_CALL_FUNC(x)       ((x) + (u8 *)__bpf_call_base)
> +

I don't like to hide code behind macros.
The code is cleaner as-is.

pw-bot: cr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ