BPF List
 help / color / mirror / Atom feed
From: Hengqi Chen <hengqi.chen@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
	toke@redhat.com, hengqi.chen@gmail.com
Subject: [PATCH bpf 2/2] selftests/bpf: Update map_in_map using map without BTF key/value info
Date: Sat, 26 Nov 2022 18:53:51 +0800	[thread overview]
Message-ID: <20221126105351.2578782-3-hengqi.chen@gmail.com> (raw)
In-Reply-To: <20221126105351.2578782-1-hengqi.chen@gmail.com>

Add a selftest to ensure that inner map without BTF key/value info
can coexist with inner map with BTF key/value info in the same map_in_map.

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 .../selftests/bpf/prog_tests/btf_map_in_map.c | 27 +++++++++++++++++++
 .../selftests/bpf/progs/test_btf_map_in_map.c | 22 +++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c b/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
index eb90a6b8850d..d34d91d6d9ca 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_map_in_map.c
@@ -154,6 +154,30 @@ static void test_diff_size(void)
 	test_btf_map_in_map__destroy(skel);
 }

+static void test_btf_key_value(void)
+{
+	struct test_btf_map_in_map *skel;
+	int err, map_fd1, map_fd2, zero = 0;
+
+	skel = test_btf_map_in_map__open_and_load();
+	if (CHECK(!skel, "skel_open", "failed to open&load skeleton\n"))
+		return;
+
+	map_fd1 = bpf_map__fd(skel->maps.inner);
+	err = bpf_map_update_elem(bpf_map__fd(skel->maps.outer), &zero, &map_fd1, 0);
+	CHECK(err, "update map_in_map using map with BTF key/value info",
+	      "cannot use inner map with BTF key/value info\n");
+
+	map_fd2 = bpf_map_create(BPF_MAP_TYPE_LRU_HASH, NULL, 4, 4, 1, NULL);
+	CHECK(map_fd2 < 0, "create map without BTF key/value info", "cannot create map\n");
+	err = bpf_map_update_elem(bpf_map__fd(skel->maps.outer), &zero, &map_fd2, 0);
+	CHECK(err, "update map_in_map using map without BTF key/value info",
+	      "cannot use inner map without BTF key/value info\n");
+
+	close(map_fd2);
+	test_btf_map_in_map__destroy(skel);
+}
+
 void test_btf_map_in_map(void)
 {
 	if (test__start_subtest("lookup_update"))
@@ -161,4 +185,7 @@ void test_btf_map_in_map(void)

 	if (test__start_subtest("diff_size"))
 		test_diff_size();
+
+	if (test__start_subtest("btf_key_value"))
+		test_btf_key_value();
 }
diff --git a/tools/testing/selftests/bpf/progs/test_btf_map_in_map.c b/tools/testing/selftests/bpf/progs/test_btf_map_in_map.c
index c218cf8989a9..8f7ca70496f2 100644
--- a/tools/testing/selftests/bpf/progs/test_btf_map_in_map.c
+++ b/tools/testing/selftests/bpf/progs/test_btf_map_in_map.c
@@ -118,6 +118,28 @@ struct outer_sockarr_sz1 {
 	.values = { (void *)&sockarr_sz1 },
 };

+struct inner_key {
+	__u32 x;
+};
+
+struct inner_value {
+	__u32 y;
+};
+
+struct inner {
+	__uint(type, BPF_MAP_TYPE_LRU_HASH);
+	__uint(max_entries, 1);
+	__type(key, struct inner_key);
+	__type(value, struct inner_value);
+} inner SEC(".maps");
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
+	__uint(max_entries, 1);
+	__type(key, __u32);
+	__array(values, struct inner);
+} outer SEC(".maps");
+
 int input = 0;

 SEC("raw_tp/sys_enter")
--
2.34.1

      parent reply	other threads:[~2022-11-26 10:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-26 10:53 [PATCH bpf 0/2] Check timer_off for map_in_map only when map value has timer Hengqi Chen
2022-11-26 10:53 ` [PATCH bpf 1/2] bpf: Check timer_off for map_in_map only when map value have timer Hengqi Chen
2022-11-27  3:21   ` Yonghong Song
2022-11-28  2:16     ` Hengqi Chen
2022-11-28  0:44   ` Alexei Starovoitov
2022-11-28  2:42     ` Hengqi Chen
2022-11-28  2:49       ` Alexei Starovoitov
2022-11-28  3:07         ` Hengqi Chen
2022-11-28  3:14           ` Alexei Starovoitov
2022-11-28  4:11             ` Hengqi Chen
2022-11-29  6:12       ` Andrii Nakryiko
2022-11-26 10:53 ` Hengqi Chen [this message]

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=20221126105351.2578782-3-hengqi.chen@gmail.com \
    --to=hengqi.chen@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=martin.lau@linux.dev \
    --cc=song@kernel.org \
    --cc=toke@redhat.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