Adapted to register names under arm and riscv, So that it can work on
arm, x86 and riscv.
In addition fix an para error on kretprobe remove in moudle exit.
Yipeng Zou (2):
tracing: kprobe: fix kprobe event gen test module on exit
tracing: kprobe: make gen test module work in arm and riscv
kernel/trace/kprobe_event_gen_test.c | 49 +++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 5 deletions(-)
--
2.17.1
Correct gen_kretprobe_test clr event para on module exit.
This will make it can't to delete.
Fixes: 64836248dda2 ("tracing: Add kprobe event command generation test module")
Signed-off-by: Yipeng Zou <[email protected]>
---
kernel/trace/kprobe_event_gen_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/trace/kprobe_event_gen_test.c b/kernel/trace/kprobe_event_gen_test.c
index 18b0f1cbb947..e023154be0f8 100644
--- a/kernel/trace/kprobe_event_gen_test.c
+++ b/kernel/trace/kprobe_event_gen_test.c
@@ -206,7 +206,7 @@ static void __exit kprobe_event_gen_test_exit(void)
WARN_ON(kprobe_event_delete("gen_kprobe_test"));
/* Disable the event or you can't remove it */
- WARN_ON(trace_array_set_clr_event(gen_kprobe_test->tr,
+ WARN_ON(trace_array_set_clr_event(gen_kretprobe_test->tr,
"kprobes",
"gen_kretprobe_test", false));
--
2.17.1
For now, this selftest module can only work in x86 because of the
kprobe cmd was fixed use of x86 registers.
This patch adapted to register names under arm and riscv, So that
this module can be worked on those platform.
Fixes: 64836248dda2 ("tracing: Add kprobe event command generation test module")
Signed-off-by: Yipeng Zou <[email protected]>
---
kernel/trace/kprobe_event_gen_test.c | 47 +++++++++++++++++++++++++---
1 file changed, 43 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/kprobe_event_gen_test.c b/kernel/trace/kprobe_event_gen_test.c
index e023154be0f8..80e04a1e1977 100644
--- a/kernel/trace/kprobe_event_gen_test.c
+++ b/kernel/trace/kprobe_event_gen_test.c
@@ -35,6 +35,45 @@
static struct trace_event_file *gen_kprobe_test;
static struct trace_event_file *gen_kretprobe_test;
+#define KPROBE_GEN_TEST_FUNC "do_sys_open"
+
+/* X86 */
+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_32)
+#define KPROBE_GEN_TEST_ARG0 "dfd=%ax"
+#define KPROBE_GEN_TEST_ARG1 "filename=%dx"
+#define KPROBE_GEN_TEST_ARG2 "flags=%cx"
+#define KPROBE_GEN_TEST_ARG3 "mode=+4($stack)"
+
+/* ARM64 */
+#elif defined(CONFIG_ARM64)
+#define KPROBE_GEN_TEST_ARG0 "dfd=%x0"
+#define KPROBE_GEN_TEST_ARG1 "filename=%x1"
+#define KPROBE_GEN_TEST_ARG2 "flags=%x2"
+#define KPROBE_GEN_TEST_ARG3 "mode=%x3"
+
+/* ARM */
+#elif defined(CONFIG_ARM)
+#define KPROBE_GEN_TEST_ARG0 "dfd=%r0"
+#define KPROBE_GEN_TEST_ARG1 "filename=%r1"
+#define KPROBE_GEN_TEST_ARG2 "flags=%r2"
+#define KPROBE_GEN_TEST_ARG3 "mode=%r3"
+
+/* RISCV */
+#elif defined(CONFIG_RISCV)
+#define KPROBE_GEN_TEST_ARG0 "dfd=%a0"
+#define KPROBE_GEN_TEST_ARG1 "filename=%a1"
+#define KPROBE_GEN_TEST_ARG2 "flags=%a2"
+#define KPROBE_GEN_TEST_ARG3 "mode=%a3"
+
+/* others */
+#else
+#define KPROBE_GEN_TEST_ARG0 NULL
+#define KPROBE_GEN_TEST_ARG1 NULL
+#define KPROBE_GEN_TEST_ARG2 NULL
+#define KPROBE_GEN_TEST_ARG3 NULL
+#endif
+
+
/*
* Test to make sure we can create a kprobe event, then add more
* fields.
@@ -58,14 +97,14 @@ static int __init test_gen_kprobe_cmd(void)
* fields.
*/
ret = kprobe_event_gen_cmd_start(&cmd, "gen_kprobe_test",
- "do_sys_open",
- "dfd=%ax", "filename=%dx");
+ KPROBE_GEN_TEST_FUNC,
+ KPROBE_GEN_TEST_ARG0, KPROBE_GEN_TEST_ARG1);
if (ret)
goto free;
/* Use kprobe_event_add_fields to add the rest of the fields */
- ret = kprobe_event_add_fields(&cmd, "flags=%cx", "mode=+4($stack)");
+ ret = kprobe_event_add_fields(&cmd, KPROBE_GEN_TEST_ARG2, KPROBE_GEN_TEST_ARG3);
if (ret)
goto free;
@@ -128,7 +167,7 @@ static int __init test_gen_kretprobe_cmd(void)
* Define the kretprobe event.
*/
ret = kretprobe_event_gen_cmd_start(&cmd, "gen_kretprobe_test",
- "do_sys_open",
+ KPROBE_GEN_TEST_FUNC,
"$retval");
if (ret)
goto free;
--
2.17.1
On Mon, 19 Sep 2022 20:56:29 +0800
Yipeng Zou <[email protected]> wrote:
> For now, this selftest module can only work in x86 because of the
> kprobe cmd was fixed use of x86 registers.
> This patch adapted to register names under arm and riscv, So that
> this module can be worked on those platform.
This also looks good to me. (good & simple solution :))
Acked-by: Masami Hiramatsu (Google) <[email protected]>
Thank you,
>
> Fixes: 64836248dda2 ("tracing: Add kprobe event command generation test module")
> Signed-off-by: Yipeng Zou <[email protected]>
> ---
> kernel/trace/kprobe_event_gen_test.c | 47 +++++++++++++++++++++++++---
> 1 file changed, 43 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/trace/kprobe_event_gen_test.c b/kernel/trace/kprobe_event_gen_test.c
> index e023154be0f8..80e04a1e1977 100644
> --- a/kernel/trace/kprobe_event_gen_test.c
> +++ b/kernel/trace/kprobe_event_gen_test.c
> @@ -35,6 +35,45 @@
> static struct trace_event_file *gen_kprobe_test;
> static struct trace_event_file *gen_kretprobe_test;
>
> +#define KPROBE_GEN_TEST_FUNC "do_sys_open"
> +
> +/* X86 */
> +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_32)
> +#define KPROBE_GEN_TEST_ARG0 "dfd=%ax"
> +#define KPROBE_GEN_TEST_ARG1 "filename=%dx"
> +#define KPROBE_GEN_TEST_ARG2 "flags=%cx"
> +#define KPROBE_GEN_TEST_ARG3 "mode=+4($stack)"
> +
> +/* ARM64 */
> +#elif defined(CONFIG_ARM64)
> +#define KPROBE_GEN_TEST_ARG0 "dfd=%x0"
> +#define KPROBE_GEN_TEST_ARG1 "filename=%x1"
> +#define KPROBE_GEN_TEST_ARG2 "flags=%x2"
> +#define KPROBE_GEN_TEST_ARG3 "mode=%x3"
> +
> +/* ARM */
> +#elif defined(CONFIG_ARM)
> +#define KPROBE_GEN_TEST_ARG0 "dfd=%r0"
> +#define KPROBE_GEN_TEST_ARG1 "filename=%r1"
> +#define KPROBE_GEN_TEST_ARG2 "flags=%r2"
> +#define KPROBE_GEN_TEST_ARG3 "mode=%r3"
> +
> +/* RISCV */
> +#elif defined(CONFIG_RISCV)
> +#define KPROBE_GEN_TEST_ARG0 "dfd=%a0"
> +#define KPROBE_GEN_TEST_ARG1 "filename=%a1"
> +#define KPROBE_GEN_TEST_ARG2 "flags=%a2"
> +#define KPROBE_GEN_TEST_ARG3 "mode=%a3"
> +
> +/* others */
> +#else
> +#define KPROBE_GEN_TEST_ARG0 NULL
> +#define KPROBE_GEN_TEST_ARG1 NULL
> +#define KPROBE_GEN_TEST_ARG2 NULL
> +#define KPROBE_GEN_TEST_ARG3 NULL
> +#endif
> +
> +
> /*
> * Test to make sure we can create a kprobe event, then add more
> * fields.
> @@ -58,14 +97,14 @@ static int __init test_gen_kprobe_cmd(void)
> * fields.
> */
> ret = kprobe_event_gen_cmd_start(&cmd, "gen_kprobe_test",
> - "do_sys_open",
> - "dfd=%ax", "filename=%dx");
> + KPROBE_GEN_TEST_FUNC,
> + KPROBE_GEN_TEST_ARG0, KPROBE_GEN_TEST_ARG1);
> if (ret)
> goto free;
>
> /* Use kprobe_event_add_fields to add the rest of the fields */
>
> - ret = kprobe_event_add_fields(&cmd, "flags=%cx", "mode=+4($stack)");
> + ret = kprobe_event_add_fields(&cmd, KPROBE_GEN_TEST_ARG2, KPROBE_GEN_TEST_ARG3);
> if (ret)
> goto free;
>
> @@ -128,7 +167,7 @@ static int __init test_gen_kretprobe_cmd(void)
> * Define the kretprobe event.
> */
> ret = kretprobe_event_gen_cmd_start(&cmd, "gen_kretprobe_test",
> - "do_sys_open",
> + KPROBE_GEN_TEST_FUNC,
> "$retval");
> if (ret)
> goto free;
> --
> 2.17.1
>
--
Masami Hiramatsu (Google) <[email protected]>
On Mon, 19 Sep 2022 20:56:28 +0800
Yipeng Zou <[email protected]> wrote:
> Correct gen_kretprobe_test clr event para on module exit.
> This will make it can't to delete.
Looks good to me. (actually, both tests will use the same root
trace_array, so the test itself will not fail, but this should
be fixed.)
Acked-by: Masami Hiramatsu (Google) <[email protected]>
Thanks!
>
> Fixes: 64836248dda2 ("tracing: Add kprobe event command generation test module")
> Signed-off-by: Yipeng Zou <[email protected]>
> ---
> kernel/trace/kprobe_event_gen_test.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/trace/kprobe_event_gen_test.c b/kernel/trace/kprobe_event_gen_test.c
> index 18b0f1cbb947..e023154be0f8 100644
> --- a/kernel/trace/kprobe_event_gen_test.c
> +++ b/kernel/trace/kprobe_event_gen_test.c
> @@ -206,7 +206,7 @@ static void __exit kprobe_event_gen_test_exit(void)
> WARN_ON(kprobe_event_delete("gen_kprobe_test"));
>
> /* Disable the event or you can't remove it */
> - WARN_ON(trace_array_set_clr_event(gen_kprobe_test->tr,
> + WARN_ON(trace_array_set_clr_event(gen_kretprobe_test->tr,
> "kprobes",
> "gen_kretprobe_test", false));
>
> --
> 2.17.1
>
--
Masami Hiramatsu (Google) <[email protected]>