lkml.org 
[lkml]   [2020]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH bpf-next 2/7] bpf: JIT helpers for fmod_ret progs
On Tue, Mar 3, 2020 at 6:13 AM KP Singh <kpsingh@chromium.org> wrote:
>
> From: KP Singh <kpsingh@google.com>
>
> * Split the invoke_bpf program to prepare for special handling of
> fmod_ret programs introduced in a subsequent patch.
> * Move the definition of emit_cond_near_jump and emit_nops as they are
> needed for fmod_ret.
> * Refactor branch target alignment into its own function
> align16_branch_target.
>
> Signed-off-by: KP Singh <kpsingh@google.com>
> ---
> arch/x86/net/bpf_jit_comp.c | 158 ++++++++++++++++++++----------------
> 1 file changed, 90 insertions(+), 68 deletions(-)
>
> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index 15c7d28bc05c..475e354c2e88 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -1361,35 +1361,100 @@ static void restore_regs(const struct btf_func_model *m, u8 **prog, int nr_args,
> -(stack_size - i * 8));
> }
>

[...]

> +
> +/* From Intel 64 and IA-32 Architectures Optimization
> + * Reference Manual, 3.4.1.4 Code Alignment, Assembly/Compiler
> + * Coding Rule 11: All branch targets should be 16-byte
> + * aligned.
> + */
> +static void align16_branch_target(u8 **pprog)
> +{
> + u8 *target, *prog = *pprog;
> +
> + target = PTR_ALIGN(prog, 16);
> + if (target != prog)
> + emit_nops(&prog, target - prog);
> + if (target != prog)
> + pr_err("calcultion error\n");

this wasn't in the original code, do you feel like it's more important
to check this and print error?

also typo: calculation error, but then it's a bit brief and
uninformative message. So I don't know, maybe just drop it?

> +}
> +
> +static int emit_cond_near_jump(u8 **pprog, void *func, void *ip, u8 jmp_cond)
> +{
> + u8 *prog = *pprog;
> + int cnt = 0;
> + s64 offset;
> +
> + offset = func - (ip + 2 + 4);
> + if (!is_simm32(offset)) {
> + pr_err("Target %p is out of range\n", func);
> + return -EINVAL;
> + }
> + EMIT2_off32(0x0F, jmp_cond + 0x10, offset);
> + *pprog = prog;
> + return 0;
> +}
> +

[...]

\
 
 \ /
  Last update: 2020-03-03 23:26    [W:0.281 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site