Skip to contentSkip to conversation

selftests/ftrace: check for do_sys_openat2 in user-memory test

PATCH Superseded Colin King 3 participants 7 messages Oct 1, 2020 – Oct 2, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 selftests/ftrace: check for do_sys_openat2 in user-memory test

From: Colin Ian King <[email protected]>

More recent libc implementations are now using openat/openat2 system calls so also add do_sys_openat2 to the tracing so that the test passes on these systems because do_sys_open may not be called.

---
 .../testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc  | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +2 -0
index a30a9c07290d..cf1b4c3e9e6b 100644
@@ -9,6 +9,8 @@ grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported
 :;: "user-memory access syntax and ustring working on user memory";:
 echo 'p:myevent do_sys_open path=+0($arg2):ustring path2=+u0($arg2):string' \
 	> kprobe_events
+echo 'p:myevent2 do_sys_openat2 path=+0($arg2):ustring path2=+u0($arg2):string' \
+	> kprobe_events
 
 grep myevent kprobe_events | \
 	grep -q 'path=+0($arg2):ustring path2=+u0($arg2):string'
Signature · 1 line
2.27.0
maintainer
#1 lore raw
Quoted 16 lines · On Thu, 1 Oct 2020 09:56:41 +0100 Colin King <[email protected]> wrote:

From: Colin Ian King <[email protected]>

More recent libc implementations are now using openat/openat2 system calls so also add do_sys_openat2 to the tracing so that the test passes on these systems because do_sys_open may not be called.

---
 .../testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc  | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
index a30a9c07290d..cf1b4c3e9e6b 100644

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported · line 14

Quoted 6 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +2 -0
@@ -9,6 +9,8 @@ grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported
 :;: "user-memory access syntax and ustring working on user memory";:
 echo 'p:myevent do_sys_open path=+0($arg2):ustring path2=+u0($arg2):string' \
 	> kprobe_events  
+echo 'p:myevent2 do_sys_openat2 path=+0($arg2):ustring path2=+u0($arg2):string' \
+	> kprobe_events
 

This still wont work, because the rest of the code only enables the myevent event, and not the one you just added.

Did you see this broken before, and this patch fixes it?

-- Steve

Quoted 2 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
 grep myevent kprobe_events | \
 	grep -q 'path=+0($arg2):ustring path2=+u0($arg2):string'
#2 lore raw
Quoted 14 lines · Steven Rostedt
Quoted 11 lines · On Thu, 1 Oct 2020 09:56:41 +0100 Colin King <[email protected]> wrote:

From: Colin Ian King <[email protected]>

More recent libc implementations are now using openat/openat2 system calls so also add do_sys_openat2 to the tracing so that the test passes on these systems because do_sys_open may not be called.

---
 .../testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc  | 2 ++
 1 file changed, 2 insertions(+)
Quoted 14 lines

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported · line 14

Quoted 11 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +2 -0
index a30a9c07290d..cf1b4c3e9e6b 100644
@@ -9,6 +9,8 @@ grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported
 :;: "user-memory access syntax and ustring working on user memory";:
 echo 'p:myevent do_sys_open path=+0($arg2):ustring path2=+u0($arg2):string' \
 	> kprobe_events  
+echo 'p:myevent2 do_sys_openat2 path=+0($arg2):ustring path2=+u0($arg2):string' \
+	> kprobe_events
 

This still wont work, because the rest of the code only enables the myevent event, and not the one you just added.

Yep, I botched this and tested the wrong fix.

Quoted 2 lines

Did you see this broken before, and this patch fixes it?

So this test breaks with a recent libc and support tools built against libc. I believe the do_sys_open is not being detected because do_sys_openat2 is being called instead.

Not sure now of the correct way to fix this.

Quoted 7 lines

-- Steve

Quoted 2 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
 grep myevent kprobe_events | \
 	grep -q 'path=+0($arg2):ustring path2=+u0($arg2):string'
maintainer
#3 lore raw
Quoted 5 lines · On Thu, 1 Oct 2020 16:40:33 +0100 Colin Ian King <[email protected]>…

So this test breaks with a recent libc and support tools built against libc. I believe the do_sys_open is not being detected because do_sys_openat2 is being called instead.

Not sure now of the correct way to fix this.

Perhaps by enabling both events?

-- Steve

maintainer
#4 lore raw
In reply to Colin Ian King
Quoted 33 lines · On Thu, 1 Oct 2020 16:40:33 +0100 Colin Ian King <[email protected]>…
Quoted 14 lines · Steven Rostedt
Quoted 11 lines · On Thu, 1 Oct 2020 09:56:41 +0100 Colin King <[email protected]> wrote:

