lkml.org 
[lkml]   [2021]   [Oct]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 9/9] bpf,x86: Respect X86_FEATURE_RETPOLINE*
On Thu, Oct 14, 2021 at 11:46:11AM +0200, Peter Zijlstra wrote:
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -396,6 +396,37 @@ static int get_pop_bytes(bool *callee_re
> return bytes;
> }
>
> +#define EMIT_LFENCE() EMIT3(0x0F, 0xAE, 0xE8)
> +
> +#ifdef CONFIG_RETPOLINE
> +#define INDIRECT_SIZE (5)

Bah, that should be:

#define INDIRECT_SIZE (2 + 3*cpu_feature_enabled(X86_FEATURE_RETPOLINE))

> +#else
> +#define INDIRECT_SIZE (2)
> +#endif
> +
> +static void emit_indirect_jump(u8 **pprog, int reg, u8 *ip)
> +{
> + static const void *reg_thunk[] = {
> +#undef GEN
> +#define GEN(reg) __x86_indirect_thunk_ ## reg,
> +#include <asm/GEN-for-each-reg.h>
> + };
> +
> + u8 *prog = *pprog;
> +
> +#ifdef CONFIG_RETPOLINE
> + if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD)) {
> + EMIT_LFENCE();
> + EMIT2(0xFF, 0xE0 + reg);
> + } else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) {
> + emit_jump(&prog, reg_thunk[reg], ip);
> + } else
> +#endif
> + EMIT2(0xFF, 0xE0 + reg);
> +
> + *pprog = prog;
> +}

\
 
 \ /
  Last update: 2021-10-14 11:51    [W:0.078 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site