Skip to contentSkip to conversation

test: Allow more variations in expected fbt kernel stacks

PATCH In review [email protected] 2 participants 4 messages Feb 8, 2025 – Feb 28, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 test: Allow more variations in expected fbt kernel stacks

From: Eugene Loh <[email protected]>

This test checks the call stack upon entry to vfs_write(). Unfortunately, these checks require some maintenance since the call stack can vary -- slightly or greatly -- depending on processor or kernel. There is a competition between ease of test maintenance and strictness of correctness checks.

Adapt post processing of output to allow new variations in stacks seen in UEK 8 (currently Linux 6.12).

Orabug: 37459289

---
 test/unittest/stack/tst.stack_fbt.sh | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
test/unittest/stack/tst.stack_fbt.sh +12 -3
index c365e14d6..8a0b7999c 100755
@@ -37,9 +37,18 @@ if [ $? -ne 0 ]; then
 	exit 1
 fi
 
-# Strip out blank lines and pointer values.
-
-awk 'NF != 0 { sub(/+0x[0-9a-f]*$/, "+{ptr}"); print }' dtrace.out > dtrace.post
+# Strip out
+# - blank lines
+# - "constprop"
+# - "isra"
+# - "_after_hwframe"    (x86 starting with UEK8)
+# - pointer values
+
+awk 'NF != 0 { sub("\\.constprop\\.[0-9]", "");
+               sub("\\.isra\\.[0-9]", "");
+               sub("_after_hwframe\\+", "+");
+               sub(/+0x[0-9a-f]*$/, "+{ptr}");
+               print }' dtrace.out > dtrace.post
 if [ $? -ne 0 ]; then
 	echo ERROR: awk failed
 	cat dtrace.out
Signature · 1 line
2.43.5
#1 lore raw

PATCH 2/2 test: Account for pid:::entry ustack() being correct

From: Eugene Loh <[email protected]>

The pid:::entry uprobe fires so early in the function preamble that the frame pointer is not yet set and the caller is not (yet) correctly identified. In Linux 6.11, x86-specific heuristics address this problem.

Post process results from this test to accommodate both cases -- missing caller and not missing caller.

Orabug: 37459289

---
 test/unittest/ustack/tst.ustack25_pid.r   |  1 +
 test/unittest/ustack/tst.ustack25_pid.r.p | 37 +++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100755 test/unittest/ustack/tst.ustack25_pid.r.p
test/unittest/ustack/tst.ustack25_pid.r +1 -0
index 89b35c028..e7732fb81 100644
@@ -1,5 +1,6 @@
 
               ustack-tst-basic`myfunc_z
+              ustack-tst-basic`myfunc_y+{ptr}
               ustack-tst-basic`myfunc_x+{ptr}
               ustack-tst-basic`myfunc_w+{ptr}
               ustack-tst-basic`myfunc_v+{ptr}
test/unittest/ustack/tst.ustack25_pid.r.p new file +37 -0
new file mode 100755
index 000000000..6486f7ec6
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# A pid entry probe places a uprobe on the first instruction of a function.
+# Unfortunately, this is so early in the function preamble that the function
+# frame pointer has not yet been established and the actual caller of the
+# traced function is missed.
+#
+# In Linux 6.11, x86-specific heuristics are introduced to fix this problem.
+# See commit cfa7f3d
+# ("perf,x86: avoid missing caller address in stack traces captured in uprobe")
+# for both a description of the problem and an explanation of the heuristics.
+#
+# Add post processing to these test results to allow for both cases:
+# caller frame is missing or not missing.
+
+missing_caller=1
+if [ $(uname -m) == "x86_64" ]; then
+        read MAJOR MINOR <<< `uname -r | grep -Eo '^[0-9]+\.[0-9]+' | tr '.' ' '`
+
+        if [ $MAJOR -ge 6 ]; then
+                if [ $MAJOR -gt 6 -o $MINOR -ge 11 ]; then
+                        missing_caller=0
+                fi
+        fi
+fi
+
+if [ $missing_caller -eq 1 ]; then
+        # Add the missing caller function after the current function.
+        awk '{ print }
+             /myfunc_z/ { print "              ustack-tst-basic`myfunc_y+{ptr}" }'
+else
+        # The .r results file has an extra frame at the end in case
+        # the caller frame is missing and the 25-frame limit goes
+        # "too far."  If the caller is not missing, fake that extra frame.
+        awk '{ print }
+             /myfunc_b/ { print "              ustack-tst-basic`myfunc_a+{ptr}" }'
+fi
Signature · 1 line
2.43.5
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] test: Account for pid:::entry ustack() being correct

