bpf: support access variable length array of integer type
authorFeng Zhou <zhoufeng.zf@bytedance.com>
Thu, 20 Apr 2023 03:27:34 +0000 (11:27 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 20 Apr 2023 04:29:39 +0000 (21:29 -0700)
After this commit:
bpf: Support variable length array in tracing programs (9c5f8a1008a1)
Trace programs can access variable length array, but for structure
type. This patch adds support for integer type.

Example:
Hook load_balance
struct sched_domain {
...
unsigned long span[];
}

The access: sd->span[0].

Co-developed-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
Link: https://lore.kernel.org/r/20230420032735.27760-2-zhoufeng.zf@bytedance.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/btf.c

index 027f9f8a355169ef798390b6ccc8070d2793fb34..a0887ee44e89968b3e2765ad15ac076ae021cc7c 100644 (file)
@@ -6157,11 +6157,13 @@ again:
                if (off < moff)
                        goto error;
 
-               /* Only allow structure for now, can be relaxed for
-                * other types later.
-                */
+               /* allow structure and integer */
                t = btf_type_skip_modifiers(btf, array_elem->type,
                                            NULL);
+
+               if (btf_type_is_int(t))
+                       return WALK_SCALAR;
+
                if (!btf_type_is_struct(t))
                        goto error;