Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Andrii Nakryiko <andriin@fb.com>, <bpf@vger.kernel.org>,
	<netdev@vger.kernel.org>, <ast@fb.com>, <daniel@iogearbox.net>
Cc: <andrii.nakryiko@gmail.com>, <kernel-team@fb.com>
Subject: Re: [PATCH v2 bpf-next 3/5] selftests/bpf: add CO-RE relo test for TYPE_ID_LOCAL/TYPE_ID_TARGET
Date: Wed, 19 Aug 2020 09:43:10 -0700	[thread overview]
Message-ID: <077f60a0-c457-15a1-ba5e-b2ec37457fcf@fb.com> (raw)
In-Reply-To: <20200819052849.336700-4-andriin@fb.com>



On 8/18/20 10:28 PM, Andrii Nakryiko wrote:
> Add tests for BTF type ID relocations. To allow testing this, enhance
> core_relo.c test runner to allow dynamic initialization of test inputs.
> If __builtin_btf_type_id() is not supported by Clang, skip tests.
> 
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
>   .../selftests/bpf/prog_tests/core_reloc.c     | 168 +++++++++++++++++-
>   .../bpf/progs/btf__core_reloc_type_id.c       |   3 +
>   ...tf__core_reloc_type_id___missing_targets.c |   3 +
>   .../selftests/bpf/progs/core_reloc_types.h    |  40 +++++
>   .../bpf/progs/test_core_reloc_type_based.c    |  14 --
>   .../bpf/progs/test_core_reloc_type_id.c       | 107 +++++++++++
>   6 files changed, 316 insertions(+), 19 deletions(-)
>   create mode 100644 tools/testing/selftests/bpf/progs/btf__core_reloc_type_id.c
>   create mode 100644 tools/testing/selftests/bpf/progs/btf__core_reloc_type_id___missing_targets.c
>   create mode 100644 tools/testing/selftests/bpf/progs/test_core_reloc_type_id.c
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
> index b775ce0ede41..ad550510ef69 100644
> --- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c
> +++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c
> @@ -3,6 +3,9 @@
>   #include "progs/core_reloc_types.h"
>   #include <sys/mman.h>
>   #include <sys/syscall.h>
> +#include <bpf/btf.h>
> +
> +static int duration = 0;
>   
>   #define STRUCT_TO_CHAR_PTR(struct_name) (const char *)&(struct struct_name)
>   
[...]
> +
> +typedef struct a_struct named_struct_typedef;
> +
> +typedef int (*func_proto_typedef)(long);
> +
> +typedef char arr_typedef[20];
> +
> +struct core_reloc_type_id_output {
> +	int local_anon_struct;
> +	int local_anon_union;
> +	int local_anon_enum;
> +	int local_anon_func_proto_ptr;
> +	int local_anon_void_ptr;
> +	int local_anon_arr;
> +
> +	int local_struct;
> +	int local_union;
> +	int local_enum;
> +	int local_int;
> +	int local_struct_typedef;
> +	int local_func_proto_typedef;
> +	int local_arr_typedef;
> +
> +	int targ_struct;
> +	int targ_union;
> +	int targ_enum;
> +	int targ_int;
> +	int targ_struct_typedef;
> +	int targ_func_proto_typedef;
> +	int targ_arr_typedef;
> +};
> +
> +/* preserve types even if Clang doesn't support built-in */
> +struct a_struct t1 = {};
> +union a_union t2 = {};
> +enum an_enum t3 = 0;
> +named_struct_typedef t4 = {};
> +func_proto_typedef t5 = 0;
> +arr_typedef t6 = {};
> +
> +SEC("raw_tracepoint/sys_enter")
> +int test_core_type_id(void *ctx)
> +{
> +#if __has_builtin(__builtin_btf_type_id)

__builtin_btf_type_id is introduced in llvm11 but has issues for the 
following case:
    - struct t { ... } is defined
    - typedef struct t __t is defined
both "struct t" and "__t" are used in __builtin_btf_type_id in the same 
function. This is a corner case but it will make the test failure with 
llvm11.

I suggest to test builtin __builtin_preserve_type_info here with a 
comment to explain why. This will available test failure with llvm11.


> +	struct core_reloc_type_id_output *out = (void *)&data.out;
> +
> +	out->local_anon_struct = bpf_core_type_id_local(struct { int marker_field; });
> +	out->local_anon_union = bpf_core_type_id_local(union { int marker_field; });
> +	out->local_anon_enum = bpf_core_type_id_local(enum { MARKER_ENUM_VAL = 123 });
> +	out->local_anon_func_proto_ptr = bpf_core_type_id_local(_Bool(*)(int));
> +	out->local_anon_void_ptr = bpf_core_type_id_local(void *);
> +	out->local_anon_arr = bpf_core_type_id_local(_Bool[47]);
> +
> +	out->local_struct = bpf_core_type_id_local(struct a_struct);
> +	out->local_union = bpf_core_type_id_local(union a_union);
> +	out->local_enum = bpf_core_type_id_local(enum an_enum);
> +	out->local_int = bpf_core_type_id_local(int);
> +	out->local_struct_typedef = bpf_core_type_id_local(named_struct_typedef);
> +	out->local_func_proto_typedef = bpf_core_type_id_local(func_proto_typedef);
> +	out->local_arr_typedef = bpf_core_type_id_local(arr_typedef);
> +
> +	out->targ_struct = bpf_core_type_id_kernel(struct a_struct);
> +	out->targ_union = bpf_core_type_id_kernel(union a_union);
> +	out->targ_enum = bpf_core_type_id_kernel(enum an_enum);
> +	out->targ_int = bpf_core_type_id_kernel(int);
> +	out->targ_struct_typedef = bpf_core_type_id_kernel(named_struct_typedef);
> +	out->targ_func_proto_typedef = bpf_core_type_id_kernel(func_proto_typedef);
> +	out->targ_arr_typedef = bpf_core_type_id_kernel(arr_typedef);
> +#else
> +	data.skip = true;
> +#endif
> +
> +	return 0;
> +}
> +

