From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: [PATCH bpf-next 4/5] selftests/bpf: add BTF_KIND_DECL_TAG typedef example in tag.c
Date: Thu, 21 Oct 2021 12:56:43 -0700 [thread overview]
Message-ID: <20211021195643.4020315-1-yhs@fb.com> (raw)
In-Reply-To: <20211021195622.4018339-1-yhs@fb.com>
Change value type in progs/tag.c to a typedef with a btf_decl_tag.
With `bpftool btf dump file tag.o`, we have
...
[14] TYPEDEF 'value_t' type_id=17
[15] DECL_TAG 'tag1' type_id=14 component_idx=-1
[16] DECL_TAG 'tag2' type_id=14 component_idx=-1
[17] STRUCT '(anon)' size=8 vlen=2
'a' type_id=2 bits_offset=0
'b' type_id=2 bits_offset=32
...
The btf_tag selftest also succeeded:
$ ./test_progs -t tag
#21 btf_tag:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Yonghong Song <yhs@fb.com>
---
tools/testing/selftests/bpf/progs/tag.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/tag.c b/tools/testing/selftests/bpf/progs/tag.c
index 672d19e7b120..1792f4eda095 100644
--- a/tools/testing/selftests/bpf/progs/tag.c
+++ b/tools/testing/selftests/bpf/progs/tag.c
@@ -24,18 +24,23 @@ struct key_t {
int c;
} __tag1 __tag2;
+typedef struct {
+ int a;
+ int b;
+} value_t __tag1 __tag2;
+
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 3);
__type(key, struct key_t);
- __type(value, __u64);
+ __type(value, value_t);
} hashmap1 SEC(".maps");
static __noinline int foo(int x __tag1 __tag2) __tag1 __tag2
{
struct key_t key;
- __u64 val = 1;
+ value_t val = {};
key.a = key.b = key.c = x;
bpf_map_update_elem(&hashmap1, &key, &val, 0);
--
2.30.2
next prev parent reply other threads:[~2021-10-21 19:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 19:56 [PATCH bpf-next 0/5] bpf: add support for BTF_KIND_DECL_TAG typedef Yonghong Song
2021-10-21 19:56 ` [PATCH bpf-next 1/5] bpf: add BTF_KIND_DECL_TAG typedef support Yonghong Song
2021-10-21 19:56 ` [PATCH bpf-next 2/5] selftests/bpf: add BTF_KIND_DECL_TAG typedef unit tests Yonghong Song
2021-10-21 19:56 ` [PATCH bpf-next 3/5] selftests/bpf: test deduplication for BTF_KIND_DECL_TAG typedef Yonghong Song
2021-10-21 19:56 ` Yonghong Song [this message]
2021-10-21 19:56 ` [PATCH bpf-next 5/5] docs/bpf: update documentation for BTF_KIND_DECL_TAG typedef support Yonghong Song
2021-10-23 0:05 ` [PATCH bpf-next 0/5] bpf: add support for BTF_KIND_DECL_TAG typedef Alexei Starovoitov
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=20211021195643.4020315-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@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