Commit e2fa0156 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by Daniel Borkmann

libbpf: Preliminary support for fd_idx

Prep libbpf to use FD_IDX kernel feature when generating loader program.
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210514003623.28033-14-alexei.starovoitov@gmail.com
parent 9ca1f56a
...@@ -412,6 +412,8 @@ struct module_btf { ...@@ -412,6 +412,8 @@ struct module_btf {
int fd; int fd;
}; };
struct bpf_gen;
struct bpf_object { struct bpf_object {
char name[BPF_OBJ_NAME_LEN]; char name[BPF_OBJ_NAME_LEN];
char license[64]; char license[64];
...@@ -432,6 +434,8 @@ struct bpf_object { ...@@ -432,6 +434,8 @@ struct bpf_object {
bool loaded; bool loaded;
bool has_subcalls; bool has_subcalls;
struct bpf_gen *gen_loader;
/* /*
* Information when doing elf related work. Only valid if fd * Information when doing elf related work. Only valid if fd
* is valid. * is valid.
...@@ -6388,19 +6392,34 @@ bpf_object__relocate_data(struct bpf_object *obj, struct bpf_program *prog) ...@@ -6388,19 +6392,34 @@ bpf_object__relocate_data(struct bpf_object *obj, struct bpf_program *prog)
switch (relo->type) { switch (relo->type) {
case RELO_LD64: case RELO_LD64:
insn[0].src_reg = BPF_PSEUDO_MAP_FD; if (obj->gen_loader) {
insn[0].imm = obj->maps[relo->map_idx].fd; insn[0].src_reg = BPF_PSEUDO_MAP_IDX;
insn[0].imm = relo->map_idx;
} else {
insn[0].src_reg = BPF_PSEUDO_MAP_FD;
insn[0].imm = obj->maps[relo->map_idx].fd;
}
break; break;
case RELO_DATA: case RELO_DATA:
insn[0].src_reg = BPF_PSEUDO_MAP_VALUE;
insn[1].imm = insn[0].imm + relo->sym_off; insn[1].imm = insn[0].imm + relo->sym_off;
insn[0].imm = obj->maps[relo->map_idx].fd; if (obj->gen_loader) {
insn[0].src_reg = BPF_PSEUDO_MAP_IDX_VALUE;
insn[0].imm = relo->map_idx;
} else {
insn[0].src_reg = BPF_PSEUDO_MAP_VALUE;
insn[0].imm = obj->maps[relo->map_idx].fd;
}
break; break;
case RELO_EXTERN_VAR: case RELO_EXTERN_VAR:
ext = &obj->externs[relo->sym_off]; ext = &obj->externs[relo->sym_off];
if (ext->type == EXT_KCFG) { if (ext->type == EXT_KCFG) {
insn[0].src_reg = BPF_PSEUDO_MAP_VALUE; if (obj->gen_loader) {
insn[0].imm = obj->maps[obj->kconfig_map_idx].fd; insn[0].src_reg = BPF_PSEUDO_MAP_IDX_VALUE;
insn[0].imm = obj->kconfig_map_idx;
} else {
insn[0].src_reg = BPF_PSEUDO_MAP_VALUE;
insn[0].imm = obj->maps[obj->kconfig_map_idx].fd;
}
insn[1].imm = ext->kcfg.data_off; insn[1].imm = ext->kcfg.data_off;
} else /* EXT_KSYM */ { } else /* EXT_KSYM */ {
if (ext->ksym.type_id) { /* typed ksyms */ if (ext->ksym.type_id) { /* typed ksyms */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment