Message ID | 20230527223137.1580717-1-yhs@fb.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | [bpf-next,1/2] bpf: Silence a warning in btf_type_id_size() | expand |
On Sat, 2023-05-27 at 15:31 -0700, Yonghong Song wrote: > Add a selftest where map creation key type_id is a decl_tag > pointing to a struct. Without previous patch, a kernel warning will > appear similar to the one in the previous patch. With the previous > patch, the kernel warning is silenced. Looks good to me with a nitpick: commit message says "map creation key type_id is a decl_tag", but test case uses ".key_type_id = 1" which is INT and ".value_type_id = 3" which is DECL_TAG. syscall.c:map_check_btf.c applies the same check both for key and value, maybe make two tests? > > Signed-off-by: Yonghong Song <yhs@fb.com> > --- > tools/testing/selftests/bpf/prog_tests/btf.c | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c > index 210d643fda6c..69521e1dc330 100644 > --- a/tools/testing/selftests/bpf/prog_tests/btf.c > +++ b/tools/testing/selftests/bpf/prog_tests/btf.c > @@ -3990,6 +3990,26 @@ static struct btf_raw_test raw_tests[] = { > .btf_load_err = true, > .err_str = "Invalid arg#1", > }, > +{ > + .descr = "decl_tag test #18, struct member, decl_tag as the value type", > + .raw_types = { > + BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ > + BTF_STRUCT_ENC(0, 2, 8), /* [2] */ > + BTF_MEMBER_ENC(NAME_TBD, 1, 0), > + BTF_MEMBER_ENC(NAME_TBD, 1, 32), > + BTF_DECL_TAG_ENC(NAME_TBD, 2, -1), /* [3] */ > + BTF_END_RAW, > + }, > + BTF_STR_SEC("\0m1\0m2\0tag"), > + .map_type = BPF_MAP_TYPE_ARRAY, > + .map_name = "tag_type_check_btf", > + .key_size = sizeof(int), > + .value_size = 8, > + .key_type_id = 1, > + .value_type_id = 3, > + .max_entries = 1, > + .map_create_err = true, > +}, > { > .descr = "type_tag test #1", > .raw_types = {
On 5/29/23 8:17 AM, Eduard Zingerman wrote: > On Sat, 2023-05-27 at 15:31 -0700, Yonghong Song wrote: >> Add a selftest where map creation key type_id is a decl_tag >> pointing to a struct. Without previous patch, a kernel warning will >> appear similar to the one in the previous patch. With the previous >> patch, the kernel warning is silenced. > > Looks good to me with a nitpick: > commit message says "map creation key type_id is a decl_tag", > but test case uses ".key_type_id = 1" which is INT > and ".value_type_id = 3" which is DECL_TAG. > > syscall.c:map_check_btf.c applies the same check both for key and value, > maybe make two tests? Sounds good. Will fix the commit message and add one more test so both key and value are covered. > >> >> Signed-off-by: Yonghong Song <yhs@fb.com> >> --- >> tools/testing/selftests/bpf/prog_tests/btf.c | 20 ++++++++++++++++++++ >> 1 file changed, 20 insertions(+) >> >> diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c >> index 210d643fda6c..69521e1dc330 100644 >> --- a/tools/testing/selftests/bpf/prog_tests/btf.c >> +++ b/tools/testing/selftests/bpf/prog_tests/btf.c >> @@ -3990,6 +3990,26 @@ static struct btf_raw_test raw_tests[] = { >> .btf_load_err = true, >> .err_str = "Invalid arg#1", >> }, >> +{ >> + .descr = "decl_tag test #18, struct member, decl_tag as the value type", >> + .raw_types = { >> + BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ >> + BTF_STRUCT_ENC(0, 2, 8), /* [2] */ >> + BTF_MEMBER_ENC(NAME_TBD, 1, 0), >> + BTF_MEMBER_ENC(NAME_TBD, 1, 32), >> + BTF_DECL_TAG_ENC(NAME_TBD, 2, -1), /* [3] */ >> + BTF_END_RAW, >> + }, >> + BTF_STR_SEC("\0m1\0m2\0tag"), >> + .map_type = BPF_MAP_TYPE_ARRAY, >> + .map_name = "tag_type_check_btf", >> + .key_size = sizeof(int), >> + .value_size = 8, >> + .key_type_id = 1, >> + .value_type_id = 3, >> + .max_entries = 1, >> + .map_create_err = true, >> +}, >> { >> .descr = "type_tag test #1", >> .raw_types = { >
diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c index 210d643fda6c..69521e1dc330 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf.c +++ b/tools/testing/selftests/bpf/prog_tests/btf.c @@ -3990,6 +3990,26 @@ static struct btf_raw_test raw_tests[] = { .btf_load_err = true, .err_str = "Invalid arg#1", }, +{ + .descr = "decl_tag test #18, struct member, decl_tag as the value type", + .raw_types = { + BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ + BTF_STRUCT_ENC(0, 2, 8), /* [2] */ + BTF_MEMBER_ENC(NAME_TBD, 1, 0), + BTF_MEMBER_ENC(NAME_TBD, 1, 32), + BTF_DECL_TAG_ENC(NAME_TBD, 2, -1), /* [3] */ + BTF_END_RAW, + }, + BTF_STR_SEC("\0m1\0m2\0tag"), + .map_type = BPF_MAP_TYPE_ARRAY, + .map_name = "tag_type_check_btf", + .key_size = sizeof(int), + .value_size = 8, + .key_type_id = 1, + .value_type_id = 3, + .max_entries = 1, + .map_create_err = true, +}, { .descr = "type_tag test #1", .raw_types = {
Add a selftest where map creation key type_id is a decl_tag pointing to a struct. Without previous patch, a kernel warning will appear similar to the one in the previous patch. With the previous patch, the kernel warning is silenced. Signed-off-by: Yonghong Song <yhs@fb.com> --- tools/testing/selftests/bpf/prog_tests/btf.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)