| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/07/07 02:01 | flow | patch-triage |
0mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch only adds and modifies BPF selftests for libarena under tools/testing/selftests/bpf/. It does not make any functional changes to the core kernel, drivers, or architecture code.",
"WorthFuzzing": false
} |
| 1/1 | 2026/07/07 02:01 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 8c4c144292ce5ce8c09630603f37d878af527fd8\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Jul 7 02:01:28 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/tools/testing/selftests/bpf/libarena/include/libarena/bitmap.h b/tools/testing/selftests/bpf/libarena/include/libarena/bitmap.h\nnew file mode 100644\nindex 00000000000000..cf6b63f5d9a45f\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/libarena/include/libarena/bitmap.h\n@@ -0,0 +1,34 @@\n+#pragma once\n+\n+#define BITS_PER_BYTE\t\t8\n+#define BYTES_TO_BITS(nb)\t((nb) * BITS_PER_BYTE)\n+\n+#define BITS_PER_LONG_LONG\t(sizeof(long long) * BITS_PER_BYTE)\n+#define BITS_TO_LONG_LONGS(nr)\t(((nr) + BITS_PER_LONG_LONG - 1) / BITS_PER_LONG_LONG)\n+#define BIT_MASK(nr)\t\t(1ULL \u003c\u003c ((nr) % BITS_PER_LONG_LONG))\n+#define BIT_WORD(nr)\t\t((nr) / BITS_PER_LONG_LONG)\n+\n+struct bitmap {\n+\tu64 bits[0];\n+};\n+\n+struct bitmap __arena *bmp_alloc(size_t bits);\n+void bmp_free(struct bitmap __arena *bmp);\n+\n+void __bmp_set_bit(u32 bit, struct bitmap __arena *bmp);\n+void __bmp_clear_bit(u32 bit, struct bitmap __arena *bmp);\n+void bmp_set_bit(u32 bit, struct bitmap __arena *bmp);\n+void bmp_clear_bit(u32 bit, struct bitmap __arena *bmp);\n+bool bmp_test_bit(u32 bit, struct bitmap __arena *bmp);\n+bool bmp_test_and_clear_bit(u32 bit, struct bitmap __arena *bmp);\n+bool bmp_test_and_set_bit(u32 bit, struct bitmap __arena *bmp);\n+\n+void bmp_clear(size_t bits, struct bitmap __arena *bmp);\n+void bmp_and(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src1, struct bitmap __arena *src2);\n+void bmp_or(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src1, struct bitmap __arena *src2);\n+bool bmp_empty(size_t bits, struct bitmap __arena *bmp);\n+void bmp_copy(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src);\n+\n+bool bmp_intersects(size_t bits, struct bitmap __arena *arg1, struct bitmap __arena *arg2);\n+bool bmp_subset(size_t bits, struct bitmap __arena *big, struct bitmap __arena *small);\n+void bmp_print(size_t bits, struct bitmap __arena *bmp);\ndiff --git a/tools/testing/selftests/bpf/libarena/include/libarena/common.h b/tools/testing/selftests/bpf/libarena/include/libarena/common.h\nindex a3eb1641ac36df..931ace9a49e2bd 100644\n--- a/tools/testing/selftests/bpf/libarena/include/libarena/common.h\n+++ b/tools/testing/selftests/bpf/libarena/include/libarena/common.h\n@@ -43,7 +43,7 @@ struct {\n * imprecise. To force the variable to be imprecise, initialize it with\n * the opaque volatile variable 0 instead of the constant 0.\n */\n-extern const volatile u32 zero;\n+volatile u32 zero __weak;\n extern volatile u64 asan_violated;\n \n int arena_fls(__u64 word);\ndiff --git a/tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c\nsimilarity index 98%\nrename from tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c\nrename to tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c\nindex 686caba2c643b5..3266a28f53d768 100644\n--- a/tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c\n+++ b/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c\n@@ -12,7 +12,7 @@ extern struct buddy __arena buddy;\n \n #ifdef BPF_ARENA_ASAN\n \n-#include \"st_asan_common.h\"\n+#include \"test_asan_common.h\"\n \n static __always_inline int asan_test_buddy_oob_single(size_t alloc_size)\n {\n@@ -154,7 +154,8 @@ __weak int asan_test_buddy_oob(void)\n \tsize_t sizes[] = {\n \t\t7, 8, 17, 18, 64, 256, 317, 512, 1024,\n \t};\n-\tint ret, i;\n+\tint ret;\n+\tu32 i;\n \n \tret = buddy_init(\u0026buddy);\n \tif (ret) {\n@@ -163,6 +164,7 @@ __weak int asan_test_buddy_oob(void)\n \t}\n \n \tfor (i = zero; i \u003c sizeof(sizes) / sizeof(sizes[0]) \u0026\u0026 can_loop; i++) {\n+\t\tbarrier_var(i);\n \t\tret = asan_test_buddy_oob_single(sizes[i]);\n \t\tif (ret) {\n \t\t\tarena_stdout(\"%s:%d Failed for size %lu\", __func__,\n@@ -190,7 +192,8 @@ __stderr(\"Call trace:\\n\"\n __weak int asan_test_buddy_uaf(void)\n {\n \tsize_t sizes[] = { 16, 32, 64, 128, 256, 512, 1024, 16384 };\n-\tint ret, i;\n+\tint ret;\n+\tu32 i;\n \n \tret = buddy_init(\u0026buddy);\n \tif (ret) {\n@@ -199,6 +202,7 @@ __weak int asan_test_buddy_uaf(void)\n \t}\n \n \tfor (i = zero; i \u003c sizeof(sizes) / sizeof(sizes[0]) \u0026\u0026 can_loop; i++) {\n+\t\tbarrier_var(i);\n \t\tret = asan_test_buddy_uaf_single(sizes[i]);\n \t\tif (ret) {\n \t\t\tarena_stdout(\"%s:%d Failed for size %lu\", __func__,\ndiff --git a/tools/testing/selftests/bpf/libarena/selftests/st_asan_common.h b/tools/testing/selftests/bpf/libarena/selftests/test_asan_common.h\nsimilarity index 100%\nrename from tools/testing/selftests/bpf/libarena/selftests/st_asan_common.h\nrename to tools/testing/selftests/bpf/libarena/selftests/test_asan_common.h\ndiff --git a/tools/testing/selftests/bpf/libarena/selftests/test_bitmap.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_bitmap.bpf.c\nnew file mode 100644\nindex 00000000000000..e7d32f44d68709\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/libarena/selftests/test_bitmap.bpf.c\n@@ -0,0 +1,394 @@\n+#include \u003clibarena/common.h\u003e\n+\n+#include \u003clibarena/asan.h\u003e\n+#include \u003clibarena/bitmap.h\u003e\n+\n+#define TEST_BITS\t(2 * BITS_PER_LONG_LONG)\n+#define TEST_WORDS\tBITS_TO_LONG_LONGS(TEST_BITS)\n+#define MID_BIT\t\t(BITS_PER_LONG_LONG + 1)\n+#define LAST_BIT\t(TEST_BITS - 1)\n+\n+static void test_bmp_setall(struct bitmap __arena *bmp)\n+{\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c TEST_WORDS \u0026\u0026 can_loop; i++)\n+\t\tbmp-\u003ebits[i] = ~0ULL;\n+}\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_alloc_free(void)\n+{\n+\tstruct bitmap __arena *bmp;\n+\n+\tbmp = bmp_alloc(TEST_BITS);\n+\tif (!bmp)\n+\t\treturn -ENOMEM;\n+\n+\tif (!bmp_empty(TEST_BITS, bmp))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(LAST_BIT, bmp);\n+\tif (!bmp_test_bit(LAST_BIT, bmp))\n+\t\tgoto err;\n+\n+\t__bmp_clear_bit(LAST_BIT, bmp);\n+\tif (bmp_test_bit(LAST_BIT, bmp))\n+\t\tgoto err;\n+\n+\tbmp_free(bmp);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(bmp);\n+\treturn -EINVAL;\n+}\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_bit_ops(void)\n+{\n+\tstruct bitmap __arena *bmp;\n+\n+\tbmp = bmp_alloc(TEST_BITS);\n+\tif (!bmp)\n+\t\treturn -ENOMEM;\n+\n+\t__bmp_set_bit(0, bmp);\n+\tif (!bmp_test_bit(0, bmp))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(MID_BIT, bmp);\n+\tif (!bmp_test_bit(MID_BIT, bmp))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(LAST_BIT, bmp);\n+\tif (!bmp_test_bit(LAST_BIT, bmp))\n+\t\tgoto err;\n+\n+\tif (bmp_test_bit(MID_BIT - 1, bmp))\n+\t\tgoto err;\n+\n+\t__bmp_clear_bit(MID_BIT, bmp);\n+\tif (bmp_test_bit(MID_BIT, bmp))\n+\t\tgoto err;\n+\n+\tif (!bmp_test_bit(0, bmp))\n+\t\tgoto err;\n+\n+\tif (!bmp_test_bit(LAST_BIT, bmp))\n+\t\tgoto err;\n+\n+\t__bmp_clear_bit(0, bmp);\n+\t__bmp_clear_bit(LAST_BIT, bmp);\n+\tif (!bmp_empty(TEST_BITS, bmp))\n+\t\tgoto err;\n+\n+\tif (bmp-\u003ebits[0])\n+\t\tgoto err;\n+\n+\tif (bmp-\u003ebits[1])\n+\t\tgoto err;\n+\n+\tbmp_free(bmp);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(bmp);\n+\treturn -EINVAL;\n+}\n+\n+static bool test_bitmap_test_and_clear_single(struct bitmap __arena *bmp, size_t ind)\n+{\n+\tif (bmp_test_and_clear_bit(ind, bmp))\n+\t\treturn false;\n+\n+\t__bmp_set_bit(ind, bmp);\n+\n+\tif (!bmp_test_and_clear_bit(ind, bmp))\n+\t\treturn false;\n+\n+\tif (bmp_test_bit(ind, bmp))\n+\t\treturn false;\n+\n+\tif (bmp_test_and_clear_bit(ind, bmp))\n+\t\treturn false;\n+\n+\treturn true;\n+}\n+\n+static bool test_bitmap_test_and_set_single(struct bitmap __arena *bmp, size_t ind)\n+{\n+\tif (bmp_test_and_set_bit(ind, bmp))\n+\t\treturn false;\n+\n+\tif (!bmp_test_and_set_bit(ind, bmp))\n+\t\treturn false;\n+\n+\tif (!bmp_test_bit(ind, bmp))\n+\t\treturn false;\n+\n+\t__bmp_clear_bit(ind, bmp);\n+\n+\tif (bmp_test_and_set_bit(ind, bmp))\n+\t\treturn false;\n+\n+\treturn true;\n+}\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_test_and_clear_bit(void)\n+{\n+\tstruct bitmap __arena *bmp;\n+\n+\tbmp = bmp_alloc(TEST_BITS);\n+\tif (!bmp)\n+\t\treturn -ENOMEM;\n+\n+\tif (!test_bitmap_test_and_clear_single(bmp, 0))\n+\t\tgoto err;\n+\n+\tif (!test_bitmap_test_and_clear_single(bmp, MID_BIT))\n+\t\tgoto err;\n+\n+\tif (!test_bitmap_test_and_clear_single(bmp, LAST_BIT))\n+\t\tgoto err;\n+\n+\tif (!bmp_empty(TEST_BITS, bmp))\n+\t\tgoto err;\n+\n+\tbmp_free(bmp);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(bmp);\n+\treturn -EINVAL;\n+}\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_test_and_set_bit(void)\n+{\n+\tstruct bitmap __arena *bmp;\n+\n+\tbmp = bmp_alloc(TEST_BITS);\n+\tif (!bmp)\n+\t\treturn -ENOMEM;\n+\n+\tif (!test_bitmap_test_and_set_single(bmp, 0))\n+\t\tgoto err;\n+\n+\tif (!test_bitmap_test_and_set_single(bmp, MID_BIT))\n+\t\tgoto err;\n+\n+\tif (!test_bitmap_test_and_set_single(bmp, LAST_BIT))\n+\t\tgoto err;\n+\n+\tbmp_free(bmp);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(bmp);\n+\treturn -EINVAL;\n+}\n+\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_and(void)\n+{\n+\tstruct bitmap __arena *src1 = NULL, *src2 = NULL, *dst = NULL;\n+\n+\tsrc1 = bmp_alloc(TEST_BITS);\n+\tsrc2 = bmp_alloc(TEST_BITS);\n+\tdst = bmp_alloc(TEST_BITS);\n+\tif (!src1 || !src2 || !dst)\n+\t\tgoto err;\n+\n+\ttest_bmp_setall(dst);\n+\n+\t__bmp_set_bit(0, src1);\n+\t__bmp_set_bit(MID_BIT, src1);\n+\t__bmp_set_bit(LAST_BIT, src1);\n+\n+\t__bmp_set_bit(MID_BIT, src2);\n+\t__bmp_set_bit(LAST_BIT, src2);\n+\n+\tbmp_and(TEST_BITS, dst, src1, src2);\n+\n+\tif (bmp_test_bit(0, dst))\n+\t\tgoto err;\n+\tif (!bmp_test_bit(MID_BIT, dst))\n+\t\tgoto err;\n+\tif (!bmp_test_bit(LAST_BIT, dst))\n+\t\tgoto err;\n+\n+\tif (dst-\u003ebits[0])\n+\t\tgoto err;\n+\tif (dst-\u003ebits[1] != (BIT_MASK(MID_BIT) | BIT_MASK(LAST_BIT)))\n+\t\tgoto err;\n+\n+\tbmp_free(src1);\n+\tbmp_free(src2);\n+\tbmp_free(dst);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(src1);\n+\tbmp_free(src2);\n+\tbmp_free(dst);\n+\treturn -EINVAL;\n+}\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_or(void)\n+{\n+\tstruct bitmap __arena *src1 = NULL, *src2 = NULL, *dst = NULL;\n+\n+\tsrc1 = bmp_alloc(TEST_BITS);\n+\tsrc2 = bmp_alloc(TEST_BITS);\n+\tdst = bmp_alloc(TEST_BITS);\n+\tif (!src1 || !src2 || !dst)\n+\t\tgoto err;\n+\n+\ttest_bmp_setall(dst);\n+\n+\t__bmp_set_bit(0, src1);\n+\t__bmp_set_bit(LAST_BIT, src1);\n+\n+\t__bmp_set_bit(MID_BIT, src2);\n+\t__bmp_set_bit(LAST_BIT, src2);\n+\n+\tbmp_or(TEST_BITS, dst, src1, src2);\n+\n+\tif (!bmp_test_bit(0, dst))\n+\t\tgoto err;\n+\tif (!bmp_test_bit(MID_BIT, dst))\n+\t\tgoto err;\n+\tif (!bmp_test_bit(LAST_BIT, dst))\n+\t\tgoto err;\n+\n+\tif (dst-\u003ebits[0] != BIT_MASK(0))\n+\t\tgoto err;\n+\tif (dst-\u003ebits[1] != (BIT_MASK(MID_BIT) | BIT_MASK(LAST_BIT)))\n+\t\tgoto err;\n+\n+\tbmp_free(src1);\n+\tbmp_free(src2);\n+\tbmp_free(dst);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(src1);\n+\tbmp_free(src2);\n+\tbmp_free(dst);\n+\treturn -EINVAL;\n+}\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_subset(void)\n+{\n+\tstruct bitmap __arena *big = NULL, *small = NULL;\n+\n+\tbig = bmp_alloc(TEST_BITS);\n+\tsmall = bmp_alloc(TEST_BITS);\n+\tif (!big || !small)\n+\t\tgoto err;\n+\n+\tif (!bmp_subset(TEST_BITS, big, small))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(0, small);\n+\tif (bmp_subset(TEST_BITS, big, small))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(0, big);\n+\tif (!bmp_subset(TEST_BITS, big, small))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(LAST_BIT, small);\n+\tif (bmp_subset(TEST_BITS, big, small))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(LAST_BIT, big);\n+\t__bmp_set_bit(MID_BIT, big);\n+\tif (!bmp_subset(TEST_BITS, big, small))\n+\t\tgoto err;\n+\n+\tif (bmp_subset(TEST_BITS, small, big))\n+\t\tgoto err;\n+\n+\tbmp_free(big);\n+\tbmp_free(small);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(big);\n+\tbmp_free(small);\n+\treturn -EINVAL;\n+\n+}\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_intersects(void)\n+{\n+\tstruct bitmap __arena *arg1 = NULL, *arg2 = NULL;\n+\n+\targ1 = bmp_alloc(TEST_BITS);\n+\targ2 = bmp_alloc(TEST_BITS);\n+\tif (!arg1 || !arg2)\n+\t\tgoto err;\n+\n+\tif (bmp_intersects(TEST_BITS, arg1, arg2))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(0, arg1);\n+\t__bmp_set_bit(MID_BIT, arg2);\n+\tif (bmp_intersects(TEST_BITS, arg1, arg2))\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(LAST_BIT, arg1);\n+\t__bmp_set_bit(LAST_BIT, arg2);\n+\tif (!bmp_intersects(TEST_BITS, arg1, arg2))\n+\t\tgoto err;\n+\n+\tbmp_free(arg1);\n+\tbmp_free(arg2);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(arg1);\n+\tbmp_free(arg2);\n+\treturn -EINVAL;\n+}\n+\n+SEC(\"syscall\")\n+__weak int test_bitmap_copy(void)\n+{\n+\tstruct bitmap __arena *arg1 = NULL, *arg2 = NULL;\n+\n+\targ1 = bmp_alloc(TEST_BITS);\n+\targ2 = bmp_alloc(TEST_BITS);\n+\tif (!arg1 || !arg2)\n+\t\tgoto err;\n+\n+\t__bmp_set_bit(0, arg1);\n+\t__bmp_set_bit(MID_BIT, arg1);\n+\n+\t/* Make sure those get overwritten. */\n+\t__bmp_set_bit(1, arg2);\n+\t__bmp_set_bit(MID_BIT + 2, arg2);\n+\n+\tbmp_copy(TEST_BITS, arg2, arg1);\n+\n+\t/* Bitmaps are equal if a subset of each other. */\n+\tif (!bmp_subset(TEST_BITS, arg1, arg2) ||\n+\t !bmp_subset(TEST_BITS, arg2, arg1))\n+\t\tgoto err;\n+\n+\tbmp_free(arg1);\n+\tbmp_free(arg2);\n+\treturn 0;\n+\n+err:\n+\tbmp_free(arg1);\n+\tbmp_free(arg2);\n+\treturn -EINVAL;\n+}\ndiff --git a/tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c\nsimilarity index 97%\nrename from tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c\nrename to tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c\nindex b45a306816c0e4..5628f09870121c 100644\n--- a/tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c\n+++ b/tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c\n@@ -171,7 +171,8 @@ __weak int test_buddy_alloc_multiple(void)\n SEC(\"syscall\")\n __weak int test_buddy_alignment(void)\n {\n-\tint ret, i;\n+\tint ret;\n+\tu32 i;\n \n \tret = buddy_init(\u0026buddy);\n \tif (ret)\n@@ -179,6 +180,7 @@ __weak int test_buddy_alignment(void)\n \n \t/* Allocate various sizes and check alignment */\n \tfor (i = zero; i \u003c 17 \u0026\u0026 can_loop; i++) {\n+\t\tbarrier_var(i);\n \t\tptrs[i] = buddy_alloc(\u0026buddy, alignment_sizes[i]);\n \t\tif (!ptrs[i]) {\n \t\t\tarena_stdout(\"alignment test: alloc failed for size %lu\",\n@@ -198,8 +200,10 @@ __weak int test_buddy_alignment(void)\n \t}\n \n \t/* Free all allocations */\n-\tfor (i = zero; i \u003c 17 \u0026\u0026 can_loop; i++)\n+\tfor (i = zero; i \u003c 17 \u0026\u0026 can_loop; i++) {\n+\t\tbarrier_var(i);\n \t\tbuddy_free(\u0026buddy, ptrs[i]);\n+\t}\n \n \tbuddy_destroy(\u0026buddy);\n \ndiff --git a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c\nnew file mode 100644\nindex 00000000000000..eec2871e2b0d10\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c\n@@ -0,0 +1,190 @@\n+// SPDX-License-Identifier: LGPL-2.1 OR BSD-2-Clause\n+\n+#include \u003cbpf_atomic.h\u003e\n+\n+#include \u003clibarena/common.h\u003e\n+\n+#include \u003clibarena/asan.h\u003e\n+#include \u003clibarena/bitmap.h\u003e\n+\n+#define TEST_BITMAP_THREADS\t2\n+#define TEST_BITMAP_BITS\t(2 * BITS_PER_LONG_LONG)\n+#define TEST_BITMAP_SYNC_SPINS\tBPF_MAX_LOOPS\n+#define TEST_BITMAP_ITERS\t10 * 1000 * 1000\n+\n+static struct bitmap __arena *bitmap;\n+static volatile u64 started;\n+static volatile bool test_abort;\n+\n+/*\n+ * The test needs cmpxchg atomics on arena memory.\n+ */\n+#if defined(ENABLE_ATOMICS_TESTS) \u0026\u0026\t\t\t\t \\\n+\t(defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \\\n+\t defined(__TARGET_ARCH_s390) || \\\n+\t defined(__TARGET_ARCH_powerpc) ||\t\t\t\t \\\n+\t (defined(__TARGET_ARCH_riscv) \u0026\u0026 __riscv_xlen == 64))\n+static bool bitmap_tests_enabled(void)\n+{\n+\treturn true;\n+}\n+#else\n+static bool bitmap_tests_enabled(void)\n+{\n+\treturn false;\n+}\n+#endif\n+\n+__weak\n+int bitmap_wait_for_start(void)\n+{\n+\tu64 i;\n+\n+\t__sync_fetch_and_add(\u0026started, 1);\n+\n+\tfor (i = zero; i \u003c TEST_BITMAP_SYNC_SPINS \u0026\u0026 can_loop; i++) {\n+\t\tif (test_abort)\n+\t\t\treturn -EINTR;\n+\t\tif (smp_load_acquire(\u0026started) \u003e= TEST_BITMAP_THREADS)\n+\t\t\treturn 0;\n+\t}\n+\n+\ttest_abort = true;\n+\treturn -ETIMEDOUT;\n+}\n+\n+/*\n+ * The test makes sure writes don't clobber each other by overwriting\n+ * the same word. One thread always writes on even bits, the other on\n+ * odds. Both should be able to operate on the bitmap oblivious of the\n+ * other's operations.\n+ */\n+__weak\n+int bitmap_test_bit_sequence(u32 bit)\n+{\n+\tif (bmp_test_and_clear_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\n+\tif (bmp_test_and_set_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\tif (!bmp_test_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\n+\tif (!bmp_test_and_set_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\tif (!bmp_test_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\n+\tif (!bmp_test_and_clear_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\tif (bmp_test_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\n+\tif (bmp_test_and_clear_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\n+\tbmp_set_bit(bit, bitmap);\n+\tif (!bmp_test_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\n+\tbmp_clear_bit(bit, bitmap);\n+\tif (bmp_test_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\n+\tbmp_set_bit(bit, bitmap);\n+\tif (!bmp_test_bit(bit, bitmap))\n+\t\treturn -EINVAL;\n+\n+\treturn 0;\n+\n+}\n+\n+static void bitmap_test_reset_single(int parity)\n+{\n+\tu32 bit;\n+\n+\tfor (bit = parity; bit \u003c TEST_BITMAP_BITS \u0026\u0026 can_loop; bit += 2)\n+\t\tbmp_clear_bit(bit, bitmap);\n+\n+}\n+\n+static int bitmap_test_common_single(int parity)\n+{\n+\tu32 bit;\n+\tint ret;\n+\n+\tfor (bit = parity; bit \u003c TEST_BITMAP_BITS \u0026\u0026 can_loop; bit += 2) {\n+\t\tif (test_abort)\n+\t\t\treturn -EINTR;\n+\n+\t\tret = bitmap_test_bit_sequence(bit);\n+\t\tif (ret) {\n+\t\t\ttest_abort = true;\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int bitmap_test_common(int parity)\n+{\n+\tint ret;\n+\tu32 i;\n+\n+\tarena_subprog_init();\n+\n+\tret = bitmap_wait_for_start();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tfor (i = zero; i \u003c TEST_BITMAP_ITERS \u0026\u0026 can_loop; i++) {\n+\t\tret = bitmap_test_common_single(parity);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\tif (test_abort)\n+\t\t\tbreak;\n+\n+\t\tbitmap_test_reset_single(parity);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\") int parallel_test_bitmap__enabled(void)\n+{\n+\treturn bitmap_tests_enabled() ? 0 : -EOPNOTSUPP;\n+}\n+\n+SEC(\"syscall\") int parallel_test_bitmap__init(void)\n+{\n+\tbitmap = bmp_alloc(TEST_BITMAP_BITS);\n+\tif (!bitmap)\n+\t\treturn -ENOMEM;\n+\n+\treturn 0;\n+}\n+\n+SEC(\"syscall\") int parallel_test_bitmap__fini(void)\n+{\n+\tint ret = 0;\n+\n+\tif (!bitmap)\n+\t\treturn -EINVAL;\n+\n+\tbmp_free(bitmap);\n+\tbitmap = NULL;\n+\n+\treturn ret;\n+}\n+\n+SEC(\"syscall\") int parallel_test_bitmap__0(void)\n+{\n+\treturn bitmap_test_common(0);\n+}\n+\n+SEC(\"syscall\") int parallel_test_bitmap__1(void)\n+{\n+\treturn bitmap_test_common(1);\n+}\ndiff --git a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c\nindex f08f2a92e19468..5fa96eb740951c 100644\n--- a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c\n+++ b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c\n@@ -155,7 +155,7 @@ int spmc_quiesce_on_owner(u64 epoch)\n {\n \tu64 i;\n \n-\tbpf_for(i, 0, TEST_SPMC_SYNC_SPINS) {\n+\tfor (i = zero; i \u003c TEST_SPMC_SYNC_SPINS \u0026\u0026 can_loop; i++) {\n \t\tif (test_abort)\n \t\t\treturn -EINTR;\n \t\tif (smp_load_acquire(\u0026owner_epoch) \u003e= epoch)\n@@ -175,8 +175,7 @@ int spmc_quiesce_on_stealer(u64 epoch)\n \tint err = -ETIMEDOUT;\n \n \ttarget = STEALER_EPOCH(epoch);\n-\tbpf_for(i, 0, TEST_SPMC_SYNC_SPINS) {\n-\n+\tfor (i = zero; i \u003c TEST_SPMC_SYNC_SPINS \u0026\u0026 can_loop; i++) {\n \t\tif (test_abort) {\n \t\t\terr = -EINTR;\n \t\t\tbreak;\n@@ -391,7 +390,7 @@ int spmc_wait_for_stealers_to_start(u64 target)\n {\n \tu64 i;\n \n-\tbpf_for(i, 0, TEST_SPMC_SYNC_SPINS) {\n+\tfor (i = zero; i \u003c TEST_SPMC_SYNC_SPINS \u0026\u0026 can_loop; i++) {\n \t\tif (test_abort)\n \t\t\treturn -EINTR;\n \t\tif (READ_ONCE(stealers_started) \u003e= target)\n@@ -537,7 +536,7 @@ static int spmc_wait_for_round_steals(u64 target)\n \n \tarena_subprog_init();\n \n-\tbpf_for(i, 0, TEST_SPMC_SYNC_SPINS) {\n+\tfor (i = zero; i \u003c TEST_SPMC_SYNC_SPINS \u0026\u0026 can_loop; i++) {\n \t\tif (test_abort)\n \t\t\treturn -EINTR;\n \t\tif (round_steals \u003e= target)\ndiff --git a/tools/testing/selftests/bpf/libarena/src/bitmap.bpf.c b/tools/testing/selftests/bpf/libarena/src/bitmap.bpf.c\nnew file mode 100644\nindex 00000000000000..80e814401fb9ea\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/libarena/src/bitmap.bpf.c\n@@ -0,0 +1,245 @@\n+// SPDX-License-Identifier: LGPL-2.1 OR BSD-2-Clause\n+/*\n+ * Copyright (c) 2025-2026 Meta Platforms, Inc. and affiliates.\n+ * Copyright (c) 2025-2026 Emil Tsalapatis \u003cemil@etsalapatis.com\u003e\n+ */\n+\n+#include \u003clibarena/common.h\u003e\n+\n+#include \u003clibarena/asan.h\u003e\n+#include \u003clibarena/bitmap.h\u003e\n+\n+__weak\n+struct bitmap __arena *bmp_alloc(size_t bits)\n+{\n+\tstruct bitmap __arena *bmp;\n+\tsize_t size = BITS_TO_LONG_LONGS(bits) * sizeof(bmp-\u003ebits[0]);\n+\n+\t/* Assume long-aligned masks. */\n+\tif (bits % BITS_PER_LONG_LONG)\n+\t\treturn NULL;\n+\n+\tbmp = (struct bitmap __arena *)arena_malloc(size);\n+\tif (!bmp)\n+\t\treturn NULL;\n+\n+\tbmp_clear(bits, bmp);\n+\n+\treturn bmp;\n+}\n+\n+__weak\n+void bmp_free(struct bitmap __arena *bmp)\n+{\n+\tarena_free(bmp);\n+}\n+\n+__weak\n+void __bmp_set_bit(u32 bit, struct bitmap __arena *bmp)\n+{\n+\tbmp-\u003ebits[BIT_WORD(bit)] |= BIT_MASK(bit);\n+}\n+\n+__weak\n+void __bmp_clear_bit(u32 bit, struct bitmap __arena *bmp)\n+{\n+\tbmp-\u003ebits[BIT_WORD(bit)] \u0026= ~BIT_MASK(bit);\n+}\n+\n+__weak\n+bool bmp_test_bit(u32 bit, struct bitmap __arena *bmp)\n+{\n+\treturn bmp-\u003ebits[BIT_WORD(bit)] \u0026 BIT_MASK(bit);\n+}\n+\n+__weak\n+bool bmp_test_and_clear_bit(u32 bit, struct bitmap __arena *bmp)\n+{\n+\tu64 val = BIT_MASK(bit);\n+\tu32 idx = BIT_WORD(bit);\n+\tu64 old, new, actual;\n+\n+\tdo {\n+\t\told = bmp-\u003ebits[idx];\n+\n+\t\tif (!(old \u0026 val))\n+\t\t\treturn false;\n+\n+\t\tnew = old \u0026 ~val;\n+\t\tactual = cmpxchg(\u0026bmp-\u003ebits[idx], old, new);\n+\n+\t\tif (actual == old)\n+\t\t\treturn true;\n+\n+\t} while (can_loop);\n+\n+\treturn false;\n+}\n+\n+__weak\n+bool bmp_test_and_set_bit(u32 bit, struct bitmap __arena *bmp)\n+{\n+\tu64 val = BIT_MASK(bit);\n+\tu32 idx = BIT_WORD(bit);\n+\tu64 old, new, actual;\n+\n+\tdo {\n+\t\told = bmp-\u003ebits[idx];\n+\n+\t\tif ((old \u0026 val))\n+\t\t\treturn true;\n+\n+\t\tnew = old | val;\n+\t\tactual = cmpxchg(\u0026bmp-\u003ebits[idx], old, new);\n+\n+\t\tif (actual == old)\n+\t\t\treturn false;\n+\n+\t} while (can_loop);\n+\n+\treturn false;\n+}\n+\n+__weak\n+void bmp_clear_bit(u32 bit, struct bitmap __arena *bmp)\n+{\n+\tu64 val = BIT_MASK(bit);\n+\tu32 idx = BIT_WORD(bit);\n+\tu64 old, new, actual;\n+\n+\tdo {\n+\t\told = bmp-\u003ebits[idx];\n+\t\tnew = old \u0026 ~val;\n+\t\tactual = cmpxchg(\u0026bmp-\u003ebits[idx], old, new);\n+\n+\t} while (actual != old \u0026\u0026 can_loop);\n+}\n+\n+__weak\n+void bmp_set_bit(u32 bit, struct bitmap __arena *bmp)\n+{\n+\tu64 val = BIT_MASK(bit);\n+\tu32 idx = BIT_WORD(bit);\n+\tu64 old, new, actual;\n+\n+\tdo {\n+\t\told = bmp-\u003ebits[idx];\n+\t\tnew = old | val;\n+\t\tactual = cmpxchg(\u0026bmp-\u003ebits[idx], old, new);\n+\n+\t} while (actual != old \u0026\u0026 can_loop);\n+}\n+\n+__weak\n+void bmp_clear(size_t bits, struct bitmap __arena *bmp)\n+{\n+\tsize_t nwords = BITS_TO_LONG_LONGS(bits);\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c nwords \u0026\u0026 can_loop; i++)\n+\t\tbmp-\u003ebits[i] = 0;\n+}\n+\n+static __always_inline u64 bmp_last_word_mask(size_t bits)\n+{\n+\tu32 rem = bits % BITS_PER_LONG_LONG;\n+\n+\treturn rem ? (1ULL \u003c\u003c rem) - 1 : ~0ULL;\n+}\n+\n+__weak\n+void bmp_and(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src1, struct bitmap __arena *src2)\n+{\n+\tsize_t nwords = BITS_TO_LONG_LONGS(bits);\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c nwords \u0026\u0026 can_loop; i++)\n+\t\tdst-\u003ebits[i] = src1-\u003ebits[i] \u0026 src2-\u003ebits[i];\n+\n+\tif (nwords \u0026\u0026 bits % BITS_PER_LONG_LONG)\n+\t\tdst-\u003ebits[nwords - 1] \u0026= bmp_last_word_mask(bits);\n+}\n+\n+__weak\n+void bmp_or(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src1, struct bitmap __arena *src2)\n+{\n+\tsize_t nwords = BITS_TO_LONG_LONGS(bits);\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c nwords \u0026\u0026 can_loop; i++)\n+\t\tdst-\u003ebits[i] = src1-\u003ebits[i] | src2-\u003ebits[i];\n+\n+\tif (nwords \u0026\u0026 bits % BITS_PER_LONG_LONG)\n+\t\tdst-\u003ebits[nwords - 1] \u0026= bmp_last_word_mask(bits);\n+}\n+\n+__weak\n+bool bmp_empty(size_t bits, struct bitmap __arena *bmp)\n+{\n+\tsize_t nwords = BITS_TO_LONG_LONGS(bits);\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c nwords \u0026\u0026 can_loop; i++) {\n+\t\tu64 mask = (i == nwords - 1) ? bmp_last_word_mask(bits) : ~0ULL;\n+\n+\t\tif (bmp-\u003ebits[i] \u0026 mask)\n+\t\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+__weak\n+void bmp_copy(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src)\n+{\n+\tsize_t nwords = BITS_TO_LONG_LONGS(bits);\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c nwords \u0026\u0026 can_loop; i++)\n+\t\tdst-\u003ebits[i] = src-\u003ebits[i];\n+\n+\tif (nwords \u0026\u0026 bits % BITS_PER_LONG_LONG)\n+\t\tdst-\u003ebits[nwords - 1] \u0026= bmp_last_word_mask(bits);\n+}\n+\n+__weak\n+bool bmp_subset(size_t bits, struct bitmap __arena *big, struct bitmap __arena *small)\n+{\n+\tsize_t nwords = BITS_TO_LONG_LONGS(bits);\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c nwords \u0026\u0026 can_loop; i++) {\n+\t\tu64 mask = (i == nwords - 1) ? bmp_last_word_mask(bits) : ~0ULL;\n+\n+\t\tif (~big-\u003ebits[i] \u0026 small-\u003ebits[i] \u0026 mask)\n+\t\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+__weak\n+bool bmp_intersects(size_t bits, struct bitmap __arena *arg1, struct bitmap __arena *arg2)\n+{\n+\tsize_t nwords = BITS_TO_LONG_LONGS(bits);\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c nwords \u0026\u0026 can_loop; i++) {\n+\t\tu64 mask = (i == nwords - 1) ? bmp_last_word_mask(bits) : ~0ULL;\n+\n+\t\tif (arg1-\u003ebits[i] \u0026 arg2-\u003ebits[i] \u0026 mask)\n+\t\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\n+\n+__weak\n+void bmp_print(size_t bits, struct bitmap __arena *bmp)\n+{\n+\tsize_t nwords = BITS_TO_LONG_LONGS(bits);\n+\tvolatile u32 i;\n+\n+\tfor (i = zero; i \u003c nwords \u0026\u0026 can_loop; i++)\n+\t\tarena_stderr(\"%016llx \", bmp-\u003ebits[i]);\n+}\ndiff --git a/tools/testing/selftests/bpf/libarena/src/common.bpf.c b/tools/testing/selftests/bpf/libarena/src/common.bpf.c\nindex 50be57213dfb8d..569f0f64d518b3 100644\n--- a/tools/testing/selftests/bpf/libarena/src/common.bpf.c\n+++ b/tools/testing/selftests/bpf/libarena/src/common.bpf.c\n@@ -4,9 +4,8 @@\n #include \u003clibarena/asan.h\u003e\n #include \u003clibarena/buddy.h\u003e\n \n-const volatile u32 zero = 0;\n-\n struct buddy __arena buddy;\n+volatile u32 zero = 0;\n \n int arena_fls(__u64 word)\n {\n@@ -38,6 +37,12 @@ __weak int arena_buddy_reset(void)\n \treturn buddy_init(\u0026buddy);\n }\n \n+SEC(\"syscall\")\n+__weak int arena_buddy_destroy(void)\n+{\n+\treturn buddy_destroy(\u0026buddy);\n+}\n+\n __weak void __arena *arena_malloc(size_t size)\n {\n \treturn buddy_alloc(\u0026buddy, size);\ndiff --git a/tools/testing/selftests/bpf/prog_tests/libarena.c b/tools/testing/selftests/bpf/prog_tests/libarena.c\nindex 61ea68dce4105f..ba5a5a50f7c07d 100644\n--- a/tools/testing/selftests/bpf/prog_tests/libarena.c\n+++ b/tools/testing/selftests/bpf/prog_tests/libarena.c\n@@ -15,7 +15,12 @@ static void run_libarena_test(struct libarena *skel, struct bpf_program *prog,\n {\n \tint ret;\n \n-\tif (!strstr(name, \"test_buddy\")) {\n+\tif (strstr(name, \"test_buddy\")) {\n+\t\t/* Buddy tests initialize the allocator directly. */\n+\t\tret = libarena_run_prog(bpf_program__fd(skel-\u003eprogs.arena_buddy_destroy));\n+\t\tif (!ASSERT_OK(ret, \"arena_buddy_destroy\"))\n+\t\t\treturn;\n+\t} else {\n \t\tret = libarena_run_prog(bpf_program__fd(skel-\u003eprogs.arena_buddy_reset));\n \t\tif (!ASSERT_OK(ret, \"arena_buddy_reset\"))\n \t\t\treturn;\n@@ -24,7 +29,6 @@ static void run_libarena_test(struct libarena *skel, struct bpf_program *prog,\n \tret = libarena_run_prog(bpf_program__fd(prog));\n \n \tASSERT_OK(ret, name);\n-\n }\n \n static void *run_libarena_parallel_prog(void *arg)\ndiff --git a/tools/testing/selftests/bpf/prog_tests/libarena_asan.c b/tools/testing/selftests/bpf/prog_tests/libarena_asan.c\nindex d59d9dd12ef2b2..f897405f701dd5 100644\n--- a/tools/testing/selftests/bpf/prog_tests/libarena_asan.c\n+++ b/tools/testing/selftests/bpf/prog_tests/libarena_asan.c\n@@ -17,7 +17,12 @@ static void run_libarena_asan_test(struct libarena_asan *skel,\n {\n \tint ret;\n \n-\tif (!strstr(name, \"test_buddy\")) {\n+\tif (strstr(name, \"test_buddy\")) {\n+\t\t/* Buddy tests initialize the allocator directly. */\n+\t\tret = libarena_run_prog(bpf_program__fd(skel-\u003eprogs.arena_buddy_destroy));\n+\t\tif (!ASSERT_OK(ret, \"arena_buddy_destroy\"))\n+\t\t\treturn;\n+\t} else {\n \t\tret = libarena_run_prog(bpf_program__fd(skel-\u003eprogs.arena_buddy_reset));\n \t\tif (!ASSERT_OK(ret, \"arena_buddy_reset\"))\n \t\t\treturn;\n@@ -90,4 +95,3 @@ void test_libarena_asan(void)\n \n \treturn;\n }\n-\n"
} |
| 2/1 | 2026/07/07 02:01 | agent | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch only adds and modifies BPF selftests for libarena under tools/testing/selftests/bpf/. It does not make any functional changes to the core kernel, drivers, or architecture code.",
"WorthFuzzing": false
}Instruction: You are an expert Linux kernel maintainer. Your job is to review a provided patch series and determine if it makes functional changes to the kernel that should be fuzzed. IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively use your code access tools to examine the actual source code and confirm any assumptions. Return WorthFuzzing=false if the patch only contains: - Modifications to Documentation/, Kconfig files, or code comments. - Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints. - Changes to numeric constants or macros that do not functionally alter execution flow. - Code paths that are impossible to reach in virtualized environments like GCE or QEMU, even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim). If it modifies reachable core kernel logic, drivers, or architectures, use your code search tools to verify the code can be executed, then return WorthFuzzing=true. When returning WorthFuzzing=true, you MUST ALSO: 1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols. Avoid listing generic hot-path functions to prevent skewed test distributions. 2. Identify any specific CONFIG_ options required to properly test this new/modified feature. Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions. Do not list too generic configs (we already have them enabled). Only list those that specifically cover the modified code. List them in the EnableConfigs output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4"). Prefer calling several tools at the same time to save round-trips. Use set-results tool to provide results of the analysis. It must be called exactly once before the final reply. Ignore results of this tool. Prompt: For your convenience, here is the diff of the changes:
commit 8c4c144292ce5ce8c09630603f37d878af527fd8
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Jul 7 02:01:28 2026 +0000
syz-cluster: applied patch under review
diff --git a/tools/testing/selftests/bpf/libarena/include/libarena/bitmap.h b/tools/testing/selftests/bpf/libarena/include/libarena/bitmap.h
new file mode 100644
index 00000000000000..cf6b63f5d9a45f
--- /dev/null
+++ b/tools/testing/selftests/bpf/libarena/include/libarena/bitmap.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#define BITS_PER_BYTE 8
+#define BYTES_TO_BITS(nb) ((nb) * BITS_PER_BYTE)
+
+#define BITS_PER_LONG_LONG (sizeof(long long) * BITS_PER_BYTE)
+#define BITS_TO_LONG_LONGS(nr) (((nr) + BITS_PER_LONG_LONG - 1) / BITS_PER_LONG_LONG)
+#define BIT_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
+#define BIT_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
+
+struct bitmap {
+ u64 bits[0];
+};
+
+struct bitmap __arena *bmp_alloc(size_t bits);
+void bmp_free(struct bitmap __arena *bmp);
+
+void __bmp_set_bit(u32 bit, struct bitmap __arena *bmp);
+void __bmp_clear_bit(u32 bit, struct bitmap __arena *bmp);
+void bmp_set_bit(u32 bit, struct bitmap __arena *bmp);
+void bmp_clear_bit(u32 bit, struct bitmap __arena *bmp);
+bool bmp_test_bit(u32 bit, struct bitmap __arena *bmp);
+bool bmp_test_and_clear_bit(u32 bit, struct bitmap __arena *bmp);
+bool bmp_test_and_set_bit(u32 bit, struct bitmap __arena *bmp);
+
+void bmp_clear(size_t bits, struct bitmap __arena *bmp);
+void bmp_and(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src1, struct bitmap __arena *src2);
+void bmp_or(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src1, struct bitmap __arena *src2);
+bool bmp_empty(size_t bits, struct bitmap __arena *bmp);
+void bmp_copy(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src);
+
+bool bmp_intersects(size_t bits, struct bitmap __arena *arg1, struct bitmap __arena *arg2);
+bool bmp_subset(size_t bits, struct bitmap __arena *big, struct bitmap __arena *small);
+void bmp_print(size_t bits, struct bitmap __arena *bmp);
diff --git a/tools/testing/selftests/bpf/libarena/include/libarena/common.h b/tools/testing/selftests/bpf/libarena/include/libarena/common.h
index a3eb1641ac36df..931ace9a49e2bd 100644
--- a/tools/testing/selftests/bpf/libarena/include/libarena/common.h
+++ b/tools/testing/selftests/bpf/libarena/include/libarena/common.h
@@ -43,7 +43,7 @@ struct {
* imprecise. To force the variable to be imprecise, initialize it with
* the opaque volatile variable 0 instead of the constant 0.
*/
-extern const volatile u32 zero;
+volatile u32 zero __weak;
extern volatile u64 asan_violated;
int arena_fls(__u64 word);
diff --git a/tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
similarity index 98%
rename from tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c
rename to tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
index 686caba2c643b5..3266a28f53d768 100644
--- a/tools/testing/selftests/bpf/libarena/selftests/st_asan_buddy.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/selftests/test_asan_buddy.bpf.c
@@ -12,7 +12,7 @@ extern struct buddy __arena buddy;
#ifdef BPF_ARENA_ASAN
-#include "st_asan_common.h"
+#include "test_asan_common.h"
static __always_inline int asan_test_buddy_oob_single(size_t alloc_size)
{
@@ -154,7 +154,8 @@ __weak int asan_test_buddy_oob(void)
size_t sizes[] = {
7, 8, 17, 18, 64, 256, 317, 512, 1024,
};
- int ret, i;
+ int ret;
+ u32 i;
ret = buddy_init(&buddy);
if (ret) {
@@ -163,6 +164,7 @@ __weak int asan_test_buddy_oob(void)
}
for (i = zero; i < sizeof(sizes) / sizeof(sizes[0]) && can_loop; i++) {
+ barrier_var(i);
ret = asan_test_buddy_oob_single(sizes[i]);
if (ret) {
arena_stdout("%s:%d Failed for size %lu", __func__,
@@ -190,7 +192,8 @@ __stderr("Call trace:\n"
__weak int asan_test_buddy_uaf(void)
{
size_t sizes[] = { 16, 32, 64, 128, 256, 512, 1024, 16384 };
- int ret, i;
+ int ret;
+ u32 i;
ret = buddy_init(&buddy);
if (ret) {
@@ -199,6 +202,7 @@ __weak int asan_test_buddy_uaf(void)
}
for (i = zero; i < sizeof(sizes) / sizeof(sizes[0]) && can_loop; i++) {
+ barrier_var(i);
ret = asan_test_buddy_uaf_single(sizes[i]);
if (ret) {
arena_stdout("%s:%d Failed for size %lu", __func__,
diff --git a/tools/testing/selftests/bpf/libarena/selftests/st_asan_common.h b/tools/testing/selftests/bpf/libarena/selftests/test_asan_common.h
similarity index 100%
rename from tools/testing/selftests/bpf/libarena/selftests/st_asan_common.h
rename to tools/testing/selftests/bpf/libarena/selftests/test_asan_common.h
diff --git a/tools/testing/selftests/bpf/libarena/selftests/test_bitmap.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_bitmap.bpf.c
new file mode 100644
index 00000000000000..e7d32f44d68709
--- /dev/null
+++ b/tools/testing/selftests/bpf/libarena/selftests/test_bitmap.bpf.c
@@ -0,0 +1,394 @@
+#include <libarena/common.h>
+
+#include <libarena/asan.h>
+#include <libarena/bitmap.h>
+
+#define TEST_BITS (2 * BITS_PER_LONG_LONG)
+#define TEST_WORDS BITS_TO_LONG_LONGS(TEST_BITS)
+#define MID_BIT (BITS_PER_LONG_LONG + 1)
+#define LAST_BIT (TEST_BITS - 1)
+
+static void test_bmp_setall(struct bitmap __arena *bmp)
+{
+ volatile u32 i;
+
+ for (i = zero; i < TEST_WORDS && can_loop; i++)
+ bmp->bits[i] = ~0ULL;
+}
+
+SEC("syscall")
+__weak int test_bitmap_alloc_free(void)
+{
+ struct bitmap __arena *bmp;
+
+ bmp = bmp_alloc(TEST_BITS);
+ if (!bmp)
+ return -ENOMEM;
+
+ if (!bmp_empty(TEST_BITS, bmp))
+ goto err;
+
+ __bmp_set_bit(LAST_BIT, bmp);
+ if (!bmp_test_bit(LAST_BIT, bmp))
+ goto err;
+
+ __bmp_clear_bit(LAST_BIT, bmp);
+ if (bmp_test_bit(LAST_BIT, bmp))
+ goto err;
+
+ bmp_free(bmp);
+ return 0;
+
+err:
+ bmp_free(bmp);
+ return -EINVAL;
+}
+
+SEC("syscall")
+__weak int test_bitmap_bit_ops(void)
+{
+ struct bitmap __arena *bmp;
+
+ bmp = bmp_alloc(TEST_BITS);
+ if (!bmp)
+ return -ENOMEM;
+
+ __bmp_set_bit(0, bmp);
+ if (!bmp_test_bit(0, bmp))
+ goto err;
+
+ __bmp_set_bit(MID_BIT, bmp);
+ if (!bmp_test_bit(MID_BIT, bmp))
+ goto err;
+
+ __bmp_set_bit(LAST_BIT, bmp);
+ if (!bmp_test_bit(LAST_BIT, bmp))
+ goto err;
+
+ if (bmp_test_bit(MID_BIT - 1, bmp))
+ goto err;
+
+ __bmp_clear_bit(MID_BIT, bmp);
+ if (bmp_test_bit(MID_BIT, bmp))
+ goto err;
+
+ if (!bmp_test_bit(0, bmp))
+ goto err;
+
+ if (!bmp_test_bit(LAST_BIT, bmp))
+ goto err;
+
+ __bmp_clear_bit(0, bmp);
+ __bmp_clear_bit(LAST_BIT, bmp);
+ if (!bmp_empty(TEST_BITS, bmp))
+ goto err;
+
+ if (bmp->bits[0])
+ goto err;
+
+ if (bmp->bits[1])
+ goto err;
+
+ bmp_free(bmp);
+ return 0;
+
+err:
+ bmp_free(bmp);
+ return -EINVAL;
+}
+
+static bool test_bitmap_test_and_clear_single(struct bitmap __arena *bmp, size_t ind)
+{
+ if (bmp_test_and_clear_bit(ind, bmp))
+ return false;
+
+ __bmp_set_bit(ind, bmp);
+
+ if (!bmp_test_and_clear_bit(ind, bmp))
+ return false;
+
+ if (bmp_test_bit(ind, bmp))
+ return false;
+
+ if (bmp_test_and_clear_bit(ind, bmp))
+ return false;
+
+ return true;
+}
+
+static bool test_bitmap_test_and_set_single(struct bitmap __arena *bmp, size_t ind)
+{
+ if (bmp_test_and_set_bit(ind, bmp))
+ return false;
+
+ if (!bmp_test_and_set_bit(ind, bmp))
+ return false;
+
+ if (!bmp_test_bit(ind, bmp))
+ return false;
+
+ __bmp_clear_bit(ind, bmp);
+
+ if (bmp_test_and_set_bit(ind, bmp))
+ return false;
+
+ return true;
+}
+
+SEC("syscall")
+__weak int test_bitmap_test_and_clear_bit(void)
+{
+ struct bitmap __arena *bmp;
+
+ bmp = bmp_alloc(TEST_BITS);
+ if (!bmp)
+ return -ENOMEM;
+
+ if (!test_bitmap_test_and_clear_single(bmp, 0))
+ goto err;
+
+ if (!test_bitmap_test_and_clear_single(bmp, MID_BIT))
+ goto err;
+
+ if (!test_bitmap_test_and_clear_single(bmp, LAST_BIT))
+ goto err;
+
+ if (!bmp_empty(TEST_BITS, bmp))
+ goto err;
+
+ bmp_free(bmp);
+ return 0;
+
+err:
+ bmp_free(bmp);
+ return -EINVAL;
+}
+
+SEC("syscall")
+__weak int test_bitmap_test_and_set_bit(void)
+{
+ struct bitmap __arena *bmp;
+
+ bmp = bmp_alloc(TEST_BITS);
+ if (!bmp)
+ return -ENOMEM;
+
+ if (!test_bitmap_test_and_set_single(bmp, 0))
+ goto err;
+
+ if (!test_bitmap_test_and_set_single(bmp, MID_BIT))
+ goto err;
+
+ if (!test_bitmap_test_and_set_single(bmp, LAST_BIT))
+ goto err;
+
+ bmp_free(bmp);
+ return 0;
+
+err:
+ bmp_free(bmp);
+ return -EINVAL;
+}
+
+
+SEC("syscall")
+__weak int test_bitmap_and(void)
+{
+ struct bitmap __arena *src1 = NULL, *src2 = NULL, *dst = NULL;
+
+ src1 = bmp_alloc(TEST_BITS);
+ src2 = bmp_alloc(TEST_BITS);
+ dst = bmp_alloc(TEST_BITS);
+ if (!src1 || !src2 || !dst)
+ goto err;
+
+ test_bmp_setall(dst);
+
+ __bmp_set_bit(0, src1);
+ __bmp_set_bit(MID_BIT, src1);
+ __bmp_set_bit(LAST_BIT, src1);
+
+ __bmp_set_bit(MID_BIT, src2);
+ __bmp_set_bit(LAST_BIT, src2);
+
+ bmp_and(TEST_BITS, dst, src1, src2);
+
+ if (bmp_test_bit(0, dst))
+ goto err;
+ if (!bmp_test_bit(MID_BIT, dst))
+ goto err;
+ if (!bmp_test_bit(LAST_BIT, dst))
+ goto err;
+
+ if (dst->bits[0])
+ goto err;
+ if (dst->bits[1] != (BIT_MASK(MID_BIT) | BIT_MASK(LAST_BIT)))
+ goto err;
+
+ bmp_free(src1);
+ bmp_free(src2);
+ bmp_free(dst);
+ return 0;
+
+err:
+ bmp_free(src1);
+ bmp_free(src2);
+ bmp_free(dst);
+ return -EINVAL;
+}
+
+SEC("syscall")
+__weak int test_bitmap_or(void)
+{
+ struct bitmap __arena *src1 = NULL, *src2 = NULL, *dst = NULL;
+
+ src1 = bmp_alloc(TEST_BITS);
+ src2 = bmp_alloc(TEST_BITS);
+ dst = bmp_alloc(TEST_BITS);
+ if (!src1 || !src2 || !dst)
+ goto err;
+
+ test_bmp_setall(dst);
+
+ __bmp_set_bit(0, src1);
+ __bmp_set_bit(LAST_BIT, src1);
+
+ __bmp_set_bit(MID_BIT, src2);
+ __bmp_set_bit(LAST_BIT, src2);
+
+ bmp_or(TEST_BITS, dst, src1, src2);
+
+ if (!bmp_test_bit(0, dst))
+ goto err;
+ if (!bmp_test_bit(MID_BIT, dst))
+ goto err;
+ if (!bmp_test_bit(LAST_BIT, dst))
+ goto err;
+
+ if (dst->bits[0] != BIT_MASK(0))
+ goto err;
+ if (dst->bits[1] != (BIT_MASK(MID_BIT) | BIT_MASK(LAST_BIT)))
+ goto err;
+
+ bmp_free(src1);
+ bmp_free(src2);
+ bmp_free(dst);
+ return 0;
+
+err:
+ bmp_free(src1);
+ bmp_free(src2);
+ bmp_free(dst);
+ return -EINVAL;
+}
+
+SEC("syscall")
+__weak int test_bitmap_subset(void)
+{
+ struct bitmap __arena *big = NULL, *small = NULL;
+
+ big = bmp_alloc(TEST_BITS);
+ small = bmp_alloc(TEST_BITS);
+ if (!big || !small)
+ goto err;
+
+ if (!bmp_subset(TEST_BITS, big, small))
+ goto err;
+
+ __bmp_set_bit(0, small);
+ if (bmp_subset(TEST_BITS, big, small))
+ goto err;
+
+ __bmp_set_bit(0, big);
+ if (!bmp_subset(TEST_BITS, big, small))
+ goto err;
+
+ __bmp_set_bit(LAST_BIT, small);
+ if (bmp_subset(TEST_BITS, big, small))
+ goto err;
+
+ __bmp_set_bit(LAST_BIT, big);
+ __bmp_set_bit(MID_BIT, big);
+ if (!bmp_subset(TEST_BITS, big, small))
+ goto err;
+
+ if (bmp_subset(TEST_BITS, small, big))
+ goto err;
+
+ bmp_free(big);
+ bmp_free(small);
+ return 0;
+
+err:
+ bmp_free(big);
+ bmp_free(small);
+ return -EINVAL;
+
+}
+
+SEC("syscall")
+__weak int test_bitmap_intersects(void)
+{
+ struct bitmap __arena *arg1 = NULL, *arg2 = NULL;
+
+ arg1 = bmp_alloc(TEST_BITS);
+ arg2 = bmp_alloc(TEST_BITS);
+ if (!arg1 || !arg2)
+ goto err;
+
+ if (bmp_intersects(TEST_BITS, arg1, arg2))
+ goto err;
+
+ __bmp_set_bit(0, arg1);
+ __bmp_set_bit(MID_BIT, arg2);
+ if (bmp_intersects(TEST_BITS, arg1, arg2))
+ goto err;
+
+ __bmp_set_bit(LAST_BIT, arg1);
+ __bmp_set_bit(LAST_BIT, arg2);
+ if (!bmp_intersects(TEST_BITS, arg1, arg2))
+ goto err;
+
+ bmp_free(arg1);
+ bmp_free(arg2);
+ return 0;
+
+err:
+ bmp_free(arg1);
+ bmp_free(arg2);
+ return -EINVAL;
+}
+
+SEC("syscall")
+__weak int test_bitmap_copy(void)
+{
+ struct bitmap __arena *arg1 = NULL, *arg2 = NULL;
+
+ arg1 = bmp_alloc(TEST_BITS);
+ arg2 = bmp_alloc(TEST_BITS);
+ if (!arg1 || !arg2)
+ goto err;
+
+ __bmp_set_bit(0, arg1);
+ __bmp_set_bit(MID_BIT, arg1);
+
+ /* Make sure those get overwritten. */
+ __bmp_set_bit(1, arg2);
+ __bmp_set_bit(MID_BIT + 2, arg2);
+
+ bmp_copy(TEST_BITS, arg2, arg1);
+
+ /* Bitmaps are equal if a subset of each other. */
+ if (!bmp_subset(TEST_BITS, arg1, arg2) ||
+ !bmp_subset(TEST_BITS, arg2, arg1))
+ goto err;
+
+ bmp_free(arg1);
+ bmp_free(arg2);
+ return 0;
+
+err:
+ bmp_free(arg1);
+ bmp_free(arg2);
+ return -EINVAL;
+}
diff --git a/tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c
similarity index 97%
rename from tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c
rename to tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c
index b45a306816c0e4..5628f09870121c 100644
--- a/tools/testing/selftests/bpf/libarena/selftests/st_buddy.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/selftests/test_buddy.bpf.c
@@ -171,7 +171,8 @@ __weak int test_buddy_alloc_multiple(void)
SEC("syscall")
__weak int test_buddy_alignment(void)
{
- int ret, i;
+ int ret;
+ u32 i;
ret = buddy_init(&buddy);
if (ret)
@@ -179,6 +180,7 @@ __weak int test_buddy_alignment(void)
/* Allocate various sizes and check alignment */
for (i = zero; i < 17 && can_loop; i++) {
+ barrier_var(i);
ptrs[i] = buddy_alloc(&buddy, alignment_sizes[i]);
if (!ptrs[i]) {
arena_stdout("alignment test: alloc failed for size %lu",
@@ -198,8 +200,10 @@ __weak int test_buddy_alignment(void)
}
/* Free all allocations */
- for (i = zero; i < 17 && can_loop; i++)
+ for (i = zero; i < 17 && can_loop; i++) {
+ barrier_var(i);
buddy_free(&buddy, ptrs[i]);
+ }
buddy_destroy(&buddy);
diff --git a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c
new file mode 100644
index 00000000000000..eec2871e2b0d10
--- /dev/null
+++ b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_bitmap.bpf.c
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: LGPL-2.1 OR BSD-2-Clause
+
+#include <bpf_atomic.h>
+
+#include <libarena/common.h>
+
+#include <libarena/asan.h>
+#include <libarena/bitmap.h>
+
+#define TEST_BITMAP_THREADS 2
+#define TEST_BITMAP_BITS (2 * BITS_PER_LONG_LONG)
+#define TEST_BITMAP_SYNC_SPINS BPF_MAX_LOOPS
+#define TEST_BITMAP_ITERS 10 * 1000 * 1000
+
+static struct bitmap __arena *bitmap;
+static volatile u64 started;
+static volatile bool test_abort;
+
+/*
+ * The test needs cmpxchg atomics on arena memory.
+ */
+#if defined(ENABLE_ATOMICS_TESTS) && \
+ (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
+ defined(__TARGET_ARCH_s390) || \
+ defined(__TARGET_ARCH_powerpc) || \
+ (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64))
+static bool bitmap_tests_enabled(void)
+{
+ return true;
+}
+#else
+static bool bitmap_tests_enabled(void)
+{
+ return false;
+}
+#endif
+
+__weak
+int bitmap_wait_for_start(void)
+{
+ u64 i;
+
+ __sync_fetch_and_add(&started, 1);
+
+ for (i = zero; i < TEST_BITMAP_SYNC_SPINS && can_loop; i++) {
+ if (test_abort)
+ return -EINTR;
+ if (smp_load_acquire(&started) >= TEST_BITMAP_THREADS)
+ return 0;
+ }
+
+ test_abort = true;
+ return -ETIMEDOUT;
+}
+
+/*
+ * The test makes sure writes don't clobber each other by overwriting
+ * the same word. One thread always writes on even bits, the other on
+ * odds. Both should be able to operate on the bitmap oblivious of the
+ * other's operations.
+ */
+__weak
+int bitmap_test_bit_sequence(u32 bit)
+{
+ if (bmp_test_and_clear_bit(bit, bitmap))
+ return -EINVAL;
+
+ if (bmp_test_and_set_bit(bit, bitmap))
+ return -EINVAL;
+ if (!bmp_test_bit(bit, bitmap))
+ return -EINVAL;
+
+ if (!bmp_test_and_set_bit(bit, bitmap))
+ return -EINVAL;
+ if (!bmp_test_bit(bit, bitmap))
+ return -EINVAL;
+
+ if (!bmp_test_and_clear_bit(bit, bitmap))
+ return -EINVAL;
+ if (bmp_test_bit(bit, bitmap))
+ return -EINVAL;
+
+ if (bmp_test_and_clear_bit(bit, bitmap))
+ return -EINVAL;
+
+ bmp_set_bit(bit, bitmap);
+ if (!bmp_test_bit(bit, bitmap))
+ return -EINVAL;
+
+ bmp_clear_bit(bit, bitmap);
+ if (bmp_test_bit(bit, bitmap))
+ return -EINVAL;
+
+ bmp_set_bit(bit, bitmap);
+ if (!bmp_test_bit(bit, bitmap))
+ return -EINVAL;
+
+ return 0;
+
+}
+
+static void bitmap_test_reset_single(int parity)
+{
+ u32 bit;
+
+ for (bit = parity; bit < TEST_BITMAP_BITS && can_loop; bit += 2)
+ bmp_clear_bit(bit, bitmap);
+
+}
+
+static int bitmap_test_common_single(int parity)
+{
+ u32 bit;
+ int ret;
+
+ for (bit = parity; bit < TEST_BITMAP_BITS && can_loop; bit += 2) {
+ if (test_abort)
+ return -EINTR;
+
+ ret = bitmap_test_bit_sequence(bit);
+ if (ret) {
+ test_abort = true;
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static int bitmap_test_common(int parity)
+{
+ int ret;
+ u32 i;
+
+ arena_subprog_init();
+
+ ret = bitmap_wait_for_start();
+ if (ret)
+ return ret;
+
+ for (i = zero; i < TEST_BITMAP_ITERS && can_loop; i++) {
+ ret = bitmap_test_common_single(parity);
+ if (ret)
+ return ret;
+
+ if (test_abort)
+ break;
+
+ bitmap_test_reset_single(parity);
+ }
+
+ return 0;
+}
+
+SEC("syscall") int parallel_test_bitmap__enabled(void)
+{
+ return bitmap_tests_enabled() ? 0 : -EOPNOTSUPP;
+}
+
+SEC("syscall") int parallel_test_bitmap__init(void)
+{
+ bitmap = bmp_alloc(TEST_BITMAP_BITS);
+ if (!bitmap)
+ return -ENOMEM;
+
+ return 0;
+}
+
+SEC("syscall") int parallel_test_bitmap__fini(void)
+{
+ int ret = 0;
+
+ if (!bitmap)
+ return -EINVAL;
+
+ bmp_free(bitmap);
+ bitmap = NULL;
+
+ return ret;
+}
+
+SEC("syscall") int parallel_test_bitmap__0(void)
+{
+ return bitmap_test_common(0);
+}
+
+SEC("syscall") int parallel_test_bitmap__1(void)
+{
+ return bitmap_test_common(1);
+}
diff --git a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c
index f08f2a92e19468..5fa96eb740951c 100644
--- a/tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/selftests/test_parallel_spmc.bpf.c
@@ -155,7 +155,7 @@ int spmc_quiesce_on_owner(u64 epoch)
{
u64 i;
- bpf_for(i, 0, TEST_SPMC_SYNC_SPINS) {
+ for (i = zero; i < TEST_SPMC_SYNC_SPINS && can_loop; i++) {
if (test_abort)
return -EINTR;
if (smp_load_acquire(&owner_epoch) >= epoch)
@@ -175,8 +175,7 @@ int spmc_quiesce_on_stealer(u64 epoch)
int err = -ETIMEDOUT;
target = STEALER_EPOCH(epoch);
- bpf_for(i, 0, TEST_SPMC_SYNC_SPINS) {
-
+ for (i = zero; i < TEST_SPMC_SYNC_SPINS && can_loop; i++) {
if (test_abort) {
err = -EINTR;
break;
@@ -391,7 +390,7 @@ int spmc_wait_for_stealers_to_start(u64 target)
{
u64 i;
- bpf_for(i, 0, TEST_SPMC_SYNC_SPINS) {
+ for (i = zero; i < TEST_SPMC_SYNC_SPINS && can_loop; i++) {
if (test_abort)
return -EINTR;
if (READ_ONCE(stealers_started) >= target)
@@ -537,7 +536,7 @@ static int spmc_wait_for_round_steals(u64 target)
arena_subprog_init();
- bpf_for(i, 0, TEST_SPMC_SYNC_SPINS) {
+ for (i = zero; i < TEST_SPMC_SYNC_SPINS && can_loop; i++) {
if (test_abort)
return -EINTR;
if (round_steals >= target)
diff --git a/tools/testing/selftests/bpf/libarena/src/bitmap.bpf.c b/tools/testing/selftests/bpf/libarena/src/bitmap.bpf.c
new file mode 100644
index 00000000000000..80e814401fb9ea
--- /dev/null
+++ b/tools/testing/selftests/bpf/libarena/src/bitmap.bpf.c
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: LGPL-2.1 OR BSD-2-Clause
+/*
+ * Copyright (c) 2025-2026 Meta Platforms, Inc. and affiliates.
+ * Copyright (c) 2025-2026 Emil Tsalapatis <emil@etsalapatis.com>
+ */
+
+#include <libarena/common.h>
+
+#include <libarena/asan.h>
+#include <libarena/bitmap.h>
+
+__weak
+struct bitmap __arena *bmp_alloc(size_t bits)
+{
+ struct bitmap __arena *bmp;
+ size_t size = BITS_TO_LONG_LONGS(bits) * sizeof(bmp->bits[0]);
+
+ /* Assume long-aligned masks. */
+ if (bits % BITS_PER_LONG_LONG)
+ return NULL;
+
+ bmp = (struct bitmap __arena *)arena_malloc(size);
+ if (!bmp)
+ return NULL;
+
+ bmp_clear(bits, bmp);
+
+ return bmp;
+}
+
+__weak
+void bmp_free(struct bitmap __arena *bmp)
+{
+ arena_free(bmp);
+}
+
+__weak
+void __bmp_set_bit(u32 bit, struct bitmap __arena *bmp)
+{
+ bmp->bits[BIT_WORD(bit)] |= BIT_MASK(bit);
+}
+
+__weak
+void __bmp_clear_bit(u32 bit, struct bitmap __arena *bmp)
+{
+ bmp->bits[BIT_WORD(bit)] &= ~BIT_MASK(bit);
+}
+
+__weak
+bool bmp_test_bit(u32 bit, struct bitmap __arena *bmp)
+{
+ return bmp->bits[BIT_WORD(bit)] & BIT_MASK(bit);
+}
+
+__weak
+bool bmp_test_and_clear_bit(u32 bit, struct bitmap __arena *bmp)
+{
+ u64 val = BIT_MASK(bit);
+ u32 idx = BIT_WORD(bit);
+ u64 old, new, actual;
+
+ do {
+ old = bmp->bits[idx];
+
+ if (!(old & val))
+ return false;
+
+ new = old & ~val;
+ actual = cmpxchg(&bmp->bits[idx], old, new);
+
+ if (actual == old)
+ return true;
+
+ } while (can_loop);
+
+ return false;
+}
+
+__weak
+bool bmp_test_and_set_bit(u32 bit, struct bitmap __arena *bmp)
+{
+ u64 val = BIT_MASK(bit);
+ u32 idx = BIT_WORD(bit);
+ u64 old, new, actual;
+
+ do {
+ old = bmp->bits[idx];
+
+ if ((old & val))
+ return true;
+
+ new = old | val;
+ actual = cmpxchg(&bmp->bits[idx], old, new);
+
+ if (actual == old)
+ return false;
+
+ } while (can_loop);
+
+ return false;
+}
+
+__weak
+void bmp_clear_bit(u32 bit, struct bitmap __arena *bmp)
+{
+ u64 val = BIT_MASK(bit);
+ u32 idx = BIT_WORD(bit);
+ u64 old, new, actual;
+
+ do {
+ old = bmp->bits[idx];
+ new = old & ~val;
+ actual = cmpxchg(&bmp->bits[idx], old, new);
+
+ } while (actual != old && can_loop);
+}
+
+__weak
+void bmp_set_bit(u32 bit, struct bitmap __arena *bmp)
+{
+ u64 val = BIT_MASK(bit);
+ u32 idx = BIT_WORD(bit);
+ u64 old, new, actual;
+
+ do {
+ old = bmp->bits[idx];
+ new = old | val;
+ actual = cmpxchg(&bmp->bits[idx], old, new);
+
+ } while (actual != old && can_loop);
+}
+
+__weak
+void bmp_clear(size_t bits, struct bitmap __arena *bmp)
+{
+ size_t nwords = BITS_TO_LONG_LONGS(bits);
+ volatile u32 i;
+
+ for (i = zero; i < nwords && can_loop; i++)
+ bmp->bits[i] = 0;
+}
+
+static __always_inline u64 bmp_last_word_mask(size_t bits)
+{
+ u32 rem = bits % BITS_PER_LONG_LONG;
+
+ return rem ? (1ULL << rem) - 1 : ~0ULL;
+}
+
+__weak
+void bmp_and(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src1, struct bitmap __arena *src2)
+{
+ size_t nwords = BITS_TO_LONG_LONGS(bits);
+ volatile u32 i;
+
+ for (i = zero; i < nwords && can_loop; i++)
+ dst->bits[i] = src1->bits[i] & src2->bits[i];
+
+ if (nwords && bits % BITS_PER_LONG_LONG)
+ dst->bits[nwords - 1] &= bmp_last_word_mask(bits);
+}
+
+__weak
+void bmp_or(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src1, struct bitmap __arena *src2)
+{
+ size_t nwords = BITS_TO_LONG_LONGS(bits);
+ volatile u32 i;
+
+ for (i = zero; i < nwords && can_loop; i++)
+ dst->bits[i] = src1->bits[i] | src2->bits[i];
+
+ if (nwords && bits % BITS_PER_LONG_LONG)
+ dst->bits[nwords - 1] &= bmp_last_word_mask(bits);
+}
+
+__weak
+bool bmp_empty(size_t bits, struct bitmap __arena *bmp)
+{
+ size_t nwords = BITS_TO_LONG_LONGS(bits);
+ volatile u32 i;
+
+ for (i = zero; i < nwords && can_loop; i++) {
+ u64 mask = (i == nwords - 1) ? bmp_last_word_mask(bits) : ~0ULL;
+
+ if (bmp->bits[i] & mask)
+ return false;
+ }
+
+ return true;
+}
+
+__weak
+void bmp_copy(size_t bits, struct bitmap __arena *dst, struct bitmap __arena *src)
+{
+ size_t nwords = BITS_TO_LONG_LONGS(bits);
+ volatile u32 i;
+
+ for (i = zero; i < nwords && can_loop; i++)
+ dst->bits[i] = src->bits[i];
+
+ if (nwords && bits % BITS_PER_LONG_LONG)
+ dst->bits[nwords - 1] &= bmp_last_word_mask(bits);
+}
+
+__weak
+bool bmp_subset(size_t bits, struct bitmap __arena *big, struct bitmap __arena *small)
+{
+ size_t nwords = BITS_TO_LONG_LONGS(bits);
+ volatile u32 i;
+
+ for (i = zero; i < nwords && can_loop; i++) {
+ u64 mask = (i == nwords - 1) ? bmp_last_word_mask(bits) : ~0ULL;
+
+ if (~big->bits[i] & small->bits[i] & mask)
+ return false;
+ }
+
+ return true;
+}
+
+__weak
+bool bmp_intersects(size_t bits, struct bitmap __arena *arg1, struct bitmap __arena *arg2)
+{
+ size_t nwords = BITS_TO_LONG_LONGS(bits);
+ volatile u32 i;
+
+ for (i = zero; i < nwords && can_loop; i++) {
+ u64 mask = (i == nwords - 1) ? bmp_last_word_mask(bits) : ~0ULL;
+
+ if (arg1->bits[i] & arg2->bits[i] & mask)
+ return true;
+ }
+
+ return false;
+}
+
+__weak
+void bmp_print(size_t bits, struct bitmap __arena *bmp)
+{
+ size_t nwords = BITS_TO_LONG_LONGS(bits);
+ volatile u32 i;
+
+ for (i = zero; i < nwords && can_loop; i++)
+ arena_stderr("%016llx ", bmp->bits[i]);
+}
diff --git a/tools/testing/selftests/bpf/libarena/src/common.bpf.c b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
index 50be57213dfb8d..569f0f64d518b3 100644
--- a/tools/testing/selftests/bpf/libarena/src/common.bpf.c
+++ b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
@@ -4,9 +4,8 @@
#include <libarena/asan.h>
#include <libarena/buddy.h>
-const volatile u32 zero = 0;
-
struct buddy __arena buddy;
+volatile u32 zero = 0;
int arena_fls(__u64 word)
{
@@ -38,6 +37,12 @@ __weak int arena_buddy_reset(void)
return buddy_init(&buddy);
}
+SEC("syscall")
+__weak int arena_buddy_destroy(void)
+{
+ return buddy_destroy(&buddy);
+}
+
__weak void __arena *arena_malloc(size_t size)
{
return buddy_alloc(&buddy, size);
diff --git a/tools/testing/selftests/bpf/prog_tests/libarena.c b/tools/testing/selftests/bpf/prog_tests/libarena.c
index 61ea68dce4105f..ba5a5a50f7c07d 100644
--- a/tools/testing/selftests/bpf/prog_tests/libarena.c
+++ b/tools/testing/selftests/bpf/prog_tests/libarena.c
@@ -15,7 +15,12 @@ static void run_libarena_test(struct libarena *skel, struct bpf_program *prog,
{
int ret;
- if (!strstr(name, "test_buddy")) {
+ if (strstr(name, "test_buddy")) {
+ /* Buddy tests initialize the allocator directly. */
+ ret = libarena_run_prog(bpf_program__fd(skel->progs.arena_buddy_destroy));
+ if (!ASSERT_OK(ret, "arena_buddy_destroy"))
+ return;
+ } else {
ret = libarena_run_prog(bpf_program__fd(skel->progs.arena_buddy_reset));
if (!ASSERT_OK(ret, "arena_buddy_reset"))
return;
@@ -24,7 +29,6 @@ static void run_libarena_test(struct libarena *skel, struct bpf_program *prog,
ret = libarena_run_prog(bpf_program__fd(prog));
ASSERT_OK(ret, name);
-
}
static void *run_libarena_parallel_prog(void *arg)
diff --git a/tools/testing/selftests/bpf/prog_tests/libarena_asan.c b/tools/testing/selftests/bpf/prog_tests/libarena_asan.c
index d59d9dd12ef2b2..f897405f701dd5 100644
--- a/tools/testing/selftests/bpf/prog_tests/libarena_asan.c
+++ b/tools/testing/selftests/bpf/prog_tests/libarena_asan.c
@@ -17,7 +17,12 @@ static void run_libarena_asan_test(struct libarena_asan *skel,
{
int ret;
- if (!strstr(name, "test_buddy")) {
+ if (strstr(name, "test_buddy")) {
+ /* Buddy tests initialize the allocator directly. */
+ ret = libarena_run_prog(bpf_program__fd(skel->progs.arena_buddy_destroy));
+ if (!ASSERT_OK(ret, "arena_buddy_destroy"))
+ return;
+ } else {
ret = libarena_run_prog(bpf_program__fd(skel->progs.arena_buddy_reset));
if (!ASSERT_OK(ret, "arena_buddy_reset"))
return;
@@ -90,4 +95,3 @@ void test_libarena_asan(void)
return;
}
-
|
| 3/2 | 2026/07/07 02:01 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 13686 output: 75 thoughts: 574 Thoughts: **Patch Analysis: libarena Selftest Modifications** Okay, so I'm looking at a patch here, and it seems to be solely focused on modifying the BPF selftests related to libarena. I see a list of files that have been touched: `bitmap.h`, `common.h`, renamed `.bpf.c` files (e.g., `st_asan_buddy.bpf.c` to `test_asan_buddy.bpf.c`, and so on), and some associated C files. The important bit is that *everything* is under `tools/testing/selftests/bpf/`. Now, given my expertise, I know immediately that selftests are just that – tests. They're designed to validate the functionality of code, but they're *not* part of the core kernel logic, drivers, or any of the architectural code. They're user-space programs or BPF programs, for testing the kernel. They are not intended to modify or change the kernel itself, so there's no inherent risk of introducing new bugs to the core system via these changes. Just to be absolutely sure, I'm checking again to ensure no files were modified in other directories. No, all files are under `/tools/testing/selftests/bpf/`, as confirmed by the list. Therefore, from a fuzzing perspective, this is a definite "WorthFuzzing=false" scenario. The patch itself doesn't introduce any new surface area for fuzzing core kernel components. It's strictly about improving test coverage or adding new tests to the libarena framework within the BPF selftests. Alright, I'll go ahead and update the results tool with this assessment. |
| 4/2 | 2026/07/07 02:01 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch only adds and modifies BPF selftests for libarena under tools/testing/selftests/bpf/. It does not make any functional changes to the core kernel, drivers, or architecture code.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch only adds and modifies BPF selftests for libarena under tools/testing/selftests/bpf/. It does not make any functional changes to the core kernel, drivers, or architecture code.",
"WorthFuzzing": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|