Skip to content

Commit eee3614

Browse files
ChaitanayaKulkarnikawasaki
authored andcommitted
blktrace: add blktrace ftrace corruption regression test
Add regression test for blktrace ftrace corruption bug that occurs when sysfs trace is enabled followed by ftrace blk tracer. When /sys/block/*/trace/enable is enabled and then ftrace's blk tracer is activated, the trace output becomes corrupted showing "Unknown action" with invalid hex values instead of proper action codes. The root cause is that ftrace allocates a blk_io_trace2 buffer (64 bytes) but calls record_blktrace_event() which writes v1 format (48 bytes), causing field offset mismatches and corruption. This test verifies that the trace output is correct and doesn't show the corruption pattern. This test confirms the fix by the kernel patch: commit e48886b9d668d80be24e37345bd0904e9138473c Author: Chaitanya Kulkarni <[email protected]> Date: Mon Oct 27 22:50:42 2025 -0700 blktrace: for ftrace use correct trace format ver Link: https://lore.kernel.org/linux-block/[email protected]/ Signed-off-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 81a0338 commit eee3614

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

tests/blktrace/002

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-3.0+
3+
# Copyright (C) 2025 Chaitanya Kulkarni <[email protected]>
4+
#
5+
# Regression test for blktrace ftrace corruption bug when using sysfs
6+
# trace enable with ftrace blk tracer.
7+
#
8+
# Bug: When sysfs trace is enabled (/sys/block/*/trace/enable) and then
9+
# ftrace blk tracer is enabled, the trace output becomes corrupted showing
10+
# "Unknown action" with invalid hex values.
11+
#
12+
# Root cause: ftrace allocated blk_io_trace2 buffer (64 bytes) but called
13+
# record_blktrace_event() which writes v1 format (48 bytes), causing field
14+
# offset mismatches and corruption.
15+
16+
. tests/blktrace/rc
17+
. common/null_blk
18+
19+
DESCRIPTION="blktrace ftrace corruption with sysfs trace"
20+
QUICK=1
21+
22+
requires() {
23+
_have_null_blk
24+
_have_tracefs
25+
}
26+
27+
test() {
28+
echo "Running ${TEST_NAME}"
29+
30+
local trace_dir="/sys/kernel/debug/tracing"
31+
local device
32+
33+
# Initialize null_blk with one device
34+
if ! _configure_null_blk nullb1 power=1; then
35+
return 1
36+
fi
37+
38+
device=/dev/nullb1
39+
40+
# Verify device exists
41+
if [[ ! -b "$device" ]]; then
42+
echo "Device $device not found"
43+
_exit_null_blk
44+
return 1
45+
fi
46+
47+
# Clean up any previous trace state
48+
echo 0 > "$trace_dir/tracing_on" 2>/dev/null
49+
echo > "$trace_dir/trace" 2>/dev/null
50+
echo nop > "$trace_dir/current_tracer" 2>/dev/null
51+
52+
# Enable sysfs trace for nullb1 (this triggers the bug path)
53+
if [[ -f /sys/block/nullb1/trace/enable ]]; then
54+
echo 1 > /sys/block/nullb1/trace/enable
55+
else
56+
echo "No sysfs trace support"
57+
_exit_null_blk
58+
return 1
59+
fi
60+
61+
# Enable blk ftrace tracer
62+
echo blk > "$trace_dir/current_tracer"
63+
echo 1 > "$trace_dir/tracing_on"
64+
65+
# Generate some I/O
66+
dd if="$device" of=/dev/null bs=4k count=10 iflag=direct >> "$FULL" 2>&1
67+
68+
# Stop tracing
69+
echo 0 > "$trace_dir/tracing_on"
70+
71+
# Check trace output for corruption
72+
# Get first 10 non-comment lines
73+
local trace_output
74+
trace_output=$(grep -v "^#" "$trace_dir/trace" | head -10)
75+
76+
if [[ -z "$trace_output" ]]; then
77+
echo "No trace output captured"
78+
_exit_null_blk
79+
return 1
80+
fi
81+
82+
# Check for "Unknown action" which indicates the bug
83+
if echo "$trace_output" | grep -q "Unknown action"; then
84+
echo "BUG: Trace corruption detected with 'Unknown action'"
85+
echo "$trace_output" | head -5 >> "$FULL"
86+
else
87+
echo "Trace output looks correct"
88+
fi
89+
90+
# Cleanup: disable sysfs trace
91+
echo 0 > /sys/block/nullb1/trace/enable 2>/dev/null
92+
echo nop > "$trace_dir/current_tracer" 2>/dev/null
93+
94+
_exit_null_blk
95+
96+
echo "Test complete"
97+
}

tests/blktrace/002.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Running blktrace/002
2+
Trace output looks correct
3+
Test complete

0 commit comments

Comments
 (0)