On 11/3/22 7:54 AM, KP Singh wrote:
On Thu, Nov 3, 2022 at 8:21 AM Yonghong Song <yhs@xxxxxx> wrote:
Add a few positive/negative tests to test bpf_rcu_read_lock()
and its corresponding verifier support.
./test_progs -t rcu_read_lock
...
#145/1 rcu_read_lock/local_storage:OK
#145/2 rcu_read_lock/runtime_diff_rcu_tag:OK
#145/3 rcu_read_lock/negative_tests:OK
#145 rcu_read_lock:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Yonghong Song <yhs@xxxxxx>
---
.../selftests/bpf/prog_tests/rcu_read_lock.c | 101 ++++++++
.../selftests/bpf/progs/rcu_read_lock.c | 241 ++++++++++++++++++
2 files changed, 342 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c
create mode 100644 tools/testing/selftests/bpf/progs/rcu_read_lock.c
diff --git a/tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c b/tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c
new file mode 100644
index 000000000000..46c02bdb1360
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates.*/
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
[...]
+
+ task = bpf_get_current_task_btf();
+
+ bpf_rcu_read_lock();
+ real_parent = task->real_parent;
+ bpf_rcu_read_unlock();
The tests are nice, It would be nice to add a comment on what actually is wrong.
e.g.
/* real_parent is accessed outside the RCU critical section */
Sure. Will add some comments.
+ (void)bpf_task_storage_get(&map_b, real_parent, 0,
+ BPF_LOCAL_STORAGE_GET_F_CREATE);
+ return 0;
+}
+
[...]
+ bpf_rcu_read_lock();
+ bkey = bpf_lookup_user_key(key_serial, flags);
+ bpf_rcu_read_unlock();
+ if (!bkey)
+ return -1;
+ bpf_key_put(bkey);
+
+ return 0;
nit: Spaces here instead of tabs.
+}
--
2.30.2