Commit 7cc595a6 authored by Alexei Starovoitov's avatar Alexei Starovoitov

Merge branch 'introduce btf_tracing_ids'

Song Liu says:

====================

Changes v2 => v3:
1. Fix bug in task_iter.c. (Kernel test robot <lkp@intel.com>)

Changes v1 => v2:
1. Add patch 2/2. (Alexei)

1/2 fixes issue with btf_task_struct_ids w/o CONFIG_DEBUG_INFO_BTF.
2/2 replaces btf_task_struct_ids with easier to understand btf_tracing_ids.
====================
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents 314f14ab d19ddb47
...@@ -73,7 +73,7 @@ asm( \ ...@@ -73,7 +73,7 @@ asm( \
__BTF_ID_LIST(name, local) \ __BTF_ID_LIST(name, local) \
extern u32 name[]; extern u32 name[];
#define BTF_ID_LIST_GLOBAL(name) \ #define BTF_ID_LIST_GLOBAL(name, n) \
__BTF_ID_LIST(name, globl) __BTF_ID_LIST(name, globl)
/* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with
...@@ -83,7 +83,7 @@ __BTF_ID_LIST(name, globl) ...@@ -83,7 +83,7 @@ __BTF_ID_LIST(name, globl)
BTF_ID_LIST(name) \ BTF_ID_LIST(name) \
BTF_ID(prefix, typename) BTF_ID(prefix, typename)
#define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \ #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) \
BTF_ID_LIST_GLOBAL(name) \ BTF_ID_LIST_GLOBAL(name, 1) \
BTF_ID(prefix, typename) BTF_ID(prefix, typename)
/* /*
...@@ -149,7 +149,7 @@ extern struct btf_id_set name; ...@@ -149,7 +149,7 @@ extern struct btf_id_set name;
#define BTF_ID_LIST(name) static u32 name[5]; #define BTF_ID_LIST(name) static u32 name[5];
#define BTF_ID(prefix, name) #define BTF_ID(prefix, name)
#define BTF_ID_UNUSED #define BTF_ID_UNUSED
#define BTF_ID_LIST_GLOBAL(name) u32 name[1]; #define BTF_ID_LIST_GLOBAL(name, n) u32 name[n];
#define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 name[1]; #define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 name[1];
#define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 name[1]; #define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 name[1];
#define BTF_SET_START(name) static struct btf_id_set name = { 0 }; #define BTF_SET_START(name) static struct btf_id_set name = { 0 };
...@@ -189,6 +189,18 @@ MAX_BTF_SOCK_TYPE, ...@@ -189,6 +189,18 @@ MAX_BTF_SOCK_TYPE,
extern u32 btf_sock_ids[]; extern u32 btf_sock_ids[];
#endif #endif
extern u32 btf_task_struct_ids[]; #define BTF_TRACING_TYPE_xxx \
BTF_TRACING_TYPE(BTF_TRACING_TYPE_TASK, task_struct) \
BTF_TRACING_TYPE(BTF_TRACING_TYPE_FILE, file) \
BTF_TRACING_TYPE(BTF_TRACING_TYPE_VMA, vm_area_struct)
enum {
#define BTF_TRACING_TYPE(name, type) name,
BTF_TRACING_TYPE_xxx
#undef BTF_TRACING_TYPE
MAX_BTF_TRACING_TYPE,
};
extern u32 btf_tracing_ids[];
#endif #endif
...@@ -323,7 +323,7 @@ const struct bpf_func_proto bpf_task_storage_get_proto = { ...@@ -323,7 +323,7 @@ const struct bpf_func_proto bpf_task_storage_get_proto = {
.ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL, .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL,
.arg1_type = ARG_CONST_MAP_PTR, .arg1_type = ARG_CONST_MAP_PTR,
.arg2_type = ARG_PTR_TO_BTF_ID, .arg2_type = ARG_PTR_TO_BTF_ID,
.arg2_btf_id = &btf_task_struct_ids[0], .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK],
.arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL, .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL,
.arg4_type = ARG_ANYTHING, .arg4_type = ARG_ANYTHING,
}; };
...@@ -334,5 +334,5 @@ const struct bpf_func_proto bpf_task_storage_delete_proto = { ...@@ -334,5 +334,5 @@ const struct bpf_func_proto bpf_task_storage_delete_proto = {
.ret_type = RET_INTEGER, .ret_type = RET_INTEGER,
.arg1_type = ARG_CONST_MAP_PTR, .arg1_type = ARG_CONST_MAP_PTR,
.arg2_type = ARG_PTR_TO_BTF_ID, .arg2_type = ARG_PTR_TO_BTF_ID,
.arg2_btf_id = &btf_task_struct_ids[0], .arg2_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK],
}; };
...@@ -6354,10 +6354,10 @@ const struct bpf_func_proto bpf_btf_find_by_name_kind_proto = { ...@@ -6354,10 +6354,10 @@ const struct bpf_func_proto bpf_btf_find_by_name_kind_proto = {
.arg4_type = ARG_ANYTHING, .arg4_type = ARG_ANYTHING,
}; };
BTF_ID_LIST_GLOBAL(btf_task_struct_ids) BTF_ID_LIST_GLOBAL(btf_tracing_ids, MAX_BTF_TRACING_TYPE)
BTF_ID(struct, task_struct) #define BTF_TRACING_TYPE(name, type) BTF_ID(struct, type)
BTF_ID(struct, file) BTF_TRACING_TYPE_xxx
BTF_ID(struct, vm_area_struct) #undef BTF_TRACING_TYPE
/* BTF ID set registration API for modules */ /* BTF ID set registration API for modules */
......
...@@ -489,7 +489,7 @@ const struct bpf_func_proto bpf_get_task_stack_proto = { ...@@ -489,7 +489,7 @@ const struct bpf_func_proto bpf_get_task_stack_proto = {
.gpl_only = false, .gpl_only = false,
.ret_type = RET_INTEGER, .ret_type = RET_INTEGER,
.arg1_type = ARG_PTR_TO_BTF_ID, .arg1_type = ARG_PTR_TO_BTF_ID,
.arg1_btf_id = &btf_task_struct_ids[0], .arg1_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK],
.arg2_type = ARG_PTR_TO_UNINIT_MEM, .arg2_type = ARG_PTR_TO_UNINIT_MEM,
.arg3_type = ARG_CONST_SIZE_OR_ZERO, .arg3_type = ARG_CONST_SIZE_OR_ZERO,
.arg4_type = ARG_ANYTHING, .arg4_type = ARG_ANYTHING,
......
...@@ -622,7 +622,7 @@ const struct bpf_func_proto bpf_find_vma_proto = { ...@@ -622,7 +622,7 @@ const struct bpf_func_proto bpf_find_vma_proto = {
.func = bpf_find_vma, .func = bpf_find_vma,
.ret_type = RET_INTEGER, .ret_type = RET_INTEGER,
.arg1_type = ARG_PTR_TO_BTF_ID, .arg1_type = ARG_PTR_TO_BTF_ID,
.arg1_btf_id = &btf_task_struct_ids[0], .arg1_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK],
.arg2_type = ARG_ANYTHING, .arg2_type = ARG_ANYTHING,
.arg3_type = ARG_PTR_TO_FUNC, .arg3_type = ARG_PTR_TO_FUNC,
.arg4_type = ARG_PTR_TO_STACK_OR_NULL, .arg4_type = ARG_PTR_TO_STACK_OR_NULL,
...@@ -652,19 +652,19 @@ static int __init task_iter_init(void) ...@@ -652,19 +652,19 @@ static int __init task_iter_init(void)
init_irq_work(&work->irq_work, do_mmap_read_unlock); init_irq_work(&work->irq_work, do_mmap_read_unlock);
} }
task_reg_info.ctx_arg_info[0].btf_id = btf_task_struct_ids[0]; task_reg_info.ctx_arg_info[0].btf_id = btf_tracing_ids[BTF_TRACING_TYPE_TASK];
ret = bpf_iter_reg_target(&task_reg_info); ret = bpf_iter_reg_target(&task_reg_info);
if (ret) if (ret)
return ret; return ret;
task_file_reg_info.ctx_arg_info[0].btf_id = btf_task_struct_ids[0]; task_file_reg_info.ctx_arg_info[0].btf_id = btf_tracing_ids[BTF_TRACING_TYPE_TASK];
task_file_reg_info.ctx_arg_info[1].btf_id = btf_task_struct_ids[1]; task_file_reg_info.ctx_arg_info[1].btf_id = btf_tracing_ids[BTF_TRACING_TYPE_FILE];
ret = bpf_iter_reg_target(&task_file_reg_info); ret = bpf_iter_reg_target(&task_file_reg_info);
if (ret) if (ret)
return ret; return ret;
task_vma_reg_info.ctx_arg_info[0].btf_id = btf_task_struct_ids[0]; task_vma_reg_info.ctx_arg_info[0].btf_id = btf_tracing_ids[BTF_TRACING_TYPE_TASK];
task_vma_reg_info.ctx_arg_info[1].btf_id = btf_task_struct_ids[2]; task_vma_reg_info.ctx_arg_info[1].btf_id = btf_tracing_ids[BTF_TRACING_TYPE_VMA];
return bpf_iter_reg_target(&task_vma_reg_info); return bpf_iter_reg_target(&task_vma_reg_info);
} }
late_initcall(task_iter_init); late_initcall(task_iter_init);
...@@ -6147,7 +6147,7 @@ static int set_find_vma_callback_state(struct bpf_verifier_env *env, ...@@ -6147,7 +6147,7 @@ static int set_find_vma_callback_state(struct bpf_verifier_env *env,
callee->regs[BPF_REG_2].type = PTR_TO_BTF_ID; callee->regs[BPF_REG_2].type = PTR_TO_BTF_ID;
__mark_reg_known_zero(&callee->regs[BPF_REG_2]); __mark_reg_known_zero(&callee->regs[BPF_REG_2]);
callee->regs[BPF_REG_2].btf = btf_vmlinux; callee->regs[BPF_REG_2].btf = btf_vmlinux;
callee->regs[BPF_REG_2].btf_id = btf_task_struct_ids[2]; callee->regs[BPF_REG_2].btf_id = btf_tracing_ids[BTF_TRACING_TYPE_VMA],
/* pointer to stack or null */ /* pointer to stack or null */
callee->regs[BPF_REG_3] = caller->regs[BPF_REG_4]; callee->regs[BPF_REG_3] = caller->regs[BPF_REG_4];
......
...@@ -764,7 +764,7 @@ const struct bpf_func_proto bpf_get_current_task_btf_proto = { ...@@ -764,7 +764,7 @@ const struct bpf_func_proto bpf_get_current_task_btf_proto = {
.func = bpf_get_current_task_btf, .func = bpf_get_current_task_btf,
.gpl_only = true, .gpl_only = true,
.ret_type = RET_PTR_TO_BTF_ID, .ret_type = RET_PTR_TO_BTF_ID,
.ret_btf_id = &btf_task_struct_ids[0], .ret_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK],
}; };
BPF_CALL_1(bpf_task_pt_regs, struct task_struct *, task) BPF_CALL_1(bpf_task_pt_regs, struct task_struct *, task)
...@@ -779,7 +779,7 @@ const struct bpf_func_proto bpf_task_pt_regs_proto = { ...@@ -779,7 +779,7 @@ const struct bpf_func_proto bpf_task_pt_regs_proto = {
.func = bpf_task_pt_regs, .func = bpf_task_pt_regs,
.gpl_only = true, .gpl_only = true,
.arg1_type = ARG_PTR_TO_BTF_ID, .arg1_type = ARG_PTR_TO_BTF_ID,
.arg1_btf_id = &btf_task_struct_ids[0], .arg1_btf_id = &btf_tracing_ids[BTF_TRACING_TYPE_TASK],
.ret_type = RET_PTR_TO_BTF_ID, .ret_type = RET_PTR_TO_BTF_ID,
.ret_btf_id = &bpf_task_pt_regs_ids[0], .ret_btf_id = &bpf_task_pt_regs_ids[0],
}; };
......
...@@ -10611,14 +10611,10 @@ void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog) ...@@ -10611,14 +10611,10 @@ void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog)
bpf_dispatcher_change_prog(BPF_DISPATCHER_PTR(xdp), prev_prog, prog); bpf_dispatcher_change_prog(BPF_DISPATCHER_PTR(xdp), prev_prog, prog);
} }
#ifdef CONFIG_DEBUG_INFO_BTF BTF_ID_LIST_GLOBAL(btf_sock_ids, MAX_BTF_SOCK_TYPE)
BTF_ID_LIST_GLOBAL(btf_sock_ids)
#define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type) #define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type)
BTF_SOCK_TYPE_xxx BTF_SOCK_TYPE_xxx
#undef BTF_SOCK_TYPE #undef BTF_SOCK_TYPE
#else
u32 btf_sock_ids[MAX_BTF_SOCK_TYPE];
#endif
BPF_CALL_1(bpf_skc_to_tcp6_sock, struct sock *, sk) BPF_CALL_1(bpf_skc_to_tcp6_sock, struct sock *, sk)
{ {
......
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