bpf: Consolidate task_struct BTF_ID declarations
authorDaniel Xu <dxu@dxuuu.xyz>
Tue, 24 Aug 2021 02:43:47 +0000 (19:43 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 25 Aug 2021 17:37:05 +0000 (10:37 -0700)
No need to have it defined 5 times. Once is enough.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/6dcefa5bed26fe1226f26683f36819bb53ec19a2.1629772842.git.dxu@dxuuu.xyz
include/linux/btf_ids.h
kernel/bpf/bpf_task_storage.c
kernel/bpf/stackmap.c
kernel/bpf/task_iter.c
kernel/trace/bpf_trace.c

index 6d13950..93d881a 100644 (file)
@@ -188,4 +188,6 @@ MAX_BTF_SOCK_TYPE,
 extern u32 btf_sock_ids[];
 #endif
 
+extern u32 btf_task_struct_ids[];
+
 #endif
index 3ce7575..ebfa8bc 100644 (file)
@@ -317,15 +317,13 @@ const struct bpf_map_ops task_storage_map_ops = {
        .map_owner_storage_ptr = task_storage_ptr,
 };
 
-BTF_ID_LIST_SINGLE(bpf_task_storage_btf_ids, struct, task_struct)
-
 const struct bpf_func_proto bpf_task_storage_get_proto = {
        .func = bpf_task_storage_get,
        .gpl_only = false,
        .ret_type = RET_PTR_TO_MAP_VALUE_OR_NULL,
        .arg1_type = ARG_CONST_MAP_PTR,
        .arg2_type = ARG_PTR_TO_BTF_ID,
-       .arg2_btf_id = &bpf_task_storage_btf_ids[0],
+       .arg2_btf_id = &btf_task_struct_ids[0],
        .arg3_type = ARG_PTR_TO_MAP_VALUE_OR_NULL,
        .arg4_type = ARG_ANYTHING,
 };
@@ -336,5 +334,5 @@ const struct bpf_func_proto bpf_task_storage_delete_proto = {
        .ret_type = RET_INTEGER,
        .arg1_type = ARG_CONST_MAP_PTR,
        .arg2_type = ARG_PTR_TO_BTF_ID,
-       .arg2_btf_id = &bpf_task_storage_btf_ids[0],
+       .arg2_btf_id = &btf_task_struct_ids[0],
 };
index 6fbc2ab..e8eefdf 100644 (file)
@@ -530,14 +530,12 @@ BPF_CALL_4(bpf_get_task_stack, struct task_struct *, task, void *, buf,
        return res;
 }
 
-BTF_ID_LIST_SINGLE(bpf_get_task_stack_btf_ids, struct, task_struct)
-
 const struct bpf_func_proto bpf_get_task_stack_proto = {
        .func           = bpf_get_task_stack,
        .gpl_only       = false,
        .ret_type       = RET_INTEGER,
        .arg1_type      = ARG_PTR_TO_BTF_ID,
-       .arg1_btf_id    = &bpf_get_task_stack_btf_ids[0],
+       .arg1_btf_id    = &btf_task_struct_ids[0],
        .arg2_type      = ARG_PTR_TO_UNINIT_MEM,
        .arg3_type      = ARG_CONST_SIZE_OR_ZERO,
        .arg4_type      = ARG_ANYTHING,
index b68cb5d..b48750b 100644 (file)
@@ -525,7 +525,6 @@ static const struct seq_operations task_vma_seq_ops = {
 };
 
 BTF_ID_LIST(btf_task_file_ids)
-BTF_ID(struct, task_struct)
 BTF_ID(struct, file)
 BTF_ID(struct, vm_area_struct)
 
@@ -591,19 +590,19 @@ static int __init task_iter_init(void)
 {
        int ret;
 
-       task_reg_info.ctx_arg_info[0].btf_id = btf_task_file_ids[0];
+       task_reg_info.ctx_arg_info[0].btf_id = btf_task_struct_ids[0];
        ret = bpf_iter_reg_target(&task_reg_info);
        if (ret)
                return ret;
 
-       task_file_reg_info.ctx_arg_info[0].btf_id = btf_task_file_ids[0];
-       task_file_reg_info.ctx_arg_info[1].btf_id = btf_task_file_ids[1];
+       task_file_reg_info.ctx_arg_info[0].btf_id = btf_task_struct_ids[0];
+       task_file_reg_info.ctx_arg_info[1].btf_id = btf_task_file_ids[0];
        ret =  bpf_iter_reg_target(&task_file_reg_info);
        if (ret)
                return ret;
 
-       task_vma_reg_info.ctx_arg_info[0].btf_id = btf_task_file_ids[0];
-       task_vma_reg_info.ctx_arg_info[1].btf_id = btf_task_file_ids[2];
+       task_vma_reg_info.ctx_arg_info[0].btf_id = btf_task_struct_ids[0];
+       task_vma_reg_info.ctx_arg_info[1].btf_id = btf_task_file_ids[1];
        return bpf_iter_reg_target(&task_vma_reg_info);
 }
 late_initcall(task_iter_init);
index cbc73c0..50d055f 100644 (file)
@@ -714,13 +714,13 @@ BPF_CALL_0(bpf_get_current_task_btf)
        return (unsigned long) current;
 }
 
-BTF_ID_LIST_SINGLE(bpf_get_current_btf_ids, struct, task_struct)
+BTF_ID_LIST_GLOBAL_SINGLE(btf_task_struct_ids, struct, task_struct)
 
 static const struct bpf_func_proto bpf_get_current_task_btf_proto = {
        .func           = bpf_get_current_task_btf,
        .gpl_only       = true,
        .ret_type       = RET_PTR_TO_BTF_ID,
-       .ret_btf_id     = &bpf_get_current_btf_ids[0],
+       .ret_btf_id     = &btf_task_struct_ids[0],
 };
 
 BPF_CALL_2(bpf_current_task_under_cgroup, struct bpf_map *, map, u32, idx)