Quoted 7 lines · On Sat, Feb 08, 2025 at 06:21:06PM -0500, [email protected] wrote:

From: Eugene Loh <[email protected]>

The pid:::entry uprobe fires so early in the function preamble that the frame pointer is not yet set and the caller is not (yet) correctly identified. In Linux 6.11, x86-specific heuristics address this problem.

Quoted 5 lines

Post process results from this test to accommodate both cases -- missing caller and not missing caller.

Orabug: 37459289

Quoted 63 lines
---
 test/unittest/ustack/tst.ustack25_pid.r   |  1 +
 test/unittest/ustack/tst.ustack25_pid.r.p | 37 +++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100755 test/unittest/ustack/tst.ustack25_pid.r.p
test/unittest/ustack/tst.ustack25_pid.r +1 -0
index 89b35c028..e7732fb81 100644
@@ -1,5 +1,6 @@
 
               ustack-tst-basic`myfunc_z
+              ustack-tst-basic`myfunc_y+{ptr}
               ustack-tst-basic`myfunc_x+{ptr}
               ustack-tst-basic`myfunc_w+{ptr}
               ustack-tst-basic`myfunc_v+{ptr}
test/unittest/ustack/tst.ustack25_pid.r.p new file +37 -0
new file mode 100755
index 000000000..6486f7ec6
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# A pid entry probe places a uprobe on the first instruction of a function.
+# Unfortunately, this is so early in the function preamble that the function
+# frame pointer has not yet been established and the actual caller of the
+# traced function is missed.
+#
+# In Linux 6.11, x86-specific heuristics are introduced to fix this problem.
+# See commit cfa7f3d
+# ("perf,x86: avoid missing caller address in stack traces captured in uprobe")
+# for both a description of the problem and an explanation of the heuristics.
+#
+# Add post processing to these test results to allow for both cases:
+# caller frame is missing or not missing.
+
+missing_caller=1
+if [ $(uname -m) == "x86_64" ]; then
+        read MAJOR MINOR <<< `uname -r | grep -Eo '^[0-9]+\.[0-9]+' | tr '.' ' '`
+
+        if [ $MAJOR -ge 6 ]; then
+                if [ $MAJOR -gt 6 -o $MINOR -ge 11 ]; then
+                        missing_caller=0
+                fi
+        fi
+fi
+
+if [ $missing_caller -eq 1 ]; then
+        # Add the missing caller function after the current function.
+        awk '{ print }
+             /myfunc_z/ { print "              ustack-tst-basic`myfunc_y+{ptr}" }'
+else
+        # The .r results file has an extra frame at the end in case
+        # the caller frame is missing and the 25-frame limit goes
+        # "too far."  If the caller is not missing, fake that extra frame.
+        awk '{ print }
+             /myfunc_b/ { print "              ustack-tst-basic`myfunc_a+{ptr}" }'
+fi
Signature · 1 line
2.43.5
Reviewed-by on v1 1/2
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Sat, Feb 08, 2025 at 06:21:05PM -0500, [email protected] wrote:

From: Eugene Loh <[email protected]>

This test checks the call stack upon entry to vfs_write(). Unfortunately, these checks require some maintenance since the call stack can vary -- slightly or greatly -- depending on processor or kernel. There is a competition between ease of test maintenance and strictness of correctness checks.

Quoted 5 lines

Adapt post processing of output to allow new variations in stacks seen in UEK 8 (currently Linux 6.12).

Orabug: 37459289

Quoted 33 lines
---
 test/unittest/stack/tst.stack_fbt.sh | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
test/unittest/stack/tst.stack_fbt.sh +12 -3
index c365e14d6..8a0b7999c 100755
@@ -37,9 +37,18 @@ if [ $? -ne 0 ]; then
 	exit 1
 fi
 
-# Strip out blank lines and pointer values.
-
-awk 'NF != 0 { sub(/+0x[0-9a-f]*$/, "+{ptr}"); print }' dtrace.out > dtrace.post
+# Strip out
+# - blank lines
+# - "constprop"
+# - "isra"
+# - "_after_hwframe"    (x86 starting with UEK8)
+# - pointer values
+
+awk 'NF != 0 { sub("\\.constprop\\.[0-9]", "");
+               sub("\\.isra\\.[0-9]", "");
+               sub("_after_hwframe\\+", "+");
+               sub(/+0x[0-9a-f]*$/, "+{ptr}");
+               print }' dtrace.out > dtrace.post
 if [ $? -ne 0 ]; then
 	echo ERROR: awk failed
 	cat dtrace.out
Signature · 1 line
2.43.5