diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-08-19 14:01:58 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-08-19 14:01:58 -0700 |
| commit | 00d66b29a66ce18e417a8436076c629d03186a27 (patch) | |
| tree | b4f5d8d1ea2734b61f866c4f00b13dea9161a8e8 /tools/testing | |
| parent | 3793b558ff3b1cae64a3eddb497ab9e5636bf022 (diff) | |
| parent | 88b3e7fedc07d940c32eb5c0733a780e944b6b47 (diff) | |
Merge tag 'ftrace-v7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull ftrace updates from Steven Rostedt:
- Deprecrate ftrace_enabled in disabling ftrace
The file /proc/sys/kernel/ftrace_enabled was created when ftrace was
first introduced back in 2008. It was to be a "kill switch" if
something was to go wrong. It was also used as a way to turn off
function tracing for the latency tracers that would have it on by
default. But in 2013 (Linux 3.10) the option "function-trace" was
introduced to disable function tracing for the latency tracers as the
"ftrace_enabled" file was considered too big of a hammer and caused
too many side effects.
When live kernel patching came along, disabling ftrace via the
ftrace_enabled file would put the system into an unstable state if a
live kernel patch was installed. This created the need to mark some
function hooks as "PERMANENT".
Now there's a need for BPF usage marked as PERMANENT for the same
reasons.
The file "ftrace_enabled" usage is no longer viable. It doesn't do
what it says it does and there is no reason to use it.
Make writing '0' to it a nop and print a message saying its usage is
deprecated. The return value of writing '0' is -EOPNOTSUPP so that
user space will error on that write (hopefully to inform any
developer that it no longer works).
Eventually the file should be removed completely, but for now just
making it not do anything is the path forward to that.
- Update the livepatch tests to handle ftrace_enabled being disabled
Because in the past, livepatch was broken by ftrace_enabled being
turned off, there's a test case that checks to make sure it still
doesn't break. But having the write of '0' return an error caused
that test to break. Updated the test to handle the new change.
* tag 'ftrace-v7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
selftests/livepatch: update test-ftrace.sh for deprecated ftrace_enabled
ftrace: deprecate disabling via ftrace_enabled sysctl
Diffstat (limited to 'tools/testing')
| -rw-r--r-- | tools/testing/selftests/livepatch/functions.sh | 14 | ||||
| -rwxr-xr-x | tools/testing/selftests/livepatch/test-ftrace.sh | 45 |
2 files changed, 42 insertions, 17 deletions
diff --git a/tools/testing/selftests/livepatch/functions.sh b/tools/testing/selftests/livepatch/functions.sh index 30dc677b2f45..a65b7b1ac8ad 100644 --- a/tools/testing/selftests/livepatch/functions.sh +++ b/tools/testing/selftests/livepatch/functions.sh @@ -126,6 +126,20 @@ function set_ftrace_enabled() { echo "livepatch: kernel.ftrace_enabled = $result" > /dev/kmsg } +# ftrace_disable_supported() - probe whether kernel.ftrace_enabled=0 +# can still disable ftrace on this kernel. Newer kernels deprecate +# the knob and always refuse the write with -EOPNOTSUPP. +function ftrace_disable_supported() { + local orig result + + orig=$(sysctl --values kernel.ftrace_enabled) + sysctl -q kernel.ftrace_enabled=0 &> /dev/null + result=$(sysctl --values kernel.ftrace_enabled) + sysctl -q "kernel.ftrace_enabled=$orig" &> /dev/null + + [[ "$result" == "0" ]] +} + function cleanup() { pop_config } diff --git a/tools/testing/selftests/livepatch/test-ftrace.sh b/tools/testing/selftests/livepatch/test-ftrace.sh index d2c3dea63104..cd27148510f8 100755 --- a/tools/testing/selftests/livepatch/test-ftrace.sh +++ b/tools/testing/selftests/livepatch/test-ftrace.sh @@ -12,29 +12,32 @@ setup_config # - turn ftrace_enabled OFF and verify livepatches can't load # - turn ftrace_enabled ON and verify livepatch can load # - verify that ftrace_enabled can't be turned OFF while a livepatch is loaded +# (skipped on kernels where the sysctl is deprecated and always refuses 0) start_test "livepatch interaction with ftrace_enabled sysctl" -set_ftrace_enabled 0 -load_failing_mod $MOD_LIVEPATCH +if ftrace_disable_supported; then -set_ftrace_enabled 1 -load_lp $MOD_LIVEPATCH -if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then - echo -e "FAIL\n\n" - die "livepatch kselftest(s) failed" -fi + set_ftrace_enabled 0 + load_failing_mod $MOD_LIVEPATCH -# Check that ftrace could not get disabled when a livepatch is enabled -set_ftrace_enabled --fail 0 -if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then - echo -e "FAIL\n\n" - die "livepatch kselftest(s) failed" -fi -disable_lp $MOD_LIVEPATCH -unload_lp $MOD_LIVEPATCH + set_ftrace_enabled 1 + load_lp $MOD_LIVEPATCH + if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then + echo -e "FAIL\n\n" + die "livepatch kselftest(s) failed" + fi -check_result "livepatch: kernel.ftrace_enabled = 0 + # Check that ftrace could not get disabled when a livepatch is enabled + set_ftrace_enabled --fail 0 + if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then + echo -e "FAIL\n\n" + die "livepatch kselftest(s) failed" + fi + disable_lp $MOD_LIVEPATCH + unload_lp $MOD_LIVEPATCH + + check_result "livepatch: kernel.ftrace_enabled = 0 % insmod test_modules/$MOD_LIVEPATCH.ko livepatch: enabling patch '$MOD_LIVEPATCH' livepatch: '$MOD_LIVEPATCH': initializing patching transition @@ -60,6 +63,14 @@ livepatch: '$MOD_LIVEPATCH': completing unpatching transition livepatch: '$MOD_LIVEPATCH': unpatching complete % rmmod $MOD_LIVEPATCH" +else + + set_ftrace_enabled --fail 0 + check_result "livepatch: sysctl: setting key \"kernel.ftrace_enabled\": \ +Operation not supported" + +fi + # - verify livepatch can load # - check if traces have a patched function |
