From: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
To: bpf@vger.kernel.org
Cc: alexei.starovoitov@gmail.com, daniel@iogearbox.net,
olsajiri@gmail.com, andrii@kernel.org, yonghong.song@linux.dev,
rjsu26@vt.edu, sairoop@vt.edu, miloc@vt.edu, memxor@gmail.com,
Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Subject: [PATCH v3 bpf-next 2/2] selftests/bpf: Added selftests to check deadlocks in queue and stack map
Date: Tue, 14 May 2024 08:40:51 -0400 [thread overview]
Message-ID: <20240514124052.1240266-1-sidchintamaneni@gmail.com> (raw)
Added selftests to check for nested deadlocks in queue and stack maps.
test_map_queue_stack_nesting_success:PASS:test_queue_stack_nested_map__open 0 nsec
test_map_queue_stack_nesting_success:PASS:test_queue_stack_nested_map__load 0 nsec
test_map_queue_stack_nesting_success:PASS:test_queue_stack_nested_map__attach 0 nsec
test_map_queue_stack_nesting_success:PASS:MAP Write 0 nsec
test_map_queue_stack_nesting_success:PASS:no map nesting 0 nsec
test_map_queue_stack_nesting_success:PASS:no map nesting 0 nsec
384/1 test_queue_stack_nested_map/map_queue_nesting:OK
test_map_queue_stack_nesting_success:PASS:test_queue_stack_nested_map__open 0 nsec
test_map_queue_stack_nesting_success:PASS:test_queue_stack_nested_map__load 0 nsec
test_map_queue_stack_nesting_success:PASS:test_queue_stack_nested_map__attach 0 nsec
test_map_queue_stack_nesting_success:PASS:MAP Write 0 nsec
test_map_queue_stack_nesting_success:PASS:no map nesting 0 nsec
384/2 test_queue_stack_nested_map/map_stack_nesting:OK
384 test_queue_stack_nested_map:OK
Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
.../prog_tests/test_queue_stack_nested_map.c | 69 +++++++++++
.../bpf/progs/test_queue_stack_nested_map.c | 116 ++++++++++++++++++
2 files changed, 185 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/test_queue_stack_nested_map.c
create mode 100644 tools/testing/selftests/bpf/progs/test_queue_stack_nested_map.c
diff --git a/tools/testing/selftests/bpf/prog_tests/test_queue_stack_nested_map.c b/tools/testing/selftests/bpf/prog_tests/test_queue_stack_nested_map.c
new file mode 100644
index 000000000000..fc46561788af
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/test_queue_stack_nested_map.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include <network_helpers.h>
+
+#include "test_queue_stack_nested_map.skel.h"
+
+
+static void test_map_queue_stack_nesting_success(bool is_map_queue)
+{
+ struct test_queue_stack_nested_map *skel;
+ int err;
+
+ skel = test_queue_stack_nested_map__open();
+ if (!ASSERT_OK_PTR(skel, "test_queue_stack_nested_map__open"))
+ return;
+
+ err = test_queue_stack_nested_map__load(skel);
+ if (!ASSERT_OK(err, "test_queue_stack_nested_map__load"))
+ goto out;
+
+ skel->bss->pid = getpid();
+ err = test_queue_stack_nested_map__attach(skel);
+ if (!ASSERT_OK(err, "test_queue_stack_nested_map__attach"))
+ goto out;
+
+ /* trigger map from userspace to check nesting */
+ int value = 0;
+
+ do {
+ if (is_map_queue) {
+ err = bpf_map_update_elem(bpf_map__fd(skel->maps.map_queue),
+ NULL, &value, 0);
+ if (err < 0)
+ break;
+ err = bpf_map_lookup_and_delete_elem(bpf_map__fd(skel->maps.map_queue),
+ NULL, &value);
+ } else {
+ err = bpf_map_update_elem(bpf_map__fd(skel->maps.map_stack),
+ NULL, &value, 0);
+ if (err < 0)
+ break;
+ err = bpf_map_lookup_and_delete_elem(bpf_map__fd(skel->maps.map_stack),
+ NULL, &value);
+ }
+ } while (0);
+
+
+ if (!ASSERT_OK(err, "MAP Write"))
+ goto out;
+
+ if (is_map_queue) {
+ ASSERT_EQ(skel->bss->err_queue_push, -EBUSY, "no map nesting");
+ ASSERT_EQ(skel->bss->err_queue_pop, -EBUSY, "no map nesting");
+ } else {
+ ASSERT_EQ(skel->bss->err_stack, -EBUSY, "no map nesting");
+ }
+out:
+ test_queue_stack_nested_map__destroy(skel);
+}
+
+void test_test_queue_stack_nested_map(void)
+{
+ if (test__start_subtest("map_queue_nesting"))
+ test_map_queue_stack_nesting_success(true);
+ if (test__start_subtest("map_stack_nesting"))
+ test_map_queue_stack_nesting_success(false);
+
+}
+
diff --git a/tools/testing/selftests/bpf/progs/test_queue_stack_nested_map.c b/tools/testing/selftests/bpf/progs/test_queue_stack_nested_map.c
new file mode 100644
index 000000000000..893a37593206
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_queue_stack_nested_map.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+struct {
+ __uint(type, BPF_MAP_TYPE_STACK);
+ __uint(max_entries, 32);
+ __uint(key_size, 0);
+ __uint(value_size, sizeof(__u32));
+} map_stack SEC(".maps");
+
+struct {
+ __uint(type, BPF_MAP_TYPE_QUEUE);
+ __uint(max_entries, 32);
+ __uint(key_size, 0);
+ __uint(value_size, sizeof(__u32));
+} map_queue SEC(".maps");
+
+
+int err_queue_push;
+int err_queue_pop;
+int err_stack;
+int pid;
+__u32 trigger_flag_queue_push;
+__u32 trigger_flag_queue_pop;
+__u32 trigger_flag_stack;
+
+SEC("fentry/queue_stack_map_push_elem")
+int BPF_PROG(test_queue_stack_push_trigger, raw_spinlock_t *lock, unsigned long flags)
+{
+
+ if ((bpf_get_current_pid_tgid() >> 32) != pid)
+ return 0;
+
+
+ trigger_flag_queue_push = 1;
+
+ return 0;
+}
+
+SEC("fentry/queue_map_pop_elem")
+int BPF_PROG(test_queue_pop_trigger, raw_spinlock_t *lock, unsigned long flags)
+{
+
+ if ((bpf_get_current_pid_tgid() >> 32) != pid)
+ return 0;
+
+ trigger_flag_queue_pop = 1;
+
+ return 0;
+}
+
+
+SEC("fentry/stack_map_pop_elem")
+int BPF_PROG(test_stack_pop_trigger, raw_spinlock_t *lock, unsigned long flags)
+{
+
+ if ((bpf_get_current_pid_tgid() >> 32) != pid)
+ return 0;
+
+ trigger_flag_stack = 1;
+
+ return 0;
+}
+
+SEC("fentry/_raw_spin_unlock_irqrestore")
+int BPF_PROG(test_queue_pop_nesting, raw_spinlock_t *lock, unsigned long flags)
+{
+ __u32 val;
+
+ if ((bpf_get_current_pid_tgid() >> 32) != pid || trigger_flag_queue_pop != 1)
+ return 0;
+
+
+ err_queue_pop = bpf_map_pop_elem(&map_queue, &val);
+
+ trigger_flag_queue_pop = 0;
+
+ return 0;
+}
+
+SEC("fentry/_raw_spin_unlock_irqrestore")
+int BPF_PROG(test_stack_nesting, raw_spinlock_t *lock, unsigned long flags)
+{
+ __u32 val;
+
+ if ((bpf_get_current_pid_tgid() >> 32) != pid || trigger_flag_stack != 1)
+ return 0;
+
+
+ err_stack = bpf_map_pop_elem(&map_stack, &val);
+
+ trigger_flag_stack = 0;
+
+ return 0;
+}
+
+
+SEC("fentry/_raw_spin_unlock_irqrestore")
+int BPF_PROG(test_queue_push_nesting, raw_spinlock_t *lock, unsigned long flags)
+{
+ __u32 val = 1;
+
+ if ((bpf_get_current_pid_tgid() >> 32) != pid || trigger_flag_queue_push != 1) {
+ return 0;
+ }
+
+ err_queue_push = bpf_map_push_elem(&map_queue, &val, 0);
+
+ trigger_flag_queue_push = 0;
+
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";
--
2.44.0
next reply other threads:[~2024-05-14 12:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-14 12:40 Siddharth Chintamaneni [this message]
2024-05-14 12:40 ` [PATCH v3 bpf-next 1/2] bpf: Patch to Fix deadlocks in queue and stack maps Siddharth Chintamaneni
2024-05-15 17:32 ` Kumar Kartikeya Dwivedi
2024-05-16 14:04 ` Barret Rhoden
2024-05-16 14:34 ` Kumar Kartikeya Dwivedi
2024-05-16 15:31 ` Siddharth Chintamaneni
2024-05-17 1:53 ` Hou Tao
2024-05-17 3:32 ` Siddharth Chintamaneni
2024-05-15 17:02 ` [PATCH v3 bpf-next 2/2] selftests/bpf: Added selftests to check deadlocks in queue and stack map Kumar Kartikeya Dwivedi
2024-05-15 17:44 ` Siddharth Chintamaneni
2024-05-15 17:56 ` Kumar Kartikeya Dwivedi
2024-05-15 17:58 ` Kumar Kartikeya Dwivedi
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=20240514124052.1240266-1-sidchintamaneni@gmail.com \
--to=sidchintamaneni@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=memxor@gmail.com \
--cc=miloc@vt.edu \
--cc=olsajiri@gmail.com \
--cc=rjsu26@vt.edu \
--cc=sairoop@vt.edu \
--cc=yonghong.song@linux.dev \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).