linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/ftrace: Use readelf to find entry point in uprobe test
@ 2025-02-20 13:01 Heiko Carstens
  2025-02-26 17:13 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Heiko Carstens @ 2025-02-20 13:01 UTC (permalink / raw)
  To: Masami Hiramatsu, Shuah Khan, Steven Rostedt
  Cc: linux-kernel, linux-trace-kernel, linux-kselftest

The uprobe events test fails on s390, but also on x86 (Fedora 41). The
problem appears to be that there is an assumption that adding a uprobe to
the beginning of the executable mapping of /bin/sh is sufficient to trigger
a uprobe event when /bin/sh is executed.

This assumption is not necessarily true. Therefore use "readelf -h" to find
the entry point address of /bin/sh and use this address when adding the
uprobe event.

This adds a dependency to readelf which is not always installed. Therefore
add a check and exit with exit_unresolved if it is not installed.

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
 .../ftrace/test.d/dynevent/add_remove_uprobe.tc        | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc
index 86c76679c56e..f2048c244526 100644
--- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc
+++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc
@@ -3,14 +3,18 @@
 # description: Generic dynamic event - add/remove/test uprobe events
 # requires: uprobe_events
 
+if ! which readelf > /dev/null 2>&1 ; then
+  echo "No readelf found. skipped."
+  exit_unresolved
+fi
+
 echo 0 > events/enable
 echo > dynamic_events
 
 REALBIN=`readlink -f /bin/sh`
+ENTRYPOINT=`readelf -h ${REALBIN} | grep Entry | sed -e 's/[^0]*//'`
 
-echo 'cat /proc/$$/maps' | /bin/sh | \
-	grep "r-xp .*${REALBIN}$" | \
-	awk '{printf "p:myevent %s:0x%s\n", $6,$3 }' >> uprobe_events
+echo "p:myevent ${REALBIN}:${ENTRYPOINT}" >> uprobe_events
 
 grep -q myevent uprobe_events
 test -d events/uprobes/myevent
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/ftrace: Use readelf to find entry point in uprobe test
  2025-02-20 13:01 [PATCH] selftests/ftrace: Use readelf to find entry point in uprobe test Heiko Carstens
@ 2025-02-26 17:13 ` Steven Rostedt
  2025-02-26 20:55   ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2025-02-26 17:13 UTC (permalink / raw)
  To: Heiko Carstens
  Cc: Masami Hiramatsu, Shuah Khan, linux-kernel, linux-trace-kernel,
	linux-kselftest, Shuah Khan

On Thu, 20 Feb 2025 14:01:02 +0100
Heiko Carstens <hca@linux.ibm.com> wrote:

> The uprobe events test fails on s390, but also on x86 (Fedora 41). The
> problem appears to be that there is an assumption that adding a uprobe to
> the beginning of the executable mapping of /bin/sh is sufficient to trigger
> a uprobe event when /bin/sh is executed.
> 
> This assumption is not necessarily true. Therefore use "readelf -h" to find
> the entry point address of /bin/sh and use this address when adding the
> uprobe event.
> 
> This adds a dependency to readelf which is not always installed. Therefore
> add a check and exit with exit_unresolved if it is not installed.
> 
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>

Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Shuah,

Can you take this in your tree?

-- Steve

> ---
>  .../ftrace/test.d/dynevent/add_remove_uprobe.tc        | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc
> index 86c76679c56e..f2048c244526 100644
> --- a/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc
> +++ b/tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc
> @@ -3,14 +3,18 @@
>  # description: Generic dynamic event - add/remove/test uprobe events
>  # requires: uprobe_events
>  
> +if ! which readelf > /dev/null 2>&1 ; then
> +  echo "No readelf found. skipped."
> +  exit_unresolved
> +fi
> +
>  echo 0 > events/enable
>  echo > dynamic_events
>  
>  REALBIN=`readlink -f /bin/sh`
> +ENTRYPOINT=`readelf -h ${REALBIN} | grep Entry | sed -e 's/[^0]*//'`
>  
> -echo 'cat /proc/$$/maps' | /bin/sh | \
> -	grep "r-xp .*${REALBIN}$" | \
> -	awk '{printf "p:myevent %s:0x%s\n", $6,$3 }' >> uprobe_events
> +echo "p:myevent ${REALBIN}:${ENTRYPOINT}" >> uprobe_events
>  
>  grep -q myevent uprobe_events
>  test -d events/uprobes/myevent


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/ftrace: Use readelf to find entry point in uprobe test
  2025-02-26 17:13 ` Steven Rostedt
@ 2025-02-26 20:55   ` Shuah Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2025-02-26 20:55 UTC (permalink / raw)
  To: Steven Rostedt, Heiko Carstens
  Cc: Masami Hiramatsu, Shuah Khan, linux-kernel, linux-trace-kernel,
	linux-kselftest, Shuah Khan

On 2/26/25 10:13, Steven Rostedt wrote:
> On Thu, 20 Feb 2025 14:01:02 +0100
> Heiko Carstens <hca@linux.ibm.com> wrote:
> 
>> The uprobe events test fails on s390, but also on x86 (Fedora 41). The
>> problem appears to be that there is an assumption that adding a uprobe to
>> the beginning of the executable mapping of /bin/sh is sufficient to trigger
>> a uprobe event when /bin/sh is executed.
>>
>> This assumption is not necessarily true. Therefore use "readelf -h" to find
>> the entry point address of /bin/sh and use this address when adding the
>> uprobe event.
>>
>> This adds a dependency to readelf which is not always installed. Therefore
>> add a check and exit with exit_unresolved if it is not installed.
>>
>> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> 
> Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> 
> Shuah,
> 
> Can you take this in your tree?
> 
> -- Steve

Applied to linux_kselftest next for Linux 6.15-rc1.

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-26 20:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-20 13:01 [PATCH] selftests/ftrace: Use readelf to find entry point in uprobe test Heiko Carstens
2025-02-26 17:13 ` Steven Rostedt
2025-02-26 20:55   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).