Re: [PATCH v2] riscv: Add kprobes KUnit test
From: Thomas Huth
Date: Fri Sep 26 2025 - 07:51:48 EST
On 13/05/2025 17.16, Nam Cao wrote:
Add KUnit test for riscv kprobes, mostly for simulated instructions. The...
test install kprobes into multiple sample functions, and check that these
functions still return the expected magic value.
This test can detect some kprobe bugs reported in the past (in Link:).
Link: https://lore.kernel.org/linux-riscv/20241119111056.2554419-1-namcao@xxxxxxxxxxxxx/
Link: https://lore.kernel.org/stable/c7e463c0-8cad-4f4e-addd-195c06b7b6de@xxxxxxxxxxx/
Link: https://lore.kernel.org/linux-riscv/20230829182500.61875-1-namcaov@xxxxxxxxx/
Signed-off-by: Nam Cao <namcao@xxxxxxxxxxxxx>
---
diff --git a/arch/riscv/kernel/tests/kprobes/test-kprobes.h b/arch/riscv/kernel/tests/kprobes/test-kprobes.h
new file mode 100644
index 000000000000..3886ab491ecb
--- /dev/null
+++ b/arch/riscv/kernel/tests/kprobes/test-kprobes.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+#ifndef TEST_KPROBES_H
+#define TEST_KPROBES_H
+
+/*
+ * The magic value that all the functions in the test_kprobes_functions array return. The test
+ * installs kprobes into these functions, and verify that the functions still correctly return this
+ * value.
+ */
+#define KPROBE_TEST_MAGIC 0xcafebabe
+#define KPROBE_TEST_MAGIC_LOWER 0x0000babe
+#define KPROBE_TEST_MAGIC_UPPER 0xcafe0000
+
+#ifndef __ASSEMBLY__
Could you maybe change that into "__ASSEMBLER__" instead of "__ASSEMBLY__" ? I'm currently trying to get rid of the latter in the kernel sources, see: https://lore.kernel.org/all/20250606070952.498274-1-thuth@xxxxxxxxxx/
+/* array of addresses to install kprobes */
+extern void *test_kprobes_addresses[];
+
+/* array of functions that return KPROBE_TEST_MAGIC */
+extern long (*test_kprobes_functions[])(void);
+
+#endif /* __ASSEMBLY__ */
dito.
Thanks,
Thomas