From: Colin Ian King <[email protected]>

More recent libc implementations are now using openat/openat2 system calls so also add do_sys_openat2 to the tracing so that the test passes on these systems because do_sys_open may not be called.

---
 .../testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc  | 2 ++
 1 file changed, 2 insertions(+)
Quoted 14 lines

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported · line 14

Quoted 11 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +2 -0
index a30a9c07290d..cf1b4c3e9e6b 100644
@@ -9,6 +9,8 @@ grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported
 :;: "user-memory access syntax and ustring working on user memory";:
 echo 'p:myevent do_sys_open path=+0($arg2):ustring path2=+u0($arg2):string' \
 	> kprobe_events  
+echo 'p:myevent2 do_sys_openat2 path=+0($arg2):ustring path2=+u0($arg2):string' \
+	> kprobe_events
 

This still wont work, because the rest of the code only enables the myevent event, and not the one you just added.

Yep, I botched this and tested the wrong fix.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

Did you see this broken before, and this patch fixes it?

So this test breaks with a recent libc and support tools built against libc. I believe the do_sys_open is not being detected because do_sys_openat2 is being called instead.

Not sure now of the correct way to fix this.

Hmm, this actually just try to catch the user-string. So the another function which accepts any user-string, is OK.
Let me try to use another one.

Thank you for reporting!

Quoted 9 lines
Quoted 8 lines

-- Steve

Quoted 2 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
 grep myevent kprobe_events | \
 	grep -q 'path=+0($arg2):ustring path2=+u0($arg2):string'
Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#5 lore raw
In reply to Colin King
Quoted 16 lines · On Thu, 1 Oct 2020 09:56:41 +0100 Colin King <[email protected]> wrote:

From: Colin Ian King <[email protected]>

More recent libc implementations are now using openat/openat2 system calls so also add do_sys_openat2 to the tracing so that the test passes on these systems because do_sys_open may not be called.

---
 .../testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc  | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
index a30a9c07290d..cf1b4c3e9e6b 100644

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported · line 11

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
@@ -9,6 +9,8 @@ grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported
 :;: "user-memory access syntax and ustring working on user memory";:
 echo 'p:myevent do_sys_open path=+0($arg2):ustring path2=+u0($arg2):string' \
 	> kprobe_events

OK, at first, you need to check the kernel has do_sys_openat2 from /proc/kallsyms (grep -qw will help you), because it is new syscall.

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported · line 13

Quoted 2 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +2 -0
+echo 'p:myevent2 do_sys_openat2 path=+0($arg2):ustring path2=+u0($arg2):string' \
+	> kprobe_events

Also, you need to append (">>") it instead overwrite (">") to kprobe_events.

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported · line 16

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
 grep myevent kprobe_events | \
 	grep -q 'path=+0($arg2):ustring path2=+u0($arg2):string'

And also you have to enable both myevent and myevent2 (if exists) after this.

Then I think your patch will work correctly.

Thank you!

Signature · 1 line
Masami Hiramatsu <[email protected]>
#6 lore raw
Quoted 32 lines · Masami Hiramatsu
Quoted 16 lines · On Thu, 1 Oct 2020 09:56:41 +0100 Colin King <[email protected]> wrote:

From: Colin Ian King <[email protected]>

More recent libc implementations are now using openat/openat2 system calls so also add do_sys_openat2 to the tracing so that the test passes on these systems because do_sys_open may not be called.

---
 .../testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc  | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
index a30a9c07290d..cf1b4c3e9e6b 100644

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported · line 11

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +0 -0
@@ -9,6 +9,8 @@ grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported
 :;: "user-memory access syntax and ustring working on user memory";:
 echo 'p:myevent do_sys_open path=+0($arg2):ustring path2=+u0($arg2):string' \
 	> kprobe_events

OK, at first, you need to check the kernel has do_sys_openat2 from /proc/kallsyms (grep -qw will help you), because it is new syscall.

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc grep -A10 "fetcharg:" README | grep -q '\[u\]<offset>' || exit_unsupported · line 13

Quoted 2 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +2 -0
+echo 'p:myevent2 do_sys_openat2 path=+0($arg2):ustring path2=+u0($arg2):string' \
+	> kprobe_events

Also, you need to append (">>") it instead overwrite (">") to kprobe_events.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

grep myevent kprobe_events | \
grep -q 'path=+0($arg2):ustring path2=+u0($arg2):string'

And also you have to enable both myevent and myevent2 (if exists) after this.

Then I think your patch will work correctly.

Indeed, thanks. I'll send a V2 shortly.

Quoted 3 lines

Thank you!