mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: x86@kernel.org, andrew.cooper3@citrix.com,
	linux-kernel@vger.kernel.org, alexei.starovoitov@gmail.com,
	ndesaulniers@google.com
Subject: Re: [PATCH 9/9] bpf,x86: Respect X86_FEATURE_RETPOLINE*
Date: Wed, 13 Oct 2021 23:54:51 +0200	[thread overview]
Message-ID: <YWdVq8UWpvMwnzht@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20211013210605.bz6l7o5xzik5ckga@treble>

On Wed, Oct 13, 2021 at 02:06:05PM -0700, Josh Poimboeuf wrote:
> On Wed, Oct 13, 2021 at 02:22:26PM +0200, Peter Zijlstra wrote:
> > Current BPF codegen doesn't respect X86_FEATURE_RETPOLINE* flags and
> > unconditionally emits a thunk call, this is sub-optimal and doesn't
> > match the regular, compiler generated, code.
> > 
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> >  arch/x86/net/bpf_jit_comp.c |   18 +++++++++++-------
> >  1 file changed, 11 insertions(+), 7 deletions(-)
> > 
> > --- a/arch/x86/net/bpf_jit_comp.c
> > +++ b/arch/x86/net/bpf_jit_comp.c
> > @@ -2123,14 +2123,18 @@ static int emit_fallback_jump(u8 **pprog
> >  	int err = 0;
> >  
> >  #ifdef CONFIG_RETPOLINE
> > -	/* Note that this assumes the the compiler uses external
> > -	 * thunks for indirect calls. Both clang and GCC use the same
> > -	 * naming convention for external thunks.
> > -	 */
> > -	err = emit_jump(&prog, __x86_indirect_thunk_rdx, prog);
> > -#else
> > -	EMIT2(0xFF, 0xE2);	/* jmp rdx */
> > +	if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) {
> > +		if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_AMD)) {
> > +			/* The AMD retpoline can be easily emitted inline. */
> > +			EMIT3(0x0F, 0xAE, 0xE8);	/* lfence */
> > +			EMIT2(0xFF, 0xE2);		/* jmp rdx */
> > +		} else {
> > +			/* Call the retpoline thunk */
> > +			err = emit_jump(&prog, __x86_indirect_thunk_rdx, prog);
> > +		}
> > +	} else
> >  #endif
> > +	EMIT2(0xFF, 0xE2);	/* jmp rdx */
> 
> But the rest of eBPF JIT just emits retpolines unconditionally
> regardless of feature, for example see RETPOLINE_RCX_BPF_JIT().  So I'm
> thinking this should probably be consistent with that (or that with
> this).

Argh, I grepped for __x86_indirect_thunk, and missed they're writing
retpolines themselves. Bah.

Yes, that needs cleaning up. I'll go prod at that tomorrow.

  reply	other threads:[~2021-10-13 21:55 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-13 12:22 [PATCH 0/9] x86: Rewrite the retpoline rewrite logic Peter Zijlstra
2021-10-13 12:22 ` [PATCH 1/9] objtool,x86: Replace alternatives with .retpoline_sites Peter Zijlstra
2021-10-13 13:29   ` Borislav Petkov
2021-10-13 20:11   ` Josh Poimboeuf
2021-10-14 15:43     ` Peter Zijlstra
2021-10-13 12:22 ` [PATCH 2/9] x86/retpoline: Remove unused replacement symbols Peter Zijlstra
2021-10-13 12:22 ` [PATCH 3/9] x86/asm: Fix register order Peter Zijlstra
2021-10-13 20:15   ` Josh Poimboeuf
2021-10-13 12:22 ` [PATCH 4/9] x86/alternative: Implement .retpoline_sites support Peter Zijlstra
2021-10-13 14:38   ` Andrew Cooper
2021-10-13 15:12     ` Peter Zijlstra
2021-10-13 17:11       ` Andrew Cooper
2021-10-14 10:05       ` Peter Zijlstra
2021-10-13 20:39   ` Josh Poimboeuf
2021-10-13 21:20     ` Peter Zijlstra
2021-10-13 21:49       ` Josh Poimboeuf
2021-10-13 21:52         ` Josh Poimboeuf
2021-10-13 22:10         ` Peter Zijlstra
2021-10-13 22:47           ` Andrew Cooper
2021-10-13 20:52   ` Josh Poimboeuf
2021-10-13 21:00     ` Peter Zijlstra
2021-10-19 11:37     ` Peter Zijlstra
2021-10-19 16:46       ` Josh Poimboeuf
2021-10-19 16:49         ` Josh Poimboeuf
2021-10-20  8:25           ` Peter Zijlstra
2021-10-20  8:30           ` Peter Zijlstra
2021-10-13 21:11   ` Josh Poimboeuf
2021-10-13 21:43     ` Peter Zijlstra
2021-10-13 22:05       ` Josh Poimboeuf
2021-10-13 22:14         ` Peter Zijlstra
2021-10-15 14:24   ` Borislav Petkov
2021-10-15 16:56     ` Peter Zijlstra
2021-10-18 23:06       ` Alexander Lobakin
2021-10-19  0:25         ` Alexander Lobakin
2021-10-19  9:47           ` Alexander Lobakin
2021-10-19 10:16             ` Peter Zijlstra
2021-10-19 15:37               ` Sami Tolvanen
2021-10-19 18:00                 ` Alexander Lobakin
2021-10-19  9:40         ` Peter Zijlstra
2021-10-19 10:02           ` Peter Zijlstra
2021-10-13 12:22 ` [PATCH 5/9] x86/alternative: Handle Jcc __x86_indirect_thunk_\reg Peter Zijlstra
2021-10-13 20:11   ` Nick Desaulniers
2021-10-13 21:08     ` Peter Zijlstra
2021-10-13 12:22 ` [PATCH 6/9] x86/alternative: Try inline spectre_v2=retpoline,amd Peter Zijlstra
2021-10-13 12:22 ` [PATCH 7/9] x86/alternative: Add debug prints to apply_retpolines() Peter Zijlstra
2021-10-13 12:22 ` [PATCH 8/9] x86,bugs: Unconditionally allow spectre_v2=retpoline,amd Peter Zijlstra
2021-10-13 12:22 ` [PATCH 9/9] bpf,x86: Respect X86_FEATURE_RETPOLINE* Peter Zijlstra
2021-10-13 21:06   ` Josh Poimboeuf
2021-10-13 21:54     ` Peter Zijlstra [this message]
2021-10-14  9:46       ` Peter Zijlstra
2021-10-14  9:48         ` Peter Zijlstra
2021-10-20  7:34         ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YWdVq8UWpvMwnzht@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®