mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 08:14:15 +08:00
bpf: Reserve space for BPF trampoline in BPF programs
BPF trampoline can be made to work with existing 5 bytes of BPF program prologue, but let's add 5 bytes of NOPs to the beginning of every JITed BPF program to make BPF trampoline job easier. They can be removed in the future. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20191114185720.1641606-14-ast@kernel.org
This commit is contained in:
parent
e76d776e9c
commit
9fd4a39dc7
@ -206,7 +206,7 @@ struct jit_context {
|
|||||||
/* number of bytes emit_call() needs to generate call instruction */
|
/* number of bytes emit_call() needs to generate call instruction */
|
||||||
#define X86_CALL_SIZE 5
|
#define X86_CALL_SIZE 5
|
||||||
|
|
||||||
#define PROLOGUE_SIZE 20
|
#define PROLOGUE_SIZE 25
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Emit x86-64 prologue code for BPF program and check its size.
|
* Emit x86-64 prologue code for BPF program and check its size.
|
||||||
@ -215,8 +215,13 @@ struct jit_context {
|
|||||||
static void emit_prologue(u8 **pprog, u32 stack_depth, bool ebpf_from_cbpf)
|
static void emit_prologue(u8 **pprog, u32 stack_depth, bool ebpf_from_cbpf)
|
||||||
{
|
{
|
||||||
u8 *prog = *pprog;
|
u8 *prog = *pprog;
|
||||||
int cnt = 0;
|
int cnt = X86_CALL_SIZE;
|
||||||
|
|
||||||
|
/* BPF trampoline can be made to work without these nops,
|
||||||
|
* but let's waste 5 bytes for now and optimize later
|
||||||
|
*/
|
||||||
|
memcpy(prog, ideal_nops[NOP_ATOMIC5], cnt);
|
||||||
|
prog += cnt;
|
||||||
EMIT1(0x55); /* push rbp */
|
EMIT1(0x55); /* push rbp */
|
||||||
EMIT3(0x48, 0x89, 0xE5); /* mov rbp, rsp */
|
EMIT3(0x48, 0x89, 0xE5); /* mov rbp, rsp */
|
||||||
/* sub rsp, rounded_stack_depth */
|
/* sub rsp, rounded_stack_depth */
|
||||||
|
Loading…
Reference in New Issue
Block a user