BPF List
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, Yonghong Song <yhs@fb.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	John Fastabend <john.fastabend@gmail.com>
Cc: bpf@vger.kernel.org, Heiko Carstens <heiko.carstens@de.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH v6 bpf-next 7/9] selftest/bpf: Add BTF_KIND_FLOAT tests
Date: Thu, 25 Feb 2021 00:51:17 +0100	[thread overview]
Message-ID: <6faacb23167b6b4612c7f9f7cd3b96fb4fdc1b72.camel@linux.ibm.com> (raw)
In-Reply-To: <20210224234535.106970-8-iii@linux.ibm.com>

On Thu, 2021-02-25 at 00:45 +0100, Ilya Leoshkevich wrote:
> Test the good variants as well as the potential malformed ones.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> Acked-by: Yonghong Song <yhs@fb.com>
> ---
>  tools/testing/selftests/bpf/btf_helpers.c    |   4 +
>  tools/testing/selftests/bpf/prog_tests/btf.c | 131 +++++++++++++++++++
>  tools/testing/selftests/bpf/test_btf.h       |   3 +
>  3 files changed, 138 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/btf_helpers.c
> b/tools/testing/selftests/bpf/btf_helpers.c
> index 48f90490f922..b692e6ead9b5 100644
> --- a/tools/testing/selftests/bpf/btf_helpers.c
> +++ b/tools/testing/selftests/bpf/btf_helpers.c
> @@ -23,6 +23,7 @@ static const char * const btf_kind_str_mapping[] = {
>         [BTF_KIND_FUNC_PROTO]   = "FUNC_PROTO",
>         [BTF_KIND_VAR]          = "VAR",
>         [BTF_KIND_DATASEC]      = "DATASEC",
> +       [BTF_KIND_FLOAT]        = "FLOAT",
>  };
>  
>  static const char *btf_kind_str(__u16 kind)
> @@ -173,6 +174,9 @@ int fprintf_btf_type_raw(FILE *out, const struct
> btf *btf, __u32 id)
>                 }
>                 break;
>         }
> +       case BTF_KIND_FLOAT:
> +               fprintf(out, " size=%u", t->size);
> +               break;
>         default:
>                 break;
>         }
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c
> b/tools/testing/selftests/bpf/prog_tests/btf.c
> index c29406736138..11d98d3cf949 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf.c
> @@ -3531,6 +3531,136 @@ static struct btf_raw_test raw_tests[] = {
>         .max_entries = 1,
>  },
>  
> +{
> +       .descr = "float test #1, well-formed",
> +       .raw_types = {
> +               BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
> +                                                               /* [1]
> */
> +               BTF_TYPE_FLOAT_ENC(NAME_TBD, 2),                /* [2]
> */
> +               BTF_TYPE_FLOAT_ENC(NAME_TBD, 4),                /* [3]
> */
> +               BTF_TYPE_FLOAT_ENC(NAME_TBD, 8),                /* [4]
> */
> +               BTF_TYPE_FLOAT_ENC(NAME_TBD, 12),               /* [5]
> */
> +               BTF_TYPE_FLOAT_ENC(NAME_TBD, 16),               /* [6]
> */
> +               BTF_STRUCT_ENC(NAME_TBD, 5, 48),                /* [7]
> */
> +               BTF_MEMBER_ENC(NAME_TBD, 2, 0),
> +               BTF_MEMBER_ENC(NAME_TBD, 3, 32),
> +               BTF_MEMBER_ENC(NAME_TBD, 4, 64),
> +               BTF_MEMBER_ENC(NAME_TBD, 5, 128),
> +               BTF_MEMBER_ENC(NAME_TBD, 6, 256),
> +               BTF_END_RAW,
> +       },
> +       BTF_STR_SEC("\0int\0_Float16\0float\0double\0_Float80\0long_dou
> ble"
> +                   "\0floats\0a\0b\0c\0d\0e"),
> +       .map_type = BPF_MAP_TYPE_ARRAY,
> +       .map_name = "float_type_check_btf",
> +       .key_size = sizeof(int),
> +       .value_size = 48,
> +       .key_type_id = 1,
> +       .value_type_id = 7,
> +       .max_entries = 1,
> +},
> +{
> +       .descr = "float test #2, invalid vlen",
> +       .raw_types = {
> +               BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
> +                                                               /* [1]
> */
> +               BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FLOAT, 0,
> 1), 4),
> +                                                               /* [2]
> */
> +               BTF_END_RAW,
> +       },
> +       BTF_STR_SEC("\0int\0float"),
> +       .map_type = BPF_MAP_TYPE_ARRAY,
> +       .map_name = "float_type_check_btf",
> +       .key_size = sizeof(int),
> +       .value_size = 4,
> +       .key_type_id = 1,
> +       .value_type_id = 2,
> +       .max_entries = 1,
> +       .btf_load_err = true,
> +       .err_str = "vlen != 0",
> +},
> +{
> +       .descr = "float test #3, invalid kind_flag",
> +       .raw_types = {
> +               BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
> +                                                               /* [1]
> */
> +               BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_FLOAT, 1,
> 0), 4),
> +                                                               /* [2]
> */
> +               BTF_END_RAW,
> +       },
> +       BTF_STR_SEC("\0int\0float"),
> +       .map_type = BPF_MAP_TYPE_ARRAY,
> +       .map_name = "float_type_check_btf",
> +       .key_size = sizeof(int),
> +       .value_size = 4,
> +       .key_type_id = 1,
> +       .value_type_id = 2,
> +       .max_entries = 1,
> +       .btf_load_err = true,
> +       .err_str = "Invalid btf_info kind_flag",
> +},
> +{
> +       .descr = "float test #4, member does not fit",
> +       .raw_types = {
> +               BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
> +                                                               /* [1]
> */
> +               BTF_TYPE_FLOAT_ENC(NAME_TBD, 4),                /* [2]
> */
> +               BTF_STRUCT_ENC(NAME_TBD, 1, 2),                 /* [3]
> */
> +               BTF_MEMBER_ENC(NAME_TBD, 2, 0),
> +               BTF_END_RAW,
> +       },
> +       BTF_STR_SEC("\0int\0float\0floats\0x"),
> +       .map_type = BPF_MAP_TYPE_ARRAY,
> +       .map_name = "float_type_check_btf",
> +       .key_size = sizeof(int),
> +       .value_size = 4,
> +       .key_type_id = 1,
> +       .value_type_id = 3,
> +       .max_entries = 1,
> +       .btf_load_err = true,
> +       .err_str = "Member exceeds struct_size",
> +},
> +{
> +       .descr = "float test #5, member is not properly aligned",
> +       .raw_types = {
> +               BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
> +                                                               /* [1]
> */
> +               BTF_TYPE_FLOAT_ENC(NAME_TBD, 4),                /* [2]
> */
> +               BTF_STRUCT_ENC(NAME_TBD, 1, 8),                 /* [3]
> */
> +               BTF_MEMBER_ENC(NAME_TBD, 2, 8),
> +               BTF_END_RAW,
> +       },
> +       BTF_STR_SEC("\0int\0float\0floats\0x"),
> +       .map_type = BPF_MAP_TYPE_ARRAY,
> +       .map_name = "float_type_check_btf",
> +       .key_size = sizeof(int),
> +       .value_size = 4,
> +       .key_type_id = 1,
> +       .value_type_id = 3,
> +       .max_entries = 1,
> +       .btf_load_err = true,
> +       .err_str = "Member is not properly aligned",
> +},
> +{
> +       .descr = "float test #6, invalid size",
> +       .raw_types = {
> +               BTF_TYPE_INT_ENC(NAME_TBD, BTF_INT_SIGNED, 0, 32, 4),
> +                                                               /* [1]
> */
> +               BTF_TYPE_FLOAT_ENC(NAME_TBD, 6),                /* [2]
> */
> +               BTF_END_RAW,
> +       },
> +       BTF_STR_SEC("\0int\0float"),
> +       .map_type = BPF_MAP_TYPE_ARRAY,
> +       .map_name = "float_type_check_btf",
> +       .key_size = sizeof(int),
> +       .value_size = 6,
> +       .key_type_id = 1,
> +       .value_type_id = 2,
> +       .max_entries = 1,
> +       .btf_load_err = true,
> +       .err_str = "Invalid type_size",
> +},
> +
>  }; /* struct btf_raw_test raw_tests[] */
>  
>  static const char *get_next_str(const char *start, const char *end)
> @@ -6630,6 +6760,7 @@ static int btf_type_size(const struct btf_type
> *t)
>         case BTF_KIND_PTR:
>         case BTF_KIND_TYPEDEF:
>         case BTF_KIND_FUNC:
> +       case BTF_KIND_FLOAT:
>                 return base_size;
>         case BTF_KIND_INT:
>                 return base_size + sizeof(__u32);
> diff --git a/tools/testing/selftests/bpf/test_btf.h
> b/tools/testing/selftests/bpf/test_btf.h
> index 2023725f1962..e2394eea4b7f 100644
> --- a/tools/testing/selftests/bpf/test_btf.h
> +++ b/tools/testing/selftests/bpf/test_btf.h
> @@ -66,4 +66,7 @@
>  #define BTF_FUNC_ENC(name, func_proto) \
>         BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 0),
> func_proto)
>  
> +#define BTF_TYPE_FLOAT_ENC(name, sz) \
> +       BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
> +
>  #endif /* _TEST_BTF_H */

