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

selftests/bpf: Use both syntaxes for field-based CO-RE helpers

Excercise both supported forms of bpf_core_field_exists() and
bpf_core_field_size() helpers: variable-based field reference and
type/field name-based one.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220509004148.1801791-5-andrii@kernel.org

authored by

Andrii Nakryiko and committed by
Daniel Borkmann
2a4ca46b 73d0280f

+9 -10
+5 -6
tools/testing/selftests/bpf/progs/test_core_reloc_existence.c
··· 45 45 struct core_reloc_existence_output *out = (void *)&data.out; 46 46 47 47 out->a_exists = bpf_core_field_exists(in->a); 48 - if (bpf_core_field_exists(in->a)) 48 + if (bpf_core_field_exists(struct core_reloc_existence, a)) 49 49 out->a_value = BPF_CORE_READ(in, a); 50 50 else 51 51 out->a_value = 0xff000001u; 52 52 53 53 out->b_exists = bpf_core_field_exists(in->b); 54 - if (bpf_core_field_exists(in->b)) 54 + if (bpf_core_field_exists(struct core_reloc_existence, b)) 55 55 out->b_value = BPF_CORE_READ(in, b); 56 56 else 57 57 out->b_value = 0xff000002u; 58 58 59 59 out->c_exists = bpf_core_field_exists(in->c); 60 - if (bpf_core_field_exists(in->c)) 60 + if (bpf_core_field_exists(struct core_reloc_existence, c)) 61 61 out->c_value = BPF_CORE_READ(in, c); 62 62 else 63 63 out->c_value = 0xff000003u; 64 64 65 65 out->arr_exists = bpf_core_field_exists(in->arr); 66 - if (bpf_core_field_exists(in->arr)) 66 + if (bpf_core_field_exists(struct core_reloc_existence, arr)) 67 67 out->arr_value = BPF_CORE_READ(in, arr[0]); 68 68 else 69 69 out->arr_value = 0xff000004u; 70 70 71 71 out->s_exists = bpf_core_field_exists(in->s); 72 - if (bpf_core_field_exists(in->s)) 72 + if (bpf_core_field_exists(struct core_reloc_existence, s)) 73 73 out->s_value = BPF_CORE_READ(in, s.x); 74 74 else 75 75 out->s_value = 0xff000005u; 76 76 77 77 return 0; 78 78 } 79 -
+4 -4
tools/testing/selftests/bpf/progs/test_core_reloc_size.c
··· 44 44 out->struct_sz = bpf_core_field_size(in->struct_field); 45 45 out->union_sz = bpf_core_field_size(in->union_field); 46 46 out->arr_sz = bpf_core_field_size(in->arr_field); 47 - out->arr_elem_sz = bpf_core_field_size(in->arr_field[0]); 48 - out->ptr_sz = bpf_core_field_size(in->ptr_field); 49 - out->enum_sz = bpf_core_field_size(in->enum_field); 50 - out->float_sz = bpf_core_field_size(in->float_field); 47 + out->arr_elem_sz = bpf_core_field_size(struct core_reloc_size, arr_field[0]); 48 + out->ptr_sz = bpf_core_field_size(struct core_reloc_size, ptr_field); 49 + out->enum_sz = bpf_core_field_size(struct core_reloc_size, enum_field); 50 + out->float_sz = bpf_core_field_size(struct core_reloc_size, float_field); 51 51 52 52 return 0; 53 53 }