Skip to contentSkip to conversation

selftests/ftrace: Select an existing function in kprobe_eventname test

PATCH In review Steven Rostedt 3 participants 6 messages Mar 22, 2019 – Jul 9, 2019

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 selftests/ftrace: Select an existing function in kprobe_eventname test

From: Steven Rostedt (VMware) <[email protected]>

Running the ftrace selftests on the latest kernel caused the kprobe_eventname test to fail. It was due to the test that searches for a function with at "dot" in the name and adding a probe to that. Unfortunately, for this test, it picked:

optimize_nops.isra.2.cold.4

Which happens to be marked as "__init", which means it no longer exists in the kernel! (kallsyms keeps those function names around for tracing purposes)

As only functions that still exist are in the available_filter_functions file, as they are removed when the functions are freed at boot or module exit, have the test search for a function with ".isra." in the name as well as being in the available_filter_functions (if the file exists).

---

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc +15 -1
index 3fb70e01b1fe..3ff236719b6e 100644
@@ -24,7 +24,21 @@ test -d events/kprobes2/event2 || exit_failure
 
 :;: "Add an event on dot function without name" ;:
 
-FUNC=`grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "`
+find_dot_func() {
+	if [ ! -f available_filter_functions ]; then
+		grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "
+		return;
+	fi
+
+	grep " [tT] .*\.isra\..*" /proc/kallsyms | cut -f 3 -d " " | while read f; do
+		if grep -s $f available_filter_functions; then
+			echo $f
+			break
+		fi
+	done
+}
+
+FUNC=`find_dot_func | tail -n 1`
 [ "x" != "x$FUNC" ] || exit_unresolved
 echo "p $FUNC" > kprobe_events
 EVENT=`grep $FUNC kprobe_events | cut -f 1 -d " " | cut -f 2 -d:`
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · On Fri, 22 Mar 2019 15:09:23 -0400 Steven Rostedt <[email protected]> wrote:

From: Steven Rostedt (VMware) <[email protected]>

Running the ftrace selftests on the latest kernel caused the kprobe_eventname test to fail. It was due to the test that searches for a function with at "dot" in the name and adding a probe to that. Unfortunately, for this test, it picked:

optimize_nops.isra.2.cold.4

Which happens to be marked as "__init", which means it no longer exists in the kernel! (kallsyms keeps those function names around for tracing purposes)

Quoted 5 lines

As only functions that still exist are in the available_filter_functions file, as they are removed when the functions are freed at boot or module exit, have the test search for a function with ".isra." in the name as well as being in the available_filter_functions (if the file exists).

OK, this looks good to me.

Thank you,

Quoted 30 lines

---

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc +15 -1
index 3fb70e01b1fe..3ff236719b6e 100644
@@ -24,7 +24,21 @@ test -d events/kprobes2/event2 || exit_failure
 
 :;: "Add an event on dot function without name" ;:
 
-FUNC=`grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "`
+find_dot_func() {
+	if [ ! -f available_filter_functions ]; then
+		grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "
+		return;
+	fi
+
+	grep " [tT] .*\.isra\..*" /proc/kallsyms | cut -f 3 -d " " | while read f; do
+		if grep -s $f available_filter_functions; then
+			echo $f
+			break
+		fi
+	done
+}
+
+FUNC=`find_dot_func | tail -n 1`
 [ "x" != "x$FUNC" ] || exit_unresolved
 echo "p $FUNC" > kprobe_events
 EVENT=`grep $FUNC kprobe_events | cut -f 1 -d " " | cut -f 2 -d:`
Signature · 1 line
Masami Hiramatsu <[email protected]>
Tested-by on v1 1/1
#2 lore raw
In reply to Steven Rostedt
Quoted 13 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

Running the ftrace selftests on the latest kernel caused the kprobe_eventname test to fail. It was due to the test that searches for a function with at "dot" in the name and adding a probe to that. Unfortunately, for this test, it picked:

optimize_nops.isra.2.cold.4

Which happens to be marked as "__init", which means it no longer exists in the kernel! (kallsyms keeps those function names around for tracing purposes)

Quoted 6 lines

As only functions that still exist are in the available_filter_functions file, as they are removed when the functions are freed at boot or module exit, have the test search for a function with ".isra." in the name as well as being in the available_filter_functions (if the file exists).

This fixes a similar problem for me.

Quoted 29 lines

---

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc +15 -1
index 3fb70e01b1fe..3ff236719b6e 100644
@@ -24,7 +24,21 @@ test -d events/kprobes2/event2 || exit_failure
 
 :;: "Add an event on dot function without name" ;:
 
