[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YWf9Aje1F06vD5O6@hirez.programming.kicks-ass.net>
Date: Thu, 14 Oct 2021 11:48:50 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Josh Poimboeuf <jpoimboe@...hat.com>
Cc: x86@...nel.org, andrew.cooper3@...rix.com,
linux-kernel@...r.kernel.org, alexei.starovoitov@...il.com,
ndesaulniers@...gle.com
Subject: Re: [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;
> +}
Powered by blists - more mailing lists