UPSTREAM: bpf: Add initial poke descriptor table for jit images
Add initial poke table data structures and management to the BPF prog that can later be used by JITs. Also add an instance of poke specific data for tail call maps; plan for later work is to extend this also for BPF static keys. Change-Id: Id1b4b5c7523f8b07e328a2b788565e1aabda6f3e Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/1db285ec2ea4207ee0455b3f8e191a4fc58b9ade.1574452833.git.daniel@iogearbox.net Signed-off-by: Sorayukii <sorayukii69@gmail.com>
This commit is contained in:
parent
7c1df8f94f
commit
eacbdf75b8
3 changed files with 64 additions and 0 deletions
|
|
@ -491,6 +491,24 @@ struct bpf_func_info_aux {
|
|||
bool unreliable;
|
||||
};
|
||||
|
||||
enum bpf_jit_poke_reason {
|
||||
BPF_POKE_REASON_TAIL_CALL,
|
||||
};
|
||||
|
||||
/* Descriptor of pokes pointing /into/ the JITed image. */
|
||||
struct bpf_jit_poke_descriptor {
|
||||
void *ip;
|
||||
union {
|
||||
struct {
|
||||
struct bpf_map *map;
|
||||
u32 key;
|
||||
} tail_call;
|
||||
};
|
||||
bool ip_stable;
|
||||
u8 adj_off;
|
||||
u16 reason;
|
||||
};
|
||||
|
||||
struct bpf_prog_aux {
|
||||
atomic64_t refcnt;
|
||||
u32 used_map_cnt;
|
||||
|
|
@ -516,6 +534,8 @@ struct bpf_prog_aux {
|
|||
const char *attach_func_name;
|
||||
struct bpf_prog **func;
|
||||
void *jit_data; /* JIT specific data. arch dependent */
|
||||
struct bpf_jit_poke_descriptor *poke_tab;
|
||||
u32 size_poke_tab;
|
||||
struct latch_tree_node ksym_tnode;
|
||||
struct list_head ksym_lnode;
|
||||
const struct bpf_prog_ops *ops;
|
||||
|
|
|
|||
|
|
@ -1005,6 +1005,9 @@ void *bpf_jit_alloc_exec(unsigned long size);
|
|||
void bpf_jit_free_exec(void *addr);
|
||||
void bpf_jit_free(struct bpf_prog *fp);
|
||||
|
||||
int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
|
||||
struct bpf_jit_poke_descriptor *poke);
|
||||
|
||||
int bpf_jit_get_func_addr(const struct bpf_prog *prog,
|
||||
const struct bpf_insn *insn, bool extra_pass,
|
||||
u64 *func_addr, bool *func_addr_fixed);
|
||||
|
|
@ -1108,6 +1111,13 @@ static inline bool bpf_prog_ebpf_jited(const struct bpf_prog *fp)
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline int
|
||||
bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
|
||||
struct bpf_jit_poke_descriptor *poke)
|
||||
{
|
||||
return -ENOTSUPP;
|
||||
}
|
||||
|
||||
static inline void bpf_jit_free(struct bpf_prog *fp)
|
||||
{
|
||||
bpf_prog_unlock_free(fp);
|
||||
|
|
|
|||
|
|
@ -265,6 +265,7 @@ void __bpf_prog_free(struct bpf_prog *fp)
|
|||
{
|
||||
if (fp->aux) {
|
||||
free_percpu(fp->aux->stats);
|
||||
kfree(fp->aux->poke_tab);
|
||||
kfree(fp->aux);
|
||||
}
|
||||
vfree(fp);
|
||||
|
|
@ -824,6 +825,39 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
|
|||
return ret;
|
||||
}
|
||||
|
||||
int bpf_jit_add_poke_descriptor(struct bpf_prog *prog,
|
||||
struct bpf_jit_poke_descriptor *poke)
|
||||
{
|
||||
struct bpf_jit_poke_descriptor *tab = prog->aux->poke_tab;
|
||||
static const u32 poke_tab_max = 1024;
|
||||
u32 slot = prog->aux->size_poke_tab;
|
||||
u32 size = slot + 1;
|
||||
|
||||
if (size > poke_tab_max)
|
||||
return -ENOSPC;
|
||||
if (poke->ip || poke->ip_stable || poke->adj_off)
|
||||
return -EINVAL;
|
||||
|
||||
switch (poke->reason) {
|
||||
case BPF_POKE_REASON_TAIL_CALL:
|
||||
if (!poke->tail_call.map)
|
||||
return -EINVAL;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
tab = krealloc(tab, size * sizeof(*poke), GFP_KERNEL);
|
||||
if (!tab)
|
||||
return -ENOMEM;
|
||||
|
||||
memcpy(&tab[slot], poke, sizeof(*poke));
|
||||
prog->aux->size_poke_tab = size;
|
||||
prog->aux->poke_tab = tab;
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
struct bpf_binary_header *
|
||||
bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
|
||||
unsigned int alignment,
|
||||
|
|
|
|||
Loading…
Reference in a new issue