Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: support access variable length array of integer type

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>

authored by

Feng Zhou and committed by
Alexei Starovoitov
2569c7b8 2ddade32

+5 -3
+5 -3
kernel/bpf/btf.c
··· 6157 6157 if (off < moff) 6158 6158 goto error; 6159 6159 6160 - /* Only allow structure for now, can be relaxed for 6161 - * other types later. 6162 - */ 6160 + /* allow structure and integer */ 6163 6161 t = btf_type_skip_modifiers(btf, array_elem->type, 6164 6162 NULL); 6163 + 6164 + if (btf_type_is_int(t)) 6165 + return WALK_SCALAR; 6166 + 6165 6167 if (!btf_type_is_struct(t)) 6166 6168 goto error; 6167 6169