selftests/bpf: Add test for new bpf_cpumask_first_and() kfunc
authorDavid Vernet <void@manifault.com>
Sat, 10 Jun 2023 03:50:50 +0000 (22:50 -0500)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 12 Jun 2023 22:09:11 +0000 (15:09 -0700)
A prior patch added a new kfunc called bpf_cpumask_first_and() which
wraps cpumask_first_and(). This patch adds a selftest to validate its
behavior.

Signed-off-by: David Vernet <void@manifault.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20230610035053.117605-2-void@manifault.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/cpumask.c
tools/testing/selftests/bpf/progs/cpumask_common.h
tools/testing/selftests/bpf/progs/cpumask_success.c

index d891914..756ea8b 100644 (file)
@@ -10,6 +10,7 @@ static const char * const cpumask_success_testcases[] = {
        "test_set_clear_cpu",
        "test_setall_clear_cpu",
        "test_first_firstzero_cpu",
+       "test_firstand_nocpu",
        "test_test_and_set_clear",
        "test_and_or_xor",
        "test_intersects_subset",
index 0c5b785..b3493d5 100644 (file)
@@ -28,6 +28,8 @@ void bpf_cpumask_release(struct bpf_cpumask *cpumask) __ksym;
 struct bpf_cpumask *bpf_cpumask_acquire(struct bpf_cpumask *cpumask) __ksym;
 u32 bpf_cpumask_first(const struct cpumask *cpumask) __ksym;
 u32 bpf_cpumask_first_zero(const struct cpumask *cpumask) __ksym;
+u32 bpf_cpumask_first_and(const struct cpumask *src1,
+                         const struct cpumask *src2) __ksym;
 void bpf_cpumask_set_cpu(u32 cpu, struct bpf_cpumask *cpumask) __ksym;
 void bpf_cpumask_clear_cpu(u32 cpu, struct bpf_cpumask *cpumask) __ksym;
 bool bpf_cpumask_test_cpu(u32 cpu, const struct cpumask *cpumask) __ksym;
index 602a88b..fbaf510 100644 (file)
@@ -176,6 +176,38 @@ release_exit:
 }
 
 SEC("tp_btf/task_newtask")
+int BPF_PROG(test_firstand_nocpu, struct task_struct *task, u64 clone_flags)
+{
+       struct bpf_cpumask *mask1, *mask2;
+       u32 first;
+
+       if (!is_test_task())
+               return 0;
+
+       mask1 = create_cpumask();
+       if (!mask1)
+               return 0;
+
+       mask2 = create_cpumask();
+       if (!mask2)
+               goto release_exit;
+
+       bpf_cpumask_set_cpu(0, mask1);
+       bpf_cpumask_set_cpu(1, mask2);
+
+       first = bpf_cpumask_first_and(cast(mask1), cast(mask2));
+       if (first <= 1)
+               err = 3;
+
+release_exit:
+       if (mask1)
+               bpf_cpumask_release(mask1);
+       if (mask2)
+               bpf_cpumask_release(mask2);
+       return 0;
+}
+
+SEC("tp_btf/task_newtask")
 int BPF_PROG(test_test_and_set_clear, struct task_struct *task, u64 clone_flags)
 {
        struct bpf_cpumask *cpumask;