-FUNC=`grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "`
+find_dot_func() {
+	if [ ! -f available_filter_functions ]; then
+		grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "
+		return;
+	fi
+
+	grep " [tT] .*\.isra\..*" /proc/kallsyms | cut -f 3 -d " " | while read f; do
+		if grep -s $f available_filter_functions; then
+			echo $f
+			break
+		fi
+	done
+}
+
+FUNC=`find_dot_func | tail -n 1`
 [ "x" != "x$FUNC" ] || exit_unresolved
 echo "p $FUNC" > kprobe_events
 EVENT=`grep $FUNC kprobe_events | cut -f 1 -d " " | cut -f 2 -d:`
author maintainer
#3 lore raw
Quoted 21 lines · On Mon, 8 Jul 2019 16:10:29 -0300 Thadeu Lima de Souza Cascardo…
Quoted 13 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

Running the ftrace selftests on the latest kernel caused the kprobe_eventname test to fail. It was due to the test that searches for a function with at "dot" in the name and adding a probe to that. Unfortunately, for this test, it picked:

optimize_nops.isra.2.cold.4

Which happens to be marked as "__init", which means it no longer exists in the kernel! (kallsyms keeps those function names around for tracing purposes)

Quoted 6 lines

As only functions that still exist are in the available_filter_functions file, as they are removed when the functions are freed at boot or module exit, have the test search for a function with ".isra." in the name as well as being in the available_filter_functions (if the file exists).

Quoted 3 lines

This fixes a similar problem for me.

Masami, can you ack this, and Shuah, can you take it?

Thanks!

-- Steve

Quoted 30 lines
Quoted 30 lines

---

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc +15 -1
index 3fb70e01b1fe..3ff236719b6e 100644
@@ -24,7 +24,21 @@ test -d events/kprobes2/event2 || exit_failure
 
 :;: "Add an event on dot function without name" ;:
 
-FUNC=`grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "`
+find_dot_func() {
+	if [ ! -f available_filter_functions ]; then
+		grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "
+		return;
+	fi
+
+	grep " [tT] .*\.isra\..*" /proc/kallsyms | cut -f 3 -d " " | while read f; do
+		if grep -s $f available_filter_functions; then
+			echo $f
+			break
+		fi
+	done
+}
+
+FUNC=`find_dot_func | tail -n 1`
 [ "x" != "x$FUNC" ] || exit_unresolved
 echo "p $FUNC" > kprobe_events
 EVENT=`grep $FUNC kprobe_events | cut -f 1 -d " " | cut -f 2 -d:`  
maintainer Acked-by
#4 lore raw
Quoted 11 lines · On Mon, 8 Jul 2019 15:22:14 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 8 lines · On Mon, 8 Jul 2019 16:10:29 -0300 Thadeu Lima de Souza Cascardo…
Quoted 7 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

Running the ftrace selftests on the latest kernel caused the kprobe_eventname test to fail. It was due to the test that searches for a function with at "dot" in the name and adding a probe to that. Unfortunately, for this test, it picked:

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

optimize_nops.isra.2.cold.4

Which happens to be marked as "__init", which means it no longer exists in the kernel! (kallsyms keeps those function names around for tracing purposes)

Ouch!

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

As only functions that still exist are in the available_filter_functions file, as they are removed when the functions are freed at boot or module exit, have the test search for a function with ".isra." in the name as well as being in the available_filter_functions (if the file exists).

Hmm, OK. But I think this eventually fixed in kallsyms, by something like having [GONE] or [__init] flag for such symbols.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

This fixes a similar problem for me.

Masami, can you ack this, and Shuah, can you take it?

Yeah anyway,

Thank you!

Quoted 36 lines

Thanks!

-- Steve

Quoted 30 lines
Quoted 30 lines

---

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc +15 -1
index 3fb70e01b1fe..3ff236719b6e 100644
@@ -24,7 +24,21 @@ test -d events/kprobes2/event2 || exit_failure
 
 :;: "Add an event on dot function without name" ;:
 
-FUNC=`grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "`
+find_dot_func() {
+	if [ ! -f available_filter_functions ]; then
+		grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "
+		return;
+	fi
+
+	grep " [tT] .*\.isra\..*" /proc/kallsyms | cut -f 3 -d " " | while read f; do
+		if grep -s $f available_filter_functions; then
+			echo $f
+			break
+		fi
+	done
+}
+
+FUNC=`find_dot_func | tail -n 1`
 [ "x" != "x$FUNC" ] || exit_unresolved
 echo "p $FUNC" > kprobe_events
 EVENT=`grep $FUNC kprobe_events | cut -f 1 -d " " | cut -f 2 -d:`  
Signature · 1 line
Masami Hiramatsu <[email protected]>