Skip to content

Commit 42a3cd5

Browse files
committed
kprobe: Update stack trace checker to accommodate kernel 6.18+ changes
Signed-off-by: Tam Mach <tam.mach@cilium.io>
1 parent c30f157 commit 42a3cd5

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

pkg/sensors/tracing/kprobe_test.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5272,27 +5272,46 @@ spec: ` + disableKprobeMulti + `
52725272
t.Fatalf("failed to run %s: %s", unameBin, err)
52735273
}
52745274

5275+
// We check that the stack trace is enabled, works and exports something coherent.
5276+
// Stack traces look different on different archs and kernel versions.
5277+
//
5278+
// On kernel 6.18+, the probed function (sys_newuname) may not appear
5279+
// in the stack trace. Instead, the stack trace starts from the syscall
5280+
// entry point. This could be a regression due to the below commit.
5281+
// 6d08340d1e35 Revert "perf/x86: Always store regs->ip in perf_callchain_kernel()"
5282+
//
5283+
// syscall /usr/bin/uname __x64_sys_newuname (pre-6.18)
5284+
// 0x0: __x64_sys_newuname+0x5
5285+
// 0x0: entry_SYSCALL_64_after_hwframe+0x72
5286+
//
5287+
// syscall /usr/bin/uname __x64_sys_newuname (6.18+)
5288+
// 0x0: entry_SYSCALL_64_after_hwframe+0x72
5289+
//
5290+
// syscall /usr/bin/uname __arm64_sys_newuname
5291+
// 0x0: __do_sys_newuname+0x2f0
5292+
// 0x0: el0_svc_common.constprop.0+0x180
5293+
// 0x0: do_el0_svc+0x30
5294+
// 0x0: el0_svc+0x48
5295+
// 0x0: el0t_64_sync_handler+0xa4
5296+
// 0x0: el0t_64_sync+0x1a4
5297+
var symbolMatcher *sm.StringMatcher
5298+
if kernels.MinKernelVersion("6.18") {
5299+
// On 6.18+ x86, the probed function may not appear due to perf_callchain_kernel() changes
5300+
// Check for syscall entry points instead
5301+
if isArm() {
5302+
symbolMatcher = sm.Prefix("el0_svc")
5303+
} else {
5304+
symbolMatcher = sm.Prefix("entry_SYSCALL_64")
5305+
}
5306+
} else {
5307+
symbolMatcher = sm.Suffix("sys_newuname")
5308+
}
5309+
52755310
stackTraceChecker := ec.NewProcessKprobeChecker("kernel-stack-trace").
52765311
WithProcess(ec.NewProcessChecker().WithBinary(sm.Full(unameBin))).
52775312
WithKernelStackTrace(ec.NewStackTraceEntryListMatcher().WithValues(
5278-
ec.NewStackTraceEntryChecker().WithSymbol(sm.Suffix(("sys_newuname"))),
5279-
// we could technically check for more but stack traces look
5280-
// different on different archs, at least we check that the stack
5281-
// trace is enabled, works and exports something coherent
5282-
//
5283-
// syscall /usr/bin/uname __x64_sys_newuname
5284-
// 0x0: __x64_sys_newuname+0x5
5285-
// 0x0: entry_SYSCALL_64_after_hwframe+0x72
5286-
//
5287-
// syscall /usr/bin/uname __arm64_sys_newuname
5288-
// 0x0: __do_sys_newuname+0x2f0
5289-
// 0x0: el0_svc_common.constprop.0+0x180
5290-
// 0x0: do_el0_svc+0x30
5291-
// 0x0: el0_svc+0x48
5292-
// 0x0: el0t_64_sync_handler+0xa4
5293-
// 0x0: el0t_64_sync+0x1a4
5313+
ec.NewStackTraceEntryChecker().WithSymbol(symbolMatcher),
52945314
))
5295-
52965315
checker := ec.NewUnorderedEventChecker(stackTraceChecker)
52975316
err = jsonchecker.JsonTestCheck(t, checker)
52985317
require.NoError(t, err)

0 commit comments

Comments
 (0)