All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	ast@kernel.org, torvalds@linux-foundation.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH bpf] bpf, x64: implement retpoline for tail call
Date: Wed, 21 Feb 2018 19:53:22 -0800	[thread overview]
Message-ID: <1519271602.55655.50.camel@gmail.com> (raw)
In-Reply-To: <20180222034325.lecpbghrrmxy2ilt@ast-mbp.dhcp.thefacebook.com>

On Wed, 2018-02-21 at 19:43 -0800, Alexei Starovoitov wrote:
> On Wed, Feb 21, 2018 at 07:04:02PM -0800, Eric Dumazet wrote:
> > On Thu, 2018-02-22 at 01:05 +0100, Daniel Borkmann wrote:
> > 
> > ...
> > 
> > > +/* Instead of plain jmp %rax, we emit a retpoline to control
> > > + * speculative execution for the indirect branch.
> > > + */
> > > +static void emit_retpoline_rax_trampoline(u8 **pprog)
> > > +{
> > > +	u8 *prog = *pprog;
> > > +	int cnt = 0;
> > > +
> > > +	EMIT1_off32(0xE8, 7);	 /* callq <set_up_target> */
> > > +	/* capture_spec: */
> > > +	EMIT2(0xF3, 0x90);	 /* pause */
> > > +	EMIT3(0x0F, 0xAE, 0xE8); /* lfence */
> > > +	EMIT2(0xEB, 0xF9);	 /* jmp <capture_spec> */
> > > +	/* set_up_target: */
> > > +	EMIT4(0x48, 0x89, 0x04, 0x24); /* mov %rax,(%rsp) */
> > > +	EMIT1(0xC3);		 /* retq */
> > > +
> > > +	BUILD_BUG_ON(cnt != RETPOLINE_SIZE);
> > > +	*pprog = prog;
> > 
> > You might define the actual code sequence (and length) in 
> > arch/x86/include/asm/nospec-branch.h
> > 
> > If we need to adjust code sequences for RETPOLINE, then we wont
> > forget/miss that arch/x86/net/bpf_jit_comp.c had it hard-coded.
> 
> like adding a comment to asm/nospec-branch.h that says
> "dont forget to adjust bpf_jit_comp.c" ?
> but clang/gcc generate slightly different sequences for
> retpoline anyway, so even if '.macro RETPOLINE_JMP' in
> nospec-branch.h changes it doesn't mean that x64 jit has to change.
> So what kinda comment there would make sense?

I was thinking of something very explicit :

/* byte sequence for following assembly code used by eBPF
   call ...
   ...
   retq
*/
#define RETPOLINE_RAX_DIRECT_FOR_EBPF                         \
       EMIT1_off32(0xE8, 7);    /* callq <set_up_target> */   \
       /* capture_spec: */                                    \
       EMIT2(0xF3, 0x90);       /* pause */                   \
       EMIT3(0x0F, 0xAE, 0xE8); /* lfence */                  \
       EMIT2(0xEB, 0xF9);       /* jmp <capture_spec> */      \
       /* set_up_target: */                                   \
       EMIT4(0x48, 0x89, 0x04, 0x24); /* mov %rax,(%rsp) */   \
       EMIT1(0xC3);             /* retq */                    \

Might be simply byte encoded, (array of 17 bytes)

Well, something like that anyway...

  reply	other threads:[~2018-02-22  3:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-22  0:05 [PATCH bpf] bpf, x64: implement retpoline for tail call Daniel Borkmann
2018-02-22  3:04 ` Eric Dumazet
2018-02-22  3:43   ` Alexei Starovoitov
2018-02-22  3:53     ` Eric Dumazet [this message]
2018-02-22  4:59       ` Alexei Starovoitov
2018-02-22  9:20       ` Daniel Borkmann

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=1519271602.55655.50.camel@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    --cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.