empty line at the end of file?

  reply	other threads:[~2020-08-19 16:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-19  5:28 [PATCH v2 bpf-next 0/5] Add support for type-based and enum value-based CO-RE relocations Andrii Nakryiko
2020-08-19  5:28 ` [PATCH v2 bpf-next 1/5] libbpf: implement type-based CO-RE relocations support Andrii Nakryiko
2020-08-19  5:28 ` [PATCH v2 bpf-next 2/5] selftests/bpf: test TYPE_EXISTS and TYPE_SIZE CO-RE relocations Andrii Nakryiko
2020-08-19 16:30   ` Yonghong Song
2020-08-19 19:29     ` Andrii Nakryiko
2020-08-19  5:28 ` [PATCH v2 bpf-next 3/5] selftests/bpf: add CO-RE relo test for TYPE_ID_LOCAL/TYPE_ID_TARGET Andrii Nakryiko
2020-08-19 16:43   ` Yonghong Song [this message]
2020-08-19 19:30     ` Andrii Nakryiko
2020-08-19  5:28 ` [PATCH v2 bpf-next 4/5] libbpf: implement enum value-based CO-RE relocations Andrii Nakryiko
2020-08-19  5:28 ` [PATCH v2 bpf-next 5/5] selftests/bpf: add tests for ENUMVAL_EXISTS/ENUMVAL_VALUE relocations Andrii Nakryiko
2020-08-19 16:44   ` Yonghong Song
2020-08-19 16:24 ` [PATCH v2 bpf-next 0/5] Add support for type-based and enum value-based CO-RE relocations Yonghong Song

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=077f60a0-c457-15a1-ba5e-b2ec37457fcf@fb.com \
    --to=yhs@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --subject='Re: [PATCH v2 bpf-next 3/5] selftests/bpf: add CO-RE relo test for TYPE_ID_LOCAL/TYPE_ID_TARGET' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).