Sorry, I forgot to add:

Acked-by: Andrii Nakryiko <andrii@kernel.org>

to the commit description here [1].

[1]
https://lore.kernel.org/bpf/CAEf4BzZXvokRMWqDrOg2JWFPr+caNjG=yeCM-W_9cDhkVraRPg@mail.gmail.com/



  reply	other threads:[~2021-02-24 23:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 23:45 [PATCH v6 bpf-next 0/9] Add BTF_KIND_FLOAT support Ilya Leoshkevich
2021-02-24 23:45 ` [PATCH v6 bpf-next 1/9] bpf: Add BTF_KIND_FLOAT to uapi Ilya Leoshkevich
2021-02-24 23:45 ` [PATCH v6 bpf-next 2/9] libbpf: Fix whitespace in btf_add_composite() comment Ilya Leoshkevich
2021-02-24 23:45 ` [PATCH v6 bpf-next 3/9] libbpf: Add BTF_KIND_FLOAT support Ilya Leoshkevich
2021-02-26  1:30   ` John Fastabend
2021-02-26  5:26     ` Yonghong Song
2021-02-26  1:57   ` John Fastabend
2021-02-24 23:45 ` [PATCH v6 bpf-next 4/9] tools/bpftool: " Ilya Leoshkevich
2021-02-25  6:29   ` Yonghong Song
2021-02-24 23:45 ` [PATCH v6 bpf-next 5/9] selftests/bpf: Use the 25th bit in the "invalid BTF_INFO" test Ilya Leoshkevich
2021-02-25  6:31   ` Yonghong Song
2021-02-24 23:45 ` [PATCH v6 bpf-next 6/9] bpf: Add BTF_KIND_FLOAT support Ilya Leoshkevich
2021-02-25  7:10   ` Yonghong Song
2021-02-25 10:40     ` Ilya Leoshkevich
2021-02-25 14:59       ` Yonghong Song
2021-02-26  1:53         ` John Fastabend
2021-02-26  5:43           ` Yonghong Song
2021-02-24 23:45 ` [PATCH v6 bpf-next 7/9] selftest/bpf: Add BTF_KIND_FLOAT tests Ilya Leoshkevich
2021-02-24 23:51   ` Ilya Leoshkevich [this message]
2021-02-26  2:01   ` John Fastabend
2021-02-24 23:45 ` [PATCH v6 bpf-next 8/9] selftests/bpf: Add BTF_KIND_FLOAT to the existing deduplication tests Ilya Leoshkevich
2021-02-24 23:45 ` [PATCH v6 bpf-next 9/9] bpf: Document BTF_KIND_FLOAT in btf.rst Ilya Leoshkevich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6faacb23167b6b4612c7f9f7cd3b96fb4fdc1b72.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=acme@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gor@linux.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=john.fastabend@gmail.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox