Commit d8ef45d6 authored by Yipeng Zou's avatar Yipeng Zou Committed by Steven Rostedt (Google)

tracing: kprobe: Make gen test module work in arm and riscv

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.

Link: https://lkml.kernel.org/r/20220919125629.238242-3-zouyipeng@huawei.com

Cc: <linux-riscv@lists.infradead.org>
Cc: <mingo@redhat.com>
Cc: <paul.walmsley@sifive.com>
Cc: <palmer@dabbelt.com>
Cc: <aou@eecs.berkeley.edu>
Cc: <zanussi@kernel.org>
Cc: <liaochang1@huawei.com>
Cc: <chris.zjh@huawei.com>
Fixes: 64836248 ("tracing: Add kprobe event command generation test module")
Signed-off-by: default avatarYipeng Zou <zouyipeng@huawei.com>
Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent ac48e189
...@@ -35,6 +35,45 @@ ...@@ -35,6 +35,45 @@
static struct trace_event_file *gen_kprobe_test; static struct trace_event_file *gen_kprobe_test;
static struct trace_event_file *gen_kretprobe_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 * Test to make sure we can create a kprobe event, then add more
* fields. * fields.
...@@ -58,14 +97,14 @@ static int __init test_gen_kprobe_cmd(void) ...@@ -58,14 +97,14 @@ static int __init test_gen_kprobe_cmd(void)
* fields. * fields.
*/ */
ret = kprobe_event_gen_cmd_start(&cmd, "gen_kprobe_test", ret = kprobe_event_gen_cmd_start(&cmd, "gen_kprobe_test",
"do_sys_open", KPROBE_GEN_TEST_FUNC,
"dfd=%ax", "filename=%dx"); KPROBE_GEN_TEST_ARG0, KPROBE_GEN_TEST_ARG1);
if (ret) if (ret)
goto free; goto free;
/* Use kprobe_event_add_fields to add the rest of the fields */ /* 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) if (ret)
goto free; goto free;
...@@ -128,7 +167,7 @@ static int __init test_gen_kretprobe_cmd(void) ...@@ -128,7 +167,7 @@ static int __init test_gen_kretprobe_cmd(void)
* Define the kretprobe event. * Define the kretprobe event.
*/ */
ret = kretprobe_event_gen_cmd_start(&cmd, "gen_kretprobe_test", ret = kretprobe_event_gen_cmd_start(&cmd, "gen_kretprobe_test",
"do_sys_open", KPROBE_GEN_TEST_FUNC,
"$retval"); "$retval");
if (ret) if (ret)
goto free; goto free;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment