| 0/0 |
2026/08/31 20:45 |
flow |
patching |
1h25m
Results: map[AckedBy:[] Fixes:map[AuthorEmail:acme@redhat.com AuthorName:Arnaldo Carvalho de Melo Hash:5f3ea37c7716db4e894a480e0c18b24399595b6b Title:blktrace: port to tracepoints] KernelBranch:master KernelCommit:cee9395acd8043be0644b25c34bfa86623f2b935 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git PatchDescription:blktrace: handle tracepoint registration failures
In blk_register_tracepoints(), register_trace_*() functions are called with
WARN_ON(ret). Tracepoint registration allocates memory for probe arrays and
can legitimately fail with -ENOMEM under memory pressure. WARN_ON() must
not be used for conditions that can legitimately happen.
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints
kernel/trace/blktrace.c:1332 [inline]
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470
kernel/trace/blktrace.c:492
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
Furthermore, blk_register_tracepoints() ignores registration errors and
continues, leaving tracepoints in a partially registered state. When
blktrace is later stopped, blk_unregister_tracepoints() unconditionally
attempts to unregister all tracepoints, which fails with -ENOENT and
triggers an additional warning in tracepoint_remove_func().
Fix this by removing WARN_ON() and properly handling registration failures
in blk_register_tracepoints(). If any registration fails, unwinding is
performed by unregistering previously registered tracepoints in reverse
order, synchronizing tracepoint unregistration, and returning the error
code. In addition, propagate the error through get_probe_ref(),
blk_trace_setup_finalize(), and the setup entry points (blk_trace_setup(),
blk_trace_setup2(), compat_blk_trace_setup(), and blk_trace_setup_queue()),
properly cleaning up allocated resources on failure. PatchDiff:diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8cd2520b4..c2324298c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -60,7 +60,7 @@ static struct tracer_flags blk_tracer_flags = {
static DEFINE_MUTEX(blk_probe_mutex);
static int blk_probes_ref;
-static void blk_register_tracepoints(void);
+static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
@@ -485,12 +485,18 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
kfree(bt);
}
-static void get_probe_ref(void)
+static int get_probe_ref(void)
{
+ int ret = 0;
+
mutex_lock(&blk_probe_mutex);
- if (++blk_probes_ref == 1)
- blk_register_tracepoints();
+ if (++blk_probes_ref == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ blk_probes_ref--;
+ }
mutex_unlock(&blk_probe_mutex);
+ return ret;
}
static void put_probe_ref(void)
@@ -727,12 +733,14 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
return ERR_PTR(ret);
}
-static void blk_trace_setup_finalize(struct request_queue *q,
- char *name, int version,
- struct blk_trace *bt,
- struct blk_user_trace_setup2 *buts)
+static int blk_trace_setup_finalize(struct request_queue *q,
+ char *name, int version,
+ struct blk_trace *bt,
+ struct blk_user_trace_setup2 *buts)
{
+ int ret;
+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
@@ -755,8 +763,12 @@ static void blk_trace_setup_finalize(struct request_queue *q,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ ret = get_probe_ref();
+ if (ret)
+ return ret;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
+ return 0;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
@@ -792,7 +804,12 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags);
@@ -810,6 +827,7 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
@@ -827,7 +845,12 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
@@ -846,6 +869,7 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
@@ -869,7 +893,12 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
@@ -1324,49 +1353,108 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len)
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static void blk_register_tracepoints(void)
+static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_remap;
+
+ return 0;
+
+out_bio_remap:
+ unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
+out_split:
+ unregister_trace_block_split(blk_add_trace_split, NULL);
+out_unplug:
+ unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
+out_plug:
+ unregister_trace_block_plug(blk_add_trace_plug, NULL);
+out_zone_unplug:
+ unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
+out_zone_plug:
+ unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
+out_zone_update_request:
+ unregister_trace_blk_zone_append_update_request_bio(
+ blk_add_trace_zone_update_request, NULL);
+out_getrq:
+ unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
+out_bio_queue:
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
+out_bio_frontmerge:
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
+out_bio_backmerge:
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
+out_bio_complete:
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
+out_rq_complete:
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
+out_rq_requeue:
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
+out_rq_merge:
+ unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
+out_rq_issue:
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
+out_rq_insert:
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
+ tracepoint_synchronize_unregister();
+out:
+ return ret;
}
static void blk_unregister_tracepoints(void)
@@ -1916,8 +2004,11 @@ static int blk_trace_setup_queue(struct request_queue *q,
blk_trace_setup_lba(bt, bdev);
+ ret = get_probe_ref();
+ if (ret)
+ goto free_bt;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
return 0;
free_bt:
Recipients:[map[Email:axboe@kernel.dk Name:Jens Axboe To:true] map[Email:linux-block@vger.kernel.org Name: To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:linux-trace-kernel@vger.kernel.org Name: To:true] map[Email:mathieu.desnoyers@efficios.com Name:Mathieu Desnoyers To:false] map[Email:mhiramat@kernel.org Name:Masami Hiramatsu To:true] map[Email:rostedt@goodmis.org Name:Steven Rostedt To:true] map[Email:acme@redhat.com Name:Arnaldo Carvalho de Melo To:true]] ReportedBy:[] ReviewedBy:[] SuggestedBy:[] TestedBy:[]]
|
| 1/1 |
2026/08/31 20:45 |
action |
base-commit-picker |
0m
Results: map[KernelBranch:master KernelCommit:cee9395acd8043be0644b25c34bfa86623f2b935 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git]
|
| 2/1 |
2026/08/31 20:45 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static int inject_fault(int nth)
{
int fd;
fd = open("/proc/thread-self/fail-nth", O_RDWR);
if (fd == -1)
exit(1);
char buf[16];
sprintf(buf, "%d", nth);
if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf))
exit(1);
return fd;
}
static const char* setup_fault()
{
int fd = open("/proc/self/make-it-fail", O_WRONLY);
if (fd == -1)
return "CONFIG_FAULT_INJECTION is not enabled";
close(fd);
fd = open("/proc/thread-self/fail-nth", O_WRONLY);
if (fd == -1)
return "kernel does not have systematic fault injection support";
close(fd);
static struct {
const char* file;
const char* val;
bool fatal;
} files[] = {
{"/sys/kernel/debug/failslab/ignore-gfp-wait", "N", true},
{"/sys/kernel/debug/fail_futex/ignore-private", "N", false},
{"/sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem", "N", false},
{"/sys/kernel/debug/fail_page_alloc/ignore-gfp-wait", "N", false},
{"/sys/kernel/debug/fail_page_alloc/min-order", "0", false},
};
unsigned i;
for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) {
if (!write_file(files[i].file, files[i].val)) {
if (files[i].fatal)
return "failed to write fault injection file";
}
}
return NULL;
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
if ((reason = setup_fault()))
printf("the reproducer may not work as expected: fault injection setup failed: %s\n", reason);
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// openat$auto_kernfs_file_fops_kernfs_internal arguments: [
// fd: const = 0xffffffffffffff9c (8 bytes)
// file: ptr[in, buffer] {
// buffer: {2f 73 79 73 2f 64 65 76 69 63 65 73 2f 76 69 72 74 75 61 6c 2f 62 6c 6f 63 6b 2f 72 61 6d 34 2f 74 72 61 63 65 2f 73 74 61 72 74 5f 6c 62 61 00} (length 0x30)
// }
// flags: open_flags = 0xa001 (4 bytes)
// mode: const = 0x0 (2 bytes)
// ]
// returns fd_kernfs_file_fops_kernfs_internal
memcpy((void*)0x200000000080, "/sys/devices/virtual/block/ram4/trace/start_lba\000", 48);
res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000080ul, /*flags=O_LARGEFILE|FASYNC|O_WRONLY*/0xa001, /*mode=*/0);
if (res != -1)
r[0] = res;
// write$auto arguments: [
// fd: fd (resource)
// buf: ptr[in, buffer] {
// buffer: {30 00 5c a0 04 7c 03 cb 12 fa 08 1c c7 6b 3e c8 1f ad f6 f0 ef e4 73 95 f2 00 97 53 b9 4f ac be d6 5c 4a 3c 02 59 4b d6 4d e6 e7 a0 b8 c3 5b 01 c5 e8 7c b0 b0 80 bf a5 3f 3d 69 88 55 42 1d 8e d3 c2 94 39 b6 fb 00 36 02 9c 83 14 13 99 c7 b4 29 4d ed 09 4e 20 24 d4 90 5e 3f 4a 92 9a 3f f8 62 03 d8 dd 84 df 92 f0 cd d8 ba ab 15 80 9e 6f 2c c8 f2 82 d2 88 be 4c a0 1a d3 d5 4f 66 95 ee 13 65 eb 7d 6f 9b 86 5f f0 3f 0c 3c f3 74 37 b6 0f 93 c7 39 40 d8 78 9e ef 21 00 36 08 db 57 42 84 dd ac da 75 86 67 8f 02 40 4f 37 0f f8 8d 28 9c f2 4e 79 44 7f 33 14 9e 67 86 25 29 d6 08 cd 1f 03 00 3a a6 83 27 f4 f2 9d 64 f4 7a 89 c5 44 c4 02 5c 81 cf 02 45 70 f6 60 de 2a 1d 56} (length 0xde)
// }
// count: intptr = 0x81 (8 bytes)
// ]
memcpy((void*)0x2000000002c0, "... [truncated large byte array] ...", 222);
inject_fault(4);
syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x2000000002c0ul, /*count=*/0x81ul);
return 0;
}
]
|
| 3/1 |
2026/08/31 20:45 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/d20ee096b85bb6348b207ca05fcfd1899d452eaa]
|
| 4/1 |
2026/08/31 20:46 |
action |
kernel-builder |
19m
Results: map[KernelObj:/app/workdir/cache/build/85a2179a93aa925c1e713bb553e825af78c84e67]
|
| 5/1 |
2026/08/31 21:05 |
action |
crash-reproducer |
2m
Results: map[OtherCrashReports:<nil> ReproducedBugTitle:WARNING in get_probe_ref ReproducedCrashReport:R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
------------[ cut here ]------------
ret
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline], CPU#1: syz.0.17/6119
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492, CPU#1: syz.0.17/6119
Modules linked in:
CPU: 1 UID: 0 PID: 6119 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Code: c3 31 ff 89 c6 e8 39 42 f7 ff 85 db 0f 85 00 01 00 00 e8 2c 3d f7 ff 48 c7 c7 00 7f bd 8e 5b e9 af 77 db 09 e8 1a 3d f7 ff 90 <0f> 0b 90 e9 e8 fc ff ff e8 0c 3d f7 ff 90 0f 0b 90 e9 07 fd ff ff
RSP: 0018:ffffc9000355fb10 EFLAGS: 00010293
RAX: ffffffff81ce06d6 RBX: 00000000fffffff4 RCX: ffff888114150000
RDX: 0000000000000000 RSI: 00000000fffffff4 RDI: 0000000000000000
RBP: ffffc9000355fc40 R08: ffffc9000355fa47 R09: 1ffff920006abf48
R10: dffffc0000000000 R11: fffff520006abf49 R12: ffff88810888c508
R13: dffffc0000000000 R14: ffff888103f8c638 R15: 0000000000002000
FS: 00007fc861b426c0(0000) GS:ffff8882e873e000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2ed24008 CR3: 00000001fdd32000 CR4: 0000000000352ef0
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc860b9e159
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fc861b42028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fc860e25fa0 RCX: 00007fc860b9e159
RDX: 0000000000000081 RSI: 00002000000002c0 RDI: 0000000000000003
RBP: 00007fc861b42090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
ReproducedFaultInjection:FAULT_INJECTION: forcing a failure.
name failslab, interval 1, probability 0, space 0, times 1
Call Trace:
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
fail_dump lib/fault-inject.c:73 [inline]
should_fail_ex+0x410/0x560 lib/fault-inject.c:174
should_failslab+0xa8/0x100 mm/failslab.c:46
slab_pre_alloc_hook mm/slub.c:4638 [inline]
slab_alloc_node mm/slub.c:4974 [inline]
__do_kmalloc_node mm/slub.c:5413 [inline]
__kmalloc_noprof+0xfe/0x720 mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
allocate_probes kernel/tracepoint.c:106 [inline]
func_add kernel/tracepoint.c:168 [inline]
tracepoint_add_func+0x351/0xa90 kernel/tracepoint.c:301
tracepoint_probe_register_prio kernel/tracepoint.c:475 [inline]
tracepoint_probe_register+0x5d/0x90 kernel/tracepoint.c:495
register_trace_block_rq_insert include/trace/events/block.h:297 [inline]
blk_register_tracepoints kernel/trace/blktrace.c:1331 [inline]
get_probe_ref+0x4f/0x470 kernel/trace/blktrace.c:492
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f]
|
| 6/1 |
2026/08/31 21:08 |
action |
codesearch-prepare |
11m
Results: map[Index:codesearch-index]
|
| 7/1 |
2026/08/31 21:19 |
agent |
debugger |
6m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with debugging a kernel crash root cause.
You need to provide a detailed explanation of the root cause for another developer to be
able to write a fix for the bug based on your explanation. Include all relevant details
into the response: function/struct/field/etc names, code snippets, line numbers,
macro/enum values, etc.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
------------[ cut here ]------------
ret
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline], CPU#1: syz.0.17/6119
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492, CPU#1: syz.0.17/6119
Modules linked in:
CPU: 1 UID: 0 PID: 6119 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Code: c3 31 ff 89 c6 e8 39 42 f7 ff 85 db 0f 85 00 01 00 00 e8 2c 3d f7 ff 48 c7 c7 00 7f bd 8e 5b e9 af 77 db 09 e8 1a 3d f7 ff 90 <0f> 0b 90 e9 e8 fc ff ff e8 0c 3d f7 ff 90 0f 0b 90 e9 07 fd ff ff
RSP: 0018:ffffc9000355fb10 EFLAGS: 00010293
RAX: ffffffff81ce06d6 RBX: 00000000fffffff4 RCX: ffff888114150000
RDX: 0000000000000000 RSI: 00000000fffffff4 RDI: 0000000000000000
RBP: ffffc9000355fc40 R08: ffffc9000355fa47 R09: 1ffff920006abf48
R10: dffffc0000000000 R11: fffff520006abf49 R12: ffff88810888c508
R13: dffffc0000000000 R14: ffff888103f8c638 R15: 0000000000002000
FS: 00007fc861b426c0(0000) GS:ffff8882e873e000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2ed24008 CR3: 00000001fdd32000 CR4: 0000000000352ef0
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc860b9e159
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fc861b42028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fc860e25fa0 RCX: 00007fc860b9e159
RDX: 0000000000000081 RSI: 00002000000002c0 RDI: 0000000000000003
RBP: 00007fc861b42090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
The following C code is a draft of the vulnerable syscall sequence. Keep in mind that
it may lack the precise threading, sandboxing, and some arguments of a working reproducer:
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static int inject_fault(int nth)
{
int fd;
fd = open("/proc/thread-self/fail-nth", O_RDWR);
if (fd == -1)
exit(1);
char buf[16];
sprintf(buf, "%d", nth);
if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf))
exit(1);
return fd;
}
static const char* setup_fault()
{
int fd = open("/proc/self/make-it-fail", O_WRONLY);
if (fd == -1)
return "CONFIG_FAULT_INJECTION is not enabled";
close(fd);
fd = open("/proc/thread-self/fail-nth", O_WRONLY);
if (fd == -1)
return "kernel does not have systematic fault injection support";
close(fd);
static struct {
const char* file;
const char* val;
bool fatal;
} files[] = {
{"/sys/kernel/debug/failslab/ignore-gfp-wait", "N", true},
{"/sys/kernel/debug/fail_futex/ignore-private", "N", false},
{"/sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem", "N", false},
{"/sys/kernel/debug/fail_page_alloc/ignore-gfp-wait", "N", false},
{"/sys/kernel/debug/fail_page_alloc/min-order", "0", false},
};
unsigned i;
for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) {
if (!write_file(files[i].file, files[i].val)) {
if (files[i].fatal)
return "failed to write fault injection file";
}
}
return NULL;
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
if ((reason = setup_fault()))
printf("the reproducer may not work as expected: fault injection setup failed: %s\n", reason);
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// openat$auto_kernfs_file_fops_kernfs_internal arguments: [
// fd: const = 0xffffffffffffff9c (8 bytes)
// file: ptr[in, buffer] {
// buffer: {2f 73 79 73 2f 64 65 76 69 63 65 73 2f 76 69 72 74 75 61 6c 2f 62 6c 6f 63 6b 2f 72 61 6d 34 2f 74 72 61 63 65 2f 73 74 61 72 74 5f 6c 62 61 00} (length 0x30)
// }
// flags: open_flags = 0xa001 (4 bytes)
// mode: const = 0x0 (2 bytes)
// ]
// returns fd_kernfs_file_fops_kernfs_internal
memcpy((void*)0x200000000080, "/sys/devices/virtual/block/ram4/trace/start_lba\000", 48);
res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000080ul, /*flags=O_LARGEFILE|FASYNC|O_WRONLY*/0xa001, /*mode=*/0);
if (res != -1)
r[0] = res;
// write$auto arguments: [
// fd: fd (resource)
// buf: ptr[in, buffer] {
// buffer: {30 00 5c a0 04 7c 03 cb 12 fa 08 1c c7 6b 3e c8 1f ad f6 f0 ef e4 73 95 f2 00 97 53 b9 4f ac be d6 5c 4a 3c 02 59 4b d6 4d e6 e7 a0 b8 c3 5b 01 c5 e8 7c b0 b0 80 bf a5 3f 3d 69 88 55 42 1d 8e d3 c2 94 39 b6 fb 00 36 02 9c 83 14 13 99 c7 b4 29 4d ed 09 4e 20 24 d4 90 5e 3f 4a 92 9a 3f f8 62 03 d8 dd 84 df 92 f0 cd d8 ba ab 15 80 9e 6f 2c c8 f2 82 d2 88 be 4c a0 1a d3 d5 4f 66 95 ee 13 65 eb 7d 6f 9b 86 5f f0 3f 0c 3c f3 74 37 b6 0f 93 c7 39 40 d8 78 9e ef 21 00 36 08 db 57 42 84 dd ac da 75 86 67 8f 02 40 4f 37 0f f8 8d 28 9c f2 4e 79 44 7f 33 14 9e 67 86 25 29 d6 08 cd 1f 03 00 3a a6 83 27 f4 f2 9d 64 f4 7a 89 c5 44 c4 02 5c 81 cf 02 45 70 f6 60 de 2a 1d 56} (length 0xde)
// }
// count: intptr = 0x81 (8 bytes)
// ]
memcpy((void*)0x2000000002c0, "... [truncated large byte array] ...", 222);
inject_fault(4);
syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x2000000002c0ul, /*count=*/0x81ul);
return 0;
}
The reproducer uses fault injection to force allocation failure at a specific point.
These injected failures often exercise rarely used error-handling paths,
so the bug is frequently in that error handling.
The following fault injection report(s) show what was injected:
FAULT_INJECTION: forcing a failure.
name failslab, interval 1, probability 0, space 0, times 1
Call Trace:
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
fail_dump lib/fault-inject.c:73 [inline]
should_fail_ex+0x410/0x560 lib/fault-inject.c:174
should_failslab+0xa8/0x100 mm/failslab.c:46
slab_pre_alloc_hook mm/slub.c:4638 [inline]
slab_alloc_node mm/slub.c:4974 [inline]
__do_kmalloc_node mm/slub.c:5413 [inline]
__kmalloc_noprof+0xfe/0x720 mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
allocate_probes kernel/tracepoint.c:106 [inline]
func_add kernel/tracepoint.c:168 [inline]
tracepoint_add_func+0x351/0xa90 kernel/tracepoint.c:301
tracepoint_probe_register_prio kernel/tracepoint.c:475 [inline]
tracepoint_probe_register+0x5d/0x90 kernel/tracepoint.c:495
register_trace_block_rq_insert include/trace/events/block.h:297 [inline]
blk_register_tracepoints kernel/trace/blktrace.c:1331 [inline]
get_probe_ref+0x4f/0x470 kernel/trace/blktrace.c:492
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Reply: The root cause of the crash is that `blk_register_tracepoints()` uses `WARN_ON(ret)` to check the return values of `register_trace_block_*()` functions. These tracepoint registration functions allocate memory for the probe array and can fail with `-ENOMEM` (e.g., under memory pressure or fault injection, as seen in the syzbot report). When they fail, `WARN_ON()` triggers a kernel panic if `panic_on_warn` is set.
Furthermore, `blk_register_tracepoints()` currently ignores the error and continues, leaving the tracepoints in a partially registered state. Later, when tracing is stopped, `blk_unregister_tracepoints()` unconditionally unregisters all tracepoints. Unregistering a tracepoint that was not successfully registered causes `tracepoint_remove_func()` to return `-ENOENT`, which triggers another `WARN_ON_ONCE` inside `tracepoint_remove_func()`.
To fix this, we need to properly handle the registration failures by returning the error, unregistering the successfully registered tracepoints, and propagating the error up the call stack to fail the blktrace setup.
### Fix Details
1. **Change `blk_register_tracepoints()` to return an `int` and handle errors:**
Instead of `WARN_ON(ret)`, check the return value of each `register_trace_*()` call. If it fails, use `goto` labels to unregister the successfully registered tracepoints in reverse order, and return the error.
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
return ret;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
if (ret)
goto err_issue;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
if (ret)
goto err_merge;
// ... (do this for all 18 tracepoints) ...
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
if (ret)
goto err_rq_remap;
return 0;
err_rq_remap:
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
// ... (unregister labels in reverse order) ...
err_merge:
unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
err_issue:
unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
return ret;
}
```
2. **Propagate the error through `get_probe_ref()`:**
```c
static int get_probe_ref(void)
{
int ret = 0;
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1) {
ret = blk_register_tracepoints();
if (ret)
blk_probes_ref--;
}
mutex_unlock(&blk_probe_mutex);
return ret;
}
```
3. **Propagate the error through `blk_trace_setup_finalize()`:**
```c
static int blk_trace_setup_finalize(struct request_queue *q,
char *name, int version,
struct blk_trace *bt,
struct blk_user_trace_setup2 *buts)
{
int ret;
// ... existing code ...
bt->trace_state = Blktrace_setup;
ret = get_probe_ref();
if (ret)
return ret;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
}
```
4. **Handle the error in the callers of `blk_trace_setup_finalize()`:**
In `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, check the return value of `blk_trace_setup_finalize()`. If it fails, clean up the allocated `bt` and return the error:
```c
ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
```
5. **Handle the error in `blk_trace_setup_queue()`:**
```c
static int blk_trace_setup_queue(struct request_queue *q,
struct block_device *bdev)
{
// ... existing code ...
blk_trace_setup_lba(bt, bdev);
ret = get_probe_ref();
if (ret)
goto free_bt;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
free_bt:
blk_trace_free(q, bt);
return ret;
}
```
|
| 8/2 |
2026/08/31 21:19 |
llm |
debugger |
0m
Model:
Tokens:
input: 8796
output: 38
thoughts: 189
Thoughts: **Analyzing a Kernel Crash in blktrace**
Okay, so I've got a crash, a WARNING specifically, in `blk_register_tracepoints`. The stack trace points me right to `kernel/trace/blktrace.c:1332`. That's the starting point. It looks like it's happening during the `blk_register_tracepoints` function itself, but the backtrace also includes `get_probe_ref` which is interesting... and at line 492 of the same file. CPU #1, process `syz.0.17/6119`. Let's dig into that `blktrace.c` file and see what's happening around line 1332, and then look around line 492 too. There's a good chance this is a race condition or some kind of resource conflict within the tracepoint registration, or, perhaps, within probe ref counting. I need to understand what's triggering this WARNING.
|
| 9/2 |
2026/08/31 21:19 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1320 LineCount:50]
Results: map[Contents:1320: __blk_add_trace(bt, blk_rq_trace_sector(rq), blk_rq_bytes(rq), 0,
1321: BLK_TA_DRV_DATA, 0, len, data,
1322: blk_trace_request_get_cgid(rq));
1323: rcu_read_unlock();
1324: }
1325: EXPORT_SYMBOL_GPL(blk_add_driver_data);
1326:
1327: static void blk_register_tracepoints(void)
1328: {
1329: int ret;
1330:
1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1332: WARN_ON(ret);
1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1334: WARN_ON(ret);
1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1336: WARN_ON(ret);
1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1338: WARN_ON(ret);
1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1340: WARN_ON(ret);
1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1342: WARN_ON(ret);
1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1344: WARN_ON(ret);
1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1346: WARN_ON(ret);
1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1348: WARN_ON(ret);
1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
1350: WARN_ON(ret);
1351: ret = register_trace_blk_zone_append_update_request_bio(
1352: blk_add_trace_zone_update_request, NULL);
1353: WARN_ON(ret);
1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
1355: NULL);
1356: WARN_ON(ret);
1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
1358: NULL);
1359: WARN_ON(ret);
1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
1361: WARN_ON(ret);
1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
1363: WARN_ON(ret);
1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
1365: WARN_ON(ret);
1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1367: WARN_ON(ret);
1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1369: WARN_ON(ret);
]
|
| 10/2 |
2026/08/31 21:19 |
llm |
debugger |
0m
Model:
Tokens:
input: 10257
output: 37
thoughts: 599
Thoughts: **Analyzing a Fault Injection Scenario**
Okay, so I'm looking at this fault injection report and immediately my eye goes to line 1332 with that `WARN_ON(ret);` call. Right, it's triggered because `register_trace_block_rq_insert` returned an error. Looking at the call stack, I see the fault is simulated in `allocate_probes` which is called during the memory allocation in `slab_alloc_node`. This is a simulated failure, a "failslab" injection, to test error handling.
The interesting question is: if `register_trace_block_rq_insert` fails, what happens next? Does the system gracefully handle the failure and continue registering other tracepoints? My concern is that `blk_register_tracepoints` might just blindly trigger the `WARN_ON` call and move on. I need to look at the surrounding code in `blk_register_tracepoints` and the `get_probe_ref` function to fully understand the consequences of this failure. It's important to understand the overall architecture so that I can accurately access the impacts of this fault.
|
| 11/2 |
2026/08/31 21:20 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:480 LineCount:40]
Results: map[Contents: 480: } else {
481: debugfs_remove(bt->dir);
482: }
483: free_percpu(bt->sequence);
484: free_percpu(bt->msg_data);
485: kfree(bt);
486: }
487:
488: static void get_probe_ref(void)
489: {
490: mutex_lock(&blk_probe_mutex);
491: if (++blk_probes_ref == 1)
492: blk_register_tracepoints();
493: mutex_unlock(&blk_probe_mutex);
494: }
495:
496: static void put_probe_ref(void)
497: {
498: mutex_lock(&blk_probe_mutex);
499: if (!--blk_probes_ref)
500: blk_unregister_tracepoints();
501: mutex_unlock(&blk_probe_mutex);
502: }
503:
504: static int blk_trace_start(struct blk_trace *bt)
505: {
506: if (bt->trace_state != Blktrace_setup &&
507: bt->trace_state != Blktrace_stopped)
508: return -EINVAL;
509:
510: blktrace_seq++;
511: smp_mb();
512: bt->trace_state = Blktrace_running;
513: raw_spin_lock_irq(&running_trace_lock);
514: list_add(&bt->running_list, &running_trace_list);
515: raw_spin_unlock_irq(&running_trace_lock);
516: trace_note_time(bt);
517:
518: return 0;
519: }
]
|
| 12/2 |
2026/08/31 21:20 |
llm |
debugger |
0m
Model:
Tokens:
input: 11701
output: 37
thoughts: 266
Thoughts: **Analyzing a Kernel Tracepoint Registration Issue**
Okay, so I'm looking at this syzbot report and it's pointing to a `WARN_ON` within `blk_register_tracepoints`. My initial thought is that `get_probe_ref` is the entry point – it increments `blk_probes_ref` and then calls `blk_register_tracepoints` if this is the first probe. The problem seems to stem from the fact that `blk_register_tracepoints` calls a few `register_trace_*` functions, but only cares about their return values enough to trigger a `WARN_ON` on failure, which is exactly what we're seeing in the report.
My immediate instinct is to ask, is this `WARN_ON` necessary? If a `register_trace_*` function fails, it returns an error, most likely `-ENOMEM`. If that happens, those tracepoints don't get registered, which is expected. But, here's the kicker: `blk_register_tracepoints` is defined with a `void` return type! That means the error signal is essentially being discarded, and the code just continues execution. The `WARN_ON` is acting as a signal that something is wrong, and presumably it would indicate the reason for not registering the tracepoints.
So, is the fact that `blk_register_tracepoints` is `void` and relies on `WARN_ON` instead of returning an error code a bug? This seems like a potential flaw, and it's worth digging into the commit history of `blk_register_tracepoints` to understand the rationale behind this design. Perhaps there was a specific reason for this approach that I'm missing, but at first glance, it feels like a potential area for improvement or at least clarification.
|
| 13/2 |
2026/08/31 21:20 |
tool |
git-log |
0m
Error:
Args: map[PathPrefix:kernel/trace/blktrace.c SymbolName:blk_register_tracepoints]
Results:
|
| 14/2 |
2026/08/31 21:20 |
llm |
debugger |
0m
Model:
Tokens:
input: 12408
output: 37
thoughts: 19
Thoughts: Okay, here's the summary, rendered as a first-person thought process, geared towards an expert:
**Refining My Search Strategy**
Right, thinking about this symbol search... I should really be leveraging `SourcePath` instead of `PathPrefix`. I keep defaulting to `PathPrefix` in these scenarios, but I know `SourcePath` will offer a more accurate and targeted result. It's a subtle distinction, but a critical one for performance and precision, especially when dealing with the scope I'm used to. Time to adjust the workflow and get the most optimal search results.
|
| 15/2 |
2026/08/31 21:20 |
tool |
git-log |
0m
Args: map[SourcePath:kernel/trace/blktrace.c SymbolName:blk_register_tracepoints]
Results: map[Output:3c289ba7c320 blktrace: remove blk_probe_mutex
5f3ea37c7716 blktrace: port to tracepoints
]
|
| 16/2 |
2026/08/31 21:21 |
llm |
debugger |
0m
Model:
Tokens:
input: 12644
output: 26
thoughts: 17
Thoughts: Okay, here's my attempt at summarizing the thought process, as if it were my own, assuming the user is an expert.
**Deconstructing the Identifier: `5f3ea37c7716`**
Alright, let's take a look at this identifier: `5f3ea37c7716`. Immediately, my mind starts sifting through potential interpretations. The format screams hexadecimal, which instantly narrows the possibilities. Given my experience, I'd instantly start considering context. Is this a database ID? A hash value from a cryptographic algorithm? Perhaps a commit ID in version control? Or maybe a segment of memory address from my program?
My first instinct is to try and correlate this string with my current project or recent work. Did I encounter something similar in my debugging log from last night? Do I recognize any part of this identifier to an object or process?
If I have more context, like knowing the programming language, system, or data structure in which it was used, it would help a lot. If I'm coming up empty, it would be useful to look up tools to perform lookups against databases or codebases that could potentially reveal the value's origin or function.
If it's a hash, is it MD5, SHA-1, SHA-256? That will help in determining its age, and whether or not it's something I need to be concerned with.
|
| 17/2 |
2026/08/31 21:21 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 5f3ea37c7716db4e894a480e0c18b24399595b6b
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Thu Oct 30 08:34:33 2008 +0100
blktrace: port to tracepoints
This was a forward port of work done by Mathieu Desnoyers, I changed it to
encode the 'what' parameter on the tracepoint name, so that one can register
interest in specific events and not on classes of events to then check the
'what' parameter.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/block/Kconfig b/block/Kconfig
index 1ab7c15c8d7a..290b219fad9c 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -47,6 +47,7 @@ config BLK_DEV_IO_TRACE
depends on SYSFS
select RELAY
select DEBUG_FS
+ select TRACEPOINTS
help
Say Y here if you want to be able to trace the block layer actions
on a given queue. Tracing allows you to see any traffic happening
diff --git a/block/blk-core.c b/block/blk-core.c
index 10e8a64a5a5b..04267d66a2b9 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -28,6 +28,7 @@
#include <linux/task_io_accounting_ops.h>
#include <linux/blktrace_api.h>
#include <linux/fault-inject.h>
+#include <trace/block.h>
#include "blk.h"
@@ -205,7 +206,7 @@ void blk_plug_device(struct request_queue *q)
if (!queue_flag_test_and_set(QUEUE_FLAG_PLUGGED, q)) {
mod_timer(&q->unplug_timer, jiffies + q->unplug_delay);
- blk_add_trace_generic(q, NULL, 0, BLK_TA_PLUG);
+ trace_block_plug(q);
}
}
EXPORT_SYMBOL(blk_plug_device);
@@ -292,9 +293,7 @@ void blk_unplug_work(struct work_struct *work)
struct request_queue *q =
container_of(work, struct request_queue, unplug_work);
- blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_IO, NULL,
- q->rq.count[READ] + q->rq.count[WRITE]);
-
+ trace_block_unplug_io(q);
q->unplug_fn(q);
}
@@ -302,9 +301,7 @@ void blk_unplug_timeout(unsigned long data)
{
struct request_queue *q = (struct request_queue *)data;
- blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_TIMER, NULL,
- q->rq.count[READ] + q->rq.count[WRITE]);
-
+ trace_block_unplug_timer(q);
kblockd_schedule_work(q, &q->unplug_work);
}
@@ -314,9 +311,7 @@ void blk_unplug(struct request_queue *q)
* devices don't necessarily have an ->unplug_fn defined
*/
if (q->unplug_fn) {
- blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_IO, NULL,
- q->rq.count[READ] + q->rq.count[WRITE]);
-
+ trace_block_unplug_io(q);
q->unplug_fn(q);
}
}
@@ -822,7 +817,7 @@ static struct request *get_request(struct request_queue *q, int rw_flags,
if (ioc_batching(q, ioc))
ioc->nr_batch_requests--;
- blk_add_trace_generic(q, bio, rw, BLK_TA_GETRQ);
+ trace_block_getrq(q, bio, rw);
out:
return rq;
}
@@ -848,7 +843,7 @@ static struct request *get_request_wait(struct request_queue *q, int rw_flags,
prepare_to_wait_exclusive(&rl->wait[rw], &wait,
TASK_UNINTERRUPTIBLE);
- blk_add_trace_generic(q, bio, rw, BLK_TA_SLEEPRQ);
+ trace_block_sleeprq(q, bio, rw);
__generic_unplug_device(q);
spin_unlock_irq(q->queue_lock);
@@ -928,7 +923,7 @@ void blk_requeue_request(struct request_queue *q, struct request *rq)
{
blk_delete_timer(rq);
blk_clear_rq_complete(rq);
- blk_add_trace_rq(q, rq, BLK_TA_REQUEUE);
+ trace_block_rq_requeue(q, rq);
if (blk_rq_tagged(rq))
blk_queue_end_tag(q, rq);
@@ -1167,7 +1162,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
if (!ll_back_merge_fn(q, req, bio))
break;
- blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE);
+ trace_block_bio_backmerge(q, bio);
req->biotail->bi_next = bio;
req->biotail = bio;
@@ -1186,7 +1181,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
if (!ll_front_merge_fn(q, req, bio))
break;
- blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE);
+ trace_block_bio_frontmerge(q, bio);
bio->bi_next = req->bio;
req->bio = bio;
@@ -1269,7 +1264,7 @@ static inline void blk_partition_remap(struct bio *bio)
bio->bi_sector += p->start_sect;
bio->bi_bdev = bdev->bd_contains;
- blk_add_trace_remap(bdev_get_queue(bio->bi_bdev), bio,
+ trace_block_remap(bdev_get_queue(bio->bi_bdev), bio,
bdev->bd_dev, bio->bi_sector,
bio->bi_sector - p->start_sect);
}
@@ -1441,10 +1436,10 @@ static inline void __generic_make_request(struct bio *bio)
goto end_io;
if (old_sector != -1)
- blk_add_trace_remap(q, bio, old_dev, bio->bi_sector,
+ trace_block_remap(q, bio, old_dev, bio->bi_sector,
old_sector);
- blk_add_trace_bio(q, bio, BLK_TA_QUEUE);
+ trace_block_bio_queue(q, bio);
old_sector = bio->bi_sector;
old_dev = bio->bi_bdev->bd_dev;
@@ -1656,7 +1651,7 @@ static int __end_that_request_first(struct request *req, int error,
int total_bytes, bio_nbytes, next_idx = 0;
struct bio *bio;
- blk_add_trace_rq(req->q, req, BLK_TA_COMPLETE);
+ trace_block_rq_complete(req->q, req);
/*
* for a REQ_TYPE_BLOCK_PC request, we want to carry any eventual
diff --git a/block/blktrace.c b/block/blktrace.c
index 85049a7e7a17..b0a2cae886db 100644
--- a/block/blktrace.c
+++ b/block/blktrace.c
@@ -23,10 +23,18 @@
#include <linux/mutex.h>
#include <linux/debugfs.h>
#include <linux/time.h>
+#include <trace/block.h>
#include <asm/uaccess.h>
static unsigned int blktrace_seq __read_mostly = 1;
+/* Global reference count of probes */
+static DEFINE_MUTEX(blk_probe_mutex);
+static atomic_t blk_probes_ref = ATOMIC_INIT(0);
+
+static int blk_register_tracepoints(void);
+static void blk_unregister_tracepoints(void);
+
/*
* Send out a notify message.
*/
@@ -119,7 +127,7 @@ static u32 ddir_act[2] __read_mostly = { BLK_TC_ACT(BLK_TC_READ), BLK_TC_ACT(BLK
* The worker for the various blk_add_trace*() types. Fills out a
* blk_io_trace structure and places it in a per-cpu subbuffer.
*/
-void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
+static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
int rw, u32 what, int error, int pdu_len, void *pdu_data)
{
struct task_struct *tsk = current;
@@ -177,8 +185,6 @@ void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
local_irq_restore(flags);
}
-EXPORT_SYMBOL_GPL(__blk_add_trace);
-
static struct dentry *blk_tree_root;
static DEFINE_MUTEX(blk_tree_mutex);
static unsigned int root_users;
@@ -237,6 +243,10 @@ static void blk_trace_cleanup(struct blk_trace *bt)
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
+ mutex_lock(&blk_probe_mutex);
+ if (atomic_dec_and_test(&blk_probes_ref))
+ blk_unregister_tracepoints();
+ mutex_unlock(&blk_probe_mutex);
}
int blk_trace_remove(struct request_queue *q)
@@ -428,6 +438,14 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ mutex_lock(&blk_probe_mutex);
+ if (atomic_add_return(1, &blk_probes_ref) == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ goto probe_err;
+ }
+ mutex_unlock(&blk_probe_mutex);
+
ret = -EBUSY;
old_bt = xchg(&q->blk_trace, bt);
if (old_bt) {
@@ -436,6 +454,9 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
}
return 0;
+probe_err:
+ atomic_dec(&blk_probes_ref);
+ mutex_unlock(&blk_probe_mutex);
err:
if (dir)
blk_remove_tree(dir);
@@ -562,3 +583,308 @@ void blk_trace_shutdown(struct request_queue *q)
blk_trace_remove(q);
}
}
+
+/*
+ * blktrace probes
+ */
+
+/**
+ * blk_add_trace_rq - Add a trace for a request oriented action
+ * @q: queue the io is for
+ * @rq: the source request
+ * @what: the action
+ *
+ * Description:
+ * Records an action against a request. Will log the bio offset + size.
+ *
+ **/
+static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
+ u32 what)
+{
+ struct blk_trace *bt = q->blk_trace;
+ int rw = rq->cmd_flags & 0x03;
+
+ if (likely(!bt))
+ return;
+
+ if (blk_discard_rq(rq))
+ rw |= (1 << BIO_RW_DISCARD);
+
+ if (blk_pc_request(rq)) {
+ what |= BLK_TC_ACT(BLK_TC_PC);
+ __blk_add_trace(bt, 0, rq->data_len, rw, what, rq->errors,
+ sizeof(rq->cmd), rq->cmd);
+ } else {
+ what |= BLK_TC_ACT(BLK_TC_FS);
+ __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9,
+ rw, what, rq->errors, 0, NULL);
+ }
+}
+
+static void blk_add_trace_rq_abort(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_ABORT);
+}
+
+static void blk_add_trace_rq_insert(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_INSERT);
+}
+
+static void blk_add_trace_rq_issue(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
+}
+
+static void blk_add_trace_rq_requeue(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_REQUEUE);
+}
+
+static void blk_add_trace_rq_complete(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_COMPLETE);
+}
+
+/**
+ * blk_add_trace_bio - Add a trace for a bio oriented action
+ * @q: queue the io is for
+ * @bio: the source bio
+ * @what: the action
+ *
+ * Description:
+ * Records an action against a bio. Will log the bio offset + size.
+ *
+ **/
+static void blk_add_trace_bio(struct request_queue *q, struct bio *bio,
+ u32 what)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (likely(!bt))
+ return;
+
+ __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what,
+ !bio_flagged(bio, BIO_UPTODATE), 0, NULL);
+}
+
+static void blk_add_trace_bio_bounce(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_BOUNCE);
+}
+
+static void blk_add_trace_bio_complete(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_COMPLETE);
+}
+
+static void blk_add_trace_bio_backmerge(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE);
+}
+
+static void blk_add_trace_bio_frontmerge(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE);
+}
+
+static void blk_add_trace_bio_queue(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_QUEUE);
+}
+
+static void blk_add_trace_getrq(struct request_queue *q, struct bio *bio, int rw)
+{
+ if (bio)
+ blk_add_trace_bio(q, bio, BLK_TA_GETRQ);
+ else {
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt)
+ __blk_add_trace(bt, 0, 0, rw, BLK_TA_GETRQ, 0, 0, NULL);
+ }
+}
+
+
+static void blk_add_trace_sleeprq(struct request_queue *q, struct bio *bio, int rw)
+{
+ if (bio)
+ blk_add_trace_bio(q, bio, BLK_TA_SLEEPRQ);
+ else {
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt)
+ __blk_add_trace(bt, 0, 0, rw, BLK_TA_SLEEPRQ, 0, 0, NULL);
+ }
+}
+
+static void blk_add_trace_plug(struct request_queue *q)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt)
+ __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL);
+}
+
+static void blk_add_trace_unplug_io(struct request_queue *q)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt) {
+ unsigned int pdu = q->rq.count[READ] + q->rq.count[WRITE];
+ __be64 rpdu = cpu_to_be64(pdu);
+
+ __blk_add_trace(bt, 0, 0, 0, BLK_TA_UNPLUG_IO, 0,
+ sizeof(rpdu), &rpdu);
+ }
+}
+
+static void blk_add_trace_unplug_timer(struct request_queue *q)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt) {
+ unsigned int pdu = q->rq.count[READ] + q->rq.count[WRITE];
+ __be64 rpdu = cpu_to_be64(pdu);
+
+ __blk_add_trace(bt, 0, 0, 0, BLK_TA_UNPLUG_TIMER, 0,
+ sizeof(rpdu), &rpdu);
+ }
+}
+
+static void blk_add_trace_split(struct request_queue *q, struct bio *bio,
+ unsigned int pdu)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt) {
+ __be64 rpdu = cpu_to_be64(pdu);
+
+ __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw,
+ BLK_TA_SPLIT, !bio_flagged(bio, BIO_UPTODATE),
+ sizeof(rpdu), &rpdu);
+ }
+}
+
+/**
+ * blk_add_trace_remap - Add a trace for a remap operation
+ * @q: queue the io is for
+ * @bio: the source bio
+ * @dev: target device
+ * @from: source sector
+ * @to: target sector
+ *
+ * Description:
+ * Device mapper or raid target sometimes need to split a bio because
+ * it spans a stripe (or similar). Add a trace for that action.
+ *
+ **/
+static void blk_add_trace_remap(struct request_queue *q, struct bio *bio,
+ dev_t dev, sector_t from, sector_t to)
+{
+ struct blk_trace *bt = q->blk_trace;
+ struct blk_io_trace_remap r;
+
+ if (likely(!bt))
+ return;
+
+ r.device = cpu_to_be32(dev);
+ r.device_from = cpu_to_be32(bio->bi_bdev->bd_dev);
+ r.sector = cpu_to_be64(to);
+
+ __blk_add_trace(bt, from, bio->bi_size, bio->bi_rw, BLK_TA_REMAP,
+ !bio_flagged(bio, BIO_UPTODATE), sizeof(r), &r);
+}
+
+/**
+ * blk_add_driver_data - Add binary message with driver-specific data
+ * @q: queue the io is for
+ * @rq: io request
+ * @data: driver-specific data
+ * @len: length of driver-specific data
+ *
+ * Description:
+ * Some drivers might want to write driver-specific data per request.
+ *
+ **/
+void blk_add_driver_data(struct request_queue *q,
+ struct request *rq,
+ void *data, size_t len)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (likely(!bt))
+ return;
+
+ if (blk_pc_request(rq))
+ __blk_add_trace(bt, 0, rq->data_len, 0, BLK_TA_DRV_DATA,
+ rq->errors, len, data);
+ else
+ __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9,
+ 0, BLK_TA_DRV_DATA, rq->errors, len, data);
+}
+EXPORT_SYMBOL_GPL(blk_add_driver_data);
+
+static int blk_register_tracepoints(void)
+{
+ int ret;
+
+ ret = register_trace_block_rq_abort(blk_add_trace_rq_abort);
+ WARN_ON(ret);
+ ret = register_trace_block_rq_insert(blk_add_trace_rq_insert);
+ WARN_ON(ret);
+ ret = register_trace_block_rq_issue(blk_add_trace_rq_issue);
+ WARN_ON(ret);
+ ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue);
+ WARN_ON(ret);
+ ret = register_trace_block_rq_complete(blk_add_trace_rq_complete);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_complete(blk_add_trace_bio_complete);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_queue(blk_add_trace_bio_queue);
+ WARN_ON(ret);
+ ret = register_trace_block_getrq(blk_add_trace_getrq);
+ WARN_ON(ret);
+ ret = register_trace_block_sleeprq(blk_add_trace_sleeprq);
+ WARN_ON(ret);
+ ret = register_trace_block_plug(blk_add_trace_plug);
+ WARN_ON(ret);
+ ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer);
+ WARN_ON(ret);
+ ret = register_trace_block_unplug_io(blk_add_trace_unplug_io);
+ WARN_ON(ret);
+ ret = register_trace_block_split(blk_add_trace_split);
+ WARN_ON(ret);
+ ret = register_trace_block_remap(blk_add_trace_remap);
+ WARN_ON(ret);
+ return 0;
+}
+
+static void blk_unregister_tracepoints(void)
+{
+ unregister_trace_block_remap(blk_add_trace_remap);
+ unregister_trace_block_split(blk_add_trace_split);
+ unregister_trace_block_unplug_io(blk_add_trace_unplug_io);
+ unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer);
+ unregister_trace_block_plug(blk_add_trace_plug);
+ unregister_trace_block_sleeprq(blk_add_trace_sleeprq);
+ unregister_trace_block_getrq(blk_add_trace_getrq);
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue);
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge);
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge);
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete);
+ unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce);
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete);
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue);
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue);
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert);
+ unregister_trace_block_rq_abort(blk_add_trace_rq_abort);
+
+ tracepoint_synchronize_unregister();
+}
diff --git a/block/elevator.c b/block/elevator.c
index 9ac82dde99dd..530fcfe2ef07 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -33,6 +33,7 @@
#include <linux/compiler.h>
#include <linux/delay.h>
#include <linux/blktrace_api.h>
+#include <trace/block.h>
#include <linux/hash.h>
#include <linux/uaccess.h>
@@ -586,7 +587,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
unsigned ordseq;
int unplug_it = 1;
- blk_add_trace_rq(q, rq, BLK_TA_INSERT);
+ trace_block_rq_insert(q, rq);
rq->q = q;
@@ -772,7 +773,7 @@ struct request *elv_next_request(struct request_queue *q)
* not be passed by new incoming requests
*/
rq->cmd_flags |= REQ_STARTED;
- blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
+ trace_block_rq_issue(q, rq);
}
if (!q->boundary_rq || q->boundary_rq == rq) {
@@ -921,7 +922,7 @@ void elv_abort_queue(struct request_queue *q)
while (!list_empty(&q->queue_head)) {
rq = list_entry_rq(q->queue_head.next);
rq->cmd_flags |= REQ_QUIET;
- blk_add_trace_rq(q, rq, BLK_TA_ABORT);
+ trace_block_rq_abort(q, rq);
__blk_end_request(rq, -EIO, blk_rq_bytes(rq));
}
}
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index c99e4728ff41..d23fda178163 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -21,6 +21,7 @@
#include <linux/idr.h>
#include <linux/hdreg.h>
#include <linux/blktrace_api.h>
+#include <trace/block.h>
#define DM_MSG_PREFIX "core"
@@ -504,8 +505,7 @@ static void dec_pending(struct dm_io *io, int error)
end_io_acct(io);
if (io->error != DM_ENDIO_REQUEUE) {
- blk_add_trace_bio(io->md->queue, io->bio,
- BLK_TA_COMPLETE);
+ trace_block_bio_complete(io->md->queue, io->bio);
bio_endio(io->bio, io->error);
}
@@ -598,7 +598,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
if (r == DM_MAPIO_REMAPPED) {
/* the bio has been remapped so dispatch it */
- blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone,
+ trace_block_remap(bdev_get_queue(clone->bi_bdev), clone,
tio->io->bio->bi_bdev->bd_dev,
clone->bi_sector, sector);
diff --git a/fs/bio.c b/fs/bio.c
index 77a55bcceedb..060859c69092 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -26,6 +26,7 @@
#include <linux/mempool.h>
#include <linux/workqueue.h>
#include <linux/blktrace_api.h>
+#include <trace/block.h>
#include <scsi/sg.h> /* for struct sg_iovec */
static struct kmem_cache *bio_slab __read_mostly;
@@ -1263,7 +1264,7 @@ struct bio_pair *bio_split(struct bio *bi, int first_sectors)
if (!bp)
return bp;
- blk_add_trace_pdu_int(bdev_get_queue(bi->bi_bdev), BLK_TA_SPLIT, bi,
+ trace_block_split(bdev_get_queue(bi->bi_bdev), bi,
bi->bi_sector + first_sectors);
BUG_ON(bi->bi_vcnt != 1);
diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
index bdf505d33e77..1dba3493d520 100644
--- a/include/linux/blktrace_api.h
+++ b/include/linux/blktrace_api.h
@@ -160,7 +160,6 @@ struct blk_trace {
extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
extern void blk_trace_shutdown(struct request_queue *);
-extern void __blk_add_trace(struct blk_trace *, sector_t, int, int, u32, int, int, void *);
extern int do_blk_trace_setup(struct request_queue *q,
char *name, dev_t dev, struct blk_user_trace_setup *buts);
extern void __trace_note_message(struct blk_trace *, const char *fmt, ...);
@@ -186,168 +185,8 @@ extern void __trace_note_message(struct blk_trace *, const char *fmt, ...);
} while (0)
#define BLK_TN_MAX_MSG 128
-/**
- * blk_add_trace_rq - Add a trace for a request oriented action
- * @q: queue the io is for
- * @rq: the source request
- * @what: the action
- *
- * Description:
- * Records an action against a request. Will log the bio offset + size.
- *
- **/
-static inline void blk_add_trace_rq(struct request_queue *q, struct request *rq,
- u32 what)
-{
- struct blk_trace *bt = q->blk_trace;
- int rw = rq->cmd_flags & 0x03;
-
- if (likely(!bt))
- return;
-
- if (blk_discard_rq(rq))
- rw |= (1 << BIO_RW_DISCARD);
-
- if (blk_pc_request(rq)) {
- what |= BLK_TC_ACT(BLK_TC_PC);
- __blk_add_trace(bt, 0, rq->data_len, rw, what, rq->errors, sizeof(rq->cmd), rq->cmd);
- } else {
- what |= BLK_TC_ACT(BLK_TC_FS);
- __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9, rw, what, rq->errors, 0, NULL);
- }
-}
-
-/**
- * blk_add_trace_bio - Add a trace for a bio oriented action
- * @q: queue the io is for
- * @bio: the source bio
- * @what: the action
- *
- * Description:
- * Records an action against a bio. Will log the bio offset + size.
- *
- **/
-static inline void blk_add_trace_bio(struct request_queue *q, struct bio *bio,
- u32 what)
-{
- struct blk_trace *bt = q->blk_trace;
-
- if (likely(!bt))
- return;
-
- __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what, !bio_flagged(bio, BIO_UPTODATE), 0, NULL);
-}
-
-/**
- * blk_add_trace_generic - Add a trace for a generic action
- * @q: queue the io is for
- * @bio: the source bio
- * @rw: the data direction
- * @what: the action
- *
- * Description:
- * Records a simple trace
- *
- **/
-static inline void blk_add_trace_generic(struct request_queue *q,
- struct bio *bio, int rw, u32 what)
-{
- struct blk_trace *bt = q->blk_trace;
-
- if (likely(!bt))
- return;
-
- if (bio)
- blk_add_trace_bio(q, bio, what);
- else
- __blk_add_trace(bt, 0, 0, rw, what, 0, 0, NULL);
-}
-
-/**
- * blk_add_trace_pdu_int - Add a trace for a bio with an integer payload
- * @q: queue the io is for
- * @what: the action
- * @bio: the source bio
- * @pdu: the integer payload
- *
- * Description:
- * Adds a trace with some integer payload. This might be an unplug
- * option given as the action, with the depth at unplug time given
- * as the payload
- *
- **/
-static inline void blk_add_trace_pdu_int(struct request_queue *q, u32 what,
- struct bio *bio, unsigned int pdu)
-{
- struct blk_trace *bt = q->blk_trace;
- __be64 rpdu = cpu_to_be64(pdu);
-
- if (likely(!bt))
- return;
-
- if (bio)
- __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what, !bio_flagged(bio, BIO_UPTODATE), sizeof(rpdu), &rpdu);
- else
- __blk_add_trace(bt, 0, 0, 0, what, 0, sizeof(rpdu), &rpdu);
-}
-
-/**
- * blk_add_trace_remap - Add a trace for a remap operation
- * @q: queue the io is for
- * @bio: the source bio
- * @dev: target device
- * @from: source sector
- * @to: target sector
- *
- * Description:
- * Device mapper or raid target sometimes need to split a bio because
- * it spans a stripe (or similar). Add a trace for that action.
- *
- **/
-static inline void blk_add_trace_remap(struct request_queue *q, struct bio *bio,
- dev_t dev, sector_t from, sector_t to)
-{
- struct blk_trace *bt = q->blk_trace;
- struct blk_io_trace_remap r;
-
- if (likely(!bt))
- return;
-
- r.device = cpu_to_be32(dev);
- r.device_from = cpu_to_be32(bio->bi_bdev->bd_dev);
- r.sector = cpu_to_be64(to);
-
- __blk_add_trace(bt, from, bio->bi_size, bio->bi_rw, BLK_TA_REMAP, !bio_flagged(bio, BIO_UPTODATE), sizeof(r), &r);
-}
-
-/**
- * blk_add_driver_data - Add binary message with driver-specific data
- * @q: queue the io is for
- * @rq: io request
- * @data: driver-specific data
- * @len: length of driver-specific data
- *
- * Description:
- * Some drivers might want to write driver-specific data per request.
- *
- **/
-static inline void blk_add_driver_data(struct request_queue *q,
- struct request *rq,
- void *data, size_t len)
-{
- struct blk_trace *bt = q->blk_trace;
-
- if (likely(!bt))
- return;
-
- if (blk_pc_request(rq))
- __blk_add_trace(bt, 0, rq->data_len, 0, BLK_TA_DRV_DATA,
- rq->errors, len, data);
- else
- __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9,
- 0, BLK_TA_DRV_DATA, rq->errors, len, data);
-}
-
+extern void blk_add_driver_data(struct request_queue *q, struct request *rq,
+ void *data, size_t len);
extern int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
char __user *arg);
extern int blk_trace_startstop(struct request_queue *q, int start);
@@ -356,13 +195,8 @@ extern int blk_trace_remove(struct request_queue *q);
#else /* !CONFIG_BLK_DEV_IO_TRACE */
#define blk_trace_ioctl(bdev, cmd, arg) (-ENOTTY)
#define blk_trace_shutdown(q) do { } while (0)
-#define blk_add_trace_rq(q, rq, what) do { } while (0)
-#define blk_add_trace_bio(q, rq, what) do { } while (0)
-#define blk_add_trace_generic(q, rq, rw, what) do { } while (0)
-#define blk_add_trace_pdu_int(q, what, bio, pdu) do { } while (0)
-#define blk_add_trace_remap(q, bio, dev, f, t) do {} while (0)
-#define blk_add_driver_data(q, rq, data, len) do {} while (0)
#define do_blk_trace_setup(q, name, dev, buts) (-ENOTTY)
+#define blk_add_driver_data(q, rq, data, len) do {} while (0)
#define blk_trace_setup(q, name, dev, arg) (-ENOTTY)
#define blk_trace_startstop(q, start) (-ENOTTY)
#define blk_trace_remove(q) (-ENOTTY)
diff --git a/include/trace/block.h b/include/trace/block.h
new file mode 100644
index 000000000000..3cc2675ebf01
--- /dev/null
+++ b/include/trace/block.h
@@ -0,0 +1,60 @@
+#ifndef _TRACE_BLOCK_H
+#define _TRACE_BLOCK_H
+
+#include <linux/blkdev.h>
+#include <linux/tracepoint.h>
+
+DEFINE_TRACE(block_rq_abort,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_rq_insert,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_rq_issue,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_rq_requeue,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_rq_complete,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_bio_bounce,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_bio_complete,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_bio_backmerge,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_bio_frontmerge,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_bio_queue,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_getrq,
+ TPPROTO(struct request_queue *q, struct bio *bio, int rw),
+ TPARGS(q, bio, rw));
+DEFINE_TRACE(block_sleeprq,
+ TPPROTO(struct request_queue *q, struct bio *bio, int rw),
+ TPARGS(q, bio, rw));
+DEFINE_TRACE(block_plug,
+ TPPROTO(struct request_queue *q),
+ TPARGS(q));
+DEFINE_TRACE(block_unplug_timer,
+ TPPROTO(struct request_queue *q),
+ TPARGS(q));
+DEFINE_TRACE(block_unplug_io,
+ TPPROTO(struct request_queue *q),
+ TPARGS(q));
+DEFINE_TRACE(block_split,
+ TPPROTO(struct request_queue *q, struct bio *bio, unsigned int pdu),
+ TPARGS(q, bio, pdu));
+DEFINE_TRACE(block_remap,
+ TPPROTO(struct request_queue *q, struct bio *bio, dev_t dev,
+ sector_t from, sector_t to),
+ TPARGS(q, bio, dev, from, to));
+
+#endif
diff --git a/mm/bounce.c b/mm/bounce.c
index 06722c403058..bd1caaa582b8 100644
--- a/mm/bounce.c
+++ b/mm/bounce.c
@@ -14,6 +14,7 @@
#include <linux/hash.h>
#include <linux/highmem.h>
#include <linux/blktrace_api.h>
+#include <trace/block.h>
#include <asm/tlbflush.h>
#define POOL_SIZE 64
@@ -222,7 +223,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig,
if (!bio)
return;
- blk_add_trace_bio(q, *bio_orig, BLK_TA_BOUNCE);
+ trace_block_bio_bounce(q, *bio_orig);
/*
* at least one page was bounced, fill in possible non-highmem
]
|
| 18/2 |
2026/08/31 21:21 |
llm |
debugger |
0m
Model:
Tokens:
input: 24874
output: 38
thoughts: 338
Thoughts: **Analyzing the Tracepoint Registration in the Block Layer**
Okay, so I'm looking at this `blk_register_tracepoints` function and immediately my expert brain flags a few things. First, the comment mentions this was added back in 2008, which gives me some historical context. The initial implementation uses this `blk_register_tracepoints` function to register a number of tracepoints, like `block_rq_abort` and `block_rq_insert`. The interesting part is the error handling. I see that if `register_trace_block_rq_abort` fails, it just issues a warning with `WARN_ON` and keeps going. I'm used to seeing a more robust approach, but maybe that's a deliberate design choice here.
Then, there's `register_trace_block_rq_insert`. Wait, a `WARN_ON` is triggered on error, which is odd. I would have expected a return, signaling the caller that something has gone wrong. But the function returns 0 even when there's an error. That doesn't make sense!
Wait a second...I'm getting confused! I need to trace this back. Checking the commit history is vital. It seems the original code did actually return an `int`. But, looking at the current code, it has been changed to `void`! This is key. The current version now lacks any error return! So if `register_trace_block_rq_insert` fails, the calling function is completely unaware! This is a potential bug. I should investigate the implications of this change. It’s certainly worth revisiting the tracing infrastructure. The lack of an error return is definitely a red flag that needs attention.
|
| 19/2 |
2026/08/31 21:21 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1327 LineCount:50]
Results: map[Contents:1327: static void blk_register_tracepoints(void)
1328: {
1329: int ret;
1330:
1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1332: WARN_ON(ret);
1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1334: WARN_ON(ret);
1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1336: WARN_ON(ret);
1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1338: WARN_ON(ret);
1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1340: WARN_ON(ret);
1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1342: WARN_ON(ret);
1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1344: WARN_ON(ret);
1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1346: WARN_ON(ret);
1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1348: WARN_ON(ret);
1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
1350: WARN_ON(ret);
1351: ret = register_trace_blk_zone_append_update_request_bio(
1352: blk_add_trace_zone_update_request, NULL);
1353: WARN_ON(ret);
1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
1355: NULL);
1356: WARN_ON(ret);
1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
1358: NULL);
1359: WARN_ON(ret);
1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
1361: WARN_ON(ret);
1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
1363: WARN_ON(ret);
1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
1365: WARN_ON(ret);
1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1367: WARN_ON(ret);
1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1369: WARN_ON(ret);
1370: }
1371:
1372: static void blk_unregister_tracepoints(void)
1373: {
1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1376: unregister_trace_block_split(blk_add_trace_split, NULL);
]
|
| 20/2 |
2026/08/31 21:21 |
llm |
debugger |
0m
Model:
Tokens:
input: 26629
output: 24
thoughts: 305
Thoughts: **My Analysis of Block Tracepoint Registration**
Okay, so `blk_register_tracepoints` returns `void`. That's a little concerning right off the bat – I always prefer functions that return an error code for this sort of critical operation. The code's structure immediately tells me that if `register_trace_block_rq_insert` fails, it just issues a warning and keeps going. That feels a bit fragile to me.
I need to understand *why* it might fail. Ah, right, fault injection via `allocate_probes`. So, it's potentially failing due to simulated memory allocation problems. Is this warning behavior the correct approach? No, absolutely not. Using `WARN_ON` for a memory allocation failure is a cardinal sin, especially in this context! Fault injection and genuine Out-of-Memory (OOM) conditions are going to trigger those warnings, which can lead to a panic if `panic_on_warn` is set, as syzbot does. That's a huge problem.
Wait a second, `register_trace_block_rq_insert` is returning `-ENOMEM` when it fails. If it fails, `blk_register_tracepoints` just prints a warning and... carries on. But that means the tracepoint is *not* registered. If `blk_register_tracepoints` fails to register *some* of the tracepoints, the system is left in an inconsistent state – a mix of registered and unregistered tracepoints. And then, when `blk_unregister_tracepoints` is called, it's going to try to unregister *all* of them, even the ones that weren't registered successfully. But wait, `unregister_trace_*` is safe, right? It handles the case of an unregistered tracepoint by returning `-ENOENT`. So, the main problem here is definitely the `WARN_ON` which will panic the kernel.
So, the real question is: should `blk_register_tracepoints` return an error if registration fails and *clean up* the already registered tracepoints to avoid this inconsistent state? Yes, it absolutely should. I need to trace where `blk_register_tracepoints` is being called to fully understand the impact of this potentially unsafe behavior.
|
| 21/2 |
2026/08/31 21:21 |
tool |
codesearch-find-references |
0m
Args: map[Name:blk_register_tracepoints]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:get_probe_ref SourceFile:kernel/trace/blktrace.c SourceLine:492]] TruncatedOutput:false]
|
| 22/2 |
2026/08/31 21:21 |
llm |
debugger |
0m
Model:
Tokens:
input: 27505
output: 37
thoughts: 12
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**My Internal Code Review: get_probe_ref Call Site**
Alright, so I see this call is coming from `get_probe_ref`. That's the entry point, or at least a very important part of the pipeline. I need to immediately understand the context of *why* we are calling this function. What's the *purpose* of getting this probe reference at this point in the execution? Is this part of probe initialization? Is it an access check prior to a crucial operation? A defensive copy? What are the implications if this call fails or returns something unexpected?
My immediate questions are: What's the expected *type* of the probe being referenced here? Does `get_probe_ref` return a raw pointer, a smart pointer, or something else entirely? What are the lifecycle guarantees? Does this function manage the probe's lifetime, or is the caller responsible? What about thread safety? Are there any known race conditions in this section of code involving shared access to the probe? And critically, are there any known side effects from this call? I need to check the documentation or the implementation of `get_probe_ref` *immediately* to answer these questions.
I need to quickly assess the error handling: How are errors from `get_probe_ref` managed here? Is the failure handled gracefully? Is there comprehensive logging? Are appropriate exceptions thrown, or are there return codes? What is the *recovery* strategy? Is the program designed to handle probe unavailability gracefully or does it crash? I'll probably start by looking at the control flow around the `get_probe_ref` call to ensure I understand these scenarios.
|
| 23/2 |
2026/08/31 21:21 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:488 LineCount:15]
Results: map[Contents: 488: static void get_probe_ref(void)
489: {
490: mutex_lock(&blk_probe_mutex);
491: if (++blk_probes_ref == 1)
492: blk_register_tracepoints();
493: mutex_unlock(&blk_probe_mutex);
494: }
495:
496: static void put_probe_ref(void)
497: {
498: mutex_lock(&blk_probe_mutex);
499: if (!--blk_probes_ref)
500: blk_unregister_tracepoints();
501: mutex_unlock(&blk_probe_mutex);
502: }
]
|
| 24/2 |
2026/08/31 21:21 |
llm |
debugger |
0m
Model:
Tokens:
input: 28142
output: 23
thoughts: 23
Thoughts: Here's my thought process, as it stands:
**Analyzing the Void Return of `get_probe_ref`**
Okay, so `get_probe_ref` returns `void`. That immediately raises a flag. A `void` return means it's likely performing an action *without* providing a direct result. I need to understand what that action is. My primary concern is going to be where that action could be called, and what the dependencies might be. This strongly suggests that I must now figure out where this `get_probe_ref` function is called within the codebase. Is the function modifying an object directly, perhaps setting a member variable? Is it manipulating some global state? Or maybe it is meant to do nothing at all? The lack of a return value means the context of the call is absolutely crucial to understanding its purpose. I need to trace its usage to figure out its role. My next step is clearly to identify all call sites.
|
| 25/2 |
2026/08/31 21:22 |
tool |
codesearch-find-references |
0m
Args:
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:blk_trace_setup_finalize SourceFile:kernel/trace/blktrace.c SourceLine:759] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:blk_trace_setup_queue SourceFile:kernel/trace/blktrace.c SourceLine:1920]] TruncatedOutput:false]
|
| 26/2 |
2026/08/31 21:22 |
llm |
debugger |
0m
Model:
Tokens:
input: 28514
output: 37
thoughts: 23
Thoughts: Okay, here's my interpretation of those thoughts, presented as my own mental process, given my expertise:
**Diving into Block Tracing Initialization**
Alright, so the focus is on tracing setup, specifically `blk_trace_setup_finalize` and `blk_trace_setup_queue`. That immediately tells me we're dealing with the initialization and teardown of block device tracing, which is critical for performance analysis and debugging. The `finalize` function likely handles cleanup – freeing resources, disabling tracing on specific queues if necessary, and maybe writing final trace data if there's any buffering. I'll need to look at how it integrates with shutdown paths and error handling.
`blk_trace_setup_queue` is where the action starts. This is where the tracing hooks are probably being established for individual block queues, likely at device registration or queue creation time. The architecture should be interesting: are we using kprobes, ftrace, or something more specialized for the block layer? What events are we hooking? And, very importantly, how efficient is this setup? We need to minimize any overhead, particularly in high-IOPS environments. I'll want to assess the impact on context switches and cache coherency. Also, the parameters to this function are key -- what control knobs are we exposing to the user for things like filtering or sample rates? And how does it interact with things like the trace buffer allocation strategy (per-CPU, global, etc.)? I bet it needs to be thread safe too. The interactions with workqueues and interrupts would also be interesting. Need to keep in mind, potential race conditions and locking strategies as well.
|
| 27/2 |
2026/08/31 21:22 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:750 LineCount:20]
Results: map[Contents: 750: if (buts->start_lba)
751: bt->start_lba = buts->start_lba;
752: if (buts->end_lba)
753: bt->end_lba = buts->end_lba;
754:
755: bt->pid = buts->pid;
756: bt->trace_state = Blktrace_setup;
757:
758: rcu_assign_pointer(q->blk_trace, bt);
759: get_probe_ref();
760: }
761:
762: int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
763: struct block_device *bdev,
764: char __user *arg)
765: {
766: struct blk_user_trace_setup2 buts2;
767: struct blk_user_trace_setup buts;
768: struct blk_trace *bt;
769: unsigned int memflags;
]
|
| 28/2 |
2026/08/31 21:22 |
llm |
debugger |
0m
Model:
Tokens:
input: 29238
output: 38
thoughts: 10
Thoughts: Okay, here's my summary, presented as a first-person account, assuming I'm an expert in the field:
**Internalizing the `blk_trace_setup_queue` Process**
Alright, let's break down this `blk_trace_setup_queue` function. Thinking about it from a high level, I'm immediately focusing on the implications for tracing block I/O. This function *has* to be responsible for setting up the necessary infrastructure to capture and record the interactions between the kernel's block layer and the underlying storage devices, or I/O schedulers, or whatever abstraction it sits between.
So, digging deeper, I'm mentally parsing the likely steps. I suspect it'll start with the allocation of some control structures – probably things like trace buffers, filter tables, and maybe even some kind of per-queue context. These structures will hold the vital information about which requests to trace, where to store the resulting trace data, and how to format it. I'm wondering if this setup involves allocating a new trace buffer for a block device or if it uses existing buffers.
Then, there's the question of the actual *enabling* mechanism. It's likely that it needs to hook into the relevant points in the block I/O path. This means attaching tracepoints, kprobes, or ftrace events to the code paths that deal with request submission, completion, and merging. It has to make sure the tracing code runs. It probably needs to ensure that tracing is only enabled at the right time.
Beyond that, I'm also considering the locking implications. This is the kernel, after all. There's almost certainly going to be some form of locking involved to protect the trace structures from concurrent access from different CPUs or interrupt handlers. Probably a spinlock or a mutex. I'm guessing this function is carefully designed to avoid deadlocks.
The error handling is also key. What happens if memory allocation fails? What if the tracepoints can't be registered? Proper error checking and graceful degradation are essential here. I assume it'll return a meaningful error code if any of this setup fails, so that tracing initialization can be handled gracefully by a higher level function or the kernel's modules.
Finally, I'm thinking about the performance impact. This whole thing needs to be as lightweight as possible. It has to avoid introducing excessive overhead during normal I/O operations, which is why the design of this `blk_trace_setup_queue` function is so critical for the overall efficiency of the tracing. Ideally, the function would only set up the tracing framework, which, then, would be used elsewhere in the kernel to trace I/O operation.
|
| 29/2 |
2026/08/31 21:22 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1910 LineCount:20]
Results: map[Contents:1910: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
1911: if (!bt->msg_data)
1912: goto free_bt;
1913:
1914: bt->dev = bdev->bd_dev;
1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
]
|
| 30/2 |
2026/08/31 21:22 |
llm |
debugger |
0m
Model:
Tokens:
input: 30133
output: 41
thoughts: 85
Thoughts: **Analyzing the `get_probe_ref` Function Call**
Okay, so I'm digging into this code and trying to understand this sequence. It looks like `get_probe_ref` is getting called *after* `blk_trace` is properly set up and assigned to `q->blk_trace`. That's the expected order of operations based on what I see here.
But then, something's snagging me. I see that `blk_register_tracepoints` *doesn't* return an error if it fails; it just throws a warning. That seems a bit... unusual, given the importance of setting up tracepoints. The really curious part is that it now returns `void`. My first instinct is to find out *why* that return type was changed. I'm going to delve into the history of `blk_register_tracepoints` to see when and why this shift happened. Understanding the reasoning behind the change in return type will probably illuminate the design considerations here and might uncover some important nuances.
|
| 31/2 |
2026/08/31 21:22 |
tool |
git-log |
0m
Args: map[CodeRegexp:static void blk_register_tracepoints PathPrefix:kernel/trace/blktrace.c]
Results: map[Output:3c289ba7c320 blktrace: remove blk_probe_mutex
]
|
| 32/2 |
2026/08/31 21:22 |
llm |
debugger |
0m
Model:
Tokens:
input: 30511
output: 26
thoughts: 17
Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, in the first person and assuming an expert audience:
**Analyzing the Digital Signature `3c289ba7c320`**
Alright, let's take a look at this signature, `3c289ba7c320`. My immediate focus, as always, is on context. Is this a hash? A cryptographic signature? An identifier? Without knowing the originating system or the data it's tied to, drawing definitive conclusions is impossible, but based on its structure, my initial hypotheses are:
* **Potential Hash:** It's hex-encoded, which strongly suggests a hash or checksum. The length, if it’s a standard hash like MD5, SHA-1, or SHA-256 is an immediate flag. I need to know the length to start making some educated guesses, or I may even test the validity of the hash, based on common hash algorithms. It could also be a short hash if it came from something more obscure.
* **Cryptographic Component:** If it's part of a larger encrypted string, a signature, or a key identifier, its significance becomes dramatically different. I'll need to know the associated protocol or algorithm to deconstruct it, and whether its length is compatible with common crypto key sizes.
* **Identifier:** Could it be a short UID or object identifier within a specific system? If it came from a database or API, I would likely have more information about it.
My immediate next steps would be:
1. **Context Gathering:** Where did I encounter this string? What other associated data is available? What system or protocol is it related to?
2. **Length Analysis:** Determine the length in characters and bytes. This is the first step in determining it's likely significance, or even what algorithm it is.
3. **Algorithm Hypothesis:** Based on the length and context, I'd form hypotheses about the possible algorithms or data formats.
4. **Lookup:** Check against known databases of hashes and signatures, if applicable.
5. **Brute-Force (If Necessary):** I'd consider running it through common hash and cryptographic functions to attempt a reverse lookup, or a proof of concept. But I'll need the proper length, and information on whether it's the beginning, middle, or end.
6. **Deconstruction:** If it's part of a larger structure, I would attempt to identify its position and function within that structure.
7. **Correlation:** I would attempt to determine if it is related to other known digital footprints, or digital artifacts.
Ultimately, without knowing the origin, `3c289ba7c320` is just a string. However, I can draw many deductions just by looking at the structure. To understand it, I must understand its origin. I need context.
|
| 33/2 |
2026/08/31 21:22 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 3c289ba7c320560ee74979a8895141c829046a2d
Author: Li Zefan <lizf@cn.fujitsu.com>
Date: Fri Mar 20 09:48:26 2009 +0800
blktrace: remove blk_probe_mutex
blk_register_tracepoints() always returns 0, so make it return void,
thus we don't need to use blk_probe_mutex to protect blk_probes_ref.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <49C2F5EA.8060606@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 73845b7968bb..223b92e77b3f 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -47,10 +47,9 @@ static struct tracer_flags blk_tracer_flags = {
};
/* Global reference count of probes */
-static DEFINE_MUTEX(blk_probe_mutex);
static atomic_t blk_probes_ref = ATOMIC_INIT(0);
-static int blk_register_tracepoints(void);
+static void blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
/*
@@ -256,10 +255,8 @@ static void blk_trace_cleanup(struct blk_trace *bt)
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
- mutex_lock(&blk_probe_mutex);
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- mutex_unlock(&blk_probe_mutex);
}
int blk_trace_remove(struct request_queue *q)
@@ -471,13 +468,8 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
- mutex_lock(&blk_probe_mutex);
- if (atomic_add_return(1, &blk_probes_ref) == 1) {
- ret = blk_register_tracepoints();
- if (ret)
- goto probe_err;
- }
- mutex_unlock(&blk_probe_mutex);
+ if (atomic_add_return(1, &blk_probes_ref) == 1)
+ blk_register_tracepoints();
ret = -EBUSY;
old_bt = xchg(&q->blk_trace, bt);
@@ -487,9 +479,6 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
}
return 0;
-probe_err:
- atomic_dec(&blk_probes_ref);
- mutex_unlock(&blk_probe_mutex);
err:
if (bt) {
if (bt->msg_file)
@@ -863,7 +852,7 @@ void blk_add_driver_data(struct request_queue *q,
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static int blk_register_tracepoints(void)
+static void blk_register_tracepoints(void)
{
int ret;
@@ -901,7 +890,6 @@ static int blk_register_tracepoints(void)
WARN_ON(ret);
ret = register_trace_block_remap(blk_add_trace_remap);
WARN_ON(ret);
- return 0;
}
static void blk_unregister_tracepoints(void)
@@ -1099,11 +1087,8 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
- mutex_lock(&blk_probe_mutex);
if (atomic_add_return(1, &blk_probes_ref) == 1)
- if (blk_register_tracepoints())
- atomic_dec(&blk_probes_ref);
- mutex_unlock(&blk_probe_mutex);
+ blk_register_tracepoints();
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1118,10 +1103,8 @@ static int blk_tracer_init(struct trace_array *tr)
static void blk_tracer_stop(struct trace_array *tr)
{
trace_flags |= TRACE_ITER_CONTEXT_INFO;
- mutex_lock(&blk_probe_mutex);
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- mutex_unlock(&blk_probe_mutex);
}
static void blk_tracer_reset(struct trace_array *tr)
]
|
| 34/2 |
2026/08/31 21:22 |
llm |
debugger |
0m
Model:
Tokens:
input: 32657
output: 37
thoughts: 432
Thoughts: **Analyzing the "blk_register_tracepoints() always returns 0" Commit**
Okay, so this commit is suggesting that `blk_register_tracepoints()` *always* returns 0, and therefore should be `void`. But hold on, the individual `register_trace_block_*` functions actually return an `int`, and that `int` *can* be `-ENOMEM`, which triggers `WARN_ON(ret)`. That's the first red flag. Why did someone think it was always 0? Probably because back in 2009, those `register_trace_*` calls likely *didn't* fail, or perhaps failures were simply ignored, with 0 being returned anyway.
Let's dig deeper, say into `register_trace_block_rq_insert`. Right, it's a macro generated by either `DEFINE_TRACE` or `TRACE_EVENT`. Okay, in modern kernels, these macros eventually call `tracepoint_probe_register`, which *does* allocate memory, and thus *can* fail, returning `-ENOMEM`. And, as stated before, a failure triggers that `WARN_ON(ret)`.
But, what happens if it *does* fail? We have a registered block, but an unregistered tracepoint. The tracepoint isn't registered, so we simply won't get trace events for *that* specific point. That's not ideal, but it's not the end of the world. However, `WARN_ON` might cause a kernel panic if `panic_on_warn` is set. So, the simple solution seems to be removing the `WARN_ON(ret)`, right?
However, removing the `WARN_ON(ret)` seems like a hack. Should we handle the error properly? If we wanted to do it right, we'd need to unregister the already registered tracepoints and then return the error code. But, `blk_register_tracepoints` is called from `get_probe_ref`, which is, in turn, called from `blk_trace_setup_queue` and `blk_trace_setup_finalize`. Wait, now, `get_probe_ref` is called *after* `rcu_assign_pointer(q->blk_trace, bt)`. If `get_probe_ref` fails, we've got a problem, we need to undo the setup.
Alright, let's go back and look at `get_probe_ref` again.
|
| 35/2 |
2026/08/31 21:22 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:488 LineCount:15]
Results: map[Contents: 488: static void get_probe_ref(void)
489: {
490: mutex_lock(&blk_probe_mutex);
491: if (++blk_probes_ref == 1)
492: blk_register_tracepoints();
493: mutex_unlock(&blk_probe_mutex);
494: }
495:
496: static void put_probe_ref(void)
497: {
498: mutex_lock(&blk_probe_mutex);
499: if (!--blk_probes_ref)
500: blk_unregister_tracepoints();
501: mutex_unlock(&blk_probe_mutex);
502: }
]
|
| 36/2 |
2026/08/31 21:22 |
llm |
debugger |
0m
Model:
Tokens:
input: 33876
output: 38
thoughts: 108
Thoughts: **Considering Error Handling in Block Tracepoint Registration**
Okay, so I'm looking at this `blk_register_tracepoints` function and I'm thinking, what if we made it return an error code? That seems like a reasonable approach to signal failure. But, if we did that, we'd have a ripple effect. `get_probe_ref` would also need to return an error, which, okay, that's manageable. Then, `blk_trace_setup_queue` and `blk_trace_setup_finalize` would have to be modified to gracefully handle that potential error return.
Ah, hang on a second. Remind myself... `blk_trace_setup_finalize` is called within the context of an ioctl operation, right? And `blk_trace_setup_queue` is called from sysfs? Right, so ioctl and sysfs calls need to change. Let's dig into `blk_trace_setup_queue` first. It's the sysfs call, so it probably requires different considerations.
|
| 37/2 |
2026/08/31 21:23 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1915 LineCount:15]
Results: map[Contents:1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
]
|
| 38/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 34443
output: 30
thoughts: 105
Thoughts: **My Analysis of Block Device Tracepoint Registration**
Okay, so I'm wrestling with a potential failure scenario during block device tracepoint registration. The `get_probe_ref` function, if it fails, throws a wrench in the works. I need to be careful with resource cleanup here. If it fails, I've got to undo the `rcu_assign_pointer(q->blk_trace, bt)` call, essentially unassigning the trace structure, and then free the `bt` structure itself. It’s a standard rollback procedure.
But here's the kicker: `blk_register_tracepoints` registers these tracepoints globally, affecting *all* block devices in the system. So, a failure here isn't just a local issue; it signifies a systemic problem—the global tracepoints aren’t fully set up.
The question then becomes: how aggressive do I need to be about error handling? Should I just ignore the failure and avoid a `WARN`, or is a more proactive response needed? Is a single error really indicative of a major problem?
To get a clearer picture, I'll need to see how other subsystems deal with these tracepoint registration failures. I should check how they handle similar issues, whether they simply log the error, halt the process, or gracefully continue. That comparative analysis will help me make the best decision for this scenario.
|
| 39/2 |
2026/08/31 21:23 |
tool |
grepper |
0m
Args: map[Expression:register_trace_.*\( PathPrefix:kernel/trace/]
Results: map[Output:
Full output is too long, showing 500 out of 589 lines.
Use more precise expression if possible.
kernel/trace/blktrace.c=1327=static void blk_register_tracepoints(void)
--
kernel/trace/blktrace.c-1330-
kernel/trace/blktrace.c:1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1332- WARN_ON(ret);
kernel/trace/blktrace.c:1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c-1334- WARN_ON(ret);
kernel/trace/blktrace.c:1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c-1336- WARN_ON(ret);
kernel/trace/blktrace.c:1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c-1338- WARN_ON(ret);
kernel/trace/blktrace.c:1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c-1340- WARN_ON(ret);
kernel/trace/blktrace.c:1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c-1342- WARN_ON(ret);
kernel/trace/blktrace.c:1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c-1344- WARN_ON(ret);
kernel/trace/blktrace.c:1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c-1346- WARN_ON(ret);
kernel/trace/blktrace.c:1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c-1348- WARN_ON(ret);
kernel/trace/blktrace.c:1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c-1350- WARN_ON(ret);
kernel/trace/blktrace.c:1351: ret = register_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1352- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c-1353- WARN_ON(ret);
kernel/trace/blktrace.c:1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
kernel/trace/blktrace.c-1355- NULL);
kernel/trace/blktrace.c-1356- WARN_ON(ret);
kernel/trace/blktrace.c:1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
kernel/trace/blktrace.c-1358- NULL);
kernel/trace/blktrace.c-1359- WARN_ON(ret);
kernel/trace/blktrace.c:1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c-1361- WARN_ON(ret);
kernel/trace/blktrace.c:1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c-1363- WARN_ON(ret);
kernel/trace/blktrace.c:1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c-1365- WARN_ON(ret);
kernel/trace/blktrace.c:1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c-1367- WARN_ON(ret);
kernel/trace/blktrace.c:1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c-1369- WARN_ON(ret);
--
kernel/trace/blktrace.c=1372=static void blk_unregister_tracepoints(void)
kernel/trace/blktrace.c-1373-{
kernel/trace/blktrace.c:1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c:1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c:1376: unregister_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c:1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c:1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c:1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
kernel/trace/blktrace.c:1380: unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
kernel/trace/blktrace.c:1381: unregister_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1382- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c:1383: unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c:1384: unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c:1385: unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c:1386: unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c:1387: unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c:1388: unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c:1389: unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c:1390: unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c:1391: unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c:1392: unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1393-
--
kernel/trace/blktrace.c=1839=static int __init __init_blk_tracer(void)
kernel/trace/blktrace.c-1840-{
kernel/trace/blktrace.c:1841: if (!register_trace_event(&trace_blk_event)) {
kernel/trace/blktrace.c-1842- pr_warn("Warning: could not register block events\n");
--
kernel/trace/blktrace.c-1847- pr_warn("Warning: could not register the block tracer\n");
kernel/trace/blktrace.c:1848: unregister_trace_event(&trace_blk_event);
kernel/trace/blktrace.c-1849- return 1;
--
kernel/trace/fgraph.c=1236=static int start_graph_tracing(void)
--
kernel/trace/fgraph.c-1257- if (!ret) {
kernel/trace/fgraph.c:1258: ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
kernel/trace/fgraph.c-1259- if (ret)
--
kernel/trace/fgraph.c=1426=void unregister_ftrace_graph(struct fgraph_ops *gops)
--
kernel/trace/fgraph.c-1463- unregister_pm_notifier(&ftrace_suspend_notifier);
kernel/trace/fgraph.c:1464: unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
kernel/trace/fgraph.c-1465- }
--
kernel/trace/ftrace.c=8691=void ftrace_pid_follow_fork(struct trace_array *tr, bool enable)
--
kernel/trace/ftrace.c-8693- if (enable) {
kernel/trace/ftrace.c:8694: register_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
kernel/trace/ftrace.c-8695- tr);
kernel/trace/ftrace.c:8696: register_trace_sched_process_free(ftrace_pid_follow_sched_process_exit,
kernel/trace/ftrace.c-8697- tr);
kernel/trace/ftrace.c-8698- } else {
kernel/trace/ftrace.c:8699: unregister_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
kernel/trace/ftrace.c-8700- tr);
kernel/trace/ftrace.c:8701: unregister_trace_sched_process_free(ftrace_pid_follow_sched_process_exit,
kernel/trace/ftrace.c-8702- tr);
--
kernel/trace/ftrace.c=8706=static void clear_ftrace_pids(struct trace_array *tr, int type)
--
kernel/trace/ftrace.c-8722- if (!still_need_pid_events(type, pid_list, no_pid_list)) {
kernel/trace/ftrace.c:8723: unregister_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr);
kernel/trace/ftrace.c-8724- for_each_possible_cpu(cpu)
--
kernel/trace/ftrace.c=8932=pid_write(struct file *filp, const char __user *ubuf,
--
kernel/trace/ftrace.c-8983- /* Register a probe to set whether to ignore the tracing of a task */
kernel/trace/ftrace.c:8984: register_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr);
kernel/trace/ftrace.c-8985- }
--
kernel/trace/trace_branch.c=178=__init static int init_branch_tracer(void)
--
kernel/trace/trace_branch.c-181-
kernel/trace/trace_branch.c:182: ret = register_trace_event(&trace_branch_event);
kernel/trace/trace_branch.c-183- if (!ret) {
--
kernel/trace/trace_eprobe.c=77=static int eprobe_dyn_event_show(struct seq_file *m, struct dyn_event *ev)
--
kernel/trace/trace_eprobe.c-94-
kernel/trace/trace_eprobe.c:95:static int unregister_trace_eprobe(struct trace_eprobe *ep)
kernel/trace/trace_eprobe.c-96-{
--
kernel/trace/trace_eprobe.c=116=static int eprobe_dyn_event_release(struct dyn_event *ev)
--
kernel/trace/trace_eprobe.c-118- struct trace_eprobe *ep = to_trace_eprobe(ev);
kernel/trace/trace_eprobe.c:119: int ret = unregister_trace_eprobe(ep);
kernel/trace/trace_eprobe.c-120-
--
kernel/trace/trace_events.c=645=int trace_event_raw_init(struct trace_event_call *call)
--
kernel/trace/trace_events.c-648-
kernel/trace/trace_events.c:649: id = register_trace_event(&call->event);
kernel/trace/trace_events.c-650- if (!id)
--
kernel/trace/trace_events.c=1093=void trace_event_follow_fork(struct trace_array *tr, bool enable)
--
kernel/trace/trace_events.c-1095- if (enable) {
kernel/trace/trace_events.c:1096: register_trace_prio_sched_process_fork(event_filter_pid_sched_process_fork,
kernel/trace/trace_events.c-1097- tr, INT_MIN);
kernel/trace/trace_events.c:1098: register_trace_prio_sched_process_free(event_filter_pid_sched_process_exit,
kernel/trace/trace_events.c-1099- tr, INT_MAX);
kernel/trace/trace_events.c-1100- } else {
kernel/trace/trace_events.c:1101: unregister_trace_sched_process_fork(event_filter_pid_sched_process_fork,
kernel/trace/trace_events.c-1102- tr);
kernel/trace/trace_events.c:1103: unregister_trace_sched_process_free(event_filter_pid_sched_process_exit,
kernel/trace/trace_events.c-1104- tr);
--
kernel/trace/trace_events.c=1188=static void unregister_pid_events(struct trace_array *tr)
kernel/trace/trace_events.c-1189-{
kernel/trace/trace_events.c:1190: unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_pre, tr);
kernel/trace/trace_events.c:1191: unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_post, tr);
kernel/trace/trace_events.c-1192-
kernel/trace/trace_events.c:1193: unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1194: unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1195-
kernel/trace/trace_events.c:1196: unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1197: unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1198-
kernel/trace/trace_events.c:1199: unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1200: unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1201-}
--
kernel/trace/trace_events.c=2562=static void register_pid_events(struct trace_array *tr)
--
kernel/trace/trace_events.c-2569- */
kernel/trace/trace_events.c:2570: register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_pre,
kernel/trace/trace_events.c-2571- tr, INT_MAX);
kernel/trace/trace_events.c:2572: register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_post,
kernel/trace/trace_events.c-2573- tr, 0);
kernel/trace/trace_events.c-2574-
kernel/trace/trace_events.c:2575: register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2576- tr, INT_MAX);
kernel/trace/trace_events.c:2577: register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2578- tr, 0);
kernel/trace/trace_events.c-2579-
kernel/trace/trace_events.c:2580: register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2581- tr, INT_MAX);
kernel/trace/trace_events.c:2582: register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2583- tr, 0);
kernel/trace/trace_events.c-2584-
kernel/trace/trace_events.c:2585: register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2586- tr, INT_MAX);
kernel/trace/trace_events.c:2587: register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2588- tr, 0);
--
kernel/trace/trace_events.c=3350=static void event_remove(struct trace_event_call *call)
--
kernel/trace/trace_events.c-3372- if (call->event.funcs)
kernel/trace/trace_events.c:3373: __unregister_trace_event(&call->event);
kernel/trace/trace_events.c-3374- remove_event_from_tracers(call);
--
kernel/trace/trace_events_synth.c=955=static int register_synth_event(struct synth_event *event)
--
kernel/trace/trace_events_synth.c-977-
kernel/trace/trace_events_synth.c:978: ret = register_trace_event(&call->event);
kernel/trace/trace_events_synth.c-979- if (!ret) {
--
kernel/trace/trace_events_synth.c-999- ret = set_synth_event_print_fmt(call);
kernel/trace/trace_events_synth.c:1000: /* unregister_trace_event() will be called inside */
kernel/trace/trace_events_synth.c-1001- if (ret < 0)
--
kernel/trace/trace_events_synth.c-1005- err:
kernel/trace/trace_events_synth.c:1006: unregister_trace_event(&call->event);
kernel/trace/trace_events_synth.c-1007- goto out;
--
kernel/trace/trace_events_user.c=1966=static int user_event_trace_register(struct user_event *user)
--
kernel/trace/trace_events_user.c-1969-
kernel/trace/trace_events_user.c:1970: ret = register_trace_event(&user->call.event);
kernel/trace/trace_events_user.c-1971-
--
kernel/trace/trace_events_user.c-1977- if (ret)
kernel/trace/trace_events_user.c:1978: unregister_trace_event(&user->call.event);
kernel/trace/trace_events_user.c-1979-
--
kernel/trace/trace_fprobe.c=797=static int trace_fprobe_verify_target(struct trace_fprobe *tf)
--
kernel/trace/trace_fprobe.c-813-/* Internal register function - just handle fprobe and flags */
kernel/trace/trace_fprobe.c:814:static int __register_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-815-{
--
kernel/trace/trace_fprobe.c-841-/* Internal unregister function - just handle fprobe and flags */
kernel/trace/trace_fprobe.c:842:static void __unregister_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-843-{
--
kernel/trace/trace_fprobe.c-853-/* Unregister a trace_probe and probe_event */
kernel/trace/trace_fprobe.c:854:static int unregister_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-855-{
--
kernel/trace/trace_fprobe.c-872-unreg:
kernel/trace/trace_fprobe.c:873: __unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-874- dyn_event_remove(&tf->devent);
--
kernel/trace/trace_fprobe.c=908=static int append_trace_fprobe_event(struct trace_fprobe *tf, struct trace_fprobe *to)
--
kernel/trace/trace_fprobe.c-945-/* Register a trace_probe and probe_event, and check the fprobe is available. */
kernel/trace/trace_fprobe.c:946:static int register_trace_fprobe_event(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-947-{
--
kernel/trace/trace_fprobe.c=1209=static int trace_fprobe_create_internal(int argc, const char *argv[],
--
kernel/trace/trace_fprobe.c-1378-
kernel/trace/trace_fprobe.c:1379: ret = register_trace_fprobe_event(tf);
kernel/trace/trace_fprobe.c-1380- if (ret) {
--
kernel/trace/trace_fprobe.c=1419=static int trace_fprobe_release(struct dyn_event *ev)
--
kernel/trace/trace_fprobe.c-1421- struct trace_fprobe *tf = to_trace_fprobe(ev);
kernel/trace/trace_fprobe.c:1422: int ret = unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1423-
--
kernel/trace/trace_fprobe.c=1457=static int enable_trace_fprobe(struct trace_event_call *call,
--
kernel/trace/trace_fprobe.c-1479- list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) {
kernel/trace/trace_fprobe.c:1480: ret = __register_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1481- if (ret < 0)
--
kernel/trace/trace_fprobe.c-1490- list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list)
kernel/trace/trace_fprobe.c:1491: __unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1492- if (file)
--
kernel/trace/trace_functions_graph.c=1814=static __init int init_graph_trace(void)
--
kernel/trace/trace_functions_graph.c-1817-
kernel/trace/trace_functions_graph.c:1818: if (!register_trace_event(&graph_trace_entry_event)) {
kernel/trace/trace_functions_graph.c-1819- pr_warn("Warning: could not register graph trace events\n");
--
kernel/trace/trace_functions_graph.c-1823-#ifdef CONFIG_FUNCTION_GRAPH_RETADDR
kernel/trace/trace_functions_graph.c:1824: if (!register_trace_event(&graph_trace_retaddr_entry_event)) {
kernel/trace/trace_functions_graph.c-1825- pr_warn("Warning: could not register graph trace retaddr events\n");
--
kernel/trace/trace_functions_graph.c-1829-
kernel/trace/trace_functions_graph.c:1830: if (!register_trace_event(&graph_trace_ret_event)) {
kernel/trace/trace_functions_graph.c-1831- pr_warn("Warning: could not register graph trace events\n");
--
kernel/trace/trace_kprobe.c=469=static bool within_notrace_func(struct trace_kprobe *tk)
--
kernel/trace/trace_kprobe.c-494-/* Internal register function - just handle k*probes and flags */
kernel/trace/trace_kprobe.c:495:static int __register_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-496-{
--
kernel/trace/trace_kprobe.c-532-/* Internal unregister function - just handle k*probes and flags */
kernel/trace/trace_kprobe.c:533:static void __unregister_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-534-{
--
kernel/trace/trace_kprobe.c-548-/* Unregister a trace_probe and probe_event */
kernel/trace/trace_kprobe.c:549:static int unregister_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-550-{
--
kernel/trace/trace_kprobe.c-567-unreg:
kernel/trace/trace_kprobe.c:568: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-569- dyn_event_remove(&tk->devent);
--
kernel/trace/trace_kprobe.c=604=static int append_trace_kprobe(struct trace_kprobe *tk, struct trace_kprobe *to)
--
kernel/trace/trace_kprobe.c-626- /* Register k*probe */
kernel/trace/trace_kprobe.c:627: ret = __register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-628- if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) {
--
kernel/trace/trace_kprobe.c-641-/* Register a trace_probe and probe_event */
kernel/trace/trace_kprobe.c:642:static int register_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-643-{
--
kernel/trace/trace_kprobe.c-671- /* Register k*probe */
kernel/trace/trace_kprobe.c:672: ret = __register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-673- if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) {
--
kernel/trace/trace_kprobe.c=689=static int register_module_trace_kprobe(struct module *mod, struct trace_kprobe *tk)
--
kernel/trace/trace_kprobe.c-697- if (!ret)
kernel/trace/trace_kprobe.c:698: ret = __register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-699- return ret;
--
kernel/trace/trace_kprobe.c=703=static int trace_kprobe_module_callback(struct notifier_block *nb,
--
kernel/trace/trace_kprobe.c-718- /* Don't need to check busy - this should have gone. */
kernel/trace/trace_kprobe.c:719: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-720- ret = register_module_trace_kprobe(mod, tk);
--
kernel/trace/trace_kprobe.c=854=static int trace_kprobe_create_internal(int argc, const char *argv[],
--
kernel/trace/trace_kprobe.c-1076-
kernel/trace/trace_kprobe.c:1077: ret = register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1078- if (ret) {
--
kernel/trace/trace_kprobe.c=1298=static int trace_kprobe_release(struct dyn_event *ev)
--
kernel/trace/trace_kprobe.c-1300- struct trace_kprobe *tk = to_trace_kprobe(ev);
kernel/trace/trace_kprobe.c:1301: int ret = unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1302-
--
kernel/trace/trace_kprobe.c=1933=create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
--
kernel/trace/trace_kprobe.c-1970-
kernel/trace/trace_kprobe.c:1971: ret = __register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1972- if (ret < 0)
--
kernel/trace/trace_kprobe.c=1978=void destroy_local_trace_kprobe(struct trace_event_call *event_call)
--
kernel/trace/trace_kprobe.c-1990-
kernel/trace/trace_kprobe.c:1991: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1992-
--
kernel/trace/trace_osnoise.c=1004=static int hook_irq_events(void)
--
kernel/trace/trace_osnoise.c-1007-
kernel/trace/trace_osnoise.c:1008: ret = register_trace_irq_handler_entry(trace_irqentry_callback, NULL);
kernel/trace/trace_osnoise.c-1009- if (ret)
--
kernel/trace/trace_osnoise.c-1011-
kernel/trace/trace_osnoise.c:1012: ret = register_trace_irq_handler_exit(trace_irqexit_callback, NULL);
kernel/trace/trace_osnoise.c-1013- if (ret)
--
kernel/trace/trace_osnoise.c-1022-out_irq_exit:
kernel/trace/trace_osnoise.c:1023: unregister_trace_irq_handler_exit(trace_irqexit_callback, NULL);
kernel/trace/trace_osnoise.c-1024-out_unregister_entry:
kernel/trace/trace_osnoise.c:1025: unregister_trace_irq_handler_entry(trace_irqentry_callback, NULL);
kernel/trace/trace_osnoise.c-1026-out_err:
--
kernel/trace/trace_osnoise.c=1036=static void unhook_irq_events(void)
--
kernel/trace/trace_osnoise.c-1038- osnoise_arch_unregister();
kernel/trace/trace_osnoise.c:1039: unregister_trace_irq_handler_exit(trace_irqexit_callback, NULL);
kernel/trace/trace_osnoise.c:1040: unregister_trace_irq_handler_entry(trace_irqentry_callback, NULL);
kernel/trace/trace_osnoise.c-1041-}
--
kernel/trace/trace_osnoise.c=1100=static int hook_softirq_events(void)
--
kernel/trace/trace_osnoise.c-1103-
kernel/trace/trace_osnoise.c:1104: ret = register_trace_softirq_entry(trace_softirq_entry_callback, NULL);
kernel/trace/trace_osnoise.c-1105- if (ret)
--
kernel/trace/trace_osnoise.c-1107-
kernel/trace/trace_osnoise.c:1108: ret = register_trace_softirq_exit(trace_softirq_exit_callback, NULL);
kernel/trace/trace_osnoise.c-1109- if (ret)
--
kernel/trace/trace_osnoise.c-1114-out_unreg_entry:
kernel/trace/trace_osnoise.c:1115: unregister_trace_softirq_entry(trace_softirq_entry_callback, NULL);
kernel/trace/trace_osnoise.c-1116-out_err:
--
kernel/trace/trace_osnoise.c=1126=static void unhook_softirq_events(void)
kernel/trace/trace_osnoise.c-1127-{
kernel/trace/trace_osnoise.c:1128: unregister_trace_softirq_entry(trace_softirq_entry_callback, NULL);
kernel/trace/trace_osnoise.c:1129: unregister_trace_softirq_exit(trace_softirq_exit_callback, NULL);
kernel/trace/trace_osnoise.c-1130-}
--
kernel/trace/trace_osnoise.c=1239=static int register_migration_monitor(void)
--
kernel/trace/trace_osnoise.c-1250-
kernel/trace/trace_osnoise.c:1251: ret = register_trace_sched_migrate_task(trace_sched_migrate_callback, NULL);
kernel/trace/trace_osnoise.c-1252- if (!ret)
--
kernel/trace/trace_osnoise.c=1259=static void unregister_migration_monitor(void)
--
kernel/trace/trace_osnoise.c-1263-
kernel/trace/trace_osnoise.c:1264: unregister_trace_sched_migrate_task(trace_sched_migrate_callback, NULL);
kernel/trace/trace_osnoise.c-1265- monitor_enabled = false;
--
kernel/trace/trace_osnoise.c=1302=static int hook_thread_events(void)
--
kernel/trace/trace_osnoise.c-1305-
kernel/trace/trace_osnoise.c:1306: ret = register_trace_sched_switch(trace_sched_switch_callback, NULL);
kernel/trace/trace_osnoise.c-1307- if (ret)
--
kernel/trace/trace_osnoise.c-1316-out_unreg:
kernel/trace/trace_osnoise.c:1317: unregister_trace_sched_switch(trace_sched_switch_callback, NULL);
kernel/trace/trace_osnoise.c-1318- return -EINVAL;
--
kernel/trace/trace_osnoise.c=1327=static void unhook_thread_events(void)
kernel/trace/trace_osnoise.c-1328-{
kernel/trace/trace_osnoise.c:1329: unregister_trace_sched_switch(trace_sched_switch_callback, NULL);
kernel/trace/trace_osnoise.c-1330- unregister_migration_monitor();
--
kernel/trace/trace_output.c=862=void trace_event_read_unlock(void)
--
kernel/trace/trace_output.c-881- */
kernel/trace/trace_output.c:882:int register_trace_event(struct trace_event *event)
kernel/trace/trace_output.c-883-{
--
kernel/trace/trace_output.c=924=EXPORT_SYMBOL_GPL(register_trace_event);
--
kernel/trace/trace_output.c-928- */
kernel/trace/trace_output.c:929:int __unregister_trace_event(struct trace_event *event)
kernel/trace/trace_output.c-930-{
--
kernel/trace/trace_output.c-939- */
kernel/trace/trace_output.c:940:int unregister_trace_event(struct trace_event *event)
kernel/trace/trace_output.c-941-{
kernel/trace/trace_output.c-942- down_write(&trace_event_sem);
kernel/trace/trace_output.c:943: __unregister_trace_event(event);
kernel/trace/trace_output.c-944- up_write(&trace_event_sem);
--
kernel/trace/trace_output.c=1922=__init int init_events(void)
--
kernel/trace/trace_output.c-1928- event = events[i];
kernel/trace/trace_output.c:1929: ret = register_trace_event(event);
kernel/trace/trace_output.c-1930- WARN_ONCE(!ret, "event %d failed to register", event->type);
--
kernel/trace/trace_output.h=43=trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry);
--
kernel/trace/trace_output.h-45-/* used by module unregistering */
kernel/trace/trace_output.h:46:extern int __unregister_trace_event(struct trace_event *event);
kernel/trace/trace_output.h-47-extern struct rw_semaphore trace_event_sem;
--
kernel/trace/trace_probe.c=2691=int trace_probe_register_event_call(struct trace_probe *tp)
--
kernel/trace/trace_probe.c-2701-
kernel/trace/trace_probe.c:2702: ret = register_trace_event(&call->event);
kernel/trace/trace_probe.c-2703- if (!ret)
--
kernel/trace/trace_probe.c-2707- if (ret)
kernel/trace/trace_probe.c:2708: unregister_trace_event(&call->event);
kernel/trace/trace_probe.c-2709-
--
kernel/trace/trace_sched_switch.c=52=static int tracing_sched_register(void)
--
kernel/trace/trace_sched_switch.c-55-
kernel/trace/trace_sched_switch.c:56: ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-57- if (ret) {
--
kernel/trace/trace_sched_switch.c-62-
kernel/trace/trace_sched_switch.c:63: ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-64- if (ret) {
--
kernel/trace/trace_sched_switch.c-69-
kernel/trace/trace_sched_switch.c:70: ret = register_trace_sched_switch(probe_sched_switch, NULL);
kernel/trace/trace_sched_switch.c-71- if (ret) {
--
kernel/trace/trace_sched_switch.c-78-fail_deprobe_wake_new:
kernel/trace/trace_sched_switch.c:79: unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-80-fail_deprobe:
kernel/trace/trace_sched_switch.c:81: unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-82- return ret;
--
kernel/trace/trace_sched_switch.c=85=static void tracing_sched_unregister(void)
kernel/trace/trace_sched_switch.c-86-{
kernel/trace/trace_sched_switch.c:87: unregister_trace_sched_switch(probe_sched_switch, NULL);
kernel/trace/trace_sched_switch.c:88: unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c:89: unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-90-}
--
kernel/trace/trace_sched_wakeup.c=612=static void start_wakeup_tracer(struct trace_array *tr)
--
kernel/trace/trace_sched_wakeup.c-615-
kernel/trace/trace_sched_wakeup.c:616: ret = register_trace_sched_wakeup(probe_wakeup, NULL);
kernel/trace/trace_sched_wakeup.c-617- if (ret) {
--
kernel/trace/trace_sched_wakeup.c-622-
kernel/trace/trace_sched_wakeup.c:623: ret = register_trace_sched_wakeup_new(probe_wakeup, NULL);
kernel/trace/trace_sched_wakeup.c-624- if (ret) {
--
kernel/trace/trace_sched_wakeup.c-629-
kernel/trace/trace_sched_wakeup.c:630: ret = register_trace_sched_switch(probe_wakeup_sched_switch, NULL);
kernel/trace/trace_sched_wakeup.c-631- if (ret) {
--
kernel/trace/trace_sched_wakeup.c-636-
kernel/trace/trace_sched_wakeup.c:637: ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
kernel/trace/trace_sched_wakeup.c-638- if (ret) {
]
|
| 40/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 46054
output: 36
thoughts: 464
Thoughts: **Analyzing Tracepoint Registration and Error Handling**
Okay, so I'm looking at this code, specifically `trace_output.c:1929`, and I see this `WARN_ONCE` about a failed event registration: `WARN_ONCE(!ret, "event %d failed to register", event->type)`. But then over in `blktrace.c`, it's just a `WARN_ON(ret)`. That's a bit odd. I know these `register_trace_*` functions return an integer, typically an error code, like `-ENOMEM` if it fails.
Right, so I checked `trace_sched_switch.c` as an example: it explicitly handles the error with a check:
```c
ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL);
if (ret) {
pr_info("wakeup trace: Couldn't activate tracepoint"
" probe to kernel_sched_wakeup\n");
return ret;
}
```
It handles the error and returns. But `blk_register_tracepoints` just uses `WARN_ON`. Why is that? Ah, it was written back in 2008 and modified in 2009 to return `void`. So it's not designed to handle errors explicitly, which is what's causing the problem.
If I just change `blk_register_tracepoints` to ignore the error or use `pr_warn`, that'll fix the crash, but will that be the right thing to do? Wait, if it *fails* to register some tracepoints, `blktrace` will be only partially broken. Some events won't be traced! Is it better to return an error and fail `blk_trace_setup` altogether? That's a tough call.
If I return an error, I need to unregister the already registered tracepoints. I need to make sure I don't leave things in a broken state. Hmm, there are 19 tracepoints involved here. So, if I return an error, I can just call `blk_unregister_tracepoints()` and return the error. It would be a clean shutdown. But wait, `blk_unregister_tracepoints()` unregisters *all* of them. Is it safe to unregister a tracepoint that wasn't successfully registered? I need to check.
Yes, `unregister_trace_*` calls `tracepoint_probe_unregister`, and that returns `-ENODEV` if the probe wasn't found. Okay, so that's safe. It handles the scenario where a probe wasn't actually registered. I'm going to quickly check `tracepoint_probe_unregister` to be extra sure.
|
| 41/2 |
2026/08/31 21:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/tracepoint.c Name:tracepoint_probe_unregister]
Results: map[SourceCode: 499: /**
500: * tracepoint_probe_unregister - Disconnect a probe from a tracepoint
501: * @tp: tracepoint
502: * @probe: probe function pointer
503: * @data: tracepoint data
504: *
505: * Returns 0 if ok, error value on error.
506: */
507: int tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data)
508: {
509: struct tracepoint_func tp_func;
510: int ret;
511:
512: mutex_lock(&tracepoints_mutex);
513: tp_func.func = probe;
514: tp_func.data = data;
515: ret = tracepoint_remove_func(tp, &tp_func);
516: mutex_unlock(&tracepoints_mutex);
517: return ret;
518: }
SourceFile:kernel/tracepoint.c]
|
| 42/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 47456
output: 38
thoughts: 285
Thoughts: **My Reasoning on the Tracepoint Registration**
Okay, so the preliminary assessment is that this is safe; we *can* change `blk_register_tracepoints` to return an integer. Here's the original code:
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
goto err;
...
err:
blk_unregister_tracepoints();
return ret;
}
```
Now, I need to consider the implications. `blk_register_tracepoints` is called by `get_probe_ref`, which is interesting:
```c
static int get_probe_ref(void)
{
int ret = 0;
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1) {
ret = blk_register_tracepoints();
if (ret)
blk_probes_ref--;
}
mutex_unlock(&blk_probe_mutex);
return ret;
}
```
Ah, that's crucial. If `get_probe_ref` starts returning an error code from `blk_register_tracepoints`, I *must* handle that error condition. That means checking `blk_trace_setup_queue` and `blk_trace_setup_finalize` to see how they currently handle (or don't handle) the return value from `get_probe_ref`. Time to investigate those functions.
|
| 43/2 |
2026/08/31 21:23 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1915 LineCount:15]
Results: map[Contents:1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
]
|
| 44/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 48333
output: 38
thoughts: 153
Thoughts: **My Immediate Concerns Regarding the `get_probe_ref` Change**
Okay, so we're changing `get_probe_ref` to potentially return an error. Let's think through this new flow: I'm seeing that we now have:
```c
ret = get_probe_ref();
if (ret) {
rcu_assign_pointer(q->blk_trace, NULL);
goto free_bt;
}
return 0;
```
Right away, alarm bells are going off. We're assigning `NULL` to `q->blk_trace` *after* a potential failure. The critical point is the `rcu_assign_pointer`. I know that `rcu_assign_pointer(q->blk_trace, bt)` *makes* that pointer visible to readers. If `get_probe_ref` fails *after* this assignment, and we immediately set it to `NULL`, we have a potential data race here. We need to consider how RCU (Read-Copy-Update) synchronization plays into this. If we immediately assign NULL after making the blk_trace visible, we likely need to ensure any RCU readers have completed their access of `bt` before freeing it.
I'm thinking, `blk_trace_free` which, I *believe*, contains the `kfree(bt)` call. This needs to be carefully scrutinized. The important question is, does `blk_trace_free` use `kfree_rcu` or `synchronize_rcu` to protect the freeing of the blk_trace? If not, we have a significant RCU hazard. We need to be absolutely certain of the memory management strategy within `blk_trace_free` to avoid any dangling pointers or data corruption. This warrants a very deep dive into that function, *right now*.
|
| 45/2 |
2026/08/31 21:23 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/trace/blktrace.c Name:blk_trace_free]
Results: map[SourceCode: 469: static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
470: {
471: relay_close(bt->rchan);
472:
473: /*
474: * If 'bt->dir' is not set, then both 'dropped' and 'msg' are created
475: * under 'q->debugfs_dir', thus lookup and remove them.
476: */
477: if (!bt->dir) {
478: debugfs_lookup_and_remove("dropped", q->debugfs_dir);
479: debugfs_lookup_and_remove("msg", q->debugfs_dir);
480: } else {
481: debugfs_remove(bt->dir);
482: }
483: free_percpu(bt->sequence);
484: free_percpu(bt->msg_data);
485: kfree(bt);
486: }
SourceFile:kernel/trace/blktrace.c]
|
| 46/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 49236
output: 38
thoughts: 513
Thoughts: **Analyzing the `blk_trace` Cleanup and RCU Interactions**
Okay, so I'm looking at this `kfree(bt)` call, and immediately the RCU interactions are flashing red in my mind. If `rcu_assign_pointer(q->blk_trace, bt)` is used, and then we have an error and end up calling `rcu_assign_pointer(q->blk_trace, NULL)`, we *must* wait for an RCU grace period before freeing `bt`. Otherwise, we could have a use-after-free issue.
Currently, I see `blk_trace_free` doesn't do that waiting. Hmmm... But then I remember `blk_trace_remove` *does* perform this properly. It uses `rcu_replace_pointer`, and if the replacement is successful, it calls `blk_trace_cleanup`. Let's refresh our memories on that:
```c
int blk_trace_remove(struct request_queue *q)
{
struct blk_trace *bt;
bt = rcu_replace_pointer(q->blk_trace, NULL,
lockdep_is_held(&q->debugfs_mutex));
if (!bt)
return -EINVAL;
if (bt->trace_state != Blktrace_running)
blk_trace_cleanup(bt);
return 0;
}
```
And `blk_trace_cleanup` does:
```c
static void blk_trace_cleanup(struct blk_trace *bt)
{
synchronize_rcu();
blk_trace_free(bt->q, bt);
put_probe_ref();
}
```
Okay, so `blk_trace_cleanup` calls `synchronize_rcu()`, ensuring the grace period. So, if we fail in `blk_trace_setup_queue` *after* we've done the `rcu_assign_pointer`, we should, in theory, call `blk_trace_cleanup(bt)` instead of a bare `blk_trace_free(q, bt)`. Got it.
But... wait. `blk_trace_cleanup` also calls `put_probe_ref()`, which decrements `blk_probes_ref`. If `get_probe_ref` failed, we didn't increment it, right? So we don't want to decrement in the cleanup. Ok, this is important. So we *could* do something like this:
```c
ret = get_probe_ref();
if (ret) {
rcu_assign_pointer(q->blk_trace, NULL);
synchronize_rcu();
blk_trace_free(q, bt);
return ret;
}
```
But, wait... why not simply call `get_probe_ref()` *before* we even assign the pointer with RCU? That seems like the cleanest and safest solution. We can then avoid all this conditional logic and keep things simpler. Let's revisit `blk_trace_setup_queue` and see what the original logic was to check for a ref.
|
| 47/2 |
2026/08/31 21:23 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1900 LineCount:30]
Results: map[Contents:1900: static int blk_trace_setup_queue(struct request_queue *q,
1901: struct block_device *bdev)
1902: {
1903: struct blk_trace *bt = NULL;
1904: int ret = -ENOMEM;
1905:
1906: bt = kzalloc_obj(*bt);
1907: if (!bt)
1908: return -ENOMEM;
1909:
1910: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
1911: if (!bt->msg_data)
1912: goto free_bt;
1913:
1914: bt->dev = bdev->bd_dev;
1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
]
|
| 48/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 50898
output: 37
thoughts: 98
Thoughts: **My Analysis of RCU and Probe References**
Okay, so I'm looking at this snippet of code and thinking about how to handle the reference counting with respect to RCU synchronization. It's pretty straightforward, actually. If `get_probe_ref()` fails *before* we even get to `rcu_assign_pointer()`, then we don't have to concern ourselves with RCU synchronization headaches. The `goto free_bt` takes care of the cleanup in that failure scenario, which is as expected. That simplifies things significantly; it means the failure case doesn't have any RCU-related considerations. No need to worry about races if we haven't successfully obtained the probe reference.
But, I need to zoom out a bit. Now I need to think about `blk_trace_setup_finalize`. This is where the real trickery will be. How does that interact with the newly updated `blk_trace` pointer? What are the synchronization requirements during finalization? Are we making sure the grace period is complete before touching `blk_trace`? I need to analyze its implementation to ensure the memory model is respected. I hope it has been considered carefully. I need to make sure I am not missing any critical edge cases.
|
| 49/2 |
2026/08/31 21:23 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:740 LineCount:25]
Results: map[Contents: 740: * to underscores for this to work as expected
741: */
742: strreplace(buts->name, '/', '_');
743:
744: bt->version = version;
745: bt->act_mask = buts->act_mask;
746: if (!bt->act_mask)
747: bt->act_mask = (u16) -1;
748:
749: /* overwrite with user settings */
750: if (buts->start_lba)
751: bt->start_lba = buts->start_lba;
752: if (buts->end_lba)
753: bt->end_lba = buts->end_lba;
754:
755: bt->pid = buts->pid;
756: bt->trace_state = Blktrace_setup;
757:
758: rcu_assign_pointer(q->blk_trace, bt);
759: get_probe_ref();
760: }
761:
762: int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
763: struct block_device *bdev,
764: char __user *arg)
]
|
| 50/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 51679
output: 37
thoughts: 21
Thoughts: Okay, here's my interpretation of that thought process, as if it were my own:
**Analyzing the Block Trace Setup Flow**
Right, so I see `blk_trace_setup_finalize` being called directly from `do_blk_trace_setup`. That's a key point. This means the finalization steps for the block trace setup are *tightly coupled* to the initial setup process. There isn't any kind of intervening function or stage. We're talking about a very direct handoff. I immediately start thinking about potential implications here:
* **Order of Operations:** The call order is crucial. Finalization *follows* setup directly. Any dependency on setup completion will be guaranteed, which is good. But it also means any error during finalization could be more complex to trace back to the original setup problems.
* **Resource Management:** What resources are being set up and then finalized? Understanding this relationship is critical. Are we talking about allocating and freeing memory? Initializing and de-initializing data structures? Any potential resource leaks or race conditions will be highly localized within these two functions.
* **Error Handling:** The direct call suggests a simple error handling strategy. Is there error checking *within* `do_blk_trace_setup` that might directly feed into the finalization process? Or, is error handling more distributed, and this call is assumed to be safe? The latter would be unusual but potentially valid, depending on the system's architecture.
* **Context:** What context is being passed between these functions? Are they sharing data, or is finalization solely operating on what the setup established? This will determine how modifications in one function affect the other.
* **Potential Bottlenecks:** This relationship looks efficient, but that is dependent on the workload. Is it possible for these functions to become a bottleneck? Could parallelization or asynchronous operations be used for greater efficiency?
I'll need to dig deeper into the actual code within those functions to understand the specifics, but this direct call is definitely a focal point for understanding the system's behavior. It likely has major implications for tracing's performance and stability.
|
| 51/2 |
2026/08/31 21:23 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:690 LineCount:50]
Results: map[Contents: 690: * directory that will be removed once the trace ends.
691: */
692: if (bdev && !bdev_is_partition(bdev))
693: dir = q->debugfs_dir;
694: else
695: bt->dir = dir = debugfs_create_dir(name, blk_debugfs_root);
696:
697: /*
698: * As blktrace relies on debugfs for its interface the debugfs directory
699: * is required, contrary to the usual mantra of not checking for debugfs
700: * files or directories.
701: */
702: if (IS_ERR_OR_NULL(dir)) {
703: pr_warn("debugfs_dir not present for %s so skipping\n", name);
704: ret = -ENOENT;
705: goto err;
706: }
707:
708: bt->dev = dev;
709: INIT_LIST_HEAD(&bt->running_list);
710:
711: ret = -EIO;
712: debugfs_create_file("dropped", 0444, dir, bt, &blk_dropped_fops);
713: debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
714:
715: bt->rchan = relay_open("trace", dir, buf_size, buf_nr,
716: &blk_relay_callbacks, bt);
717: if (!bt->rchan)
718: goto err;
719:
720: blk_trace_setup_lba(bt, bdev);
721:
722: return bt;
723:
724: err:
725: blk_trace_free(q, bt);
726:
727: return ERR_PTR(ret);
728: }
729:
730: static void blk_trace_setup_finalize(struct request_queue *q,
731: char *name, int version,
732: struct blk_trace *bt,
733: struct blk_user_trace_setup2 *buts)
734:
735: {
736: strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
737:
738: /*
739: * some device names have larger paths - convert the slashes
]
|
| 52/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 52934
output: 37
thoughts: 19
Thoughts: Here's a summary of my understanding, framed as my own thoughts:
**Dissecting the `blk_trace` Setup Sequence**
Okay, so I'm looking at how the tracing system for block devices, specifically `blk_trace`, is initialized. It seems the primary setup function is `blk_trace_setup`. That's where it all begins. And from what I'm reading, within that setup routine, there's a call to `blk_trace_setup_finalize`. So, `blk_trace_setup` sets the stage and `blk_trace_setup_finalize` is used to complete the setup process. It's a two-stage approach. Presumably, `blk_trace_setup` handles the initial allocation and configuration, while `blk_trace_setup_finalize` likely takes care of any necessary finalization steps or linking up of resources, once the basic structure is ready. Let me dig deeper into those two calls, to discover what specific initialization procedures are handled by each of those functions.
|
| 53/2 |
2026/08/31 21:23 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:762 LineCount:40]
Results: map[Contents: 762: int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
763: struct block_device *bdev,
764: char __user *arg)
765: {
766: struct blk_user_trace_setup2 buts2;
767: struct blk_user_trace_setup buts;
768: struct blk_trace *bt;
769: unsigned int memflags;
770: int ret;
771:
772: ret = copy_from_user(&buts, arg, sizeof(buts));
773: if (ret)
774: return -EFAULT;
775:
776: if (!buts.buf_size || !buts.buf_nr)
777: return -EINVAL;
778:
779: buts2 = (struct blk_user_trace_setup2) {
780: .act_mask = buts.act_mask,
781: .buf_size = buts.buf_size,
782: .buf_nr = buts.buf_nr,
783: .start_lba = buts.start_lba,
784: .end_lba = buts.end_lba,
785: .pid = buts.pid,
786: };
787:
788: memflags = blk_debugfs_lock(q);
789: bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
790: bdev);
791: if (IS_ERR(bt)) {
792: blk_debugfs_unlock(q, memflags);
793: return PTR_ERR(bt);
794: }
795: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
796: strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
797: blk_debugfs_unlock(q, memflags);
798:
799: if (copy_to_user(arg, &buts, sizeof(buts))) {
800: blk_trace_remove(q);
801: return -EFAULT;
]
|
| 54/2 |
2026/08/31 21:23 |
llm |
debugger |
0m
Model:
Tokens:
input: 53879
output: 37
thoughts: 550
Thoughts: **Refining the Error Handling in Block Trace Setup**
Okay, so I'm looking at this `blk_trace_setup_finalize` function and thinking about how we handle errors, particularly if `get_probe_ref` fails. Currently, if that function call fails, we just continue on, which seems... less than ideal. My initial thought was, "Hey, why don't we just make `blk_trace_setup_finalize` return an error code? Then `blk_trace_setup` would catch that, call `blk_trace_free(q, bt)`, and return the error. Simple enough, right?"
But then I re-read the code and saw the `rcu_assign_pointer(q->blk_trace, bt)` call. Ah, that's the bit that's causing the problem. We have to assign the `blk_trace` pointer to the request queue *before* the error check, if we want to follow the code as it is.
The solution is to move `get_probe_ref()` call *before* `rcu_assign_pointer(q->blk_trace, bt)`. It's a clean and elegant fix that addresses the core issue. By changing the order, if `get_probe_ref` returns an error, we simply return that error. `blk_trace_setup` can then take care of freeing the trace data. That way, we aren't introducing a race condition.
And since `blk_trace_setup2` also uses this function, this change will simplify error handling in that context as well. Done.
|
| 55/2 |
2026/08/31 21:24 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:802 LineCount:40]
Results: map[Contents: 802: }
803: return 0;
804: }
805: EXPORT_SYMBOL_GPL(blk_trace_setup);
806:
807: static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
808: struct block_device *bdev, char __user *arg)
809: {
810: struct blk_user_trace_setup2 buts2;
811: struct blk_trace *bt;
812: unsigned int memflags;
813:
814: if (copy_from_user(&buts2, arg, sizeof(buts2)))
815: return -EFAULT;
816:
817: if (!buts2.buf_size || !buts2.buf_nr)
818: return -EINVAL;
819:
820: if (buts2.flags != 0)
821: return -EINVAL;
822:
823: memflags = blk_debugfs_lock(q);
824: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
825: bdev);
826: if (IS_ERR(bt)) {
827: blk_debugfs_unlock(q, memflags);
828: return PTR_ERR(bt);
829: }
830: blk_trace_setup_finalize(q, name, 2, bt, &buts2);
831: blk_debugfs_unlock(q, memflags);
832:
833: if (copy_to_user(arg, &buts2, sizeof(buts2))) {
834: blk_trace_remove(q);
835: return -EFAULT;
836: }
837: return 0;
838: }
839:
840: #if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
841: static int compat_blk_trace_setup(struct request_queue *q, char *name,
]
|
| 56/2 |
2026/08/31 21:24 |
llm |
debugger |
0m
Model:
Tokens:
input: 55447
output: 37
thoughts: 50
Thoughts: Okay, here's my interpretation of those thoughts, presented as my own mental process:
**Handling Errors in Trace Setup**
Alright, so I've been reviewing the changes, and I'm realizing something. I had initially thought only `blk_trace_setup2` needed to deal with the potential errors. But, then I took another look and thought, "Oh, right, the `compat_blk_trace_setup` function also needs to incorporate the necessary error handling."
Wait a minute, `compat_blk_trace_setup` calls `blk_trace_setup_finalize`, doesn't it? Okay, I'll need to double check the error handling there too.
|
| 57/2 |
2026/08/31 21:24 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:842 LineCount:40]
Results: map[Contents: 842: dev_t dev, struct block_device *bdev,
843: char __user *arg)
844: {
845: struct blk_user_trace_setup2 buts2;
846: struct compat_blk_user_trace_setup cbuts;
847: struct blk_trace *bt;
848: unsigned int memflags;
849:
850: if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
851: return -EFAULT;
852:
853: if (!cbuts.buf_size || !cbuts.buf_nr)
854: return -EINVAL;
855:
856: buts2 = (struct blk_user_trace_setup2) {
857: .act_mask = cbuts.act_mask,
858: .buf_size = cbuts.buf_size,
859: .buf_nr = cbuts.buf_nr,
860: .start_lba = cbuts.start_lba,
861: .end_lba = cbuts.end_lba,
862: .pid = cbuts.pid,
863: };
864:
865: memflags = blk_debugfs_lock(q);
866: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
867: bdev);
868: if (IS_ERR(bt)) {
869: blk_debugfs_unlock(q, memflags);
870: return PTR_ERR(bt);
871: }
872: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
873: blk_debugfs_unlock(q, memflags);
874:
875: if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
876: blk_trace_remove(q);
877: return -EFAULT;
878: }
879:
880: return 0;
881: }
]
|
| 58/2 |
2026/08/31 21:24 |
llm |
debugger |
0m
Model:
Tokens:
input: 56339
output: 38
thoughts: 186
Thoughts: **Refining Error Handling in Block Tracing Setup**
Okay, so looking at this code, it's clear that the current error handling strategy in these block tracing setup functions isn't ideal. I need to make some changes to ensure errors are propagated correctly. It seems that `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup` all need to properly handle any errors that might originate from `blk_trace_setup_finalize`. Similarly, `blk_trace_setup_queue` has a potential failure point in `get_probe_ref` that requires explicit error handling.
Alright, let's break down the necessary modifications:
1. First, `blk_register_tracepoints` absolutely needs to return an integer to signal success or failure.
2. Also, `get_probe_ref` should also return an integer, so that failures are detectable.
3. Next, `blk_trace_setup_finalize` needs to return an integer so that failures can be communicated, which is critical.
4. Then, within `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`, I'll implement error handling for the return value of `blk_trace_setup_finalize`.
5. And finally, in `blk_trace_setup_queue`, I'll need to handle any error returns from `get_probe_ref`.
Just to be absolutely sure, I'll take another look at the `blk_register_tracepoints` function to make sure that will work.
|
| 59/2 |
2026/08/31 21:24 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1327 LineCount:50]
Results: map[Contents:1327: static void blk_register_tracepoints(void)
1328: {
1329: int ret;
1330:
1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1332: WARN_ON(ret);
1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1334: WARN_ON(ret);
1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1336: WARN_ON(ret);
1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1338: WARN_ON(ret);
1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1340: WARN_ON(ret);
1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1342: WARN_ON(ret);
1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1344: WARN_ON(ret);
1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1346: WARN_ON(ret);
1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1348: WARN_ON(ret);
1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
1350: WARN_ON(ret);
1351: ret = register_trace_blk_zone_append_update_request_bio(
1352: blk_add_trace_zone_update_request, NULL);
1353: WARN_ON(ret);
1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
1355: NULL);
1356: WARN_ON(ret);
1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
1358: NULL);
1359: WARN_ON(ret);
1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
1361: WARN_ON(ret);
1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
1363: WARN_ON(ret);
1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
1365: WARN_ON(ret);
1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1367: WARN_ON(ret);
1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1369: WARN_ON(ret);
1370: }
1371:
1372: static void blk_unregister_tracepoints(void)
1373: {
1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1376: unregister_trace_block_split(blk_add_trace_split, NULL);
]
|
| 60/2 |
2026/08/31 21:24 |
llm |
debugger |
0m
Model:
Tokens:
input: 57922
output: 36
thoughts: 1391
Thoughts: **Tracepoint Registration: A Deliberation**
Okay, so I'm looking at how to handle tracepoint registration failures in `blk_register_tracepoints`. The current implementation uses `WARN_ON`, but I'm thinking about making the function return an `int` to propagate the error. This would let me handle potential `ENOMEM` issues during registration.
Initially, I considered a straightforward approach: chaining a bunch of `if (ret) goto err;` statements, given there are 19 tracepoints. It's a bit verbose, but it's a standard pattern. Alternatively, I could just use `pr_warn` instead of `WARN_ON` and return 0. But hold on, if I do that, I don't need to change `get_probe_ref` and `blk_trace_setup_finalize`. This would be simpler...
But is it really acceptable to just ignore the error? If a tracepoint fails to register, it means that `blktrace` will miss events for that specific point, while the rest of the tracepoints might still work. Is it better to allow partial functionality or fail the whole `blktrace` setup? A full failure with `-ENOMEM` makes it clear to the user that something is broken. If I just print a warning, the user might not notice and wonder why they're missing events. Returning an error seems like the proper way to go.
To validate my approach, let's peek at how similar functions handle error conditions in other parts of the kernel. Looking at `trace_sched_switch.c` and `trace_osnoise.c` I see that they explicitly return errors, printing info messages. This reinforces the idea that returning an error is the standard method.
So, let's implement the change, I'll write out the function with the `if (ret) goto err;` pattern to maintain consistency and clarity:
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
goto err;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
if (ret)
goto err;
// ... rest of the 19 tracepoints ...
return 0;
err:
blk_unregister_tracepoints();
return ret;
}
```
Okay, now for the unregistration. The `blk_unregister_tracepoints()` function unregisters all of them. Is it safe to call it if a tracepoint wasn't registered in the first place? Yes, looking at `tracepoint_probe_unregister`, it returns `-ENODEV` if the probe isn't found, and it won't crash or leak memory. That's good to know. It also calls `tracepoint_remove_func` internally. I think I'm now certain this is the correct approach.
|
| 61/2 |
2026/08/31 21:24 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/tracepoint.c Name:tracepoint_remove_func]
Results: map[SourceCode: 355: /*
356: * Remove a probe function from a tracepoint.
357: * Note: only waiting an RCU period after setting elem->call to the empty
358: * function insures that the original callback is not used anymore. This insured
359: * by preempt_disable around the call site.
360: */
361: static int tracepoint_remove_func(struct tracepoint *tp,
362: struct tracepoint_func *func)
363: {
364: struct tracepoint_func *old, *tp_funcs;
365:
366: tp_funcs = rcu_dereference_protected(tp->funcs,
367: lockdep_is_held(&tracepoints_mutex));
368: old = func_remove(&tp_funcs, func);
369: if (WARN_ON_ONCE(IS_ERR(old)))
370: return PTR_ERR(old);
371:
372: if (tp_funcs == old)
373: /* Failed allocating new tp_funcs, replaced func with stub */
374: return 0;
375:
376: switch (nr_func_state(tp_funcs)) {
377: case TP_FUNC_0: /* 1->0 */
378: /* Removed last function */
379: if (tp->ext && tp->ext->unregfunc && static_key_enabled(&tp->key))
380: tp->ext->unregfunc();
381: static_branch_disable(&tp->key);
382: /* Set iterator static call */
383: tracepoint_update_call(tp, tp_funcs);
384: /* Both iterator and static call handle NULL tp->funcs */
385: rcu_assign_pointer(tp->funcs, NULL);
386: /*
387: * Make sure new static func never uses old data after a
388: * 1->0->1 transition sequence.
389: */
390: tp_rcu_get_state(TP_TRANSITION_SYNC_1_0_1);
391: break;
392: case TP_FUNC_1: /* 2->1 */
393: rcu_assign_pointer(tp->funcs, tp_funcs);
394: /*
395: * Make sure static func never uses incorrect data after a
396: * N->...->2->1 (N>2) transition sequence. If the first
397: * element's data has changed, then force the synchronization
398: * to prevent current readers that have loaded the old data
399: * from calling the new function.
400: */
401: if (tp_funcs[0].data != old[0].data)
402: tp_rcu_get_state(TP_TRANSITION_SYNC_N_2_1);
403: tp_rcu_cond_sync(TP_TRANSITION_SYNC_N_2_1);
404: /* Set static call to first function */
405: tracepoint_update_call(tp, tp_funcs);
406: break;
407: case TP_FUNC_2: /* N->N-1 (N>2) */
408: fallthrough;
409: case TP_FUNC_N:
410: rcu_assign_pointer(tp->funcs, tp_funcs);
411: /*
412: * Make sure static func never uses incorrect data after a
413: * N->...->2->1 (N>2) transition sequence.
414: */
415: if (tp_funcs[0].data != old[0].data)
416: tp_rcu_get_state(TP_TRANSITION_SYNC_N_2_1);
417: break;
418: default:
419: WARN_ON_ONCE(1);
420: break;
421: }
422: release_probes(tp, old);
423: return 0;
424: }
SourceFile:kernel/tracepoint.c]
|
| 62/2 |
2026/08/31 21:24 |
llm |
debugger |
0m
Model:
Tokens:
input: 61187
output: 33
thoughts: 23
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing the Error Handling in `func_remove`**
Okay, so I'm just reviewing the code, and a detail jumped out at me. The documentation clearly states that `func_remove` returns `ERR_PTR(-ENOENT)` if the specified function isn't found in the symbol table. This is important to understand because it's the expected error condition. I need to make sure the calling code correctly interprets this return value and doesn't treat it as some other, potentially more serious, error. That negative pointer value needs to be checked against `IS_ERR()` and `PTR_ERR()` to extract the proper error code (`-ENOENT`) if the search fails. I should confirm that this behavior is consistent across all calls to the function and any potential wrappers. Perhaps I should search for all usages of `func_remove` within this code base to ensure that this fundamental error condition is being handled correctly at every point it's called. This seems like a potential source of subtle, but hard-to-debug, issues if it's not handled consistently.
|
| 63/2 |
2026/08/31 21:24 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/tracepoint.c Name:func_remove]
Results: map[SourceCode: 195: static void *func_remove(struct tracepoint_func **funcs,
196: struct tracepoint_func *tp_func)
197: {
198: int nr_probes = 0, nr_del = 0, i;
199: struct tracepoint_func *old, *new;
200:
201: old = *funcs;
202:
203: if (!old)
204: return ERR_PTR(-ENOENT);
205:
206: debug_print_probes(*funcs);
207: /* (N -> M), (N > 1, M >= 0) probes */
208: if (tp_func->func) {
209: for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
210: if ((old[nr_probes].func == tp_func->func &&
211: old[nr_probes].data == tp_func->data) ||
212: old[nr_probes].func == tp_stub_func)
213: nr_del++;
214: }
215: }
216:
217: /*
218: * If probe is NULL, then nr_probes = nr_del = 0, and then the
219: * entire entry will be removed.
220: */
221: if (nr_probes - nr_del == 0) {
222: /* N -> 0, (N > 1) */
223: *funcs = NULL;
224: debug_print_probes(*funcs);
225: return old;
226: } else {
227: int j = 0;
228: /* N -> M, (N > 1, M > 0) */
229: /* + 1 for NULL */
230: new = allocate_probes(nr_probes - nr_del + 1);
231: if (new) {
232: for (i = 0; old[i].func; i++) {
233: if ((old[i].func != tp_func->func ||
234: old[i].data != tp_func->data) &&
235: old[i].func != tp_stub_func)
236: new[j++] = old[i];
237: }
238: new[nr_probes - nr_del].func = NULL;
239: *funcs = new;
240: } else {
241: /*
242: * Failed to allocate, replace the old function
243: * with calls to tp_stub_func.
244: */
245: for (i = 0; old[i].func; i++) {
246: if (old[i].func == tp_func->func &&
247: old[i].data == tp_func->data)
248: WRITE_ONCE(old[i].func, tp_stub_func);
249: }
250: *funcs = old;
251: }
252: }
253: debug_print_probes(*funcs);
254: return old;
255: }
SourceFile:kernel/tracepoint.c]
|
| 64/2 |
2026/08/31 21:24 |
llm |
debugger |
0m
Model:
Tokens:
input: 62456
output: 36
thoughts: 669
Thoughts: **Analyzing Tracepoint Unregistration Behavior**
Okay, so I'm digging into how tracepoints are unregistered, and I've hit a potential issue. It looks like `func_remove` within the tracepoint framework can return `-ENOENT` if the function isn't found. This happens specifically when we try to unregister something that wasn't actually registered in the first place, or if the list of functions is NULL.
I see that `tracepoint_remove_func` uses `WARN_ON_ONCE(IS_ERR(old))`, which is problematic because it will generate a warning if `func_remove` returns an error. This is triggered by a call to `unregister_trace_*` functions, for example in `tracepoint_probe_unregister`. I'm concerned that this will be triggered by `blk_unregister_tracepoints()` if certain tracepoints failed to register, leading to these spurious warnings.
Let's break it down further. If registration fails (e.g., `register_trace_block_rq_insert`), we currently log a `WARN_ON`. However, we still *eventually* call `blk_unregister_tracepoints()`. If that registration failed, when `unregister_trace_block_rq_insert` is called, `func_remove` will return `-ENOENT`! If the function list isn't NULL, then it doesn't return an error.
I need to confirm if my understanding of `func_remove` is correct, and I'm seeing it has two conditions where it returns `-ENOENT`. Either the `*funcs` is NULL, or the probe isn't found in the list. It returns NULL when it is not found. If the probe is not found, `nr_del` will be 0, and if the list is not NULL, then the code will copy the data, realloc and return a value that's not an error.
But if `*funcs` is NULL, it *definitely* returns `-ENOENT`, and that will trigger the warning.
Looking more closely at how `tracepoint_probe_unregister` is called by the `unregister_trace_*` functions, it doesn't seem to have any checks for whether a probe was *actually* registered before calling `tracepoint_probe_unregister`. So, if we call an unregister function on a tracepoint without probes, we're guaranteed to hit that warning. This needs to be checked.
|
| 65/2 |
2026/08/31 21:24 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/tracepoint.c Name:tracepoint_probe_unregister]
Results: map[SourceCode: 499: /**
500: * tracepoint_probe_unregister - Disconnect a probe from a tracepoint
501: * @tp: tracepoint
502: * @probe: probe function pointer
503: * @data: tracepoint data
504: *
505: * Returns 0 if ok, error value on error.
506: */
507: int tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data)
508: {
509: struct tracepoint_func tp_func;
510: int ret;
511:
512: mutex_lock(&tracepoints_mutex);
513: tp_func.func = probe;
514: tp_func.data = data;
515: ret = tracepoint_remove_func(tp, &tp_func);
516: mutex_unlock(&tracepoints_mutex);
517: return ret;
518: }
SourceFile:kernel/tracepoint.c]
|
| 66/2 |
2026/08/31 21:24 |
llm |
debugger |
0m
Model:
Tokens:
input: 63990
output: 36
thoughts: 60
Thoughts: Here's my summary, as if I were thinking these things myself:
**Tracing a Tracing Bug**
Hold on a second, something just clicked. If `tracepoint_remove_func` is set up to issue a `WARN_ON_ONCE` specifically when it encounters an error – and specifically when that error is indicated by `IS_ERR(old)` – then calling `unregister_trace_*` on something that *wasn't* even registered in the first place has got to be a bug! That's precisely the situation that should trigger the warning. That would be an obvious sign of an improper use of the tracing API!
Alright, time to go back and meticulously re-examine the implementation of `tracepoint_remove_func`. I need to understand this better.
|
| 67/2 |
2026/08/31 21:25 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/tracepoint.c Name:tracepoint_remove_func]
Results: map[SourceCode: 355: /*
356: * Remove a probe function from a tracepoint.
357: * Note: only waiting an RCU period after setting elem->call to the empty
358: * function insures that the original callback is not used anymore. This insured
359: * by preempt_disable around the call site.
360: */
361: static int tracepoint_remove_func(struct tracepoint *tp,
362: struct tracepoint_func *func)
363: {
364: struct tracepoint_func *old, *tp_funcs;
365:
366: tp_funcs = rcu_dereference_protected(tp->funcs,
367: lockdep_is_held(&tracepoints_mutex));
368: old = func_remove(&tp_funcs, func);
369: if (WARN_ON_ONCE(IS_ERR(old)))
370: return PTR_ERR(old);
371:
372: if (tp_funcs == old)
373: /* Failed allocating new tp_funcs, replaced func with stub */
374: return 0;
375:
376: switch (nr_func_state(tp_funcs)) {
377: case TP_FUNC_0: /* 1->0 */
378: /* Removed last function */
379: if (tp->ext && tp->ext->unregfunc && static_key_enabled(&tp->key))
380: tp->ext->unregfunc();
381: static_branch_disable(&tp->key);
382: /* Set iterator static call */
383: tracepoint_update_call(tp, tp_funcs);
384: /* Both iterator and static call handle NULL tp->funcs */
385: rcu_assign_pointer(tp->funcs, NULL);
386: /*
387: * Make sure new static func never uses old data after a
388: * 1->0->1 transition sequence.
389: */
390: tp_rcu_get_state(TP_TRANSITION_SYNC_1_0_1);
391: break;
392: case TP_FUNC_1: /* 2->1 */
393: rcu_assign_pointer(tp->funcs, tp_funcs);
394: /*
395: * Make sure static func never uses incorrect data after a
396: * N->...->2->1 (N>2) transition sequence. If the first
397: * element's data has changed, then force the synchronization
398: * to prevent current readers that have loaded the old data
399: * from calling the new function.
400: */
401: if (tp_funcs[0].data != old[0].data)
402: tp_rcu_get_state(TP_TRANSITION_SYNC_N_2_1);
403: tp_rcu_cond_sync(TP_TRANSITION_SYNC_N_2_1);
404: /* Set static call to first function */
405: tracepoint_update_call(tp, tp_funcs);
406: break;
407: case TP_FUNC_2: /* N->N-1 (N>2) */
408: fallthrough;
409: case TP_FUNC_N:
410: rcu_assign_pointer(tp->funcs, tp_funcs);
411: /*
412: * Make sure static func never uses incorrect data after a
413: * N->...->2->1 (N>2) transition sequence.
414: */
415: if (tp_funcs[0].data != old[0].data)
416: tp_rcu_get_state(TP_TRANSITION_SYNC_N_2_1);
417: break;
418: default:
419: WARN_ON_ONCE(1);
420: break;
421: }
422: release_probes(tp, old);
423: return 0;
424: }
SourceFile:kernel/tracepoint.c]
|
| 68/2 |
2026/08/31 21:25 |
llm |
debugger |
0m
Model:
Tokens:
input: 65431
output: 44
thoughts: 1612
Thoughts: **Analyzing Tracepoint Registration and Unregistration**
Okay, so I'm looking at this `WARN_ON_ONCE` that pops up when unregistering tracepoints, specifically when `blk_unregister_tracepoints` is called. It seems like the issue stems from a failure during the registration process. If `blk_unregister_tracepoints` is called, and some tracepoints were *never* registered (due to a failure), then it triggers the `WARN_ON_ONCE`.
Currently, `blk_register_tracepoints` registers and *immediately* `WARN_ON` the return value of `register_trace_*`, but *continues* regardless. That's a problem because if the registration fails, the tracepoint's function pointers (`tp->funcs`) might be NULL. Then, during unregistration via `unregister_trace_*`, it will try to call `tracepoint_remove_func`. `tracepoint_remove_func` calls `func_remove`, and that will return `-ENOENT` and trigger the `WARN_ON_ONCE`. The current code issues a `WARN_ON` on failure to register, but it will *later* issue a `WARN_ON_ONCE` on unregister.
If the goal is proper fix, I could either keep track of which tracepoints *succeeded* or simply use `pr_warn` and ignore the error. But that doesn't solve the fact that `WARN_ON_ONCE` will still fire during unregistration! It's clear that we must *not* call `unregister_trace_*` if `register_trace_*` failed!
The problem is, `blk_unregister_tracepoints` unconditionally unregisters *everything*. If I were to change `blk_register_tracepoints` to return an error, then I'd need to know which ones registered successfully, and that gets tedious really fast.
I'm thinking about how I could make this efficient. Could I check if a tracepoint is registered *before* unregistering? Unfortunately, `unregister_trace_*` doesn't provide a way to check. Putting the tracepoints in an array seems difficult because they're different types, though `register_trace_*` is a macro that calls `tracepoint_probe_register`.
Let's look at `kernel/trace/trace_osnoise.c` for inspiration. Ah, they use labels to handle multiple tracepoints, and they do it with labels. But nineteen labels is… a lot.
Perhaps I could just use `pr_warn` and not unregister if it fails? But if I don't unregister, I'll need to remember which ones failed. Since `blk_register_tracepoints` is called globally (protected by `blk_probes_ref`), a global boolean array or bitmask is an option.
But… registration failures are often due to `-ENOMEM`. Returning the error and failing the setup, then using labels, seems like a reasonable approach. I'll need to explore similar registration patterns in the kernel. Let's see if there are other places with lots of tracepoints.
In `kernel/trace/trace_events.c`, `register_pid_events` doesn't *check* the return value. And `unregister_pid_events` unregisters them *unconditionally*. If a `register_trace_prio_sched_switch` call fails, the corresponding `unregister_trace_sched_switch` will trigger the dreaded `WARN_ON_ONCE`!
Let's double-check the `tracepoint_probe_unregister` code. If the probe isn't found, it returns `-ENOENT`. Then, `tracepoint_remove_func` triggers `WARN_ON_ONCE(IS_ERR(old))` if `func_remove` returns an error, specifically `-ENOENT`. So, yes, it *will* trigger `WARN_ON_ONCE` if `tp_funcs` is NULL.
So, why doesn't `unregister_pid_events` trigger it in practice? Because `register_trace_*` rarely fails, usually only on `-ENOMEM`. But with fault injection, it *does* fail. And that's exactly what syzbot found with `blk_register_tracepoints`! Wait. syzbot found the `WARN_ON(ret)` in `blk_register_tracepoints`, not the `WARN_ON_ONCE` in `tracepoint_remove_func`. Right, because there's an explicit `WARN_ON(ret)`.
Now, if I remove the `WARN_ON(ret)` in `blk_register_tracepoints`, syzbot might just hit the `WARN_ON_ONCE` in `tracepoint_remove_func` *later* when `
|
| 69/2 |
2026/08/31 21:25 |
tool |
git-log |
0m
Args: map[CodeRegexp:WARN_ON_ONCE\(IS_ERR\(old\)\) PathPrefix:kernel/tracepoint.c]
Results: map[Output:befe6d946551 tracepoint: Do not fail unregistering a probe due to memory failure
]
|
| 70/2 |
2026/08/31 21:25 |
llm |
debugger |
0m
Model:
Tokens:
input: 68151
output: 25
thoughts: 16
Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, in the first person and assuming the user is an expert:
**Analyzing That String: bef56d946551**
Alright, let's break this down. Seeing `befe6d946551` immediately triggers a mental checklist. Is this a hash? A UUID? An API key? What context have I seen this string in previously? The structure itself looks like a hexadecimal string, the length is somewhat suggestive. The 'be' at the start seems to be potentially significant. I'm mentally parsing it as I would any potential cryptographic hash or identifier.
Is it a truncated SHA-1? Possibly MD5? I need more context to be sure. I'm already comparing the form to known patterns for common security hashes. Length would be key; the 12 character string suggests a base-16 encoding. Need a key to test hash possibilities - if I get the hash family, then the input for this hash should be easily recoverable. My expertise tells me, even from just looking at it, I might quickly determine the algorithm or context. Time to pull up some of the usual tools and see if a quick check reveals anything. Is it a component of a larger system?
If it's not a hash, is it a key? An ID? Where was this string encountered, and what else was present? Is this string being used to look up a record in a database? Perhaps I will run it in a database query tool to see if the record can be located. Need to consider the possibilities.
|
| 71/2 |
2026/08/31 21:25 |
tool |
git-show |
0m
Args:
Results: map[Output:commit befe6d946551d65cddbd32b9cb0170b0249fd5ed
Author: Steven Rostedt (VMware) <rostedt@goodmis.org>
Date: Wed Nov 18 09:34:05 2020 -0500
tracepoint: Do not fail unregistering a probe due to memory failure
The list of tracepoint callbacks is managed by an array that is protected
by RCU. To update this array, a new array is allocated, the updates are
copied over to the new array, and then the list of functions for the
tracepoint is switched over to the new array. After a completion of an RCU
grace period, the old array is freed.
This process happens for both adding a callback as well as removing one.
But on removing a callback, if the new array fails to be allocated, the
callback is not removed, and may be used after it is freed by the clients
of the tracepoint.
There's really no reason to fail if the allocation for a new array fails
when removing a function. Instead, the function can simply be replaced by a
stub function that could be cleaned up on the next modification of the
array. That is, instead of calling the function registered to the
tracepoint, it would call a stub function in its place.
Link: https://lore.kernel.org/r/20201115055256.65625-1-mmullins@mmlx.us
Link: https://lore.kernel.org/r/20201116175107.02db396d@gandalf.local.home
Link: https://lore.kernel.org/r/20201117211836.54acaef2@oasis.local.home
Link: https://lkml.kernel.org/r/20201118093405.7a6d2290@gandalf.local.home
[ Note, this version does use undefined compiler behavior (assuming that
a stub function with no parameters or return, can be called by a location
that thinks it has parameters but still no return value. Static calls
do the same thing, so this trick is not without precedent.
There's another solution that uses RCU tricks and is more complex, but
can be an alternative if this solution becomes an issue.
Link: https://lore.kernel.org/lkml/20210127170721.58bce7cc@gandalf.local.home/
]
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@chromium.org>
Cc: netdev <netdev@vger.kernel.org>
Cc: bpf <bpf@vger.kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Florian Weimer <fw@deneb.enyo.de>
Fixes: 97e1c18e8d17b ("tracing: Kernel Tracepoints")
Reported-by: syzbot+83aa762ef23b6f0d1991@syzkaller.appspotmail.com
Reported-by: syzbot+d29e58bb557324e55e5e@syzkaller.appspotmail.com
Reported-by: Matt Mullins <mmullins@mmlx.us>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Tested-by: Matt Mullins <mmullins@mmlx.us>
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 7261fa0f5e3c..e8f20ae29c18 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -53,6 +53,12 @@ struct tp_probes {
struct tracepoint_func probes[];
};
+/* Called in removal of a func but failed to allocate a new tp_funcs */
+static void tp_stub_func(void)
+{
+ return;
+}
+
static inline void *allocate_probes(int count)
{
struct tp_probes *p = kmalloc(struct_size(p, probes, count),
@@ -131,6 +137,7 @@ func_add(struct tracepoint_func **funcs, struct tracepoint_func *tp_func,
{
struct tracepoint_func *old, *new;
int nr_probes = 0;
+ int stub_funcs = 0;
int pos = -1;
if (WARN_ON(!tp_func->func))
@@ -147,14 +154,34 @@ func_add(struct tracepoint_func **funcs, struct tracepoint_func *tp_func,
if (old[nr_probes].func == tp_func->func &&
old[nr_probes].data == tp_func->data)
return ERR_PTR(-EEXIST);
+ if (old[nr_probes].func == tp_stub_func)
+ stub_funcs++;
}
}
- /* + 2 : one for new probe, one for NULL func */
- new = allocate_probes(nr_probes + 2);
+ /* + 2 : one for new probe, one for NULL func - stub functions */
+ new = allocate_probes(nr_probes + 2 - stub_funcs);
if (new == NULL)
return ERR_PTR(-ENOMEM);
if (old) {
- if (pos < 0) {
+ if (stub_funcs) {
+ /* Need to copy one at a time to remove stubs */
+ int probes = 0;
+
+ pos = -1;
+ for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
+ if (old[nr_probes].func == tp_stub_func)
+ continue;
+ if (pos < 0 && old[nr_probes].prio < prio)
+ pos = probes++;
+ new[probes++] = old[nr_probes];
+ }
+ nr_probes = probes;
+ if (pos < 0)
+ pos = probes;
+ else
+ nr_probes--; /* Account for insertion */
+
+ } else if (pos < 0) {
pos = nr_probes;
memcpy(new, old, nr_probes * sizeof(struct tracepoint_func));
} else {
@@ -188,8 +215,9 @@ static void *func_remove(struct tracepoint_func **funcs,
/* (N -> M), (N > 1, M >= 0) probes */
if (tp_func->func) {
for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
- if (old[nr_probes].func == tp_func->func &&
- old[nr_probes].data == tp_func->data)
+ if ((old[nr_probes].func == tp_func->func &&
+ old[nr_probes].data == tp_func->data) ||
+ old[nr_probes].func == tp_stub_func)
nr_del++;
}
}
@@ -208,14 +236,32 @@ static void *func_remove(struct tracepoint_func **funcs,
/* N -> M, (N > 1, M > 0) */
/* + 1 for NULL */
new = allocate_probes(nr_probes - nr_del + 1);
- if (new == NULL)
- return ERR_PTR(-ENOMEM);
- for (i = 0; old[i].func; i++)
- if (old[i].func != tp_func->func
- || old[i].data != tp_func->data)
- new[j++] = old[i];
- new[nr_probes - nr_del].func = NULL;
- *funcs = new;
+ if (new) {
+ for (i = 0; old[i].func; i++)
+ if ((old[i].func != tp_func->func
+ || old[i].data != tp_func->data)
+ && old[i].func != tp_stub_func)
+ new[j++] = old[i];
+ new[nr_probes - nr_del].func = NULL;
+ *funcs = new;
+ } else {
+ /*
+ * Failed to allocate, replace the old function
+ * with calls to tp_stub_func.
+ */
+ for (i = 0; old[i].func; i++)
+ if (old[i].func == tp_func->func &&
+ old[i].data == tp_func->data) {
+ old[i].func = tp_stub_func;
+ /* Set the prio to the next event. */
+ if (old[i + 1].func)
+ old[i].prio =
+ old[i + 1].prio;
+ else
+ old[i].prio = -1;
+ }
+ *funcs = old;
+ }
}
debug_print_probes(*funcs);
return old;
@@ -295,10 +341,12 @@ static int tracepoint_remove_func(struct tracepoint *tp,
tp_funcs = rcu_dereference_protected(tp->funcs,
lockdep_is_held(&tracepoints_mutex));
old = func_remove(&tp_funcs, func);
- if (IS_ERR(old)) {
- WARN_ON_ONCE(PTR_ERR(old) != -ENOMEM);
+ if (WARN_ON_ONCE(IS_ERR(old)))
return PTR_ERR(old);
- }
+
+ if (tp_funcs == old)
+ /* Failed allocating new tp_funcs, replaced func with stub */
+ return 0;
if (!tp_funcs) {
/* Removed last function */
]
|
| 72/2 |
2026/08/31 21:25 |
llm |
debugger |
0m
Model:
Tokens:
input: 71360
output: 40
thoughts: 3529
Thoughts: **Analyzing Tracepoint Registration and Unregistration in the Block Layer**
Okay, so the initial issue boils down to how we handle errors when registering and unregistering tracepoints. Specifically, `func_remove` returns an error if `old` is NULL, which leads to a `WARN_ON_ONCE` in `tracepoint_remove_func` when attempting to unregister a tracepoint that wasn't registered in the first place. That's a textbook race condition, and it's something we need to fix.
The root cause is that if `register_trace_*` fails, `tp->funcs` could be NULL, and the subsequent `unregister_trace_*` calls trigger this `WARN_ON_ONCE`. Thus, we cannot unconditionally unregister the tracepoints if registration failed. It's a fundamental flaw in `blk_unregister_tracepoints` as it exists now.
The correct approach is either to have the `blk_register_tracepoints` function *return an error* on failure and, crucially, *only unregister the tracepoints that were successfully registered* or to check if each tracepoint is registered before unregistering. There is no API available to test the registration state.
I thought about other approaches, such as providing an error return from `unregister_trace_*` but that seems less useful in general.
Looking at other subsystems, such as `kernel/trace/trace_osnoise.c`, they use labels for this type of error handling. That is, if a registration fails, then the unregistration is skipped. Given that we have 19 tracepoints, we can just use 19 labels to handle this.
So I wrote out the labels for `blk_register_tracepoints` and the `goto` logic to unregister only registered ones. That's a little bit of boilerplate, but necessary for correct error handling.
The next step is to ensure `get_probe_ref` can return an `int`. This will allow the use of `blk_register_tracepoints` which also returns an integer.
The `blk_trace_setup_queue` function then calls `get_probe_ref`, which now has a return code, and thus we can handle the return code more gracefully.
The same refactoring needs to be added to `blk_trace_setup_finalize`, `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`. `blk_trace_setup_prepare` calls `debugfs_create_dir` and `relay_open`.
Finally, after the changes, the error handling is now correct, and resources are released properly, regardless of whether tracepoint registration succeeds. That is, if `blk_trace_setup_finalize` fails, then `blk_trace_free(q, bt)` is called, which calls `relay_close` and `debugfs_remove` and frees `bt`, the correct actions that are performed by `blk_trace_setup_prepare` on its error path.
|
| 73/2 |
2026/08/31 21:25 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/trace/blktrace.c Name:blk_trace_setup_prepare]
Results: map[SourceCode: 649: /*
650: * Setup everything required to start tracing
651: */
652: static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
653: char *name, dev_t dev,
654: u32 buf_size, u32 buf_nr,
655: struct block_device *bdev)
656: {
657: struct blk_trace *bt = NULL;
658: struct dentry *dir = NULL;
659: int ret;
660:
661: lockdep_assert_held(&q->debugfs_mutex);
662:
663: /*
664: * bdev can be NULL, as with scsi-generic, this is a helpful as
665: * we can be.
666: */
667: if (rcu_dereference_protected(q->blk_trace,
668: lockdep_is_held(&q->debugfs_mutex))) {
669: pr_warn("Concurrent blktraces are not allowed on %s\n", name);
670: return ERR_PTR(-EBUSY);
671: }
672:
673: bt = kzalloc_obj(*bt);
674: if (!bt)
675: return ERR_PTR(-ENOMEM);
676:
677: ret = -ENOMEM;
678: bt->sequence = alloc_percpu(unsigned long);
679: if (!bt->sequence)
680: goto err;
681:
682: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
683: if (!bt->msg_data)
684: goto err;
685:
686: /*
687: * When tracing the whole disk reuse the existing debugfs directory
688: * created by the block layer on init. For partitions block devices,
689: * and scsi-generic block devices we create a temporary new debugfs
690: * directory that will be removed once the trace ends.
691: */
692: if (bdev && !bdev_is_partition(bdev))
693: dir = q->debugfs_dir;
694: else
695: bt->dir = dir = debugfs_create_dir(name, blk_debugfs_root);
696:
697: /*
698: * As blktrace relies on debugfs for its interface the debugfs directory
699: * is required, contrary to the usual mantra of not checking for debugfs
700: * files or directories.
701: */
702: if (IS_ERR_OR_NULL(dir)) {
703: pr_warn("debugfs_dir not present for %s so skipping\n", name);
704: ret = -ENOENT;
705: goto err;
706: }
707:
708: bt->dev = dev;
709: INIT_LIST_HEAD(&bt->running_list);
710:
711: ret = -EIO;
712: debugfs_create_file("dropped", 0444, dir, bt, &blk_dropped_fops);
713: debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
714:
715: bt->rchan = relay_open("trace", dir, buf_size, buf_nr,
716: &blk_relay_callbacks, bt);
717: if (!bt->rchan)
718: goto err;
719:
720: blk_trace_setup_lba(bt, bdev);
721:
722: return bt;
723:
724: err:
725: blk_trace_free(q, bt);
726:
727: return ERR_PTR(ret);
728: }
SourceFile:kernel/trace/blktrace.c]
|
| 74/2 |
2026/08/31 21:25 |
llm |
debugger |
0m
Model:
Tokens:
input: 76773
output: 38
thoughts: 1550
Thoughts: **Analyzing and Fixing blktrace Error Handling**
Okay, so `blk_trace_free(q, bt)` is definitely the correct function to use for cleanup, that much is clear. Now, let's look at the error handling in `blk_register_tracepoints`.
There are 18 tracepoints, not 19, and `blk_register_tracepoints` seems like a key function here. I'm wondering if `register_trace_*` functions could fail with something *other* than `-ENOMEM`. Based on `tracepoint_probe_register`, it returns either `-ENOMEM` or `-EEXIST`. The `-EEXIST` is interesting; it means the probe is already registered. However, since `blk_register_tracepoints` is protected by `blk_probes_ref`, it should only be called once, so a duplicate registration seems unlikely. If it *does* occur, it would suggest a fundamental flaw in how these probes are being set up, but since `blk_add_trace_rq_insert`, et al., are all static functions within `blktrace.c`, there's no way someone else could've added them. It should only fail with `-ENOMEM`.
Right, let's review the root cause and proposed fix. The current implementation uses `WARN_ON(ret)` to check the return values of the `register_trace_block_*` functions. This is problematic because these functions *can* fail, especially due to memory allocation issues that fault injection can trigger. When they do fail, `WARN_ON` is triggered and that could lead to a kernel panic, especially if `panic_on_warn` is set. Even worse, if there's a failure during tracepoint registration, the function continues and leaves the system in a partially registered state, and then `blk_unregister_tracepoints` is later called to remove tracepoints. This unconditional unregistration of tracepoints that may not be registered triggers `WARN_ON_ONCE` inside `tracepoint_remove_func` because `func_remove` would return `-ENOENT`. The current error handling, therefore, has two flaws: it uses `WARN_ON` for a failure that could be transient and it lacks proper cleanup.
Here's the fix:
1. Change `blk_register_tracepoints` to return an `int`. This provides the caller with the information about success or failure.
2. In `blk_register_tracepoints`, we need to check the return value of *each* `register_trace_*` call. If any of them fail, we'll use `goto` labels to unregister the successfully registered tracepoints in reverse order, and return the error. This ensures a clean rollback.
3. Change `get_probe_ref` to return an `int` and propagate the error from `blk_register_tracepoints`. This way the error is handled at a higher level, and can be tracked as it goes up the call stack.
4. Change `blk_trace_setup_finalize` to return an `int` and propagate the error from `get_probe_ref`.
5. Update the callers of `blk_trace_setup_finalize` (`blk_trace_setup`, `blk_trace_setup2`, `compat_blk_trace_setup`) to handle the error by calling `blk_trace_free` and returning the error. We need to be able to safely cleanup and signal failure up the chain.
6. Update `blk_trace_setup_queue` to handle the error from `get_probe_ref` by calling `blk_trace_free` and returning the error.
I've already confirmed that the `blk_trace_setup_queue` error path is handled correctly, with a check for `ret`, and calling `blk_trace_free` before returning.
Similarly, I've checked and confirmed that the error path in `blk_trace_setup_finalize` is handled correctly as well.
The error paths in `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup` are all consistent and handled appropriately.
Now, let's double-check the call hierarchy: `blk_register_tracepoints` is only called from `get_probe_ref`. Also, `get_probe_ref` is only called from `blk_trace_setup_queue` and `blk_trace_setup_finalize`. Then, `blk_trace_setup_finalize` is only called by `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`. I have the call graph correct in my head now.
Finally, I got the count wrong the first time, there are 1
|
| 75/2 |
2026/08/31 21:26 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1327 LineCount:50]
Results: map[Contents:1327: static void blk_register_tracepoints(void)
1328: {
1329: int ret;
1330:
1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1332: WARN_ON(ret);
1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1334: WARN_ON(ret);
1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1336: WARN_ON(ret);
1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1338: WARN_ON(ret);
1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1340: WARN_ON(ret);
1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1342: WARN_ON(ret);
1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1344: WARN_ON(ret);
1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1346: WARN_ON(ret);
1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1348: WARN_ON(ret);
1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
1350: WARN_ON(ret);
1351: ret = register_trace_blk_zone_append_update_request_bio(
1352: blk_add_trace_zone_update_request, NULL);
1353: WARN_ON(ret);
1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
1355: NULL);
1356: WARN_ON(ret);
1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
1358: NULL);
1359: WARN_ON(ret);
1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
1361: WARN_ON(ret);
1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
1363: WARN_ON(ret);
1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
1365: WARN_ON(ret);
1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1367: WARN_ON(ret);
1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1369: WARN_ON(ret);
1370: }
1371:
1372: static void blk_unregister_tracepoints(void)
1373: {
1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1376: unregister_trace_block_split(blk_add_trace_split, NULL);
]
|
| 76/2 |
2026/08/31 21:26 |
llm |
debugger |
0m
Model:
Tokens:
input: 80401
output: 1216
thoughts: 462
Thoughts: **My Analysis of the Tracepoint Registration Issue**
Okay, so there are 18 tracepoints involved here. The fix seems pretty straightforward, which is always good news. Let's break down the root cause and then walk through the proposed solution.
The problem lies within `blk_register_tracepoints()`. It's using `WARN_ON(ret)` to check the return values of those `register_trace_block_*()` functions. Those functions are allocating memory for the tracepoint probe arrays. And, as we know, memory allocation can fail, especially under memory pressure or if we're dealing with fault injection, resulting in an `-ENOMEM` error.
The current implementation has two significant flaws. First, that `WARN_ON()` call can lead to a kernel panic if `panic_on_warn` is set, which is obviously undesirable. Second, even if it *doesn't* panic, `blk_register_tracepoints()` just ignores the error and merrily continues on, leaving the tracepoints only *partially* registered. Then, later, when we go to stop tracing, `blk_unregister_tracepoints()` gets called, and it tries to unregister *all* tracepoints, regardless of whether they were successfully registered or not. This is where `tracepoint_remove_func()` comes in. And here we get into the crux of the problem: unregistering a tracepoint that was never correctly registered will cause `tracepoint_remove_func()` to return `-ENOENT`. That, in turn, triggers a `WARN_ON_ONCE` call within `tracepoint_remove_func()`, which is obviously a bad state.
So, the proposed solution is a clean, top-to-bottom approach that seems correct.
First, we'll change `blk_register_tracepoints()` itself to return an `int`. This allows us to actually propagate the error. Then, for each call to the `register_trace_*()` functions, we need to check the return value. If we get a failure, we'll use `goto` labels to clean up, which means unregistering the successfully registered tracepoints in reverse order, and returning the error from `blk_register_tracepoints()`. This ensures that we don't leave things in an inconsistent state.
Next, we need to propagate the error up the chain. So we're going to update `get_probe_ref()` to return an `int` and pass the error that it gets from `blk_register_tracepoints()` onwards. Then, `blk_trace_setup_finalize()` will also be updated to return an `int` so that it can properly propagate the error from `get_probe_ref()`.
Finally, we'll ensure that all the callers of `blk_trace_setup_finalize()`, namely `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, handle the error by calling `blk_trace_free()` and returning the error to the caller. We do the same for `blk_trace_setup_queue()` in the same manner. This covers all the bases.
This is a well-thought-out fix. It addresses the root cause directly, and ensures that the errors are properly handled and propagated, which is exactly what's needed.
|
| 77/1 |
2026/08/31 21:26 |
agent |
history-explorer |
3m
Model:
Instruction:
You are an experienced Linux kernel developer researching prior art for fixing a kernel bug.
You are given a bug explanation. This explanation details the root cause of the bug resulting
from debugging, but does not provide the final fix strategy. Your goal is to explore how
similar bugs were fixed in the past in the same subsystem or files.
CRITICAL: Do NOT attempt to debug the issue further or write a patch for it yourself.
Your ONLY objective is to research and provide the necessary historical context.
Use the git-log tool with the Since parameter set to "3 years" to focus on recent history.
Search for commits that address issues with similar root causes (e.g. similar missing locks,
incorrect refcounting, or similar error path bugs) in the affected files.
Your final reply must summarize your findings: what idioms, locking rules, or common patterns
should be followed when writing a fix for this bug based on how previous similar bugs were addressed.
If you find no relevant past fixes, clearly state that.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
------------[ cut here ]------------
ret
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline], CPU#1: syz.0.17/6119
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492, CPU#1: syz.0.17/6119
Modules linked in:
CPU: 1 UID: 0 PID: 6119 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Code: c3 31 ff 89 c6 e8 39 42 f7 ff 85 db 0f 85 00 01 00 00 e8 2c 3d f7 ff 48 c7 c7 00 7f bd 8e 5b e9 af 77 db 09 e8 1a 3d f7 ff 90 <0f> 0b 90 e9 e8 fc ff ff e8 0c 3d f7 ff 90 0f 0b 90 e9 07 fd ff ff
RSP: 0018:ffffc9000355fb10 EFLAGS: 00010293
RAX: ffffffff81ce06d6 RBX: 00000000fffffff4 RCX: ffff888114150000
RDX: 0000000000000000 RSI: 00000000fffffff4 RDI: 0000000000000000
RBP: ffffc9000355fc40 R08: ffffc9000355fa47 R09: 1ffff920006abf48
R10: dffffc0000000000 R11: fffff520006abf49 R12: ffff88810888c508
R13: dffffc0000000000 R14: ffff888103f8c638 R15: 0000000000002000
FS: 00007fc861b426c0(0000) GS:ffff8882e873e000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2ed24008 CR3: 00000001fdd32000 CR4: 0000000000352ef0
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc860b9e159
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fc861b42028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fc860e25fa0 RCX: 00007fc860b9e159
RDX: 0000000000000081 RSI: 00002000000002c0 RDI: 0000000000000003
RBP: 00007fc861b42090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
The explanation of the root cause of the bug is:
The root cause of the crash is that `blk_register_tracepoints()` uses `WARN_ON(ret)` to check the return values of `register_trace_block_*()` functions. These tracepoint registration functions allocate memory for the probe array and can fail with `-ENOMEM` (e.g., under memory pressure or fault injection, as seen in the syzbot report). When they fail, `WARN_ON()` triggers a kernel panic if `panic_on_warn` is set.
Furthermore, `blk_register_tracepoints()` currently ignores the error and continues, leaving the tracepoints in a partially registered state. Later, when tracing is stopped, `blk_unregister_tracepoints()` unconditionally unregisters all tracepoints. Unregistering a tracepoint that was not successfully registered causes `tracepoint_remove_func()` to return `-ENOENT`, which triggers another `WARN_ON_ONCE` inside `tracepoint_remove_func()`.
To fix this, we need to properly handle the registration failures by returning the error, unregistering the successfully registered tracepoints, and propagating the error up the call stack to fail the blktrace setup.
### Fix Details
1. **Change `blk_register_tracepoints()` to return an `int` and handle errors:**
Instead of `WARN_ON(ret)`, check the return value of each `register_trace_*()` call. If it fails, use `goto` labels to unregister the successfully registered tracepoints in reverse order, and return the error.
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
return ret;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
if (ret)
goto err_issue;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
if (ret)
goto err_merge;
// ... (do this for all 18 tracepoints) ...
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
if (ret)
goto err_rq_remap;
return 0;
err_rq_remap:
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
// ... (unregister labels in reverse order) ...
err_merge:
unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
err_issue:
unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
return ret;
}
```
2. **Propagate the error through `get_probe_ref()`:**
```c
static int get_probe_ref(void)
{
int ret = 0;
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1) {
ret = blk_register_tracepoints();
if (ret)
blk_probes_ref--;
}
mutex_unlock(&blk_probe_mutex);
return ret;
}
```
3. **Propagate the error through `blk_trace_setup_finalize()`:**
```c
static int blk_trace_setup_finalize(struct request_queue *q,
char *name, int version,
struct blk_trace *bt,
struct blk_user_trace_setup2 *buts)
{
int ret;
// ... existing code ...
bt->trace_state = Blktrace_setup;
ret = get_probe_ref();
if (ret)
return ret;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
}
```
4. **Handle the error in the callers of `blk_trace_setup_finalize()`:**
In `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, check the return value of `blk_trace_setup_finalize()`. If it fails, clean up the allocated `bt` and return the error:
```c
ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
```
5. **Handle the error in `blk_trace_setup_queue()`:**
```c
static int blk_trace_setup_queue(struct request_queue *q,
struct block_device *bdev)
{
// ... existing code ...
blk_trace_setup_lba(bt, bdev);
ret = get_probe_ref();
if (ret)
goto free_bt;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
free_bt:
blk_trace_free(q, bt);
return ret;
}
```
Reply: Based on the research into how similar bugs were addressed in the kernel (particularly within the tracing subsystem), the proposed fix strategy aligns perfectly with established kernel idioms and past fixes.
Here is a summary of the findings, common patterns, and locking rules that should be followed when writing the fix:
### 1. Removing `WARN_ON` for Expected Errors
Tracepoint registration functions (e.g., `register_trace_*()`) can legitimately fail, most commonly with `-ENOMEM` when allocating memory for the probe array. Using `WARN_ON()` to handle these expected failures is an anti-pattern because it will crash the kernel if `panic_on_warn` is enabled (which is common in testing environments like syzbot).
* **Prior Art:** Commit `1dd349ab74d2` ("tracing: Do not start benchmark on boot up") explicitly removed a `WARN_ON` on tracepoint setup failure, noting that registration can handle failure cases and should simply return `-ENOMEM`.
### 2. Symmetric Rollback via `goto` Labels
When a function registers multiple tracepoints sequentially, it must implement a symmetric rollback if any registration fails partway through. The standard kernel idiom is to use `goto` labels to unregister the successfully registered tracepoints in the **reverse order** of their registration.
* **Prior Art:**
* Commit `aca0cd1bf165` ("tracing/fprobe: Roll back on enable_trace_fprobe() failure") fixed a similar issue where failing partway through left events half-enabled. It introduced a rollback path to unregister all previously registered probes.
* Commit `bce29ac9ce0b` ("trace: Add osnoise tracer") demonstrates the exact `goto` label pattern for registering/unregistering multiple tracepoints in `osnoise_arch_register()`.
### 3. Preventing Secondary `WARN_ON_ONCE` in Unregistration
If a rollback is not performed, the subsystem is left in a partially initialized state. Later, when the tracer is stopped, it will unconditionally attempt to unregister all tracepoints. Unregistering a tracepoint that was never successfully registered causes `tracepoint_remove_func()` to return `-ENOENT`, which triggers a secondary `WARN_ON_ONCE`.
* **Prior Art:** Commit `0878355b51f5` ("tracing/osnoise: Properly unhook events if start_per_cpu_kthreads() fails") fixed an identical bug where failing to clean up hooks on an error path led to a `WARN_ON_ONCE()` in `tracepoint_remove_func()` during tracer disablement.
### 4. Error Propagation and Locking Rules
The error must be propagated up the call stack to ensure the setup fails gracefully.
* In `get_probe_ref()`, the `blk_probe_mutex` is held. If `blk_register_tracepoints()` fails, you must decrement the `blk_probes_ref` counter before unlocking the mutex, which your proposed fix correctly does.
* In the callers (`blk_trace_setup_finalize()` and `blk_trace_setup_queue()`), propagating the error and cleaning up allocated resources (like `blk_trace_free(q, bt)`) is the correct and expected behavior to prevent memory leaks.
**Conclusion:**
Your proposed fix strategy is completely correct. You should proceed with changing `blk_register_tracepoints()` to return an `int`, replacing the `WARN_ON()` checks with standard `if (ret) goto err_*` blocks for reverse-order unregistration, and propagating the error up through `get_probe_ref()` and the blktrace setup functions.
|
| 78/2 |
2026/08/31 21:26 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 7016
output: 32
thoughts: 280
Thoughts: **Analyzing the Bug in `kernel/trace/blktrace.c`**
Okay, so I've got this bug to tackle in `kernel/trace/blktrace.c`. It looks like the core issue is the way `blk_register_tracepoints()` handles errors from the `register_trace_block_*()` functions. Specifically, using `WARN_ON(ret)` for `-ENOMEM` is a problem. We need a more robust approach.
My initial thought is to see how similar issues have been handled in this subsystem or related parts of the kernel. Let's use `git-log` to search for relevant commits. I'll focus on `kernel/trace/blktrace.c` and potentially other files within `kernel/trace/`. I want to look for fixes that address error handling, specifically unregistering in reverse order, or removing `WARN_ON` statements on tracepoint registration.
Ah, right, the prompt says to hone the search a bit. Let's set the `Since` parameter to "3 years" to focus on more recent history. That should give us a more relevant set of results. I'll run `git-log` on `kernel/trace/blktrace.c` with that `Since` parameter. I'll also be looking for commits that involve problems similar to this one: maybe missing locks, incorrect refcounting, or errors in error paths. That should give me the best chance of finding a good example.
|
| 79/2 |
2026/08/31 21:26 |
tool |
git-log |
0m
Args: map[PathPrefix:kernel/trace/blktrace.c Since:3 years]
Results: map[Output:da46b5dfef48 blktrace: fix __this_cpu_read/write in preemptible context
bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
dfe48ea17973 blk-mq: use NOIO context to prevent deadlock during debugfs creation
0c2580a80946 blktrace: Make init_blk_tracer() asynchronous
ee4784a83fb2 block: don't use strcpy to copy blockdev name
bbec8e28cac5 tracing: Allow tracer to add more than 32 options
bc49af56eea8 blktrace: add support for REQ_OP_WRITE_ZEROES tracing
e48886b9d668 blktrace: for ftrace use correct trace format ver
4a0940bdcac2 blktrace: use debug print to report dropped events
]
|
| 80/2 |
2026/08/31 21:26 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 7907
output: 38
thoughts: 179
Thoughts: **My Investigation into Potential Tracepoint Registration Issues**
Okay, so I need to dig into potential problems related to tracepoint registration, specifically starting with the `kernel/trace/blktrace.c` file. My initial thought was to simply check the commits in that file directly, but I didn't see anything obvious that addressed registration errors. I thought about expanding the search to the entire `kernel/trace/` directory, or perhaps other subsystems where `register_trace_*` functions are used.
Then I re-read the prompt. It's asking about *similar root causes*, things like missing locks, incorrect refcounting, or errors in the same code path, not just issues *in* the given file. Okay, that's a key distinction.
This means I need to broaden my perspective a bit. I could go back and look at the commit history for `kernel/trace/blktrace.c`, perhaps going further back in time, or even at the history of the `kernel/trace/` directory as a whole to see what kinds of problems that area has faced. But, let's back up a step. I need to be more strategic. I'm going to search for the terms "register_trace" or "WARN_ON" within either `kernel/trace/` or `block/` directories to see if these keywords trigger anything related to errors or unusual behavior. This seems like a good approach to cast a wide enough net to catch the relevant commits, based on the keywords.
|
| 81/2 |
2026/08/31 21:26 |
tool |
git-log |
0m
Args: map[CodeRegexp:register_trace_ PathPrefix:kernel/trace/ Since:3 years]
Results: map[Output:aca0cd1bf165 tracing/fprobe: Roll back on enable_trace_fprobe() failure
2e82e256df19 perf: tracing: Have perf system calls read user space
bd1b80fba71a perf: tracing: Simplify perf_sysenter_enable/disable() with guards
3f6722816a73 blktrace: trace zone write plugging operations
1c164fcc1b08 blktrace: expose ZONE APPEND completions to blktrace
2db832ec9090 tracing: fprobe-events: Register fprobe-events only when it is enabled
eeadd68e2a5f block: remove bounce buffering support
e3ff4245928f tracing/osnoise: Fix resetting of tracepoints
21e92806d39c function_graph: Support recording and printing the function return address
9d8616034f16 tracing/kprobes: Add symbol counting check when module loads
]
|
| 82/2 |
2026/08/31 21:26 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 8691
output: 23
thoughts: 63
Thoughts: **Analyzing Error Handling in `blktrace.c`**
Okay, so I'm thinking, before I dive too deep into this specific issue, it's always smart to see if there's existing precedent, particularly in the same area. Let's start by quickly checking the commit history for `kernel/trace/blktrace.c` – see if any previous commits there tackled similar error paths or error recovery scenarios. I want to build on any lessons already learned.
Wait a second, before I get lost in that, I recall a potentially relevant commit, `aca0cd1bf165`, that handles a *tracing* failure. That sounds potentially related to the broader topic and failure scenarios for tracing, but in fprobe. I'll take a quick look at that one first, since it specifically mentions rollback. It might give me some clues as to the logic used for error handling and mitigation when tracing functions fail during their "enable" phase. That could provide helpful insight before tackling my target file.
|
| 83/2 |
2026/08/31 21:26 |
tool |
git-show |
0m
Args:
Results: map[Output:commit aca0cd1bf16574327ef64f3178e5f5e37a61ef0b
Author: Raushan Patel <raushan.jhon@gmail.com>
Date: Fri Jul 24 12:12:08 2026 +0530
tracing/fprobe: Roll back on enable_trace_fprobe() failure
enable_trace_fprobe() sets the file link or the TP_FLAG_PROFILE flag and
then registers each trace_fprobe in the probe list. If
__register_trace_fprobe() fails partway through, the function returns
immediately without unregistering the trace_fprobes it already registered
or undoing the file link / flag it set, leaving the event half-enabled and
leaking the registered fprobe(s).
enable_trace_kprobe() already handles this with a rollback path. Do the
same for fprobe: on failure, unregister all probes and clear the file link
or profile flag.
Link: https://lore.kernel.org/all/20260724064208.480030-1-raushan.jhon@gmail.com/
Fixes: 334e5519c375 ("tracing/probes: Add fprobe events for tracing function entry and exit.")
Cc: stable@vger.kernel.org
Signed-off-by: Raushan Patel <raushan.jhon@gmail.com>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c
index 9f5f08c0e7c2..3120403a5b60 100644
--- a/kernel/trace/trace_fprobe.c
+++ b/kernel/trace/trace_fprobe.c
@@ -1481,11 +1481,21 @@ static int enable_trace_fprobe(struct trace_event_call *call,
list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) {
ret = __register_trace_fprobe(tf);
if (ret < 0)
- return ret;
+ goto err;
}
}
return 0;
+
+err:
+ /* Failed to enable one of them. Roll back all */
+ list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list)
+ __unregister_trace_fprobe(tf);
+ if (file)
+ trace_probe_remove_file(tp, file);
+ else
+ trace_probe_clear_flag(tp, TP_FLAG_PROFILE);
+ return ret;
}
/*
]
|
| 84/2 |
2026/08/31 21:26 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 9726
output: 36
thoughts: 121
Thoughts: **Analyzing a Recent Kernel Commit**
Okay, so commit `aca0cd1bf165` is specifically addressing a critical failure scenario in tracepoint registration. The core issue is that when `__register_trace_fprobe()` fails mid-process, it currently *doesn't* roll back the registrations it *has* already completed. This means we're left with a potentially inconsistent state, with some probes registered and others not, leading to potential instability or unexpected behavior in the tracing system. The commit notes that `enable_trace_kprobe()` already has a rollback path to handle this problem. Excellent, so the fix is to implement the *same* robust unregistration/cleanup behavior for `fprobe`: If registration goes south, we *must* unregister everything that was previously registered and clear any associated file links or profiling flags. A very sensible solution.
Now, I'm thinking, let's see if this pattern—the need for explicit rollback on registration failure—appears elsewhere in the kernel, specifically within the `kernel/trace/` or `block/` directories. Maybe there are related commits addressing similar issues in these areas that could inform us or indicate potential related issues that we should look out for. Let's see if we can find any other similar solutions that could be relevant to this area of the code.
|
| 85/2 |
2026/08/31 21:26 |
tool |
git-log |
0m
Args: map[CodeRegexp:goto err PathPrefix:kernel/trace/ Since:3 years]
Results: map[Output:aca0cd1bf165 tracing/fprobe: Roll back on enable_trace_fprobe() failure
d471d4f86e86 tracing/remotes: Fix struct_len in trace_remote_alloc_buffer()
15d9968b68e8 tracing/synthetic: Free pending field on error path
d5dc200c3a3f bpf: Add missing access_ok call to copy_user_syms
ba042ed6446f bpf: Add support for tracing_multi link session
46b42af27d40 bpf: Add support for tracing_multi link cookies
c1d32dea5d46 bpf: Add support for tracing multi link
ea908a2b79c8 tracing: Add a trace remote module for testing
330b0cceb306 tracing: Add non-consuming read to trace remotes
9af4ab0e11e3 tracing: Add reset to trace remotes
]
|
| 86/2 |
2026/08/31 21:26 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 10409
output: 41
thoughts: 30
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating `enable_trace_kprobe()` in `trace_kprobe.c`**
Alright, time to dive into this. I'm thinking the best starting point is probably `kernel/trace/trace_kprobe.c`. Specifically, I need to understand what's happening within the `enable_trace_kprobe()` function. I'm betting that's where the core logic resides for enabling and initializing the kprobes, and that's where I need to focus my attention. It's the lynchpin function, if I recall correctly. I'll need to see how it manages the registration, what it does with the probe's address, and how it links everything together. It's a critical path to understanding the control flow and the state transitions related to kprobe enablement, which is essential to my broader investigation. Let's dig in and see what treasures this function holds.
|
| 87/2 |
2026/08/31 21:27 |
tool |
git-log |
0m
Args: map[CodeRegexp:enable_trace_kprobe PathPrefix:kernel/trace/ Since:10 years]
Results: map[Output:60d53e2c3b75 tracing/probe: Split trace_event related data from trace_probe
b5f935ee1339 tracing/probe: Add trace_event_file access APIs for trace_probe
87107a25a2f8 tracing/kprobes: Simplify the logic of enable_trace_kprobe()
]
|
| 88/2 |
2026/08/31 21:27 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 10792
output: 27
thoughts: 38
Thoughts: Here's a summary of my thoughts, as though I'm working through this commit:
**Analyzing `87107a25a2f8` "tracing/kprobes: Simplify the logic of enable_trace_kprobe()"**
Alright, let's dive into commit `87107a25a2f8` related to `tracing/kprobes`. The title itself suggests simplification, which is always a welcome sign. I need to understand what complexities existed before, and how they've been addressed. My gut tells me this will likely involve refactoring conditional logic, maybe consolidating duplicated code, and perhaps improving the overall readability and maintainability of the `enable_trace_kprobe()` function. I'll need to pay close attention to the potential impact on performance, error handling, and any subtle changes in behavior that might arise from this simplification. I'll be looking for comments that help clarify the previous design's rationale and why the changes are beneficial. Now, let's see what the diff says. I need to make sure this doesn't introduce any regressions to the kprobe infrastructure.
|
| 89/2 |
2026/08/31 21:27 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 87107a25a2f857693156f075da6e2a1438f4b4a0
Author: Steven Rostedt (VMware) <rostedt@goodmis.org>
Date: Thu Jul 26 12:07:32 2018 -0400
tracing/kprobes: Simplify the logic of enable_trace_kprobe()
The function enable_trace_kprobe() performs slightly differently if the file
parameter is passed in as NULL on non-NULL. Instead of checking file twice,
move the code between the two tests into a static inline helper function to
make the code easier to follow.
Link: http://lkml.kernel.org/r/20180725224728.7b1d5db2@vmware.local.home
Link: http://lkml.kernel.org/r/20180726121152.4dd54330@gandalf.local.home
Reviewed-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 6b71860f3998..0534eb8b7640 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -393,6 +393,20 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
return NULL;
}
+static inline int __enable_trace_kprobe(struct trace_kprobe *tk)
+{
+ int ret = 0;
+
+ if (trace_probe_is_registered(&tk->tp) && !trace_kprobe_has_gone(tk)) {
+ if (trace_kprobe_is_return(tk))
+ ret = enable_kretprobe(&tk->rp);
+ else
+ ret = enable_kprobe(&tk->rp.kp);
+ }
+
+ return ret;
+}
+
/*
* Enable trace_probe
* if the file is NULL, enable "perf" handler, or enable "trace" handler.
@@ -400,7 +414,7 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
static int
enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
{
- struct event_file_link *link = NULL;
+ struct event_file_link *link;
int ret = 0;
if (file) {
@@ -414,26 +428,18 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
list_add_tail_rcu(&link->list, &tk->tp.files);
tk->tp.flags |= TP_FLAG_TRACE;
- } else
- tk->tp.flags |= TP_FLAG_PROFILE;
-
- if (trace_probe_is_registered(&tk->tp) && !trace_kprobe_has_gone(tk)) {
- if (trace_kprobe_is_return(tk))
- ret = enable_kretprobe(&tk->rp);
- else
- ret = enable_kprobe(&tk->rp.kp);
- }
-
- if (ret) {
- if (file) {
- /* Notice the if is true on not WARN() */
- if (!WARN_ON_ONCE(!link))
- list_del_rcu(&link->list);
+ ret = __enable_trace_kprobe(tk);
+ if (ret) {
+ list_del_rcu(&link->list);
kfree(link);
tk->tp.flags &= ~TP_FLAG_TRACE;
- } else {
- tk->tp.flags &= ~TP_FLAG_PROFILE;
}
+
+ } else {
+ tk->tp.flags |= TP_FLAG_PROFILE;
+ ret = __enable_trace_kprobe(tk);
+ if (ret)
+ tk->tp.flags &= ~TP_FLAG_PROFILE;
}
out:
return ret;
]
|
| 90/2 |
2026/08/31 21:27 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 12259
output: 35
thoughts: 130
Thoughts: **Analyzing Error Handling in Tracepoint Registration**
Okay, so I'm looking at how we handle potential failures during tracepoint registration, specifically focusing on kernel probes (`kprobe`) and potentially `uprobe`. From the `enable_trace_kprobe` function (circa 2018), it's clear that if `__enable_trace_kprobe()` fails, we make sure to clean up by resetting flags and freeing the link – good, basic error handling.
Now, I want to expand this view. The `ret` in `enable_trace_kprobe` is a good place to start, but to get a broader understanding, I need to look at other parts of the tracing infrastructure. The `kernel/trace/trace_uprobe.c` file feels like a good spot to start, or other uses of `register_trace_*`. But wait, that rings a bell. These `register_trace_*` functions... they're generated by the `TRACE_EVENT` macros, right? That's right. So, I need to broaden the search. I should search for `register_trace_` across the kernel, specifically in the `kernel/trace/` directory, `block/` and other subsystems to understand how different subsystems deal with registration errors. This should provide a more complete picture of the best practices and potential pitfalls in these tracepoint registration contexts.
|
| 91/2 |
2026/08/31 21:27 |
tool |
grepper |
0m
Args: map[Expression:register_trace_[a-zA-Z0-9_]+\( PathPrefix:]
Results: map[Output:
Full output is too long, showing 500 out of 882 lines.
Use more precise expression if possible.
Documentation/trace/tracepoints.rst=94=probe (function to call) for the specific tracepoint through
Documentation/trace/tracepoints.rst:95:register_trace_subsys_eventname(). Removing a probe is done through
Documentation/trace/tracepoints.rst:96:unregister_trace_subsys_eventname(); it will remove the probe.
Documentation/trace/tracepoints.rst-97-
--
arch/powerpc/platforms/pseries/hvCall_inst.c=112=static int __init hcall_inst_init(void)
--
arch/powerpc/platforms/pseries/hvCall_inst.c-120-
arch/powerpc/platforms/pseries/hvCall_inst.c:121: if (register_trace_hcall_entry(probe_hcall_entry, NULL))
arch/powerpc/platforms/pseries/hvCall_inst.c-122- return -EINVAL;
arch/powerpc/platforms/pseries/hvCall_inst.c-123-
arch/powerpc/platforms/pseries/hvCall_inst.c:124: if (register_trace_hcall_exit(probe_hcall_exit, NULL)) {
arch/powerpc/platforms/pseries/hvCall_inst.c:125: unregister_trace_hcall_entry(probe_hcall_entry, NULL);
arch/powerpc/platforms/pseries/hvCall_inst.c-126- return -EINVAL;
--
arch/x86/kernel/trace.c=26=int osnoise_arch_register(void)
--
arch/x86/kernel/trace.c-29-
arch/x86/kernel/trace.c:30: ret = register_trace_local_timer_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-31- if (ret)
--
arch/x86/kernel/trace.c-33-
arch/x86/kernel/trace.c:34: ret = register_trace_local_timer_exit(trace_intel_irq_exit, "local_timer");
arch/x86/kernel/trace.c-35- if (ret)
--
arch/x86/kernel/trace.c-38-#ifdef CONFIG_X86_THERMAL_VECTOR
arch/x86/kernel/trace.c:39: ret = register_trace_thermal_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-40- if (ret)
--
arch/x86/kernel/trace.c-42-
arch/x86/kernel/trace.c:43: ret = register_trace_thermal_apic_exit(trace_intel_irq_exit, "thermal_apic");
arch/x86/kernel/trace.c-44- if (ret)
--
arch/x86/kernel/trace.c-48-#ifdef CONFIG_X86_MCE_AMD
arch/x86/kernel/trace.c:49: ret = register_trace_deferred_error_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-50- if (ret)
--
arch/x86/kernel/trace.c-52-
arch/x86/kernel/trace.c:53: ret = register_trace_deferred_error_apic_exit(trace_intel_irq_exit, "deferred_error");
arch/x86/kernel/trace.c-54- if (ret)
--
arch/x86/kernel/trace.c-58-#ifdef CONFIG_X86_MCE_THRESHOLD
arch/x86/kernel/trace.c:59: ret = register_trace_threshold_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-60- if (ret)
--
arch/x86/kernel/trace.c-62-
arch/x86/kernel/trace.c:63: ret = register_trace_threshold_apic_exit(trace_intel_irq_exit, "threshold_apic");
arch/x86/kernel/trace.c-64- if (ret)
--
arch/x86/kernel/trace.c-68-#ifdef CONFIG_SMP
arch/x86/kernel/trace.c:69: ret = register_trace_call_function_single_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-70- if (ret)
--
arch/x86/kernel/trace.c-72-
arch/x86/kernel/trace.c:73: ret = register_trace_call_function_single_exit(trace_intel_irq_exit,
arch/x86/kernel/trace.c-74- "call_function_single");
--
arch/x86/kernel/trace.c-77-
arch/x86/kernel/trace.c:78: ret = register_trace_call_function_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-79- if (ret)
--
arch/x86/kernel/trace.c-81-
arch/x86/kernel/trace.c:82: ret = register_trace_call_function_exit(trace_intel_irq_exit, "call_function");
arch/x86/kernel/trace.c-83- if (ret)
--
arch/x86/kernel/trace.c-85-
arch/x86/kernel/trace.c:86: ret = register_trace_reschedule_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-87- if (ret)
--
arch/x86/kernel/trace.c-89-
arch/x86/kernel/trace.c:90: ret = register_trace_reschedule_exit(trace_intel_irq_exit, "reschedule");
arch/x86/kernel/trace.c-91- if (ret)
--
arch/x86/kernel/trace.c-95-#ifdef CONFIG_IRQ_WORK
arch/x86/kernel/trace.c:96: ret = register_trace_irq_work_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-97- if (ret)
--
arch/x86/kernel/trace.c-99-
arch/x86/kernel/trace.c:100: ret = register_trace_irq_work_exit(trace_intel_irq_exit, "irq_work");
arch/x86/kernel/trace.c-101- if (ret)
--
arch/x86/kernel/trace.c-104-
arch/x86/kernel/trace.c:105: ret = register_trace_x86_platform_ipi_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-106- if (ret)
--
arch/x86/kernel/trace.c-108-
arch/x86/kernel/trace.c:109: ret = register_trace_x86_platform_ipi_exit(trace_intel_irq_exit, "x86_platform_ipi");
arch/x86/kernel/trace.c-110- if (ret)
--
arch/x86/kernel/trace.c-112-
arch/x86/kernel/trace.c:113: ret = register_trace_error_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-114- if (ret)
--
arch/x86/kernel/trace.c-116-
arch/x86/kernel/trace.c:117: ret = register_trace_error_apic_exit(trace_intel_irq_exit, "error_apic");
arch/x86/kernel/trace.c-118- if (ret)
--
arch/x86/kernel/trace.c-120-
arch/x86/kernel/trace.c:121: ret = register_trace_spurious_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-122- if (ret)
--
arch/x86/kernel/trace.c-124-
arch/x86/kernel/trace.c:125: ret = register_trace_spurious_apic_exit(trace_intel_irq_exit, "spurious_apic");
arch/x86/kernel/trace.c-126- if (ret)
--
arch/x86/kernel/trace.c-131-out_spurious_apic_entry:
arch/x86/kernel/trace.c:132: unregister_trace_spurious_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-133-out_error_apic_exit:
arch/x86/kernel/trace.c:134: unregister_trace_error_apic_exit(trace_intel_irq_exit, "error_apic");
arch/x86/kernel/trace.c-135-out_error_apic_entry:
arch/x86/kernel/trace.c:136: unregister_trace_error_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-137-out_x86_ipi_exit:
arch/x86/kernel/trace.c:138: unregister_trace_x86_platform_ipi_exit(trace_intel_irq_exit, "x86_platform_ipi");
arch/x86/kernel/trace.c-139-out_x86_ipi_entry:
arch/x86/kernel/trace.c:140: unregister_trace_x86_platform_ipi_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-141-out_irq_work_exit:
--
arch/x86/kernel/trace.c-143-#ifdef CONFIG_IRQ_WORK
arch/x86/kernel/trace.c:144: unregister_trace_irq_work_exit(trace_intel_irq_exit, "irq_work");
arch/x86/kernel/trace.c-145-out_irq_work_entry:
arch/x86/kernel/trace.c:146: unregister_trace_irq_work_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-147-out_reschedule_exit:
--
arch/x86/kernel/trace.c-150-#ifdef CONFIG_SMP
arch/x86/kernel/trace.c:151: unregister_trace_reschedule_exit(trace_intel_irq_exit, "reschedule");
arch/x86/kernel/trace.c-152-out_reschedule_entry:
arch/x86/kernel/trace.c:153: unregister_trace_reschedule_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-154-out_call_function_exit:
arch/x86/kernel/trace.c:155: unregister_trace_call_function_exit(trace_intel_irq_exit, "call_function");
arch/x86/kernel/trace.c-156-out_call_function_entry:
arch/x86/kernel/trace.c:157: unregister_trace_call_function_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-158-out_call_function_single_exit:
arch/x86/kernel/trace.c:159: unregister_trace_call_function_single_exit(trace_intel_irq_exit, "call_function_single");
arch/x86/kernel/trace.c-160-out_call_function_single_entry:
arch/x86/kernel/trace.c:161: unregister_trace_call_function_single_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-162-out_threshold_exit:
--
arch/x86/kernel/trace.c-165-#ifdef CONFIG_X86_MCE_THRESHOLD
arch/x86/kernel/trace.c:166: unregister_trace_threshold_apic_exit(trace_intel_irq_exit, "threshold_apic");
arch/x86/kernel/trace.c-167-out_threshold_entry:
arch/x86/kernel/trace.c:168: unregister_trace_threshold_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-169-out_deferred_exit:
--
arch/x86/kernel/trace.c-172-#ifdef CONFIG_X86_MCE_AMD
arch/x86/kernel/trace.c:173: unregister_trace_deferred_error_apic_exit(trace_intel_irq_exit, "deferred_error");
arch/x86/kernel/trace.c-174-out_deferred_entry:
arch/x86/kernel/trace.c:175: unregister_trace_deferred_error_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-176-out_thermal_exit:
--
arch/x86/kernel/trace.c-179-#ifdef CONFIG_X86_THERMAL_VECTOR
arch/x86/kernel/trace.c:180: unregister_trace_thermal_apic_exit(trace_intel_irq_exit, "thermal_apic");
arch/x86/kernel/trace.c-181-out_thermal_entry:
arch/x86/kernel/trace.c:182: unregister_trace_thermal_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-183-out_timer_exit:
--
arch/x86/kernel/trace.c-185-
arch/x86/kernel/trace.c:186: unregister_trace_local_timer_exit(trace_intel_irq_exit, "local_timer");
arch/x86/kernel/trace.c-187-out_timer_entry:
arch/x86/kernel/trace.c:188: unregister_trace_local_timer_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-189-out_err:
--
arch/x86/kernel/trace.c=193=void osnoise_arch_unregister(void)
arch/x86/kernel/trace.c-194-{
arch/x86/kernel/trace.c:195: unregister_trace_spurious_apic_exit(trace_intel_irq_exit, "spurious_apic");
arch/x86/kernel/trace.c:196: unregister_trace_spurious_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c:197: unregister_trace_error_apic_exit(trace_intel_irq_exit, "error_apic");
arch/x86/kernel/trace.c:198: unregister_trace_error_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c:199: unregister_trace_x86_platform_ipi_exit(trace_intel_irq_exit, "x86_platform_ipi");
arch/x86/kernel/trace.c:200: unregister_trace_x86_platform_ipi_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-201-
arch/x86/kernel/trace.c-202-#ifdef CONFIG_IRQ_WORK
arch/x86/kernel/trace.c:203: unregister_trace_irq_work_exit(trace_intel_irq_exit, "irq_work");
arch/x86/kernel/trace.c:204: unregister_trace_irq_work_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-205-#endif
--
arch/x86/kernel/trace.c-207-#ifdef CONFIG_SMP
arch/x86/kernel/trace.c:208: unregister_trace_reschedule_exit(trace_intel_irq_exit, "reschedule");
arch/x86/kernel/trace.c:209: unregister_trace_reschedule_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c:210: unregister_trace_call_function_exit(trace_intel_irq_exit, "call_function");
arch/x86/kernel/trace.c:211: unregister_trace_call_function_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c:212: unregister_trace_call_function_single_exit(trace_intel_irq_exit, "call_function_single");
arch/x86/kernel/trace.c:213: unregister_trace_call_function_single_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-214-#endif
--
arch/x86/kernel/trace.c-216-#ifdef CONFIG_X86_MCE_THRESHOLD
arch/x86/kernel/trace.c:217: unregister_trace_threshold_apic_exit(trace_intel_irq_exit, "threshold_apic");
arch/x86/kernel/trace.c:218: unregister_trace_threshold_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-219-#endif
--
arch/x86/kernel/trace.c-221-#ifdef CONFIG_X86_MCE_AMD
arch/x86/kernel/trace.c:222: unregister_trace_deferred_error_apic_exit(trace_intel_irq_exit, "deferred_error");
arch/x86/kernel/trace.c:223: unregister_trace_deferred_error_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-224-#endif
--
arch/x86/kernel/trace.c-226-#ifdef CONFIG_X86_THERMAL_VECTOR
arch/x86/kernel/trace.c:227: unregister_trace_thermal_apic_exit(trace_intel_irq_exit, "thermal_apic");
arch/x86/kernel/trace.c:228: unregister_trace_thermal_apic_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-229-#endif /* CONFIG_X86_THERMAL_VECTOR */
arch/x86/kernel/trace.c-230-
arch/x86/kernel/trace.c:231: unregister_trace_local_timer_exit(trace_intel_irq_exit, "local_timer");
arch/x86/kernel/trace.c:232: unregister_trace_local_timer_entry(trace_intel_irq_entry, NULL);
arch/x86/kernel/trace.c-233-}
--
include/linux/trace_events.h=158=struct trace_event {
--
include/linux/trace_events.h-163-
include/linux/trace_events.h:164:extern int register_trace_event(struct trace_event *event);
include/linux/trace_events.h:165:extern int unregister_trace_event(struct trace_event *event);
include/linux/trace_events.h-166-
--
init/main.c=1312=static void __init initcall_debug_enable(void)
--
init/main.c-1315-
init/main.c:1316: ret = register_trace_initcall_start(trace_initcall_start_cb,
init/main.c-1317- &initcall_calltime);
init/main.c:1318: ret |= register_trace_initcall_finish(trace_initcall_finish_cb,
init/main.c-1319- &initcall_calltime);
init/main.c:1320: ret |= register_trace_initcall_level(trace_initcall_level_cb, NULL);
init/main.c-1321- WARN(ret, "Failed to register initcall tracepoints\n");
--
kernel/kcsan/kcsan_test.c=1589=static void register_tracepoints(void)
kernel/kcsan/kcsan_test.c-1590-{
kernel/kcsan/kcsan_test.c:1591: register_trace_console(probe_console, NULL);
kernel/kcsan/kcsan_test.c-1592-}
--
kernel/kcsan/kcsan_test.c=1595=static void unregister_tracepoints(void)
kernel/kcsan/kcsan_test.c-1596-{
kernel/kcsan/kcsan_test.c:1597: unregister_trace_console(probe_console, NULL);
kernel/kcsan/kcsan_test.c-1598-}
--
kernel/trace/blktrace.c=1327=static void blk_register_tracepoints(void)
--
kernel/trace/blktrace.c-1330-
kernel/trace/blktrace.c:1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1332- WARN_ON(ret);
kernel/trace/blktrace.c:1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c-1334- WARN_ON(ret);
kernel/trace/blktrace.c:1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c-1336- WARN_ON(ret);
kernel/trace/blktrace.c:1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c-1338- WARN_ON(ret);
kernel/trace/blktrace.c:1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c-1340- WARN_ON(ret);
kernel/trace/blktrace.c:1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c-1342- WARN_ON(ret);
kernel/trace/blktrace.c:1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c-1344- WARN_ON(ret);
kernel/trace/blktrace.c:1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c-1346- WARN_ON(ret);
kernel/trace/blktrace.c:1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c-1348- WARN_ON(ret);
kernel/trace/blktrace.c:1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c-1350- WARN_ON(ret);
kernel/trace/blktrace.c:1351: ret = register_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1352- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c-1353- WARN_ON(ret);
kernel/trace/blktrace.c:1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
kernel/trace/blktrace.c-1355- NULL);
kernel/trace/blktrace.c-1356- WARN_ON(ret);
kernel/trace/blktrace.c:1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
kernel/trace/blktrace.c-1358- NULL);
kernel/trace/blktrace.c-1359- WARN_ON(ret);
kernel/trace/blktrace.c:1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c-1361- WARN_ON(ret);
kernel/trace/blktrace.c:1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c-1363- WARN_ON(ret);
kernel/trace/blktrace.c:1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c-1365- WARN_ON(ret);
kernel/trace/blktrace.c:1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c-1367- WARN_ON(ret);
kernel/trace/blktrace.c:1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c-1369- WARN_ON(ret);
--
kernel/trace/blktrace.c=1372=static void blk_unregister_tracepoints(void)
kernel/trace/blktrace.c-1373-{
kernel/trace/blktrace.c:1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c:1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c:1376: unregister_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c:1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c:1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c:1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
kernel/trace/blktrace.c:1380: unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
kernel/trace/blktrace.c:1381: unregister_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1382- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c:1383: unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c:1384: unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c:1385: unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c:1386: unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c:1387: unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c:1388: unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c:1389: unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c:1390: unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c:1391: unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c:1392: unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1393-
--
kernel/trace/blktrace.c=1839=static int __init __init_blk_tracer(void)
kernel/trace/blktrace.c-1840-{
kernel/trace/blktrace.c:1841: if (!register_trace_event(&trace_blk_event)) {
kernel/trace/blktrace.c-1842- pr_warn("Warning: could not register block events\n");
--
kernel/trace/blktrace.c-1847- pr_warn("Warning: could not register the block tracer\n");
kernel/trace/blktrace.c:1848: unregister_trace_event(&trace_blk_event);
kernel/trace/blktrace.c-1849- return 1;
--
kernel/trace/fgraph.c=1236=static int start_graph_tracing(void)
--
kernel/trace/fgraph.c-1257- if (!ret) {
kernel/trace/fgraph.c:1258: ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
kernel/trace/fgraph.c-1259- if (ret)
--
kernel/trace/fgraph.c=1426=void unregister_ftrace_graph(struct fgraph_ops *gops)
--
kernel/trace/fgraph.c-1463- unregister_pm_notifier(&ftrace_suspend_notifier);
kernel/trace/fgraph.c:1464: unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
kernel/trace/fgraph.c-1465- }
--
kernel/trace/ftrace.c=8691=void ftrace_pid_follow_fork(struct trace_array *tr, bool enable)
--
kernel/trace/ftrace.c-8693- if (enable) {
kernel/trace/ftrace.c:8694: register_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
kernel/trace/ftrace.c-8695- tr);
kernel/trace/ftrace.c:8696: register_trace_sched_process_free(ftrace_pid_follow_sched_process_exit,
kernel/trace/ftrace.c-8697- tr);
kernel/trace/ftrace.c-8698- } else {
kernel/trace/ftrace.c:8699: unregister_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
kernel/trace/ftrace.c-8700- tr);
kernel/trace/ftrace.c:8701: unregister_trace_sched_process_free(ftrace_pid_follow_sched_process_exit,
kernel/trace/ftrace.c-8702- tr);
--
kernel/trace/ftrace.c=8706=static void clear_ftrace_pids(struct trace_array *tr, int type)
--
kernel/trace/ftrace.c-8722- if (!still_need_pid_events(type, pid_list, no_pid_list)) {
kernel/trace/ftrace.c:8723: unregister_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr);
kernel/trace/ftrace.c-8724- for_each_possible_cpu(cpu)
--
kernel/trace/ftrace.c=8932=pid_write(struct file *filp, const char __user *ubuf,
--
kernel/trace/ftrace.c-8983- /* Register a probe to set whether to ignore the tracing of a task */
kernel/trace/ftrace.c:8984: register_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr);
kernel/trace/ftrace.c-8985- }
--
kernel/trace/trace_branch.c=178=__init static int init_branch_tracer(void)
--
kernel/trace/trace_branch.c-181-
kernel/trace/trace_branch.c:182: ret = register_trace_event(&trace_branch_event);
kernel/trace/trace_branch.c-183- if (!ret) {
--
kernel/trace/trace_eprobe.c=77=static int eprobe_dyn_event_show(struct seq_file *m, struct dyn_event *ev)
--
kernel/trace/trace_eprobe.c-94-
kernel/trace/trace_eprobe.c:95:static int unregister_trace_eprobe(struct trace_eprobe *ep)
kernel/trace/trace_eprobe.c-96-{
--
kernel/trace/trace_eprobe.c=116=static int eprobe_dyn_event_release(struct dyn_event *ev)
--
kernel/trace/trace_eprobe.c-118- struct trace_eprobe *ep = to_trace_eprobe(ev);
kernel/trace/trace_eprobe.c:119: int ret = unregister_trace_eprobe(ep);
kernel/trace/trace_eprobe.c-120-
--
kernel/trace/trace_events.c=645=int trace_event_raw_init(struct trace_event_call *call)
--
kernel/trace/trace_events.c-648-
kernel/trace/trace_events.c:649: id = register_trace_event(&call->event);
kernel/trace/trace_events.c-650- if (!id)
--
kernel/trace/trace_events.c=1093=void trace_event_follow_fork(struct trace_array *tr, bool enable)
--
kernel/trace/trace_events.c-1095- if (enable) {
kernel/trace/trace_events.c:1096: register_trace_prio_sched_process_fork(event_filter_pid_sched_process_fork,
kernel/trace/trace_events.c-1097- tr, INT_MIN);
kernel/trace/trace_events.c:1098: register_trace_prio_sched_process_free(event_filter_pid_sched_process_exit,
kernel/trace/trace_events.c-1099- tr, INT_MAX);
kernel/trace/trace_events.c-1100- } else {
kernel/trace/trace_events.c:1101: unregister_trace_sched_process_fork(event_filter_pid_sched_process_fork,
kernel/trace/trace_events.c-1102- tr);
kernel/trace/trace_events.c:1103: unregister_trace_sched_process_free(event_filter_pid_sched_process_exit,
kernel/trace/trace_events.c-1104- tr);
--
kernel/trace/trace_events.c=1188=static void unregister_pid_events(struct trace_array *tr)
kernel/trace/trace_events.c-1189-{
kernel/trace/trace_events.c:1190: unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_pre, tr);
kernel/trace/trace_events.c:1191: unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_post, tr);
kernel/trace/trace_events.c-1192-
kernel/trace/trace_events.c:1193: unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1194: unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1195-
kernel/trace/trace_events.c:1196: unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1197: unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1198-
kernel/trace/trace_events.c:1199: unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1200: unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1201-}
--
kernel/trace/trace_events.c=2562=static void register_pid_events(struct trace_array *tr)
--
kernel/trace/trace_events.c-2569- */
kernel/trace/trace_events.c:2570: register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_pre,
kernel/trace/trace_events.c-2571- tr, INT_MAX);
kernel/trace/trace_events.c:2572: register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_post,
kernel/trace/trace_events.c-2573- tr, 0);
kernel/trace/trace_events.c-2574-
kernel/trace/trace_events.c:2575: register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2576- tr, INT_MAX);
kernel/trace/trace_events.c:2577: register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2578- tr, 0);
kernel/trace/trace_events.c-2579-
kernel/trace/trace_events.c:2580: register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2581- tr, INT_MAX);
kernel/trace/trace_events.c:2582: register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2583- tr, 0);
kernel/trace/trace_events.c-2584-
kernel/trace/trace_events.c:2585: register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2586- tr, INT_MAX);
kernel/trace/trace_events.c:2587: register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2588- tr, 0);
--
kernel/trace/trace_events.c=3350=static void event_remove(struct trace_event_call *call)
--
kernel/trace/trace_events.c-3372- if (call->event.funcs)
kernel/trace/trace_events.c:3373: __unregister_trace_event(&call->event);
kernel/trace/trace_events.c-3374- remove_event_from_tracers(call);
--
kernel/trace/trace_events_synth.c=955=static int register_synth_event(struct synth_event *event)
--
kernel/trace/trace_events_synth.c-977-
kernel/trace/trace_events_synth.c:978: ret = register_trace_event(&call->event);
kernel/trace/trace_events_synth.c-979- if (!ret) {
--
kernel/trace/trace_events_synth.c-999- ret = set_synth_event_print_fmt(call);
kernel/trace/trace_events_synth.c:1000: /* unregister_trace_event() will be called inside */
kernel/trace/trace_events_synth.c-1001- if (ret < 0)
--
kernel/trace/trace_events_synth.c-1005- err:
kernel/trace/trace_events_synth.c:1006: unregister_trace_event(&call->event);
kernel/trace/trace_events_synth.c-1007- goto out;
--
kernel/trace/trace_events_user.c=1966=static int user_event_trace_register(struct user_event *user)
--
kernel/trace/trace_events_user.c-1969-
kernel/trace/trace_events_user.c:1970: ret = register_trace_event(&user->call.event);
kernel/trace/trace_events_user.c-1971-
--
kernel/trace/trace_events_user.c-1977- if (ret)
kernel/trace/trace_events_user.c:1978: unregister_trace_event(&user->call.event);
kernel/trace/trace_events_user.c-1979-
--
kernel/trace/trace_fprobe.c=797=static int trace_fprobe_verify_target(struct trace_fprobe *tf)
--
kernel/trace/trace_fprobe.c-813-/* Internal register function - just handle fprobe and flags */
kernel/trace/trace_fprobe.c:814:static int __register_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-815-{
--
kernel/trace/trace_fprobe.c-841-/* Internal unregister function - just handle fprobe and flags */
kernel/trace/trace_fprobe.c:842:static void __unregister_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-843-{
--
kernel/trace/trace_fprobe.c-853-/* Unregister a trace_probe and probe_event */
kernel/trace/trace_fprobe.c:854:static int unregister_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-855-{
--
kernel/trace/trace_fprobe.c-872-unreg:
kernel/trace/trace_fprobe.c:873: __unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-874- dyn_event_remove(&tf->devent);
--
kernel/trace/trace_fprobe.c=908=static int append_trace_fprobe_event(struct trace_fprobe *tf, struct trace_fprobe *to)
--
kernel/trace/trace_fprobe.c-945-/* Register a trace_probe and probe_event, and check the fprobe is available. */
kernel/trace/trace_fprobe.c:946:static int register_trace_fprobe_event(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-947-{
--
kernel/trace/trace_fprobe.c=1209=static int trace_fprobe_create_internal(int argc, const char *argv[],
--
kernel/trace/trace_fprobe.c-1378-
kernel/trace/trace_fprobe.c:1379: ret = register_trace_fprobe_event(tf);
kernel/trace/trace_fprobe.c-1380- if (ret) {
--
kernel/trace/trace_fprobe.c=1419=static int trace_fprobe_release(struct dyn_event *ev)
--
kernel/trace/trace_fprobe.c-1421- struct trace_fprobe *tf = to_trace_fprobe(ev);
kernel/trace/trace_fprobe.c:1422: int ret = unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1423-
--
kernel/trace/trace_fprobe.c=1457=static int enable_trace_fprobe(struct trace_event_call *call,
--
kernel/trace/trace_fprobe.c-1479- list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) {
kernel/trace/trace_fprobe.c:1480: ret = __register_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1481- if (ret < 0)
--
kernel/trace/trace_fprobe.c-1490- list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list)
kernel/trace/trace_fprobe.c:1491: __unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1492- if (file)
--
kernel/trace/trace_functions_graph.c=1814=static __init int init_graph_trace(void)
--
kernel/trace/trace_functions_graph.c-1817-
kernel/trace/trace_functions_graph.c:1818: if (!register_trace_event(&graph_trace_entry_event)) {
kernel/trace/trace_functions_graph.c-1819- pr_warn("Warning: could not register graph trace events\n");
--
kernel/trace/trace_functions_graph.c-1823-#ifdef CONFIG_FUNCTION_GRAPH_RETADDR
]
|
| 92/2 |
2026/08/31 21:27 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 24965
output: 34
thoughts: 478
Thoughts: **Analyzing Tracepoint Registration and Error Handling**
Okay, so I've pinpointed the relevant code: `kernel/trace/blktrace.c:1327`. Specifically, `blk_register_tracepoints()`. This is where the tracepoints are registered, using functions like `register_trace_block_rq_insert()` and `register_trace_block_rq_issue()`. That's the starting point for addressing the bug. This is the code that needs fixing, or at least understanding, in relation to previous patterns.
My focus now is on best practices for handling potential registration failures. The prompt demands a summary of idioms, locking rules, or common patterns observed in similar fixes.
The `arch/x86/kernel/trace.c` file from the grep output is incredibly helpful. It demonstrates a very clear pattern. The `osnoise_arch_register` function registers several tracepoints, checks the return value (`ret`) of each registration, and *crucially*, if a registration fails, it jumps to a labeled section to unregister the previously registered tracepoints in reverse order. The specific labels involved in the example are `out_spurious_apic_entry` and `out_error_apic_exit`. This is *exactly* the idiom I'm looking for!
So, the pattern is:
1. **Register multiple tracepoints.**
2. **Check the return value (error code) of *each* registration.**
3. **If an error occurs, jump to a label that handles unregistering any *previously* registered tracepoints, in reverse order of registration.**
I now need to find a past commit to confirm if this pattern is considered best practice. I'll search for commits around this file or with similar keywords. If there are no past fixes, I will have to state so.
|
| 93/2 |
2026/08/31 21:27 |
tool |
git-log |
0m
Args: map[PathPrefix:arch/x86/kernel/trace.c Since:3 years]
Results:
|
| 94/2 |
2026/08/31 21:27 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 25883
output: 27
thoughts: 32
Thoughts: Here's my thinking:
**Debugging the Trace.c Search**
Okay, so I just ran a search and used the `Since="3 years"` filter on `arch/x86/kernel/trace.c`, but it came back with *nothing*. That's not right. I'm getting suspicious. I need to figure out why. Clearly, the filter isn't behaving as I expect it to in this case. My first thought is that there might be an issue with how the filtering is being interpreted in conjunction with that specific file path. Let's start by isolating the problem and removing the `Since` parameter altogether. Maybe the issue is just with that filtering component. If the standard search with just the file path produces results, then the `Since` filter is clearly where the problem lies. That will give me a clear path to go down to further investigate the issue.
|
| 95/2 |
2026/08/31 21:27 |
tool |
git-log |
0m
Args: map[PathPrefix:arch/x86/kernel/trace.c]
Results: map[Output:9bd985766a43 trace/osnoise: Fix an ifdef comment
f7d9f6370e00 trace/osnoise: Fix 'no previous prototype' warnings
bce29ac9ce0b trace: Add osnoise tracer
]
|
| 96/2 |
2026/08/31 21:27 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 26204
output: 24
thoughts: 23
Thoughts: Here's a summary of my immediate thought process, focusing on an expert perspective:
**Initial Assessment of a Commit Hash**
Okay, `bce29ac9ce0b`... Let's see. My first thought is to immediately grab the context. It's a commit hash, so likely from a version control system like Git. I need to quickly recall the associated project, repository, and branch. Based on the commit message, "trace: Add osnoise tracer," I'm already mentally classifying this as related to system-level tracing, possibly performance analysis or debugging tools within an operating system context. My experience suggests "osnoise" is likely referring to noise within the OS, which could impact latency or introduce jitter. I'm primed to look for changes in tracing instrumentation, perhaps a new kernel module, user-space tools, or improvements to existing tracing infrastructure. My immediate objective is to rapidly assess the scope and potential impact of this change.
|
| 97/2 |
2026/08/31 21:27 |
tool |
git-show |
0m
Args:
Results: map[Output:
Full output is too long, showing 1000 out of 2416 lines.
[commit bce29ac9ce0bb0b0b146b687ab978378c21e9078
Author: Daniel Bristot de Oliveira <bristot@redhat.com>
Date: Tue Jun 22 16:42:27 2021 +0200
trace: Add osnoise tracer
In the context of high-performance computing (HPC), the Operating System
Noise (*osnoise*) refers to the interference experienced by an application
due to activities inside the operating system. In the context of Linux,
NMIs, IRQs, SoftIRQs, and any other system thread can cause noise to the
system. Moreover, hardware-related jobs can also cause noise, for example,
via SMIs.
The osnoise tracer leverages the hwlat_detector by running a similar
loop with preemption, SoftIRQs and IRQs enabled, thus allowing all
the sources of *osnoise* during its execution. Using the same approach
of hwlat, osnoise takes note of the entry and exit point of any
source of interferences, increasing a per-cpu interference counter. The
osnoise tracer also saves an interference counter for each source of
interference. The interference counter for NMI, IRQs, SoftIRQs, and
threads is increased anytime the tool observes these interferences' entry
events. When a noise happens without any interference from the operating
system level, the hardware noise counter increases, pointing to a
hardware-related noise. In this way, osnoise can account for any
source of interference. At the end of the period, the osnoise tracer
prints the sum of all noise, the max single noise, the percentage of CPU
available for the thread, and the counters for the noise sources.
Usage
Write the ASCII text "osnoise" into the current_tracer file of the
tracing system (generally mounted at /sys/kernel/tracing).
For example::
[root@f32 ~]# cd /sys/kernel/tracing/
[root@f32 tracing]# echo osnoise > current_tracer
It is possible to follow the trace by reading the trace trace file::
[root@f32 tracing]# cat trace
# tracer: osnoise
#
# _-----=> irqs-off
# / _----=> need-resched
# | / _---=> hardirq/softirq
# || / _--=> preempt-depth MAX
# || / SINGLE Interference counters:
# |||| RUNTIME NOISE % OF CPU NOISE +-----------------------------+
# TASK-PID CPU# |||| TIMESTAMP IN US IN US AVAILABLE IN US HW NMI IRQ SIRQ THREAD
# | | | |||| | | | | | | | | | |
<...>-859 [000] .... 81.637220: 1000000 190 99.98100 9 18 0 1007 18 1
<...>-860 [001] .... 81.638154: 1000000 656 99.93440 74 23 0 1006 16 3
<...>-861 [002] .... 81.638193: 1000000 5675 99.43250 202 6 0 1013 25 21
<...>-862 [003] .... 81.638242: 1000000 125 99.98750 45 1 0 1011 23 0
<...>-863 [004] .... 81.638260: 1000000 1721 99.82790 168 7 0 1002 49 41
<...>-864 [005] .... 81.638286: 1000000 263 99.97370 57 6 0 1006 26 2
<...>-865 [006] .... 81.638302: 1000000 109 99.98910 21 3 0 1006 18 1
<...>-866 [007] .... 81.638326: 1000000 7816 99.21840 107 8 0 1016 39 19
In addition to the regular trace fields (from TASK-PID to TIMESTAMP), the
tracer prints a message at the end of each period for each CPU that is
running an osnoise/CPU thread. The osnoise specific fields report:
- The RUNTIME IN USE reports the amount of time in microseconds that
the osnoise thread kept looping reading the time.
- The NOISE IN US reports the sum of noise in microseconds observed
by the osnoise tracer during the associated runtime.
- The % OF CPU AVAILABLE reports the percentage of CPU available for
the osnoise thread during the runtime window.
- The MAX SINGLE NOISE IN US reports the maximum single noise observed
during the runtime window.
- The Interference counters display how many each of the respective
interference happened during the runtime window.
Note that the example above shows a high number of HW noise samples.
The reason being is that this sample was taken on a virtual machine,
and the host interference is detected as a hardware interference.
Tracer options
The tracer has a set of options inside the osnoise directory, they are:
- osnoise/cpus: CPUs at which a osnoise thread will execute.
- osnoise/period_us: the period of the osnoise thread.
- osnoise/runtime_us: how long an osnoise thread will look for noise.
- osnoise/stop_tracing_us: stop the system tracing if a single noise
higher than the configured value happens. Writing 0 disables this
option.
- osnoise/stop_tracing_total_us: stop the system tracing if total noise
higher than the configured value happens. Writing 0 disables this
option.
- tracing_threshold: the minimum delta between two time() reads to be
considered as noise, in us. When set to 0, the default value will
be used, which is currently 5 us.
Additional Tracing
In addition to the tracer, a set of tracepoints were added to
facilitate the identification of the osnoise source.
- osnoise:sample_threshold: printed anytime a noise is higher than
the configurable tolerance_ns.
- osnoise:nmi_noise: noise from NMI, including the duration.
- osnoise:irq_noise: noise from an IRQ, including the duration.
- osnoise:softirq_noise: noise from a SoftIRQ, including the
duration.
- osnoise:thread_noise: noise from a thread, including the duration.
Note that all the values are *net values*. For example, if while osnoise
is running, another thread preempts the osnoise thread, it will start a
thread_noise duration at the start. Then, an IRQ takes place, preempting
the thread_noise, starting a irq_noise. When the IRQ ends its execution,
it will compute its duration, and this duration will be subtracted from
the thread_noise, in such a way as to avoid the double accounting of the
IRQ execution. This logic is valid for all sources of noise.
Here is one example of the usage of these tracepoints::
osnoise/8-961 [008] d.h. 5789.857532: irq_noise: local_timer:236 start 5789.857529929 duration 1845 ns
osnoise/8-961 [008] dNh. 5789.858408: irq_noise: local_timer:236 start 5789.858404871 duration 2848 ns
migration/8-54 [008] d... 5789.858413: thread_noise: migration/8:54 start 5789.858409300 duration 3068 ns
osnoise/8-961 [008] .... 5789.858413: sample_threshold: start 5789.858404555 duration 8723 ns interferences 2
In this example, a noise sample of 8 microseconds was reported in the last
line, pointing to two interferences. Looking backward in the trace, the
two previous entries were about the migration thread running after a
timer IRQ execution. The first event is not part of the noise because
it took place one millisecond before.
It is worth noticing that the sum of the duration reported in the
tracepoints is smaller than eight us reported in the sample_threshold.
The reason roots in the overhead of the entry and exit code that happens
before and after any interference execution. This justifies the dual
approach: measuring thread and tracing.
Link: https://lkml.kernel.org/r/e649467042d60e7b62714c9c6751a56299d15119.1624372313.git.bristot@redhat.com
Cc: Phil Auld <pauld@redhat.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Kate Carcia <kcarcia@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Alexandre Chartre <alexandre.chartre@oracle.com>
Cc: Clark Willaims <williams@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Daniel Bristot de Oliveira <bristot@redhat.com>
[
Made the following functions static:
trace_irqentry_callback()
trace_irqexit_callback()
trace_intel_irqentry_callback()
trace_intel_irqexit_callback()
Added to include/trace.h:
osnoise_arch_register()
osnoise_arch_unregister()
Fixed define logic for LATENCY_FS_NOTIFY
Reported-by: kernel test robot <lkp@intel.com>
]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
diff --git a/Documentation/trace/index.rst b/Documentation/trace/index.rst
index f634b36fd3aa..608107b27cc0 100644
--- a/Documentation/trace/index.rst
+++ b/Documentation/trace/index.rst
@@ -23,6 +23,7 @@ Linux Tracing Technologies
histogram-design
boottime-trace
hwlat_detector
+ osnoise-tracer
intel_th
ring-buffer-design
stm
diff --git a/Documentation/trace/osnoise-tracer.rst b/Documentation/trace/osnoise-tracer.rst
new file mode 100644
index 000000000000..37a3c10fb216
--- /dev/null
+++ b/Documentation/trace/osnoise-tracer.rst
@@ -0,0 +1,152 @@
+==============
+OSNOISE Tracer
+==============
+
+In the context of high-performance computing (HPC), the Operating System
+Noise (*osnoise*) refers to the interference experienced by an application
+due to activities inside the operating system. In the context of Linux,
+NMIs, IRQs, SoftIRQs, and any other system thread can cause noise to the
+system. Moreover, hardware-related jobs can also cause noise, for example,
+via SMIs.
+
+hwlat_detector is one of the tools used to identify the most complex
+source of noise: *hardware noise*.
+
+In a nutshell, the hwlat_detector creates a thread that runs
+periodically for a given period. At the beginning of a period, the thread
+disables interrupt and starts sampling. While running, the hwlatd
+thread reads the time in a loop. As interrupts are disabled, threads,
+IRQs, and SoftIRQs cannot interfere with the hwlatd thread. Hence, the
+cause of any gap between two different reads of the time roots either on
+NMI or in the hardware itself. At the end of the period, hwlatd enables
+interrupts and reports the max observed gap between the reads. It also
+prints a NMI occurrence counter. If the output does not report NMI
+executions, the user can conclude that the hardware is the culprit for
+the latency. The hwlat detects the NMI execution by observing
+the entry and exit of a NMI.
+
+The osnoise tracer leverages the hwlat_detector by running a
+similar loop with preemption, SoftIRQs and IRQs enabled, thus allowing
+all the sources of *osnoise* during its execution. Using the same approach
+of hwlat, osnoise takes note of the entry and exit point of any
+source of interferences, increasing a per-cpu interference counter. The
+osnoise tracer also saves an interference counter for each source of
+interference. The interference counter for NMI, IRQs, SoftIRQs, and
+threads is increased anytime the tool observes these interferences' entry
+events. When a noise happens without any interference from the operating
+system level, the hardware noise counter increases, pointing to a
+hardware-related noise. In this way, osnoise can account for any
+source of interference. At the end of the period, the osnoise tracer
+prints the sum of all noise, the max single noise, the percentage of CPU
+available for the thread, and the counters for the noise sources.
+
+Usage
+-----
+
+Write the ASCII text "osnoise" into the current_tracer file of the
+tracing system (generally mounted at /sys/kernel/tracing).
+
+For example::
+
+ [root@f32 ~]# cd /sys/kernel/tracing/
+ [root@f32 tracing]# echo osnoise > current_tracer
+
+It is possible to follow the trace by reading the trace trace file::
+
+ [root@f32 tracing]# cat trace
+ # tracer: osnoise
+ #
+ # _-----=> irqs-off
+ # / _----=> need-resched
+ # | / _---=> hardirq/softirq
+ # || / _--=> preempt-depth MAX
+ # || / SINGLE Interference counters:
+ # |||| RUNTIME NOISE % OF CPU NOISE +-----------------------------+
+ # TASK-PID CPU# |||| TIMESTAMP IN US IN US AVAILABLE IN US HW NMI IRQ SIRQ THREAD
+ # | | | |||| | | | | | | | | | |
+ <...>-859 [000] .... 81.637220: 1000000 190 99.98100 9 18 0 1007 18 1
+ <...>-860 [001] .... 81.638154: 1000000 656 99.93440 74 23 0 1006 16 3
+ <...>-861 [002] .... 81.638193: 1000000 5675 99.43250 202 6 0 1013 25 21
+ <...>-862 [003] .... 81.638242: 1000000 125 99.98750 45 1 0 1011 23 0
+ <...>-863 [004] .... 81.638260: 1000000 1721 99.82790 168 7 0 1002 49 41
+ <...>-864 [005] .... 81.638286: 1000000 263 99.97370 57 6 0 1006 26 2
+ <...>-865 [006] .... 81.638302: 1000000 109 99.98910 21 3 0 1006 18 1
+ <...>-866 [007] .... 81.638326: 1000000 7816 99.21840 107 8 0 1016 39 19
+
+In addition to the regular trace fields (from TASK-PID to TIMESTAMP), the
+tracer prints a message at the end of each period for each CPU that is
+running an osnoise/ thread. The osnoise specific fields report:
+
+ - The RUNTIME IN USE reports the amount of time in microseconds that
+ the osnoise thread kept looping reading the time.
+ - The NOISE IN US reports the sum of noise in microseconds observed
+ by the osnoise tracer during the associated runtime.
+ - The % OF CPU AVAILABLE reports the percentage of CPU available for
+ the osnoise thread during the runtime window.
+ - The MAX SINGLE NOISE IN US reports the maximum single noise observed
+ during the runtime window.
+ - The Interference counters display how many each of the respective
+ interference happened during the runtime window.
+
+Note that the example above shows a high number of HW noise samples.
+The reason being is that this sample was taken on a virtual machine,
+and the host interference is detected as a hardware interference.
+
+Tracer options
+---------------------
+
+The tracer has a set of options inside the osnoise directory, they are:
+
+ - osnoise/cpus: CPUs at which a osnoise thread will execute.
+ - osnoise/period_us: the period of the osnoise thread.
+ - osnoise/runtime_us: how long an osnoise thread will look for noise.
+ - osnoise/stop_tracing_us: stop the system tracing if a single noise
+ higher than the configured value happens. Writing 0 disables this
+ option.
+ - osnoise/stop_tracing_total_us: stop the system tracing if total noise
+ higher than the configured value happens. Writing 0 disables this
+ option.
+ - tracing_threshold: the minimum delta between two time() reads to be
+ considered as noise, in us. When set to 0, the default value will
+ will be used, which is currently 5 us.
+
+Additional Tracing
+------------------
+
+In addition to the tracer, a set of tracepoints were added to
+facilitate the identification of the osnoise source.
+
+ - osnoise:sample_threshold: printed anytime a noise is higher than
+ the configurable tolerance_ns.
+ - osnoise:nmi_noise: noise from NMI, including the duration.
+ - osnoise:irq_noise: noise from an IRQ, including the duration.
+ - osnoise:softirq_noise: noise from a SoftIRQ, including the
+ duration.
+ - osnoise:thread_noise: noise from a thread, including the duration.
+
+Note that all the values are *net values*. For example, if while osnoise
+is running, another thread preempts the osnoise thread, it will start a
+thread_noise duration at the start. Then, an IRQ takes place, preempting
+the thread_noise, starting a irq_noise. When the IRQ ends its execution,
+it will compute its duration, and this duration will be subtracted from
+the thread_noise, in such a way as to avoid the double accounting of the
+IRQ execution. This logic is valid for all sources of noise.
+
+Here is one example of the usage of these tracepoints::
+
+ osnoise/8-961 [008] d.h. 5789.857532: irq_noise: local_timer:236 start 5789.857529929 duration 1845 ns
+ osnoise/8-961 [008] dNh. 5789.858408: irq_noise: local_timer:236 start 5789.858404871 duration 2848 ns
+ migration/8-54 [008] d... 5789.858413: thread_noise: migration/8:54 start 5789.858409300 duration 3068 ns
+ osnoise/8-961 [008] .... 5789.858413: sample_threshold: start 5789.858404555 duration 8812 ns interferences 2
+
+In this example, a noise sample of 8 microseconds was reported in the last
+line, pointing to two interferences. Looking backward in the trace, the
+two previous entries were about the migration thread running after a
+timer IRQ execution. The first event is not part of the noise because
+it took place one millisecond before.
+
+It is worth noticing that the sum of the duration reported in the
+tracepoints is smaller than eight us reported in the sample_threshold.
+The reason roots in the overhead of the entry and exit code that happens
+before and after any interference execution. This justifies the dual
+approach: measuring thread and tracing.
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 0f66682ac02a..3e625c61f008 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_FUNCTION_TRACER) += ftrace_$(BITS).o
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o
obj-$(CONFIG_X86_TSC) += trace_clock.o
+obj-$(CONFIG_TRACING) += trace.o
obj-$(CONFIG_CRASH_CORE) += crash_core_$(BITS).o
obj-$(CONFIG_KEXEC_CORE) += machine_kexec_$(BITS).o
obj-$(CONFIG_KEXEC_CORE) += relocate_kernel_$(BITS).o crash.o
diff --git a/arch/x86/kernel/trace.c b/arch/x86/kernel/trace.c
new file mode 100644
index 000000000000..6912672c33a7
--- /dev/null
+++ b/arch/x86/kernel/trace.c
@@ -0,0 +1,237 @@
+#include <asm/trace/irq_vectors.h>
+#include <linux/trace.h>
+
+#if defined(CONFIG_OSNOISE_TRACER) && defined(CONFIG_X86_LOCAL_APIC)
+extern void osnoise_trace_irq_entry(int id);
+extern void osnoise_trace_irq_exit(int id, const char *desc);
+
+/*
+ * trace_intel_irq_entry - record intel specific IRQ entry
+ */
+static void trace_intel_irq_entry(void *data, int vector)
+{
+ osnoise_trace_irq_entry(vector);
+}
+
+/*
+ * trace_intel_irq_exit - record intel specific IRQ exit
+ */
+static void trace_intel_irq_exit(void *data, int vector)
+{
+ char *vector_desc = (char *) data;
+
+ osnoise_trace_irq_exit(vector, vector_desc);
+}
+
+/*
+ * register_intel_irq_tp - Register intel specific IRQ entry tracepoints
+ */
+int osnoise_arch_register(void)
+{
+ int ret;
+
+ ret = register_trace_local_timer_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_err;
+
+ ret = register_trace_local_timer_exit(trace_intel_irq_exit, "local_timer");
+ if (ret)
+ goto out_timer_entry;
+
+#ifdef CONFIG_X86_THERMAL_VECTOR
+ ret = register_trace_thermal_apic_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_timer_exit;
+
+ ret = register_trace_thermal_apic_exit(trace_intel_irq_exit, "thermal_apic");
+ if (ret)
+ goto out_thermal_entry;
+#endif /* CONFIG_X86_THERMAL_VECTOR */
+
+#ifdef CONFIG_X86_MCE_AMD
+ ret = register_trace_deferred_error_apic_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_thermal_exit;
+
+ ret = register_trace_deferred_error_apic_exit(trace_intel_irq_exit, "deferred_error");
+ if (ret)
+ goto out_deferred_entry;
+#endif
+
+#ifdef CONFIG_X86_MCE_THRESHOLD
+ ret = register_trace_threshold_apic_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_deferred_exit;
+
+ ret = register_trace_threshold_apic_exit(trace_intel_irq_exit, "threshold_apic");
+ if (ret)
+ goto out_threshold_entry;
+#endif /* CONFIG_X86_MCE_THRESHOLD */
+
+#ifdef CONFIG_SMP
+ ret = register_trace_call_function_single_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_threshold_exit;
+
+ ret = register_trace_call_function_single_exit(trace_intel_irq_exit,
+ "call_function_single");
+ if (ret)
+ goto out_call_function_single_entry;
+
+ ret = register_trace_call_function_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_call_function_single_exit;
+
+ ret = register_trace_call_function_exit(trace_intel_irq_exit, "call_function");
+ if (ret)
+ goto out_call_function_entry;
+
+ ret = register_trace_reschedule_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_call_function_exit;
+
+ ret = register_trace_reschedule_exit(trace_intel_irq_exit, "reschedule");
+ if (ret)
+ goto out_reschedule_entry;
+#endif /* CONFIG_SMP */
+
+#ifdef CONFIG_IRQ_WORK
+ ret = register_trace_irq_work_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_reschedule_exit;
+
+ ret = register_trace_irq_work_exit(trace_intel_irq_exit, "irq_work");
+ if (ret)
+ goto out_irq_work_entry;
+#endif
+
+ ret = register_trace_x86_platform_ipi_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_irq_work_exit;
+
+ ret = register_trace_x86_platform_ipi_exit(trace_intel_irq_exit, "x86_platform_ipi");
+ if (ret)
+ goto out_x86_ipi_entry;
+
+ ret = register_trace_error_apic_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_x86_ipi_exit;
+
+ ret = register_trace_error_apic_exit(trace_intel_irq_exit, "error_apic");
+ if (ret)
+ goto out_error_apic_entry;
+
+ ret = register_trace_spurious_apic_entry(trace_intel_irq_entry, NULL);
+ if (ret)
+ goto out_error_apic_exit;
+
+ ret = register_trace_spurious_apic_exit(trace_intel_irq_exit, "spurious_apic");
+ if (ret)
+ goto out_spurious_apic_entry;
+
+ return 0;
+
+out_spurious_apic_entry:
+ unregister_trace_spurious_apic_entry(trace_intel_irq_entry, NULL);
+out_error_apic_exit:
+ unregister_trace_error_apic_exit(trace_intel_irq_exit, "error_apic");
+out_error_apic_entry:
+ unregister_trace_error_apic_entry(trace_intel_irq_entry, NULL);
+out_x86_ipi_exit:
+ unregister_trace_x86_platform_ipi_exit(trace_intel_irq_exit, "x86_platform_ipi");
+out_x86_ipi_entry:
+ unregister_trace_x86_platform_ipi_entry(trace_intel_irq_entry, NULL);
+out_irq_work_exit:
+
+#ifdef CONFIG_IRQ_WORK
+ unregister_trace_irq_work_exit(trace_intel_irq_exit, "irq_work");
+out_irq_work_entry:
+ unregister_trace_irq_work_entry(trace_intel_irq_entry, NULL);
+out_reschedule_exit:
+#endif
+
+#ifdef CONFIG_SMP
+ unregister_trace_reschedule_exit(trace_intel_irq_exit, "reschedule");
+out_reschedule_entry:
+ unregister_trace_reschedule_entry(trace_intel_irq_entry, NULL);
+out_call_function_exit:
+ unregister_trace_call_function_exit(trace_intel_irq_exit, "call_function");
+out_call_function_entry:
+ unregister_trace_call_function_entry(trace_intel_irq_entry, NULL);
+out_call_function_single_exit:
+ unregister_trace_call_function_single_exit(trace_intel_irq_exit, "call_function_single");
+out_call_function_single_entry:
+ unregister_trace_call_function_single_entry(trace_intel_irq_entry, NULL);
+out_threshold_exit:
+#endif
+
+#ifdef CONFIG_X86_MCE_THRESHOLD
+ unregister_trace_threshold_apic_exit(trace_intel_irq_exit, "threshold_apic");
+out_threshold_entry:
+ unregister_trace_threshold_apic_entry(trace_intel_irq_entry, NULL);
+out_deferred_exit:
+#endif
+
+#ifdef CONFIG_X86_MCE_AMD
+ unregister_trace_deferred_error_apic_exit(trace_intel_irq_exit, "deferred_error");
+out_deferred_entry:
+ unregister_trace_deferred_error_apic_entry(trace_intel_irq_entry, NULL);
+out_thermal_exit:
+#endif /* CONFIG_X86_MCE_AMD */
+
+#ifdef CONFIG_X86_THERMAL_VECTOR
+ unregister_trace_thermal_apic_exit(trace_intel_irq_exit, "thermal_apic");
+out_thermal_entry:
+ unregister_trace_thermal_apic_entry(trace_intel_irq_entry, NULL);
+out_timer_exit:
+#endif /* CONFIG_X86_THERMAL_VECTOR */
+
+ unregister_trace_local_timer_exit(trace_intel_irq_exit, "local_timer");
+out_timer_entry:
+ unregister_trace_local_timer_entry(trace_intel_irq_entry, NULL);
+out_err:
+ return -EINVAL;
+}
+
+void osnoise_arch_unregister(void)
+{
+ unregister_trace_spurious_apic_exit(trace_intel_irq_exit, "spurious_apic");
+ unregister_trace_spurious_apic_entry(trace_intel_irq_entry, NULL);
+ unregister_trace_error_apic_exit(trace_intel_irq_exit, "error_apic");
+ unregister_trace_error_apic_entry(trace_intel_irq_entry, NULL);
+ unregister_trace_x86_platform_ipi_exit(trace_intel_irq_exit, "x86_platform_ipi");
+ unregister_trace_x86_platform_ipi_entry(trace_intel_irq_entry, NULL);
+
+#ifdef CONFIG_IRQ_WORK
+ unregister_trace_irq_work_exit(trace_intel_irq_exit, "irq_work");
+ unregister_trace_irq_work_entry(trace_intel_irq_entry, NULL);
+#endif
+
+#ifdef CONFIG_SMP
+ unregister_trace_reschedule_exit(trace_intel_irq_exit, "reschedule");
+ unregister_trace_reschedule_entry(trace_intel_irq_entry, NULL);
+ unregister_trace_call_function_exit(trace_intel_irq_exit, "call_function");
+ unregister_trace_call_function_entry(trace_intel_irq_entry, NULL);
+ unregister_trace_call_function_single_exit(trace_intel_irq_exit, "call_function_single");
+ unregister_trace_call_function_single_entry(trace_intel_irq_entry, NULL);
+#endif
+
+#ifdef CONFIG_X86_MCE_THRESHOLD
+ unregister_trace_threshold_apic_exit(trace_intel_irq_exit, "threshold_apic");
+ unregister_trace_threshold_apic_entry(trace_intel_irq_entry, NULL);
+#endif
+
+#ifdef CONFIG_X86_MCE_AMD
+ unregister_trace_deferred_error_apic_exit(trace_intel_irq_exit, "deferred_error");
+ unregister_trace_deferred_error_apic_entry(trace_intel_irq_entry, NULL);
+#endif
+
+#ifdef CONFIG_X86_THERMAL_VECTOR
+ unregister_trace_thermal_apic_exit(trace_intel_irq_exit, "thermal_apic");
+ unregister_trace_thermal_apic_entry(trace_intel_irq_entry, NULL);
+#endif /* CONFIG_X86_THERMAL_VECTOR */
+
+ unregister_trace_local_timer_exit(trace_intel_irq_exit, "local_timer");
+ unregister_trace_local_timer_entry(trace_intel_irq_entry, NULL);
+}
+#endif /* CONFIG_OSNOISE_TRAECR && CONFIG_X86_LOCAL_APIC */
diff --git a/include/linux/ftrace_irq.h b/include/linux/ftrace_irq.h
index 0abd9a1d2852..f6faa31289ba 100644
--- a/include/linux/ftrace_irq.h
+++ b/include/linux/ftrace_irq.h
@@ -7,12 +7,21 @@ extern bool trace_hwlat_callback_enabled;
extern void trace_hwlat_callback(bool enter);
#endif
+#ifdef CONFIG_OSNOISE_TRACER
+extern bool trace_osnoise_callback_enabled;
+extern void trace_osnoise_callback(bool enter);
+#endif
+
static inline void ftrace_nmi_enter(void)
{
#ifdef CONFIG_HWLAT_TRACER
if (trace_hwlat_callback_enabled)
trace_hwlat_callback(true);
#endif
+#ifdef CONFIG_OSNOISE_TRACER
+ if (trace_osnoise_callback_enabled)
+ trace_osnoise_callback(true);
+#endif
}
static inline void ftrace_nmi_exit(void)
@@ -21,6 +30,10 @@ static inline void ftrace_nmi_exit(void)
if (trace_hwlat_callback_enabled)
trace_hwlat_callback(false);
#endif
+#ifdef CONFIG_OSNOISE_TRACER
+ if (trace_osnoise_callback_enabled)
+ trace_osnoise_callback(false);
+#endif
}
#endif /* _LINUX_FTRACE_IRQ_H */
diff --git a/include/linux/trace.h b/include/linux/trace.h
index be1e130ed87c..4e3858640c47 100644
--- a/include/linux/trace.h
+++ b/include/linux/trace.h
@@ -41,6 +41,11 @@ int trace_array_init_printk(struct trace_array *tr);
void trace_array_put(struct trace_array *tr);
struct trace_array *trace_array_get_by_name(const char *name);
int trace_array_destroy(struct trace_array *tr);
+
+/* For osnoise tracer */
+int osnoise_arch_register(void);
+void osnoise_arch_unregister(void);
+
#endif /* CONFIG_TRACING */
#endif /* _LINUX_TRACE_H */
diff --git a/include/trace/events/osnoise.h b/include/trace/events/osnoise.h
new file mode 100644
index 000000000000..28762c69f6c9
--- /dev/null
+++ b/include/trace/events/osnoise.h
@@ -0,0 +1,142 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM osnoise
+
+#if !defined(_OSNOISE_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _OSNOISE_TRACE_H
+
+#include <linux/tracepoint.h>
+TRACE_EVENT(thread_noise,
+
+ TP_PROTO(struct task_struct *t, u64 start, u64 duration),
+
+ TP_ARGS(t, start, duration),
+
+ TP_STRUCT__entry(
+ __array( char, comm, TASK_COMM_LEN)
+ __field( u64, start )
+ __field( u64, duration)
+ __field( pid_t, pid )
+ ),
+
+ TP_fast_assign(
+ memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
+ __entry->pid = t->pid;
+ __entry->start = start;
+ __entry->duration = duration;
+ ),
+
+ TP_printk("%8s:%d start %llu.%09u duration %llu ns",
+ __entry->comm,
+ __entry->pid,
+ __print_ns_to_secs(__entry->start),
+ __print_ns_without_secs(__entry->start),
+ __entry->duration)
+);
+
+TRACE_EVENT(softirq_noise,
+
+ TP_PROTO(int vector, u64 start, u64 duration),
+
+ TP_ARGS(vector, start, duration),
+
+ TP_STRUCT__entry(
+ __field( u64, start )
+ __field( u64, duration)
+ __field( int, vector )
+ ),
+
+ TP_fast_assign(
+ __entry->vector = vector;
+ __entry->start = start;
+ __entry->duration = duration;
+ ),
+
+ TP_printk("%8s:%d start %llu.%09u duration %llu ns",
+ show_softirq_name(__entry->vector),
+ __entry->vector,
+ __print_ns_to_secs(__entry->start),
+ __print_ns_without_secs(__entry->start),
+ __entry->duration)
+);
+
+TRACE_EVENT(irq_noise,
+
+ TP_PROTO(int vector, const char *desc, u64 start, u64 duration),
+
+ TP_ARGS(vector, desc, start, duration),
+
+ TP_STRUCT__entry(
+ __field( u64, start )
+ __field( u64, duration)
+ __string( desc, desc )
+ __field( int, vector )
+
+ ),
+
+ TP_fast_assign(
+ __assign_str(desc, desc);
+ __entry->vector = vector;
+ __entry->start = start;
+ __entry->duration = duration;
+ ),
+
+ TP_printk("%s:%d start %llu.%09u duration %llu ns",
+ __get_str(desc),
+ __entry->vector,
+ __print_ns_to_secs(__entry->start),
+ __print_ns_without_secs(__entry->start),
+ __entry->duration)
+);
+
+TRACE_EVENT(nmi_noise,
+
+ TP_PROTO(u64 start, u64 duration),
+
+ TP_ARGS(start, duration),
+
+ TP_STRUCT__entry(
+ __field( u64, start )
+ __field( u64, duration)
+ ),
+
+ TP_fast_assign(
+ __entry->start = start;
+ __entry->duration = duration;
+ ),
+
+ TP_printk("start %llu.%09u duration %llu ns",
+ __print_ns_to_secs(__entry->start),
+ __print_ns_without_secs(__entry->start),
+ __entry->duration)
+);
+
+TRACE_EVENT(sample_threshold,
+
+ TP_PROTO(u64 start, u64 duration, u64 interference),
+
+ TP_ARGS(start, duration, interference),
+
+ TP_STRUCT__entry(
+ __field( u64, start )
+ __field( u64, duration)
+ __field( u64, interference)
+ ),
+
+ TP_fast_assign(
+ __entry->start = start;
+ __entry->duration = duration;
+ __entry->interference = interference;
+ ),
+
+ TP_printk("start %llu.%09u duration %llu ns interferences %llu",
+ __print_ns_to_secs(__entry->start),
+ __print_ns_without_secs(__entry->start),
+ __entry->duration,
+ __entry->interference)
+);
+
+#endif /* _TRACE_OSNOISE_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index 7fa82778c3e6..41582ae4682b 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -356,6 +356,40 @@ config HWLAT_TRACER
file. Every time a latency is greater than tracing_thresh, it will
be recorded into the ring buffer.
+config OSNOISE_TRACER
+ bool "OS Noise tracer"
+ select GENERIC_TRACER
+ help
+ In the context of high-performance computing (HPC), the Operating
+ System Noise (osnoise) refers to the interference experienced by an
+ application due to activities inside the operating system. In the
+ context of Linux, NMIs, IRQs, SoftIRQs, and any other system thread
+ can cause noise to the system. Moreover, hardware-related jobs can
+ also cause noise, for example, via SMIs.
+
+ The osnoise tracer leverages the hwlat_detector by running a similar
+ loop with preemption, SoftIRQs and IRQs enabled, thus allowing all
+ the sources of osnoise during its execution. The osnoise tracer takes
+ note of the entry and exit point of any source of interferences,
+ increasing a per-cpu interference counter. It saves an interference
+ counter for each source of interference. The interference counter for
+ NMI, IRQs, SoftIRQs, and threads is increased anytime the tool
+ observes these interferences' entry events. When a noise happens
+ without any interference from the operating system level, the
+ hardware noise counter increases, pointing to a hardware-related
+ noise. In this way, osnoise can account for any source of
+ interference. At the end of the period, the osnoise tracer prints
+ the sum of all noise, the max single noise, the percentage of CPU
+ available for the thread, and the counters for the noise sources.
+
+ In addition to the tracer, a set of tracepoints were added to
+ facilitate the identification of the osnoise source.
+
+ The output will appear in the trace and trace_pipe files.
+
+ To enable this tracer, echo in "osnoise" into the current_tracer
+ file.
+
config MMIOTRACE
bool "Memory mapped IO tracing"
depends on HAVE_MMIOTRACE_SUPPORT && PCI
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index b28d3e5013cd..b1c47ccf4f73 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o
obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o
obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
obj-$(CONFIG_HWLAT_TRACER) += trace_hwlat.o
+obj-$(CONFIG_OSNOISE_TRACER) += trace_osnoise.o
obj-$(CONFIG_NOP_TRACER) += trace_nop.o
obj-$(CONFIG_STACK_TRACER) += trace_stack.o
obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 87588d1e24ca..b959c9ec9711 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -44,6 +44,7 @@ enum trace_type {
TRACE_BLK,
TRACE_BPUTS,
TRACE_HWLAT,
+ TRACE_OSNOISE,
TRACE_RAW_DATA,
TRACE_FUNC_REPEATS,
@@ -297,7 +298,8 @@ struct trace_array {
struct array_buffer max_buffer;
bool allocated_snapshot;
#endif
-#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
+#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) \
+ || defined(CONFIG_OSNOISE_TRACER)
unsigned long max_latency;
#ifdef CONFIG_FSNOTIFY
struct dentry *d_max_latency;
@@ -445,6 +447,7 @@ extern void __ftrace_bad_type(void);
IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS); \
IF_ASSIGN(var, ent, struct hwlat_entry, TRACE_HWLAT); \
+ IF_ASSIGN(var, ent, struct osnoise_entry, TRACE_OSNOISE);\
IF_ASSIGN(var, ent, struct raw_data_entry, TRACE_RAW_DATA);\
IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
TRACE_MMIO_RW); \
@@ -675,8 +678,8 @@ void update_max_tr_single(struct trace_array *tr,
struct task_struct *tsk, int cpu);
#endif /* CONFIG_TRACER_MAX_TRACE */
-#if (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)) && \
- defined(CONFIG_FSNOTIFY)
+#if (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) \
+ || defined(CONFIG_OSNOISE_TRACER)) && defined(CONFIG_FSNOTIFY)
#define LATENCY_FS_NOTIFY
#endif
diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index 251c819cf0c5..158c0984b59b 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -360,3 +360,28 @@ FTRACE_ENTRY(func_repeats, func_repeats_entry,
__entry->count,
FUNC_REPEATS_GET_DELTA_TS(__entry))
);
+
+FTRACE_ENTRY(osnoise, osnoise_entry,
+
+ TRACE_OSNOISE,
+
+ F_STRUCT(
+ __field( u64, noise )
+ __field( u64, runtime )
+ __field( u64, max_sample )
+ __field( unsigned int, hw_count )
+ __field( unsigned int, nmi_count )
+ __field( unsigned int, irq_count )
+ __field( unsigned int, softirq_count )
+ __field( unsigned int, thread_count )
+ ),
+
+ F_printk("noise:%llu\tmax_sample:%llu\thw:%u\tnmi:%u\tirq:%u\tsoftirq:%u\tthread:%u\n",
+ __entry->noise,
+ __entry->max_sample,
+ __entry->hw_count,
+ __entry->nmi_count,
+ __entry->irq_count,
+ __entry->softirq_count,
+ __entry->thread_count)
+);
diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
new file mode 100644
index 000000000000..4e2c47dc4f19
--- /dev/null
+++ b/kernel/trace/trace_osnoise.c
@@ -0,0 +1,1384 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * OS Noise Tracer: computes the OS Noise suffered by a running thread.
+ *
+ * Based on "hwlat_detector" tracer by:
+ * Copyright (C) 2008-2009 Jon Masters, Red Hat, Inc. <jcm@redhat.com>
+ * Copyright (C) 2013-2016 Steven Rostedt, Red Hat, Inc. <srostedt@redhat.com>
+ * With feedback from Clark Williams <williams@redhat.com>
+ *
+ * And also based on the rtsl tracer presented on:
+ * DE OLIVEIRA, Daniel Bristot, et al. Demystifying the real-time linux
+ * scheduling latency. In: 32nd Euromicro Conference on Real-Time Systems
+ * (ECRTS 2020). Schloss Dagstuhl-Leibniz-Zentrum fur Informatik, 2020.
+ *
+ * Copyright (C) 2021 Daniel Bristot de Oliveira, Red Hat, Inc. <bristot@redhat.com>
+ */
+
+#include <linux/kthread.h>
+#include <linux/tracefs.h>
+#include <linux/uaccess.h>
+#include <linux/cpumask.h>
+#include <linux/delay.h>
+#include <linux/sched/clock.h>
+#include <linux/sched.h>
+#include "trace.h"
+
+#ifdef CONFIG_X86_LOCAL_APIC
+#include <asm/trace/irq_vectors.h>
+#undef TRACE_INCLUDE_PATH
+#undef TRACE_INCLUDE_FILE
+#endif /* CONFIG_X86_LOCAL_APIC */
+
+#include <trace/events/irq.h>
+#include <trace/events/sched.h>
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/osnoise.h>
+
+static struct trace_array *osnoise_trace;
+
+/*
+ * Default values.
+ */
+#define BANNER "osnoise: "
+#define DEFAULT_SAMPLE_PERIOD 1000000 /* 1s */
+#define DEFAULT_SAMPLE_RUNTIME 1000000 /* 1s */
+
+/*
+ * NMI runtime info.
+ */
+struct osn_nmi {
+ u64 count;
+ u64 delta_start;
+};
+
+/*
+ * IRQ runtime info.
+ */
+struct osn_irq {
+ u64 count;
+ u64 arrival_time;
+ u64 delta_start;
+};
+
+/*
]
]
|
| 98/2 |
2026/08/31 21:27 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 40544
output: 42
thoughts: 979
Thoughts: **Analyzing Tracepoint Registration and Error Handling**
Okay, so I'm looking at commit `bce29ac9ce0b` and how it handles tracepoint registration with `osnoise_arch_register`. The use of `goto` labels to unregister in reverse order on failure is interesting, a common pattern to ensure a clean rollback. This immediately makes me think of other instances where we see this kind of registration/unregistration logic.
Let's see, `kernel/trace/trace_events_synth.c` seems relevant. Right, `register_synth_event` also follows a similar strategy. If `register_trace_event` succeeds, it proceeds, but if `set_synth_event_print_fmt` fails *after* registration, it unregisters with `unregister_trace_event` before bailing out. Standard practice.
Now, let's turn to `kernel/trace/ftrace.c` and specifically `ftrace_pid_follow_fork`. Hold on a second... it *registers* `trace_sched_process_fork` and `trace_sched_process_free`, but it doesn't check the return values of these `register_*` functions! That's a potential problem. We are assuming they work?
Moving on, `kernel/trace/trace_events.c` and `register_pid_events` also looks like it's missing the error checking for the registration of `trace_prio_sched_switch`. Why are these return values not being checked? Is there an assumption being made about the underlying functions? Is it because they can never fail?
Now, let's consider `blk_register_tracepoints`. Ah, this is different, because there's `WARN_ON` after calling `register_trace_block_rq_insert`. That's because `register_trace_block_rq_insert` *can* fail, specifically with `-ENOMEM`. It makes sense to check for failure here.
Let's go back and examine `kernel/trace/trace_fprobe.c`. Right, in `enable_trace_fprobe` we have explicit error checking. The return value of `__register_trace_fprobe(tf)` is checked, and if it fails, it properly unregisters the previously registered probes in a loop. A comprehensive approach.
The discrepancy here is pretty glaring, now I'm thinking about searching for commits in `kernel/trace/` that removed these `WARN_ON` checks. It's possible that these functions were assumed to be infallible at one point, or that a change in the underlying mechanisms or usage patterns necessitated the removal of error checking. This warrants further investigation to understand why some registrations are checked and others aren't.
|
| 99/2 |
2026/08/31 21:27 |
tool |
git-log |
0m
Args: map[CodeRegexp:WARN_ON.*register_trace PathPrefix:kernel/trace/ Since:10 years]
Results:
|
| 100/2 |
2026/08/31 21:27 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 42163
output: 43
thoughts: 27
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing the Absence of Commits**
Well, this is interesting. The system reports *no* commits. That's a starting point, right? Means there's nothing immediately obvious in the repository's history that addresses the core issue. Time to dig deeper. I'm going to focus my search. I'm going to start looking for commits in the `kernel/trace/` directory that specifically address error handling related to `register_trace`. Given the importance of tracepoints, and the potential for delicate system interactions, a robust error-handling regime around tracepoint registration is crucial. I suspect there may have been a historical pattern to the handling that I can identify, or, perhaps, a recent regression that I can narrow down with the correct search terms. A focussed search on that sub-section should yield the right clues.
|
| 101/2 |
2026/08/31 21:28 |
tool |
git-log |
0m
Args: map[CodeRegexp:if \(ret\).*unregister_trace PathPrefix:kernel/trace/ Since:10 years]
Results:
|
| 102/2 |
2026/08/31 21:28 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 42437
output: 43
thoughts: 34
Thoughts: Okay, here's my interpretation of those thoughts, framed as my own, given my expertise:
**Examining Potential Memory Issues Related to Tracepoints**
Right, let's dive into some kernel code. My gut tells me there might be some interplay between tracepoints, memory allocation issues (specifically, ENOMEM errors), and the unregistration process. I need to get a better sense of how those pieces fit together, so I'm going to search through the commit history. My initial focus is going to be within the `block/` and `kernel/trace/` directories, since those areas seem most likely to be relevant given my understanding of the system. I'm going to look for commits that mention "tracepoint", which is a given, but then I'm also going to look for any mentions of "ENOMEM" – because that's a red flag for memory allocation failures – and also "unregister" – as that might be related to leaks or other cleanup problems. With this search, I should be able to get a quick overview of relevant areas in these source repositories and look at related commits.
|
| 103/2 |
2026/08/31 21:28 |
tool |
git-log |
0m
Args: map[MessageRegexps:[tracepoint ENOMEM] PathPrefix:kernel/trace/ Since:10 years]
Results: map[Output:1dd349ab74d2 tracing: Do not start benchmark on boot up
]
|
| 104/2 |
2026/08/31 21:28 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 42780
output: 25
thoughts: 16
Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, geared toward an expert audience, and written in the first person:
**Investigating `1dd349ab74d2`**
Alright, time to dive into `1dd349ab74d2`. My initial scan is always critical. I'm immediately running through a mental checklist: Is this a commit hash? A file ID? A process ID? The format definitely suggests something unique, potentially a cryptographic hash or identifier within a system. Given the context of our field, I'm leaning heavily towards it being a version-control identifier.
First, I need to know where I can actually *find* this. What system am I working within? Is this a local sandbox, a production environment, or something in between? Without that context, this is just an alphanumeric string. My priority is establishing the scope. Is there a relevant codebase, a log file, an orchestration system, or a database I should reference?
Once I know where it lives, I’ll need the appropriate tools to look it up. This may involve a `git log` lookup, a database query, or a search through some specific log files. I'm going to determine what my search syntax will need to be to avoid extraneous results and hone in on exactly what I'm looking for.
I'm making a mental note that if it *is* a Git commit hash, I'll need to consider branching strategies, rebasing, merges, and potential conflicts. If it's something else, I'll tailor my expectations accordingly. I'm already anticipating potential dead ends; sometimes these IDs are misleading or refer to data that's been removed or purged. I'm ready to handle that and adjust my strategy.
My goal is to uncover the relevant metadata. I want to know when it was created or modified, what it’s associated with, and, most importantly, *why* it's relevant to what I'm currently working on. Is this a bug fix? A feature implementation? A security patch? I need the context.
|
| 105/2 |
2026/08/31 21:28 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 1dd349ab74d278cee50fc24dc26c023f3b149642
Author: Steven Rostedt (Red Hat) <rostedt@goodmis.org>
Date: Mon Nov 28 13:17:25 2016 -0500
tracing: Do not start benchmark on boot up
Trace events are enabled very early on boot up via the boot command line
parameter. The benchmark tool creates a new thread to perform the trace
event benchmarking. But at start up, it is called before scheduling is set
up and because it creates a new thread before the init thread is created,
this crashes the kernel.
Have the benchmark fail to register when started via the kernel command
line.
Also, since the registering of a tracepoint now can handle failure cases,
return -ENOMEM instead of warning if the thread cannot be created.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
diff --git a/kernel/trace/trace_benchmark.c b/kernel/trace/trace_benchmark.c
index f76d0416dd83..2bc7dc3e8ff8 100644
--- a/kernel/trace/trace_benchmark.c
+++ b/kernel/trace/trace_benchmark.c
@@ -166,9 +166,18 @@ static int benchmark_event_kthread(void *arg)
*/
int trace_benchmark_reg(void)
{
+ if (system_state != SYSTEM_RUNNING) {
+ pr_warning("trace benchmark cannot be started via kernel command line\n");
+ return -EBUSY;
+ }
+
bm_event_thread = kthread_run(benchmark_event_kthread,
NULL, "event_benchmark");
- WARN_ON(!bm_event_thread);
+ if (!bm_event_thread) {
+ pr_warning("trace benchmark failed to create kernel thread\n");
+ return -ENOMEM;
+ }
+
return 0;
}
@@ -183,6 +192,7 @@ void trace_benchmark_unreg(void)
return;
kthread_stop(bm_event_thread);
+ bm_event_thread = NULL;
strcpy(bm_str, "START");
bm_total = 0;
]
|
| 106/2 |
2026/08/31 21:28 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 43880
output: 41
thoughts: 78
Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing:
**Analyzing a Tracepoint Registration Change**
Alright, so this commit's interesting. It's essentially saying, "Hey, we've updated the tracepoint registration process to be more robust, specifically by handling memory allocation failures." Before, if we couldn't create a thread during tracepoint registration, it would just log a warning. Now, we're returning `-ENOMEM`, a proper error code signaling a memory allocation problem, from the `register_trace_*` function. Good. That's a definite improvement. Less vague, more actionable.
Now, I need to dig into how `register_trace_*` actually works. My immediate thought is, how is this memory allocation happening and why is it happening during registration? I remember from the code that these `register_trace_*` functions all ultimately call `tracepoint_probe_register`. So, my next step is to look at the implementation of *that* function and see what's happening under the hood. I expect that's where the thread creation, or at least the logic surrounding it, is happening. I need to understand the implications of this change on the overall registration flow.
|
| 107/2 |
2026/08/31 21:28 |
tool |
git-log |
0m
Args: map[CodeRegexp:tracepoint_probe_register PathPrefix:kernel/trace/ Since:10 years]
Results: map[Output:e3d6e1b9a34c tracing: tprobe-events: Support multiple tprobes on the same tracepoint
57a7e6de9e30 tracing/fprobe: Support raw tracepoints on future loaded modules
d4dfc5700e86 bpf: pass whole link instead of prog when triggering raw tracepoint
e2d0d7b2f42d tracing/probes: Add tracepoint support on fprobe_events
3207d0459ef3 user_events: Add basic perf and eBPF support
7f5a08c79df3 user_events: Add minimal support for trace_event into ftrace
9913d5745bd7 tracepoint: Add tracepoint_probe_register_may_exist() for BPF tracing
c4f6699dfcb8 bpf: introduce BPF_RAW_TRACEPOINT
]
|
| 108/2 |
2026/08/31 21:28 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 44483
output: 30
thoughts: 28
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Kernel Tracepoint Dive**
Alright, time to get to the heart of this. My initial instinct is to go digging in `kernel/trace/tracepoint.c`. Wait a second… that's almost right, just a quick mental correction. It's actually just `kernel/tracepoint.c`. No big deal, just a minor typo in my mental filesystem, I am so used to the `trace` subdirectory. Let's get to work.
|
| 109/2 |
2026/08/31 21:28 |
tool |
git-log |
0m
Args: map[PathPrefix:kernel/tracepoint.c Since:10 years]
Results: map[Output:fad217e16fde tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func()
323bbfcf1ef8 Convert 'alloc_flex' family to use the new default GFP_KERNEL argument
bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
a46023d5616e tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast
30c94bbceeda tracepoint: Print the function symbol when tracepoint_debug is set
2e8a12b82c40 tracing: Fix syscall tracepoint use-after-free
a9cfb8778c43 tracing: Introduce tracepoint extended structure
e53244e2c893 tracepoint: Remove SRCU protection
4a8840af5f53 tracepoints: Use new static branch API
]
|
| 110/2 |
2026/08/31 21:28 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 44924
output: 24
thoughts: 38
Thoughts: Okay, here's my interpretation of that thought process, as if I were having it:
**Examining a Tracepoint Issue**
Alright, time to dig into this. Let's see... the commit hash is `fad217e16fde`. That suggests a very specific fix or investigation is underway. The commit message itself, "tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func()", is dense but informative. My understanding is it relates to a balancing issue with a registration function in the tracepoint system, specifically when `func_add()` fails within `tracepoint_add_func()`. This sounds like a potential resource leak or an incorrect state transition within the tracepoint framework. This is a common situation with tracepoints, when function addition fails, you often need to consider memory cleanup or other resource management. I will now start going through the code.
|
| 111/2 |
2026/08/31 21:28 |
tool |
git-show |
0m
Args:
Results: map[Output:commit fad217e16fded7f3c09f8637b0f6a224d58b5f2e
Author: David Carlier <devnexen@gmail.com>
Date: Mon Apr 13 20:06:01 2026 +0100
tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func()
When a tracepoint goes through the 0 -> 1 transition, tracepoint_add_func()
invokes the subsystem's ext->regfunc() before attempting to install the
new probe via func_add(). If func_add() then fails (for example, when
allocate_probes() cannot allocate a new probe array under memory pressure
and returns -ENOMEM), the function returns the error without calling the
matching ext->unregfunc(), leaving the side effects of regfunc() behind
with no installed probe to justify them.
For syscall tracepoints this is particularly unpleasant: syscall_regfunc()
bumps sys_tracepoint_refcount and sets SYSCALL_TRACEPOINT on every task.
After a leaked failure, the refcount is stuck at a non-zero value with no
consumer, and every task continues paying the syscall trace entry/exit
overhead until reboot. Other subsystems providing regfunc()/unregfunc()
pairs exhibit similarly scoped persistent state.
Mirror the existing 1 -> 0 cleanup and call ext->unregfunc() in the
func_add() error path, gated on the same condition used there so the
unwind is symmetric with the registration.
Fixes: 8cf868affdc4 ("tracing: Have the reg function allow to fail")
Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://patch.msgid.link/20260413190601.21993-1-devnexen@gmail.com
Signed-off-by: David Carlier <devnexen@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 91905aa19294..dffef52a807b 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -300,6 +300,8 @@ static int tracepoint_add_func(struct tracepoint *tp,
lockdep_is_held(&tracepoints_mutex));
old = func_add(&tp_funcs, func, prio);
if (IS_ERR(old)) {
+ if (tp->ext && tp->ext->unregfunc && !static_key_enabled(&tp->key))
+ tp->ext->unregfunc();
WARN_ON_ONCE(warn && PTR_ERR(old) != -ENOMEM);
return PTR_ERR(old);
}
]
|
| 112/2 |
2026/08/31 21:28 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 45958
output: 43
thoughts: 559
Thoughts: **My Thoughts on Handling Tracepoint Registration Errors**
Okay, so this commit addresses a memory and state leak in `tracepoint_add_func` when `func_add()` fails with `-ENOMEM`. Essentially, it's another instance of the "missing rollback on `-ENOMEM`" problem. I've seen this before, and it looks like `blk_register_tracepoints()` in `kernel/trace/blktrace.c` is the culprit, using `WARN_ON(ret)` for error checking on the registration functions. That's a classic mistake.
The correct approach, as I see it, is to return the error code, unregister any successfully registered tracepoints, and propagate the error up. I need to make sure I get this right.
The prompt specifically wants me to outline the common idioms, locking rules, and patterns I should be following based on past similar fixes. Right, let's break it down:
The established pattern, especially when dealing with multiple tracepoint or probe registrations, is pretty clear. I should:
1. Meticulously check the return value of *every* registration function (e.g., `register_trace_*()`). No shortcuts.
2. If any registration fails, immediately use `goto` labels to jump to a dedicated error handling block. This avoids messy nested `if` statements.
3. Within that error handling block, unregister the tracepoints in *reverse* order of their registration. It's crucial for maintaining consistency.
4. Then, I propagate the specific error code up the call stack so the caller can handle it appropriately.
5. And finally, I will never use `WARN_ON` or `WARN_ON_ONCE` for error conditions that are expected, like `-ENOMEM` from tracepoint registration. This can trigger kernel panics if `panic_on_warn` is set, and that's exactly what we want to avoid.
I've taken a look around in `kernel/trace/` and `block/` to see what past fixes look like. It looks like:
* `aca0cd1bf165` "tracing/fprobe: Roll back on enable\_trace\_fprobe() failure"
* `bce29ac9ce0b` "trace: Add osnoise tracer" demonstrates the `goto` pattern for reverse unregistration.
* `fad217e16fde` "tracepoint: balance regfunc() on func\_add() failure in tracepoint\_add\_func()" shows proper rollback for tracepoint registration failures.
* `1dd349ab74d2` "tracing: Do not start benchmark on boot up" is a good example of removing `WARN_ON` and returning `-ENOMEM` instead.
A quick search for `WARN_ON` removals related to tracepoints in those areas should provide even more confidence in the fix. This should be a straightforward implementation of a well-understood pattern.
|
| 113/2 |
2026/08/31 21:28 |
tool |
git-log |
0m
Args: map[MessageRegexps:[WARN_ON tracepoint] PathPrefix:kernel/trace/ Since:10 years]
Results: map[Output:3880cdbed1c4 bpf: Fix WARN() in get_bpf_raw_tp_regs
0878355b51f5 tracing/osnoise: Properly unhook events if start_per_cpu_kthreads() fails
9913d5745bd7 tracepoint: Add tracepoint_probe_register_may_exist() for BPF tracing
f27107fa20ad tracing/irqsoff: Handle preempt_count for different configs
]
|
| 114/2 |
2026/08/31 21:28 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 47332
output: 27
thoughts: 40
Thoughts: Okay, let's dive into this commit, `0878355b51f5`, specifically the one dealing with `tracing/osnoise`. It looks like we're addressing a crucial error case. I'm immediately drawn to the title: "Properly unhook events if `start_per_cpu_kthreads()` fails."
My initial thought is that this is likely a subtle but potentially critical bug fix. The fact that we're talking about *unhooking* events suggests that there's a mechanism in place to register these events in the first place, likely in a per-CPU context, and that this registration needs to be gracefully undone if something goes wrong during the initialization of those per-CPU kernel threads.
Failing `start_per_cpu_kthreads()` is a serious error. If we can't spin up those threads, then whatever tracing or event collection functionality depends on them is rendered unusable. The concern here seems to be about resource cleanup, specifically making sure that if this initialization fails, we don't leave any dangling pointers or orphaned events that could lead to memory leaks, incorrect data, or even system instability. I'm picturing a situation where events might get registered, but then those threads never get started to actually *process* them. This could be problematic, especially with regards to how it handles the cleanup, which should be robust and thorough. We wouldn't want to create any silent failures that corrupt other systems.
So, the focus here is on ensuring that everything is cleaned up properly if `start_per_cpu_kthreads()` bails out. This is good defensive programming, and exactly the kind of detail you need to get right in kernel development. It's about protecting against a failure scenario and maintaining the overall integrity of the tracing subsystem. Good stuff.
|
| 115/2 |
2026/08/31 21:29 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 0878355b51f5f26632e652c848a8e174bb02d22d
Author: Nikita Yushchenko <nikita.yushchenko@virtuozzo.com>
Date: Sun Jan 9 18:34:59 2022 +0300
tracing/osnoise: Properly unhook events if start_per_cpu_kthreads() fails
If start_per_cpu_kthreads() called from osnoise_workload_start() returns
error, event hooks are left in broken state: unhook_irq_events() called
but unhook_thread_events() and unhook_softirq_events() not called, and
trace_osnoise_callback_enabled flag not cleared.
On the next tracer enable, hooks get not installed due to
trace_osnoise_callback_enabled flag.
And on the further tracer disable an attempt to remove non-installed
hooks happened, hitting a WARN_ON_ONCE() in tracepoint_remove_func().
Fix the error path by adding the missing part of cleanup.
While at this, introduce osnoise_unhook_events() to avoid code
duplication between this error path and normal tracer disable.
Link: https://lkml.kernel.org/r/20220109153459.3701773-1-nikita.yushchenko@virtuozzo.com
Cc: stable@vger.kernel.org
Fixes: bce29ac9ce0b ("trace: Add osnoise tracer")
Acked-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Nikita Yushchenko <nikita.yushchenko@virtuozzo.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index 4719a848bf17..36d9d5be08b4 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -2122,6 +2122,13 @@ static int osnoise_hook_events(void)
return -EINVAL;
}
+static void osnoise_unhook_events(void)
+{
+ unhook_thread_events();
+ unhook_softirq_events();
+ unhook_irq_events();
+}
+
/*
* osnoise_workload_start - start the workload and hook to events
*/
@@ -2154,7 +2161,14 @@ static int osnoise_workload_start(void)
retval = start_per_cpu_kthreads();
if (retval) {
- unhook_irq_events();
+ trace_osnoise_callback_enabled = false;
+ /*
+ * Make sure that ftrace_nmi_enter/exit() see
+ * trace_osnoise_callback_enabled as false before continuing.
+ */
+ barrier();
+
+ osnoise_unhook_events();
return retval;
}
@@ -2185,9 +2199,7 @@ static void osnoise_workload_stop(void)
stop_per_cpu_kthreads();
- unhook_irq_events();
- unhook_softirq_events();
- unhook_thread_events();
+ osnoise_unhook_events();
}
static void osnoise_tracer_start(struct trace_array *tr)
]
|
| 116/2 |
2026/08/31 21:29 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 48732
output: 43
thoughts: 346
Thoughts: **Analyzing a Recent Kernel Commit**
Okay, this commit, `0878355b51f5`, is remarkably similar to the issue we were dealing with! The description nails it: a failed `start_per_cpu_kthreads()` call from `osnoise_workload_start()` leaves the event hooks in a broken state. Consequently, a subsequent attempt to disable the tracer triggers the `WARN_ON_ONCE()` in `tracepoint_remove_func()` – a familiar error.
Essentially, it's the exact scenario we were dealing with: an attempt to unregister a tracepoint that wasn't properly registered results in `-ENOENT` from `tracepoint_remove_func()`, which then triggers that `WARN_ON_ONCE`. The pattern is clear now:
1. When you're registering multiple tracepoints or event hooks, and one fails, you *must* unregister any that succeeded.
2. Leaving them registered after a failure creates a broken state.
3. Later, a tracer stop unconditionally attempts to unregister everything.
4. Attempting to unregister a tracepoint that isn't there leads to the `WARN_ON_ONCE()` inside `tracepoint_remove_func()`.
5. The solution is a proper rollback mechanism during registration – maybe using `goto` labels to unregister in reverse order – and propagate errors up the call stack so the initialization fails cleanly rather than leaving the system in a half-baked state.
I should probably confirm that `WARN_ON_ONCE` in `tracepoint_remove_func` is what the commit is referring to by looking at the source code in `kernel/tracepoint.c`. Always good to double-check the details.
|
| 117/2 |
2026/08/31 21:29 |
tool |
git-log |
0m
Args: map[CodeRegexp:tracepoint_remove_func PathPrefix:kernel/tracepoint.c Since:10 years]
Results:
|
| 118/2 |
2026/08/31 21:29 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 49509
output: 32
thoughts: 28
Thoughts: Here's my thought process, summarized as you requested:
**Navigating Kernel Code: A Potential Location for `tracepoint_remove_func`**
Okay, so I'm thinking about where `tracepoint_remove_func` might actually reside within the kernel source. My first hunch is that it's likely nestled within `kernel/tracepoint.c`. That seems like a logical place, given its function. Now, I'm going to quickly confirm this suspicion. Time to whip out a `grep` and see if my intuition holds. That should give me a definitive answer pretty fast.
|
| 119/2 |
2026/08/31 21:29 |
tool |
grepper |
0m
Args: map[Expression:tracepoint_remove_func PathPrefix:kernel/tracepoint.c]
Results: map[Output:kernel/tracepoint.c=286=static int tracepoint_add_func(struct tracepoint *tp,
--
kernel/tracepoint.c-360- */
kernel/tracepoint.c:361:static int tracepoint_remove_func(struct tracepoint *tp,
kernel/tracepoint.c-362- struct tracepoint_func *func)
--
kernel/tracepoint.c=507=int tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data)
--
kernel/tracepoint.c-514- tp_func.data = data;
kernel/tracepoint.c:515: ret = tracepoint_remove_func(tp, &tp_func);
kernel/tracepoint.c-516- mutex_unlock(&tracepoints_mutex);
]
|
| 120/2 |
2026/08/31 21:29 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 49907
output: 34
thoughts: 21
Thoughts: Here's my summary, as though I'm reading and thinking about the code:
**Diving into `tracepoint_remove_func`**
Okay, let's get into the heart of this. I'm going to pull up `tracepoint_remove_func` from `kernel/tracepoint.c`. I need to understand how we're actually *removing* a function from a tracepoint, not just how we're attaching it. This is crucial for cleanup, avoiding dangling pointers, and generally maintaining system integrity after a tracepoint is no longer needed or if a module is unloaded. The details in *this* function, whatever they might be, have the potential to make or break the design's stability. I need to be sure that the removal is handled correctly for all the possible cases. I expect to be reading very carefully.
|
| 121/2 |
2026/08/31 21:29 |
tool |
read-file |
0m
Args: map[File:kernel/tracepoint.c FirstLine:361 LineCount:20]
Results: map[Contents: 361: static int tracepoint_remove_func(struct tracepoint *tp,
362: struct tracepoint_func *func)
363: {
364: struct tracepoint_func *old, *tp_funcs;
365:
366: tp_funcs = rcu_dereference_protected(tp->funcs,
367: lockdep_is_held(&tracepoints_mutex));
368: old = func_remove(&tp_funcs, func);
369: if (WARN_ON_ONCE(IS_ERR(old)))
370: return PTR_ERR(old);
371:
372: if (tp_funcs == old)
373: /* Failed allocating new tp_funcs, replaced func with stub */
374: return 0;
375:
376: switch (nr_func_state(tp_funcs)) {
377: case TP_FUNC_0: /* 1->0 */
378: /* Removed last function */
379: if (tp->ext && tp->ext->unregfunc && static_key_enabled(&tp->key))
380: tp->ext->unregfunc();
]
|
| 122/2 |
2026/08/31 21:29 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 50482
output: 796
thoughts: 1023
Thoughts: **My Analysis of the Tracepoint Registration Issue**
Okay, so I've confirmed that `WARN_ON_ONCE(IS_ERR(old))` is present, and `func_remove` returns `-ENOENT` if the function isn't found, which is expected. The core of the problem boils down to a failure to handle potential errors when registering multiple tracepoints. The `register_trace_*` functions *can* fail, typically due to memory pressure (`-ENOMEM`).
My findings are as follows:
1. The root cause is a missing error-handling mechanism when registering multiple tracepoints. We don't adequately handle the scenarios where `register_trace_*` might fail, for instance, due to memory allocation issues within the probe array.
2. The original approach used `WARN_ON(ret)` to catch registration errors, but this is clearly flawed, as it can lead to a kernel panic if `panic_on_warn` is enabled, which is unacceptable.
3. Moreover, ignoring the error leaves tracepoints in a partially registered state. Later, when the tracing is stopped, the system attempts to unregister *all* tracepoints unconditionally. This then results in an attempt to unregister a tracepoint that wasn't actually registered, leading to `tracepoint_remove_func()` returning `-ENOENT` and thus triggering the now-infamous `WARN_ON_ONCE`.
4. I see similar issues addressed and resolved in the past. Notable examples include commits like `0878355b51f5` ("tracing/osnoise: Properly unhook events if start_per_cpu_kthreads() fails"), `aca0cd1bf165` ("tracing/fprobe: Roll back on enable_trace_fprobe() failure"), and `1dd349ab74d2` ("tracing: Do not start benchmark on boot up"). This pattern is familiar, so I'm confident we're on the right track.
5. Based on my review of the codebase, I can confidently say that the established idiom for fixing this is clear. We need to:
* Thoroughly check the return value of *each* `register_trace_*` call.
* If a registration fails, *never* use `WARN_ON`. Instead, employ `goto` labels to jump to an error-handling block.
* Within the error-handling block, unregister the tracepoints that were successfully registered. It's *crucial* to unregister them in the *reverse* order of registration, to ensure everything's properly rolled back.
* Finally, return the appropriate error code (like `-ENOMEM`) and, very importantly, propagate that error up the call stack, so the setup sequence fails gracefully and resources are cleaned up.
I double-checked the locking rules, specifically the `blk_register_tracepoints()` function. I can see that it's called from `get_probe_ref()`, which holds `blk_probe_mutex`. The code here looks correct, and the proposed fix addresses the issues related to tracepoint registration and unregistration outside of this mutex.
Now, to summarize this for the final reply, here's what I'm seeing as the key idiomatic patterns:
**Key Takeaways**
* **Error Checking without `WARN_ON`:** Tracepoint registration functions are expected to fail, and doing so is not an error in the sense that `WARN_ON` is expected. `WARN_ON()` is an anti-pattern for handling these expected failures and will cause an unrecoverable kernel panic when `panic_on_warn` is enabled. Past commits like `1dd349ab74d2` ("tracing: Do not start benchmark on boot up") show that returning `-ENOMEM` is preferred.
* **Symmetric Rollback on Failure:** Whenever a function registers multiple tracepoints or hooks, the code must implement a rollback strategy when a registration fails. Use `goto` labels to unregister successfully registered tracepoints in reverse order of registration. Commit examples include `aca0cd1bf165` ("tracing/fprobe: Roll back on enable_trace_fprobe() failure") and `bce29ac9ce0b` ("trace: Add osnoise tracer").
* **Preventing `WARN_ON_ONCE` in `tracepoint_remove_func`:** Leaving tracepoints in a partially registered state, then trying to unregister all of them unconditionally later, results in `tracepoint_remove_func()` failing with `-ENOENT`, which triggers `WARN_ON_ONCE`. Commit `0878355b51f5` ("tracing/osnoise: Properly unhook events if start_
|
| 123/1 |
2026/08/31 21:29 |
action |
kernel-scratch-checkouter |
0m
Results: map[KernelScratchSrc:/app/workdir/cache/tmp/tmp526336236]
|
| 124/1 |
2026/08/31 21:29 |
loop |
|
28m
|
| 125/2 |
2026/08/31 21:29 |
iteration |
0 |
28m
|
| 126/3 |
2026/08/31 21:29 |
agent |
patch-generator |
2m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with creating a fix for a kernel bug.
You will be given a crash report, an initial explanation of the root cause done by another
kernel expert, and a summary of how similar bugs were fixed in the past.
Use the codeeditor tool to do code edits.
Note: you will not see your changes when looking at the code using codesearch tools.
Use the patch-diff tool to review the modifications you applied.
Your final reply should contain explanation of what you did in the patch and why
(details not present in the initial explanation of the bug).
Your fix must not just prevent the given crash, but also be the best fix for the underlying
root cause from the software engineering point of view. There can be several ways to fix the
same bug. Consider alternatives, and pick the best one. For example, additional checks may be
added at different locations/functions, it's usually better to place them earlier in the
execution to avoid multiple checks at various locations later.
Frequently the same coding mistake is done in several locations in the source code.
Check if your fix should be extended/applied to similar cases around to fix other similar bugs.
But don't go too wide, don't try to fix problems kernel-wide, fix similar issues
in the same file only.
If you are changing post-conditions of a function, consider all callers of the functions,
and if they need to be updated to handle new post-conditions. For example, if you make
a function that previously never returned a NULL, return NULL, consider if callers
need to be updated to handle NULL return value.
If you will end up removing the WARN_ON macro because the condition can legitimately happen,
add a pr_err/dev_err/... (whatever is the macro for printing runtime errors used in the file)
call that logs that the unlikely condition has happened. The pr_err/dev_err/... message
must not include "WARNING" nor "BUG" strings.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
------------[ cut here ]------------
ret
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline], CPU#1: syz.0.17/6119
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492, CPU#1: syz.0.17/6119
Modules linked in:
CPU: 1 UID: 0 PID: 6119 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Code: c3 31 ff 89 c6 e8 39 42 f7 ff 85 db 0f 85 00 01 00 00 e8 2c 3d f7 ff 48 c7 c7 00 7f bd 8e 5b e9 af 77 db 09 e8 1a 3d f7 ff 90 <0f> 0b 90 e9 e8 fc ff ff e8 0c 3d f7 ff 90 0f 0b 90 e9 07 fd ff ff
RSP: 0018:ffffc9000355fb10 EFLAGS: 00010293
RAX: ffffffff81ce06d6 RBX: 00000000fffffff4 RCX: ffff888114150000
RDX: 0000000000000000 RSI: 00000000fffffff4 RDI: 0000000000000000
RBP: ffffc9000355fc40 R08: ffffc9000355fa47 R09: 1ffff920006abf48
R10: dffffc0000000000 R11: fffff520006abf49 R12: ffff88810888c508
R13: dffffc0000000000 R14: ffff888103f8c638 R15: 0000000000002000
FS: 00007fc861b426c0(0000) GS:ffff8882e873e000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2ed24008 CR3: 00000001fdd32000 CR4: 0000000000352ef0
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc860b9e159
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fc861b42028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fc860e25fa0 RCX: 00007fc860b9e159
RDX: 0000000000000081 RSI: 00002000000002c0 RDI: 0000000000000003
RBP: 00007fc861b42090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
The explanation of the root cause of the bug is:
The root cause of the crash is that `blk_register_tracepoints()` uses `WARN_ON(ret)` to check the return values of `register_trace_block_*()` functions. These tracepoint registration functions allocate memory for the probe array and can fail with `-ENOMEM` (e.g., under memory pressure or fault injection, as seen in the syzbot report). When they fail, `WARN_ON()` triggers a kernel panic if `panic_on_warn` is set.
Furthermore, `blk_register_tracepoints()` currently ignores the error and continues, leaving the tracepoints in a partially registered state. Later, when tracing is stopped, `blk_unregister_tracepoints()` unconditionally unregisters all tracepoints. Unregistering a tracepoint that was not successfully registered causes `tracepoint_remove_func()` to return `-ENOENT`, which triggers another `WARN_ON_ONCE` inside `tracepoint_remove_func()`.
To fix this, we need to properly handle the registration failures by returning the error, unregistering the successfully registered tracepoints, and propagating the error up the call stack to fail the blktrace setup.
### Fix Details
1. **Change `blk_register_tracepoints()` to return an `int` and handle errors:**
Instead of `WARN_ON(ret)`, check the return value of each `register_trace_*()` call. If it fails, use `goto` labels to unregister the successfully registered tracepoints in reverse order, and return the error.
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
return ret;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
if (ret)
goto err_issue;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
if (ret)
goto err_merge;
// ... (do this for all 18 tracepoints) ...
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
if (ret)
goto err_rq_remap;
return 0;
err_rq_remap:
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
// ... (unregister labels in reverse order) ...
err_merge:
unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
err_issue:
unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
return ret;
}
```
2. **Propagate the error through `get_probe_ref()`:**
```c
static int get_probe_ref(void)
{
int ret = 0;
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1) {
ret = blk_register_tracepoints();
if (ret)
blk_probes_ref--;
}
mutex_unlock(&blk_probe_mutex);
return ret;
}
```
3. **Propagate the error through `blk_trace_setup_finalize()`:**
```c
static int blk_trace_setup_finalize(struct request_queue *q,
char *name, int version,
struct blk_trace *bt,
struct blk_user_trace_setup2 *buts)
{
int ret;
// ... existing code ...
bt->trace_state = Blktrace_setup;
ret = get_probe_ref();
if (ret)
return ret;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
}
```
4. **Handle the error in the callers of `blk_trace_setup_finalize()`:**
In `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, check the return value of `blk_trace_setup_finalize()`. If it fails, clean up the allocated `bt` and return the error:
```c
ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
```
5. **Handle the error in `blk_trace_setup_queue()`:**
```c
static int blk_trace_setup_queue(struct request_queue *q,
struct block_device *bdev)
{
// ... existing code ...
blk_trace_setup_lba(bt, bdev);
ret = get_probe_ref();
if (ret)
goto free_bt;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
free_bt:
blk_trace_free(q, bt);
return ret;
}
```
Historical context on how similar bugs were fixed in the past:
Based on the research into how similar bugs were addressed in the kernel (particularly within the tracing subsystem), the proposed fix strategy aligns perfectly with established kernel idioms and past fixes.
Here is a summary of the findings, common patterns, and locking rules that should be followed when writing the fix:
### 1. Removing `WARN_ON` for Expected Errors
Tracepoint registration functions (e.g., `register_trace_*()`) can legitimately fail, most commonly with `-ENOMEM` when allocating memory for the probe array. Using `WARN_ON()` to handle these expected failures is an anti-pattern because it will crash the kernel if `panic_on_warn` is enabled (which is common in testing environments like syzbot).
* **Prior Art:** Commit `1dd349ab74d2` ("tracing: Do not start benchmark on boot up") explicitly removed a `WARN_ON` on tracepoint setup failure, noting that registration can handle failure cases and should simply return `-ENOMEM`.
### 2. Symmetric Rollback via `goto` Labels
When a function registers multiple tracepoints sequentially, it must implement a symmetric rollback if any registration fails partway through. The standard kernel idiom is to use `goto` labels to unregister the successfully registered tracepoints in the **reverse order** of their registration.
* **Prior Art:**
* Commit `aca0cd1bf165` ("tracing/fprobe: Roll back on enable_trace_fprobe() failure") fixed a similar issue where failing partway through left events half-enabled. It introduced a rollback path to unregister all previously registered probes.
* Commit `bce29ac9ce0b` ("trace: Add osnoise tracer") demonstrates the exact `goto` label pattern for registering/unregistering multiple tracepoints in `osnoise_arch_register()`.
### 3. Preventing Secondary `WARN_ON_ONCE` in Unregistration
If a rollback is not performed, the subsystem is left in a partially initialized state. Later, when the tracer is stopped, it will unconditionally attempt to unregister all tracepoints. Unregistering a tracepoint that was never successfully registered causes `tracepoint_remove_func()` to return `-ENOENT`, which triggers a secondary `WARN_ON_ONCE`.
* **Prior Art:** Commit `0878355b51f5` ("tracing/osnoise: Properly unhook events if start_per_cpu_kthreads() fails") fixed an identical bug where failing to clean up hooks on an error path led to a `WARN_ON_ONCE()` in `tracepoint_remove_func()` during tracer disablement.
### 4. Error Propagation and Locking Rules
The error must be propagated up the call stack to ensure the setup fails gracefully.
* In `get_probe_ref()`, the `blk_probe_mutex` is held. If `blk_register_tracepoints()` fails, you must decrement the `blk_probes_ref` counter before unlocking the mutex, which your proposed fix correctly does.
* In the callers (`blk_trace_setup_finalize()` and `blk_trace_setup_queue()`), propagating the error and cleaning up allocated resources (like `blk_trace_free(q, bt)`) is the correct and expected behavior to prevent memory leaks.
**Conclusion:**
Your proposed fix strategy is completely correct. You should proceed with changing `blk_register_tracepoints()` to return an `int`, replacing the `WARN_ON()` checks with standard `if (ret) goto err_*` blocks for reverse-order unregistration, and propagating the error up through `get_probe_ref()` and the blktrace setup functions.
Reply: The crash occurred because `blk_register_tracepoints()` used `WARN_ON(ret)` on `register_trace_*()` calls. Tracepoint registration functions allocate memory for probe arrays and can legitimately fail with `-ENOMEM` (e.g. under memory pressure or fault injection). Using `WARN_ON()` in this situation triggered kernel panics when `panic_on_warn` was set. Furthermore, ignoring the return value left tracepoints in a partially registered state, leading to subsequent warnings or errors during unregistration.
### Changes Made
1. **Error handling and rollback in `blk_register_tracepoints()`**:
- Changed `blk_register_tracepoints()` to return an `int`.
- Removed `WARN_ON(ret)` for all 18 tracepoints.
- Added sequential error checks and a symmetric `goto` rollback path that unregisters previously registered tracepoints in reverse order and invokes `tracepoint_synchronize_unregister()` before returning the error code.
2. **Reference counter handling in `get_probe_ref()`**:
- Changed `get_probe_ref()` to return an `int`.
- If `blk_register_tracepoints()` fails when initializing the first probe reference (`blk_probes_ref == 1`), `blk_probes_ref` is decremented back to 0 before releasing `blk_probe_mutex` and propagating the error.
3. **Error propagation in `blk_trace_setup_finalize()`**:
- Changed `blk_trace_setup_finalize()` to return an `int`.
- Called `get_probe_ref()` before assigning `rcu_assign_pointer(q->blk_trace, bt)`.
- Propagated the error code to the caller.
4. **Resource cleanup in setup callers**:
- In `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, checked the return value of `blk_trace_setup_finalize()`. If setup fails, freed the allocated `blk_trace` structure using `blk_trace_free(q, bt)` and released debugfs locks before returning the error.
- In `blk_trace_setup_queue()`, checked `get_probe_ref()` before assigning `q->blk_trace`, jumping to `free_bt` on failure.
|
| 127/4 |
2026/08/31 21:29 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 8351
output: 75
thoughts: 66
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Diving into blktrace.c**
Okay, let's get right to it. I need to understand the current implementation of `blktrace` – the go-to file is obviously `kernel/trace/blktrace.c`. My plan is to start with a targeted inspection. I'll use `read-file` to zero in on the key areas. I want to look closely at the code around line 492, then jump down to around line 1332, focusing on the relevant function calls within this file, to quickly grasp its core mechanics and data flow. This approach should give me a solid high-level understanding of what's going on quickly.
|
| 128/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:480 LineCount:50]
Results: map[Contents: 480: } else {
481: debugfs_remove(bt->dir);
482: }
483: free_percpu(bt->sequence);
484: free_percpu(bt->msg_data);
485: kfree(bt);
486: }
487:
488: static void get_probe_ref(void)
489: {
490: mutex_lock(&blk_probe_mutex);
491: if (++blk_probes_ref == 1)
492: blk_register_tracepoints();
493: mutex_unlock(&blk_probe_mutex);
494: }
495:
496: static void put_probe_ref(void)
497: {
498: mutex_lock(&blk_probe_mutex);
499: if (!--blk_probes_ref)
500: blk_unregister_tracepoints();
501: mutex_unlock(&blk_probe_mutex);
502: }
503:
504: static int blk_trace_start(struct blk_trace *bt)
505: {
506: if (bt->trace_state != Blktrace_setup &&
507: bt->trace_state != Blktrace_stopped)
508: return -EINVAL;
509:
510: blktrace_seq++;
511: smp_mb();
512: bt->trace_state = Blktrace_running;
513: raw_spin_lock_irq(&running_trace_lock);
514: list_add(&bt->running_list, &running_trace_list);
515: raw_spin_unlock_irq(&running_trace_lock);
516: trace_note_time(bt);
517:
518: return 0;
519: }
520:
521: static int blk_trace_stop(struct blk_trace *bt)
522: {
523: if (bt->trace_state != Blktrace_running)
524: return -EINVAL;
525:
526: bt->trace_state = Blktrace_stopped;
527: raw_spin_lock_irq(&running_trace_lock);
528: list_del_init(&bt->running_list);
529: raw_spin_unlock_irq(&running_trace_lock);
]
|
| 129/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1300 LineCount:80]
Results: map[Contents:1300: * blk_add_driver_data - Add binary message with driver-specific data
1301: * @rq: io request
1302: * @data: driver-specific data
1303: * @len: length of driver-specific data
1304: *
1305: * Description:
1306: * Some drivers might want to write driver-specific data per request.
1307: *
1308: **/
1309: void blk_add_driver_data(struct request *rq, void *data, size_t len)
1310: {
1311: struct blk_trace *bt;
1312:
1313: rcu_read_lock();
1314: bt = rcu_dereference(rq->q->blk_trace);
1315: if (likely(!bt)) {
1316: rcu_read_unlock();
1317: return;
1318: }
1319:
1320: __blk_add_trace(bt, blk_rq_trace_sector(rq), blk_rq_bytes(rq), 0,
1321: BLK_TA_DRV_DATA, 0, len, data,
1322: blk_trace_request_get_cgid(rq));
1323: rcu_read_unlock();
1324: }
1325: EXPORT_SYMBOL_GPL(blk_add_driver_data);
1326:
1327: static void blk_register_tracepoints(void)
1328: {
1329: int ret;
1330:
1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1332: WARN_ON(ret);
1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1334: WARN_ON(ret);
1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1336: WARN_ON(ret);
1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1338: WARN_ON(ret);
1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1340: WARN_ON(ret);
1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1342: WARN_ON(ret);
1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1344: WARN_ON(ret);
1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1346: WARN_ON(ret);
1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1348: WARN_ON(ret);
1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
1350: WARN_ON(ret);
1351: ret = register_trace_blk_zone_append_update_request_bio(
1352: blk_add_trace_zone_update_request, NULL);
1353: WARN_ON(ret);
1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
1355: NULL);
1356: WARN_ON(ret);
1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
1358: NULL);
1359: WARN_ON(ret);
1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
1361: WARN_ON(ret);
1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
1363: WARN_ON(ret);
1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
1365: WARN_ON(ret);
1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1367: WARN_ON(ret);
1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1369: WARN_ON(ret);
1370: }
1371:
1372: static void blk_unregister_tracepoints(void)
1373: {
1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1376: unregister_trace_block_split(blk_add_trace_split, NULL);
1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
]
|
| 130/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 10890
output: 114
thoughts: 55
Thoughts: Here's my take on the kernel tracing code, specifically `kernel/trace/blktrace.c`:
**Deep Dive into `blktrace.c` - Unregistration and Setup**
Alright, let's get into the nitty-gritty of how block trace points work. I need to understand how the system unregisters and sets up these trace points, especially around `blk_unregister_tracepoints` and the setup functions. I'm focusing on the sections of the code spanning roughly lines 550 to 700 and then a bit later, from 1900 to 2150. These areas likely contain the core logic for managing the lifecycle of these trace points. I'm expecting to find details about cleanup procedures when the tracing is stopped, memory management related to the trace buffer, and interactions with other kernel subsystems. I'll be looking for how the data structures are initialized, linked, and eventually freed. More than likely I will find function calls to the general kernel trace points interface. I'm hoping to confirm my understanding of how tracing is enabled, disabled, and how the resources associated with tracing blocks are managed during their lifecycle. I'll need to pay close attention to potential race conditions and locking mechanisms. I'll be looking for design patterns that are common in this kind of kernel module. The goal is to fully grasp the unregistration and setup sequence.
|
| 131/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1370 LineCount:60]
Results: map[Contents:1370: }
1371:
1372: static void blk_unregister_tracepoints(void)
1373: {
1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1376: unregister_trace_block_split(blk_add_trace_split, NULL);
1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
1380: unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
1381: unregister_trace_blk_zone_append_update_request_bio(
1382: blk_add_trace_zone_update_request, NULL);
1383: unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
1384: unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1385: unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1386: unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1387: unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1388: unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1389: unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1390: unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1391: unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1392: unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1393:
1394: tracepoint_synchronize_unregister();
1395: }
1396:
1397: /*
1398: * struct blk_io_tracer formatting routines
1399: */
1400:
1401: static void fill_rwbs(char *rwbs, const struct blk_io_trace2 *t)
1402: {
1403: int i = 0;
1404: int tc = t->action >> BLK_TC_SHIFT;
1405:
1406: if ((t->action & ~__BLK_TN_CGROUP) == BLK_TN_MESSAGE) {
1407: rwbs[i++] = 'N';
1408: goto out;
1409: }
1410:
1411: if (tc & BLK_TC_FLUSH)
1412: rwbs[i++] = 'F';
1413:
1414: if (tc & BLK_TC_DISCARD)
1415: rwbs[i++] = 'D';
1416: else if (tc & BLK_TC_WRITE_ZEROES) {
1417: rwbs[i++] = 'W';
1418: rwbs[i++] = 'Z';
1419: } else if (tc & BLK_TC_WRITE)
1420: rwbs[i++] = 'W';
1421: else if (t->bytes)
1422: rwbs[i++] = 'R';
1423: else
1424: rwbs[i++] = 'N';
1425:
1426: if (tc & BLK_TC_FUA)
1427: rwbs[i++] = 'F';
1428: if (tc & BLK_TC_AHEAD)
1429: rwbs[i++] = 'A';
]
|
| 132/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:550 LineCount:100]
Results: map[Contents: 550: return -EINVAL;
551:
552: blk_trace_cleanup(q, bt);
553:
554: return 0;
555: }
556:
557: int blk_trace_remove(struct request_queue *q)
558: {
559: int ret;
560:
561: blk_debugfs_lock_nomemsave(q);
562: ret = __blk_trace_remove(q);
563: blk_debugfs_unlock_nomemrestore(q);
564:
565: return ret;
566: }
567: EXPORT_SYMBOL_GPL(blk_trace_remove);
568:
569: static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
570: size_t count, loff_t *ppos)
571: {
572: struct blk_trace *bt = filp->private_data;
573: size_t dropped = relay_stats(bt->rchan, RELAY_STATS_BUF_FULL);
574: char buf[16];
575:
576: snprintf(buf, sizeof(buf), "%zu\n", dropped);
577:
578: return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
579: }
580:
581: static const struct file_operations blk_dropped_fops = {
582: .owner = THIS_MODULE,
583: .open = simple_open,
584: .read = blk_dropped_read,
585: .llseek = default_llseek,
586: };
587:
588: static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,
589: size_t count, loff_t *ppos)
590: {
591: char *msg;
592: struct blk_trace *bt;
593:
594: if (count >= BLK_TN_MAX_MSG)
595: return -EINVAL;
596:
597: msg = memdup_user_nul(buffer, count);
598: if (IS_ERR(msg))
599: return PTR_ERR(msg);
600:
601: bt = filp->private_data;
602: __blk_trace_note_message(bt, NULL, "%s", msg);
603: kfree(msg);
604:
605: return count;
606: }
607:
608: static const struct file_operations blk_msg_fops = {
609: .owner = THIS_MODULE,
610: .open = simple_open,
611: .write = blk_msg_write,
612: .llseek = noop_llseek,
613: };
614:
615: static int blk_remove_buf_file_callback(struct dentry *dentry)
616: {
617: debugfs_remove(dentry);
618:
619: return 0;
620: }
621:
622: static struct dentry *blk_create_buf_file_callback(const char *filename,
623: struct dentry *parent,
624: umode_t mode,
625: struct rchan_buf *buf,
626: int *is_global)
627: {
628: return debugfs_create_file(filename, mode, parent, buf,
629: &relay_file_operations);
630: }
631:
632: static const struct rchan_callbacks blk_relay_callbacks = {
633: .create_buf_file = blk_create_buf_file_callback,
634: .remove_buf_file = blk_remove_buf_file_callback,
635: };
636:
637: static void blk_trace_setup_lba(struct blk_trace *bt,
638: struct block_device *bdev)
639: {
640: if (bdev) {
641: bt->start_lba = bdev->bd_start_sect;
642: bt->end_lba = bdev->bd_start_sect + bdev_nr_sectors(bdev);
643: } else {
644: bt->start_lba = 0;
645: bt->end_lba = -1ULL;
646: }
647: }
648:
649: /*
]
|
| 133/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:650 LineCount:100]
Results: map[Contents: 650: * Setup everything required to start tracing
651: */
652: static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
653: char *name, dev_t dev,
654: u32 buf_size, u32 buf_nr,
655: struct block_device *bdev)
656: {
657: struct blk_trace *bt = NULL;
658: struct dentry *dir = NULL;
659: int ret;
660:
661: lockdep_assert_held(&q->debugfs_mutex);
662:
663: /*
664: * bdev can be NULL, as with scsi-generic, this is a helpful as
665: * we can be.
666: */
667: if (rcu_dereference_protected(q->blk_trace,
668: lockdep_is_held(&q->debugfs_mutex))) {
669: pr_warn("Concurrent blktraces are not allowed on %s\n", name);
670: return ERR_PTR(-EBUSY);
671: }
672:
673: bt = kzalloc_obj(*bt);
674: if (!bt)
675: return ERR_PTR(-ENOMEM);
676:
677: ret = -ENOMEM;
678: bt->sequence = alloc_percpu(unsigned long);
679: if (!bt->sequence)
680: goto err;
681:
682: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
683: if (!bt->msg_data)
684: goto err;
685:
686: /*
687: * When tracing the whole disk reuse the existing debugfs directory
688: * created by the block layer on init. For partitions block devices,
689: * and scsi-generic block devices we create a temporary new debugfs
690: * directory that will be removed once the trace ends.
691: */
692: if (bdev && !bdev_is_partition(bdev))
693: dir = q->debugfs_dir;
694: else
695: bt->dir = dir = debugfs_create_dir(name, blk_debugfs_root);
696:
697: /*
698: * As blktrace relies on debugfs for its interface the debugfs directory
699: * is required, contrary to the usual mantra of not checking for debugfs
700: * files or directories.
701: */
702: if (IS_ERR_OR_NULL(dir)) {
703: pr_warn("debugfs_dir not present for %s so skipping\n", name);
704: ret = -ENOENT;
705: goto err;
706: }
707:
708: bt->dev = dev;
709: INIT_LIST_HEAD(&bt->running_list);
710:
711: ret = -EIO;
712: debugfs_create_file("dropped", 0444, dir, bt, &blk_dropped_fops);
713: debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
714:
715: bt->rchan = relay_open("trace", dir, buf_size, buf_nr,
716: &blk_relay_callbacks, bt);
717: if (!bt->rchan)
718: goto err;
719:
720: blk_trace_setup_lba(bt, bdev);
721:
722: return bt;
723:
724: err:
725: blk_trace_free(q, bt);
726:
727: return ERR_PTR(ret);
728: }
729:
730: static void blk_trace_setup_finalize(struct request_queue *q,
731: char *name, int version,
732: struct blk_trace *bt,
733: struct blk_user_trace_setup2 *buts)
734:
735: {
736: strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
737:
738: /*
739: * some device names have larger paths - convert the slashes
740: * to underscores for this to work as expected
741: */
742: strreplace(buts->name, '/', '_');
743:
744: bt->version = version;
745: bt->act_mask = buts->act_mask;
746: if (!bt->act_mask)
747: bt->act_mask = (u16) -1;
748:
749: /* overwrite with user settings */
]
|
| 134/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 15384
output: 77
thoughts: 36
Thoughts: Here's my take on those code segments in blktrace.c:
**Diving Deep into blktrace.c**
Alright, let's get down to brass tacks. I'm focusing in on specific segments of `blktrace.c` – specifically lines 740 through 860 and then a jump to 1900 through 2200. These sections are crucial to how the tool actually functions, and I need to refresh my understanding and perhaps spot any nuances I might have missed before. My expertise allows me to quickly navigate the codebase, understand the potential implications of various operations, and pinpoint areas that might warrant further investigation or optimization. I'm anticipating that these segments deal with core aspects of event handling, filtering, or data processing within the blktrace workflow. I'm keen to see if any new techniques or approaches have been implemented since the last time I reviewed it. Time to dig in!
|
| 135/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:740 LineCount:100]
Results: map[Contents: 740: * to underscores for this to work as expected
741: */
742: strreplace(buts->name, '/', '_');
743:
744: bt->version = version;
745: bt->act_mask = buts->act_mask;
746: if (!bt->act_mask)
747: bt->act_mask = (u16) -1;
748:
749: /* overwrite with user settings */
750: if (buts->start_lba)
751: bt->start_lba = buts->start_lba;
752: if (buts->end_lba)
753: bt->end_lba = buts->end_lba;
754:
755: bt->pid = buts->pid;
756: bt->trace_state = Blktrace_setup;
757:
758: rcu_assign_pointer(q->blk_trace, bt);
759: get_probe_ref();
760: }
761:
762: int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
763: struct block_device *bdev,
764: char __user *arg)
765: {
766: struct blk_user_trace_setup2 buts2;
767: struct blk_user_trace_setup buts;
768: struct blk_trace *bt;
769: unsigned int memflags;
770: int ret;
771:
772: ret = copy_from_user(&buts, arg, sizeof(buts));
773: if (ret)
774: return -EFAULT;
775:
776: if (!buts.buf_size || !buts.buf_nr)
777: return -EINVAL;
778:
779: buts2 = (struct blk_user_trace_setup2) {
780: .act_mask = buts.act_mask,
781: .buf_size = buts.buf_size,
782: .buf_nr = buts.buf_nr,
783: .start_lba = buts.start_lba,
784: .end_lba = buts.end_lba,
785: .pid = buts.pid,
786: };
787:
788: memflags = blk_debugfs_lock(q);
789: bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
790: bdev);
791: if (IS_ERR(bt)) {
792: blk_debugfs_unlock(q, memflags);
793: return PTR_ERR(bt);
794: }
795: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
796: strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
797: blk_debugfs_unlock(q, memflags);
798:
799: if (copy_to_user(arg, &buts, sizeof(buts))) {
800: blk_trace_remove(q);
801: return -EFAULT;
802: }
803: return 0;
804: }
805: EXPORT_SYMBOL_GPL(blk_trace_setup);
806:
807: static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
808: struct block_device *bdev, char __user *arg)
809: {
810: struct blk_user_trace_setup2 buts2;
811: struct blk_trace *bt;
812: unsigned int memflags;
813:
814: if (copy_from_user(&buts2, arg, sizeof(buts2)))
815: return -EFAULT;
816:
817: if (!buts2.buf_size || !buts2.buf_nr)
818: return -EINVAL;
819:
820: if (buts2.flags != 0)
821: return -EINVAL;
822:
823: memflags = blk_debugfs_lock(q);
824: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
825: bdev);
826: if (IS_ERR(bt)) {
827: blk_debugfs_unlock(q, memflags);
828: return PTR_ERR(bt);
829: }
830: blk_trace_setup_finalize(q, name, 2, bt, &buts2);
831: blk_debugfs_unlock(q, memflags);
832:
833: if (copy_to_user(arg, &buts2, sizeof(buts2))) {
834: blk_trace_remove(q);
835: return -EFAULT;
836: }
837: return 0;
838: }
839:
]
|
| 136/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1900 LineCount:100]
Results: map[Contents:1900: static int blk_trace_setup_queue(struct request_queue *q,
1901: struct block_device *bdev)
1902: {
1903: struct blk_trace *bt = NULL;
1904: int ret = -ENOMEM;
1905:
1906: bt = kzalloc_obj(*bt);
1907: if (!bt)
1908: return -ENOMEM;
1909:
1910: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
1911: if (!bt->msg_data)
1912: goto free_bt;
1913:
1914: bt->dev = bdev->bd_dev;
1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
1930: */
1931:
1932: static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
1933: struct device_attribute *attr,
1934: char *buf);
1935: static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
1936: struct device_attribute *attr,
1937: const char *buf, size_t count);
1938: #define BLK_TRACE_DEVICE_ATTR(_name) \
1939: DEVICE_ATTR(_name, S_IRUGO | S_IWUSR, \
1940: sysfs_blk_trace_attr_show, \
1941: sysfs_blk_trace_attr_store)
1942:
1943: static BLK_TRACE_DEVICE_ATTR(enable);
1944: static BLK_TRACE_DEVICE_ATTR(act_mask);
1945: static BLK_TRACE_DEVICE_ATTR(pid);
1946: static BLK_TRACE_DEVICE_ATTR(start_lba);
1947: static BLK_TRACE_DEVICE_ATTR(end_lba);
1948:
1949: static struct attribute *blk_trace_attrs[] = {
1950: &dev_attr_enable.attr,
1951: &dev_attr_act_mask.attr,
1952: &dev_attr_pid.attr,
1953: &dev_attr_start_lba.attr,
1954: &dev_attr_end_lba.attr,
1955: NULL
1956: };
1957:
1958: struct attribute_group blk_trace_attr_group = {
1959: .name = "trace",
1960: .attrs = blk_trace_attrs,
1961: };
1962:
1963: static const struct {
1964: int mask;
1965: const char *str;
1966: } mask_maps[] = {
1967: { BLK_TC_READ, "read" },
1968: { BLK_TC_WRITE, "write" },
1969: { BLK_TC_FLUSH, "flush" },
1970: { BLK_TC_SYNC, "sync" },
1971: { BLK_TC_QUEUE, "queue" },
1972: { BLK_TC_REQUEUE, "requeue" },
1973: { BLK_TC_ISSUE, "issue" },
1974: { BLK_TC_COMPLETE, "complete" },
1975: { BLK_TC_FS, "fs" },
1976: { BLK_TC_PC, "pc" },
1977: { BLK_TC_NOTIFY, "notify" },
1978: { BLK_TC_AHEAD, "ahead" },
1979: { BLK_TC_META, "meta" },
1980: { BLK_TC_DISCARD, "discard" },
1981: { BLK_TC_DRV_DATA, "drv_data" },
1982: { BLK_TC_FUA, "fua" },
1983: { BLK_TC_WRITE_ZEROES, "write-zeroes" },
1984: };
1985:
1986: static int blk_trace_str2mask(const char *str)
1987: {
1988: int i;
1989: int mask = 0;
1990: char *buf, *s, *token;
1991:
1992: buf = kstrdup(str, GFP_KERNEL);
1993: if (buf == NULL)
1994: return -ENOMEM;
1995: s = strstrip(buf);
1996:
1997: while (1) {
1998: token = strsep(&s, ",");
1999: if (token == NULL)
]
|
| 137/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 18814
output: 37
thoughts: 73
Thoughts: **Diving Deep into the Blktrace Implementation**
Okay, so we need to make absolutely sure we've covered our bases here. Before we go any further, I need to thoroughly examine the interactions with `compat_blk_trace_setup`. I also need to verify every single caller of `blk_trace_setup_finalize`, as well as `get_probe_ref`, `blk_register_tracepoints`, and any other related function in this area. We can't afford to miss any potential points of integration or conflict. To get a handle on the current implementation, I should direct my attention to lines 830 through 900 in `kernel/trace/blktrace.c`. Let's get reading.
|
| 138/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:830 LineCount:80]
Results: map[Contents: 830: blk_trace_setup_finalize(q, name, 2, bt, &buts2);
831: blk_debugfs_unlock(q, memflags);
832:
833: if (copy_to_user(arg, &buts2, sizeof(buts2))) {
834: blk_trace_remove(q);
835: return -EFAULT;
836: }
837: return 0;
838: }
839:
840: #if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
841: static int compat_blk_trace_setup(struct request_queue *q, char *name,
842: dev_t dev, struct block_device *bdev,
843: char __user *arg)
844: {
845: struct blk_user_trace_setup2 buts2;
846: struct compat_blk_user_trace_setup cbuts;
847: struct blk_trace *bt;
848: unsigned int memflags;
849:
850: if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
851: return -EFAULT;
852:
853: if (!cbuts.buf_size || !cbuts.buf_nr)
854: return -EINVAL;
855:
856: buts2 = (struct blk_user_trace_setup2) {
857: .act_mask = cbuts.act_mask,
858: .buf_size = cbuts.buf_size,
859: .buf_nr = cbuts.buf_nr,
860: .start_lba = cbuts.start_lba,
861: .end_lba = cbuts.end_lba,
862: .pid = cbuts.pid,
863: };
864:
865: memflags = blk_debugfs_lock(q);
866: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
867: bdev);
868: if (IS_ERR(bt)) {
869: blk_debugfs_unlock(q, memflags);
870: return PTR_ERR(bt);
871: }
872: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
873: blk_debugfs_unlock(q, memflags);
874:
875: if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
876: blk_trace_remove(q);
877: return -EFAULT;
878: }
879:
880: return 0;
881: }
882: #endif
883:
884: static int __blk_trace_startstop(struct request_queue *q, int start)
885: {
886: struct blk_trace *bt;
887:
888: bt = rcu_dereference_protected(q->blk_trace,
889: lockdep_is_held(&q->debugfs_mutex));
890: if (bt == NULL)
891: return -EINVAL;
892:
893: if (start)
894: return blk_trace_start(bt);
895: else
896: return blk_trace_stop(bt);
897: }
898:
899: int blk_trace_startstop(struct request_queue *q, int start)
900: {
901: int ret;
902:
903: blk_debugfs_lock_nomemsave(q);
904: ret = __blk_trace_startstop(q, start);
905: blk_debugfs_unlock_nomemrestore(q);
906:
907: return ret;
908: }
909: EXPORT_SYMBOL_GPL(blk_trace_startstop);
]
|
| 139/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 20315
output: 72
thoughts: 70
Thoughts: Here's my summary, as though I'm thinking through this process:
**Tracing Down Tracepoint Registration & Management**
Okay, so I need to get a handle on how these tracepoints are being registered and managed within the block layer. I know there are a few key functions involved: `blk_register_tracepoints`, `blk_unregister_tracepoints`, those probe reference functions `get_probe_ref`, `put_probe_ref`, and then the setup and finalization routines, `blk_trace_setup_finalize`, `blk_trace_setup_queue`.
My approach is going to be systematic. Instead of wading through the entire codebase manually, I'll leverage my usual tools to quickly pinpoint the relevant code locations. I'm thinking I'll start with either `codesearch-find-references` or `grepper` – probably just use whichever is fastest to index the source and return results. I want to see *every* instance where these functions are called. That should give me a solid map of the call graph and how the tracing infrastructure is initialized and shut down within the block layer. From there, I can analyze the surrounding code to understand the context and flow. This should be a straightforward task to build a base of understanding of the system.
|
| 140/4 |
2026/08/31 21:30 |
tool |
grepper |
0m
Args: map[Expression:(blk_register_tracepoints|blk_unregister_tracepoints|get_probe_ref|put_probe_ref|blk_trace_setup_finalize|blk_trace_setup_queue) PathPrefix:kernel/trace/blktrace.c]
Results: map[Output:kernel/trace/blktrace.c=61=static int blk_probes_ref;
kernel/trace/blktrace.c-62-
kernel/trace/blktrace.c:63:static void blk_register_tracepoints(void);
kernel/trace/blktrace.c:64:static void blk_unregister_tracepoints(void);
kernel/trace/blktrace.c-65-
--
kernel/trace/blktrace.c=310=static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
--
kernel/trace/blktrace.c-397- * For sysfs-enabled tracing path (enabled via
kernel/trace/blktrace.c:398: * /sys/block/DEV/trace/enable), blk_trace_setup_queue()
kernel/trace/blktrace.c-399- * never initializes bt->version, leaving it 0 from
--
kernel/trace/blktrace.c=469=static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
--
kernel/trace/blktrace.c-487-
kernel/trace/blktrace.c:488:static void get_probe_ref(void)
kernel/trace/blktrace.c-489-{
--
kernel/trace/blktrace.c-491- if (++blk_probes_ref == 1)
kernel/trace/blktrace.c:492: blk_register_tracepoints();
kernel/trace/blktrace.c-493- mutex_unlock(&blk_probe_mutex);
--
kernel/trace/blktrace.c-495-
kernel/trace/blktrace.c:496:static void put_probe_ref(void)
kernel/trace/blktrace.c-497-{
--
kernel/trace/blktrace.c-499- if (!--blk_probes_ref)
kernel/trace/blktrace.c:500: blk_unregister_tracepoints();
kernel/trace/blktrace.c-501- mutex_unlock(&blk_probe_mutex);
--
kernel/trace/blktrace.c=535=static void blk_trace_cleanup(struct request_queue *q, struct blk_trace *bt)
--
kernel/trace/blktrace.c-539- blk_trace_free(q, bt);
kernel/trace/blktrace.c:540: put_probe_ref();
kernel/trace/blktrace.c-541-}
--
kernel/trace/blktrace.c=652=static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
--
kernel/trace/blktrace.c-729-
kernel/trace/blktrace.c:730:static void blk_trace_setup_finalize(struct request_queue *q,
kernel/trace/blktrace.c-731- char *name, int version,
--
kernel/trace/blktrace.c-758- rcu_assign_pointer(q->blk_trace, bt);
kernel/trace/blktrace.c:759: get_probe_ref();
kernel/trace/blktrace.c-760-}
--
kernel/trace/blktrace.c=762=int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
--
kernel/trace/blktrace.c-794- }
kernel/trace/blktrace.c:795: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
kernel/trace/blktrace.c-796- strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
--
kernel/trace/blktrace.c=807=static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
--
kernel/trace/blktrace.c-829- }
kernel/trace/blktrace.c:830: blk_trace_setup_finalize(q, name, 2, bt, &buts2);
kernel/trace/blktrace.c-831- blk_debugfs_unlock(q, memflags);
--
kernel/trace/blktrace.c=841=static int compat_blk_trace_setup(struct request_queue *q, char *name,
--
kernel/trace/blktrace.c-871- }
kernel/trace/blktrace.c:872: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
kernel/trace/blktrace.c-873- blk_debugfs_unlock(q, memflags);
--
kernel/trace/blktrace.c=1325=EXPORT_SYMBOL_GPL(blk_add_driver_data);
kernel/trace/blktrace.c-1326-
kernel/trace/blktrace.c:1327:static void blk_register_tracepoints(void)
kernel/trace/blktrace.c-1328-{
--
kernel/trace/blktrace.c-1371-
kernel/trace/blktrace.c:1372:static void blk_unregister_tracepoints(void)
kernel/trace/blktrace.c-1373-{
--
kernel/trace/blktrace.c=1880=static int blk_trace_remove_queue(struct request_queue *q)
--
kernel/trace/blktrace.c-1890-
kernel/trace/blktrace.c:1891: put_probe_ref();
kernel/trace/blktrace.c-1892- synchronize_rcu();
--
kernel/trace/blktrace.c-1899- */
kernel/trace/blktrace.c:1900:static int blk_trace_setup_queue(struct request_queue *q,
kernel/trace/blktrace.c-1901- struct block_device *bdev)
--
kernel/trace/blktrace.c-1919- rcu_assign_pointer(q->blk_trace, bt);
kernel/trace/blktrace.c:1920: get_probe_ref();
kernel/trace/blktrace.c-1921- return 0;
--
kernel/trace/blktrace.c=2071=static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
--
kernel/trace/blktrace.c-2107- if (value)
kernel/trace/blktrace.c:2108: ret = blk_trace_setup_queue(q, bdev);
kernel/trace/blktrace.c-2109- else
--
kernel/trace/blktrace.c-2115- if (bt == NULL) {
kernel/trace/blktrace.c:2116: ret = blk_trace_setup_queue(q, bdev);
kernel/trace/blktrace.c-2117- bt = rcu_dereference_protected(q->blk_trace,
]
|
| 141/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 22578
output: 36
thoughts: 28
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Analyzing `blktrace.c` Forward Declarations**
Alright, time to dive into this. Based on my existing knowledge, I need to understand how the forward declarations are set up in `kernel/trace/blktrace.c`. It's a key spot to ensure proper function linking and avoid compilation issues. Let's zero in on lines 60-70. That range is usually where you'd find a concentration of those critical function prototypes, definitions that the compiler uses to link up the rest of the code. This is where I will begin my analysis.
|
| 142/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:55 LineCount:25]
Results: map[Contents: 55: .val = 0,
56: .opts = blk_tracer_opts,
57: };
58:
59: /* Global reference count of probes */
60: static DEFINE_MUTEX(blk_probe_mutex);
61: static int blk_probes_ref;
62:
63: static void blk_register_tracepoints(void);
64: static void blk_unregister_tracepoints(void);
65:
66: static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
67: sector_t sector, int bytes, u64 what,
68: dev_t dev, int error, u64 cgid,
69: ssize_t cgid_len, void *pdu_data, int pdu_len)
70:
71: {
72: /*
73: * These two are not needed in ftrace as they are in the
74: * generic trace_entry, filled by tracing_generic_entry_update,
75: * but for the trace_event->bin() synthesizer benefit we do it
76: * here too.
77: */
78: t->cpu = cpu;
79: t->pid = pid;
]
|
| 143/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 23158
output: 20
thoughts: 1388
Thoughts: **Analyzing Tracepoint Registration and Error Handling**
Okay, let's break this down. First, I'm looking at `static void blk_register_tracepoints(void);` and I'm pretty sure it should be returning an `int`, not `void`, given the registration logic. So, that's the first thing I need to correct: `static int blk_register_tracepoints(void);`.
Now, I'm going to meticulously examine every instance of `blk_register_tracepoints`, `get_probe_ref`, `blk_trace_setup_finalize`, `blk_trace_setup`, `blk_trace_setup2`, `compat_blk_trace_setup`, and `blk_trace_setup_queue`, and especially their associated error paths. We need to make sure any change here cascades correctly. I have to be absolutely certain of the correct behavior.
Let's start with `blk_register_tracepoints` itself. I'm going to inspect the registration process in detail. Here's the current code:
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
WARN_ON(ret);
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
WARN_ON(ret);
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
WARN_ON(ret);
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
WARN_ON(ret);
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
WARN_ON(ret);
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
WARN_ON(ret);
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
WARN_ON(ret);
ret = register_trace_block_split(blk_add_trace_split, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
WARN_ON(ret);
}
```
Okay, so it registers a whole bunch of tracepoints. And here's the unregistration function:
```c
static void blk_unregister_tracepoints(void)
{
unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
unregister_trace_block_split(blk_add_trace_split, NULL);
unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
|
| 144/4 |
2026/08/31 21:30 |
tool |
grepper |
0m
Error:
Args: map[Expression:register_trace_.*goto]
Results:
|
| 145/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 25605
output: 28
thoughts: 18
Thoughts: Here's my take on those thoughts:
**Tracing Kernel Unregistration Functions**
Alright, time to get digging. I need to find the specific functions related to unregistering trace points within the kernel's tracing subsystem. My instinct is to zero in on `kernel/trace/`. That's the logical place to start looking for the core implementation of tracing functionality. I'll need to use my search tools to pinpoint those unregistration functions; my go-to search term will be `unregister_trace_`. That should be precise enough to filter out a lot of the irrelevant noise and hone in on the code I'm actually interested in. Let's see what that search yields.
|
| 146/4 |
2026/08/31 21:30 |
tool |
grepper |
0m
Args: map[Expression:unregister_trace_ PathPrefix:kernel/trace/]
Results: map[Output:kernel/trace/blktrace.c=1372=static void blk_unregister_tracepoints(void)
kernel/trace/blktrace.c-1373-{
kernel/trace/blktrace.c:1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c:1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c:1376: unregister_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c:1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c:1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c:1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
kernel/trace/blktrace.c:1380: unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
kernel/trace/blktrace.c:1381: unregister_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1382- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c:1383: unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c:1384: unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c:1385: unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c:1386: unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c:1387: unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c:1388: unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c:1389: unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c:1390: unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c:1391: unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c:1392: unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1393-
--
kernel/trace/blktrace.c=1839=static int __init __init_blk_tracer(void)
--
kernel/trace/blktrace.c-1847- pr_warn("Warning: could not register the block tracer\n");
kernel/trace/blktrace.c:1848: unregister_trace_event(&trace_blk_event);
kernel/trace/blktrace.c-1849- return 1;
--
kernel/trace/fgraph.c=1426=void unregister_ftrace_graph(struct fgraph_ops *gops)
--
kernel/trace/fgraph.c-1463- unregister_pm_notifier(&ftrace_suspend_notifier);
kernel/trace/fgraph.c:1464: unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
kernel/trace/fgraph.c-1465- }
--
kernel/trace/ftrace.c=8691=void ftrace_pid_follow_fork(struct trace_array *tr, bool enable)
--
kernel/trace/ftrace.c-8698- } else {
kernel/trace/ftrace.c:8699: unregister_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
kernel/trace/ftrace.c-8700- tr);
kernel/trace/ftrace.c:8701: unregister_trace_sched_process_free(ftrace_pid_follow_sched_process_exit,
kernel/trace/ftrace.c-8702- tr);
--
kernel/trace/ftrace.c=8706=static void clear_ftrace_pids(struct trace_array *tr, int type)
--
kernel/trace/ftrace.c-8722- if (!still_need_pid_events(type, pid_list, no_pid_list)) {
kernel/trace/ftrace.c:8723: unregister_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr);
kernel/trace/ftrace.c-8724- for_each_possible_cpu(cpu)
--
kernel/trace/trace_eprobe.c=77=static int eprobe_dyn_event_show(struct seq_file *m, struct dyn_event *ev)
--
kernel/trace/trace_eprobe.c-94-
kernel/trace/trace_eprobe.c:95:static int unregister_trace_eprobe(struct trace_eprobe *ep)
kernel/trace/trace_eprobe.c-96-{
--
kernel/trace/trace_eprobe.c=116=static int eprobe_dyn_event_release(struct dyn_event *ev)
--
kernel/trace/trace_eprobe.c-118- struct trace_eprobe *ep = to_trace_eprobe(ev);
kernel/trace/trace_eprobe.c:119: int ret = unregister_trace_eprobe(ep);
kernel/trace/trace_eprobe.c-120-
--
kernel/trace/trace_events.c=1093=void trace_event_follow_fork(struct trace_array *tr, bool enable)
--
kernel/trace/trace_events.c-1100- } else {
kernel/trace/trace_events.c:1101: unregister_trace_sched_process_fork(event_filter_pid_sched_process_fork,
kernel/trace/trace_events.c-1102- tr);
kernel/trace/trace_events.c:1103: unregister_trace_sched_process_free(event_filter_pid_sched_process_exit,
kernel/trace/trace_events.c-1104- tr);
--
kernel/trace/trace_events.c=1188=static void unregister_pid_events(struct trace_array *tr)
kernel/trace/trace_events.c-1189-{
kernel/trace/trace_events.c:1190: unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_pre, tr);
kernel/trace/trace_events.c:1191: unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_post, tr);
kernel/trace/trace_events.c-1192-
kernel/trace/trace_events.c:1193: unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1194: unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1195-
kernel/trace/trace_events.c:1196: unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1197: unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1198-
kernel/trace/trace_events.c:1199: unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1200: unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1201-}
--
kernel/trace/trace_events.c=3350=static void event_remove(struct trace_event_call *call)
--
kernel/trace/trace_events.c-3372- if (call->event.funcs)
kernel/trace/trace_events.c:3373: __unregister_trace_event(&call->event);
kernel/trace/trace_events.c-3374- remove_event_from_tracers(call);
--
kernel/trace/trace_events_synth.c=955=static int register_synth_event(struct synth_event *event)
--
kernel/trace/trace_events_synth.c-999- ret = set_synth_event_print_fmt(call);
kernel/trace/trace_events_synth.c:1000: /* unregister_trace_event() will be called inside */
kernel/trace/trace_events_synth.c-1001- if (ret < 0)
--
kernel/trace/trace_events_synth.c-1005- err:
kernel/trace/trace_events_synth.c:1006: unregister_trace_event(&call->event);
kernel/trace/trace_events_synth.c-1007- goto out;
--
kernel/trace/trace_events_user.c=1966=static int user_event_trace_register(struct user_event *user)
--
kernel/trace/trace_events_user.c-1977- if (ret)
kernel/trace/trace_events_user.c:1978: unregister_trace_event(&user->call.event);
kernel/trace/trace_events_user.c-1979-
--
kernel/trace/trace_fprobe.c=814=static int __register_trace_fprobe(struct trace_fprobe *tf)
--
kernel/trace/trace_fprobe.c-841-/* Internal unregister function - just handle fprobe and flags */
kernel/trace/trace_fprobe.c:842:static void __unregister_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-843-{
--
kernel/trace/trace_fprobe.c-853-/* Unregister a trace_probe and probe_event */
kernel/trace/trace_fprobe.c:854:static int unregister_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-855-{
--
kernel/trace/trace_fprobe.c-872-unreg:
kernel/trace/trace_fprobe.c:873: __unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-874- dyn_event_remove(&tf->devent);
--
kernel/trace/trace_fprobe.c=1419=static int trace_fprobe_release(struct dyn_event *ev)
--
kernel/trace/trace_fprobe.c-1421- struct trace_fprobe *tf = to_trace_fprobe(ev);
kernel/trace/trace_fprobe.c:1422: int ret = unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1423-
--
kernel/trace/trace_fprobe.c=1457=static int enable_trace_fprobe(struct trace_event_call *call,
--
kernel/trace/trace_fprobe.c-1490- list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list)
kernel/trace/trace_fprobe.c:1491: __unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1492- if (file)
--
kernel/trace/trace_kprobe.c=495=static int __register_trace_kprobe(struct trace_kprobe *tk)
--
kernel/trace/trace_kprobe.c-532-/* Internal unregister function - just handle k*probes and flags */
kernel/trace/trace_kprobe.c:533:static void __unregister_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-534-{
--
kernel/trace/trace_kprobe.c-548-/* Unregister a trace_probe and probe_event */
kernel/trace/trace_kprobe.c:549:static int unregister_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-550-{
--
kernel/trace/trace_kprobe.c-567-unreg:
kernel/trace/trace_kprobe.c:568: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-569- dyn_event_remove(&tk->devent);
--
kernel/trace/trace_kprobe.c=703=static int trace_kprobe_module_callback(struct notifier_block *nb,
--
kernel/trace/trace_kprobe.c-718- /* Don't need to check busy - this should have gone. */
kernel/trace/trace_kprobe.c:719: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-720- ret = register_module_trace_kprobe(mod, tk);
--
kernel/trace/trace_kprobe.c=1298=static int trace_kprobe_release(struct dyn_event *ev)
--
kernel/trace/trace_kprobe.c-1300- struct trace_kprobe *tk = to_trace_kprobe(ev);
kernel/trace/trace_kprobe.c:1301: int ret = unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1302-
--
kernel/trace/trace_kprobe.c=1978=void destroy_local_trace_kprobe(struct trace_event_call *event_call)
--
kernel/trace/trace_kprobe.c-1990-
kernel/trace/trace_kprobe.c:1991: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1992-
--
kernel/trace/trace_osnoise.c=1004=static int hook_irq_events(void)
--
kernel/trace/trace_osnoise.c-1022-out_irq_exit:
kernel/trace/trace_osnoise.c:1023: unregister_trace_irq_handler_exit(trace_irqexit_callback, NULL);
kernel/trace/trace_osnoise.c-1024-out_unregister_entry:
kernel/trace/trace_osnoise.c:1025: unregister_trace_irq_handler_entry(trace_irqentry_callback, NULL);
kernel/trace/trace_osnoise.c-1026-out_err:
--
kernel/trace/trace_osnoise.c=1036=static void unhook_irq_events(void)
--
kernel/trace/trace_osnoise.c-1038- osnoise_arch_unregister();
kernel/trace/trace_osnoise.c:1039: unregister_trace_irq_handler_exit(trace_irqexit_callback, NULL);
kernel/trace/trace_osnoise.c:1040: unregister_trace_irq_handler_entry(trace_irqentry_callback, NULL);
kernel/trace/trace_osnoise.c-1041-}
--
kernel/trace/trace_osnoise.c=1100=static int hook_softirq_events(void)
--
kernel/trace/trace_osnoise.c-1114-out_unreg_entry:
kernel/trace/trace_osnoise.c:1115: unregister_trace_softirq_entry(trace_softirq_entry_callback, NULL);
kernel/trace/trace_osnoise.c-1116-out_err:
--
kernel/trace/trace_osnoise.c=1126=static void unhook_softirq_events(void)
kernel/trace/trace_osnoise.c-1127-{
kernel/trace/trace_osnoise.c:1128: unregister_trace_softirq_entry(trace_softirq_entry_callback, NULL);
kernel/trace/trace_osnoise.c:1129: unregister_trace_softirq_exit(trace_softirq_exit_callback, NULL);
kernel/trace/trace_osnoise.c-1130-}
--
kernel/trace/trace_osnoise.c=1259=static void unregister_migration_monitor(void)
--
kernel/trace/trace_osnoise.c-1263-
kernel/trace/trace_osnoise.c:1264: unregister_trace_sched_migrate_task(trace_sched_migrate_callback, NULL);
kernel/trace/trace_osnoise.c-1265- monitor_enabled = false;
--
kernel/trace/trace_osnoise.c=1302=static int hook_thread_events(void)
--
kernel/trace/trace_osnoise.c-1316-out_unreg:
kernel/trace/trace_osnoise.c:1317: unregister_trace_sched_switch(trace_sched_switch_callback, NULL);
kernel/trace/trace_osnoise.c-1318- return -EINVAL;
--
kernel/trace/trace_osnoise.c=1327=static void unhook_thread_events(void)
kernel/trace/trace_osnoise.c-1328-{
kernel/trace/trace_osnoise.c:1329: unregister_trace_sched_switch(trace_sched_switch_callback, NULL);
kernel/trace/trace_osnoise.c-1330- unregister_migration_monitor();
--
kernel/trace/trace_output.c=924=EXPORT_SYMBOL_GPL(register_trace_event);
--
kernel/trace/trace_output.c-928- */
kernel/trace/trace_output.c:929:int __unregister_trace_event(struct trace_event *event)
kernel/trace/trace_output.c-930-{
--
kernel/trace/trace_output.c-936-/**
kernel/trace/trace_output.c:937: * unregister_trace_event - remove a no longer used event
kernel/trace/trace_output.c-938- * @event: the event to remove
kernel/trace/trace_output.c-939- */
kernel/trace/trace_output.c:940:int unregister_trace_event(struct trace_event *event)
kernel/trace/trace_output.c-941-{
kernel/trace/trace_output.c-942- down_write(&trace_event_sem);
kernel/trace/trace_output.c:943: __unregister_trace_event(event);
kernel/trace/trace_output.c-944- up_write(&trace_event_sem);
--
kernel/trace/trace_output.c-947-}
kernel/trace/trace_output.c:948:EXPORT_SYMBOL_GPL(unregister_trace_event);
kernel/trace/trace_output.c-949-
--
kernel/trace/trace_output.h=43=trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry);
--
kernel/trace/trace_output.h-45-/* used by module unregistering */
kernel/trace/trace_output.h:46:extern int __unregister_trace_event(struct trace_event *event);
kernel/trace/trace_output.h-47-extern struct rw_semaphore trace_event_sem;
--
kernel/trace/trace_probe.c=2691=int trace_probe_register_event_call(struct trace_probe *tp)
--
kernel/trace/trace_probe.c-2707- if (ret)
kernel/trace/trace_probe.c:2708: unregister_trace_event(&call->event);
kernel/trace/trace_probe.c-2709-
--
kernel/trace/trace_sched_switch.c=52=static int tracing_sched_register(void)
--
kernel/trace/trace_sched_switch.c-78-fail_deprobe_wake_new:
kernel/trace/trace_sched_switch.c:79: unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-80-fail_deprobe:
kernel/trace/trace_sched_switch.c:81: unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-82- return ret;
--
kernel/trace/trace_sched_switch.c=85=static void tracing_sched_unregister(void)
kernel/trace/trace_sched_switch.c-86-{
kernel/trace/trace_sched_switch.c:87: unregister_trace_sched_switch(probe_sched_switch, NULL);
kernel/trace/trace_sched_switch.c:88: unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c:89: unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-90-}
--
kernel/trace/trace_sched_wakeup.c=612=static void start_wakeup_tracer(struct trace_array *tr)
--
kernel/trace/trace_sched_wakeup.c-659-fail_deprobe_sched_switch:
kernel/trace/trace_sched_wakeup.c:660: unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
kernel/trace/trace_sched_wakeup.c-661-fail_deprobe_wake_new:
kernel/trace/trace_sched_wakeup.c:662: unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
kernel/trace/trace_sched_wakeup.c-663-fail_deprobe:
kernel/trace/trace_sched_wakeup.c:664: unregister_trace_sched_wakeup(probe_wakeup, NULL);
kernel/trace/trace_sched_wakeup.c-665-}
--
kernel/trace/trace_sched_wakeup.c=667=static void stop_wakeup_tracer(struct trace_array *tr)
--
kernel/trace/trace_sched_wakeup.c-670- stop_func_tracer(tr, is_graph(tr));
kernel/trace/trace_sched_wakeup.c:671: unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
kernel/trace/trace_sched_wakeup.c:672: unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
kernel/trace/trace_sched_wakeup.c:673: unregister_trace_sched_wakeup(probe_wakeup, NULL);
kernel/trace/trace_sched_wakeup.c:674: unregister_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
kernel/trace/trace_sched_wakeup.c-675-}
--
kernel/trace/trace_syscalls.c=999=static void unreg_event_syscall_enter(struct trace_event_file *file,
--
kernel/trace/trace_syscalls.c-1012- if (!tr->sys_refcount_enter)
kernel/trace/trace_syscalls.c:1013: unregister_trace_sys_enter(ftrace_syscall_enter, tr);
kernel/trace/trace_syscalls.c-1014- if (sys_data->user_mask)
--
kernel/trace/trace_syscalls.c=1039=static void unreg_event_syscall_exit(struct trace_event_file *file,
--
kernel/trace/trace_syscalls.c-1051- if (!tr->sys_refcount_exit)
kernel/trace/trace_syscalls.c:1052: unregister_trace_sys_exit(ftrace_syscall_exit, tr);
kernel/trace/trace_syscalls.c-1053- mutex_unlock(&syscall_trace_lock);
--
kernel/trace/trace_syscalls.c=1527=static void perf_sysenter_disable(struct trace_event_call *call)
--
kernel/trace/trace_syscalls.c-1537- if (!sys_perf_refcount_enter)
kernel/trace/trace_syscalls.c:1538: unregister_trace_sys_enter(perf_syscall_enter, NULL);
kernel/trace/trace_syscalls.c-1539- if (sys_data->user_mask)
--
kernel/trace/trace_syscalls.c=1637=static void perf_sysexit_disable(struct trace_event_call *call)
--
kernel/trace/trace_syscalls.c-1646- if (!sys_perf_refcount_exit)
kernel/trace/trace_syscalls.c:1647: unregister_trace_sys_exit(perf_syscall_exit, NULL);
kernel/trace/trace_syscalls.c-1648-}
--
kernel/trace/trace_uprobe.c=381=static struct trace_uprobe *find_probe_event(const char *event, const char *group)
--
kernel/trace/trace_uprobe.c-394-/* Unregister a trace_uprobe and probe_event */
kernel/trace/trace_uprobe.c:395:static int unregister_trace_uprobe(struct trace_uprobe *tu)
kernel/trace/trace_uprobe.c-396-{
--
kernel/trace/trace_uprobe.c=743=static int trace_uprobe_release(struct dyn_event *ev)
--
kernel/trace/trace_uprobe.c-746-
kernel/trace/trace_uprobe.c:747: return unregister_trace_uprobe(tu);
kernel/trace/trace_uprobe.c-748-}
]
|
| 147/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 32600
output: 38
thoughts: 34
Thoughts: Okay, here's the summary, rendered as a first-person thought process, keeping in mind the user is an expert:
**Navigating the Scheduler Tracepoint Registration**
Alright, let's dive into this. I'm focusing on the `trace_sched_switch.c` file – that's the one handling the `sched_switch` tracepoint, right? Hmm, time to check my memory... yeah, I'm pretty sure that's where the registration logic lives. So, the key function I'm after should be `tracing_sched_register()`. Makes sense.
Okay, let's pull up the code. *read-file*, let's see what we've got in there... I want to see how that tracepoint gets hooked into the scheduler infrastructure, the details of the arguments it uses... the whole registration process. It's time to dig into the implementation specifics and confirm my initial assumptions. Let's start reading.
|
| 148/4 |
2026/08/31 21:30 |
tool |
read-file |
0m
Args: map[File:kernel/trace/trace_sched_switch.c FirstLine:50 LineCount:45]
Results: map[Contents: 50: }
51:
52: static int tracing_sched_register(void)
53: {
54: int ret;
55:
56: ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL);
57: if (ret) {
58: pr_info("wakeup trace: Couldn't activate tracepoint"
59: " probe to kernel_sched_wakeup\n");
60: return ret;
61: }
62:
63: ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
64: if (ret) {
65: pr_info("wakeup trace: Couldn't activate tracepoint"
66: " probe to kernel_sched_wakeup_new\n");
67: goto fail_deprobe;
68: }
69:
70: ret = register_trace_sched_switch(probe_sched_switch, NULL);
71: if (ret) {
72: pr_info("sched trace: Couldn't activate tracepoint"
73: " probe to kernel_sched_switch\n");
74: goto fail_deprobe_wake_new;
75: }
76:
77: return ret;
78: fail_deprobe_wake_new:
79: unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
80: fail_deprobe:
81: unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
82: return ret;
83: }
84:
85: static void tracing_sched_unregister(void)
86: {
87: unregister_trace_sched_switch(probe_sched_switch, NULL);
88: unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
89: unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
90: }
91:
92: static void tracing_start_sched_switch(int ops)
93: {
94: bool sched_register;
]
|
| 149/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 33481
output: 21
thoughts: 103
Thoughts: **Analyzing Tracepoint Unregistration**
Okay, let's dive into this. My initial focus is on `tracepoint_synchronize_unregister()`. Specifically, I'm trying to determine the correct call flow and if it's being handled appropriately in all scenarios. Right now, I see that `blk_unregister_tracepoints()` calls `tracepoint_synchronize_unregister()` at the very end. That makes logical sense, but I'm thinking about error handling during the *registration* process, `blk_register_tracepoints()`. If there's a rollback during registration due to an error, should `tracepoint_synchronize_unregister()` be part of that rollback sequence? That's the critical question I need to answer. To do that effectively, I'm going to need a deeper understanding of what `tracepoint_synchronize_unregister()` actually *does*. I need to see what's happening under the hood. Time to fire up my search tools and look for every instance of `tracepoint_synchronize_unregister` across the entire kernel. This will paint a complete picture of its usage and any potential dependencies or side effects.
|
| 150/4 |
2026/08/31 21:30 |
tool |
grepper |
0m
Args: map[Expression:tracepoint_synchronize_unregister]
Results: map[Output:Documentation/trace/tracepoints.rst=96=unregister_trace_subsys_eventname(); it will remove the probe.
Documentation/trace/tracepoints.rst-97-
Documentation/trace/tracepoints.rst:98:tracepoint_synchronize_unregister() must be called before the end of
Documentation/trace/tracepoints.rst-99-the module exit function to make sure there is no caller left using
--
drivers/greybus/core.c=367=static void __exit gb_exit(void)
--
drivers/greybus/core.c-372- gb_debugfs_cleanup();
drivers/greybus/core.c:373: tracepoint_synchronize_unregister();
drivers/greybus/core.c-374-}
--
drivers/i2c/i2c-core-base.c=2154=static void __exit i2c_exit(void)
--
drivers/i2c/i2c-core-base.c-2162- bus_unregister(&i2c_bus_type);
drivers/i2c/i2c-core-base.c:2163: tracepoint_synchronize_unregister();
drivers/i2c/i2c-core-base.c-2164-}
--
include/linux/tracepoint.h=96=void for_each_tracepoint_in_module(struct module *mod,
--
include/linux/tracepoint.h-104-/*
include/linux/tracepoint.h:105: * tracepoint_synchronize_unregister must be called between the last tracepoint
include/linux/tracepoint.h-106- * probe unregistration and the end of module exit to make sure there is no
--
include/linux/tracepoint.h=116=extern struct srcu_struct tracepoint_srcu;
include/linux/tracepoint.h:117:static inline void tracepoint_synchronize_unregister(void)
include/linux/tracepoint.h-118-{
--
include/linux/tracepoint.h=138=static inline void call_tracepoint_unregister_syscall(struct rcu_head *rcu, rcu_callback_t func)
--
include/linux/tracepoint.h-142-#else
include/linux/tracepoint.h:143:static inline void tracepoint_synchronize_unregister(void)
include/linux/tracepoint.h-144-{ }
--
include/rv/da_monitor.h=387=static inline void da_monitor_destroy(void)
--
include/rv/da_monitor.h-393-
include/rv/da_monitor.h:394: tracepoint_synchronize_unregister();
include/rv/da_monitor.h-395- da_monitor_reset_all();
--
include/rv/da_monitor.h=596=static inline void da_monitor_destroy(void)
--
include/rv/da_monitor.h-601-
include/rv/da_monitor.h:602: tracepoint_synchronize_unregister();
include/rv/da_monitor.h-603- da_monitor_reset_all();
--
include/rv/ltl_monitor.h=76=static void ltl_monitor_destroy(void)
--
include/rv/ltl_monitor.h-79-
include/rv/ltl_monitor.h:80: tracepoint_synchronize_unregister();
include/rv/ltl_monitor.h-81- rv_put_task_monitor_slot(ltl_monitor_slot);
--
kernel/kcsan/kcsan_test.c=1606=static void kcsan_suite_exit(struct kunit_suite *suite)
--
kernel/kcsan/kcsan_test.c-1608- unregister_tracepoints();
kernel/kcsan/kcsan_test.c:1609: tracepoint_synchronize_unregister();
kernel/kcsan/kcsan_test.c-1610-}
--
kernel/trace/blktrace.c=1372=static void blk_unregister_tracepoints(void)
--
kernel/trace/blktrace.c-1393-
kernel/trace/blktrace.c:1394: tracepoint_synchronize_unregister();
kernel/trace/blktrace.c-1395-}
--
kernel/trace/rv/rv.c=249=static int __rv_disable_monitor(struct rv_monitor *mon, bool sync)
--
kernel/trace/rv/rv.c-263- if (sync)
kernel/trace/rv/rv.c:264: tracepoint_synchronize_unregister();
kernel/trace/rv/rv.c-265- return 1;
--
kernel/trace/rv/rv.c=292=static void rv_disable_container(struct rv_monitor *mon)
--
kernel/trace/rv/rv.c-302- if (enabled)
kernel/trace/rv/rv.c:303: tracepoint_synchronize_unregister();
kernel/trace/rv/rv.c-304- mon->enabled = 0;
--
kernel/trace/rv/rv.c=550=static void disable_all_monitors(void)
--
kernel/trace/rv/rv.c-565- */
kernel/trace/rv/rv.c:566: tracepoint_synchronize_unregister();
kernel/trace/rv/rv.c-567- }
--
kernel/trace/rv/rv.c=710=static ssize_t monitoring_on_write_data(struct file *filp, const char __user *user_buf,
--
kernel/trace/rv/rv.c-730- */
kernel/trace/rv/rv.c:731: tracepoint_synchronize_unregister();
kernel/trace/rv/rv.c-732-
--
kernel/trace/rv/rv_reactors.c=373=static ssize_t reacting_on_write_data(struct file *filp, const char __user *user_buf,
--
kernel/trace/rv/rv_reactors.c-393- */
kernel/trace/rv/rv_reactors.c:394: tracepoint_synchronize_unregister();
kernel/trace/rv/rv_reactors.c-395-
--
kernel/trace/trace_eprobe.c=600=static int disable_eprobe(struct trace_eprobe *ep,
--
kernel/trace/trace_eprobe.c-629- /* Make sure nothing is using the edata or trigger */
kernel/trace/trace_eprobe.c:630: tracepoint_synchronize_unregister();
kernel/trace/trace_eprobe.c-631-
--
kernel/trace/trace_eprobe.c=699=static int disable_trace_eprobe(struct trace_event_call *call,
--
kernel/trace/trace_eprobe.c-727- * file == NULL and perf_trace_event_unreg() calls
kernel/trace/trace_eprobe.c:728: * tracepoint_synchronize_unregister() to ensure synchronize
kernel/trace/trace_eprobe.c-729- * event. We don't need to care about it.
--
kernel/trace/trace_event_perf.c=154=static void perf_trace_event_unreg(struct perf_event *p_event)
--
kernel/trace/trace_event_perf.c-167- */
kernel/trace/trace_event_perf.c:168: tracepoint_synchronize_unregister();
kernel/trace/trace_event_perf.c-169-
--
kernel/trace/trace_events.c=1203=static void __ftrace_clear_event_pids(struct trace_array *tr, int type)
--
kernel/trace/trace_events.c-1236- /* Wait till all users are no longer using pid filtering */
kernel/trace/trace_events.c:1237: tracepoint_synchronize_unregister();
kernel/trace/trace_events.c-1238-
--
kernel/trace/trace_events.c=2592=event_pid_write(struct file *filp, const char __user *ubuf,
--
kernel/trace/trace_events.c-2637- if (filtered_pids) {
kernel/trace/trace_events.c:2638: tracepoint_synchronize_unregister();
kernel/trace/trace_events.c-2639- trace_pid_list_free(filtered_pids);
--
kernel/trace/trace_events.c=4779=int event_trace_del_tracer(struct trace_array *tr)
--
kernel/trace/trace_events.c-4792- /* Make sure no more events are being executed */
kernel/trace/trace_events.c:4793: tracepoint_synchronize_unregister();
kernel/trace/trace_events.c-4794-
--
kernel/trace/trace_events_filter.c=1374=static void free_filter_list_tasks(struct rcu_head *rhp)
--
kernel/trace/trace_events_filter.c-1382-/*
kernel/trace/trace_events_filter.c:1383: * The tracepoint_synchronize_unregister() is a double rcu call.
kernel/trace/trace_events_filter.c-1384- * It calls synchronize_rcu_tasks_trace() followed by synchronize_rcu().
--
kernel/trace/trace_events_filter.c=1393=static void try_delay_free_filter(struct event_filter *filter)
--
kernel/trace/trace_events_filter.c-1416- /* Make sure the filter is not being used */
kernel/trace/trace_events_filter.c:1417: tracepoint_synchronize_unregister();
kernel/trace/trace_events_filter.c-1418- __free_filter(filter);
--
kernel/trace/trace_events_filter.c=1438=static void filter_free_subsystem_filters(struct trace_subsystem_dir *dir,
--
kernel/trace/trace_events_filter.c-1472- free_now:
kernel/trace/trace_events_filter.c:1473: tracepoint_synchronize_unregister();
kernel/trace/trace_events_filter.c-1474-
--
kernel/trace/trace_events_hist.c=6358=static void event_hist_trigger_free(struct event_trigger_data *data)
--
kernel/trace/trace_events_hist.c-6371-
kernel/trace/trace_events_hist.c:6372: tracepoint_synchronize_unregister();
kernel/trace/trace_events_hist.c-6373- remove_hist_vars(hist_data);
--
kernel/trace/trace_events_hist.c=6399=static void event_hist_trigger_named_free(struct event_trigger_data *data)
--
kernel/trace/trace_events_hist.c-6411- trigger_data_free(data);
kernel/trace/trace_events_hist.c:6412: tracepoint_synchronize_unregister();
kernel/trace/trace_events_hist.c-6413- kfree(cmd_ops);
--
kernel/trace/trace_events_hist.c=6417=static void hist_clear(struct event_trigger_data *data)
--
kernel/trace/trace_events_hist.c-6423-
kernel/trace/trace_events_hist.c:6424: tracepoint_synchronize_unregister();
kernel/trace/trace_events_hist.c-6425-
--
kernel/trace/trace_events_trigger.c=48=static void trigger_data_free_queued_locked(void)
--
kernel/trace/trace_events_trigger.c-58-
kernel/trace/trace_events_trigger.c:59: tracepoint_synchronize_unregister();
kernel/trace/trace_events_trigger.c-60-
--
kernel/trace/trace_events_trigger.c=66=static int trigger_kthread_fn(void *ignore)
--
kernel/trace/trace_events_trigger.c-81- /* make sure current triggers exit before free */
kernel/trace/trace_events_trigger.c:82: tracepoint_synchronize_unregister();
kernel/trace/trace_events_trigger.c-83-
--
kernel/trace/trace_events_trigger.c=1192=int set_trigger_filter(char *filter_str,
--
kernel/trace/trace_events_trigger.c-1238- if (system_state != SYSTEM_BOOTING)
kernel/trace/trace_events_trigger.c:1239: tracepoint_synchronize_unregister();
kernel/trace/trace_events_trigger.c-1240- free_event_filter(tmp);
--
kernel/trace/trace_fprobe.c=1503=static int disable_trace_fprobe(struct trace_event_call *call,
--
kernel/trace/trace_fprobe.c-1536- * file == NULL and perf_trace_event_unreg() calls
kernel/trace/trace_fprobe.c:1537: * tracepoint_synchronize_unregister() to ensure synchronize
kernel/trace/trace_fprobe.c-1538- * event. We don't need to care about it.
--
kernel/trace/trace_kprobe.c=416=static int disable_trace_kprobe(struct trace_event_call *call,
--
kernel/trace/trace_kprobe.c-441- * file == NULL and perf_trace_event_unreg() calls
kernel/trace/trace_kprobe.c:442: * tracepoint_synchronize_unregister() to ensure synchronize
kernel/trace/trace_kprobe.c-443- * event. We don't need to care about it.
--
mm/kasan/kasan_test_c.c=83=static void kasan_suite_exit(struct kunit_suite *suite)
--
mm/kasan/kasan_test_c.c-87- unregister_trace_console(probe_console, NULL);
mm/kasan/kasan_test_c.c:88: tracepoint_synchronize_unregister();
mm/kasan/kasan_test_c.c-89-}
--
mm/kfence/kfence_test.c=855=static void kfence_suite_exit(struct kunit_suite *suite)
--
mm/kfence/kfence_test.c-857- unregister_trace_console(probe_console, NULL);
mm/kfence/kfence_test.c:858: tracepoint_synchronize_unregister();
mm/kfence/kfence_test.c-859-}
--
mm/kmsan/kmsan_test.c=794=static void kmsan_suite_exit(struct kunit_suite *suite)
--
mm/kmsan/kmsan_test.c-796- unregister_trace_console(probe_console, NULL);
mm/kmsan/kmsan_test.c:797: tracepoint_synchronize_unregister();
mm/kmsan/kmsan_test.c-798- panic_on_kmsan = orig_panic_on_kmsan;
--
net/core/drop_monitor.c=1028=static void net_dm_hw_probe_unregister(const struct net_dm_alert_ops *ops)
--
net/core/drop_monitor.c-1030- unregister_trace_devlink_trap_report(ops->hw_trap_probe, NULL);
net/core/drop_monitor.c:1031: tracepoint_synchronize_unregister();
net/core/drop_monitor.c-1032-}
--
net/core/drop_monitor.c=1190=static void net_dm_trace_off_set(void)
--
net/core/drop_monitor.c-1199-
net/core/drop_monitor.c:1200: tracepoint_synchronize_unregister();
net/core/drop_monitor.c-1201-
]
|
| 151/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 37965
output: 19
thoughts: 4160
Thoughts: **Analysis of Blktrace Tracepoint Registration and Synchronization**
Okay, here's what I've been thinking through. First, I confirmed that `tracepoint_synchronize_unregister()` is indeed called within `blk_unregister_tracepoints()` and that it's good practice. Then I systematically reviewed the 18 tracepoints registered in `blk_register_tracepoints()` and double-checked the unregistering process to confirm the matching between the registration and unregistration. I verified that the unregistration occurs in reverse order, which makes perfect sense. Furthermore, I went through the registration process within `blk_register_tracepoints()`. I confirmed that `tracepoint_synchronize_unregister()` is only executed if any tracepoint was registered (and thus needs to be unregistered). If a registration fails, the execution jumps to `out` and does not call `tracepoint_synchronize_unregister()`.
Next, I looked at the change in `get_probe_ref()`. The core of the change is correct: we now properly handle the failure of `blk_register_tracepoints()` by decrementing the reference count if the registration fails. This ensures that a failed registration doesn't leave the probe reference count in an inconsistent state, causing the system to possibly attempt unregistration when nothing was actually registered. I carefully analyzed the multi-threaded aspect, verifying the locking mechanism and making certain that there are no race conditions by analyzing its implementation, specifically related to the mutex and reference count handling. The updated code maintains thread safety by decrementing the reference count when registration fails inside the mutex, which is precisely what is needed.
Finally, I checked all the call sites to `get_probe_ref()` and double-checked the blktrace initialization path. I identified the call sites to ensure that the tracepoint registration and unregistration paths are appropriately managed. I will now search through the rest of the kernel for any other occurrences of these functions for good measure.
|
| 152/4 |
2026/08/31 21:30 |
tool |
grepper |
0m
Args: map[Expression:get_probe_ref]
Results: map[Output:kernel/trace/blktrace.c=469=static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
--
kernel/trace/blktrace.c-487-
kernel/trace/blktrace.c:488:static void get_probe_ref(void)
kernel/trace/blktrace.c-489-{
--
kernel/trace/blktrace.c=730=static void blk_trace_setup_finalize(struct request_queue *q,
--
kernel/trace/blktrace.c-758- rcu_assign_pointer(q->blk_trace, bt);
kernel/trace/blktrace.c:759: get_probe_ref();
kernel/trace/blktrace.c-760-}
--
kernel/trace/blktrace.c=1900=static int blk_trace_setup_queue(struct request_queue *q,
--
kernel/trace/blktrace.c-1919- rcu_assign_pointer(q->blk_trace, bt);
kernel/trace/blktrace.c:1920: get_probe_ref();
kernel/trace/blktrace.c-1921- return 0;
]
|
| 153/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 42877
output: 19
thoughts: 20
Thoughts: Here's my summary, as I understand it:
**Digging Deeper into Teardown with `put_probe_ref`**
Okay, so we're looking at the teardown process, and to get a more comprehensive grasp of how everything's cleaned up, I think we need to examine the `put_probe_ref` function, too. I already have a handle on the main teardown procedures, but `put_probe_ref` likely handles a crucial piece of the puzzle, especially when dealing with probe references. It could be responsible for managing memory, releasing resources, or performing other cleanup actions specific to those references. Understanding its role will give me a more complete picture of the whole teardown mechanism. I'll need to see how it integrates with the rest of the teardown process to identify any potential gaps or areas for optimization.
|
| 154/4 |
2026/08/31 21:30 |
tool |
grepper |
0m
Args: map[Expression:put_probe_ref]
Results: map[Output:kernel/trace/blktrace.c=488=static void get_probe_ref(void)
--
kernel/trace/blktrace.c-495-
kernel/trace/blktrace.c:496:static void put_probe_ref(void)
kernel/trace/blktrace.c-497-{
--
kernel/trace/blktrace.c=535=static void blk_trace_cleanup(struct request_queue *q, struct blk_trace *bt)
--
kernel/trace/blktrace.c-539- blk_trace_free(q, bt);
kernel/trace/blktrace.c:540: put_probe_ref();
kernel/trace/blktrace.c-541-}
--
kernel/trace/blktrace.c=1880=static int blk_trace_remove_queue(struct request_queue *q)
--
kernel/trace/blktrace.c-1890-
kernel/trace/blktrace.c:1891: put_probe_ref();
kernel/trace/blktrace.c-1892- synchronize_rcu();
]
|
| 155/4 |
2026/08/31 21:30 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 43395
output: 75
thoughts: 59
Thoughts: Here's my analysis of what I'm thinking about, presented as you requested:
**Investigating Block Trace Removal Procedures**
Alright, I need to get a clear picture of the cleanup process involved when a block trace is removed. My focus is going to be on understanding the mechanics of `blk_trace_cleanup` and `blk_trace_remove_queue`. I know there are specific aspects of these functions that are critical to my work.
To make sure I'm getting the right picture, I'm going to jump into the code and focus on the regions around lines 530-570 and then jump to lines 1870-1930. These sections usually hold the core logic I'm interested in, based on my past experience with the codebase. I expect to find the handling of resources, data structures, and any specific considerations for removing a trace.
|
| 156/4 |
2026/08/31 21:31 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:530 LineCount:40]
Results: map[Contents: 530: relay_flush(bt->rchan);
531:
532: return 0;
533: }
534:
535: static void blk_trace_cleanup(struct request_queue *q, struct blk_trace *bt)
536: {
537: blk_trace_stop(bt);
538: synchronize_rcu();
539: blk_trace_free(q, bt);
540: put_probe_ref();
541: }
542:
543: static int __blk_trace_remove(struct request_queue *q)
544: {
545: struct blk_trace *bt;
546:
547: bt = rcu_replace_pointer(q->blk_trace, NULL,
548: lockdep_is_held(&q->debugfs_mutex));
549: if (!bt)
550: return -EINVAL;
551:
552: blk_trace_cleanup(q, bt);
553:
554: return 0;
555: }
556:
557: int blk_trace_remove(struct request_queue *q)
558: {
559: int ret;
560:
561: blk_debugfs_lock_nomemsave(q);
562: ret = __blk_trace_remove(q);
563: blk_debugfs_unlock_nomemrestore(q);
564:
565: return ret;
566: }
567: EXPORT_SYMBOL_GPL(blk_trace_remove);
568:
569: static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
]
|
| 157/4 |
2026/08/31 21:31 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1870 LineCount:60]
Results: map[Contents:1870: queue_work(trace_init_wq, &blktrace_works);
1871: } else {
1872: ret = __init_blk_tracer();
1873: }
1874:
1875: return ret;
1876: }
1877:
1878: device_initcall(init_blk_tracer);
1879:
1880: static int blk_trace_remove_queue(struct request_queue *q)
1881: {
1882: struct blk_trace *bt;
1883:
1884: bt = rcu_replace_pointer(q->blk_trace, NULL,
1885: lockdep_is_held(&q->debugfs_mutex));
1886: if (bt == NULL)
1887: return -EINVAL;
1888:
1889: blk_trace_stop(bt);
1890:
1891: put_probe_ref();
1892: synchronize_rcu();
1893: blk_trace_free(q, bt);
1894: return 0;
1895: }
1896:
1897: /*
1898: * Setup everything required to start tracing
1899: */
1900: static int blk_trace_setup_queue(struct request_queue *q,
1901: struct block_device *bdev)
1902: {
1903: struct blk_trace *bt = NULL;
1904: int ret = -ENOMEM;
1905:
1906: bt = kzalloc_obj(*bt);
1907: if (!bt)
1908: return -ENOMEM;
1909:
1910: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
1911: if (!bt->msg_data)
1912: goto free_bt;
1913:
1914: bt->dev = bdev->bd_dev;
1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
]
|
| 158/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 45040
output: 36
thoughts: 823
Thoughts: **Analyzing the `blk_trace_setup_queue` Function**
Okay, let's dive into how `blk_trace_setup_queue` actually functions. I need to understand its subtleties. First, I see the basic setup. A `blk_trace` struct is allocated and initialized, which includes allocation of per-CPU message data. The device and activity mask are set, and then `blk_trace_setup_lba` is called.
The critical part jumps out: the call to `get_probe_ref()` happens *before* the `rcu_assign_pointer(q->blk_trace, bt)`. Wait, is this order safe? If `get_probe_ref()` fails, `q->blk_trace` remains NULL. The code then jumps to `free_bt` and calls `blk_trace_free(q, bt)`. But is this sequence valid?
Ah, right! It *is* safe. Until `q->blk_trace` is assigned with `rcu_assign_pointer`, no block tracepoints will actually see the `blk_trace` structure. Even if probes *are* registered, the `rcu_dereference(rq->q->blk_trace)` will still evaluate to NULL, causing probes to exit early. This means that a failure in `get_probe_ref()` doesn't leak an uninitialized structure. Furthermore, the code cleanly frees `bt` via `blk_trace_free(q, bt)` if `get_probe_ref()` fails, which is exactly what we want. The `put_probe_ref()` call is *not* necessary here because the `get_probe_ref()` function handles restoring the reference count on failure.
Now, let's verify `blk_trace_free`. It's crucial that this function is safe to call on a potentially partially initialized `bt`. Let's look at that function directly.
Okay, inside `blk_trace_free`: the code calls `relay_close(bt->rchan)`. In our case, `bt->rchan` is NULL. This means that we need to confirm `relay_close` can handle a NULL argument. Then we have a `dir` member to deal with: if `bt->dir` is set, there's debugfs cleanup. However, in our context `bt->dir` is NULL. After that, we have `free_percpu(bt->sequence)` and `free_percpu(bt->msg_data)`. Finally, `kfree(bt)`. The per-cpu allocations are the crucial points.
Therefore, in `blk_trace_setup_queue`, `bt->rchan` is NULL, `bt->dir` is NULL, `bt->sequence` is NULL, and `bt->msg_data` is either allocated or NULL. So, the question remains: is `relay_close(NULL)` safe? I need to check the `relay_close` definition or references to verify this.
|
| 159/4 |
2026/08/31 21:31 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/trace/blktrace.c Name:relay_close]
Results: map[SourceCode: 643: /**
644: * relay_close - close the channel
645: * @chan: the channel
646: *
647: * Closes all channel buffers and frees the channel.
648: */
649: void relay_close(struct rchan *chan)
650: {
651: struct rchan_buf *buf;
652: unsigned int i;
653:
654: if (!chan)
655: return;
656:
657: mutex_lock(&relay_channels_mutex);
658: if (chan->is_global && (buf = *per_cpu_ptr(chan->buf, 0)))
659: relay_close_buf(buf);
660: else
661: for_each_possible_cpu(i)
662: if ((buf = *per_cpu_ptr(chan->buf, i)))
663: relay_close_buf(buf);
664:
665: list_del(&chan->list);
666: kref_put(&chan->kref, relay_destroy_channel);
667: mutex_unlock(&relay_channels_mutex);
668: }
SourceFile:kernel/relay.c]
|
| 160/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 46926
output: 38
thoughts: 2806
Thoughts: **Analysis of blktrace Setup and Cleanup**
Okay, so I've gone through the `blktrace` code to ensure everything is handled correctly, particularly regarding resource management. I've confirmed that `free_percpu(NULL)`, `kfree(NULL)`, and `relay_close(NULL)` are perfectly safe operations, as one would expect. Further, I've checked that `blk_trace_free(q, bt)` is already present and correctly used within `blk_trace_setup_queue()` at line 1924, specifically in the error path.
Now, the focus shifts to `blk_trace_setup_finalize()` and its callers. The logic within `blk_trace_setup_finalize()` itself appears sound; it populates the `blk_user_trace_setup2` structure, sets up trace parameters, and attempts to acquire a probe reference. The crucial aspect here is the RCU assignment of `q->blk_trace`. That will be important.
The next step is to examine the callers of `blk_trace_setup_finalize()`: `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`. I read through the code of each of the callers.
In the first case, `blk_trace_setup`, I am meticulously reviewing the error handling paths. Specifically, I see that if `blk_trace_setup_prepare` succeeds but `blk_trace_setup_finalize` fails, `blk_trace_free(q, bt)` *is* correctly called to clean up. The key is that the assignment to `q->blk_trace` hasn't happened yet, so `blk_trace_free` on that `bt` will be safe. If `copy_to_user` fails *after* `blk_trace_setup_finalize` has succeeded, which means `q->blk_trace` was already set, then `blk_trace_remove(q)` gets called. This is a crucial detail, as it ensures that if the setup appears to succeed, but the data copy to user fails, the trace is properly removed, including the decrementing of the probe reference.
I checked `blk_trace_setup2` and verified that `int ret;` is declared.
I also checked `compat_blk_trace_setup` and added the declaration.
Now, my attention is directed towards the `sysfs_blk_trace_attr_store` function (lines 2070-2160), which I need to check too.
|
| 161/4 |
2026/08/31 21:31 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:2070 LineCount:90]
Results: map[Contents:2070:
2071: static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
2072: struct device_attribute *attr,
2073: const char *buf, size_t count)
2074: {
2075: struct block_device *bdev = dev_to_bdev(dev);
2076: struct request_queue *q = bdev_get_queue(bdev);
2077: struct blk_trace *bt;
2078: unsigned int memflags;
2079: u64 value;
2080: ssize_t ret = -EINVAL;
2081:
2082: if (count == 0)
2083: goto out;
2084:
2085: if (attr == &dev_attr_act_mask) {
2086: if (kstrtoull(buf, 0, &value)) {
2087: /* Assume it is a list of trace category names */
2088: ret = blk_trace_str2mask(buf);
2089: if (ret < 0)
2090: goto out;
2091: value = ret;
2092: }
2093: } else {
2094: if (kstrtoull(buf, 0, &value))
2095: goto out;
2096: }
2097:
2098: memflags = blk_debugfs_lock(q);
2099:
2100: bt = rcu_dereference_protected(q->blk_trace,
2101: lockdep_is_held(&q->debugfs_mutex));
2102: if (attr == &dev_attr_enable) {
2103: if (!!value == !!bt) {
2104: ret = 0;
2105: goto out_unlock_bdev;
2106: }
2107: if (value)
2108: ret = blk_trace_setup_queue(q, bdev);
2109: else
2110: ret = blk_trace_remove_queue(q);
2111: goto out_unlock_bdev;
2112: }
2113:
2114: ret = 0;
2115: if (bt == NULL) {
2116: ret = blk_trace_setup_queue(q, bdev);
2117: bt = rcu_dereference_protected(q->blk_trace,
2118: lockdep_is_held(&q->debugfs_mutex));
2119: }
2120:
2121: if (ret == 0) {
2122: if (attr == &dev_attr_act_mask)
2123: bt->act_mask = value;
2124: else if (attr == &dev_attr_pid)
2125: bt->pid = value;
2126: else if (attr == &dev_attr_start_lba)
2127: bt->start_lba = value;
2128: else if (attr == &dev_attr_end_lba)
2129: bt->end_lba = value;
2130: }
2131:
2132: out_unlock_bdev:
2133: blk_debugfs_unlock(q, memflags);
2134: out:
2135: return ret ? ret : count;
2136: }
2137: #endif /* CONFIG_BLK_DEV_IO_TRACE */
2138:
2139: #ifdef CONFIG_EVENT_TRACING
2140:
2141: /**
2142: * blk_fill_rwbs - Fill the buffer rwbs by mapping op to character string.
2143: * @rwbs: buffer to be filled
2144: * @opf: request operation type (REQ_OP_XXX) and flags for the tracepoint
2145: *
2146: * Description:
2147: * Maps each request operation and flag to a single character and fills the
2148: * buffer provided by the caller with resulting string.
2149: *
2150: **/
2151: void blk_fill_rwbs(char *rwbs, blk_opf_t opf)
2152: {
2153: int i = 0;
2154:
2155: if (opf & REQ_PREFLUSH)
2156: rwbs[i++] = 'F';
2157:
2158: switch (opf & REQ_OP_MASK) {
2159: case REQ_OP_WRITE:
]
|
| 162/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 51647
output: 32
thoughts: 521
Thoughts: **Analyzing `sysfs_blk_trace_attr_store()` and the Crash Report**
Okay, let's break this down. I'm looking at `sysfs_blk_trace_attr_store()`, specifically the code path where `blk_trace_setup_queue()` is called. It's clear that the return value of `blk_trace_setup_queue()` is crucial, stored in `ret`. If `ret` is non-zero, indicating an error, the function should return that error. The critical observation here is that the function then returns this error.
The crash report confirms that the issue stems from within `blk_trace_setup_queue()`, specifically when it calls `blk_register_tracepoints()`. The trace indicates the crash happened at line 2116 where `blk_trace_setup_queue(q, bdev)` was called.
The `WARN_ON(ret)` at line 1332 within `blk_register_tracepoints()` is the smoking gun – it suggests a registration issue. I've got to find the root cause for this registration failure. Since `blk_trace_setup_queue()` calls `blk_register_tracepoints()` which is the root cause, I need to check where `blk_register_tracepoints` is called, and why this is failing.
|
| 163/4 |
2026/08/31 21:31 |
tool |
grepper |
0m
Args: map[Expression:register_trace PathPrefix:kernel/trace/blktrace.c]
Results: map[Output:kernel/trace/blktrace.c=61=static int blk_probes_ref;
kernel/trace/blktrace.c-62-
kernel/trace/blktrace.c:63:static void blk_register_tracepoints(void);
kernel/trace/blktrace.c:64:static void blk_unregister_tracepoints(void);
kernel/trace/blktrace.c-65-
--
kernel/trace/blktrace.c=488=static void get_probe_ref(void)
--
kernel/trace/blktrace.c-491- if (++blk_probes_ref == 1)
kernel/trace/blktrace.c:492: blk_register_tracepoints();
kernel/trace/blktrace.c-493- mutex_unlock(&blk_probe_mutex);
--
kernel/trace/blktrace.c=496=static void put_probe_ref(void)
--
kernel/trace/blktrace.c-499- if (!--blk_probes_ref)
kernel/trace/blktrace.c:500: blk_unregister_tracepoints();
kernel/trace/blktrace.c-501- mutex_unlock(&blk_probe_mutex);
--
kernel/trace/blktrace.c=1325=EXPORT_SYMBOL_GPL(blk_add_driver_data);
kernel/trace/blktrace.c-1326-
kernel/trace/blktrace.c:1327:static void blk_register_tracepoints(void)
kernel/trace/blktrace.c-1328-{
--
kernel/trace/blktrace.c-1330-
kernel/trace/blktrace.c:1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1332- WARN_ON(ret);
kernel/trace/blktrace.c:1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c-1334- WARN_ON(ret);
kernel/trace/blktrace.c:1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c-1336- WARN_ON(ret);
kernel/trace/blktrace.c:1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c-1338- WARN_ON(ret);
kernel/trace/blktrace.c:1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c-1340- WARN_ON(ret);
kernel/trace/blktrace.c:1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c-1342- WARN_ON(ret);
kernel/trace/blktrace.c:1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c-1344- WARN_ON(ret);
kernel/trace/blktrace.c:1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c-1346- WARN_ON(ret);
kernel/trace/blktrace.c:1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c-1348- WARN_ON(ret);
kernel/trace/blktrace.c:1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c-1350- WARN_ON(ret);
kernel/trace/blktrace.c:1351: ret = register_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1352- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c-1353- WARN_ON(ret);
kernel/trace/blktrace.c:1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
kernel/trace/blktrace.c-1355- NULL);
kernel/trace/blktrace.c-1356- WARN_ON(ret);
kernel/trace/blktrace.c:1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
kernel/trace/blktrace.c-1358- NULL);
kernel/trace/blktrace.c-1359- WARN_ON(ret);
kernel/trace/blktrace.c:1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c-1361- WARN_ON(ret);
kernel/trace/blktrace.c:1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c-1363- WARN_ON(ret);
kernel/trace/blktrace.c:1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c-1365- WARN_ON(ret);
kernel/trace/blktrace.c:1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c-1367- WARN_ON(ret);
kernel/trace/blktrace.c:1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c-1369- WARN_ON(ret);
--
kernel/trace/blktrace.c-1371-
kernel/trace/blktrace.c:1372:static void blk_unregister_tracepoints(void)
kernel/trace/blktrace.c-1373-{
kernel/trace/blktrace.c:1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c:1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c:1376: unregister_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c:1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c:1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c:1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
kernel/trace/blktrace.c:1380: unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
kernel/trace/blktrace.c:1381: unregister_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1382- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c:1383: unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c:1384: unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c:1385: unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c:1386: unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c:1387: unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c:1388: unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c:1389: unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c:1390: unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c:1391: unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c:1392: unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1393-
--
kernel/trace/blktrace.c=1839=static int __init __init_blk_tracer(void)
kernel/trace/blktrace.c-1840-{
kernel/trace/blktrace.c:1841: if (!register_trace_event(&trace_blk_event)) {
kernel/trace/blktrace.c-1842- pr_warn("Warning: could not register block events\n");
--
kernel/trace/blktrace.c-1845-
kernel/trace/blktrace.c:1846: if (register_tracer(&blk_tracer) != 0) {
kernel/trace/blktrace.c-1847- pr_warn("Warning: could not register the block tracer\n");
kernel/trace/blktrace.c:1848: unregister_trace_event(&trace_blk_event);
kernel/trace/blktrace.c-1849- return 1;
]
|
| 164/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 55196
output: 19
thoughts: 45
Thoughts: Okay, here's my thought process on this, presented as a first-person expert summary:
**Digging into Block Trace Calls**
Right, so I need to understand the scope of these `blk_trace` functions. My first instinct is to see how extensively they're being utilized within the codebase. I need to get a handle on all the call sites for things like `blk_trace_setup`, `blk_trace_remove`, and the other related functions. The goal here is a quick overview of how the tracing system is integrated.
Therefore, I'm going to kick off a search directly within the repository. Let's start with a broad search for `blk_trace_setup`. That will give me a baseline to work from; a kind of inventory of where this function is being called. From there, I can refine the search if necessary, looking for related calls or specific usage patterns. I'll take notes, of course, because this sort of thing requires keeping track of the details.
|
| 165/4 |
2026/08/31 21:31 |
tool |
grepper |
0m
Args: map[Expression:blk_trace_setup]
Results: map[Output:drivers/scsi/sg.c=914=sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp,
--
drivers/scsi/sg.c-1114- case BLKTRACESETUP:
drivers/scsi/sg.c:1115: return blk_trace_setup(sdp->device->request_queue, sdp->name,
drivers/scsi/sg.c-1116- MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
--
include/linux/blktrace_api.h=76=extern void blk_add_driver_data(struct request *rq, void *data, size_t len);
include/linux/blktrace_api.h:77:extern int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
include/linux/blktrace_api.h-78- struct block_device *bdev,
--
include/linux/blktrace_api.h=81=extern int blk_trace_remove(struct request_queue *q);
--
include/linux/blktrace_api.h-86-# define blk_add_driver_data(rq, data, len) do {} while (0)
include/linux/blktrace_api.h:87:# define blk_trace_setup(q, name, dev, bdev, arg) (-ENOTTY)
include/linux/blktrace_api.h-88-# define blk_trace_startstop(q, start) (-ENOTTY)
--
kernel/trace/blktrace.c=310=static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
--
kernel/trace/blktrace.c-397- * For sysfs-enabled tracing path (enabled via
kernel/trace/blktrace.c:398: * /sys/block/DEV/trace/enable), blk_trace_setup_queue()
kernel/trace/blktrace.c-399- * never initializes bt->version, leaving it 0 from
--
kernel/trace/blktrace.c=632=static const struct rchan_callbacks blk_relay_callbacks = {
--
kernel/trace/blktrace.c-636-
kernel/trace/blktrace.c:637:static void blk_trace_setup_lba(struct blk_trace *bt,
kernel/trace/blktrace.c-638- struct block_device *bdev)
--
kernel/trace/blktrace.c-651- */
kernel/trace/blktrace.c:652:static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
kernel/trace/blktrace.c-653- char *name, dev_t dev,
--
kernel/trace/blktrace.c-719-
kernel/trace/blktrace.c:720: blk_trace_setup_lba(bt, bdev);
kernel/trace/blktrace.c-721-
--
kernel/trace/blktrace.c-729-
kernel/trace/blktrace.c:730:static void blk_trace_setup_finalize(struct request_queue *q,
kernel/trace/blktrace.c-731- char *name, int version,
--
kernel/trace/blktrace.c-761-
kernel/trace/blktrace.c:762:int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
kernel/trace/blktrace.c-763- struct block_device *bdev,
--
kernel/trace/blktrace.c-788- memflags = blk_debugfs_lock(q);
kernel/trace/blktrace.c:789: bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
kernel/trace/blktrace.c-790- bdev);
--
kernel/trace/blktrace.c-794- }
kernel/trace/blktrace.c:795: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
kernel/trace/blktrace.c-796- strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
--
kernel/trace/blktrace.c-804-}
kernel/trace/blktrace.c:805:EXPORT_SYMBOL_GPL(blk_trace_setup);
kernel/trace/blktrace.c-806-
kernel/trace/blktrace.c:807:static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
kernel/trace/blktrace.c-808- struct block_device *bdev, char __user *arg)
--
kernel/trace/blktrace.c-823- memflags = blk_debugfs_lock(q);
kernel/trace/blktrace.c:824: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
kernel/trace/blktrace.c-825- bdev);
--
kernel/trace/blktrace.c-829- }
kernel/trace/blktrace.c:830: blk_trace_setup_finalize(q, name, 2, bt, &buts2);
kernel/trace/blktrace.c-831- blk_debugfs_unlock(q, memflags);
--
kernel/trace/blktrace.c-840-#if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
kernel/trace/blktrace.c:841:static int compat_blk_trace_setup(struct request_queue *q, char *name,
kernel/trace/blktrace.c-842- dev_t dev, struct block_device *bdev,
--
kernel/trace/blktrace.c-865- memflags = blk_debugfs_lock(q);
kernel/trace/blktrace.c:866: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
kernel/trace/blktrace.c-867- bdev);
--
kernel/trace/blktrace.c-871- }
kernel/trace/blktrace.c:872: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
kernel/trace/blktrace.c-873- blk_debugfs_unlock(q, memflags);
--
kernel/trace/blktrace.c=924=int blk_trace_ioctl(struct block_device *bdev, unsigned cmd, char __user *arg)
--
kernel/trace/blktrace.c-932- snprintf(b, sizeof(b), "%pg", bdev);
kernel/trace/blktrace.c:933: ret = blk_trace_setup2(q, b, bdev->bd_dev, bdev, arg);
kernel/trace/blktrace.c-934- break;
--
kernel/trace/blktrace.c-936- snprintf(b, sizeof(b), "%pg", bdev);
kernel/trace/blktrace.c:937: ret = blk_trace_setup(q, b, bdev->bd_dev, bdev, arg);
kernel/trace/blktrace.c-938- break;
--
kernel/trace/blktrace.c-941- snprintf(b, sizeof(b), "%pg", bdev);
kernel/trace/blktrace.c:942: ret = compat_blk_trace_setup(q, b, bdev->bd_dev, bdev, arg);
kernel/trace/blktrace.c-943- break;
--
kernel/trace/blktrace.c=1880=static int blk_trace_remove_queue(struct request_queue *q)
--
kernel/trace/blktrace.c-1899- */
kernel/trace/blktrace.c:1900:static int blk_trace_setup_queue(struct request_queue *q,
kernel/trace/blktrace.c-1901- struct block_device *bdev)
--
kernel/trace/blktrace.c-1916-
kernel/trace/blktrace.c:1917: blk_trace_setup_lba(bt, bdev);
kernel/trace/blktrace.c-1918-
--
kernel/trace/blktrace.c=2071=static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
--
kernel/trace/blktrace.c-2107- if (value)
kernel/trace/blktrace.c:2108: ret = blk_trace_setup_queue(q, bdev);
kernel/trace/blktrace.c-2109- else
--
kernel/trace/blktrace.c-2115- if (bt == NULL) {
kernel/trace/blktrace.c:2116: ret = blk_trace_setup_queue(q, bdev);
kernel/trace/blktrace.c-2117- bt = rcu_dereference_protected(q->blk_trace,
]
|
| 166/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 57920
output: 86
thoughts: 4257
Thoughts: **Analyzing Block Tracepoint Registration and Setup**
Alright, let's break this down. My primary concern here is ensuring the correctness and safety of the block tracepoint registration and setup process within the kernel. I've reviewed `blk_register_tracepoints()` and `blk_unregister_tracepoints()` meticulously. The core function, `blk_register_tracepoints()`, registers a series of tracepoints related to block I/O operations (request insertion, issue, merge, requeue, completion, bio operations, zone operations, etc.). The critical aspect is the error handling using `goto` statements. If a registration fails, the code *must* unregister any previously registered tracepoints in reverse order to maintain consistency and prevent leaks. The unwinding order of `unregister_*` functions is crucial, and a direct comparison shows a perfect match between registration and unregistration sequences.
I've confirmed the matching sequence of registration and unregistration. This is a common pattern, but it *must* be perfect to avoid issues.
Next, I examined `get_probe_ref()` and `blk_trace_setup_finalize()`. The use of a mutex (`blk_probe_mutex`) for reference counting (`blk_probes_ref`) ensures that the tracepoints are only registered when they're actually needed. The `get_probe_ref()` function increments this reference count and *conditionally* calls `blk_register_tracepoints()` only if the count goes from 0 to 1. The reverse happens in `put_probe_ref()`. The critical bit is the placement of `get_probe_ref()` *before* `rcu_assign_pointer(q->blk_trace, bt)`. I wanted to make sure that the tracepoints are active *before* the setup is considered complete. This ordering ensures that tracing is only enabled if the registration of tracepoints is successful. If `get_probe_ref()` fails (tracepoint registration fails), the device is never actually enabled and the trace setup is cleaned up.
Finally, I considered the various callers of `blk_trace_setup_finalize()`: `blk_trace_setup`, `blk_trace_setup2`, `compat_blk_trace_setup`, and `blk_trace_setup_queue`. All of these call paths appear to be sound and consistent with the intended design. They all follow the same pattern of setting up the tracing structure and then calling `blk_trace_setup_finalize()` to finalize the setup. They all handle errors correctly by cleaning up the allocated resources (most importantly, by calling `blk_trace_free()`). `blk_trace_setup_queue()` appears to be an internal setup which just directly creates a trace instance when creating a queue.
Overall, everything appears to be correct and well-handled. The checks and error handling are robust. The critical ordering of registration, reference counting, and assignment to the request queue all contribute to a clean and safe tracing mechanism.
|
| 167/4 |
2026/08/31 21:31 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static void blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void); NewCode:static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void); SourceFile:kernel/trace/blktrace.c]
Results:
|
| 168/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 62891
output: 37
thoughts: 39
Thoughts: Okay, here's my interpretation of those thoughts, presented as a personal thought process, as requested:
**Updating `get_probe_ref`**
Alright, time to dive into that `get_probe_ref` function, specifically lines 488-494. Before I make any changes, though, I always like to get a solid grasp of the surrounding context. So, let's take a quick look at the larger section, say from line 485 to 505. That should give me the necessary information to ensure any modifications I make are sound and don't introduce unexpected side effects within this critical piece of code. Context is king, as usual!
|
| 169/4 |
2026/08/31 21:31 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:485 LineCount:20]
Results: map[Contents: 485: kfree(bt);
486: }
487:
488: static void get_probe_ref(void)
489: {
490: mutex_lock(&blk_probe_mutex);
491: if (++blk_probes_ref == 1)
492: blk_register_tracepoints();
493: mutex_unlock(&blk_probe_mutex);
494: }
495:
496: static void put_probe_ref(void)
497: {
498: mutex_lock(&blk_probe_mutex);
499: if (!--blk_probes_ref)
500: blk_unregister_tracepoints();
501: mutex_unlock(&blk_probe_mutex);
502: }
503:
504: static int blk_trace_start(struct blk_trace *bt)
]
|
| 170/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 63389
output: 193
thoughts: 16
Thoughts: Here's my summary, as though I were thinking through the process:
**Refactoring `get_probe_ref` with `codeeditor`**
Okay, time to get this done. I need to make some changes to `get_probe_ref`, and the most efficient way is definitely going to be using `codeeditor`. It's my go-to for these kinds of edits, so I'll fire it up and get started. Let's see what needs to be changed and make this as seamless as possible. I'll make sure to double check any dependencies after this, as always.
|
| 171/4 |
2026/08/31 21:31 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static void get_probe_ref(void)
{
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1)
blk_register_tracepoints();
mutex_unlock(&blk_probe_mutex);
} NewCode:static int get_probe_ref(void)
{
int ret = 0;
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1) {
ret = blk_register_tracepoints();
if (ret)
blk_probes_ref--;
}
mutex_unlock(&blk_probe_mutex);
return ret;
} SourceFile:kernel/trace/blktrace.c]
Results:
|
| 172/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 63733
output: 74
thoughts: 60
Thoughts: Here's my summary, as though I'm thinking through this myself:
**Diving into Block Trace Setup**
Okay, time to dig into the trace setup code. I need to get a firm grasp on how this all works. Right now, I'm thinking I should start by examining `blk_trace_setup_finalize`, `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`. These seem like the core entry points, so understanding their interactions is key. Let's see...I'm going to pull up the source code and I'll focus on lines 730 to 885 with `read-file`. This should give me a solid chunk to work with and give me a good handle on how the initialization and finalization are handled.
|
| 173/4 |
2026/08/31 21:31 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:730 LineCount:80]
Results: map[Contents: 730: static void blk_trace_setup_finalize(struct request_queue *q,
731: char *name, int version,
732: struct blk_trace *bt,
733: struct blk_user_trace_setup2 *buts)
734:
735: {
736: strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
737:
738: /*
739: * some device names have larger paths - convert the slashes
740: * to underscores for this to work as expected
741: */
742: strreplace(buts->name, '/', '_');
743:
744: bt->version = version;
745: bt->act_mask = buts->act_mask;
746: if (!bt->act_mask)
747: bt->act_mask = (u16) -1;
748:
749: /* overwrite with user settings */
750: if (buts->start_lba)
751: bt->start_lba = buts->start_lba;
752: if (buts->end_lba)
753: bt->end_lba = buts->end_lba;
754:
755: bt->pid = buts->pid;
756: bt->trace_state = Blktrace_setup;
757:
758: rcu_assign_pointer(q->blk_trace, bt);
759: get_probe_ref();
760: }
761:
762: int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
763: struct block_device *bdev,
764: char __user *arg)
765: {
766: struct blk_user_trace_setup2 buts2;
767: struct blk_user_trace_setup buts;
768: struct blk_trace *bt;
769: unsigned int memflags;
770: int ret;
771:
772: ret = copy_from_user(&buts, arg, sizeof(buts));
773: if (ret)
774: return -EFAULT;
775:
776: if (!buts.buf_size || !buts.buf_nr)
777: return -EINVAL;
778:
779: buts2 = (struct blk_user_trace_setup2) {
780: .act_mask = buts.act_mask,
781: .buf_size = buts.buf_size,
782: .buf_nr = buts.buf_nr,
783: .start_lba = buts.start_lba,
784: .end_lba = buts.end_lba,
785: .pid = buts.pid,
786: };
787:
788: memflags = blk_debugfs_lock(q);
789: bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
790: bdev);
791: if (IS_ERR(bt)) {
792: blk_debugfs_unlock(q, memflags);
793: return PTR_ERR(bt);
794: }
795: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
796: strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
797: blk_debugfs_unlock(q, memflags);
798:
799: if (copy_to_user(arg, &buts, sizeof(buts))) {
800: blk_trace_remove(q);
801: return -EFAULT;
802: }
803: return 0;
804: }
805: EXPORT_SYMBOL_GPL(blk_trace_setup);
806:
807: static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
808: struct block_device *bdev, char __user *arg)
809: {
]
|
| 174/4 |
2026/08/31 21:31 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:810 LineCount:80]
Results: map[Contents: 810: struct blk_user_trace_setup2 buts2;
811: struct blk_trace *bt;
812: unsigned int memflags;
813:
814: if (copy_from_user(&buts2, arg, sizeof(buts2)))
815: return -EFAULT;
816:
817: if (!buts2.buf_size || !buts2.buf_nr)
818: return -EINVAL;
819:
820: if (buts2.flags != 0)
821: return -EINVAL;
822:
823: memflags = blk_debugfs_lock(q);
824: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
825: bdev);
826: if (IS_ERR(bt)) {
827: blk_debugfs_unlock(q, memflags);
828: return PTR_ERR(bt);
829: }
830: blk_trace_setup_finalize(q, name, 2, bt, &buts2);
831: blk_debugfs_unlock(q, memflags);
832:
833: if (copy_to_user(arg, &buts2, sizeof(buts2))) {
834: blk_trace_remove(q);
835: return -EFAULT;
836: }
837: return 0;
838: }
839:
840: #if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
841: static int compat_blk_trace_setup(struct request_queue *q, char *name,
842: dev_t dev, struct block_device *bdev,
843: char __user *arg)
844: {
845: struct blk_user_trace_setup2 buts2;
846: struct compat_blk_user_trace_setup cbuts;
847: struct blk_trace *bt;
848: unsigned int memflags;
849:
850: if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
851: return -EFAULT;
852:
853: if (!cbuts.buf_size || !cbuts.buf_nr)
854: return -EINVAL;
855:
856: buts2 = (struct blk_user_trace_setup2) {
857: .act_mask = cbuts.act_mask,
858: .buf_size = cbuts.buf_size,
859: .buf_nr = cbuts.buf_nr,
860: .start_lba = cbuts.start_lba,
861: .end_lba = cbuts.end_lba,
862: .pid = cbuts.pid,
863: };
864:
865: memflags = blk_debugfs_lock(q);
866: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
867: bdev);
868: if (IS_ERR(bt)) {
869: blk_debugfs_unlock(q, memflags);
870: return PTR_ERR(bt);
871: }
872: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
873: blk_debugfs_unlock(q, memflags);
874:
875: if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
876: blk_trace_remove(q);
877: return -EFAULT;
878: }
879:
880: return 0;
881: }
882: #endif
883:
884: static int __blk_trace_startstop(struct request_queue *q, int start)
885: {
886: struct blk_trace *bt;
887:
888: bt = rcu_dereference_protected(q->blk_trace,
889: lockdep_is_held(&q->debugfs_mutex));
]
|
| 175/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 66582
output: 640
thoughts: 1541
Thoughts: **Analyzing blk-trace Setup and Finalization**
Okay, let's dive into these functions. I'm focusing on `blk_trace_setup_finalize`, `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`. I see a clear sequence here, a common pattern that's worth noting.
First, I'm checking out `blk_trace_setup_finalize`. This function seems to be the core of the setup process. It takes a `request_queue`, a name, a version, a `blk_trace` structure, and a `blk_user_trace_setup2` structure. It copies the provided name into the `buts->name` field, crucially replacing any forward slashes with underscores. I know this is to avoid issues with some device names, which makes sense. Then, the version and activity mask (`act_mask`) are set in the `blk_trace` structure. If `act_mask` is zero, a default value of -1 (all bits set) is assigned, so it covers all requests. Next, user-provided values for `start_lba`, `end_lba`, and the process ID (`pid`) are applied. It also sets the state to `Blktrace_setup`. Crucially, there's a reference count managed via `get_probe_ref()`. The final step is assigning the `blk_trace` structure to the `request_queue`, using `rcu_assign_pointer`.
Now, looking at `blk_trace_setup`, this function seems to be the entry point for version 1. It calls `blk_debugfs_lock` to protect the critical sections. It calls `blk_trace_setup_prepare` which handles some of the pre-allocation tasks. It then calls `blk_trace_setup_finalize`. If there are any errors during `blk_trace_setup_finalize`, it cleans up any allocated resources before returning. After a successful finalize call, it copies the device name from the `buts2` structure back into the `buts` structure, and unlocks the debugfs.
Next, I'm examining `blk_trace_setup2`, which seems to be the entry point for version 2. It also acquires the debugfs lock and does some basic input validation on `buts2` (checking for valid `buf_size` and `buf_nr` values, and ensuring the `flags` field is zero). Then, it also calls `blk_trace_setup_prepare`, and ultimately `blk_trace_setup_finalize`. I can see the pattern is very similar, just the arguments have been passed differently. The main difference is the copying back of the `buts2` structure to the user space.
Finally, `compat_blk_trace_setup` handles compatibility with older versions, specifically for 64-bit systems. It receives a `compat_blk_user_trace_setup` structure. This function converts the old structure into the new `blk_user_trace_setup2` format. This looks like a shim, translating the old data format to the new one. The rest of this function's code flow is like the above two, `blk_trace_setup_prepare`, `blk_trace_setup_finalize`, then locking and unlocking debugfs. The `copy_to_user` here copies the device name back, and no additional fields.
So, the pattern is: lock, prepare, finalize, unlock, with appropriate error handling and resource cleanup throughout. The main job of these functions is to set up a `blk_trace` structure, assign it to a `request_queue`, and handle user-provided configuration.
|
| 176/4 |
2026/08/31 21:31 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static void blk_trace_setup_finalize(struct request_queue *q,
char *name, int version,
struct blk_trace *bt,
struct blk_user_trace_setup2 *buts)
{
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
* some device names have larger paths - convert the slashes
* to underscores for this to work as expected
*/
strreplace(buts->name, '/', '_');
bt->version = version;
bt->act_mask = buts->act_mask;
if (!bt->act_mask)
bt->act_mask = (u16) -1;
/* overwrite with user settings */
if (buts->start_lba)
bt->start_lba = buts->start_lba;
if (buts->end_lba)
bt->end_lba = buts->end_lba;
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
rcu_assign_pointer(q->blk_trace, bt);
get_probe_ref();
} NewCode:static int blk_trace_setup_finalize(struct request_queue *q,
char *name, int version,
struct blk_trace *bt,
struct blk_user_trace_setup2 *buts)
{
int ret;
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
* some device names have larger paths - convert the slashes
* to underscores for this to work as expected
*/
strreplace(buts->name, '/', '_');
bt->version = version;
bt->act_mask = buts->act_mask;
if (!bt->act_mask)
bt->act_mask = (u16) -1;
/* overwrite with user settings */
if (buts->start_lba)
bt->start_lba = buts->start_lba;
if (buts->end_lba)
bt->end_lba = buts->end_lba;
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
ret = get_probe_ref();
if (ret)
return ret;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
} SourceFile:kernel/trace/blktrace.c]
Results:
|
| 177/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 69563
output: 382
thoughts: 26
Thoughts: Here's my take on those thoughts, tailored for an expert like yourself:
**Refactoring Block Tracing Initialization**
Alright, let's get down to brass tacks. I'm focusing on the setup procedures for block tracing, specifically `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`. I see a potential for streamlining or consolidation here. I need to dive into the internals of these functions and understand their individual roles and overlapping functionality. My initial hunch is there's probably some redundant code, especially if we're dealing with older compatibility modes.
The key questions I'm asking myself are: Are there opportunities to avoid code duplication across these functions? Can I make the control flow easier to follow, maybe even eliminate the distinct '2' variant by merging it with the first one and incorporating all features in the core one? Does `compat_blk_trace_setup` still need to exist, or can its functionality be subsumed elsewhere, perhaps with a more elegant compatibility layer? I'll be paying close attention to any conditional logic dependent on specific kernel versions or configuration options, as that will drive any potential refactoring strategy. We want to clean this up, increase its performance and make it more manageable for future developments.
|
| 178/4 |
2026/08/31 21:31 |
tool |
codeeditor |
0m
Args: map[CurrentCode: memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
blk_trace_setup_finalize(q, name, 1, bt, &buts2);
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags); NewCode: memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags); SourceFile:kernel/trace/blktrace.c]
Results:
|
| 179/4 |
2026/08/31 21:31 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 70245
output: 1760
thoughts: 23
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Diving into blk_trace_setup2 and Compat Considerations**
Right, let's get down to brass tacks. I'm going to jump into `blk_trace_setup2` and `compat_blk_trace_setup`. These are the core functions for initializing and configuring block trace setups, and naturally, compatibility has to be a top concern. I need to refresh my memory on the interactions with the underlying trace infrastructure – specifically, how we handle the trace buffer, the filters, and the control mechanisms. There's a high probability I'll need to double check the differences between these versions, including any changes in data structures or argument passing, especially regarding the 'compat' aspects. Ensuring that the new version doesn't break the compatibility of the older version will be a priority. I'll need to carefully review how the user-space interface interacts, too. Specifically, I should look into the control files, the format of trace events, and the potential for any discrepancies across kernel versions. In the back of my mind, I'm already anticipating the typical race conditions and locking complexities in any tracing setup – the challenges in guaranteeing atomic updates, particularly when dealing with concurrent access from multiple CPUs or processes. I'm thinking about the potential need for read-copy-update (RCU) or other synchronization primitives. Time to grab the code and start digging!
|
| 180/4 |
2026/08/31 21:32 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct block_device *bdev, char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
if (!buts2.buf_size || !buts2.buf_nr)
return -EINVAL;
if (buts2.flags != 0)
return -EINVAL;
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
blk_trace_setup_finalize(q, name, 2, bt, &buts2);
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
#if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
static int compat_blk_trace_setup(struct request_queue *q, char *name,
dev_t dev, struct block_device *bdev,
char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
if (!cbuts.buf_size || !cbuts.buf_nr)
return -EINVAL;
buts2 = (struct blk_user_trace_setup2) {
.act_mask = cbuts.act_mask,
.buf_size = cbuts.buf_size,
.buf_nr = cbuts.buf_nr,
.start_lba = cbuts.start_lba,
.end_lba = cbuts.end_lba,
.pid = cbuts.pid,
};
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
blk_trace_setup_finalize(q, name, 1, bt, &buts2);
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
#endif NewCode:static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct block_device *bdev, char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
if (!buts2.buf_size || !buts2.buf_nr)
return -EINVAL;
if (buts2.flags != 0)
return -EINVAL;
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
#if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
static int compat_blk_trace_setup(struct request_queue *q, char *name,
dev_t dev, struct block_device *bdev,
char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
if (!cbuts.buf_size || !cbuts.buf_nr)
return -EINVAL;
buts2 = (struct blk_user_trace_setup2) {
.act_mask = cbuts.act_mask,
.buf_size = cbuts.buf_size,
.buf_nr = cbuts.buf_nr,
.start_lba = cbuts.start_lba,
.end_lba = cbuts.end_lba,
.pid = cbuts.pid,
};
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
#endif SourceFile:kernel/trace/blktrace.c]
Results:
|
| 181/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 72338
output: 38
thoughts: 44
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Analyzing `blk_register_tracepoints`**
Right, let's zero in on `blk_register_tracepoints`. Specifically, I'm going to jump to that function around line 1327. I want to get a good overview of what's happening there, so I'll quickly use `read-file` to get a look at the code block spanning lines 1325 to 1398. That should give me enough context to understand the surrounding logic and the core of what `blk_register_tracepoints` is doing. I need to refresh my memory on the interactions of those tracepoints within this module.
|
| 182/4 |
2026/08/31 21:32 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1325 LineCount:75]
Results: map[Contents:1325: EXPORT_SYMBOL_GPL(blk_add_driver_data);
1326:
1327: static void blk_register_tracepoints(void)
1328: {
1329: int ret;
1330:
1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1332: WARN_ON(ret);
1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1334: WARN_ON(ret);
1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1336: WARN_ON(ret);
1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1338: WARN_ON(ret);
1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1340: WARN_ON(ret);
1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1342: WARN_ON(ret);
1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1344: WARN_ON(ret);
1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1346: WARN_ON(ret);
1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1348: WARN_ON(ret);
1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
1350: WARN_ON(ret);
1351: ret = register_trace_blk_zone_append_update_request_bio(
1352: blk_add_trace_zone_update_request, NULL);
1353: WARN_ON(ret);
1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
1355: NULL);
1356: WARN_ON(ret);
1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
1358: NULL);
1359: WARN_ON(ret);
1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
1361: WARN_ON(ret);
1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
1363: WARN_ON(ret);
1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
1365: WARN_ON(ret);
1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1367: WARN_ON(ret);
1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1369: WARN_ON(ret);
1370: }
1371:
1372: static void blk_unregister_tracepoints(void)
1373: {
1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1376: unregister_trace_block_split(blk_add_trace_split, NULL);
1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
1380: unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
1381: unregister_trace_blk_zone_append_update_request_bio(
1382: blk_add_trace_zone_update_request, NULL);
1383: unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
1384: unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1385: unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1386: unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1387: unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1388: unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1389: unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1390: unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1391: unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1392: unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1393:
1394: tracepoint_synchronize_unregister();
1395: }
1396:
1397: /*
1398: * struct blk_io_tracer formatting routines
1399: */
]
|
| 183/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 74147
output: 2036
thoughts: 1777
Thoughts: **Analyzing Tracepoint Registration and Unregistration in blk_register_tracepoints**
Okay, let's dive into this `blk_register_tracepoints` function. My primary concern here is the integrity of the tracepoint system within the block layer, ensuring each registration has a corresponding unregistration, and that everything handles errors gracefully.
First, I'm noting the sequence of 18 tracepoint registrations. Each call, such as `register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL)`, has a corresponding conditional jump to an `out_` label if the registration fails. The `NULL` argument suggests these tracepoints are not associated with any specific data.
Now, the error handling is where the real interesting stuff is: The `out_` labels, `out_bio_remap`, `out_split`, etc. These form a cascade of unregistrations. If registration 18 fails, we jump to `out_bio_remap` and *first* unregister 17 and work back. Essentially, if *any* registration fails, the code ensures that *all* subsequent registrations are rolled back in reverse order, which is the correct pattern. `tracepoint_synchronize_unregister()` is called at the end, which is important to clean up properly.
It is critical that we have this error unwind logic. Without it, we could have a partially registered system, leaving us with a corrupted tracing state, which would be a nightmare to debug.
Finally, I'm checking the formatting. I've noted a few lines with long function names like `register_trace_blk_zone_append_update_request_bio()` and their unregister counterparts, which need to be checked against kernel style guidelines regarding line wrapping, to ensure readability.
The core logic appears sound, but a quick `codeeditor` edit would align any stylistic inconsistencies.
|
| 184/4 |
2026/08/31 21:32 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static void blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
WARN_ON(ret);
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
WARN_ON(ret);
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
WARN_ON(ret);
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
WARN_ON(ret);
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
WARN_ON(ret);
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
WARN_ON(ret);
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
WARN_ON(ret);
ret = register_trace_block_split(blk_add_trace_split, NULL);
WARN_ON(ret);
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
WARN_ON(ret);
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
WARN_ON(ret);
} NewCode:static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
if (ret)
goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
if (ret)
goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
if (ret)
goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
if (ret)
goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
if (ret)
goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
if (ret)
goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
if (ret)
goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
if (ret)
goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
if (ret)
goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
if (ret)
goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
if (ret)
goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
if (ret)
goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
if (ret)
goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
if (ret)
goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
if (ret)
goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
if (ret)
goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
if (ret)
goto out_bio_remap;
return 0;
out_bio_remap:
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
out_split:
unregister_trace_block_split(blk_add_trace_split, NULL);
out_unplug:
unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
out_plug:
unregister_trace_block_plug(blk_add_trace_plug, NULL);
out_zone_unplug:
unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
out_zone_plug:
unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
out_zone_update_request:
unregister_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
out_getrq:
unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
out_bio_queue:
unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
out_bio_frontmerge:
unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
out_bio_backmerge:
unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
out_bio_complete:
unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
out_rq_complete:
unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
out_rq_requeue:
unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
out_rq_merge:
unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
out_rq_issue:
unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
out_rq_insert:
unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
tracepoint_synchronize_unregister();
out:
return ret;
} SourceFile:kernel/trace/blktrace.c]
Results:
|
| 185/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 78370
output: 38
thoughts: 45
Thoughts: Here's my take on the thought process:
**Diving into `blk_trace_setup_queue`**
Okay, time to dig into the `blk_trace_setup_queue` function. Let's start by zeroing in on that area around line 1900. I'll use the `read-file` command, specifically pulling lines 1900 through 1930. This should give me a good, focused snippet to understand the core logic within that region of the code. I need a clear picture of what's happening there to proceed.
|
| 186/4 |
2026/08/31 21:32 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1945 LineCount:40]
Results: map[Contents:1945: static BLK_TRACE_DEVICE_ATTR(pid);
1946: static BLK_TRACE_DEVICE_ATTR(start_lba);
1947: static BLK_TRACE_DEVICE_ATTR(end_lba);
1948:
1949: static struct attribute *blk_trace_attrs[] = {
1950: &dev_attr_enable.attr,
1951: &dev_attr_act_mask.attr,
1952: &dev_attr_pid.attr,
1953: &dev_attr_start_lba.attr,
1954: &dev_attr_end_lba.attr,
1955: NULL
1956: };
1957:
1958: struct attribute_group blk_trace_attr_group = {
1959: .name = "trace",
1960: .attrs = blk_trace_attrs,
1961: };
1962:
1963: static const struct {
1964: int mask;
1965: const char *str;
1966: } mask_maps[] = {
1967: { BLK_TC_READ, "read" },
1968: { BLK_TC_WRITE, "write" },
1969: { BLK_TC_FLUSH, "flush" },
1970: { BLK_TC_SYNC, "sync" },
1971: { BLK_TC_QUEUE, "queue" },
1972: { BLK_TC_REQUEUE, "requeue" },
1973: { BLK_TC_ISSUE, "issue" },
1974: { BLK_TC_COMPLETE, "complete" },
1975: { BLK_TC_FS, "fs" },
1976: { BLK_TC_PC, "pc" },
1977: { BLK_TC_NOTIFY, "notify" },
1978: { BLK_TC_AHEAD, "ahead" },
1979: { BLK_TC_META, "meta" },
1980: { BLK_TC_DISCARD, "discard" },
1981: { BLK_TC_DRV_DATA, "drv_data" },
1982: { BLK_TC_FUA, "fua" },
1983: { BLK_TC_WRITE_ZEROES, "write-zeroes" },
1984: };
]
|
| 187/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 79291
output: 36
thoughts: 24
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Pinpointing `blk_trace_setup_queue`**
Okay, time to zero in on the exact location of `blk_trace_setup_queue`. Let's use `grepper` – it's the most efficient tool for this kind of precise code navigation within the kernel source. No need to mess around with `find` or `grep` iteratively. I'm after the direct hit, the line numbers, pronto. I need to get into the details quickly, and understand the calling context if necessary. `grepper` is the fastest way to get there. Now, let's see what it turns up.
|
| 188/4 |
2026/08/31 21:32 |
tool |
grepper |
0m
Args: map[Expression:blk_trace_setup_queue PathPrefix:kernel/trace/blktrace.c]
Results: map[Output:kernel/trace/blktrace.c=310=static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
--
kernel/trace/blktrace.c-397- * For sysfs-enabled tracing path (enabled via
kernel/trace/blktrace.c:398: * /sys/block/DEV/trace/enable), blk_trace_setup_queue()
kernel/trace/blktrace.c-399- * never initializes bt->version, leaving it 0 from
--
kernel/trace/blktrace.c=1880=static int blk_trace_remove_queue(struct request_queue *q)
--
kernel/trace/blktrace.c-1899- */
kernel/trace/blktrace.c:1900:static int blk_trace_setup_queue(struct request_queue *q,
kernel/trace/blktrace.c-1901- struct block_device *bdev)
--
kernel/trace/blktrace.c=2071=static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
--
kernel/trace/blktrace.c-2107- if (value)
kernel/trace/blktrace.c:2108: ret = blk_trace_setup_queue(q, bdev);
kernel/trace/blktrace.c-2109- else
--
kernel/trace/blktrace.c-2115- if (bt == NULL) {
kernel/trace/blktrace.c:2116: ret = blk_trace_setup_queue(q, bdev);
kernel/trace/blktrace.c-2117- bt = rcu_dereference_protected(q->blk_trace,
]
|
| 189/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 79965
output: 38
thoughts: 28
Thoughts: Here's a first-person summary, tailored as requested:
**Diving into `blktrace.c` - a Critical Section**
Okay, time to get my hands dirty and jump into the heart of `blktrace.c`. I'm going to focus specifically on lines 1935 through 1980. This usually indicates a crucial section, a block dealing with data collection, event handling, or potentially some core logic regarding tracing block I/O operations. Given my understanding of the kernel's tracing infrastructure, I'm anticipating that this section likely manages the interaction with the underlying block device driver or the queueing mechanism, or perhaps deals with how trace data is formatted before being written out. I'll need to pay close attention to the data structures involved – the `blktrace_dev`, `blktrace_percpu`, or whatever context is being maintained. This could be where the rubber meets the road in terms of performance impact; I'll be looking for any potential bottlenecks or areas that could introduce latency. Any use of spinlocks, mutexes, or atomic operations is immediately going to catch my eye. I'm especially keen on any conditional logic within this section, any "if" statements that could indicate how the trace data is handled in different situations. This is where the subtleties of the blktrace design will really come through. Let's see what gems are hidden in this code.
|
| 190/4 |
2026/08/31 21:32 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1935 LineCount:45]
Results: map[Contents:1935: static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
1936: struct device_attribute *attr,
1937: const char *buf, size_t count);
1938: #define BLK_TRACE_DEVICE_ATTR(_name) \
1939: DEVICE_ATTR(_name, S_IRUGO | S_IWUSR, \
1940: sysfs_blk_trace_attr_show, \
1941: sysfs_blk_trace_attr_store)
1942:
1943: static BLK_TRACE_DEVICE_ATTR(enable);
1944: static BLK_TRACE_DEVICE_ATTR(act_mask);
1945: static BLK_TRACE_DEVICE_ATTR(pid);
1946: static BLK_TRACE_DEVICE_ATTR(start_lba);
1947: static BLK_TRACE_DEVICE_ATTR(end_lba);
1948:
1949: static struct attribute *blk_trace_attrs[] = {
1950: &dev_attr_enable.attr,
1951: &dev_attr_act_mask.attr,
1952: &dev_attr_pid.attr,
1953: &dev_attr_start_lba.attr,
1954: &dev_attr_end_lba.attr,
1955: NULL
1956: };
1957:
1958: struct attribute_group blk_trace_attr_group = {
1959: .name = "trace",
1960: .attrs = blk_trace_attrs,
1961: };
1962:
1963: static const struct {
1964: int mask;
1965: const char *str;
1966: } mask_maps[] = {
1967: { BLK_TC_READ, "read" },
1968: { BLK_TC_WRITE, "write" },
1969: { BLK_TC_FLUSH, "flush" },
1970: { BLK_TC_SYNC, "sync" },
1971: { BLK_TC_QUEUE, "queue" },
1972: { BLK_TC_REQUEUE, "requeue" },
1973: { BLK_TC_ISSUE, "issue" },
1974: { BLK_TC_COMPLETE, "complete" },
1975: { BLK_TC_FS, "fs" },
1976: { BLK_TC_PC, "pc" },
1977: { BLK_TC_NOTIFY, "notify" },
1978: { BLK_TC_AHEAD, "ahead" },
1979: { BLK_TC_META, "meta" },
]
|
| 191/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 81128
output: 38
thoughts: 27
Thoughts: Here's my attempt at summarizing that thought process, tailored for an expert audience:
**Diving into `blk_trace_setup_queue`**
Okay, so I need to understand how the tracing infrastructure hooks into the block layer. Let's zero in on lines 1900 to 1935. The function `blk_trace_setup_queue` is probably the key here. It's almost certainly responsible for the initialization and configuration of tracing-related aspects for a specific block device queue. I'm guessing this function will handle setting up per-queue data structures, registering relevant tracepoints (if it's using the tracepoint infrastructure, which is highly likely given the context), and potentially managing filters or control mechanisms for event capture. It's also possible there's some interaction with the global tracing infrastructure here – registering the queue with a central manager, or perhaps initializing a specific per-queue buffer. I’ll need to look for calls to functions related to tracepoint registration, ring buffer allocation, or potentially even filter setup within that section of code to get a complete picture. This is where the real mechanics of event collection are defined and it should be an interesting area to investigate in detail.
|
| 192/4 |
2026/08/31 21:32 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1900 LineCount:35]
Results: map[Contents:1900: static int blk_trace_setup_queue(struct request_queue *q,
1901: struct block_device *bdev)
1902: {
1903: struct blk_trace *bt = NULL;
1904: int ret = -ENOMEM;
1905:
1906: bt = kzalloc_obj(*bt);
1907: if (!bt)
1908: return -ENOMEM;
1909:
1910: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
1911: if (!bt->msg_data)
1912: goto free_bt;
1913:
1914: bt->dev = bdev->bd_dev;
1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
1930: */
1931:
1932: static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
1933: struct device_attribute *attr,
1934: char *buf);
]
|
| 193/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 81931
output: 153
thoughts: 18
Thoughts: Here's my summary, as though I were thinking through the process:
**Diving into `blk_trace_setup_queue` with `codeeditor`**
Okay, time to get to work. I need to take a look at `blk_trace_setup_queue`. I'm going to fire up `codeeditor` and open that function. This is a critical function in the block tracing subsystem, so I need to be thorough. I'll need to understand how it's setting up the tracing queue itself. I'll be looking for how it handles memory allocation, initialization of the data structures, and how it interacts with the underlying block device or virtual block device structures. I'll have to pay very close attention to any locking mechanisms to ensure concurrency is properly handled. I know this code pretty well, so I'm expecting to see specific calls to the ring buffer implementation, likely calls to allocate the trace buffer. Also, I'll be focused on how tracing is enabled and disabled and how the setup function plays a role in configuring it. This should be interesting; let's get started.
|
| 194/4 |
2026/08/31 21:32 |
tool |
codeeditor |
0m
Args: map[CurrentCode: blk_trace_setup_lba(bt, bdev);
rcu_assign_pointer(q->blk_trace, bt);
get_probe_ref();
return 0;
free_bt: NewCode: blk_trace_setup_lba(bt, bdev);
ret = get_probe_ref();
if (ret)
goto free_bt;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
free_bt: SourceFile:kernel/trace/blktrace.c]
Results:
|
| 195/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 82341
output: 10
thoughts: 19
Thoughts: Okay, let's dive into it.
**My Analysis of the Current Code State**
Right, time to get a clear picture of the modifications I've implemented. My next step is to examine the output of `patch-diff`. This command will provide me with a comprehensive view of all the changes I've made up to this point, detailing every line added, removed, or modified. By carefully reviewing this diff, I'll be able to ensure the codebase is evolving as intended and that no unexpected regressions or unintended consequences have been introduced. This is a critical checkpoint for me.
|
| 196/4 |
2026/08/31 21:32 |
tool |
patch-diff |
0m
Error:
|
| 197/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 82510
output: 15
thoughts: 20
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing the `patch-diff` Strategy**
Alright, so I'm thinking about how to leverage `patch-diff` effectively here. The core idea is to understand the state of changes, and I'm considering a specific approach: calling `patch-diff` with a blank `File` parameter. The reasoning behind this is pretty straightforward: it's a quick way to get a consolidated overview of *all* the diffs present. Essentially, I want to see everything at once, like a global delta of the entire workspace. By giving an empty file parameter it becomes clear how to do this. I'm exploring the implications of using this approach. My goal is to understand how this can be implemented.
I'm mentally running through the edge cases and potential pitfalls.
|
| 198/4 |
2026/08/31 21:32 |
tool |
patch-diff |
0m
Args:
Results: map[Output:diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8cd2520b4..4e4f85a9f 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -53,21 +53,21 @@ static struct tracer_opt blk_tracer_opts[] = {
static struct tracer_flags blk_tracer_flags = {
.val = 0,
.opts = blk_tracer_opts,
};
/* Global reference count of probes */
static DEFINE_MUTEX(blk_probe_mutex);
static int blk_probes_ref;
-static void blk_register_tracepoints(void);
+static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
sector_t sector, int bytes, u64 what,
dev_t dev, int error, u64 cgid,
ssize_t cgid_len, void *pdu_data, int pdu_len)
{
/*
* These two are not needed in ftrace as they are in the
@@ -478,26 +478,32 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
debugfs_lookup_and_remove("dropped", q->debugfs_dir);
debugfs_lookup_and_remove("msg", q->debugfs_dir);
} else {
debugfs_remove(bt->dir);
}
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
}
-static void get_probe_ref(void)
+static int get_probe_ref(void)
{
+ int ret = 0;
+
mutex_lock(&blk_probe_mutex);
- if (++blk_probes_ref == 1)
- blk_register_tracepoints();
+ if (++blk_probes_ref == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ blk_probes_ref--;
+ }
mutex_unlock(&blk_probe_mutex);
+ return ret;
}
static void put_probe_ref(void)
{
mutex_lock(&blk_probe_mutex);
if (!--blk_probes_ref)
blk_unregister_tracepoints();
mutex_unlock(&blk_probe_mutex);
}
@@ -720,163 +726,186 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
blk_trace_setup_lba(bt, bdev);
return bt;
err:
blk_trace_free(q, bt);
return ERR_PTR(ret);
}
-static void blk_trace_setup_finalize(struct request_queue *q,
- char *name, int version,
- struct blk_trace *bt,
- struct blk_user_trace_setup2 *buts)
+static int blk_trace_setup_finalize(struct request_queue *q,
+ char *name, int version,
+ struct blk_trace *bt,
+ struct blk_user_trace_setup2 *buts)
{
+ int ret;
+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
* some device names have larger paths - convert the slashes
* to underscores for this to work as expected
*/
strreplace(buts->name, '/', '_');
bt->version = version;
bt->act_mask = buts->act_mask;
if (!bt->act_mask)
bt->act_mask = (u16) -1;
/* overwrite with user settings */
if (buts->start_lba)
bt->start_lba = buts->start_lba;
if (buts->end_lba)
bt->end_lba = buts->end_lba;
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ ret = get_probe_ref();
+ if (ret)
+ return ret;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
+ return 0;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
struct block_device *bdev,
char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct blk_user_trace_setup buts;
struct blk_trace *bt;
unsigned int memflags;
int ret;
ret = copy_from_user(&buts, arg, sizeof(buts));
if (ret)
return -EFAULT;
if (!buts.buf_size || !buts.buf_nr)
return -EINVAL;
buts2 = (struct blk_user_trace_setup2) {
.act_mask = buts.act_mask,
.buf_size = buts.buf_size,
.buf_nr = buts.buf_nr,
.start_lba = buts.start_lba,
.end_lba = buts.end_lba,
.pid = buts.pid,
};
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts, sizeof(buts))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
EXPORT_SYMBOL_GPL(blk_trace_setup);
static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
- struct block_device *bdev, char __user *arg)
+ struct block_device *bdev, char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
if (!buts2.buf_size || !buts2.buf_nr)
return -EINVAL;
if (buts2.flags != 0)
return -EINVAL;
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
#if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
static int compat_blk_trace_setup(struct request_queue *q, char *name,
dev_t dev, struct block_device *bdev,
char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
if (!cbuts.buf_size || !cbuts.buf_nr)
return -EINVAL;
buts2 = (struct blk_user_trace_setup2) {
.act_mask = cbuts.act_mask,
.buf_size = cbuts.buf_size,
.buf_nr = cbuts.buf_nr,
.start_lba = cbuts.start_lba,
.end_lba = cbuts.end_lba,
.pid = cbuts.pid,
};
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
#endif
@@ -1317,63 +1346,122 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len)
return;
}
__blk_add_trace(bt, blk_rq_trace_sector(rq), blk_rq_bytes(rq), 0,
BLK_TA_DRV_DATA, 0, len, data,
blk_trace_request_get_cgid(rq));
rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static void blk_register_tracepoints(void)
+static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_remap;
+
+ return 0;
+
+out_bio_remap:
+ unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
+out_split:
+ unregister_trace_block_split(blk_add_trace_split, NULL);
+out_unplug:
+ unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
+out_plug:
+ unregister_trace_block_plug(blk_add_trace_plug, NULL);
+out_zone_unplug:
+ unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
+out_zone_plug:
+ unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
+out_zone_update_request:
+ unregister_trace_blk_zone_append_update_request_bio(
+ blk_add_trace_zone_update_request, NULL);
+out_getrq:
+ unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
+out_bio_queue:
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
+out_bio_frontmerge:
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
+out_bio_backmerge:
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
+out_bio_complete:
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
+out_rq_complete:
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
+out_rq_requeue:
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
+out_rq_merge:
+ unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
+out_rq_issue:
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
+out_rq_insert:
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
+ tracepoint_synchronize_unregister();
+out:
+ return ret;
}
static void blk_unregister_tracepoints(void)
{
unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
unregister_trace_block_split(blk_add_trace_split, NULL);
unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
unregister_trace_block_plug(blk_add_trace_plug, NULL);
unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
@@ -1897,34 +1985,37 @@ static int blk_trace_remove_queue(struct request_queue *q)
/*
* Setup everything required to start tracing
*/
static int blk_trace_setup_queue(struct request_queue *q,
struct block_device *bdev)
{
struct blk_trace *bt = NULL;
int ret = -ENOMEM;
bt = kzalloc_obj(*bt);
if (!bt)
return -ENOMEM;
bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
if (!bt->msg_data)
goto free_bt;
bt->dev = bdev->bd_dev;
bt->act_mask = (u16)-1;
blk_trace_setup_lba(bt, bdev);
+ ret = get_probe_ref();
+ if (ret)
+ goto free_bt;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
return 0;
free_bt:
blk_trace_free(q, bt);
return ret;
}
/*
* sysfs interface to enable and configure tracing
*/
]
|
| 199/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 87931
output: 122
thoughts: 116
Thoughts: **Fixing a Minor Indentation Quirk in Block Trace Setup**
Alright, let's take a look at this `blk_trace_setup2` function. Specifically, I need to make a quick adjustment on line 808. There's a subtle indentation inconsistency there that's bugging me. I mean, it's probably just spaces versus tabs, but consistency is key, especially in something as critical as the block layer. I want to ensure the formatting aligns perfectly with the established style in this code base. Let's get the indentation sorted out to match the original formatting. I'll fire up the code editor and make that minor tweak. A little cleanup goes a long way.
|
| 200/4 |
2026/08/31 21:32 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct block_device *bdev, char __user *arg) NewCode:static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct block_device *bdev, char __user *arg) SourceFile:kernel/trace/blktrace.c]
Results:
|
| 201/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 88323
output: 24
thoughts: 11
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert and adopting a first-person perspective:
**Checking That Diff Again...**
Alright, time to revisit that `patch-diff`. I remember going over it, but there's a nagging feeling, a little doubt whispering in the back of my mind. It's that subtle sense you get when you've reviewed something, but you haven't quite *felt* it sink in completely. I need to make absolutely sure everything there aligns with my understanding and the overall architecture we're working with. This project's intricacies demand that level of rigor. Let's make sure there aren't any potential edge cases that I missed on the first pass. No point in pushing something upstream without having absolute confidence. Deep breath, and let's dive back in.
|
| 202/4 |
2026/08/31 21:32 |
tool |
patch-diff |
0m
Args: map[File:kernel/trace/blktrace.c]
Results: map[Output:diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8cd2520b4..c2324298c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -53,21 +53,21 @@ static struct tracer_opt blk_tracer_opts[] = {
static struct tracer_flags blk_tracer_flags = {
.val = 0,
.opts = blk_tracer_opts,
};
/* Global reference count of probes */
static DEFINE_MUTEX(blk_probe_mutex);
static int blk_probes_ref;
-static void blk_register_tracepoints(void);
+static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
sector_t sector, int bytes, u64 what,
dev_t dev, int error, u64 cgid,
ssize_t cgid_len, void *pdu_data, int pdu_len)
{
/*
* These two are not needed in ftrace as they are in the
@@ -478,26 +478,32 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
debugfs_lookup_and_remove("dropped", q->debugfs_dir);
debugfs_lookup_and_remove("msg", q->debugfs_dir);
} else {
debugfs_remove(bt->dir);
}
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
}
-static void get_probe_ref(void)
+static int get_probe_ref(void)
{
+ int ret = 0;
+
mutex_lock(&blk_probe_mutex);
- if (++blk_probes_ref == 1)
- blk_register_tracepoints();
+ if (++blk_probes_ref == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ blk_probes_ref--;
+ }
mutex_unlock(&blk_probe_mutex);
+ return ret;
}
static void put_probe_ref(void)
{
mutex_lock(&blk_probe_mutex);
if (!--blk_probes_ref)
blk_unregister_tracepoints();
mutex_unlock(&blk_probe_mutex);
}
@@ -720,163 +726,186 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
blk_trace_setup_lba(bt, bdev);
return bt;
err:
blk_trace_free(q, bt);
return ERR_PTR(ret);
}
-static void blk_trace_setup_finalize(struct request_queue *q,
- char *name, int version,
- struct blk_trace *bt,
- struct blk_user_trace_setup2 *buts)
+static int blk_trace_setup_finalize(struct request_queue *q,
+ char *name, int version,
+ struct blk_trace *bt,
+ struct blk_user_trace_setup2 *buts)
{
+ int ret;
+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
* some device names have larger paths - convert the slashes
* to underscores for this to work as expected
*/
strreplace(buts->name, '/', '_');
bt->version = version;
bt->act_mask = buts->act_mask;
if (!bt->act_mask)
bt->act_mask = (u16) -1;
/* overwrite with user settings */
if (buts->start_lba)
bt->start_lba = buts->start_lba;
if (buts->end_lba)
bt->end_lba = buts->end_lba;
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ ret = get_probe_ref();
+ if (ret)
+ return ret;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
+ return 0;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
struct block_device *bdev,
char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct blk_user_trace_setup buts;
struct blk_trace *bt;
unsigned int memflags;
int ret;
ret = copy_from_user(&buts, arg, sizeof(buts));
if (ret)
return -EFAULT;
if (!buts.buf_size || !buts.buf_nr)
return -EINVAL;
buts2 = (struct blk_user_trace_setup2) {
.act_mask = buts.act_mask,
.buf_size = buts.buf_size,
.buf_nr = buts.buf_nr,
.start_lba = buts.start_lba,
.end_lba = buts.end_lba,
.pid = buts.pid,
};
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts, sizeof(buts))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
EXPORT_SYMBOL_GPL(blk_trace_setup);
static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct block_device *bdev, char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
if (!buts2.buf_size || !buts2.buf_nr)
return -EINVAL;
if (buts2.flags != 0)
return -EINVAL;
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
#if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
static int compat_blk_trace_setup(struct request_queue *q, char *name,
dev_t dev, struct block_device *bdev,
char __user *arg)
{
struct blk_user_trace_setup2 buts2;
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
if (!cbuts.buf_size || !cbuts.buf_nr)
return -EINVAL;
buts2 = (struct blk_user_trace_setup2) {
.act_mask = cbuts.act_mask,
.buf_size = cbuts.buf_size,
.buf_nr = cbuts.buf_nr,
.start_lba = cbuts.start_lba,
.end_lba = cbuts.end_lba,
.pid = cbuts.pid,
};
memflags = blk_debugfs_lock(q);
bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
blk_trace_remove(q);
return -EFAULT;
}
return 0;
}
#endif
@@ -1317,63 +1346,122 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len)
return;
}
__blk_add_trace(bt, blk_rq_trace_sector(rq), blk_rq_bytes(rq), 0,
BLK_TA_DRV_DATA, 0, len, data,
blk_trace_request_get_cgid(rq));
rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static void blk_register_tracepoints(void)
+static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_remap;
+
+ return 0;
+
+out_bio_remap:
+ unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
+out_split:
+ unregister_trace_block_split(blk_add_trace_split, NULL);
+out_unplug:
+ unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
+out_plug:
+ unregister_trace_block_plug(blk_add_trace_plug, NULL);
+out_zone_unplug:
+ unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
+out_zone_plug:
+ unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
+out_zone_update_request:
+ unregister_trace_blk_zone_append_update_request_bio(
+ blk_add_trace_zone_update_request, NULL);
+out_getrq:
+ unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
+out_bio_queue:
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
+out_bio_frontmerge:
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
+out_bio_backmerge:
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
+out_bio_complete:
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
+out_rq_complete:
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
+out_rq_requeue:
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
+out_rq_merge:
+ unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
+out_rq_issue:
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
+out_rq_insert:
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
+ tracepoint_synchronize_unregister();
+out:
+ return ret;
}
static void blk_unregister_tracepoints(void)
{
unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
unregister_trace_block_split(blk_add_trace_split, NULL);
unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
unregister_trace_block_plug(blk_add_trace_plug, NULL);
unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
@@ -1897,34 +1985,37 @@ static int blk_trace_remove_queue(struct request_queue *q)
/*
* Setup everything required to start tracing
*/
static int blk_trace_setup_queue(struct request_queue *q,
struct block_device *bdev)
{
struct blk_trace *bt = NULL;
int ret = -ENOMEM;
bt = kzalloc_obj(*bt);
if (!bt)
return -ENOMEM;
bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
if (!bt->msg_data)
goto free_bt;
bt->dev = bdev->bd_dev;
bt->act_mask = (u16)-1;
blk_trace_setup_lba(bt, bdev);
+ ret = get_probe_ref();
+ if (ret)
+ goto free_bt;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
return 0;
free_bt:
blk_trace_free(q, bt);
return ret;
}
/*
* sysfs interface to enable and configure tracing
*/
]
|
| 203/4 |
2026/08/31 21:32 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 93729
output: 514
thoughts: 502
Thoughts: **Reviewing the Tracepoint Registration Logic**
Okay, let's break this down. I've got a diff in front of me, and I need to ensure it's sound. I'm focusing on how the tracepoints are registered and de-registered, making sure everything is handled correctly, especially error paths.
First, there's a forward declaration: `static int blk_register_tracepoints(void);`. Simple enough, sets the stage.
Then there's `get_probe_ref()`. This seems critical – it returns an integer. Inside, I see it increments `blk_probes_ref`. If that increment results in 1, it calls `blk_register_tracepoints()`. If that call returns non-zero, it decrements the reference count and returns. This seems like it's managing a reference count for the tracepoints, only registering them when the count hits 1. Clever.
`blk_trace_setup_finalize()` then follows. It too returns an integer. It *calls* `get_probe_ref()` before it assigns `q->blk_trace = bt` and if it fails, immediately returns. I see how this is architected. It is using `get_probe_ref()` to safely acquire the tracepoint resources, only proceeding to setup the trace itself if the refcount increment succeeds.
Now I see the callers of `blk_trace_setup_finalize()` – `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`. They all check the return value and upon error, they call `blk_trace_free(q, bt)`, unlock the debugfs mutex, and return the error code. Clean and predictable error handling here.
Next, I look at `blk_register_tracepoints()`. It returns an integer and checks the return values of each `register_trace_*()` call. If any of those fail, it uses a `goto` to unwind the registrations in reverse order, calls `tracepoint_synchronize_unregister()`, and returns the error code. This demonstrates that there are a number of tracepoints, and they are handled as a single unit with complete undo capability.
Finally, I see `blk_trace_setup_queue()` which makes a call to `get_probe_ref()`. If it has a failure, it jumps to `free_bt:` and returns. Only if it succeeds it assigns `q->blk_trace = bt` and returns 0. So, again, that same `get_probe_ref()` is being used to acquire the tracepoint resources.
Alright, after this careful review, it is all looking clean and solid. It adheres to kernel conventions, and seems to be a complete fix. I see the flow, the reference counting, the error handling, and the registration/unregistration.
|
| 204/3 |
2026/08/31 21:32 |
action |
test-patch |
23m
Results: map[PatchDiff:diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8cd2520b4..c2324298c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -60,7 +60,7 @@ static struct tracer_flags blk_tracer_flags = {
static DEFINE_MUTEX(blk_probe_mutex);
static int blk_probes_ref;
-static void blk_register_tracepoints(void);
+static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
@@ -485,12 +485,18 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
kfree(bt);
}
-static void get_probe_ref(void)
+static int get_probe_ref(void)
{
+ int ret = 0;
+
mutex_lock(&blk_probe_mutex);
- if (++blk_probes_ref == 1)
- blk_register_tracepoints();
+ if (++blk_probes_ref == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ blk_probes_ref--;
+ }
mutex_unlock(&blk_probe_mutex);
+ return ret;
}
static void put_probe_ref(void)
@@ -727,12 +733,14 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
return ERR_PTR(ret);
}
-static void blk_trace_setup_finalize(struct request_queue *q,
- char *name, int version,
- struct blk_trace *bt,
- struct blk_user_trace_setup2 *buts)
+static int blk_trace_setup_finalize(struct request_queue *q,
+ char *name, int version,
+ struct blk_trace *bt,
+ struct blk_user_trace_setup2 *buts)
{
+ int ret;
+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
@@ -755,8 +763,12 @@ static void blk_trace_setup_finalize(struct request_queue *q,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ ret = get_probe_ref();
+ if (ret)
+ return ret;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
+ return 0;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
@@ -792,7 +804,12 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags);
@@ -810,6 +827,7 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
@@ -827,7 +845,12 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
@@ -846,6 +869,7 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
@@ -869,7 +893,12 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
@@ -1324,49 +1353,108 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len)
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static void blk_register_tracepoints(void)
+static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_remap;
+
+ return 0;
+
+out_bio_remap:
+ unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
+out_split:
+ unregister_trace_block_split(blk_add_trace_split, NULL);
+out_unplug:
+ unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
+out_plug:
+ unregister_trace_block_plug(blk_add_trace_plug, NULL);
+out_zone_unplug:
+ unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
+out_zone_plug:
+ unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
+out_zone_update_request:
+ unregister_trace_blk_zone_append_update_request_bio(
+ blk_add_trace_zone_update_request, NULL);
+out_getrq:
+ unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
+out_bio_queue:
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
+out_bio_frontmerge:
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
+out_bio_backmerge:
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
+out_bio_complete:
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
+out_rq_complete:
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
+out_rq_requeue:
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
+out_rq_merge:
+ unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
+out_rq_issue:
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
+out_rq_insert:
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
+ tracepoint_synchronize_unregister();
+out:
+ return ret;
}
static void blk_unregister_tracepoints(void)
@@ -1916,8 +2004,11 @@ static int blk_trace_setup_queue(struct request_queue *q,
blk_trace_setup_lba(bt, bdev);
+ ret = get_probe_ref();
+ if (ret)
+ goto free_bt;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
return 0;
free_bt:
TestError:]
|
| 205/3 |
2026/08/31 21:56 |
action |
If |
1m
Args:
|
| 206/4 |
2026/08/31 21:56 |
agent |
patch-reviewer |
1m
Model:
Results: map[ReviewApproved:true ReviewComments:[]]
Instruction: You are an experienced Linux kernel maintainer reviewing a proposed patch that compiles and passes reproducer tests.
Evaluate the patch diff against the crash report, root cause, and the architectural design guidelines below.
Scope Constraint (Single-Patch Submissions):
We only generate single, standalone patches (not patch series). If a comprehensive architectural redesign would require a multi-patch series touching many files, accept a localized single-patch fix as long as it correctly fixes the bug, does not introduce new issues, and avoids sentinel band-aids within its local scope.
Evaluation:
- Set ReviewApproved=true (and leave ReviewComments empty) if the patch is acceptable for upstream submission as a single-patch fix.
- Set ReviewApproved=false and list concise, actionable feedback in ReviewComments if the patch contains fixable "Kernel Architectural Design & Maintainer Taste" violations.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
---
# Kernel Architectural Design & Maintainer Taste
Evaluate kernel patches and fix proposals beyond binary bug presence. Enforce **maintainer taste**, **lifecycle symmetry**, **typestate soundness**, and **topological graph simplicity**.
---
## 1. Core Philosophy: Band-Aid vs. Architectural Design
Naive patches often introduce **defensive sentinel guards** (e.g., ad-hoc `if (!ptr) return;` checks, status flags, or suppressed warnings) directly at the point of failure. While locally avoiding crashes, they degrade subsystem architecture by leaving uninitialized states reachable.
Maintainer "good taste" solves the root cause by **shifting invariants** (making invalid states unrepresentable) and moving dynamic runtime checks into static typestate guarantees.
```
HACKY BAND-AID FIX (Monolithic Cleanup) ARCHITECTURAL DESIGN (Scoped RAII / Invariant Shift)
─────────────────────────────────────── ────────────────────────────────────────────────────
[ Init / Entry ] [ Init / Entry ]
│ │
(Register Global Cleanup) (Allocate Resource A)
│ │
[ Init Sub-B ] ──fail──┐ [ Init Sub-B ] ──fail──┐
│ (success) │ │ (success) │
▼ │ ▼ ▼
[ Setup Complete ] │ (Arm B Cleanup / RAII) (Unwind A Only:
│ │ │ B never armed)
(Deferred Teardown) │ ▼ │
│ │ [ Setup Complete ] ▼
▼ ▼ │ [ Error Exit ]
[ release_all ] ◄───────┘ (LIFO Scope Teardown)
│ │
(if (!ctx->b) return;) <-- Defensive guard! ▼
│ [ Clean Destruction ]
[ Unsafe State ] (Zero sentinel checks needed)
```
```c
// ANTI-PATTERN (Defensive Sentinel Guard): Teardown called on partial init -> callee needs guard
void driver_cleanup(struct ctx *ctx) {
if (!ctx->buf) return; // <-- Sentinel band-aid
free_buffer(ctx->buf);
}
// CANONICAL SHIFT (Granular Scoped Action): Registered only upon complete initialization
ctx->buf = alloc_buffer();
if (!ctx->buf) return -ENOMEM;
devm_add_action_or_reset(dev, free_buffer_action, ctx->buf);
```
---
## 2. Maintainer Taste as Graph Topology & Structural Simplicity
Software design quality maps directly to graph-theoretic properties across the Control-Flow Graph (CFG), Data-Flow Graph (DFG), and Object Lifecycle DAG:
### A. Control-Flow Graph (CFG) Simplification
* **Branch Minimization & Path Explosion (McCabe 1976):** Every defensive check added to a compound destructor or callback (`if (!ctx->buffer) return;`) adds a predicate node ($\pi$), increases cyclomatic complexity $v(G) = |E| - |V| + 2$, causes exponential path explosion ($O(2^k)$ paths), and enlarges explicit state spaces ($|S| = \prod |D_i|$). Good taste eliminates the branch by guaranteeing destructors are invoked only on initialized typestates. *(Note: Standard idempotent leaf deallocators like `kfree(NULL)` and public API input sanitizers are exempt).*
* **Single-Entry Single-Exit (SESE) Symmetry (Ferrante 1987, Johnson 1994, Dijkstra 1972):** Resource acquisition and release must form strict **nested dominator trees**. If resource $R_i$ is acquired at node $A$, the set of release actions $\{B_1, \dots, B_m\}$ must form a strict **post-dominating cut** relative to $A$ across all maximal exit paths.
* **Pointer Uniformity (Linus's "Good Taste" Rule):** Eliminate special-case conditional branches by operating on address indirection (e.g., indirect pointers `**curr` in linked list unlinking) to unify edge and interior cases into a branchless invariant.
* **Lexical Scope Invariants & Affine Lifecycles (Wadler 1990, RAII):** Enforce SESE symmetry and "consumed exactly once" affine invariants using compiler-backed scoped cleanup (`<linux/cleanup.h>` `guard()`, `scoped_guard()`, `__free()`).
### B. Ownership & Lifetime DAGs
* **Acyclic Lifecycles & Topological Teardown (Tarjan 1972, Kahn 1962):** Resource ownership must form a strict Directed Acyclic Graph (DAG) $G = (R, E)$. Teardown order must strictly follow reverse topological sort $\text{toposort}(G)^R$. Mixing conflicting lifetime paradigms (e.g., embedding a dynamic refcounted `kref`/socket struct inside a device-managed `devres` buffer or parent container) violates DAG acyclicity, creating synchronous blocking hacks (`wait_for_completion`), circular pins, and Use-After-Free hazards.
* **Three-Phase Concurrent Quiescence:** Multi-threaded and asynchronous teardown (networking, block layer, RCU) must strictly sequence: (1) **Deactivation/Delisting** (make unreachable) -> (2) **Quiescence & Draining** (`synchronize_rcu()`, `cancel_work_sync()`, `napi_disable()`) -> (3) **Physical Reclamation** (`kfree()`, `kmem_cache_destroy()`).
* **Typestate Validity (Strom & Yemini 1986, Aldrich et al. 2009):** A struct with $N$ fields should not use runtime boolean flags (`ctx->is_initialized`) to model incomplete typestates. Sub-resources must transition as a deterministic typestate automaton ($S_{uninit} \xrightarrow{\text{alloc}} S_{init} \xrightarrow{\text{publish}} S_{registered}$), and registration functions must accept only fully initialized typestates.
---
## 3. Deterministic Decision Trigger Matrix
| Code Symptom / Trigger (When you see X) | Anti-Pattern Band-Aid (DO NOT DO Z) | Canonical Invariant Shift (DO Y) |
| :--- | :--- | :--- |
| **Null deref in compound destructor / cleanup callback** | Add `if (!priv->buf) return;` in composite cleanup handler | Register granular cleanup immediately upon allocation via `devm_add_action_or_reset()`, `<linux/cleanup.h>` `__free()`, or discrete reverse LIFO labels |
| **UAF on dynamic object after container unbind** | Allocate with `devm_kzalloc()` and block on `wait_for_completion()` | Allocate with `kzalloc()`, manage lifetime via `kref_get()`/`kref_put()`, call unbind/delist on unbind, free in `kref` release callback |
| **Goto ladder lock leaks on early error exit** | Sprinkle manual `mutex_unlock()` across error returns | Use `guard(mutex)(&lock)` or `scoped_guard(spinlock, &lock)` from `<linux/cleanup.h>` |
| **Callback / IRQ / timer fires before full init** | Add `if (!priv->ready)` check inside IRQ/timer handler | Move `request_irq()`, `timer_setup()`, or `napi_enable()` strictly to the end of setup after all state structures are fully initialized |
| **Multi-step setup failure leaks resources** | Route all errors to a single `err:` label calling a monolithic `cleanup(priv)` with NULL checks | Use `cleanup.h` RAII, granular `devm` actions, or a strict reverse LIFO goto ladder (`err_free_b:` -> `err_free_a:`) |
| **Mixed ownership / asymmetric refcount drops** | Conditionally call `kref_put()` in caller based on error code | Enforce unconditional callee-cleans or caller-cleans ownership convention across all paths |
| **Ad-hoc state flag polling during teardown** | Add `priv->stopping = true` and spin/poll in callbacks | Use atomic typestate transitions and synchronous flush/drain APIs (`cancel_work_sync()`, `drain_workqueue()`) |
---
## 4. The Architectural Review Checklist
Before finalizing any kernel fix or review, audit against the following four criteria:
1. **The Sentinel Test (Caller vs. Callee Responsibility):**
* *Smell:* Adding a defensive guard (`if (!ptr)` or `if (flags & INITIALIZED)`) inside a compound teardown callback or destructor to mask partial initialization.
* *Invariant:* If a destructor executes on uninitialized data, the defect is at the **caller's registration/invocation point**, not the callee.
* *Note:* Standard C allocator no-ops (`kfree(NULL)`) and public API parameter validators (`if (WARN_ON(!ptr)) return -EINVAL;`) are exempt; this rule targets *internal subsystem lifecycle pipelines and teardown paths*.
* *Action:* Move registration to the point of complete initialization (`devm_add_action_or_reset()`, RAII/`__free()`, or discrete caller unwinding).
2. **LIFO Stack Unwinding Symmetry:**
* *Smell:* Releasing resources in arbitrary order or invoking destructors for partially initialized subsystems.
* *Invariant:* Resource release must strictly mirror acquisition order in reverse (LIFO) without monolithic cleanup guards.
* *Action:* Verify that partial setup/initialization failures (e.g., `probe()`, `mount()`, `open()`, `alloc_pool()`) unwind only already-allocated resources in reverse order via strict LIFO labels or `cleanup.h` scope exit.
3. **Ownership Decoupling:**
* *Smell:* Embedding dynamically refcounted objects (`kref`, `struct sock`, `struct inode`, `struct file`) directly inside hardware device-bound allocations (`devres`) or parent containers (`super_block`, `net_device`).
* *Invariant:* Dynamic consumer references must outlive parent unregistration without use-after-free, circular pins, or blocking hacks.
* *Action:* Decouple the refcounted core object from the container binding; container teardown must unbind/delist the object, but memory is freed exclusively by the final `kref_put()`.
4. **Codebase Idiom Alignment:**
* *Smell:* Using legacy custom rollback ladders, ad-hoc state flags, or manual lock unlocking on error paths.
* *Invariant:* Prefer standard, modern kernel abstractions with compiler-enforced safety guarantees.
* *Action (Modern >= 6.6):* Replace manual boilerplate with `cleanup.h` (`guard()`, `scoped_guard()`, `__free()`), `devm_add_action_or_reset()`, `refcount_t`, and standard `kref` helpers.
* *Action (Legacy / LTS / No-RAII Subsystems):* Enforce clean, branchless reverse LIFO goto ladders (`err_free_b:` -> `err_free_a:`).
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
Bug title:
WARNING in get_probe_ref
The crash report:
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
------------[ cut here ]------------
ret
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline], CPU#1: syz.0.17/6119
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492, CPU#1: syz.0.17/6119
Modules linked in:
CPU: 1 UID: 0 PID: 6119 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Code: c3 31 ff 89 c6 e8 39 42 f7 ff 85 db 0f 85 00 01 00 00 e8 2c 3d f7 ff 48 c7 c7 00 7f bd 8e 5b e9 af 77 db 09 e8 1a 3d f7 ff 90 <0f> 0b 90 e9 e8 fc ff ff e8 0c 3d f7 ff 90 0f 0b 90 e9 07 fd ff ff
RSP: 0018:ffffc9000355fb10 EFLAGS: 00010293
RAX: ffffffff81ce06d6 RBX: 00000000fffffff4 RCX: ffff888114150000
RDX: 0000000000000000 RSI: 00000000fffffff4 RDI: 0000000000000000
RBP: ffffc9000355fc40 R08: ffffc9000355fa47 R09: 1ffff920006abf48
R10: dffffc0000000000 R11: fffff520006abf49 R12: ffff88810888c508
R13: dffffc0000000000 R14: ffff888103f8c638 R15: 0000000000002000
FS: 00007fc861b426c0(0000) GS:ffff8882e873e000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2ed24008 CR3: 00000001fdd32000 CR4: 0000000000352ef0
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc860b9e159
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fc861b42028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fc860e25fa0 RCX: 00007fc860b9e159
RDX: 0000000000000081 RSI: 00002000000002c0 RDI: 0000000000000003
RBP: 00007fc861b42090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
The root cause explanation:
The root cause of the crash is that `blk_register_tracepoints()` uses `WARN_ON(ret)` to check the return values of `register_trace_block_*()` functions. These tracepoint registration functions allocate memory for the probe array and can fail with `-ENOMEM` (e.g., under memory pressure or fault injection, as seen in the syzbot report). When they fail, `WARN_ON()` triggers a kernel panic if `panic_on_warn` is set.
Furthermore, `blk_register_tracepoints()` currently ignores the error and continues, leaving the tracepoints in a partially registered state. Later, when tracing is stopped, `blk_unregister_tracepoints()` unconditionally unregisters all tracepoints. Unregistering a tracepoint that was not successfully registered causes `tracepoint_remove_func()` to return `-ENOENT`, which triggers another `WARN_ON_ONCE` inside `tracepoint_remove_func()`.
To fix this, we need to properly handle the registration failures by returning the error, unregistering the successfully registered tracepoints, and propagating the error up the call stack to fail the blktrace setup.
### Fix Details
1. **Change `blk_register_tracepoints()` to return an `int` and handle errors:**
Instead of `WARN_ON(ret)`, check the return value of each `register_trace_*()` call. If it fails, use `goto` labels to unregister the successfully registered tracepoints in reverse order, and return the error.
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
return ret;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
if (ret)
goto err_issue;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
if (ret)
goto err_merge;
// ... (do this for all 18 tracepoints) ...
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
if (ret)
goto err_rq_remap;
return 0;
err_rq_remap:
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
// ... (unregister labels in reverse order) ...
err_merge:
unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
err_issue:
unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
return ret;
}
```
2. **Propagate the error through `get_probe_ref()`:**
```c
static int get_probe_ref(void)
{
int ret = 0;
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1) {
ret = blk_register_tracepoints();
if (ret)
blk_probes_ref--;
}
mutex_unlock(&blk_probe_mutex);
return ret;
}
```
3. **Propagate the error through `blk_trace_setup_finalize()`:**
```c
static int blk_trace_setup_finalize(struct request_queue *q,
char *name, int version,
struct blk_trace *bt,
struct blk_user_trace_setup2 *buts)
{
int ret;
// ... existing code ...
bt->trace_state = Blktrace_setup;
ret = get_probe_ref();
if (ret)
return ret;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
}
```
4. **Handle the error in the callers of `blk_trace_setup_finalize()`:**
In `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, check the return value of `blk_trace_setup_finalize()`. If it fails, clean up the allocated `bt` and return the error:
```c
ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
```
5. **Handle the error in `blk_trace_setup_queue()`:**
```c
static int blk_trace_setup_queue(struct request_queue *q,
struct block_device *bdev)
{
// ... existing code ...
blk_trace_setup_lba(bt, bdev);
ret = get_probe_ref();
if (ret)
goto free_bt;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
free_bt:
blk_trace_free(q, bt);
return ret;
}
```
The proposed patch diff:
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8cd2520b4..c2324298c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -60,7 +60,7 @@ static struct tracer_flags blk_tracer_flags = {
static DEFINE_MUTEX(blk_probe_mutex);
static int blk_probes_ref;
-static void blk_register_tracepoints(void);
+static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
@@ -485,12 +485,18 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
kfree(bt);
}
-static void get_probe_ref(void)
+static int get_probe_ref(void)
{
+ int ret = 0;
+
mutex_lock(&blk_probe_mutex);
- if (++blk_probes_ref == 1)
- blk_register_tracepoints();
+ if (++blk_probes_ref == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ blk_probes_ref--;
+ }
mutex_unlock(&blk_probe_mutex);
+ return ret;
}
static void put_probe_ref(void)
@@ -727,12 +733,14 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
return ERR_PTR(ret);
}
-static void blk_trace_setup_finalize(struct request_queue *q,
- char *name, int version,
- struct blk_trace *bt,
- struct blk_user_trace_setup2 *buts)
+static int blk_trace_setup_finalize(struct request_queue *q,
+ char *name, int version,
+ struct blk_trace *bt,
+ struct blk_user_trace_setup2 *buts)
{
+ int ret;
+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
@@ -755,8 +763,12 @@ static void blk_trace_setup_finalize(struct request_queue *q,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ ret = get_probe_ref();
+ if (ret)
+ return ret;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
+ return 0;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
@@ -792,7 +804,12 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags);
@@ -810,6 +827,7 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
@@ -827,7 +845,12 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
@@ -846,6 +869,7 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
@@ -869,7 +893,12 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
@@ -1324,49 +1353,108 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len)
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static void blk_register_tracepoints(void)
+static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_remap;
+
+ return 0;
+
+out_bio_remap:
+ unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
+out_split:
+ unregister_trace_block_split(blk_add_trace_split, NULL);
+out_unplug:
+ unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
+out_plug:
+ unregister_trace_block_plug(blk_add_trace_plug, NULL);
+out_zone_unplug:
+ unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
+out_zone_plug:
+ unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
+out_zone_update_request:
+ unregister_trace_blk_zone_append_update_request_bio(
+ blk_add_trace_zone_update_request, NULL);
+out_getrq:
+ unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
+out_bio_queue:
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
+out_bio_frontmerge:
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
+out_bio_backmerge:
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
+out_bio_complete:
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
+out_rq_complete:
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
+out_rq_requeue:
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
+out_rq_merge:
+ unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
+out_rq_issue:
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
+out_rq_insert:
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
+ tracepoint_synchronize_unregister();
+out:
+ return ret;
}
static void blk_unregister_tracepoints(void)
@@ -1916,8 +2004,11 @@ static int blk_trace_setup_queue(struct request_queue *q,
blk_trace_setup_lba(bt, bdev);
+ ret = get_probe_ref();
+ if (ret)
+ goto free_bt;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
return 0;
free_bt:
Review this patch diff against the crash report, root cause explanation, and kernel architectural design guidelines.
|
| 207/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 13242
output: 37
thoughts: 128
Thoughts: **Analyzing the Patch for Block Trace Issues**
Okay, let's dive in. I need to understand this patch thoroughly, especially in light of the crash report, the identified root cause, and the existing guidelines. My approach is to be meticulous.
First, I'm going to zero in on the kernel source, specifically `kernel/trace/blktrace.c`. I need to understand the architecture, so I'll be looking closely at how `blk_register_tracepoints`, `get_probe_ref`, `put_probe_ref`, `blk_trace_setup_finalize`, and `blk_trace_setup_queue` are implemented and, more importantly, how they interact. I want to see how the block tracing functionality is structured and where potential weaknesses lie.
I'll be using my standard tools – I'll probably start with a `read-file` command to quickly get an overview, then drill down with something like `codesearch-definition-source` to jump directly to the relevant definitions and usage sites. I want a concrete understanding of the surrounding code and how this patch potentially modifies the critical path. My goal is to determine if the changes address the root cause effectively and if they adhere to the best practices for the kernel's tracing subsystem. This means a careful review of reference counting, initialization, and de-initialization sequences.
|
| 208/5 |
2026/08/31 21:56 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:480 LineCount:50]
Results: map[Contents: 480: } else {
481: debugfs_remove(bt->dir);
482: }
483: free_percpu(bt->sequence);
484: free_percpu(bt->msg_data);
485: kfree(bt);
486: }
487:
488: static void get_probe_ref(void)
489: {
490: mutex_lock(&blk_probe_mutex);
491: if (++blk_probes_ref == 1)
492: blk_register_tracepoints();
493: mutex_unlock(&blk_probe_mutex);
494: }
495:
496: static void put_probe_ref(void)
497: {
498: mutex_lock(&blk_probe_mutex);
499: if (!--blk_probes_ref)
500: blk_unregister_tracepoints();
501: mutex_unlock(&blk_probe_mutex);
502: }
503:
504: static int blk_trace_start(struct blk_trace *bt)
505: {
506: if (bt->trace_state != Blktrace_setup &&
507: bt->trace_state != Blktrace_stopped)
508: return -EINVAL;
509:
510: blktrace_seq++;
511: smp_mb();
512: bt->trace_state = Blktrace_running;
513: raw_spin_lock_irq(&running_trace_lock);
514: list_add(&bt->running_list, &running_trace_list);
515: raw_spin_unlock_irq(&running_trace_lock);
516: trace_note_time(bt);
517:
518: return 0;
519: }
520:
521: static int blk_trace_stop(struct blk_trace *bt)
522: {
523: if (bt->trace_state != Blktrace_running)
524: return -EINVAL;
525:
526: bt->trace_state = Blktrace_stopped;
527: raw_spin_lock_irq(&running_trace_lock);
528: list_del_init(&bt->running_list);
529: raw_spin_unlock_irq(&running_trace_lock);
]
|
| 209/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 14417
output: 52
thoughts: 96
Thoughts: **Analyzing Block Trace References**
Okay, let's dive into this. My initial focus will be to meticulously map out the usage of `get_probe_ref` and `put_probe_ref` within the block trace implementation, specifically the `blktrace.c` file. I need to understand how these reference counting functions are being used, and if there are any potential race conditions or locking issues that I can identify.
I will also carefully examine the surrounding setup and finalization routines – `blk_trace_setup_finalize`, `blk_trace_setup_queue`, `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup` – to get a complete picture. Understanding the complete call stack and how these functions are intertwined is vital. The interaction between probe reference management, and the trace setup and teardown process is key.
My first step is to perform a targeted search for `get_probe_ref` within `kernel/trace/blktrace.c`. This will establish the initial baseline, and from there I can assess each call-site within its context.
|
| 210/5 |
2026/08/31 21:56 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:kernel/trace/blktrace.c IncludeSnippetLines:10 Name:get_probe_ref SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:blk_trace_setup_finalize SourceFile:kernel/trace/blktrace.c SourceLine:759 SourceSnippet: 749: /* overwrite with user settings */
750: if (buts->start_lba)
751: bt->start_lba = buts->start_lba;
752: if (buts->end_lba)
753: bt->end_lba = buts->end_lba;
754:
755: bt->pid = buts->pid;
756: bt->trace_state = Blktrace_setup;
757:
758: rcu_assign_pointer(q->blk_trace, bt);
759: get_probe_ref();
760: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:blk_trace_setup_queue SourceFile:kernel/trace/blktrace.c SourceLine:1920 SourceSnippet:1910: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
1911: if (!bt->msg_data)
1912: goto free_bt;
1913:
1914: bt->dev = bdev->bd_dev;
1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
]] TruncatedOutput:false]
|
| 211/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 15360
output: 52
thoughts: 15
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating `put_probe_ref` Usage**
Okay, so we're diving deeper into this issue. I've already explored the immediate context, but now I need a broader view. My primary concern is to ensure a comprehensive understanding of how `put_probe_ref` is being used throughout the codebase. I need to track down all the callers of this function. This isn't just about the direct calls, but also how the return values are being handled and what assumptions are being made based on those returns. Essentially, I'm thinking, "Let's track all the places that could possibly have any impact." The more complete the review, the greater my confidence level.
|
| 212/5 |
2026/08/31 21:56 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:kernel/trace/blktrace.c IncludeSnippetLines:10 Name:put_probe_ref SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:blk_trace_cleanup SourceFile:kernel/trace/blktrace.c SourceLine:540 SourceSnippet: 535: static void blk_trace_cleanup(struct request_queue *q, struct blk_trace *bt)
536: {
537: blk_trace_stop(bt);
538: synchronize_rcu();
539: blk_trace_free(q, bt);
540: put_probe_ref();
541: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:blk_trace_remove_queue SourceFile:kernel/trace/blktrace.c SourceLine:1891 SourceSnippet:1881: {
1882: struct blk_trace *bt;
1883:
1884: bt = rcu_replace_pointer(q->blk_trace, NULL,
1885: lockdep_is_held(&q->debugfs_mutex));
1886: if (bt == NULL)
1887: return -EINVAL;
1888:
1889: blk_trace_stop(bt);
1890:
1891: put_probe_ref();
1892: synchronize_rcu();
1893: blk_trace_free(q, bt);
1894: return 0;
1895: }
]] TruncatedOutput:false]
|
| 213/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 16022
output: 37
thoughts: 83
Thoughts: Here's my take on the kernel tracing setup, thinking as an expert:
**Diving Deep into Block Trace Initialization**
Alright, let's get down to brass tacks. I need to understand the initialization sequence for `blktrace`. Time to revisit `kernel/trace/blktrace.c`. Specifically, I'm going to walk through the critical functions managing the setup process. I'll need to dissect the interaction between `blk_trace_setup_prepare`, `blk_trace_setup_finalize`, and the core `blk_trace_setup` and `blk_trace_setup2` functions. I know there's likely some pre/post-processing happening there, and I want to see exactly how the tracing infrastructure is prepared and finalized.
The compatibility layer, `compat_blk_trace_setup`, is another area of focus. I'll need to understand how it handles older trace setups, ensuring forward compatibility. A likely look will be how it handles data structures and configuration differences.
I'm also paying close attention to the tracepoint registration and unregistration logic: `blk_register_tracepoints` and `blk_unregister_tracepoints`. These functions are central to defining the tracing events. I need to see how they interact with the overall trace infrastructure and how the appropriate hooks are installed and removed in the relevant kernel subsystems. A careful review will be crucial to avoiding any race conditions or resource leaks.
Finally, the queue-specific setup, `blk_trace_setup_queue`, is a must. This is where the tracing is hooked into the block layer's queue management, and the devil is in the details, especially around how the tracing contexts are associated with specific block devices and queues. I'll be looking for how the per-queue data structures are initialized and managed, and especially the synchronization mechanisms used to protect the trace data. I'm keen to ensure any performance bottlenecks or locking issues are caught early.
|
| 214/5 |
2026/08/31 21:56 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:710 LineCount:90]
Results: map[Contents: 710:
711: ret = -EIO;
712: debugfs_create_file("dropped", 0444, dir, bt, &blk_dropped_fops);
713: debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
714:
715: bt->rchan = relay_open("trace", dir, buf_size, buf_nr,
716: &blk_relay_callbacks, bt);
717: if (!bt->rchan)
718: goto err;
719:
720: blk_trace_setup_lba(bt, bdev);
721:
722: return bt;
723:
724: err:
725: blk_trace_free(q, bt);
726:
727: return ERR_PTR(ret);
728: }
729:
730: static void blk_trace_setup_finalize(struct request_queue *q,
731: char *name, int version,
732: struct blk_trace *bt,
733: struct blk_user_trace_setup2 *buts)
734:
735: {
736: strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
737:
738: /*
739: * some device names have larger paths - convert the slashes
740: * to underscores for this to work as expected
741: */
742: strreplace(buts->name, '/', '_');
743:
744: bt->version = version;
745: bt->act_mask = buts->act_mask;
746: if (!bt->act_mask)
747: bt->act_mask = (u16) -1;
748:
749: /* overwrite with user settings */
750: if (buts->start_lba)
751: bt->start_lba = buts->start_lba;
752: if (buts->end_lba)
753: bt->end_lba = buts->end_lba;
754:
755: bt->pid = buts->pid;
756: bt->trace_state = Blktrace_setup;
757:
758: rcu_assign_pointer(q->blk_trace, bt);
759: get_probe_ref();
760: }
761:
762: int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
763: struct block_device *bdev,
764: char __user *arg)
765: {
766: struct blk_user_trace_setup2 buts2;
767: struct blk_user_trace_setup buts;
768: struct blk_trace *bt;
769: unsigned int memflags;
770: int ret;
771:
772: ret = copy_from_user(&buts, arg, sizeof(buts));
773: if (ret)
774: return -EFAULT;
775:
776: if (!buts.buf_size || !buts.buf_nr)
777: return -EINVAL;
778:
779: buts2 = (struct blk_user_trace_setup2) {
780: .act_mask = buts.act_mask,
781: .buf_size = buts.buf_size,
782: .buf_nr = buts.buf_nr,
783: .start_lba = buts.start_lba,
784: .end_lba = buts.end_lba,
785: .pid = buts.pid,
786: };
787:
788: memflags = blk_debugfs_lock(q);
789: bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
790: bdev);
791: if (IS_ERR(bt)) {
792: blk_debugfs_unlock(q, memflags);
793: return PTR_ERR(bt);
794: }
795: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
796: strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
797: blk_debugfs_unlock(q, memflags);
798:
799: if (copy_to_user(arg, &buts, sizeof(buts))) {
]
|
| 215/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 17940
output: 38
thoughts: 26
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `blktrace.c` for Analysis**
Okay, time to zero in on a specific section of `kernel/trace/blktrace.c`. My immediate focus is on lines 800 through 930. This range typically houses some critical function(s) or logic pertaining to block trace event handling, parsing, or maybe even the writing of trace data. I'm likely looking for something specific – perhaps a particular event type's processing, a suspected bottleneck, or maybe a potential source of a bug I've been chasing. I’ll be paying close attention to data structures used, any locking that might be involved (spinlocks, mutexes, etc.), and the flow of control within that section. It's time to refresh my memory on what that section *should* be doing and assess whether it aligns with what I *expect* it to do, given the context of the problem I'm trying to solve. I anticipate I will be checking for potential race conditions or locking issues that I may have suspected, or perhaps I'm looking to check some calculations to verify whether the data in the trace is accurate. I'm going to start by quickly scanning the code for any immediate red flags, then dig deeper.
|
| 216/5 |
2026/08/31 21:56 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:795 LineCount:100]
Results: map[Contents: 795: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
796: strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
797: blk_debugfs_unlock(q, memflags);
798:
799: if (copy_to_user(arg, &buts, sizeof(buts))) {
800: blk_trace_remove(q);
801: return -EFAULT;
802: }
803: return 0;
804: }
805: EXPORT_SYMBOL_GPL(blk_trace_setup);
806:
807: static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
808: struct block_device *bdev, char __user *arg)
809: {
810: struct blk_user_trace_setup2 buts2;
811: struct blk_trace *bt;
812: unsigned int memflags;
813:
814: if (copy_from_user(&buts2, arg, sizeof(buts2)))
815: return -EFAULT;
816:
817: if (!buts2.buf_size || !buts2.buf_nr)
818: return -EINVAL;
819:
820: if (buts2.flags != 0)
821: return -EINVAL;
822:
823: memflags = blk_debugfs_lock(q);
824: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
825: bdev);
826: if (IS_ERR(bt)) {
827: blk_debugfs_unlock(q, memflags);
828: return PTR_ERR(bt);
829: }
830: blk_trace_setup_finalize(q, name, 2, bt, &buts2);
831: blk_debugfs_unlock(q, memflags);
832:
833: if (copy_to_user(arg, &buts2, sizeof(buts2))) {
834: blk_trace_remove(q);
835: return -EFAULT;
836: }
837: return 0;
838: }
839:
840: #if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64)
841: static int compat_blk_trace_setup(struct request_queue *q, char *name,
842: dev_t dev, struct block_device *bdev,
843: char __user *arg)
844: {
845: struct blk_user_trace_setup2 buts2;
846: struct compat_blk_user_trace_setup cbuts;
847: struct blk_trace *bt;
848: unsigned int memflags;
849:
850: if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
851: return -EFAULT;
852:
853: if (!cbuts.buf_size || !cbuts.buf_nr)
854: return -EINVAL;
855:
856: buts2 = (struct blk_user_trace_setup2) {
857: .act_mask = cbuts.act_mask,
858: .buf_size = cbuts.buf_size,
859: .buf_nr = cbuts.buf_nr,
860: .start_lba = cbuts.start_lba,
861: .end_lba = cbuts.end_lba,
862: .pid = cbuts.pid,
863: };
864:
865: memflags = blk_debugfs_lock(q);
866: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
867: bdev);
868: if (IS_ERR(bt)) {
869: blk_debugfs_unlock(q, memflags);
870: return PTR_ERR(bt);
871: }
872: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
873: blk_debugfs_unlock(q, memflags);
874:
875: if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
876: blk_trace_remove(q);
877: return -EFAULT;
878: }
879:
880: return 0;
881: }
882: #endif
883:
884: static int __blk_trace_startstop(struct request_queue *q, int start)
885: {
886: struct blk_trace *bt;
887:
888: bt = rcu_dereference_protected(q->blk_trace,
889: lockdep_is_held(&q->debugfs_mutex));
890: if (bt == NULL)
891: return -EINVAL;
892:
893: if (start)
894: return blk_trace_start(bt);
]
|
| 217/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 19885
output: 38
thoughts: 47
Thoughts: Here's my take on the thought process, as if it were my own:
**Diving into Block Tracing Initialization**
Alright, I need to understand how these tracepoints in `blktrace` are being registered and unregistered. I'll focus my attention on `kernel/trace/blktrace.c` specifically around the `blk_register_tracepoints` and `blk_unregister_tracepoints` functions, which, based on the file and function names, are likely the core of the initialization and cleanup routines. I'm going to quickly skim the lines 1320 to 1420 to refresh my memory of the context. I'll be looking for how the tracepoints are hooked into the kernel's tracing infrastructure and what mechanisms are used to cleanly remove them when the module unloads or the tracing session ends. I expect to see the usual suspects: calls to `register_trace_*` macros or functions, related data structures being populated, and the reverse for unregistration. I'm also curious about any potential error handling or synchronization aspects within those function regions, because those are often points of interest, especially in a tracing system that needs to be as non-intrusive as possible.
|
| 218/5 |
2026/08/31 21:56 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1320 LineCount:90]
Results: map[Contents:1320: __blk_add_trace(bt, blk_rq_trace_sector(rq), blk_rq_bytes(rq), 0,
1321: BLK_TA_DRV_DATA, 0, len, data,
1322: blk_trace_request_get_cgid(rq));
1323: rcu_read_unlock();
1324: }
1325: EXPORT_SYMBOL_GPL(blk_add_driver_data);
1326:
1327: static void blk_register_tracepoints(void)
1328: {
1329: int ret;
1330:
1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1332: WARN_ON(ret);
1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1334: WARN_ON(ret);
1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1336: WARN_ON(ret);
1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1338: WARN_ON(ret);
1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1340: WARN_ON(ret);
1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1342: WARN_ON(ret);
1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1344: WARN_ON(ret);
1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1346: WARN_ON(ret);
1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1348: WARN_ON(ret);
1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
1350: WARN_ON(ret);
1351: ret = register_trace_blk_zone_append_update_request_bio(
1352: blk_add_trace_zone_update_request, NULL);
1353: WARN_ON(ret);
1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
1355: NULL);
1356: WARN_ON(ret);
1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
1358: NULL);
1359: WARN_ON(ret);
1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
1361: WARN_ON(ret);
1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
1363: WARN_ON(ret);
1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
1365: WARN_ON(ret);
1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1367: WARN_ON(ret);
1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1369: WARN_ON(ret);
1370: }
1371:
1372: static void blk_unregister_tracepoints(void)
1373: {
1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
1376: unregister_trace_block_split(blk_add_trace_split, NULL);
1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
1380: unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
1381: unregister_trace_blk_zone_append_update_request_bio(
1382: blk_add_trace_zone_update_request, NULL);
1383: unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
1384: unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
1385: unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
1386: unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
1387: unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
1388: unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
1389: unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
1390: unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
1391: unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
1392: unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
1393:
1394: tracepoint_synchronize_unregister();
1395: }
1396:
1397: /*
1398: * struct blk_io_tracer formatting routines
1399: */
1400:
1401: static void fill_rwbs(char *rwbs, const struct blk_io_trace2 *t)
1402: {
1403: int i = 0;
1404: int tc = t->action >> BLK_TC_SHIFT;
1405:
1406: if ((t->action & ~__BLK_TN_CGROUP) == BLK_TN_MESSAGE) {
1407: rwbs[i++] = 'N';
1408: goto out;
1409: }
]
|
| 219/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 22054
output: 38
thoughts: 39
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Analyzing blktrace.c's Queue Setup**
Okay, time to dive in. I need to refresh my memory on how `blktrace` sets up its tracing queue. Let's zero in on the relevant code. I'm going to jump into `kernel/trace/blktrace.c` – specifically, lines 1900 through 1950. That should put me right around the `blk_trace_setup_queue` function, which, if memory serves, handles the crucial initialization of the tracing infrastructure for a given block device queue. I'll need to re-familiarize myself with the data structures involved, the locking mechanisms they employ, and how the tracing points get attached. This section's where the magic happens, so I want a complete overview.
|
| 220/5 |
2026/08/31 21:56 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1900 LineCount:50]
Results: map[Contents:1900: static int blk_trace_setup_queue(struct request_queue *q,
1901: struct block_device *bdev)
1902: {
1903: struct blk_trace *bt = NULL;
1904: int ret = -ENOMEM;
1905:
1906: bt = kzalloc_obj(*bt);
1907: if (!bt)
1908: return -ENOMEM;
1909:
1910: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
1911: if (!bt->msg_data)
1912: goto free_bt;
1913:
1914: bt->dev = bdev->bd_dev;
1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
1930: */
1931:
1932: static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
1933: struct device_attribute *attr,
1934: char *buf);
1935: static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
1936: struct device_attribute *attr,
1937: const char *buf, size_t count);
1938: #define BLK_TRACE_DEVICE_ATTR(_name) \
1939: DEVICE_ATTR(_name, S_IRUGO | S_IWUSR, \
1940: sysfs_blk_trace_attr_show, \
1941: sysfs_blk_trace_attr_store)
1942:
1943: static BLK_TRACE_DEVICE_ATTR(enable);
1944: static BLK_TRACE_DEVICE_ATTR(act_mask);
1945: static BLK_TRACE_DEVICE_ATTR(pid);
1946: static BLK_TRACE_DEVICE_ATTR(start_lba);
1947: static BLK_TRACE_DEVICE_ATTR(end_lba);
1948:
1949: static struct attribute *blk_trace_attrs[] = {
]
|
| 221/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 23080
output: 54
thoughts: 66
Thoughts: Here's my summary, as though I'm thinking it:
**Digging into Trace Setup Functions**
Okay, so I need to get a handle on how this tracing setup is functioning. Let's start by doing a quick sweep of the codebase. I need to make sure I haven't missed any other calls to `get_probe_ref`, that's a key function I need to look out for. And then I should search for `blk_trace_setup_finalize` or `blk_trace_setup_prepare`. I should also cast a wide net and look for any other trace setup functions that might be relevant; it's easy to miss something when you're focusing on specific function names. I want to make sure I have a complete picture of the landscape. I'm going to start with those function names but I'm going to keep an open mind for other related calls.
|
| 222/5 |
2026/08/31 21:56 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:kernel/trace/blktrace.c IncludeSnippetLines:10 Name:blk_trace_setup_finalize SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:blk_trace_setup SourceFile:kernel/trace/blktrace.c SourceLine:795 SourceSnippet: 785: .pid = buts.pid,
786: };
787:
788: memflags = blk_debugfs_lock(q);
789: bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
790: bdev);
791: if (IS_ERR(bt)) {
792: blk_debugfs_unlock(q, memflags);
793: return PTR_ERR(bt);
794: }
795: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
796: strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
797: blk_debugfs_unlock(q, memflags);
798:
799: if (copy_to_user(arg, &buts, sizeof(buts))) {
800: blk_trace_remove(q);
801: return -EFAULT;
802: }
803: return 0;
804: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:blk_trace_setup2 SourceFile:kernel/trace/blktrace.c SourceLine:830 SourceSnippet: 820: if (buts2.flags != 0)
821: return -EINVAL;
822:
823: memflags = blk_debugfs_lock(q);
824: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
825: bdev);
826: if (IS_ERR(bt)) {
827: blk_debugfs_unlock(q, memflags);
828: return PTR_ERR(bt);
829: }
830: blk_trace_setup_finalize(q, name, 2, bt, &buts2);
831: blk_debugfs_unlock(q, memflags);
832:
833: if (copy_to_user(arg, &buts2, sizeof(buts2))) {
834: blk_trace_remove(q);
835: return -EFAULT;
836: }
837: return 0;
838: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:compat_blk_trace_setup SourceFile:kernel/trace/blktrace.c SourceLine:872 SourceSnippet: 862: .pid = cbuts.pid,
863: };
864:
865: memflags = blk_debugfs_lock(q);
866: bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
867: bdev);
868: if (IS_ERR(bt)) {
869: blk_debugfs_unlock(q, memflags);
870: return PTR_ERR(bt);
871: }
872: blk_trace_setup_finalize(q, name, 1, bt, &buts2);
873: blk_debugfs_unlock(q, memflags);
874:
875: if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
876: blk_trace_remove(q);
877: return -EFAULT;
878: }
879:
880: return 0;
881: }
]] TruncatedOutput:false]
|
| 223/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 24512
output: 37
thoughts: 123
Thoughts: **Diving into Block Trace Initialization and Cleanup**
Okay, so I need to really understand the lifecycle management within blktrace. My focus is on the crucial points – specifically, what's going on during `blk_trace_setup_finalize`, `blk_trace_setup_prepare`, `blk_trace_free`, and `blk_trace_remove`. I know these are the functions that either set it up or take it down, so it's critical to understanding how to best operate and perhaps extend this code.
I'm particularly interested in the setup process, which probably means I need a good grasp of both `blk_trace_setup_prepare` and `blk_trace_free`, as well as how devices are subsequently removed, with `blk_trace_remove`. Time to dive into the code.
Alright, I'm going to start by getting a solid handle on the code. I'll read through `kernel/trace/blktrace.c`, specifically lines 650 to 730, then 460 to 505 and, finally, 1880 to 1910. That should give me a good overview of the important sections of the lifecycle management, including resource setup, allocation, teardown, and cleanup, and will set the stage for deeper analysis.
|
| 224/5 |
2026/08/31 21:56 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:650 LineCount:80]
Results: map[Contents: 650: * Setup everything required to start tracing
651: */
652: static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
653: char *name, dev_t dev,
654: u32 buf_size, u32 buf_nr,
655: struct block_device *bdev)
656: {
657: struct blk_trace *bt = NULL;
658: struct dentry *dir = NULL;
659: int ret;
660:
661: lockdep_assert_held(&q->debugfs_mutex);
662:
663: /*
664: * bdev can be NULL, as with scsi-generic, this is a helpful as
665: * we can be.
666: */
667: if (rcu_dereference_protected(q->blk_trace,
668: lockdep_is_held(&q->debugfs_mutex))) {
669: pr_warn("Concurrent blktraces are not allowed on %s\n", name);
670: return ERR_PTR(-EBUSY);
671: }
672:
673: bt = kzalloc_obj(*bt);
674: if (!bt)
675: return ERR_PTR(-ENOMEM);
676:
677: ret = -ENOMEM;
678: bt->sequence = alloc_percpu(unsigned long);
679: if (!bt->sequence)
680: goto err;
681:
682: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
683: if (!bt->msg_data)
684: goto err;
685:
686: /*
687: * When tracing the whole disk reuse the existing debugfs directory
688: * created by the block layer on init. For partitions block devices,
689: * and scsi-generic block devices we create a temporary new debugfs
690: * directory that will be removed once the trace ends.
691: */
692: if (bdev && !bdev_is_partition(bdev))
693: dir = q->debugfs_dir;
694: else
695: bt->dir = dir = debugfs_create_dir(name, blk_debugfs_root);
696:
697: /*
698: * As blktrace relies on debugfs for its interface the debugfs directory
699: * is required, contrary to the usual mantra of not checking for debugfs
700: * files or directories.
701: */
702: if (IS_ERR_OR_NULL(dir)) {
703: pr_warn("debugfs_dir not present for %s so skipping\n", name);
704: ret = -ENOENT;
705: goto err;
706: }
707:
708: bt->dev = dev;
709: INIT_LIST_HEAD(&bt->running_list);
710:
711: ret = -EIO;
712: debugfs_create_file("dropped", 0444, dir, bt, &blk_dropped_fops);
713: debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
714:
715: bt->rchan = relay_open("trace", dir, buf_size, buf_nr,
716: &blk_relay_callbacks, bt);
717: if (!bt->rchan)
718: goto err;
719:
720: blk_trace_setup_lba(bt, bdev);
721:
722: return bt;
723:
724: err:
725: blk_trace_free(q, bt);
726:
727: return ERR_PTR(ret);
728: }
729:
]
|
| 225/5 |
2026/08/31 21:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 26137
output: 37
thoughts: 21
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `blk_trace_free`**
Alright, let's zero in on `blk_trace_free`, specifically lines 460 through 487. I'm focusing on this region because... well, I suspect there's something interesting happening there. My mental model suggests a particular interaction with the trace buffers or some potential contention point within the freeing logic. I'm probably looking for a specific data race or a subtle memory management issue that's causing intermittent performance degradation or a deadlock, or even just some inefficiencies. The fact that I've zoned in on this particular section means I probably have a nagging feeling about something related to how trace records are being handled during the deallocation process. Time to dig in and validate my hunch, line by line.
|
| 226/5 |
2026/08/31 21:57 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:460 LineCount:35]
Results: map[Contents: 460: */
461: local_irq_save(flags);
462: sequence = per_cpu_ptr(bt->sequence, cpu);
463: (*sequence)++;
464: relay_blktrace_event(bt, *sequence, pid, cpu, sector, bytes,
465: what, error, cgid, cgid_len, pdu_data, pdu_len);
466: local_irq_restore(flags);
467: }
468:
469: static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
470: {
471: relay_close(bt->rchan);
472:
473: /*
474: * If 'bt->dir' is not set, then both 'dropped' and 'msg' are created
475: * under 'q->debugfs_dir', thus lookup and remove them.
476: */
477: if (!bt->dir) {
478: debugfs_lookup_and_remove("dropped", q->debugfs_dir);
479: debugfs_lookup_and_remove("msg", q->debugfs_dir);
480: } else {
481: debugfs_remove(bt->dir);
482: }
483: free_percpu(bt->sequence);
484: free_percpu(bt->msg_data);
485: kfree(bt);
486: }
487:
488: static void get_probe_ref(void)
489: {
490: mutex_lock(&blk_probe_mutex);
491: if (++blk_probes_ref == 1)
492: blk_register_tracepoints();
493: mutex_unlock(&blk_probe_mutex);
494: }
]
|
| 227/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 26923
output: 38
thoughts: 16
Thoughts: Here's a summary of my thought process:
**Diving into Block Trace Removal and the sysfs Interface**
Okay, so I need to refresh my memory on how block trace removal is handled. Let's start by digging into `blk_trace_remove`. I want to understand the mechanics of it, specifically how it interacts with the system. Then, I need to look at the sysfs interface. I know it's a critical component for managing and controlling tracing, so understanding how these two pieces work together will be key. I'll need to see how they're connected. Perhaps there's a dependency, or maybe it's completely separate. The `sysfs` interface is likely the user's window into the tracing subsystem, so I expect `blk_trace_remove` to interact with it, either directly or indirectly. Let's get to the code and see.
|
| 228/5 |
2026/08/31 21:57 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:1860 LineCount:80]
Results: map[Contents:1860: {
1861: __init_blk_tracer();
1862: }
1863:
1864: static int __init init_blk_tracer(void)
1865: {
1866: int ret = 0;
1867:
1868: if (trace_init_wq) {
1869: INIT_WORK(&blktrace_works, blktrace_works_func);
1870: queue_work(trace_init_wq, &blktrace_works);
1871: } else {
1872: ret = __init_blk_tracer();
1873: }
1874:
1875: return ret;
1876: }
1877:
1878: device_initcall(init_blk_tracer);
1879:
1880: static int blk_trace_remove_queue(struct request_queue *q)
1881: {
1882: struct blk_trace *bt;
1883:
1884: bt = rcu_replace_pointer(q->blk_trace, NULL,
1885: lockdep_is_held(&q->debugfs_mutex));
1886: if (bt == NULL)
1887: return -EINVAL;
1888:
1889: blk_trace_stop(bt);
1890:
1891: put_probe_ref();
1892: synchronize_rcu();
1893: blk_trace_free(q, bt);
1894: return 0;
1895: }
1896:
1897: /*
1898: * Setup everything required to start tracing
1899: */
1900: static int blk_trace_setup_queue(struct request_queue *q,
1901: struct block_device *bdev)
1902: {
1903: struct blk_trace *bt = NULL;
1904: int ret = -ENOMEM;
1905:
1906: bt = kzalloc_obj(*bt);
1907: if (!bt)
1908: return -ENOMEM;
1909:
1910: bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG, __alignof__(char));
1911: if (!bt->msg_data)
1912: goto free_bt;
1913:
1914: bt->dev = bdev->bd_dev;
1915: bt->act_mask = (u16)-1;
1916:
1917: blk_trace_setup_lba(bt, bdev);
1918:
1919: rcu_assign_pointer(q->blk_trace, bt);
1920: get_probe_ref();
1921: return 0;
1922:
1923: free_bt:
1924: blk_trace_free(q, bt);
1925: return ret;
1926: }
1927:
1928: /*
1929: * sysfs interface to enable and configure tracing
1930: */
1931:
1932: static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
1933: struct device_attribute *attr,
1934: char *buf);
1935: static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
1936: struct device_attribute *attr,
1937: const char *buf, size_t count);
1938: #define BLK_TRACE_DEVICE_ATTR(_name) \
1939: DEVICE_ATTR(_name, S_IRUGO | S_IWUSR, \
]
|
| 229/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 28247
output: 38
thoughts: 126
Thoughts: Okay, let's dive into this kernel crash. My initial thought is to pinpoint the exact location. The backtrace points directly to `sysfs_blk_trace_attr_store` and within it, to `kernel/trace/blktrace.c`. Looks like the crash occurred during the setup of a block trace - interesting.
I'm zeroing in on that function, and I'll focus my attention on the code block around lines 2000-2200 within `sysfs_blk_trace_attr_store`. That's where the failure is most likely occurring, given the backtrace. It seems this region will contain the key to understanding this issue. Let's see what's happening there!
|
| 230/5 |
2026/08/31 21:57 |
tool |
read-file |
0m
Args: map[File:kernel/trace/blktrace.c FirstLine:2080 LineCount:80]
Results: map[Contents:2080: ssize_t ret = -EINVAL;
2081:
2082: if (count == 0)
2083: goto out;
2084:
2085: if (attr == &dev_attr_act_mask) {
2086: if (kstrtoull(buf, 0, &value)) {
2087: /* Assume it is a list of trace category names */
2088: ret = blk_trace_str2mask(buf);
2089: if (ret < 0)
2090: goto out;
2091: value = ret;
2092: }
2093: } else {
2094: if (kstrtoull(buf, 0, &value))
2095: goto out;
2096: }
2097:
2098: memflags = blk_debugfs_lock(q);
2099:
2100: bt = rcu_dereference_protected(q->blk_trace,
2101: lockdep_is_held(&q->debugfs_mutex));
2102: if (attr == &dev_attr_enable) {
2103: if (!!value == !!bt) {
2104: ret = 0;
2105: goto out_unlock_bdev;
2106: }
2107: if (value)
2108: ret = blk_trace_setup_queue(q, bdev);
2109: else
2110: ret = blk_trace_remove_queue(q);
2111: goto out_unlock_bdev;
2112: }
2113:
2114: ret = 0;
2115: if (bt == NULL) {
2116: ret = blk_trace_setup_queue(q, bdev);
2117: bt = rcu_dereference_protected(q->blk_trace,
2118: lockdep_is_held(&q->debugfs_mutex));
2119: }
2120:
2121: if (ret == 0) {
2122: if (attr == &dev_attr_act_mask)
2123: bt->act_mask = value;
2124: else if (attr == &dev_attr_pid)
2125: bt->pid = value;
2126: else if (attr == &dev_attr_start_lba)
2127: bt->start_lba = value;
2128: else if (attr == &dev_attr_end_lba)
2129: bt->end_lba = value;
2130: }
2131:
2132: out_unlock_bdev:
2133: blk_debugfs_unlock(q, memflags);
2134: out:
2135: return ret ? ret : count;
2136: }
2137: #endif /* CONFIG_BLK_DEV_IO_TRACE */
2138:
2139: #ifdef CONFIG_EVENT_TRACING
2140:
2141: /**
2142: * blk_fill_rwbs - Fill the buffer rwbs by mapping op to character string.
2143: * @rwbs: buffer to be filled
2144: * @opf: request operation type (REQ_OP_XXX) and flags for the tracepoint
2145: *
2146: * Description:
2147: * Maps each request operation and flag to a single character and fills the
2148: * buffer provided by the caller with resulting string.
2149: *
2150: **/
2151: void blk_fill_rwbs(char *rwbs, blk_opf_t opf)
2152: {
2153: int i = 0;
2154:
2155: if (opf & REQ_PREFLUSH)
2156: rwbs[i++] = 'F';
2157:
2158: switch (opf & REQ_OP_MASK) {
2159: case REQ_OP_WRITE:
]
|
| 231/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 29735
output: 32
thoughts: 42
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Investigating Block Tracepoint Registration**
Alright, so I need to dig into the recent history or changes surrounding the block tracepoint registration in the kernel. My first instinct is to fire up `git log` and specifically target the `kernel/trace/blktrace.c` file. That should give me a good, focused view of commits that might have touched the area I'm interested in. Given the specifics of this situation, I should go ahead and broaden the search as much as possible.
However, just to be thorough and because it is a common pattern for the kernel, I'll also want to cast a wider net. I'm going to scan the commit messages for any mentions of `blk_register_tracepoints` or `register_trace_block`. Those are the usual suspects, and it’s possible a refactoring or related change might have affected registration indirectly, even if `blktrace.c` itself wasn't directly modified. It's about being comprehensive and considering the broader context of the changes made around the target functionality. With any luck, I'll find what I'm looking for quickly and efficiently.
|
| 232/5 |
2026/08/31 21:57 |
tool |
git-log |
0m
Args: map[PathPrefix:kernel/trace/blktrace.c Since:3 years]
Results: map[Output:da46b5dfef48 blktrace: fix __this_cpu_read/write in preemptible context
bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
dfe48ea17973 blk-mq: use NOIO context to prevent deadlock during debugfs creation
0c2580a80946 blktrace: Make init_blk_tracer() asynchronous
ee4784a83fb2 block: don't use strcpy to copy blockdev name
bbec8e28cac5 tracing: Allow tracer to add more than 32 options
bc49af56eea8 blktrace: add support for REQ_OP_WRITE_ZEROES tracing
e48886b9d668 blktrace: for ftrace use correct trace format ver
4a0940bdcac2 blktrace: use debug print to report dropped events
]
|
| 233/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 30330
output: 26
thoughts: 44
Thoughts: Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts:
**Analyzing Tracepoint Registration and Error Handling in the Kernel**
Alright, I need to get a better handle on how tracepoints are being registered within the kernel and, critically, how they deal with error scenarios. Specifically, I want to understand how different kernel subsystems might manage error unwinding in the context of `register_trace_*` functions. Are there any common patterns or unique approaches out there?
My initial plan is to leverage `grepper`. It’s the perfect tool for this type of kernel-wide code search. I'll use it to scour the entire kernel source tree, looking for instances where `register_trace_` is used. This should give me a good overview of how prevalent tracepoint registration is and where it's happening. From there, I can start diving into the surrounding code to understand the broader context and see how errors are handled in each case. This should lead me to a useful data set to study error handling around the registered tracepoints.
|
| 234/5 |
2026/08/31 21:57 |
tool |
grepper |
0m
Args: map[Expression:register_trace_ PathPrefix:kernel/]
Results: map[Output:
Full output is too long, showing 500 out of 612 lines.
Use more precise expression if possible.
kernel/kcsan/kcsan_test.c=1589=static void register_tracepoints(void)
kernel/kcsan/kcsan_test.c-1590-{
kernel/kcsan/kcsan_test.c:1591: register_trace_console(probe_console, NULL);
kernel/kcsan/kcsan_test.c-1592-}
--
kernel/kcsan/kcsan_test.c=1595=static void unregister_tracepoints(void)
kernel/kcsan/kcsan_test.c-1596-{
kernel/kcsan/kcsan_test.c:1597: unregister_trace_console(probe_console, NULL);
kernel/kcsan/kcsan_test.c-1598-}
--
kernel/trace/blktrace.c=1327=static void blk_register_tracepoints(void)
--
kernel/trace/blktrace.c-1330-
kernel/trace/blktrace.c:1331: ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1332- WARN_ON(ret);
kernel/trace/blktrace.c:1333: ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c-1334- WARN_ON(ret);
kernel/trace/blktrace.c:1335: ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c-1336- WARN_ON(ret);
kernel/trace/blktrace.c:1337: ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c-1338- WARN_ON(ret);
kernel/trace/blktrace.c:1339: ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c-1340- WARN_ON(ret);
kernel/trace/blktrace.c:1341: ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c-1342- WARN_ON(ret);
kernel/trace/blktrace.c:1343: ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c-1344- WARN_ON(ret);
kernel/trace/blktrace.c:1345: ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c-1346- WARN_ON(ret);
kernel/trace/blktrace.c:1347: ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c-1348- WARN_ON(ret);
kernel/trace/blktrace.c:1349: ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c-1350- WARN_ON(ret);
kernel/trace/blktrace.c:1351: ret = register_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1352- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c-1353- WARN_ON(ret);
kernel/trace/blktrace.c:1354: ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
kernel/trace/blktrace.c-1355- NULL);
kernel/trace/blktrace.c-1356- WARN_ON(ret);
kernel/trace/blktrace.c:1357: ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
kernel/trace/blktrace.c-1358- NULL);
kernel/trace/blktrace.c-1359- WARN_ON(ret);
kernel/trace/blktrace.c:1360: ret = register_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c-1361- WARN_ON(ret);
kernel/trace/blktrace.c:1362: ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c-1363- WARN_ON(ret);
kernel/trace/blktrace.c:1364: ret = register_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c-1365- WARN_ON(ret);
kernel/trace/blktrace.c:1366: ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c-1367- WARN_ON(ret);
kernel/trace/blktrace.c:1368: ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c-1369- WARN_ON(ret);
--
kernel/trace/blktrace.c=1372=static void blk_unregister_tracepoints(void)
kernel/trace/blktrace.c-1373-{
kernel/trace/blktrace.c:1374: unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
kernel/trace/blktrace.c:1375: unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
kernel/trace/blktrace.c:1376: unregister_trace_block_split(blk_add_trace_split, NULL);
kernel/trace/blktrace.c:1377: unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
kernel/trace/blktrace.c:1378: unregister_trace_block_plug(blk_add_trace_plug, NULL);
kernel/trace/blktrace.c:1379: unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
kernel/trace/blktrace.c:1380: unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
kernel/trace/blktrace.c:1381: unregister_trace_blk_zone_append_update_request_bio(
kernel/trace/blktrace.c-1382- blk_add_trace_zone_update_request, NULL);
kernel/trace/blktrace.c:1383: unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
kernel/trace/blktrace.c:1384: unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
kernel/trace/blktrace.c:1385: unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
kernel/trace/blktrace.c:1386: unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
kernel/trace/blktrace.c:1387: unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
kernel/trace/blktrace.c:1388: unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
kernel/trace/blktrace.c:1389: unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
kernel/trace/blktrace.c:1390: unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
kernel/trace/blktrace.c:1391: unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
kernel/trace/blktrace.c:1392: unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
kernel/trace/blktrace.c-1393-
--
kernel/trace/blktrace.c=1839=static int __init __init_blk_tracer(void)
kernel/trace/blktrace.c-1840-{
kernel/trace/blktrace.c:1841: if (!register_trace_event(&trace_blk_event)) {
kernel/trace/blktrace.c-1842- pr_warn("Warning: could not register block events\n");
--
kernel/trace/blktrace.c-1847- pr_warn("Warning: could not register the block tracer\n");
kernel/trace/blktrace.c:1848: unregister_trace_event(&trace_blk_event);
kernel/trace/blktrace.c-1849- return 1;
--
kernel/trace/fgraph.c=1236=static int start_graph_tracing(void)
--
kernel/trace/fgraph.c-1257- if (!ret) {
kernel/trace/fgraph.c:1258: ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
kernel/trace/fgraph.c-1259- if (ret)
--
kernel/trace/fgraph.c=1426=void unregister_ftrace_graph(struct fgraph_ops *gops)
--
kernel/trace/fgraph.c-1463- unregister_pm_notifier(&ftrace_suspend_notifier);
kernel/trace/fgraph.c:1464: unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
kernel/trace/fgraph.c-1465- }
--
kernel/trace/ftrace.c=8691=void ftrace_pid_follow_fork(struct trace_array *tr, bool enable)
--
kernel/trace/ftrace.c-8693- if (enable) {
kernel/trace/ftrace.c:8694: register_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
kernel/trace/ftrace.c-8695- tr);
kernel/trace/ftrace.c:8696: register_trace_sched_process_free(ftrace_pid_follow_sched_process_exit,
kernel/trace/ftrace.c-8697- tr);
kernel/trace/ftrace.c-8698- } else {
kernel/trace/ftrace.c:8699: unregister_trace_sched_process_fork(ftrace_pid_follow_sched_process_fork,
kernel/trace/ftrace.c-8700- tr);
kernel/trace/ftrace.c:8701: unregister_trace_sched_process_free(ftrace_pid_follow_sched_process_exit,
kernel/trace/ftrace.c-8702- tr);
--
kernel/trace/ftrace.c=8706=static void clear_ftrace_pids(struct trace_array *tr, int type)
--
kernel/trace/ftrace.c-8722- if (!still_need_pid_events(type, pid_list, no_pid_list)) {
kernel/trace/ftrace.c:8723: unregister_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr);
kernel/trace/ftrace.c-8724- for_each_possible_cpu(cpu)
--
kernel/trace/ftrace.c=8932=pid_write(struct file *filp, const char __user *ubuf,
--
kernel/trace/ftrace.c-8983- /* Register a probe to set whether to ignore the tracing of a task */
kernel/trace/ftrace.c:8984: register_trace_sched_switch(ftrace_filter_pid_sched_switch_probe, tr);
kernel/trace/ftrace.c-8985- }
--
kernel/trace/trace_branch.c=178=__init static int init_branch_tracer(void)
--
kernel/trace/trace_branch.c-181-
kernel/trace/trace_branch.c:182: ret = register_trace_event(&trace_branch_event);
kernel/trace/trace_branch.c-183- if (!ret) {
--
kernel/trace/trace_eprobe.c=77=static int eprobe_dyn_event_show(struct seq_file *m, struct dyn_event *ev)
--
kernel/trace/trace_eprobe.c-94-
kernel/trace/trace_eprobe.c:95:static int unregister_trace_eprobe(struct trace_eprobe *ep)
kernel/trace/trace_eprobe.c-96-{
--
kernel/trace/trace_eprobe.c=116=static int eprobe_dyn_event_release(struct dyn_event *ev)
--
kernel/trace/trace_eprobe.c-118- struct trace_eprobe *ep = to_trace_eprobe(ev);
kernel/trace/trace_eprobe.c:119: int ret = unregister_trace_eprobe(ep);
kernel/trace/trace_eprobe.c-120-
--
kernel/trace/trace_events.c=645=int trace_event_raw_init(struct trace_event_call *call)
--
kernel/trace/trace_events.c-648-
kernel/trace/trace_events.c:649: id = register_trace_event(&call->event);
kernel/trace/trace_events.c-650- if (!id)
--
kernel/trace/trace_events.c=1093=void trace_event_follow_fork(struct trace_array *tr, bool enable)
--
kernel/trace/trace_events.c-1095- if (enable) {
kernel/trace/trace_events.c:1096: register_trace_prio_sched_process_fork(event_filter_pid_sched_process_fork,
kernel/trace/trace_events.c-1097- tr, INT_MIN);
kernel/trace/trace_events.c:1098: register_trace_prio_sched_process_free(event_filter_pid_sched_process_exit,
kernel/trace/trace_events.c-1099- tr, INT_MAX);
kernel/trace/trace_events.c-1100- } else {
kernel/trace/trace_events.c:1101: unregister_trace_sched_process_fork(event_filter_pid_sched_process_fork,
kernel/trace/trace_events.c-1102- tr);
kernel/trace/trace_events.c:1103: unregister_trace_sched_process_free(event_filter_pid_sched_process_exit,
kernel/trace/trace_events.c-1104- tr);
--
kernel/trace/trace_events.c=1188=static void unregister_pid_events(struct trace_array *tr)
kernel/trace/trace_events.c-1189-{
kernel/trace/trace_events.c:1190: unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_pre, tr);
kernel/trace/trace_events.c:1191: unregister_trace_sched_switch(event_filter_pid_sched_switch_probe_post, tr);
kernel/trace/trace_events.c-1192-
kernel/trace/trace_events.c:1193: unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1194: unregister_trace_sched_wakeup(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1195-
kernel/trace/trace_events.c:1196: unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1197: unregister_trace_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1198-
kernel/trace/trace_events.c:1199: unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_pre, tr);
kernel/trace/trace_events.c:1200: unregister_trace_sched_waking(event_filter_pid_sched_wakeup_probe_post, tr);
kernel/trace/trace_events.c-1201-}
--
kernel/trace/trace_events.c=2562=static void register_pid_events(struct trace_array *tr)
--
kernel/trace/trace_events.c-2569- */
kernel/trace/trace_events.c:2570: register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_pre,
kernel/trace/trace_events.c-2571- tr, INT_MAX);
kernel/trace/trace_events.c:2572: register_trace_prio_sched_switch(event_filter_pid_sched_switch_probe_post,
kernel/trace/trace_events.c-2573- tr, 0);
kernel/trace/trace_events.c-2574-
kernel/trace/trace_events.c:2575: register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2576- tr, INT_MAX);
kernel/trace/trace_events.c:2577: register_trace_prio_sched_wakeup(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2578- tr, 0);
kernel/trace/trace_events.c-2579-
kernel/trace/trace_events.c:2580: register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2581- tr, INT_MAX);
kernel/trace/trace_events.c:2582: register_trace_prio_sched_wakeup_new(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2583- tr, 0);
kernel/trace/trace_events.c-2584-
kernel/trace/trace_events.c:2585: register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_pre,
kernel/trace/trace_events.c-2586- tr, INT_MAX);
kernel/trace/trace_events.c:2587: register_trace_prio_sched_waking(event_filter_pid_sched_wakeup_probe_post,
kernel/trace/trace_events.c-2588- tr, 0);
--
kernel/trace/trace_events.c=3350=static void event_remove(struct trace_event_call *call)
--
kernel/trace/trace_events.c-3372- if (call->event.funcs)
kernel/trace/trace_events.c:3373: __unregister_trace_event(&call->event);
kernel/trace/trace_events.c-3374- remove_event_from_tracers(call);
--
kernel/trace/trace_events_synth.c=955=static int register_synth_event(struct synth_event *event)
--
kernel/trace/trace_events_synth.c-977-
kernel/trace/trace_events_synth.c:978: ret = register_trace_event(&call->event);
kernel/trace/trace_events_synth.c-979- if (!ret) {
--
kernel/trace/trace_events_synth.c-999- ret = set_synth_event_print_fmt(call);
kernel/trace/trace_events_synth.c:1000: /* unregister_trace_event() will be called inside */
kernel/trace/trace_events_synth.c-1001- if (ret < 0)
--
kernel/trace/trace_events_synth.c-1005- err:
kernel/trace/trace_events_synth.c:1006: unregister_trace_event(&call->event);
kernel/trace/trace_events_synth.c-1007- goto out;
--
kernel/trace/trace_events_user.c=1966=static int user_event_trace_register(struct user_event *user)
--
kernel/trace/trace_events_user.c-1969-
kernel/trace/trace_events_user.c:1970: ret = register_trace_event(&user->call.event);
kernel/trace/trace_events_user.c-1971-
--
kernel/trace/trace_events_user.c-1977- if (ret)
kernel/trace/trace_events_user.c:1978: unregister_trace_event(&user->call.event);
kernel/trace/trace_events_user.c-1979-
--
kernel/trace/trace_fprobe.c=797=static int trace_fprobe_verify_target(struct trace_fprobe *tf)
--
kernel/trace/trace_fprobe.c-813-/* Internal register function - just handle fprobe and flags */
kernel/trace/trace_fprobe.c:814:static int __register_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-815-{
--
kernel/trace/trace_fprobe.c-841-/* Internal unregister function - just handle fprobe and flags */
kernel/trace/trace_fprobe.c:842:static void __unregister_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-843-{
--
kernel/trace/trace_fprobe.c-853-/* Unregister a trace_probe and probe_event */
kernel/trace/trace_fprobe.c:854:static int unregister_trace_fprobe(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-855-{
--
kernel/trace/trace_fprobe.c-872-unreg:
kernel/trace/trace_fprobe.c:873: __unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-874- dyn_event_remove(&tf->devent);
--
kernel/trace/trace_fprobe.c=908=static int append_trace_fprobe_event(struct trace_fprobe *tf, struct trace_fprobe *to)
--
kernel/trace/trace_fprobe.c-945-/* Register a trace_probe and probe_event, and check the fprobe is available. */
kernel/trace/trace_fprobe.c:946:static int register_trace_fprobe_event(struct trace_fprobe *tf)
kernel/trace/trace_fprobe.c-947-{
--
kernel/trace/trace_fprobe.c=1209=static int trace_fprobe_create_internal(int argc, const char *argv[],
--
kernel/trace/trace_fprobe.c-1378-
kernel/trace/trace_fprobe.c:1379: ret = register_trace_fprobe_event(tf);
kernel/trace/trace_fprobe.c-1380- if (ret) {
--
kernel/trace/trace_fprobe.c=1419=static int trace_fprobe_release(struct dyn_event *ev)
--
kernel/trace/trace_fprobe.c-1421- struct trace_fprobe *tf = to_trace_fprobe(ev);
kernel/trace/trace_fprobe.c:1422: int ret = unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1423-
--
kernel/trace/trace_fprobe.c=1457=static int enable_trace_fprobe(struct trace_event_call *call,
--
kernel/trace/trace_fprobe.c-1479- list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) {
kernel/trace/trace_fprobe.c:1480: ret = __register_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1481- if (ret < 0)
--
kernel/trace/trace_fprobe.c-1490- list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list)
kernel/trace/trace_fprobe.c:1491: __unregister_trace_fprobe(tf);
kernel/trace/trace_fprobe.c-1492- if (file)
--
kernel/trace/trace_functions_graph.c=1814=static __init int init_graph_trace(void)
--
kernel/trace/trace_functions_graph.c-1817-
kernel/trace/trace_functions_graph.c:1818: if (!register_trace_event(&graph_trace_entry_event)) {
kernel/trace/trace_functions_graph.c-1819- pr_warn("Warning: could not register graph trace events\n");
--
kernel/trace/trace_functions_graph.c-1823-#ifdef CONFIG_FUNCTION_GRAPH_RETADDR
kernel/trace/trace_functions_graph.c:1824: if (!register_trace_event(&graph_trace_retaddr_entry_event)) {
kernel/trace/trace_functions_graph.c-1825- pr_warn("Warning: could not register graph trace retaddr events\n");
--
kernel/trace/trace_functions_graph.c-1829-
kernel/trace/trace_functions_graph.c:1830: if (!register_trace_event(&graph_trace_ret_event)) {
kernel/trace/trace_functions_graph.c-1831- pr_warn("Warning: could not register graph trace events\n");
--
kernel/trace/trace_kprobe.c=469=static bool within_notrace_func(struct trace_kprobe *tk)
--
kernel/trace/trace_kprobe.c-494-/* Internal register function - just handle k*probes and flags */
kernel/trace/trace_kprobe.c:495:static int __register_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-496-{
--
kernel/trace/trace_kprobe.c-532-/* Internal unregister function - just handle k*probes and flags */
kernel/trace/trace_kprobe.c:533:static void __unregister_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-534-{
--
kernel/trace/trace_kprobe.c-548-/* Unregister a trace_probe and probe_event */
kernel/trace/trace_kprobe.c:549:static int unregister_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-550-{
--
kernel/trace/trace_kprobe.c-567-unreg:
kernel/trace/trace_kprobe.c:568: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-569- dyn_event_remove(&tk->devent);
--
kernel/trace/trace_kprobe.c=604=static int append_trace_kprobe(struct trace_kprobe *tk, struct trace_kprobe *to)
--
kernel/trace/trace_kprobe.c-626- /* Register k*probe */
kernel/trace/trace_kprobe.c:627: ret = __register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-628- if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) {
--
kernel/trace/trace_kprobe.c-641-/* Register a trace_probe and probe_event */
kernel/trace/trace_kprobe.c:642:static int register_trace_kprobe(struct trace_kprobe *tk)
kernel/trace/trace_kprobe.c-643-{
--
kernel/trace/trace_kprobe.c-671- /* Register k*probe */
kernel/trace/trace_kprobe.c:672: ret = __register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-673- if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) {
--
kernel/trace/trace_kprobe.c=689=static int register_module_trace_kprobe(struct module *mod, struct trace_kprobe *tk)
--
kernel/trace/trace_kprobe.c-697- if (!ret)
kernel/trace/trace_kprobe.c:698: ret = __register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-699- return ret;
--
kernel/trace/trace_kprobe.c=703=static int trace_kprobe_module_callback(struct notifier_block *nb,
--
kernel/trace/trace_kprobe.c-718- /* Don't need to check busy - this should have gone. */
kernel/trace/trace_kprobe.c:719: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-720- ret = register_module_trace_kprobe(mod, tk);
--
kernel/trace/trace_kprobe.c=854=static int trace_kprobe_create_internal(int argc, const char *argv[],
--
kernel/trace/trace_kprobe.c-1076-
kernel/trace/trace_kprobe.c:1077: ret = register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1078- if (ret) {
--
kernel/trace/trace_kprobe.c=1298=static int trace_kprobe_release(struct dyn_event *ev)
--
kernel/trace/trace_kprobe.c-1300- struct trace_kprobe *tk = to_trace_kprobe(ev);
kernel/trace/trace_kprobe.c:1301: int ret = unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1302-
--
kernel/trace/trace_kprobe.c=1933=create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
--
kernel/trace/trace_kprobe.c-1970-
kernel/trace/trace_kprobe.c:1971: ret = __register_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1972- if (ret < 0)
--
kernel/trace/trace_kprobe.c=1978=void destroy_local_trace_kprobe(struct trace_event_call *event_call)
--
kernel/trace/trace_kprobe.c-1990-
kernel/trace/trace_kprobe.c:1991: __unregister_trace_kprobe(tk);
kernel/trace/trace_kprobe.c-1992-
--
kernel/trace/trace_osnoise.c=1004=static int hook_irq_events(void)
--
kernel/trace/trace_osnoise.c-1007-
kernel/trace/trace_osnoise.c:1008: ret = register_trace_irq_handler_entry(trace_irqentry_callback, NULL);
kernel/trace/trace_osnoise.c-1009- if (ret)
--
kernel/trace/trace_osnoise.c-1011-
kernel/trace/trace_osnoise.c:1012: ret = register_trace_irq_handler_exit(trace_irqexit_callback, NULL);
kernel/trace/trace_osnoise.c-1013- if (ret)
--
kernel/trace/trace_osnoise.c-1022-out_irq_exit:
kernel/trace/trace_osnoise.c:1023: unregister_trace_irq_handler_exit(trace_irqexit_callback, NULL);
kernel/trace/trace_osnoise.c-1024-out_unregister_entry:
kernel/trace/trace_osnoise.c:1025: unregister_trace_irq_handler_entry(trace_irqentry_callback, NULL);
kernel/trace/trace_osnoise.c-1026-out_err:
--
kernel/trace/trace_osnoise.c=1036=static void unhook_irq_events(void)
--
kernel/trace/trace_osnoise.c-1038- osnoise_arch_unregister();
kernel/trace/trace_osnoise.c:1039: unregister_trace_irq_handler_exit(trace_irqexit_callback, NULL);
kernel/trace/trace_osnoise.c:1040: unregister_trace_irq_handler_entry(trace_irqentry_callback, NULL);
kernel/trace/trace_osnoise.c-1041-}
--
kernel/trace/trace_osnoise.c=1100=static int hook_softirq_events(void)
--
kernel/trace/trace_osnoise.c-1103-
kernel/trace/trace_osnoise.c:1104: ret = register_trace_softirq_entry(trace_softirq_entry_callback, NULL);
kernel/trace/trace_osnoise.c-1105- if (ret)
--
kernel/trace/trace_osnoise.c-1107-
kernel/trace/trace_osnoise.c:1108: ret = register_trace_softirq_exit(trace_softirq_exit_callback, NULL);
kernel/trace/trace_osnoise.c-1109- if (ret)
--
kernel/trace/trace_osnoise.c-1114-out_unreg_entry:
kernel/trace/trace_osnoise.c:1115: unregister_trace_softirq_entry(trace_softirq_entry_callback, NULL);
kernel/trace/trace_osnoise.c-1116-out_err:
--
kernel/trace/trace_osnoise.c=1126=static void unhook_softirq_events(void)
kernel/trace/trace_osnoise.c-1127-{
kernel/trace/trace_osnoise.c:1128: unregister_trace_softirq_entry(trace_softirq_entry_callback, NULL);
kernel/trace/trace_osnoise.c:1129: unregister_trace_softirq_exit(trace_softirq_exit_callback, NULL);
kernel/trace/trace_osnoise.c-1130-}
--
kernel/trace/trace_osnoise.c=1239=static int register_migration_monitor(void)
--
kernel/trace/trace_osnoise.c-1250-
kernel/trace/trace_osnoise.c:1251: ret = register_trace_sched_migrate_task(trace_sched_migrate_callback, NULL);
kernel/trace/trace_osnoise.c-1252- if (!ret)
--
kernel/trace/trace_osnoise.c=1259=static void unregister_migration_monitor(void)
--
kernel/trace/trace_osnoise.c-1263-
kernel/trace/trace_osnoise.c:1264: unregister_trace_sched_migrate_task(trace_sched_migrate_callback, NULL);
kernel/trace/trace_osnoise.c-1265- monitor_enabled = false;
--
kernel/trace/trace_osnoise.c=1302=static int hook_thread_events(void)
--
kernel/trace/trace_osnoise.c-1305-
kernel/trace/trace_osnoise.c:1306: ret = register_trace_sched_switch(trace_sched_switch_callback, NULL);
kernel/trace/trace_osnoise.c-1307- if (ret)
--
kernel/trace/trace_osnoise.c-1316-out_unreg:
kernel/trace/trace_osnoise.c:1317: unregister_trace_sched_switch(trace_sched_switch_callback, NULL);
kernel/trace/trace_osnoise.c-1318- return -EINVAL;
--
kernel/trace/trace_osnoise.c=1327=static void unhook_thread_events(void)
kernel/trace/trace_osnoise.c-1328-{
kernel/trace/trace_osnoise.c:1329: unregister_trace_sched_switch(trace_sched_switch_callback, NULL);
kernel/trace/trace_osnoise.c-1330- unregister_migration_monitor();
--
kernel/trace/trace_output.c=862=void trace_event_read_unlock(void)
--
kernel/trace/trace_output.c-867-/**
kernel/trace/trace_output.c:868: * register_trace_event - register output for an event type
kernel/trace/trace_output.c-869- * @event: the event type to register
--
kernel/trace/trace_output.c-881- */
kernel/trace/trace_output.c:882:int register_trace_event(struct trace_event *event)
kernel/trace/trace_output.c-883-{
--
kernel/trace/trace_output.c-923-}
kernel/trace/trace_output.c:924:EXPORT_SYMBOL_GPL(register_trace_event);
kernel/trace/trace_output.c-925-
--
kernel/trace/trace_output.c-928- */
kernel/trace/trace_output.c:929:int __unregister_trace_event(struct trace_event *event)
kernel/trace/trace_output.c-930-{
--
kernel/trace/trace_output.c-936-/**
kernel/trace/trace_output.c:937: * unregister_trace_event - remove a no longer used event
kernel/trace/trace_output.c-938- * @event: the event to remove
kernel/trace/trace_output.c-939- */
kernel/trace/trace_output.c:940:int unregister_trace_event(struct trace_event *event)
kernel/trace/trace_output.c-941-{
kernel/trace/trace_output.c-942- down_write(&trace_event_sem);
kernel/trace/trace_output.c:943: __unregister_trace_event(event);
kernel/trace/trace_output.c-944- up_write(&trace_event_sem);
--
kernel/trace/trace_output.c-947-}
kernel/trace/trace_output.c:948:EXPORT_SYMBOL_GPL(unregister_trace_event);
kernel/trace/trace_output.c-949-
--
kernel/trace/trace_output.c=1922=__init int init_events(void)
--
kernel/trace/trace_output.c-1928- event = events[i];
kernel/trace/trace_output.c:1929: ret = register_trace_event(event);
kernel/trace/trace_output.c-1930- WARN_ONCE(!ret, "event %d failed to register", event->type);
--
kernel/trace/trace_output.h=43=trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry);
--
kernel/trace/trace_output.h-45-/* used by module unregistering */
kernel/trace/trace_output.h:46:extern int __unregister_trace_event(struct trace_event *event);
kernel/trace/trace_output.h-47-extern struct rw_semaphore trace_event_sem;
--
kernel/trace/trace_probe.c=2691=int trace_probe_register_event_call(struct trace_probe *tp)
--
kernel/trace/trace_probe.c-2701-
kernel/trace/trace_probe.c:2702: ret = register_trace_event(&call->event);
kernel/trace/trace_probe.c-2703- if (!ret)
--
kernel/trace/trace_probe.c-2707- if (ret)
kernel/trace/trace_probe.c:2708: unregister_trace_event(&call->event);
kernel/trace/trace_probe.c-2709-
--
kernel/trace/trace_sched_switch.c=52=static int tracing_sched_register(void)
--
kernel/trace/trace_sched_switch.c-55-
kernel/trace/trace_sched_switch.c:56: ret = register_trace_sched_wakeup(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-57- if (ret) {
--
kernel/trace/trace_sched_switch.c-62-
kernel/trace/trace_sched_switch.c:63: ret = register_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-64- if (ret) {
--
kernel/trace/trace_sched_switch.c-69-
kernel/trace/trace_sched_switch.c:70: ret = register_trace_sched_switch(probe_sched_switch, NULL);
kernel/trace/trace_sched_switch.c-71- if (ret) {
--
kernel/trace/trace_sched_switch.c-78-fail_deprobe_wake_new:
kernel/trace/trace_sched_switch.c:79: unregister_trace_sched_wakeup_new(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-80-fail_deprobe:
kernel/trace/trace_sched_switch.c:81: unregister_trace_sched_wakeup(probe_sched_wakeup, NULL);
kernel/trace/trace_sched_switch.c-82- return ret;
--
kernel/trace/trace_sched_switch.c=85=static void tracing_sched_unregister(void)
]
|
| 235/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 41771
output: 20
thoughts: 6884
Thoughts: **Analyzing the Patch for Tracepoint Registration and Unregistration**
Okay, so I've been tasked with thoroughly reviewing this patch and I've started by focusing on how the tracepoints are registered and unregistered within the block layer. I'm seeing a change to the return type of `blk_register_tracepoints` from `static void` to `static int`, and I need to understand why. Looking at `kernel/trace/trace_sched_switch.c` and similar files, I am reminded that registration and unregistration often involve synchronization to prevent race conditions during module loading and unloading, so let's dig into the details to verify the changes maintain integrity.
I've examined the `blk_register_tracepoints` function itself and noticed that it now explicitly returns an integer value and uses a series of `register_trace_...` calls, each potentially leading to a `goto` statement to an unregistration sequence in case of failure. This pattern strongly suggests error handling is now integrated directly into the registration process. It’s an interesting design choice, as the code now unwinds the registration process systematically in case of failure. The patch also shows `tracepoint_synchronize_unregister()` being used for graceful unregistration, which is a good practice to avoid deadlocks. This matches the corresponding `blk_unregister_tracepoints()` perfectly, with the unwinding being a reverse LIFO ladder, which is what I would expect.
Now, I'm focusing on `get_probe_ref()` and `put_probe_ref()`, because these functions are clearly managing a reference count (`blk_probes_ref`) to ensure the tracepoints are only registered when needed. I’m satisfied that `blk_probes_ref` is correctly managed. If the registration fails initially, it's properly reset to 0, ensuring that subsequent calls will attempt registration again if needed. When it goes from 0 -> 1 the probe is registered and vice versa. It seems robust and avoids double registration or premature unregistration. `get_probe_ref()` increments and `put_probe_ref()` decrements, so the setup and teardown are safe. The changes seem sound in principle.
Next, I have to verify that all the callers of `get_probe_ref()` are handling the potential return error from `blk_register_tracepoints()` correctly. I've located and reviewed `blk_trace_setup_queue`, `blk_trace_setup_finalize`, `blk_trace_setup`, `blk_trace_setup2`, and `compat_blk_trace_setup`. I see that the new `get_probe_ref()` call is placed before the assignment of the `blk_trace` structure. Crucially, if `get_probe_ref()` returns an error, the code jumps to an error path that calls `blk_trace_free()`, which will free all the resources allocated so far and *importantly*, the `blk_trace` structure remains NULL, preventing any potential use-after-free or double-free issues. I verified that `blk_trace_free` properly closes `relay_close` which handles memory, calls debugfs_remove and unregisters all the traces from the system, and properly free percpu data.
I'm confident that these error handling mechanisms are sound and complete. The callers all check the return value of `get_probe_ref()`, and if the registration fails the code immediately calls the teardown logic to ensure all acquired resources are released. It prevents assigning `q->blk_trace` if the probe registration fails. The changes appear safe and avoid any introduction of new memory leaks or use-after-free bugs.
Finally, I've confirmed by searching the whole kernel code that the patch has addressed all use cases of `blk_register_tracepoints`.
So, from my expert perspective, this patch looks well-designed and the added error handling around the tracepoint registration process appears to be correctly implemented, adding robustness to the blktrace system. I'm comfortable with the changes.
|
| 236/5 |
2026/08/31 21:57 |
tool |
grepper |
0m
Args: map[Expression:blk_probes_ref]
Results: map[Output:kernel/trace/blktrace.c=60=static DEFINE_MUTEX(blk_probe_mutex);
kernel/trace/blktrace.c:61:static int blk_probes_ref;
kernel/trace/blktrace.c-62-
--
kernel/trace/blktrace.c=488=static void get_probe_ref(void)
--
kernel/trace/blktrace.c-490- mutex_lock(&blk_probe_mutex);
kernel/trace/blktrace.c:491: if (++blk_probes_ref == 1)
kernel/trace/blktrace.c-492- blk_register_tracepoints();
--
kernel/trace/blktrace.c=496=static void put_probe_ref(void)
--
kernel/trace/blktrace.c-498- mutex_lock(&blk_probe_mutex);
kernel/trace/blktrace.c:499: if (!--blk_probes_ref)
kernel/trace/blktrace.c-500- blk_unregister_tracepoints();
]
|
| 237/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 49810
output: 20
thoughts: 19
Thoughts: Here's my take on those thoughts:
**Checking for Redundancy**
Okay, so I'm thinking, before I go any further down this rabbit hole, I should just make sure I'm not duplicating effort. The first thing that comes to mind is: has anyone else already implemented or partially implemented what I'm aiming for? Specifically, I need to know if `blk_register_tracepoints` (or something similar in functionality) has already been addressed elsewhere. A quick search seems prudent. I need to know if there is existing work.
|
| 238/5 |
2026/08/31 21:57 |
tool |
grepper |
0m
Args: map[Expression:blk_register_tracepoints]
Results: map[Output:kernel/trace/blktrace.c=61=static int blk_probes_ref;
kernel/trace/blktrace.c-62-
kernel/trace/blktrace.c:63:static void blk_register_tracepoints(void);
kernel/trace/blktrace.c-64-static void blk_unregister_tracepoints(void);
--
kernel/trace/blktrace.c=488=static void get_probe_ref(void)
--
kernel/trace/blktrace.c-491- if (++blk_probes_ref == 1)
kernel/trace/blktrace.c:492: blk_register_tracepoints();
kernel/trace/blktrace.c-493- mutex_unlock(&blk_probe_mutex);
--
kernel/trace/blktrace.c=1325=EXPORT_SYMBOL_GPL(blk_add_driver_data);
kernel/trace/blktrace.c-1326-
kernel/trace/blktrace.c:1327:static void blk_register_tracepoints(void)
kernel/trace/blktrace.c-1328-{
]
|
| 239/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 50267
output: 22
thoughts: 26
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing Probe Reference Usage**
Alright, let's see. My initial hunch is to ensure we're accounting for every instance where `get_probe_ref` or `put_probe_ref` are being invoked. I need to make sure we're not missing any potential edge cases or subtly different implementations that could cause issues down the line. We want to be absolutely certain of the scope of these references. This calls for a thorough search of the codebase. I need to know where these functions are getting called to ensure there are no surprises with reference counts or unexpected sharing.
|
| 240/5 |
2026/08/31 21:57 |
tool |
grepper |
0m
Args: map[Expression:(get|put)_probe_ref]
Results: map[Output:kernel/trace/blktrace.c=469=static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
--
kernel/trace/blktrace.c-487-
kernel/trace/blktrace.c:488:static void get_probe_ref(void)
kernel/trace/blktrace.c-489-{
--
kernel/trace/blktrace.c-495-
kernel/trace/blktrace.c:496:static void put_probe_ref(void)
kernel/trace/blktrace.c-497-{
--
kernel/trace/blktrace.c=535=static void blk_trace_cleanup(struct request_queue *q, struct blk_trace *bt)
--
kernel/trace/blktrace.c-539- blk_trace_free(q, bt);
kernel/trace/blktrace.c:540: put_probe_ref();
kernel/trace/blktrace.c-541-}
--
kernel/trace/blktrace.c=730=static void blk_trace_setup_finalize(struct request_queue *q,
--
kernel/trace/blktrace.c-758- rcu_assign_pointer(q->blk_trace, bt);
kernel/trace/blktrace.c:759: get_probe_ref();
kernel/trace/blktrace.c-760-}
--
kernel/trace/blktrace.c=1880=static int blk_trace_remove_queue(struct request_queue *q)
--
kernel/trace/blktrace.c-1890-
kernel/trace/blktrace.c:1891: put_probe_ref();
kernel/trace/blktrace.c-1892- synchronize_rcu();
--
kernel/trace/blktrace.c=1900=static int blk_trace_setup_queue(struct request_queue *q,
--
kernel/trace/blktrace.c-1919- rcu_assign_pointer(q->blk_trace, bt);
kernel/trace/blktrace.c:1920: get_probe_ref();
kernel/trace/blktrace.c-1921- return 0;
]
|
| 241/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 51043
output: 52
thoughts: 29
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Investigating `blk_trace_cleanup`**
Right, time to dig into this. First, I need to make absolutely certain about the implications of `blk_trace_cleanup`. Just calling it isn't enough; I need to understand its context. Let's start by methodically searching for all references to `blk_trace_cleanup`. This isn't just a casual scan; I need to find all the call sites, all the potential uses. Only then can I be confident I understand how this function interacts with the rest of the block tracing infrastructure. I need to know *who* calls it, *when* they call it, and *why* they call it. That should be enough to start my analysis.
|
| 242/5 |
2026/08/31 21:57 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:kernel/trace/blktrace.c IncludeSnippetLines:10 Name:blk_trace_cleanup SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:__blk_trace_remove SourceFile:kernel/trace/blktrace.c SourceLine:552 SourceSnippet: 543: static int __blk_trace_remove(struct request_queue *q)
544: {
545: struct blk_trace *bt;
546:
547: bt = rcu_replace_pointer(q->blk_trace, NULL,
548: lockdep_is_held(&q->debugfs_mutex));
549: if (!bt)
550: return -EINVAL;
551:
552: blk_trace_cleanup(q, bt);
553:
554: return 0;
555: }
]] TruncatedOutput:false]
|
| 243/5 |
2026/08/31 21:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 51542
output: 19
thoughts: 5260
Thoughts: **Review of Blktrace Patch - Thorough Analysis**
Okay, let's dive into this patch. My initial impression is that it's a solid, careful piece of work. The main focus is on improving the robustness of the block tracing probe registration and unregistration process, particularly around concurrency and failure handling. I'm going to run through each diff part to confirm my initial thought.
* **Diff Part 1:** The forward declaration change from `void` to `int` is correct. Standard practice. Nothing to see here.
* **Diff Part 2:** This is the core of the patch. The introduction of the `get_probe_ref()` function and its associated mutex (`blk_probe_mutex`) is all about managing probe registration/unregistration. The use of a reference counter (`blk_probes_ref`) along with the conditional `blk_register_tracepoints()` call under the mutex lock is the correct way to handle this. The key is that the patch *correctly* now ensures that `blk_register_tracepoints()` is only called *once*, even in concurrent scenarios, when the reference count goes from 0 to 1. The introduction of the return value from `blk_register_tracepoints()` and the subsequent cleanup if registration fails is also a crucial improvement. Now, if the registration fails, we decrement the refcount, which is the correct cleanup. The patch elegantly handles the concurrency and the potential for a registration failure.
* **Diff Parts 3, 4, 5, 6, 8:** The changes in `blk_trace_setup_finalize`, `blk_trace_setup`, `blk_trace_setup2`, `compat_blk_trace_setup` and `blk_trace_setup_queue` all focus on ensuring that the probe registration is done *before* the trace data structure (`bt`) is published to the `request_queue` (`q->blk_trace`). This addresses a fundamental lifecycle problem and ensures that callers of `get_probe_ref()` will *always* see a valid state. This is exactly what we want.
* **Diff Part 7:** This is the most crucial part to check: the implementation of `blk_register_tracepoints()` and its associated unwinding. I'm going to review the full ladder and tracepoints to verify that there are no bugs. I see 18 tracepoints being registered and an equally long, carefully crafted unwind ladder on failures. This is *textbook* correct LIFO unwinding. The gotos all line up exactly with reverse registration order. I am also happy to see `tracepoint_synchronize_unregister()` called.
* **Architectural Review Checklist:** I can definitively answer yes to all checklist items:
1. **The Sentinel Test:** The sentinel is not necessary because the caller handles any failures with the correct LIFO unwind ladder.
2. **LIFO Stack Unwinding Symmetry:** As shown in Diff part 7, the unwinding is spot-on.
3. **Ownership Decoupling:** Correct. `rcu_assign_pointer` is done *after* probes are registered.
4. **Codebase Idiom Alignment:** Standard LIFO ladder, error propagation and synchronization are used.
Therefore, `ReviewApproved` should be `true`, and `ReviewComments` should be `[]`. This is an excellent patch.
|
| 244/5 |
2026/08/31 21:58 |
tool |
set-results |
0m
Args: map[ReviewApproved:true ReviewComments:[]]
Results: map[ReviewApproved:true ReviewComments:[]]
|
| 245/4 |
2026/08/31 21:58 |
action |
evaluate-patch-review |
0m
Results: map[NeedsIteration:false ReviewFeedback:]
|
| 246/1 |
2026/08/31 21:58 |
action |
apply-patch |
0m
Results:
|
| 247/1 |
2026/08/31 21:58 |
action |
init-style-items |
0m
Results:
|
| 248/1 |
2026/08/31 21:58 |
action |
run-checkpatch |
0m
Results: map[CheckpatchOutput:total: 0 errors, 0 warnings, 252 lines checked
Your patch has no obvious style problems and is ready for submission.
]
|
| 249/1 |
2026/08/31 21:58 |
loop |
|
0m
|
| 250/2 |
2026/08/31 21:58 |
iteration |
0 |
0m
|
| 251/3 |
2026/08/31 21:58 |
agent |
checkpatch-arbiter |
0m
Model:
Results:
Instruction:
You are an expert Linux kernel maintainer acting as a code style arbiter.
Your task is to review scripts/checkpatch.pl output and reviewer style requests for a proposed patch.
Determine which reported issues are genuine, actionable formatting/style defects (e.g. indentation, whitespace,
naming, syntax style) and should be fixed. List them in ActionableIssues.
Ignore issues that are false positives, intentional constructs (e.g. BUG_ON/XA_BUG_ON in test files, macros,
subsystem conventions), or unfixable without breaking code logic or tests. If no issues should be changed,
leave ActionableIssues empty.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The patch diff is:
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8cd2520b4..c2324298c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -60,7 +60,7 @@ static struct tracer_flags blk_tracer_flags = {
static DEFINE_MUTEX(blk_probe_mutex);
static int blk_probes_ref;
-static void blk_register_tracepoints(void);
+static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
@@ -485,12 +485,18 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
kfree(bt);
}
-static void get_probe_ref(void)
+static int get_probe_ref(void)
{
+ int ret = 0;
+
mutex_lock(&blk_probe_mutex);
- if (++blk_probes_ref == 1)
- blk_register_tracepoints();
+ if (++blk_probes_ref == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ blk_probes_ref--;
+ }
mutex_unlock(&blk_probe_mutex);
+ return ret;
}
static void put_probe_ref(void)
@@ -727,12 +733,14 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
return ERR_PTR(ret);
}
-static void blk_trace_setup_finalize(struct request_queue *q,
- char *name, int version,
- struct blk_trace *bt,
- struct blk_user_trace_setup2 *buts)
+static int blk_trace_setup_finalize(struct request_queue *q,
+ char *name, int version,
+ struct blk_trace *bt,
+ struct blk_user_trace_setup2 *buts)
{
+ int ret;
+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
@@ -755,8 +763,12 @@ static void blk_trace_setup_finalize(struct request_queue *q,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ ret = get_probe_ref();
+ if (ret)
+ return ret;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
+ return 0;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
@@ -792,7 +804,12 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags);
@@ -810,6 +827,7 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
@@ -827,7 +845,12 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
@@ -846,6 +869,7 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
@@ -869,7 +893,12 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
@@ -1324,49 +1353,108 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len)
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static void blk_register_tracepoints(void)
+static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_remap;
+
+ return 0;
+
+out_bio_remap:
+ unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
+out_split:
+ unregister_trace_block_split(blk_add_trace_split, NULL);
+out_unplug:
+ unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
+out_plug:
+ unregister_trace_block_plug(blk_add_trace_plug, NULL);
+out_zone_unplug:
+ unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
+out_zone_plug:
+ unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
+out_zone_update_request:
+ unregister_trace_blk_zone_append_update_request_bio(
+ blk_add_trace_zone_update_request, NULL);
+out_getrq:
+ unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
+out_bio_queue:
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
+out_bio_frontmerge:
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
+out_bio_backmerge:
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
+out_bio_complete:
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
+out_rq_complete:
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
+out_rq_requeue:
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
+out_rq_merge:
+ unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
+out_rq_issue:
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
+out_rq_insert:
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
+ tracepoint_synchronize_unregister();
+out:
+ return ret;
}
static void blk_unregister_tracepoints(void)
@@ -1916,8 +2004,11 @@ static int blk_trace_setup_queue(struct request_queue *q,
blk_trace_setup_lba(bt, bdev);
+ ret = get_probe_ref();
+ if (ret)
+ goto free_bt;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
return 0;
free_bt:
The checkpatch.pl output is:
total: 0 errors, 0 warnings, 252 lines checked
Your patch has no obvious style problems and is ready for submission.
Carefully evaluate each issue and populate ActionableIssues.
|
| 252/4 |
2026/08/31 21:58 |
llm |
checkpatch-arbiter |
0m
Model:
Tokens:
input: 3849
output: 15
thoughts: 519
Thoughts: **Patch Evaluation: Style and Structure**
Okay, let's take a look at this patch. First, I need to check the `checkpatch` output. Alright, looks clean: "0 errors, 0 warnings, 252 lines checked." That's a good start, "Your patch has no obvious style problems and is ready for submission." Still, I should confirm there are no subtle, *actionable* style issues missed by the tool. I need to make sure I'm not overlooking anything. There aren't any reviewer comments to consider, so it's just me.
Let's do a quick visual scan of the diff. I see `static int blk_register_tracepoints(void);`. Looks fine. I see a `get_probe_ref` returning `int`, which is correct. Scanning down... Aha! `blk_trace_setup_finalize`. Wait... is that extra blank line before the opening brace supposed to be there? Let me double-check the context... Okay, yeah, it's there in the *original* code too (the context line shows this). Not an issue.
Now, let's look at the unwinding labels in `blk_register_tracepoints`. Labels and gotos... looks like they are correctly aligned to column 0, which is the standard kernel style.
Alright, so `checkpatch` is happy, and my quick review didn't turn up any actionable style issues. I'm going to set the results to `ActionableIssues: []`. Patch looks good from a style perspective.
|
| 253/4 |
2026/08/31 21:58 |
tool |
set-results |
0m
Args:
Results:
|
| 254/3 |
2026/08/31 21:58 |
action |
evaluate-checkpatch-arbiter |
0m
Results: map[NeedRefinement:false]
|
| 255/3 |
2026/08/31 21:58 |
action |
If |
0m
Args: map[NeedRefinement:false]
|
| 256/1 |
2026/08/31 21:58 |
agent |
fixes-finder |
12m
Model:
Results: map[FixesHash:5f3ea37c7716db4e894a480e0c18b24399595b6b]
Instruction:
You are an experienced Linux kernel developer tasked with identifying the commit
that introduced the bug being fixed. Identifying the correct buggy commit is crucial
for proper kernel maintenance (backporting to stable trees, etc.).
Your investigation strategy:
1. Examine the patch that fixes the bug. Use git tools (like git-log or git-blame)
to trace the history of the lines or functions modified by the patch.
2. Analyze the stack trace in the crash report. Identify the key files and functions
involved in the crash and investigate their history to see when the problematic
logic was introduced.
3. Compare the bug explanation with the commit history to find the point where
the described logic error first appeared.
A bug is typically introduced when a piece of code is first written, or when
a refactoring changed its logic in a way that introduced the bug.
Trace the history of relevant symbols or find when specific code patterns were introduced/removed.
You must provide exactly one bug-introducing commit hash.
If you are unable to confidently determine the bug-introducing commit after investigation,
return an empty string rather than guessing.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The crash is:
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
------------[ cut here ]------------
ret
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline], CPU#1: syz.0.17/6119
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492, CPU#1: syz.0.17/6119
Modules linked in:
CPU: 1 UID: 0 PID: 6119 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Code: c3 31 ff 89 c6 e8 39 42 f7 ff 85 db 0f 85 00 01 00 00 e8 2c 3d f7 ff 48 c7 c7 00 7f bd 8e 5b e9 af 77 db 09 e8 1a 3d f7 ff 90 <0f> 0b 90 e9 e8 fc ff ff e8 0c 3d f7 ff 90 0f 0b 90 e9 07 fd ff ff
RSP: 0018:ffffc9000355fb10 EFLAGS: 00010293
RAX: ffffffff81ce06d6 RBX: 00000000fffffff4 RCX: ffff888114150000
RDX: 0000000000000000 RSI: 00000000fffffff4 RDI: 0000000000000000
RBP: ffffc9000355fc40 R08: ffffc9000355fa47 R09: 1ffff920006abf48
R10: dffffc0000000000 R11: fffff520006abf49 R12: ffff88810888c508
R13: dffffc0000000000 R14: ffff888103f8c638 R15: 0000000000002000
FS: 00007fc861b426c0(0000) GS:ffff8882e873e000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2ed24008 CR3: 00000001fdd32000 CR4: 0000000000352ef0
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc860b9e159
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fc861b42028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fc860e25fa0 RCX: 00007fc860b9e159
RDX: 0000000000000081 RSI: 00002000000002c0 RDI: 0000000000000003
RBP: 00007fc861b42090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
The explanation of the root cause is:
The root cause of the crash is that `blk_register_tracepoints()` uses `WARN_ON(ret)` to check the return values of `register_trace_block_*()` functions. These tracepoint registration functions allocate memory for the probe array and can fail with `-ENOMEM` (e.g., under memory pressure or fault injection, as seen in the syzbot report). When they fail, `WARN_ON()` triggers a kernel panic if `panic_on_warn` is set.
Furthermore, `blk_register_tracepoints()` currently ignores the error and continues, leaving the tracepoints in a partially registered state. Later, when tracing is stopped, `blk_unregister_tracepoints()` unconditionally unregisters all tracepoints. Unregistering a tracepoint that was not successfully registered causes `tracepoint_remove_func()` to return `-ENOENT`, which triggers another `WARN_ON_ONCE` inside `tracepoint_remove_func()`.
To fix this, we need to properly handle the registration failures by returning the error, unregistering the successfully registered tracepoints, and propagating the error up the call stack to fail the blktrace setup.
### Fix Details
1. **Change `blk_register_tracepoints()` to return an `int` and handle errors:**
Instead of `WARN_ON(ret)`, check the return value of each `register_trace_*()` call. If it fails, use `goto` labels to unregister the successfully registered tracepoints in reverse order, and return the error.
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
return ret;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
if (ret)
goto err_issue;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
if (ret)
goto err_merge;
// ... (do this for all 18 tracepoints) ...
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
if (ret)
goto err_rq_remap;
return 0;
err_rq_remap:
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
// ... (unregister labels in reverse order) ...
err_merge:
unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
err_issue:
unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
return ret;
}
```
2. **Propagate the error through `get_probe_ref()`:**
```c
static int get_probe_ref(void)
{
int ret = 0;
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1) {
ret = blk_register_tracepoints();
if (ret)
blk_probes_ref--;
}
mutex_unlock(&blk_probe_mutex);
return ret;
}
```
3. **Propagate the error through `blk_trace_setup_finalize()`:**
```c
static int blk_trace_setup_finalize(struct request_queue *q,
char *name, int version,
struct blk_trace *bt,
struct blk_user_trace_setup2 *buts)
{
int ret;
// ... existing code ...
bt->trace_state = Blktrace_setup;
ret = get_probe_ref();
if (ret)
return ret;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
}
```
4. **Handle the error in the callers of `blk_trace_setup_finalize()`:**
In `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, check the return value of `blk_trace_setup_finalize()`. If it fails, clean up the allocated `bt` and return the error:
```c
ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
```
5. **Handle the error in `blk_trace_setup_queue()`:**
```c
static int blk_trace_setup_queue(struct request_queue *q,
struct block_device *bdev)
{
// ... existing code ...
blk_trace_setup_lba(bt, bdev);
ret = get_probe_ref();
if (ret)
goto free_bt;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
free_bt:
blk_trace_free(q, bt);
return ret;
}
```
The patch that fixes the bug is:
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8cd2520b4..c2324298c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -60,7 +60,7 @@ static struct tracer_flags blk_tracer_flags = {
static DEFINE_MUTEX(blk_probe_mutex);
static int blk_probes_ref;
-static void blk_register_tracepoints(void);
+static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
@@ -485,12 +485,18 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
kfree(bt);
}
-static void get_probe_ref(void)
+static int get_probe_ref(void)
{
+ int ret = 0;
+
mutex_lock(&blk_probe_mutex);
- if (++blk_probes_ref == 1)
- blk_register_tracepoints();
+ if (++blk_probes_ref == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ blk_probes_ref--;
+ }
mutex_unlock(&blk_probe_mutex);
+ return ret;
}
static void put_probe_ref(void)
@@ -727,12 +733,14 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
return ERR_PTR(ret);
}
-static void blk_trace_setup_finalize(struct request_queue *q,
- char *name, int version,
- struct blk_trace *bt,
- struct blk_user_trace_setup2 *buts)
+static int blk_trace_setup_finalize(struct request_queue *q,
+ char *name, int version,
+ struct blk_trace *bt,
+ struct blk_user_trace_setup2 *buts)
{
+ int ret;
+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
@@ -755,8 +763,12 @@ static void blk_trace_setup_finalize(struct request_queue *q,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ ret = get_probe_ref();
+ if (ret)
+ return ret;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
+ return 0;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
@@ -792,7 +804,12 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags);
@@ -810,6 +827,7 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
@@ -827,7 +845,12 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
@@ -846,6 +869,7 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
@@ -869,7 +893,12 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
@@ -1324,49 +1353,108 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len)
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static void blk_register_tracepoints(void)
+static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_remap;
+
+ return 0;
+
+out_bio_remap:
+ unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
+out_split:
+ unregister_trace_block_split(blk_add_trace_split, NULL);
+out_unplug:
+ unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
+out_plug:
+ unregister_trace_block_plug(blk_add_trace_plug, NULL);
+out_zone_unplug:
+ unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
+out_zone_plug:
+ unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
+out_zone_update_request:
+ unregister_trace_blk_zone_append_update_request_bio(
+ blk_add_trace_zone_update_request, NULL);
+out_getrq:
+ unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
+out_bio_queue:
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
+out_bio_frontmerge:
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
+out_bio_backmerge:
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
+out_bio_complete:
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
+out_rq_complete:
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
+out_rq_requeue:
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
+out_rq_merge:
+ unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
+out_rq_issue:
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
+out_rq_insert:
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
+ tracepoint_synchronize_unregister();
+out:
+ return ret;
}
static void blk_unregister_tracepoints(void)
@@ -1916,8 +2004,11 @@ static int blk_trace_setup_queue(struct request_queue *q,
blk_trace_setup_lba(bt, bdev);
+ ret = get_probe_ref();
+ if (ret)
+ goto free_bt;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
return 0;
free_bt:
Search for the commit(s) that introduced this bug.
|
| 257/2 |
2026/08/31 21:58 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 10622
output: 38
thoughts: 191
Thoughts: **Analyzing the Bug-Fixing Patch**
Okay, so the challenge is to pinpoint the commit that initially introduced the bug that this patch in `kernel/trace/blktrace.c` is fixing. Let's dig in. I see the patch's changes revolve around `blk_register_tracepoints()`. Specifically, it's transforming `blk_register_tracepoints()` from a `void` return type with a `WARN_ON` on failure of the `register_trace_block_*()` functions, into an `int`-returning function. Now, if `register_trace_block_*()` fails, it rolls back the registered tracepoints, and crucially, propagates the error up through `get_probe_ref()`, `blk_trace_setup_finalize()`, and `blk_trace_setup_queue()`. This is a significant improvement in error handling.
To find the source of the bug, my immediate thought is to use my favorite tools. I'll reach for `git-log` or `git-blame` on `kernel/trace/blktrace.c` itself. I need to focus on the history of changes related to `blk_register_tracepoints`, the calls to `get_probe_ref`, and any instances where `WARN_ON` was used *within* that function. The switch from void with a warning to an error code and cleanup is the key, so any change around those lines is what I need to see. Hopefully, that will give me enough information to pinpoint when and why the change occurred that ultimately allowed the bug to exist.
|
| 258/2 |
2026/08/31 21:58 |
tool |
git-log |
0m
Args: map[CodeRegexp:blk_register_tracepoints PathPrefix:kernel/trace/blktrace.c]
Results: map[Output:a6da0024ffc1 blktrace: fix unlocked registration of tracepoints
17ba97e347be blktrace: fix blk_probes_ref chaos
cbe28296eb1a blktrace: don't increase blk_probes_ref if failed to setup blk trace
3c289ba7c320 blktrace: remove blk_probe_mutex
2db270a80b8f tracing/blktrace: move the tracing file to kernel/trace
]
|
| 259/2 |
2026/08/31 21:58 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 11326
output: 101
thoughts: 23
Thoughts: Here's a summary of my thinking process, delivered as though I'm the one having these thoughts:
**Analyzing the Git History**
Okay, so I've got a list of commits here. My immediate thought is, let's dive into the history. I need to understand the evolution of this code, the changes that were made, and the context around them.
To do this efficiently, I'm reaching for my trusty Git tools. `git-blame` will be the starting point to identify the author and the specific commit responsible for introducing particular lines of code. This is fantastic for understanding who wrote what and when they last touched it, which is especially handy for debugging or understanding the rationale behind a design choice.
Then, depending on what I find with blame, I'll likely use `git-show` to examine a specific commit in detail. `git-show` will let me see the exact diff introduced by that commit – the additions, deletions, and modifications. This will give me the low-level change data, and the commit message, which will provide context for the changes.
Finally, if I need a broader overview, a longer view of the whole process of changes, I'll turn to `git-log`. This command gives me the entire commit history in a more abstract form, which helps me see the big picture. I can trace the development timeline, visualize branches, and quickly identify potential areas of interest or important milestones.
In essence, I'm formulating a plan that uses a progressive level of detail, starting with identifying the immediate source of changes and then working backwards to understand the larger context. This gives me a comprehensive view of how we arrived at the current state of the code.
|
| 260/2 |
2026/08/31 21:58 |
tool |
git-show |
0m
Args:
Results: map[Output:commit a6da0024ffc19e0d47712bb5ca4fd083f76b07df
Author: Jens Axboe <axboe@kernel.dk>
Date: Sun Nov 5 09:16:09 2017 -0700
blktrace: fix unlocked registration of tracepoints
We need to ensure that tracepoints are registered and unregistered
with the users of them. The existing atomic count isn't enough for
that. Add a lock around the tracepoints, so we serialize access
to them.
This fixes cases where we have multiple users setting up and
tearing down tracepoints, like this:
CPU: 0 PID: 2995 Comm: syzkaller857118 Not tainted
4.14.0-rc5-next-20171018+ #36
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:16 [inline]
dump_stack+0x194/0x257 lib/dump_stack.c:52
panic+0x1e4/0x41c kernel/panic.c:183
__warn+0x1c4/0x1e0 kernel/panic.c:546
report_bug+0x211/0x2d0 lib/bug.c:183
fixup_bug+0x40/0x90 arch/x86/kernel/traps.c:177
do_trap_no_signal arch/x86/kernel/traps.c:211 [inline]
do_trap+0x260/0x390 arch/x86/kernel/traps.c:260
do_error_trap+0x120/0x390 arch/x86/kernel/traps.c:297
do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:310
invalid_op+0x18/0x20 arch/x86/entry/entry_64.S:905
RIP: 0010:tracepoint_add_func kernel/tracepoint.c:210 [inline]
RIP: 0010:tracepoint_probe_register_prio+0x397/0x9a0 kernel/tracepoint.c:283
RSP: 0018:ffff8801d1d1f6c0 EFLAGS: 00010293
RAX: ffff8801d22e8540 RBX: 00000000ffffffef RCX: ffffffff81710f07
RDX: 0000000000000000 RSI: ffffffff85b679c0 RDI: ffff8801d5f19818
RBP: ffff8801d1d1f7c8 R08: ffffffff81710c10 R09: 0000000000000004
R10: ffff8801d1d1f6b0 R11: 0000000000000003 R12: ffffffff817597f0
R13: 0000000000000000 R14: 00000000ffffffff R15: ffff8801d1d1f7a0
tracepoint_probe_register+0x2a/0x40 kernel/tracepoint.c:304
register_trace_block_rq_insert include/trace/events/block.h:191 [inline]
blk_register_tracepoints+0x1e/0x2f0 kernel/trace/blktrace.c:1043
do_blk_trace_setup+0xa10/0xcf0 kernel/trace/blktrace.c:542
blk_trace_setup+0xbd/0x180 kernel/trace/blktrace.c:564
sg_ioctl+0xc71/0x2d90 drivers/scsi/sg.c:1089
vfs_ioctl fs/ioctl.c:45 [inline]
do_vfs_ioctl+0x1b1/0x1520 fs/ioctl.c:685
SYSC_ioctl fs/ioctl.c:700 [inline]
SyS_ioctl+0x8f/0xc0 fs/ioctl.c:691
entry_SYSCALL_64_fastpath+0x1f/0xbe
RIP: 0033:0x444339
RSP: 002b:00007ffe05bb5b18 EFLAGS: 00000206 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00000000006d66c0 RCX: 0000000000444339
RDX: 000000002084cf90 RSI: 00000000c0481273 RDI: 0000000000000009
RBP: 0000000000000082 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000206 R12: ffffffffffffffff
R13: 00000000c0481273 R14: 0000000000000000 R15: 0000000000000000
since we can now run these in parallel. Ensure that the exported helpers
for doing this are grabbing the queue trace mutex.
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Tested-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index ea57dd94b2b2..206e0e2ace53 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -66,7 +66,8 @@ static struct tracer_flags blk_tracer_flags = {
};
/* Global reference count of probes */
-static atomic_t blk_probes_ref = ATOMIC_INIT(0);
+static DEFINE_MUTEX(blk_probe_mutex);
+static int blk_probes_ref;
static void blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
@@ -329,11 +330,26 @@ static void blk_trace_free(struct blk_trace *bt)
kfree(bt);
}
+static void get_probe_ref(void)
+{
+ mutex_lock(&blk_probe_mutex);
+ if (++blk_probes_ref == 1)
+ blk_register_tracepoints();
+ mutex_unlock(&blk_probe_mutex);
+}
+
+static void put_probe_ref(void)
+{
+ mutex_lock(&blk_probe_mutex);
+ if (!--blk_probes_ref)
+ blk_unregister_tracepoints();
+ mutex_unlock(&blk_probe_mutex);
+}
+
static void blk_trace_cleanup(struct blk_trace *bt)
{
blk_trace_free(bt);
- if (atomic_dec_and_test(&blk_probes_ref))
- blk_unregister_tracepoints();
+ put_probe_ref();
}
static int __blk_trace_remove(struct request_queue *q)
@@ -549,8 +565,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (cmpxchg(&q->blk_trace, NULL, bt))
goto err;
- if (atomic_inc_return(&blk_probes_ref) == 1)
- blk_register_tracepoints();
+ get_probe_ref();
ret = 0;
err:
@@ -1596,9 +1611,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (bt == NULL)
return -EINVAL;
- if (atomic_dec_and_test(&blk_probes_ref))
- blk_unregister_tracepoints();
-
+ put_probe_ref();
blk_trace_free(bt);
return 0;
}
@@ -1629,8 +1642,7 @@ static int blk_trace_setup_queue(struct request_queue *q,
if (cmpxchg(&q->blk_trace, NULL, bt))
goto free_bt;
- if (atomic_inc_return(&blk_probes_ref) == 1)
- blk_register_tracepoints();
+ get_probe_ref();
return 0;
free_bt:
]
|
| 261/2 |
2026/08/31 21:58 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 17ba97e347bec9bbc47a0877c7a098708982129d
Author: Li Zefan <lizf@cn.fujitsu.com>
Date: Fri Mar 27 10:20:09 2009 +0800
blktrace: fix blk_probes_ref chaos
Impact: fix mixed ioctl and ftrace-plugin blktrace use refcount bugs
ioctl-based blktrace allocates bt and registers tracepoints when
ioctl(BLKTRACESETUP), and do all cleanups when ioctl(BLKTRACETEARDOWN).
while ftrace-based blktrace allocates/frees bt when:
# echo 1/0 > /sys/block/sda/sda1/trace/enable
and registers/unregisters tracepoints when:
# echo blk/nop > /debugfs/tracing/current_tracer
or
# echo 1/0 > /debugfs/tracing/tracing_enable
The separatation of allocation and registeration causes 2 problems:
1. current user-space blktrace still calls ioctl(TEARDOWN) when
ioctl(SETUP) failed:
# echo 1 > /sys/block/sda/sda1/trace/enable
# blktrace /dev/sda
BLKTRACESETUP: Device or resource busy
^C
and now blk_probes_ref == -1
2. Another way to make blk_probes_ref == -1:
# plugin sdb && mount sdb1
# echo 1 > /sys/block/sdb/sdb1/trace/enable
# remove sdb
This patch does the allocation and registeration when writing
sdaX/trace/enable.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Jens Axboe <jens.axboe@oracle.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 5b28f0f119c5..8d6bd12aab10 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -478,7 +478,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
goto err;
}
- if (atomic_add_return(1, &blk_probes_ref) == 1)
+ if (atomic_inc_return(&blk_probes_ref) == 1)
blk_register_tracepoints();
return 0;
@@ -1091,8 +1091,6 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
- if (atomic_add_return(1, &blk_probes_ref) == 1)
- blk_register_tracepoints();
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1107,15 +1105,10 @@ static int blk_tracer_init(struct trace_array *tr)
static void blk_tracer_stop(struct trace_array *tr)
{
trace_flags |= TRACE_ITER_CONTEXT_INFO;
- if (atomic_dec_and_test(&blk_probes_ref))
- blk_unregister_tracepoints();
}
static void blk_tracer_reset(struct trace_array *tr)
{
- if (!atomic_read(&blk_probes_ref))
- return;
-
blk_tracer_enabled = false;
blk_tracer_stop(tr);
}
@@ -1254,6 +1247,9 @@ static int blk_trace_remove_queue(struct request_queue *q)
if (bt == NULL)
return -EINVAL;
+ if (atomic_dec_and_test(&blk_probes_ref))
+ blk_unregister_tracepoints();
+
kfree(bt);
return 0;
}
@@ -1280,6 +1276,9 @@ static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
return -EBUSY;
}
+ if (atomic_inc_return(&blk_probes_ref) == 1)
+ blk_register_tracepoints();
+
return 0;
}
]
|
| 262/2 |
2026/08/31 21:58 |
tool |
git-show |
0m
Args:
Results: map[Output:commit cbe28296eb1ac441b35cf45804d0ae808add7dd1
Author: Li Zefan <lizf@cn.fujitsu.com>
Date: Fri Mar 20 09:48:47 2009 +0800
blktrace: don't increase blk_probes_ref if failed to setup blk trace
do_blk_trace_setup() may return EBUSY, but the current code
doesn't decrease blk_probes_ref in this case.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <49C2F5FF.80002@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 223b92e77b3f..11e7c8d9d222 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -468,9 +468,6 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
- if (atomic_add_return(1, &blk_probes_ref) == 1)
- blk_register_tracepoints();
-
ret = -EBUSY;
old_bt = xchg(&q->blk_trace, bt);
if (old_bt) {
@@ -478,6 +475,9 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
goto err;
}
+ if (atomic_add_return(1, &blk_probes_ref) == 1)
+ blk_register_tracepoints();
+
return 0;
err:
if (bt) {
]
|
| 263/2 |
2026/08/31 21:58 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 3c289ba7c320560ee74979a8895141c829046a2d
Author: Li Zefan <lizf@cn.fujitsu.com>
Date: Fri Mar 20 09:48:26 2009 +0800
blktrace: remove blk_probe_mutex
blk_register_tracepoints() always returns 0, so make it return void,
thus we don't need to use blk_probe_mutex to protect blk_probes_ref.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jens Axboe <jens.axboe@oracle.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <49C2F5EA.8060606@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 73845b7968bb..223b92e77b3f 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -47,10 +47,9 @@ static struct tracer_flags blk_tracer_flags = {
};
/* Global reference count of probes */
-static DEFINE_MUTEX(blk_probe_mutex);
static atomic_t blk_probes_ref = ATOMIC_INIT(0);
-static int blk_register_tracepoints(void);
+static void blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
/*
@@ -256,10 +255,8 @@ static void blk_trace_cleanup(struct blk_trace *bt)
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
- mutex_lock(&blk_probe_mutex);
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- mutex_unlock(&blk_probe_mutex);
}
int blk_trace_remove(struct request_queue *q)
@@ -471,13 +468,8 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
- mutex_lock(&blk_probe_mutex);
- if (atomic_add_return(1, &blk_probes_ref) == 1) {
- ret = blk_register_tracepoints();
- if (ret)
- goto probe_err;
- }
- mutex_unlock(&blk_probe_mutex);
+ if (atomic_add_return(1, &blk_probes_ref) == 1)
+ blk_register_tracepoints();
ret = -EBUSY;
old_bt = xchg(&q->blk_trace, bt);
@@ -487,9 +479,6 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
}
return 0;
-probe_err:
- atomic_dec(&blk_probes_ref);
- mutex_unlock(&blk_probe_mutex);
err:
if (bt) {
if (bt->msg_file)
@@ -863,7 +852,7 @@ void blk_add_driver_data(struct request_queue *q,
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static int blk_register_tracepoints(void)
+static void blk_register_tracepoints(void)
{
int ret;
@@ -901,7 +890,6 @@ static int blk_register_tracepoints(void)
WARN_ON(ret);
ret = register_trace_block_remap(blk_add_trace_remap);
WARN_ON(ret);
- return 0;
}
static void blk_unregister_tracepoints(void)
@@ -1099,11 +1087,8 @@ static void blk_tracer_print_header(struct seq_file *m)
static void blk_tracer_start(struct trace_array *tr)
{
- mutex_lock(&blk_probe_mutex);
if (atomic_add_return(1, &blk_probes_ref) == 1)
- if (blk_register_tracepoints())
- atomic_dec(&blk_probes_ref);
- mutex_unlock(&blk_probe_mutex);
+ blk_register_tracepoints();
trace_flags &= ~TRACE_ITER_CONTEXT_INFO;
}
@@ -1118,10 +1103,8 @@ static int blk_tracer_init(struct trace_array *tr)
static void blk_tracer_stop(struct trace_array *tr)
{
trace_flags |= TRACE_ITER_CONTEXT_INFO;
- mutex_lock(&blk_probe_mutex);
if (atomic_dec_and_test(&blk_probes_ref))
blk_unregister_tracepoints();
- mutex_unlock(&blk_probe_mutex);
}
static void blk_tracer_reset(struct trace_array *tr)
]
|
| 264/2 |
2026/08/31 21:58 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 17731
output: 26
thoughts: 136
Thoughts: **Investigating the Origins of a Tracepoint Registration**
Okay, so I've got this commit, 3c289ba7c320560ee74979a8895141c829046a2d, that I need to understand better. Before diving into the specifics of *that* commit, my first thought is to contextualize it. What did the codebase look like *before* this point? I need a baseline.
My immediate next step is to figure out the introduction point of `blk_register_tracepoints` or `register_trace_block_*` with `WARN_ON`. I'm going to start by searching the Git history. It's the most efficient way to trace back the origin of these functions, especially since I'm trying to identify the introduction of `WARN_ON` alongside them. I'll search for occurrences of both `register_trace_block_` and `blk_register_tracepoints` *prior* to commit 3c289ba7c320. This should provide the information I'm looking for regarding the changes introduced, and ultimately point to the location of the cause.
|
| 265/2 |
2026/08/31 21:58 |
tool |
git-log |
10m
Error:
Args: map[CodeRegexp:register_trace_block_rq_insert]
Results:
|
| 266/2 |
2026/08/31 22:08 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 18186
output: 36
thoughts: 11
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm already deep in the weeds of Git and development practices:
**Adding PathPrefix to `git-log` - The Nuances**
Right, let's think this through. The first thing that pops into my head is, "Why?" Why am I considering adding `PathPrefix` to the `git-log` output? What specific problem am I trying to solve? Am I aiming for better file-level granularity in a large project? Perhaps I'm trying to filter commits related to a specific feature or subsystem without getting buried in irrelevant noise. Or, maybe I'm troubleshooting a recent change and want to see how a specific file has evolved over time?
Okay, so I understand the *purpose*. Now, how does `PathPrefix` actually accomplish that? It allows me to specify a directory or even a specific file, and then the `git-log` command will only show me commits that modified something *within* that specified path. This is huge for streamlining my investigation of complex codebases. I'm imagining it already: being able to quickly isolate the history of a critical module in a sprawling project.
I need to make sure I understand the potential pitfalls. Are there any caveats I should be aware of? Am I assuming the correct level of granularity? Is there a possibility that my use of `PathPrefix` will exclude important, tangential commits that touch on the file or directory, but aren't strictly contained within it? Let's check the man page and some online examples to ensure I'm using the command in the most effective way. I need to use it in a way that is accurate and useful.
So, okay, `PathPrefix` is a solid addition to my `git-log` workflow. Time to start incorporating it into my daily tasks.
|
| 267/2 |
2026/08/31 22:08 |
tool |
git-log |
0m
Args: map[CodeRegexp:register_trace_block_rq_insert PathPrefix:kernel/trace/]
Results: map[Output:38516ab59fbc tracing: Let tracepoints have data passed to tracepoint callbacks
2db270a80b8f tracing/blktrace: move the tracing file to kernel/trace
]
|
| 268/2 |
2026/08/31 22:08 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 18679
output: 31
thoughts: 62
Thoughts: **Investigating the Tracepoint Registration in blktrace.c**
Okay, let's dive in. I need to figure out what happened in or before commit `2db270a80b8f` regarding `block/blktrace.c`. My hunch is, that's where the relevant changes are. To get a clear picture of what transpired, I'll leverage `git log` specifically targeting the `block/blktrace.c` file. I'm going to look for that file and search the history for occurrences of `blk_register_tracepoints`. That function call, or changes related to it, is probably the key to understanding the context of the change. This should quickly uncover the commit(s) responsible for introducing, modifying, or removing the tracepoint registration logic within that specific module.
|
| 269/2 |
2026/08/31 22:08 |
tool |
git-log |
0m
Args: map[CodeRegexp:blk_register_tracepoints PathPrefix:block/]
Results: map[Output:2db270a80b8f tracing/blktrace: move the tracing file to kernel/trace
c71a89615411 blktrace: add ftrace plugin
5f3ea37c7716 blktrace: port to tracepoints
]
|
| 270/2 |
2026/08/31 22:08 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 19027
output: 53
thoughts: 44
Thoughts: Okay, here's my interpretation of those "thoughts," presented as a first-person summary, keeping in mind my presumed expertise:
**Examining Specific Commits**
Right, let's get down to brass tacks. I need to take a close look at a few specific commits. I want to see commit `5f3ea37c7716`. I know that identifier – it likely represents a significant change, perhaps a crucial bug fix, or maybe a key feature introduction. It's time to refresh my memory or perhaps review for the next analysis.
And let's pull up commit `c71a89615411` as well. I have a recollection of it, and I want to investigate the context, see the code modifications. I'm especially interested in this one, as I have some questions.
Finally, throw in commit `3c289ba7c320` to the queue. I might have tagged it for follow-up earlier, or perhaps it's related to the other two in some way that requires cross-referencing. I'm expecting to analyze the changes in their proper context.
Essentially, I need to see what's happening at those precise points in the history. This is how I'll understand the evolution, the impact, and the potential implications of these commits within this project, product, or research. Time to dig in.
|
| 271/2 |
2026/08/31 22:09 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 5f3ea37c7716db4e894a480e0c18b24399595b6b
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Thu Oct 30 08:34:33 2008 +0100
blktrace: port to tracepoints
This was a forward port of work done by Mathieu Desnoyers, I changed it to
encode the 'what' parameter on the tracepoint name, so that one can register
interest in specific events and not on classes of events to then check the
'what' parameter.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/block/Kconfig b/block/Kconfig
index 1ab7c15c8d7a..290b219fad9c 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -47,6 +47,7 @@ config BLK_DEV_IO_TRACE
depends on SYSFS
select RELAY
select DEBUG_FS
+ select TRACEPOINTS
help
Say Y here if you want to be able to trace the block layer actions
on a given queue. Tracing allows you to see any traffic happening
diff --git a/block/blk-core.c b/block/blk-core.c
index 10e8a64a5a5b..04267d66a2b9 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -28,6 +28,7 @@
#include <linux/task_io_accounting_ops.h>
#include <linux/blktrace_api.h>
#include <linux/fault-inject.h>
+#include <trace/block.h>
#include "blk.h"
@@ -205,7 +206,7 @@ void blk_plug_device(struct request_queue *q)
if (!queue_flag_test_and_set(QUEUE_FLAG_PLUGGED, q)) {
mod_timer(&q->unplug_timer, jiffies + q->unplug_delay);
- blk_add_trace_generic(q, NULL, 0, BLK_TA_PLUG);
+ trace_block_plug(q);
}
}
EXPORT_SYMBOL(blk_plug_device);
@@ -292,9 +293,7 @@ void blk_unplug_work(struct work_struct *work)
struct request_queue *q =
container_of(work, struct request_queue, unplug_work);
- blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_IO, NULL,
- q->rq.count[READ] + q->rq.count[WRITE]);
-
+ trace_block_unplug_io(q);
q->unplug_fn(q);
}
@@ -302,9 +301,7 @@ void blk_unplug_timeout(unsigned long data)
{
struct request_queue *q = (struct request_queue *)data;
- blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_TIMER, NULL,
- q->rq.count[READ] + q->rq.count[WRITE]);
-
+ trace_block_unplug_timer(q);
kblockd_schedule_work(q, &q->unplug_work);
}
@@ -314,9 +311,7 @@ void blk_unplug(struct request_queue *q)
* devices don't necessarily have an ->unplug_fn defined
*/
if (q->unplug_fn) {
- blk_add_trace_pdu_int(q, BLK_TA_UNPLUG_IO, NULL,
- q->rq.count[READ] + q->rq.count[WRITE]);
-
+ trace_block_unplug_io(q);
q->unplug_fn(q);
}
}
@@ -822,7 +817,7 @@ static struct request *get_request(struct request_queue *q, int rw_flags,
if (ioc_batching(q, ioc))
ioc->nr_batch_requests--;
- blk_add_trace_generic(q, bio, rw, BLK_TA_GETRQ);
+ trace_block_getrq(q, bio, rw);
out:
return rq;
}
@@ -848,7 +843,7 @@ static struct request *get_request_wait(struct request_queue *q, int rw_flags,
prepare_to_wait_exclusive(&rl->wait[rw], &wait,
TASK_UNINTERRUPTIBLE);
- blk_add_trace_generic(q, bio, rw, BLK_TA_SLEEPRQ);
+ trace_block_sleeprq(q, bio, rw);
__generic_unplug_device(q);
spin_unlock_irq(q->queue_lock);
@@ -928,7 +923,7 @@ void blk_requeue_request(struct request_queue *q, struct request *rq)
{
blk_delete_timer(rq);
blk_clear_rq_complete(rq);
- blk_add_trace_rq(q, rq, BLK_TA_REQUEUE);
+ trace_block_rq_requeue(q, rq);
if (blk_rq_tagged(rq))
blk_queue_end_tag(q, rq);
@@ -1167,7 +1162,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
if (!ll_back_merge_fn(q, req, bio))
break;
- blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE);
+ trace_block_bio_backmerge(q, bio);
req->biotail->bi_next = bio;
req->biotail = bio;
@@ -1186,7 +1181,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
if (!ll_front_merge_fn(q, req, bio))
break;
- blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE);
+ trace_block_bio_frontmerge(q, bio);
bio->bi_next = req->bio;
req->bio = bio;
@@ -1269,7 +1264,7 @@ static inline void blk_partition_remap(struct bio *bio)
bio->bi_sector += p->start_sect;
bio->bi_bdev = bdev->bd_contains;
- blk_add_trace_remap(bdev_get_queue(bio->bi_bdev), bio,
+ trace_block_remap(bdev_get_queue(bio->bi_bdev), bio,
bdev->bd_dev, bio->bi_sector,
bio->bi_sector - p->start_sect);
}
@@ -1441,10 +1436,10 @@ static inline void __generic_make_request(struct bio *bio)
goto end_io;
if (old_sector != -1)
- blk_add_trace_remap(q, bio, old_dev, bio->bi_sector,
+ trace_block_remap(q, bio, old_dev, bio->bi_sector,
old_sector);
- blk_add_trace_bio(q, bio, BLK_TA_QUEUE);
+ trace_block_bio_queue(q, bio);
old_sector = bio->bi_sector;
old_dev = bio->bi_bdev->bd_dev;
@@ -1656,7 +1651,7 @@ static int __end_that_request_first(struct request *req, int error,
int total_bytes, bio_nbytes, next_idx = 0;
struct bio *bio;
- blk_add_trace_rq(req->q, req, BLK_TA_COMPLETE);
+ trace_block_rq_complete(req->q, req);
/*
* for a REQ_TYPE_BLOCK_PC request, we want to carry any eventual
diff --git a/block/blktrace.c b/block/blktrace.c
index 85049a7e7a17..b0a2cae886db 100644
--- a/block/blktrace.c
+++ b/block/blktrace.c
@@ -23,10 +23,18 @@
#include <linux/mutex.h>
#include <linux/debugfs.h>
#include <linux/time.h>
+#include <trace/block.h>
#include <asm/uaccess.h>
static unsigned int blktrace_seq __read_mostly = 1;
+/* Global reference count of probes */
+static DEFINE_MUTEX(blk_probe_mutex);
+static atomic_t blk_probes_ref = ATOMIC_INIT(0);
+
+static int blk_register_tracepoints(void);
+static void blk_unregister_tracepoints(void);
+
/*
* Send out a notify message.
*/
@@ -119,7 +127,7 @@ static u32 ddir_act[2] __read_mostly = { BLK_TC_ACT(BLK_TC_READ), BLK_TC_ACT(BLK
* The worker for the various blk_add_trace*() types. Fills out a
* blk_io_trace structure and places it in a per-cpu subbuffer.
*/
-void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
+static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
int rw, u32 what, int error, int pdu_len, void *pdu_data)
{
struct task_struct *tsk = current;
@@ -177,8 +185,6 @@ void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
local_irq_restore(flags);
}
-EXPORT_SYMBOL_GPL(__blk_add_trace);
-
static struct dentry *blk_tree_root;
static DEFINE_MUTEX(blk_tree_mutex);
static unsigned int root_users;
@@ -237,6 +243,10 @@ static void blk_trace_cleanup(struct blk_trace *bt)
free_percpu(bt->sequence);
free_percpu(bt->msg_data);
kfree(bt);
+ mutex_lock(&blk_probe_mutex);
+ if (atomic_dec_and_test(&blk_probes_ref))
+ blk_unregister_tracepoints();
+ mutex_unlock(&blk_probe_mutex);
}
int blk_trace_remove(struct request_queue *q)
@@ -428,6 +438,14 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ mutex_lock(&blk_probe_mutex);
+ if (atomic_add_return(1, &blk_probes_ref) == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ goto probe_err;
+ }
+ mutex_unlock(&blk_probe_mutex);
+
ret = -EBUSY;
old_bt = xchg(&q->blk_trace, bt);
if (old_bt) {
@@ -436,6 +454,9 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
}
return 0;
+probe_err:
+ atomic_dec(&blk_probes_ref);
+ mutex_unlock(&blk_probe_mutex);
err:
if (dir)
blk_remove_tree(dir);
@@ -562,3 +583,308 @@ void blk_trace_shutdown(struct request_queue *q)
blk_trace_remove(q);
}
}
+
+/*
+ * blktrace probes
+ */
+
+/**
+ * blk_add_trace_rq - Add a trace for a request oriented action
+ * @q: queue the io is for
+ * @rq: the source request
+ * @what: the action
+ *
+ * Description:
+ * Records an action against a request. Will log the bio offset + size.
+ *
+ **/
+static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
+ u32 what)
+{
+ struct blk_trace *bt = q->blk_trace;
+ int rw = rq->cmd_flags & 0x03;
+
+ if (likely(!bt))
+ return;
+
+ if (blk_discard_rq(rq))
+ rw |= (1 << BIO_RW_DISCARD);
+
+ if (blk_pc_request(rq)) {
+ what |= BLK_TC_ACT(BLK_TC_PC);
+ __blk_add_trace(bt, 0, rq->data_len, rw, what, rq->errors,
+ sizeof(rq->cmd), rq->cmd);
+ } else {
+ what |= BLK_TC_ACT(BLK_TC_FS);
+ __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9,
+ rw, what, rq->errors, 0, NULL);
+ }
+}
+
+static void blk_add_trace_rq_abort(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_ABORT);
+}
+
+static void blk_add_trace_rq_insert(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_INSERT);
+}
+
+static void blk_add_trace_rq_issue(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
+}
+
+static void blk_add_trace_rq_requeue(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_REQUEUE);
+}
+
+static void blk_add_trace_rq_complete(struct request_queue *q, struct request *rq)
+{
+ blk_add_trace_rq(q, rq, BLK_TA_COMPLETE);
+}
+
+/**
+ * blk_add_trace_bio - Add a trace for a bio oriented action
+ * @q: queue the io is for
+ * @bio: the source bio
+ * @what: the action
+ *
+ * Description:
+ * Records an action against a bio. Will log the bio offset + size.
+ *
+ **/
+static void blk_add_trace_bio(struct request_queue *q, struct bio *bio,
+ u32 what)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (likely(!bt))
+ return;
+
+ __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what,
+ !bio_flagged(bio, BIO_UPTODATE), 0, NULL);
+}
+
+static void blk_add_trace_bio_bounce(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_BOUNCE);
+}
+
+static void blk_add_trace_bio_complete(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_COMPLETE);
+}
+
+static void blk_add_trace_bio_backmerge(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_BACKMERGE);
+}
+
+static void blk_add_trace_bio_frontmerge(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_FRONTMERGE);
+}
+
+static void blk_add_trace_bio_queue(struct request_queue *q, struct bio *bio)
+{
+ blk_add_trace_bio(q, bio, BLK_TA_QUEUE);
+}
+
+static void blk_add_trace_getrq(struct request_queue *q, struct bio *bio, int rw)
+{
+ if (bio)
+ blk_add_trace_bio(q, bio, BLK_TA_GETRQ);
+ else {
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt)
+ __blk_add_trace(bt, 0, 0, rw, BLK_TA_GETRQ, 0, 0, NULL);
+ }
+}
+
+
+static void blk_add_trace_sleeprq(struct request_queue *q, struct bio *bio, int rw)
+{
+ if (bio)
+ blk_add_trace_bio(q, bio, BLK_TA_SLEEPRQ);
+ else {
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt)
+ __blk_add_trace(bt, 0, 0, rw, BLK_TA_SLEEPRQ, 0, 0, NULL);
+ }
+}
+
+static void blk_add_trace_plug(struct request_queue *q)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt)
+ __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL);
+}
+
+static void blk_add_trace_unplug_io(struct request_queue *q)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt) {
+ unsigned int pdu = q->rq.count[READ] + q->rq.count[WRITE];
+ __be64 rpdu = cpu_to_be64(pdu);
+
+ __blk_add_trace(bt, 0, 0, 0, BLK_TA_UNPLUG_IO, 0,
+ sizeof(rpdu), &rpdu);
+ }
+}
+
+static void blk_add_trace_unplug_timer(struct request_queue *q)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt) {
+ unsigned int pdu = q->rq.count[READ] + q->rq.count[WRITE];
+ __be64 rpdu = cpu_to_be64(pdu);
+
+ __blk_add_trace(bt, 0, 0, 0, BLK_TA_UNPLUG_TIMER, 0,
+ sizeof(rpdu), &rpdu);
+ }
+}
+
+static void blk_add_trace_split(struct request_queue *q, struct bio *bio,
+ unsigned int pdu)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (bt) {
+ __be64 rpdu = cpu_to_be64(pdu);
+
+ __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw,
+ BLK_TA_SPLIT, !bio_flagged(bio, BIO_UPTODATE),
+ sizeof(rpdu), &rpdu);
+ }
+}
+
+/**
+ * blk_add_trace_remap - Add a trace for a remap operation
+ * @q: queue the io is for
+ * @bio: the source bio
+ * @dev: target device
+ * @from: source sector
+ * @to: target sector
+ *
+ * Description:
+ * Device mapper or raid target sometimes need to split a bio because
+ * it spans a stripe (or similar). Add a trace for that action.
+ *
+ **/
+static void blk_add_trace_remap(struct request_queue *q, struct bio *bio,
+ dev_t dev, sector_t from, sector_t to)
+{
+ struct blk_trace *bt = q->blk_trace;
+ struct blk_io_trace_remap r;
+
+ if (likely(!bt))
+ return;
+
+ r.device = cpu_to_be32(dev);
+ r.device_from = cpu_to_be32(bio->bi_bdev->bd_dev);
+ r.sector = cpu_to_be64(to);
+
+ __blk_add_trace(bt, from, bio->bi_size, bio->bi_rw, BLK_TA_REMAP,
+ !bio_flagged(bio, BIO_UPTODATE), sizeof(r), &r);
+}
+
+/**
+ * blk_add_driver_data - Add binary message with driver-specific data
+ * @q: queue the io is for
+ * @rq: io request
+ * @data: driver-specific data
+ * @len: length of driver-specific data
+ *
+ * Description:
+ * Some drivers might want to write driver-specific data per request.
+ *
+ **/
+void blk_add_driver_data(struct request_queue *q,
+ struct request *rq,
+ void *data, size_t len)
+{
+ struct blk_trace *bt = q->blk_trace;
+
+ if (likely(!bt))
+ return;
+
+ if (blk_pc_request(rq))
+ __blk_add_trace(bt, 0, rq->data_len, 0, BLK_TA_DRV_DATA,
+ rq->errors, len, data);
+ else
+ __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9,
+ 0, BLK_TA_DRV_DATA, rq->errors, len, data);
+}
+EXPORT_SYMBOL_GPL(blk_add_driver_data);
+
+static int blk_register_tracepoints(void)
+{
+ int ret;
+
+ ret = register_trace_block_rq_abort(blk_add_trace_rq_abort);
+ WARN_ON(ret);
+ ret = register_trace_block_rq_insert(blk_add_trace_rq_insert);
+ WARN_ON(ret);
+ ret = register_trace_block_rq_issue(blk_add_trace_rq_issue);
+ WARN_ON(ret);
+ ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue);
+ WARN_ON(ret);
+ ret = register_trace_block_rq_complete(blk_add_trace_rq_complete);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_complete(blk_add_trace_bio_complete);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge);
+ WARN_ON(ret);
+ ret = register_trace_block_bio_queue(blk_add_trace_bio_queue);
+ WARN_ON(ret);
+ ret = register_trace_block_getrq(blk_add_trace_getrq);
+ WARN_ON(ret);
+ ret = register_trace_block_sleeprq(blk_add_trace_sleeprq);
+ WARN_ON(ret);
+ ret = register_trace_block_plug(blk_add_trace_plug);
+ WARN_ON(ret);
+ ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer);
+ WARN_ON(ret);
+ ret = register_trace_block_unplug_io(blk_add_trace_unplug_io);
+ WARN_ON(ret);
+ ret = register_trace_block_split(blk_add_trace_split);
+ WARN_ON(ret);
+ ret = register_trace_block_remap(blk_add_trace_remap);
+ WARN_ON(ret);
+ return 0;
+}
+
+static void blk_unregister_tracepoints(void)
+{
+ unregister_trace_block_remap(blk_add_trace_remap);
+ unregister_trace_block_split(blk_add_trace_split);
+ unregister_trace_block_unplug_io(blk_add_trace_unplug_io);
+ unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer);
+ unregister_trace_block_plug(blk_add_trace_plug);
+ unregister_trace_block_sleeprq(blk_add_trace_sleeprq);
+ unregister_trace_block_getrq(blk_add_trace_getrq);
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue);
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge);
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge);
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete);
+ unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce);
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete);
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue);
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue);
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert);
+ unregister_trace_block_rq_abort(blk_add_trace_rq_abort);
+
+ tracepoint_synchronize_unregister();
+}
diff --git a/block/elevator.c b/block/elevator.c
index 9ac82dde99dd..530fcfe2ef07 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -33,6 +33,7 @@
#include <linux/compiler.h>
#include <linux/delay.h>
#include <linux/blktrace_api.h>
+#include <trace/block.h>
#include <linux/hash.h>
#include <linux/uaccess.h>
@@ -586,7 +587,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
unsigned ordseq;
int unplug_it = 1;
- blk_add_trace_rq(q, rq, BLK_TA_INSERT);
+ trace_block_rq_insert(q, rq);
rq->q = q;
@@ -772,7 +773,7 @@ struct request *elv_next_request(struct request_queue *q)
* not be passed by new incoming requests
*/
rq->cmd_flags |= REQ_STARTED;
- blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
+ trace_block_rq_issue(q, rq);
}
if (!q->boundary_rq || q->boundary_rq == rq) {
@@ -921,7 +922,7 @@ void elv_abort_queue(struct request_queue *q)
while (!list_empty(&q->queue_head)) {
rq = list_entry_rq(q->queue_head.next);
rq->cmd_flags |= REQ_QUIET;
- blk_add_trace_rq(q, rq, BLK_TA_ABORT);
+ trace_block_rq_abort(q, rq);
__blk_end_request(rq, -EIO, blk_rq_bytes(rq));
}
}
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index c99e4728ff41..d23fda178163 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -21,6 +21,7 @@
#include <linux/idr.h>
#include <linux/hdreg.h>
#include <linux/blktrace_api.h>
+#include <trace/block.h>
#define DM_MSG_PREFIX "core"
@@ -504,8 +505,7 @@ static void dec_pending(struct dm_io *io, int error)
end_io_acct(io);
if (io->error != DM_ENDIO_REQUEUE) {
- blk_add_trace_bio(io->md->queue, io->bio,
- BLK_TA_COMPLETE);
+ trace_block_bio_complete(io->md->queue, io->bio);
bio_endio(io->bio, io->error);
}
@@ -598,7 +598,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
if (r == DM_MAPIO_REMAPPED) {
/* the bio has been remapped so dispatch it */
- blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone,
+ trace_block_remap(bdev_get_queue(clone->bi_bdev), clone,
tio->io->bio->bi_bdev->bd_dev,
clone->bi_sector, sector);
diff --git a/fs/bio.c b/fs/bio.c
index 77a55bcceedb..060859c69092 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -26,6 +26,7 @@
#include <linux/mempool.h>
#include <linux/workqueue.h>
#include <linux/blktrace_api.h>
+#include <trace/block.h>
#include <scsi/sg.h> /* for struct sg_iovec */
static struct kmem_cache *bio_slab __read_mostly;
@@ -1263,7 +1264,7 @@ struct bio_pair *bio_split(struct bio *bi, int first_sectors)
if (!bp)
return bp;
- blk_add_trace_pdu_int(bdev_get_queue(bi->bi_bdev), BLK_TA_SPLIT, bi,
+ trace_block_split(bdev_get_queue(bi->bi_bdev), bi,
bi->bi_sector + first_sectors);
BUG_ON(bi->bi_vcnt != 1);
diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
index bdf505d33e77..1dba3493d520 100644
--- a/include/linux/blktrace_api.h
+++ b/include/linux/blktrace_api.h
@@ -160,7 +160,6 @@ struct blk_trace {
extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
extern void blk_trace_shutdown(struct request_queue *);
-extern void __blk_add_trace(struct blk_trace *, sector_t, int, int, u32, int, int, void *);
extern int do_blk_trace_setup(struct request_queue *q,
char *name, dev_t dev, struct blk_user_trace_setup *buts);
extern void __trace_note_message(struct blk_trace *, const char *fmt, ...);
@@ -186,168 +185,8 @@ extern void __trace_note_message(struct blk_trace *, const char *fmt, ...);
} while (0)
#define BLK_TN_MAX_MSG 128
-/**
- * blk_add_trace_rq - Add a trace for a request oriented action
- * @q: queue the io is for
- * @rq: the source request
- * @what: the action
- *
- * Description:
- * Records an action against a request. Will log the bio offset + size.
- *
- **/
-static inline void blk_add_trace_rq(struct request_queue *q, struct request *rq,
- u32 what)
-{
- struct blk_trace *bt = q->blk_trace;
- int rw = rq->cmd_flags & 0x03;
-
- if (likely(!bt))
- return;
-
- if (blk_discard_rq(rq))
- rw |= (1 << BIO_RW_DISCARD);
-
- if (blk_pc_request(rq)) {
- what |= BLK_TC_ACT(BLK_TC_PC);
- __blk_add_trace(bt, 0, rq->data_len, rw, what, rq->errors, sizeof(rq->cmd), rq->cmd);
- } else {
- what |= BLK_TC_ACT(BLK_TC_FS);
- __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9, rw, what, rq->errors, 0, NULL);
- }
-}
-
-/**
- * blk_add_trace_bio - Add a trace for a bio oriented action
- * @q: queue the io is for
- * @bio: the source bio
- * @what: the action
- *
- * Description:
- * Records an action against a bio. Will log the bio offset + size.
- *
- **/
-static inline void blk_add_trace_bio(struct request_queue *q, struct bio *bio,
- u32 what)
-{
- struct blk_trace *bt = q->blk_trace;
-
- if (likely(!bt))
- return;
-
- __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what, !bio_flagged(bio, BIO_UPTODATE), 0, NULL);
-}
-
-/**
- * blk_add_trace_generic - Add a trace for a generic action
- * @q: queue the io is for
- * @bio: the source bio
- * @rw: the data direction
- * @what: the action
- *
- * Description:
- * Records a simple trace
- *
- **/
-static inline void blk_add_trace_generic(struct request_queue *q,
- struct bio *bio, int rw, u32 what)
-{
- struct blk_trace *bt = q->blk_trace;
-
- if (likely(!bt))
- return;
-
- if (bio)
- blk_add_trace_bio(q, bio, what);
- else
- __blk_add_trace(bt, 0, 0, rw, what, 0, 0, NULL);
-}
-
-/**
- * blk_add_trace_pdu_int - Add a trace for a bio with an integer payload
- * @q: queue the io is for
- * @what: the action
- * @bio: the source bio
- * @pdu: the integer payload
- *
- * Description:
- * Adds a trace with some integer payload. This might be an unplug
- * option given as the action, with the depth at unplug time given
- * as the payload
- *
- **/
-static inline void blk_add_trace_pdu_int(struct request_queue *q, u32 what,
- struct bio *bio, unsigned int pdu)
-{
- struct blk_trace *bt = q->blk_trace;
- __be64 rpdu = cpu_to_be64(pdu);
-
- if (likely(!bt))
- return;
-
- if (bio)
- __blk_add_trace(bt, bio->bi_sector, bio->bi_size, bio->bi_rw, what, !bio_flagged(bio, BIO_UPTODATE), sizeof(rpdu), &rpdu);
- else
- __blk_add_trace(bt, 0, 0, 0, what, 0, sizeof(rpdu), &rpdu);
-}
-
-/**
- * blk_add_trace_remap - Add a trace for a remap operation
- * @q: queue the io is for
- * @bio: the source bio
- * @dev: target device
- * @from: source sector
- * @to: target sector
- *
- * Description:
- * Device mapper or raid target sometimes need to split a bio because
- * it spans a stripe (or similar). Add a trace for that action.
- *
- **/
-static inline void blk_add_trace_remap(struct request_queue *q, struct bio *bio,
- dev_t dev, sector_t from, sector_t to)
-{
- struct blk_trace *bt = q->blk_trace;
- struct blk_io_trace_remap r;
-
- if (likely(!bt))
- return;
-
- r.device = cpu_to_be32(dev);
- r.device_from = cpu_to_be32(bio->bi_bdev->bd_dev);
- r.sector = cpu_to_be64(to);
-
- __blk_add_trace(bt, from, bio->bi_size, bio->bi_rw, BLK_TA_REMAP, !bio_flagged(bio, BIO_UPTODATE), sizeof(r), &r);
-}
-
-/**
- * blk_add_driver_data - Add binary message with driver-specific data
- * @q: queue the io is for
- * @rq: io request
- * @data: driver-specific data
- * @len: length of driver-specific data
- *
- * Description:
- * Some drivers might want to write driver-specific data per request.
- *
- **/
-static inline void blk_add_driver_data(struct request_queue *q,
- struct request *rq,
- void *data, size_t len)
-{
- struct blk_trace *bt = q->blk_trace;
-
- if (likely(!bt))
- return;
-
- if (blk_pc_request(rq))
- __blk_add_trace(bt, 0, rq->data_len, 0, BLK_TA_DRV_DATA,
- rq->errors, len, data);
- else
- __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9,
- 0, BLK_TA_DRV_DATA, rq->errors, len, data);
-}
-
+extern void blk_add_driver_data(struct request_queue *q, struct request *rq,
+ void *data, size_t len);
extern int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
char __user *arg);
extern int blk_trace_startstop(struct request_queue *q, int start);
@@ -356,13 +195,8 @@ extern int blk_trace_remove(struct request_queue *q);
#else /* !CONFIG_BLK_DEV_IO_TRACE */
#define blk_trace_ioctl(bdev, cmd, arg) (-ENOTTY)
#define blk_trace_shutdown(q) do { } while (0)
-#define blk_add_trace_rq(q, rq, what) do { } while (0)
-#define blk_add_trace_bio(q, rq, what) do { } while (0)
-#define blk_add_trace_generic(q, rq, rw, what) do { } while (0)
-#define blk_add_trace_pdu_int(q, what, bio, pdu) do { } while (0)
-#define blk_add_trace_remap(q, bio, dev, f, t) do {} while (0)
-#define blk_add_driver_data(q, rq, data, len) do {} while (0)
#define do_blk_trace_setup(q, name, dev, buts) (-ENOTTY)
+#define blk_add_driver_data(q, rq, data, len) do {} while (0)
#define blk_trace_setup(q, name, dev, arg) (-ENOTTY)
#define blk_trace_startstop(q, start) (-ENOTTY)
#define blk_trace_remove(q) (-ENOTTY)
diff --git a/include/trace/block.h b/include/trace/block.h
new file mode 100644
index 000000000000..3cc2675ebf01
--- /dev/null
+++ b/include/trace/block.h
@@ -0,0 +1,60 @@
+#ifndef _TRACE_BLOCK_H
+#define _TRACE_BLOCK_H
+
+#include <linux/blkdev.h>
+#include <linux/tracepoint.h>
+
+DEFINE_TRACE(block_rq_abort,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_rq_insert,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_rq_issue,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_rq_requeue,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_rq_complete,
+ TPPROTO(struct request_queue *q, struct request *rq),
+ TPARGS(q, rq));
+DEFINE_TRACE(block_bio_bounce,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_bio_complete,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_bio_backmerge,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_bio_frontmerge,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_bio_queue,
+ TPPROTO(struct request_queue *q, struct bio *bio),
+ TPARGS(q, bio));
+DEFINE_TRACE(block_getrq,
+ TPPROTO(struct request_queue *q, struct bio *bio, int rw),
+ TPARGS(q, bio, rw));
+DEFINE_TRACE(block_sleeprq,
+ TPPROTO(struct request_queue *q, struct bio *bio, int rw),
+ TPARGS(q, bio, rw));
+DEFINE_TRACE(block_plug,
+ TPPROTO(struct request_queue *q),
+ TPARGS(q));
+DEFINE_TRACE(block_unplug_timer,
+ TPPROTO(struct request_queue *q),
+ TPARGS(q));
+DEFINE_TRACE(block_unplug_io,
+ TPPROTO(struct request_queue *q),
+ TPARGS(q));
+DEFINE_TRACE(block_split,
+ TPPROTO(struct request_queue *q, struct bio *bio, unsigned int pdu),
+ TPARGS(q, bio, pdu));
+DEFINE_TRACE(block_remap,
+ TPPROTO(struct request_queue *q, struct bio *bio, dev_t dev,
+ sector_t from, sector_t to),
+ TPARGS(q, bio, dev, from, to));
+
+#endif
diff --git a/mm/bounce.c b/mm/bounce.c
index 06722c403058..bd1caaa582b8 100644
--- a/mm/bounce.c
+++ b/mm/bounce.c
@@ -14,6 +14,7 @@
#include <linux/hash.h>
#include <linux/highmem.h>
#include <linux/blktrace_api.h>
+#include <trace/block.h>
#include <asm/tlbflush.h>
#define POOL_SIZE 64
@@ -222,7 +223,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig,
if (!bio)
return;
- blk_add_trace_bio(q, *bio_orig, BLK_TA_BOUNCE);
+ trace_block_bio_bounce(q, *bio_orig);
/*
* at least one page was bounced, fill in possible non-highmem
]
|
| 272/2 |
2026/08/31 22:09 |
tool |
git-show |
0m
Args:
Results: map[Output:commit c71a896154119f4ca9e89d6078f5f63ad60ef199
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Fri Jan 23 12:06:27 2009 -0200
blktrace: add ftrace plugin
Impact: New way of using the blktrace infrastructure
This drops the requirement of userspace utilities to use the blktrace
facility.
Configuration is done thru sysfs, adding a "trace" directory to the
partition directory where blktrace can be enabled for the associated
request_queue.
The same filters present in the IOCTL interface are present as sysfs
device attributes.
The /sys/block/sdX/sdXN/trace/enable file allows tracing without any
filters.
The other files in this directory: pid, act_mask, start_lba and end_lba
can be used with the same meaning as with the IOCTL interface.
Using the sysfs interface will only setup the request_queue->blk_trace
fields, tracing will only take place when the "blk" tracer is selected
via the ftrace interface, as in the following example:
To see the trace, one can use the /d/tracing/trace file or the
/d/tracign/trace_pipe file, with semantics defined in the ftrace
documentation in Documentation/ftrace.txt.
[root@f10-1 ~]# cat /t/trace
kjournald-305 [000] 3046.491224: 8,1 A WBS 6367 + 8 <- (8,1) 6304
kjournald-305 [000] 3046.491227: 8,1 Q R 6367 + 8 [kjournald]
kjournald-305 [000] 3046.491236: 8,1 G RB 6367 + 8 [kjournald]
kjournald-305 [000] 3046.491239: 8,1 P NS [kjournald]
kjournald-305 [000] 3046.491242: 8,1 I RBS 6367 + 8 [kjournald]
kjournald-305 [000] 3046.491251: 8,1 D WB 6367 + 8 [kjournald]
kjournald-305 [000] 3046.491610: 8,1 U WS [kjournald] 1
<idle>-0 [000] 3046.511914: 8,1 C RS 6367 + 8 [6367]
[root@f10-1 ~]#
The default line context (prefix) format is the one described in the ftrace
documentation, with the blktrace specific bits using its existing format,
described in blkparse(8).
If one wants to have the classic blktrace formatting, this is possible by
using:
[root@f10-1 ~]# echo blk_classic > /t/trace_options
[root@f10-1 ~]# cat /t/trace
8,1 0 3046.491224 305 A WBS 6367 + 8 <- (8,1) 6304
8,1 0 3046.491227 305 Q R 6367 + 8 [kjournald]
8,1 0 3046.491236 305 G RB 6367 + 8 [kjournald]
8,1 0 3046.491239 305 P NS [kjournald]
8,1 0 3046.491242 305 I RBS 6367 + 8 [kjournald]
8,1 0 3046.491251 305 D WB 6367 + 8 [kjournald]
8,1 0 3046.491610 305 U WS [kjournald] 1
8,1 0 3046.511914 0 C RS 6367 + 8 [6367]
[root@f10-1 ~]#
Using the ftrace standard format allows more flexibility, such
as the ability of asking for backtraces via trace_options:
[root@f10-1 ~]# echo noblk_classic > /t/trace_options
[root@f10-1 ~]# echo stacktrace > /t/trace_options
[root@f10-1 ~]# cat /t/trace
kjournald-305 [000] 3318.826779: 8,1 A WBS 6375 + 8 <- (8,1) 6312
kjournald-305 [000] 3318.826782:
<= submit_bio
<= submit_bh
<= sync_dirty_buffer
<= journal_commit_transaction
<= kjournald
<= kthread
<= child_rip
kjournald-305 [000] 3318.826836: 8,1 Q R 6375 + 8 [kjournald]
kjournald-305 [000] 3318.826837:
<= generic_make_request
<= submit_bio
<= submit_bh
<= sync_dirty_buffer
<= journal_commit_transaction
<= kjournald
<= kthread
Please read the ftrace documentation to use aditional, standardized
tracing filters such as /d/tracing/trace_cpumask, etc.
See also /d/tracing/trace_mark to add comments in the trace stream,
that is equivalent to the /d/block/sdaN/msg interface.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
diff --git a/block/blktrace.c b/block/blktrace.c
index b0a2cae886db..630f167f8240 100644
--- a/block/blktrace.c
+++ b/block/blktrace.c
@@ -25,9 +25,27 @@
#include <linux/time.h>
#include <trace/block.h>
#include <asm/uaccess.h>
+#include <../kernel/trace/trace_output.h>
static unsigned int blktrace_seq __read_mostly = 1;
+static struct trace_array *blk_tr;
+static int __read_mostly blk_tracer_enabled;
+
+/* Select an alternative, minimalistic output than the original one */
+#define TRACE_BLK_OPT_CLASSIC 0x1
+
+static struct tracer_opt blk_tracer_opts[] = {
+ /* Default disable the minimalistic output */
+ { TRACER_OPT(blk_classic, TRACE_BLK_OPT_CLASSIC ) },
+ { }
+};
+
+static struct tracer_flags blk_tracer_flags = {
+ .val = 0,
+ .opts = blk_tracer_opts,
+};
+
/* Global reference count of probes */
static DEFINE_MUTEX(blk_probe_mutex);
static atomic_t blk_probes_ref = ATOMIC_INIT(0);
@@ -43,6 +61,9 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
{
struct blk_io_trace *t;
+ if (!bt->rchan)
+ return;
+
t = relay_reserve(bt->rchan, sizeof(*t) + len);
if (t) {
const int cpu = smp_processor_id();
@@ -90,6 +111,16 @@ void __trace_note_message(struct blk_trace *bt, const char *fmt, ...)
unsigned long flags;
char *buf;
+ if (blk_tr) {
+ va_start(args, fmt);
+ ftrace_vprintk(fmt, args);
+ va_end(args);
+ return;
+ }
+
+ if (!bt->msg_data)
+ return;
+
local_irq_save(flags);
buf = per_cpu_ptr(bt->msg_data, smp_processor_id());
va_start(args, fmt);
@@ -131,13 +162,14 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
int rw, u32 what, int error, int pdu_len, void *pdu_data)
{
struct task_struct *tsk = current;
+ struct ring_buffer_event *event = NULL;
struct blk_io_trace *t;
unsigned long flags;
unsigned long *sequence;
pid_t pid;
- int cpu;
+ int cpu, pc = 0;
- if (unlikely(bt->trace_state != Blktrace_running))
+ if (unlikely(bt->trace_state != Blktrace_running || !blk_tracer_enabled))
return;
what |= ddir_act[rw & WRITE];
@@ -150,6 +182,24 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
pid = tsk->pid;
if (unlikely(act_log_check(bt, what, sector, pid)))
return;
+ cpu = raw_smp_processor_id();
+
+ if (blk_tr) {
+ struct trace_entry *ent;
+ tracing_record_cmdline(current);
+
+ event = ring_buffer_lock_reserve(blk_tr->buffer,
+ sizeof(*t) + pdu_len, &flags);
+ if (!event)
+ return;
+
+ ent = ring_buffer_event_data(event);
+ t = (struct blk_io_trace *)ent;
+ pc = preempt_count();
+ tracing_generic_entry_update(ent, 0, pc);
+ ent->type = TRACE_BLK;
+ goto record_it;
+ }
/*
* A word about the locking here - we disable interrupts to reserve
@@ -163,23 +213,33 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes,
t = relay_reserve(bt->rchan, sizeof(*t) + pdu_len);
if (t) {
- cpu = smp_processor_id();
sequence = per_cpu_ptr(bt->sequence, cpu);
t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION;
t->sequence = ++(*sequence);
t->time = ktime_to_ns(ktime_get());
+ t->cpu = cpu;
+ t->pid = pid;
+record_it:
t->sector = sector;
t->bytes = bytes;
t->action = what;
- t->pid = pid;
t->device = bt->dev;
- t->cpu = cpu;
t->error = error;
t->pdu_len = pdu_len;
if (pdu_len)
memcpy((void *) t + sizeof(*t), pdu_data, pdu_len);
+
+ if (blk_tr) {
+ ring_buffer_unlock_commit(blk_tr->buffer, event, flags);
+ if (pid != 0 &&
+ (blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC) == 0 &&
+ (trace_flags & TRACE_ITER_STACKTRACE) != 0)
+ __trace_stack(blk_tr, NULL, flags, 5, pc);
+ trace_wake_up();
+ return;
+ }
}
local_irq_restore(flags);
@@ -888,3 +948,584 @@ static void blk_unregister_tracepoints(void)
tracepoint_synchronize_unregister();
}
+
+/*
+ * struct blk_io_tracer formatting routines
+ */
+
+static void fill_rwbs(char *rwbs, const struct blk_io_trace *t)
+{
+ int i = 0;
+
+ if (t->action & BLK_TC_DISCARD) rwbs[i++] = 'D';
+ else if (t->action & BLK_TC_WRITE) rwbs[i++] = 'W';
+ else if (t->bytes) rwbs[i++] = 'R';
+ else rwbs[i++] = 'N';
+
+ if (t->action & BLK_TC_AHEAD) rwbs[i++] = 'A';
+ if (t->action & BLK_TC_BARRIER) rwbs[i++] = 'B';
+ if (t->action & BLK_TC_SYNC) rwbs[i++] = 'S';
+ if (t->action & BLK_TC_META) rwbs[i++] = 'M';
+
+ rwbs[i] = '\0';
+}
+
+static inline
+const struct blk_io_trace *te_blk_io_trace(const struct trace_entry *ent)
+{
+ return (const struct blk_io_trace *)ent;
+}
+
+static inline const void *pdu_start(const struct trace_entry *ent)
+{
+ return te_blk_io_trace(ent) + 1;
+}
+
+static inline u32 t_sec(const struct trace_entry *ent)
+{
+ return te_blk_io_trace(ent)->bytes >> 9;
+}
+
+static inline unsigned long long t_sector(const struct trace_entry *ent)
+{
+ return te_blk_io_trace(ent)->sector;
+}
+
+static inline __u16 t_error(const struct trace_entry *ent)
+{
+ return te_blk_io_trace(ent)->sector;
+}
+
+static __u64 get_pdu_int(const struct trace_entry *ent)
+{
+ const __u64 *val = pdu_start(ent);
+ return be64_to_cpu(*val);
+}
+
+static void get_pdu_remap(const struct trace_entry *ent,
+ struct blk_io_trace_remap *r)
+{
+ const struct blk_io_trace_remap *__r = pdu_start(ent);
+ __u64 sector = __r->sector;
+
+ r->device = be32_to_cpu(__r->device);
+ r->device_from = be32_to_cpu(__r->device_from);
+ r->sector = be64_to_cpu(sector);
+}
+
+static int blk_log_action_iter(struct trace_iterator *iter, const char *act)
+{
+ char rwbs[6];
+ unsigned long long ts = ns2usecs(iter->ts);
+ unsigned long usec_rem = do_div(ts, USEC_PER_SEC);
+ unsigned secs = (unsigned long)ts;
+ const struct trace_entry *ent = iter->ent;
+ const struct blk_io_trace *t = (const struct blk_io_trace *)ent;
+
+ fill_rwbs(rwbs, t);
+
+ return trace_seq_printf(&iter->seq,
+ "%3d,%-3d %2d %5d.%06lu %5u %2s %3s ",
+ MAJOR(t->device), MINOR(t->device), iter->cpu,
+ secs, usec_rem, ent->pid, act, rwbs);
+}
+
+static int blk_log_action_seq(struct trace_seq *s, const struct blk_io_trace *t,
+ const char *act)
+{
+ char rwbs[6];
+ fill_rwbs(rwbs, t);
+ return trace_seq_printf(s, "%3d,%-3d %2s %3s ",
+ MAJOR(t->device), MINOR(t->device), act, rwbs);
+}
+
+static int blk_log_generic(struct trace_seq *s, const struct trace_entry *ent)
+{
+ const char *cmd = trace_find_cmdline(ent->pid);
+
+ if (t_sec(ent))
+ return trace_seq_printf(s, "%llu + %u [%s]\n",
+ t_sector(ent), t_sec(ent), cmd);
+ return trace_seq_printf(s, "[%s]\n", cmd);
+}
+
+static int blk_log_with_error(struct trace_seq *s, const struct trace_entry *ent)
+{
+ if (t_sec(ent))
+ return trace_seq_printf(s, "%llu + %u [%d]\n", t_sector(ent),
+ t_sec(ent), t_error(ent));
+ return trace_seq_printf(s, "%llu [%d]\n", t_sector(ent), t_error(ent));
+}
+
+static int blk_log_remap(struct trace_seq *s, const struct trace_entry *ent)
+{
+ struct blk_io_trace_remap r = { .device = 0, };
+
+ get_pdu_remap(ent, &r);
+ return trace_seq_printf(s, "%llu + %u <- (%d,%d) %llu\n",
+ t_sector(ent),
+ t_sec(ent), MAJOR(r.device), MINOR(r.device),
+ (unsigned long long)r.sector);
+}
+
+static int blk_log_plug(struct trace_seq *s, const struct trace_entry *ent)
+{
+ return trace_seq_printf(s, "[%s]\n", trace_find_cmdline(ent->pid));
+}
+
+static int blk_log_unplug(struct trace_seq *s, const struct trace_entry *ent)
+{
+ return trace_seq_printf(s, "[%s] %llu\n", trace_find_cmdline(ent->pid),
+ get_pdu_int(ent));
+}
+
+static int blk_log_split(struct trace_seq *s, const struct trace_entry *ent)
+{
+ return trace_seq_printf(s, "%llu / %llu [%s]\n", t_sector(ent),
+ get_pdu_int(ent), trace_find_cmdline(ent->pid));
+}
+
+/*
+ * struct tracer operations
+ */
+
+static void blk_tracer_print_header(struct seq_file *m)
+{
+ if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC))
+ return;
+ seq_puts(m, "# DEV CPU TIMESTAMP PID ACT FLG\n"
+ "# | | | | | |\n");
+}
+
+static void blk_tracer_start(struct trace_array *tr)
+{
+ int cpu;
+
+ tr->time_start = ftrace_now(tr->cpu);
+
+ for_each_online_cpu(cpu)
+ tracing_reset(tr, cpu);
+
+ mutex_lock(&blk_probe_mutex);
+ if (atomic_add_return(1, &blk_probes_ref) == 1)
+ if (blk_register_tracepoints())
+ atomic_dec(&blk_probes_ref);
+ mutex_unlock(&blk_probe_mutex);
+}
+
+static int blk_tracer_init(struct trace_array *tr)
+{
+ blk_tr = tr;
+ blk_tracer_start(tr);
+ mutex_lock(&blk_probe_mutex);
+ blk_tracer_enabled++;
+ mutex_unlock(&blk_probe_mutex);
+ return 0;
+}
+
+static void blk_tracer_stop(struct trace_array *tr)
+{
+ mutex_lock(&blk_probe_mutex);
+ if (atomic_dec_and_test(&blk_probes_ref))
+ blk_unregister_tracepoints();
+ mutex_unlock(&blk_probe_mutex);
+}
+
+static void blk_tracer_reset(struct trace_array *tr)
+{
+ if (!atomic_read(&blk_probes_ref))
+ return;
+
+ mutex_lock(&blk_probe_mutex);
+ blk_tracer_enabled--;
+ WARN_ON(blk_tracer_enabled < 0);
+ mutex_unlock(&blk_probe_mutex);
+
+ blk_tracer_stop(tr);
+}
+
+static struct {
+ const char *act[2];
+ int (*print)(struct trace_seq *s, const struct trace_entry *ent);
+} what2act[] __read_mostly = {
+ [__BLK_TA_QUEUE] = {{ "Q", "queue" }, blk_log_generic },
+ [__BLK_TA_BACKMERGE] = {{ "M", "backmerge" }, blk_log_generic },
+ [__BLK_TA_FRONTMERGE] = {{ "F", "frontmerge" }, blk_log_generic },
+ [__BLK_TA_GETRQ] = {{ "G", "getrq" }, blk_log_generic },
+ [__BLK_TA_SLEEPRQ] = {{ "S", "sleeprq" }, blk_log_generic },
+ [__BLK_TA_REQUEUE] = {{ "R", "requeue" }, blk_log_with_error },
+ [__BLK_TA_ISSUE] = {{ "D", "issue" }, blk_log_generic },
+ [__BLK_TA_COMPLETE] = {{ "C", "complete" }, blk_log_with_error },
+ [__BLK_TA_PLUG] = {{ "P", "plug" }, blk_log_plug },
+ [__BLK_TA_UNPLUG_IO] = {{ "U", "unplug_io" }, blk_log_unplug },
+ [__BLK_TA_UNPLUG_TIMER] = {{ "UT", "unplug_timer" }, blk_log_unplug },
+ [__BLK_TA_INSERT] = {{ "I", "insert" }, blk_log_generic },
+ [__BLK_TA_SPLIT] = {{ "X", "split" }, blk_log_split },
+ [__BLK_TA_BOUNCE] = {{ "B", "bounce" }, blk_log_generic },
+ [__BLK_TA_REMAP] = {{ "A", "remap" }, blk_log_remap },
+};
+
+static int blk_trace_event_print(struct trace_seq *s, struct trace_entry *ent,
+ int flags)
+{
+ const struct blk_io_trace *t = (struct blk_io_trace *)ent;
+ const u16 what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+ int ret;
+
+ if (unlikely(what == 0 || what > ARRAY_SIZE(what2act)))
+ ret = trace_seq_printf(s, "Bad pc action %x\n", what);
+ else {
+ const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
+ ret = blk_log_action_seq(s, t, what2act[what].act[long_act]);
+ if (ret)
+ ret = what2act[what].print(s, ent);
+ }
+
+ return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
+}
+
+static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter)
+{
+ const struct blk_io_trace *t;
+ u16 what;
+ int ret;
+
+ if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC))
+ return TRACE_TYPE_UNHANDLED;
+
+ t = (const struct blk_io_trace *)iter->ent;
+ what = t->action & ((1 << BLK_TC_SHIFT) - 1);
+
+ if (unlikely(what == 0 || what > ARRAY_SIZE(what2act)))
+ ret = trace_seq_printf(&iter->seq, "Bad pc action %x\n", what);
+ else {
+ const bool long_act = !!(trace_flags & TRACE_ITER_VERBOSE);
+ ret = blk_log_action_iter(iter, what2act[what].act[long_act]);
+ if (ret)
+ ret = what2act[what].print(&iter->seq, iter->ent);
+ }
+
+ return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
+}
+
+static struct tracer blk_tracer __read_mostly = {
+ .name = "blk",
+ .init = blk_tracer_init,
+ .reset = blk_tracer_reset,
+ .start = blk_tracer_start,
+ .stop = blk_tracer_stop,
+ .print_header = blk_tracer_print_header,
+ .print_line = blk_tracer_print_line,
+ .flags = &blk_tracer_flags,
+};
+
+static struct trace_event trace_blk_event = {
+ .type = TRACE_BLK,
+ .trace = blk_trace_event_print,
+ .latency_trace = blk_trace_event_print,
+ .raw = trace_nop_print,
+ .hex = trace_nop_print,
+ .binary = trace_nop_print,
+};
+
+static int __init init_blk_tracer(void)
+{
+ if (!register_ftrace_event(&trace_blk_event)) {
+ pr_warning("Warning: could not register block events\n");
+ return 1;
+ }
+
+ if (register_tracer(&blk_tracer) != 0) {
+ pr_warning("Warning: could not register the block tracer\n");
+ unregister_ftrace_event(&trace_blk_event);
+ return 1;
+ }
+
+ return 0;
+}
+
+device_initcall(init_blk_tracer);
+
+static int blk_trace_remove_queue(struct request_queue *q)
+{
+ struct blk_trace *bt;
+
+ bt = xchg(&q->blk_trace, NULL);
+ if (bt == NULL)
+ return -EINVAL;
+
+ kfree(bt);
+ return 0;
+}
+
+/*
+ * Setup everything required to start tracing
+ */
+static int blk_trace_setup_queue(struct request_queue *q, dev_t dev)
+{
+ struct blk_trace *old_bt, *bt = NULL;
+ int ret;
+
+ ret = -ENOMEM;
+ bt = kzalloc(sizeof(*bt), GFP_KERNEL);
+ if (!bt)
+ goto err;
+
+ bt->dev = dev;
+ bt->act_mask = (u16)-1;
+ bt->end_lba = -1ULL;
+ bt->trace_state = Blktrace_running;
+
+ old_bt = xchg(&q->blk_trace, bt);
+ if (old_bt != NULL) {
+ (void)xchg(&q->blk_trace, old_bt);
+ kfree(bt);
+ ret = -EBUSY;
+ }
+ return 0;
+err:
+ return ret;
+}
+
+/*
+ * sysfs interface to enable and configure tracing
+ */
+
+static ssize_t sysfs_blk_trace_enable_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct hd_struct *p = dev_to_part(dev);
+ struct block_device *bdev;
+ ssize_t ret = -ENXIO;
+
+ lock_kernel();
+ bdev = bdget(part_devt(p));
+ if (bdev != NULL) {
+ struct request_queue *q = bdev_get_queue(bdev);
+
+ if (q != NULL) {
+ mutex_lock(&bdev->bd_mutex);
+ ret = sprintf(buf, "%u\n", !!q->blk_trace);
+ mutex_unlock(&bdev->bd_mutex);
+ }
+
+ bdput(bdev);
+ }
+
+ unlock_kernel();
+ return ret;
+}
+
+static ssize_t sysfs_blk_trace_enable_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct block_device *bdev;
+ struct request_queue *q;
+ struct hd_struct *p;
+ int value;
+ ssize_t ret = -ENXIO;
+
+ if (count == 0 || sscanf(buf, "%d", &value) != 1)
+ goto out;
+
+ lock_kernel();
+ p = dev_to_part(dev);
+ bdev = bdget(part_devt(p));
+ if (bdev == NULL)
+ goto out_unlock_kernel;
+
+ q = bdev_get_queue(bdev);
+ if (q == NULL)
+ goto out_bdput;
+
+ mutex_lock(&bdev->bd_mutex);
+ if (value)
+ ret = blk_trace_setup_queue(q, bdev->bd_dev);
+ else
+ ret = blk_trace_remove_queue(q);
+ mutex_unlock(&bdev->bd_mutex);
+
+ if (ret == 0)
+ ret = count;
+out_bdput:
+ bdput(bdev);
+out_unlock_kernel:
+ unlock_kernel();
+out:
+ return ret;
+}
+
+static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf);
+static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count);
+#define BLK_TRACE_DEVICE_ATTR(_name) \
+ DEVICE_ATTR(_name, S_IRUGO | S_IWUSR, \
+ sysfs_blk_trace_attr_show, \
+ sysfs_blk_trace_attr_store)
+
+static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR,
+ sysfs_blk_trace_enable_show, sysfs_blk_trace_enable_store);
+static BLK_TRACE_DEVICE_ATTR(act_mask);
+static BLK_TRACE_DEVICE_ATTR(pid);
+static BLK_TRACE_DEVICE_ATTR(start_lba);
+static BLK_TRACE_DEVICE_ATTR(end_lba);
+
+static struct attribute *blk_trace_attrs[] = {
+ &dev_attr_enable.attr,
+ &dev_attr_act_mask.attr,
+ &dev_attr_pid.attr,
+ &dev_attr_start_lba.attr,
+ &dev_attr_end_lba.attr,
+ NULL
+};
+
+struct attribute_group blk_trace_attr_group = {
+ .name = "trace",
+ .attrs = blk_trace_attrs,
+};
+
+static int blk_str2act_mask(const char *str)
+{
+ int mask = 0;
+ char *copy = kstrdup(str, GFP_KERNEL), *s;
+
+ if (copy == NULL)
+ return -ENOMEM;
+
+ s = strstrip(copy);
+
+ while (1) {
+ char *sep = strchr(s, ',');
+
+ if (sep != NULL)
+ *sep = '\0';
+
+ if (strcasecmp(s, "barrier") == 0)
+ mask |= BLK_TC_BARRIER;
+ else if (strcasecmp(s, "complete") == 0)
+ mask |= BLK_TC_COMPLETE;
+ else if (strcasecmp(s, "fs") == 0)
+ mask |= BLK_TC_FS;
+ else if (strcasecmp(s, "issue") == 0)
+ mask |= BLK_TC_ISSUE;
+ else if (strcasecmp(s, "pc") == 0)
+ mask |= BLK_TC_PC;
+ else if (strcasecmp(s, "queue") == 0)
+ mask |= BLK_TC_QUEUE;
+ else if (strcasecmp(s, "read") == 0)
+ mask |= BLK_TC_READ;
+ else if (strcasecmp(s, "requeue") == 0)
+ mask |= BLK_TC_REQUEUE;
+ else if (strcasecmp(s, "sync") == 0)
+ mask |= BLK_TC_SYNC;
+ else if (strcasecmp(s, "write") == 0)
+ mask |= BLK_TC_WRITE;
+
+ if (sep == NULL)
+ break;
+
+ s = sep + 1;
+ }
+ kfree(copy);
+
+ return mask;
+}
+
+static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct hd_struct *p = dev_to_part(dev);
+ struct request_queue *q;
+ struct block_device *bdev;
+ ssize_t ret = -ENXIO;
+
+ lock_kernel();
+ bdev = bdget(part_devt(p));
+ if (bdev == NULL)
+ goto out_unlock_kernel;
+
+ q = bdev_get_queue(bdev);
+ if (q == NULL)
+ goto out_bdput;
+ mutex_lock(&bdev->bd_mutex);
+ if (q->blk_trace == NULL)
+ ret = sprintf(buf, "disabled\n");
+ else if (attr == &dev_attr_act_mask)
+ ret = sprintf(buf, "%#x\n", q->blk_trace->act_mask);
+ else if (attr == &dev_attr_pid)
+ ret = sprintf(buf, "%u\n", q->blk_trace->pid);
+ else if (attr == &dev_attr_start_lba)
+ ret = sprintf(buf, "%llu\n", q->blk_trace->start_lba);
+ else if (attr == &dev_attr_end_lba)
+ ret = sprintf(buf, "%llu\n", q->blk_trace->end_lba);
+ mutex_unlock(&bdev->bd_mutex);
+out_bdput:
+ bdput(bdev);
+out_unlock_kernel:
+ unlock_kernel();
+ return ret;
+}
+
+static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct block_device *bdev;
+ struct request_queue *q;
+ struct hd_struct *p;
+ u64 value;
+ ssize_t ret = -ENXIO;
+
+ if (count == 0)
+ goto out;
+
+ if (attr == &dev_attr_act_mask) {
+ if (sscanf(buf, "%llx", &value) != 1) {
+ /* Assume it is a list of trace category names */
+ value = blk_str2act_mask(buf);
+ if (value < 0)
+ goto out;
+ }
+ } else if (sscanf(buf, "%llu", &value) != 1)
+ goto out;
+
+ lock_kernel();
+ p = dev_to_part(dev);
+ bdev = bdget(part_devt(p));
+ if (bdev == NULL)
+ goto out_unlock_kernel;
+
+ q = bdev_get_queue(bdev);
+ if (q == NULL)
+ goto out_bdput;
+
+ mutex_lock(&bdev->bd_mutex);
+ ret = 0;
+ if (q->blk_trace == NULL)
+ ret = blk_trace_setup_queue(q, bdev->bd_dev);
+
+ if (ret == 0) {
+ if (attr == &dev_attr_act_mask)
+ q->blk_trace->act_mask = value;
+ else if (attr == &dev_attr_pid)
+ q->blk_trace->pid = value;
+ else if (attr == &dev_attr_start_lba)
+ q->blk_trace->start_lba = value;
+ else if (attr == &dev_attr_end_lba)
+ q->blk_trace->end_lba = value;
+ ret = count;
+ }
+ mutex_unlock(&bdev->bd_mutex);
+out_bdput:
+ bdput(bdev);
+out_unlock_kernel:
+ unlock_kernel();
+out:
+ return ret;
+}
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 6d720243f5f4..01714efdc65a 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -268,6 +268,10 @@ ssize_t part_fail_store(struct device *dev,
}
#endif
+#ifdef CONFIG_BLK_DEV_IO_TRACE
+extern struct attribute_group blk_trace_attr_group;
+#endif
+
static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL);
static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
@@ -294,6 +298,9 @@ static struct attribute_group part_attr_group = {
static struct attribute_group *part_attr_groups[] = {
&part_attr_group,
+#ifdef CONFIG_BLK_DEV_IO_TRACE
+ &blk_trace_attr_group,
+#endif
NULL
};
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index b96037d970df..e603a291134b 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -32,6 +32,7 @@ enum trace_type {
TRACE_KMEM_ALLOC,
TRACE_KMEM_FREE,
TRACE_POWER,
+ TRACE_BLK,
__TRACE_LAST_TYPE,
};
]
|
| 273/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 41733
output: 37
thoughts: 396
Thoughts: **Analyzing Tracepoint Registration in blktrace**
Okay, let's break this down. I'm looking at commit `5f3ea37c7716db4e894a480e0c18b24399595b6b`, specifically the "blktrace: port to tracepoints" change. The key thing here is the introduction of `blk_register_tracepoints()`. I see the code, and it's calling `register_trace_block_*` functions, each followed by `WARN_ON(ret)`.
Now, here's where my expert intuition kicks in. My immediate question is whether those `register_trace_block_*` calls *always* behaved this way. Did they always potentially return an error, and did this commit introduce that behavior? Or was that error checking – and the `WARN_ON` – added later? I need to understand when `tracepoint_probe_register` started allocating memory or returning `ENOMEM` or other error codes. This might have been present in `5f3ea37c7716`, or added later.
To clarify, I need to investigate the history of `tracepoint_probe_register` itself. I need to check the Git log. I need to search for occurrences of `tracepoint_probe_register`, as well as `register_trace_` and possibly the source file, `tracepoint.c`, to figure out when error handling and memory allocation became relevant in the context of these tracepoint registrations. The goal is to isolate the point at which this error handling became an issue.
|
| 274/2 |
2026/08/31 22:09 |
tool |
git-log |
0m
Args: map[CodeRegexp:register_trace_block PathPrefix:kernel/trace/blktrace.c]
Results: map[Output:eeadd68e2a5f block: remove bounce buffering support
b81b8f40c5b4 block: remove the unused block_sleeprq tracepoint
f3bdc62fd82e blktrace: Provide event for request merging
cee4b7ce3f91 blktrace: remove the unused block_rq_abort tracepoint
49cac01e1fa7 block: make unplug timer trace event correspond to the schedule() unplug
d9c978331790 block: remove block_unplug_timer() trace point
d07335e51df0 block: Rename "block_remap" tracepoint to "block_bio_remap" to clarify the event.
38516ab59fbc tracing: Let tracepoints have data passed to tracepoint callbacks
b0da3f0dada7 Add a tracepoint for block request remapping
2db270a80b8f tracing/blktrace: move the tracing file to kernel/trace
]
|
| 275/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 42768
output: 26
thoughts: 66
Thoughts: Here's my thinking process:
**Diving into Tracepoint History**
Okay, so I'm trying to figure out something about the tracepoint implementation, probably debugging a potential issue. My first instinct is to go right to the source: `tracepoint.c` and how it handles registration. I need to understand how the `register_trace_` function works – its history, its evolution.
I'm thinking commit 5f3ea37c7716 might be a key point. I want to see when that landed, and then I'll likely need to check the commits immediately before and after it to understand any context or related changes. That usually gives me a good sense of the scope of any changes.
Hold on, I also need to consider the environment I'm working with. Different kernel versions can change how features work. It's important to understand this because there could have been significant changes to the code. I know there were changes to tracepoints around the 2.6.28 kernel, so let's start there. I'll need to check the tracepoint implementation in that version to establish a baseline for comparison.
|
| 276/2 |
2026/08/31 22:09 |
tool |
git-log |
0m
Args: map[Count:5 PathPrefix:kernel/tracepoint.c]
Results: map[Output:fad217e16fde tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func()
323bbfcf1ef8 Convert 'alloc_flex' family to use the new default GFP_KERNEL argument
bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
a46023d5616e tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast
]
|
| 277/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 43267
output: 34
thoughts: 19
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:
**Initial Dive into Tracepoint.c**
Okay, let's get down to brass tacks. I'm starting at the very beginning, the initial commit for tracepoints in `kernel/tracepoint.c`. I want to understand the foundational architecture, the core data structures, and the basic mechanisms implemented before things get layered on top. I'm looking for the elegance (or lack thereof) in the early design choices. What's the fundamental model of interaction? Are we talking about a simple registration and callback system, or is there something more elaborate even from the start? I'm anticipating some potentially naive implementations that were later refined, but that's what I want to see. This starting point will tell me everything about where the code came from. I am looking for the essential groundwork, the assumptions made, and any obvious constraints they had to work within. Understanding this initial implementation will provide the necessary context to appreciate any later complexities or performance optimizations that were added. Let's see what we've got.
|
| 278/2 |
2026/08/31 22:09 |
tool |
git-log |
0m
Args: map[Count:5 PathPrefix:kernel/tracepoint.c Since:20 years]
Results: map[Output:fad217e16fde tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func()
323bbfcf1ef8 Convert 'alloc_flex' family to use the new default GFP_KERNEL argument
bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
a46023d5616e tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast
]
|
| 279/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 43717
output: 33
thoughts: 120
Thoughts: **Investigating the Introduction of Tracepoints**
Okay, so I need to quickly grab the five most recent commits using `git log`, right? I'll probably want to specify a count to limit the output. Wait a minute, that's right, `git log --count=5` just gets me the *last* five commits! I need to be more precise in my approach.
Alright, let's say I want to examine commit *5f3ea37c7716*. I need to focus on what happened around the introduction of `tracepoint_probe_register`. My aim is to check when the tracepoint functionality itself was introduced.
Okay, I seem to recall that this was around the 2.6.28 kernel version, so commit *7b453719cbf8* sounds like a good place to start, or something similar from that timeframe.
I'll check the `git log` history for `kernel/tracepoint.c` – specifically, I'll focus on the commits around 2008. That should provide a clearer picture of the initial implementation.
|
| 280/2 |
2026/08/31 22:09 |
tool |
git-log |
0m
Args: map[CodeRegexp:allocate_probes PathPrefix:kernel/tracepoint.c]
Results: map[Output:7211f0a25781 tracepoints: Code clean up
befe6d946551 tracepoint: Do not fail unregistering a probe due to memory failure
19dba33c43a2 tracepoint: simplification for tracepoints using RCU
]
|
| 281/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 44189
output: 24
thoughts: 28
Thoughts: Here's my summary, as if I were the one thinking these thoughts:
**Analyzing Mathieu Desnoyers' Tracepoint Commit**
Okay, let's dive into commit `7b453719cbf8`. I recognize that hash, it should be Mathieu Desnoyers' initial tracepoint implementation, if memory serves. I'm especially interested in this, as it's the genesis of a significant piece of observability infrastructure. This should shed light on the original design choices, the architectural considerations, and hopefully, some of the reasoning behind the early decisions. I need to refresh my understanding of how he approached this initially, which will give me a better understanding of how the code evolved, and what trade-offs were made from the outset. I'll focus on the data structures and control flow, and think about the design implications in terms of performance and extensibility. There are often subtleties in the initial commits that provide valuable context. Let's dig in.
|
| 282/2 |
2026/08/31 22:09 |
tool |
git-log |
0m
Args: map[MessageRegexps:[tracepoint: infrastructure]]
Results: map[Output:8e677a466145 trace: tcp: Add tracepoint for tcp_cwnd_reduction()
54a59aed395c net, sched: Make tc-related drop reason more flexible
ff40e51043af bpf, lockdown, audit: Fix buggy SELinux lockdown permission checks
]
|
| 283/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 44534
output: 39
thoughts: 14
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Tracing the Tracepoint Timeline**
Alright, before I dive too deep into this performance issue I'm looking at, I need a solid timeline. My immediate instinct is to pinpoint when the tracepoint infrastructure was actually introduced into the kernel. Knowing the introduction date will give me a valuable context, especially if I'm troubleshooting problems with earlier versions. It sets the stage for any changes, bugs, or limitations I might encounter relative to its initial implementation, so I can immediately dismiss potential areas of conflict. Time to start digging through the changelogs!
|
| 284/2 |
2026/08/31 22:09 |
tool |
git-log |
0m
Args: map[CodeRegexp:struct tracepoint Count:10 PathPrefix:include/linux/tracepoint.h]
Results: map[Output:a46023d5616e tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast
654ced4a1377 tracing: Introduce tracepoint_is_faultable()
a9cfb8778c43 tracing: Introduce tracepoint extended structure
e53244e2c893 tracepoint: Remove SRCU protection
d4df54f338e4 tracepoint: Support iterating tracepoints in a loading module
d5dbf8b48a46 tracepoint: Support iterating over tracepoints on modules
9913d5745bd7 tracepoint: Add tracepoint_probe_register_may_exist() for BPF tracing
d9a1be1be331 tracepoints: Do not punish non static call users
d25e37d89dd2 tracepoint: Optimize using static_call()
1c39d761ff5c tracepoint: Use __used attribute definitions from compiler_attributes.h
]
|
| 285/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 44979
output: 30
thoughts: 1001
Thoughts: **Analyzing the blktrace Tracepoint Registration**
Okay, let's dive back into this blktrace issue. First, I'm reviewing commit 5f3ea37c7716db4e894a480e0c18b24399595b6b. Arnaldo's commit introduced `blk_register_tracepoints()` and the initial setup. I see that it explicitly checks the return values of `register_trace_block_*()` functions with `WARN_ON(ret)`. That's interesting; it suggests there was an expectation of potential failure during tracepoint registration, likely due to memory allocation within those registration functions. However, the function *always* returns 0, and the `WARN_ON` macros seem a bit out of place, given this.
Then, there's commit 3c289ba7c320560ee74979a8895141c829046a2d, which removes `blk_probe_mutex`. The justification here is that since `blk_register_tracepoints()` *always* returns 0, the mutex protecting `blk_probes_ref` isn't needed. The return type gets changed to `void`. Ah, the lightbulb moment: it seems the original `WARN_ON(ret)` was never actually triggered because `blk_register_tracepoints` *always* returned zero!
Now, the root cause explanation brings it all together: those tracepoint registration functions *can* fail, especially under memory pressure or with fault injection, because of allocations. A failure should return -ENOMEM. The `WARN_ON()` was set to catch these, *but* the errors were ignored and the function continued. This leaves the tracepoints in a partially registered state. Unregistering that state later leads to an `-ENOENT` return from `tracepoint_remove_func()` and *another* `WARN_ON_ONCE`! That's a classic example of an incomplete error handling.
Therefore, the fix is going to involve proper error handling: returning the error from `blk_register_tracepoints`, unregistering successfully registered tracepoints on error, and propagating the error up the call stack.
Time to look at the history of `blktrace.c` using `git log`, focusing on commits touching `blk_register_tracepoints`, `blk_trace_setup_queue`, or `blk_trace_setup_finalize`. This should give a clearer picture of the code's evolution and any relevant refactorings.
|
| 286/2 |
2026/08/31 22:09 |
tool |
git-log |
0m
Args: map[Count:30 PathPrefix:kernel/trace/blktrace.c]
Results: map[Output:da46b5dfef48 blktrace: fix __this_cpu_read/write in preemptible context
bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
dfe48ea17973 blk-mq: use NOIO context to prevent deadlock during debugfs creation
0c2580a80946 blktrace: Make init_blk_tracer() asynchronous
ee4784a83fb2 block: don't use strcpy to copy blockdev name
bbec8e28cac5 tracing: Allow tracer to add more than 32 options
bc49af56eea8 blktrace: add support for REQ_OP_WRITE_ZEROES tracing
e48886b9d668 blktrace: for ftrace use correct trace format ver
4a0940bdcac2 blktrace: use debug print to report dropped events
4ae8efb4f907 blktrace: handle BLKTRACESETUP2 ioctl
3f6722816a73 blktrace: trace zone write plugging operations
1c164fcc1b08 blktrace: expose ZONE APPEND completions to blktrace
f9ee38bbf70f blktrace: add block trace commands for zone operations
4d8bc7bd4f73 blktrace: move ftrace blk_io_tracer to blk_io_trace2
67bfa74d81ba blktrace: move trace_note to blk_io_trace2
915bb53860c3 blktrace: differentiate between blk_io_trace versions
c44347d60626 blktrace: add definitions for struct blk_io_trace2
113cbd62824a blktrace: pass blk_user_trace2 to setup functions
0d8627cc936d blktrace: add definitions for blk_user_trace_setup2
42da88a724d8 blktrace: split do_blk_trace_setup into two functions
370cd70a402f blktrace: change the internal action to 64bit
70e3c62b8912 blktrace: untangle if/else sequence in __blk_add_trace
04678e72e95f blktrace: split out relaying a blktrace event
472eca538358 blktrace: factor out recording a blktrace event
a65988a0ad04 blktrace: only calculate trace length once
bd116214d53c blktrace: add zoned block commands to blk_fill_rwbs
7f2173894f7b blktrace: use rbuf->stats.full as a drop indicator in relayfs
2489e958129f relayfs: abolish prev_padding
927244f6efff traceevent/block: Add REQ_ATOMIC flag to block trace events
]
|
| 287/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 47349
output: 26
thoughts: 34
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing blktrace.c Commits**
Right, let's dive into this. The initial thought is to examine commit `42da88a724d8` and then widen the scope to include related commits to understand the recent modifications within `blktrace.c`. This isn't just a casual glance; I'm expecting to dissect the *why* behind the code changes, not just the *what*. My goal is a full understanding of the changes' implications – potential performance impacts, bug fixes, new features implemented, or perhaps architectural shifts. I'll need to assess the context of these modifications within the larger framework of `blktrace`. I want to see how these changes interact with the existing codebase and, if I'm lucky, I may be able to piece together the reasoning behind this commit.
|
| 288/2 |
2026/08/31 22:09 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 42da88a724d8a3b92ade35ae2ef4d5e5a491df2d
Author: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Date: Wed Oct 22 13:41:05 2025 +0200
blktrace: split do_blk_trace_setup into two functions
Split do_blk_trace_setup into two functions, this is done to prepare for
an incoming new BLKTRACESETUP2 ioctl(2) which can receive extended
parameters from user-space.
Also move the size verification logic to the callers in preparation for
using a new internal structure later.
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 15d6788700ca..df90422ae613 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -518,9 +518,10 @@ static void blk_trace_setup_lba(struct blk_trace *bt,
/*
* Setup everything required to start tracing
*/
-static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
- struct block_device *bdev,
- struct blk_user_trace_setup *buts)
+static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
+ char *name, dev_t dev,
+ u32 buf_size, u32 buf_nr,
+ struct block_device *bdev)
{
struct blk_trace *bt = NULL;
struct dentry *dir = NULL;
@@ -528,31 +529,19 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
lockdep_assert_held(&q->debugfs_mutex);
- if (!buts->buf_size || !buts->buf_nr)
- return -EINVAL;
-
- strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE);
-
- /*
- * some device names have larger paths - convert the slashes
- * to underscores for this to work as expected
- */
- strreplace(buts->name, '/', '_');
-
/*
* bdev can be NULL, as with scsi-generic, this is a helpful as
* we can be.
*/
if (rcu_dereference_protected(q->blk_trace,
lockdep_is_held(&q->debugfs_mutex))) {
- pr_warn("Concurrent blktraces are not allowed on %s\n",
- buts->name);
- return -EBUSY;
+ pr_warn("Concurrent blktraces are not allowed on %s\n", name);
+ return ERR_PTR(-EBUSY);
}
bt = kzalloc(sizeof(*bt), GFP_KERNEL);
if (!bt)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
ret = -ENOMEM;
bt->sequence = alloc_percpu(unsigned long);
@@ -572,7 +561,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (bdev && !bdev_is_partition(bdev))
dir = q->debugfs_dir;
else
- bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root);
+ bt->dir = dir = debugfs_create_dir(name, blk_debugfs_root);
/*
* As blktrace relies on debugfs for its interface the debugfs directory
@@ -580,8 +569,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
* files or directories.
*/
if (IS_ERR_OR_NULL(dir)) {
- pr_warn("debugfs_dir not present for %s so skipping\n",
- buts->name);
+ pr_warn("debugfs_dir not present for %s so skipping\n", name);
ret = -ENOENT;
goto err;
}
@@ -593,17 +581,38 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
debugfs_create_file("dropped", 0444, dir, bt, &blk_dropped_fops);
debugfs_create_file("msg", 0222, dir, bt, &blk_msg_fops);
- bt->rchan = relay_open("trace", dir, buts->buf_size,
- buts->buf_nr, &blk_relay_callbacks, bt);
+ bt->rchan = relay_open("trace", dir, buf_size, buf_nr,
+ &blk_relay_callbacks, bt);
if (!bt->rchan)
goto err;
+ blk_trace_setup_lba(bt, bdev);
+
+ return bt;
+
+err:
+ blk_trace_free(q, bt);
+
+ return ERR_PTR(ret);
+}
+
+static void blk_trace_setup_finalize(struct request_queue *q,
+ char *name, struct blk_trace *bt,
+ struct blk_user_trace_setup *buts)
+
+{
+ strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE);
+
+ /*
+ * some device names have larger paths - convert the slashes
+ * to underscores for this to work as expected
+ */
+ strreplace(buts->name, '/', '_');
+
bt->act_mask = buts->act_mask;
if (!bt->act_mask)
bt->act_mask = (u16) -1;
- blk_trace_setup_lba(bt, bdev);
-
/* overwrite with user settings */
if (buts->start_lba)
bt->start_lba = buts->start_lba;
@@ -615,12 +624,6 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
rcu_assign_pointer(q->blk_trace, bt);
get_probe_ref();
-
- ret = 0;
-err:
- if (ret)
- blk_trace_free(q, bt);
- return ret;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
@@ -628,17 +631,25 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
char __user *arg)
{
struct blk_user_trace_setup buts;
+ struct blk_trace *bt;
int ret;
ret = copy_from_user(&buts, arg, sizeof(buts));
if (ret)
return -EFAULT;
+ if (!buts.buf_size || !buts.buf_nr)
+ return -EINVAL;
+
mutex_lock(&q->debugfs_mutex);
- ret = do_blk_trace_setup(q, name, dev, bdev, &buts);
+ bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
+ bdev);
+ if (IS_ERR(bt)) {
+ mutex_unlock(&q->debugfs_mutex);
+ return PTR_ERR(bt);
+ }
+ blk_trace_setup_finalize(q, name, bt, &buts);
mutex_unlock(&q->debugfs_mutex);
- if (ret)
- return ret;
if (copy_to_user(arg, &buts, sizeof(buts))) {
blk_trace_remove(q);
@@ -655,11 +666,14 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
{
struct blk_user_trace_setup buts;
struct compat_blk_user_trace_setup cbuts;
- int ret;
+ struct blk_trace *bt;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
+ if (!cbuts.buf_size || !cbuts.buf_nr)
+ return -EINVAL;
+
buts = (struct blk_user_trace_setup) {
.act_mask = cbuts.act_mask,
.buf_size = cbuts.buf_size,
@@ -670,10 +684,14 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
};
mutex_lock(&q->debugfs_mutex);
- ret = do_blk_trace_setup(q, name, dev, bdev, &buts);
+ bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
+ bdev);
+ if (IS_ERR(bt)) {
+ mutex_unlock(&q->debugfs_mutex);
+ return PTR_ERR(bt);
+ }
+ blk_trace_setup_finalize(q, name, bt, &buts);
mutex_unlock(&q->debugfs_mutex);
- if (ret)
- return ret;
if (copy_to_user(arg, &buts.name, ARRAY_SIZE(buts.name))) {
blk_trace_remove(q);
]
|
| 289/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 50333
output: 39
thoughts: 662
Thoughts: **Analyzing a Kernel Crash Related to Block Tracing**
Okay, let's dive into this. First, I'm going to look at the stack trace and the relevant code snippets from the crash report. It looks like the kernel is complaining about an issue within `kernel/trace/blktrace.c`, specifically around line 1332, and this is happening in `get_probe_ref` at line 492 as well. The CPU context is `syz.0.17/6119`, which implies syzkaller is involved.
Alright, let's take a look at what's going on at those lines. Line 1332 within `blk_register_tracepoints` has a `WARN_ON` call after registering a tracepoint:
```c
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
WARN_ON(ret);
```
So it looks like the crash involves the `register_trace_block_rq_insert` call, or the immediate `WARN_ON` check after it.
Then, line 492 which is a call into `get_probe_ref`. That's important. It appears that `get_probe_ref` is responsible for registering tracepoints, guarded by a mutex to ensure thread safety.
```c
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1)
blk_register_tracepoints();
mutex_unlock(&blk_probe_mutex);
```
Now let's examine the call trace: The issue is linked to `sysfs_blk_trace_attr_store`, which calls `blk_trace_setup_queue` from `kernel/trace/blktrace.c`. Then, it's called through kernfs write operations. So, it's triggered from the sysfs interface when setting up tracing for a block device.
My next step is to examine the `git blame` history for `blk_register_tracepoints` in `kernel/trace/blktrace.c`. This will give me context on recent changes, who touched this code, and potentially any related bug fixes or recent modifications that might have introduced this issue. The goal is to understand what might be causing the return value `ret` from `register_trace_block_rq_insert` to be non-zero (indicating an error). It could be a race condition, a resource limit, or a conflict in the initialization. I have a hunch it might be related to how the trace points are registered, maybe an issue when multiple threads try to do it simultaneously or related to how syzkaller is triggering it.
|
| 290/2 |
2026/08/31 22:09 |
tool |
git-blame |
0m
Args: map[End:1360 File:kernel/trace/blktrace.c Start:1320]
Results: map[Output:919dbca8670d0 kernel/trace/blktrace.c 1320) __blk_add_trace(bt, blk_rq_trace_sector(rq), blk_rq_bytes(rq), 0,
ca1136c99b66b kernel/trace/blktrace.c 1321) BLK_TA_DRV_DATA, 0, len, data,
a54895fa057c6 kernel/trace/blktrace.c 1322) blk_trace_request_get_cgid(rq));
c780e86dd48ef kernel/trace/blktrace.c 1323) rcu_read_unlock();
5f3ea37c7716d block/blktrace.c 1324) }
5f3ea37c7716d block/blktrace.c 1325) EXPORT_SYMBOL_GPL(blk_add_driver_data);
5f3ea37c7716d block/blktrace.c 1326)
3c289ba7c3205 kernel/trace/blktrace.c 1327) static void blk_register_tracepoints(void)
5f3ea37c7716d block/blktrace.c 1328) {
5f3ea37c7716d block/blktrace.c 1329) int ret;
5f3ea37c7716d block/blktrace.c 1330)
38516ab59fbc5 kernel/trace/blktrace.c 1331) ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
5f3ea37c7716d block/blktrace.c 1332) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1333) ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
5f3ea37c7716d block/blktrace.c 1334) WARN_ON(ret);
f3bdc62fd82ed kernel/trace/blktrace.c 1335) ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
f3bdc62fd82ed kernel/trace/blktrace.c 1336) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1337) ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
5f3ea37c7716d block/blktrace.c 1338) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1339) ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
5f3ea37c7716d block/blktrace.c 1340) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1341) ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
5f3ea37c7716d block/blktrace.c 1342) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1343) ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
5f3ea37c7716d block/blktrace.c 1344) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1345) ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
5f3ea37c7716d block/blktrace.c 1346) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1347) ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
5f3ea37c7716d block/blktrace.c 1348) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1349) ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
5f3ea37c7716d block/blktrace.c 1350) WARN_ON(ret);
1c164fcc1b08e kernel/trace/blktrace.c 1351) ret = register_trace_blk_zone_append_update_request_bio(
1c164fcc1b08e kernel/trace/blktrace.c 1352) blk_add_trace_zone_update_request, NULL);
1c164fcc1b08e kernel/trace/blktrace.c 1353) WARN_ON(ret);
3f6722816a73e kernel/trace/blktrace.c 1354) ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
3f6722816a73e kernel/trace/blktrace.c 1355) NULL);
3f6722816a73e kernel/trace/blktrace.c 1356) WARN_ON(ret);
3f6722816a73e kernel/trace/blktrace.c 1357) ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
3f6722816a73e kernel/trace/blktrace.c 1358) NULL);
3f6722816a73e kernel/trace/blktrace.c 1359) WARN_ON(ret);
38516ab59fbc5 kernel/trace/blktrace.c 1360) ret = register_trace_block_plug(blk_add_trace_plug, NULL);
]
|
| 291/2 |
2026/08/31 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 53341
output: 23
thoughts: 2302
Thoughts: **Analysis of the Blktrace Tracepoint Registration Bug**
Okay, let's break this down systematically. My initial thought process is to understand the chronology of events and pinpoint where the error handling was introduced or, more accurately, where it *wasn't* handled correctly. My first instinct is to zero in on the commit that introduced `blk_register_tracepoints`.
So, the first place I'm going to look is commit `5f3ea37c7716`. Aha! This "blktrace: port to tracepoints" commit introduces `blk_register_tracepoints`, and immediately I see the problem: `WARN_ON(ret)` after *every* call to a `register_trace_*` function. This *immediately* raises a red flag. The code checks for an error with `WARN_ON(ret)`, which triggers a kernel panic if `panic_on_warn` is set, but it *doesn't* actually stop if it fails! It just keeps going, and then it *always* returns 0. I remember the description of the problem specifically mentions `-ENOMEM` from allocation failures, which makes sense in the context of the tracepoint registration process.
I'm starting to think this is the source of the issue.
Next, I need to check the surrounding commits to see how this function evolved. I see commit `3c289ba7c320` ("blktrace: remove blk_probe_mutex"). This commit modifies the return type of `blk_register_tracepoints` to `void` because the function *always* returns 0. That confirms what I was thinking. The author (Li Zefan) realized the return value was meaningless because it was being ignored. They were not the ones who introduced the bug, they simply adapted to what was there. The initial code, in commit `5f3ea37c7716`, made the `int` return type of the function superfluous.
Then, commit `a6da0024ffc1` ("blktrace: fix unlocked registration of tracepoints") comes along and reintroduces the mutex with `get_probe_ref()` / `put_probe_ref()`, re-introducing the conditional call to `blk_register_tracepoints()`.
Now, the bug description. The description states that `blk_register_tracepoints()` uses `WARN_ON(ret)` and that `blk_register_tracepoints()` ignores the error and continues, leaving tracepoints in a partially registered state, and that later, `blk_unregister_tracepoints()` unconditionally unregisters all tracepoints. The description is correct in the fact that any failures during tracepoint registration, particularly when the tracepoint is later unregistered, could lead to issues.
So, let's go back and examine `5f3ea37c7716` and the commit history. The core of the problem is in `5f3ea37c7716`, where the code calls `register_trace_*()` and uses `WARN_ON(ret)`. No proper error handling is performed, and the return value is ignored.
I'm now confident that the root cause lies in `5f3ea37c7716`. The original implementation did not handle failures to register tracepoints, instead, merely warning via `WARN_ON(ret)`. The crash happens because the unregistration of the tracepoints does not account for their potentially being partially registered, or not registered at all.
|
| 292/2 |
2026/08/31 22:10 |
tool |
git-log |
0m
Args: map[MessageRegexps:[blk_register_tracepoints]]
Results: map[Output:a6da0024ffc1 blktrace: fix unlocked registration of tracepoints
3c289ba7c320 blktrace: remove blk_probe_mutex
]
|
| 293/2 |
2026/08/31 22:10 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 56473
output: 37
thoughts: 48
Thoughts: **Investigating Recent Changes to the Block Tracepoint Registration**
Okay, so I need to quickly get a lay of the land regarding any recent modifications to `blk_register_tracepoints`. My first step is to see if any other commits have touched that specific function. I'll execute a `git log -L` command, targeting that function specifically within the `kernel/trace/blktrace.c` file. This should give me a concise list of any relevant commits, allowing me to quickly understand the history and potential impact of those changes. I'm looking for a quick overview – anything significant that might require further inspection.
|
| 294/2 |
2026/08/31 22:10 |
tool |
git-log |
0m
Args: map[SourcePath:kernel/trace/blktrace.c SymbolName:blk_register_tracepoints]
Results: map[Output:3c289ba7c320 blktrace: remove blk_probe_mutex
5f3ea37c7716 blktrace: port to tracepoints
]
|
| 295/2 |
2026/08/31 22:10 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 56745
output: 55
thoughts: 616
Thoughts: **Analyzing the blktrace Tracepoint Registration Issue**
Okay, so I've been digging into this `blktrace` issue. My first move was to use `git log -L :blk_register_tracepoints:kernel/trace/blktrace.c` to pinpoint relevant commits. It gave me two: `3c289ba7c320` which removes a mutex, and, more importantly, `5f3ea37c7716` "blktrace: port to tracepoints."
Let's dive into that second commit, `5f3ea37c7716db4e894a480e0c18b24399595b6b`. It's Arnaldo Carvalho de Melo's commit from October 2008, titled "blktrace: port to tracepoints." Time to verify the details.
Now, let's break this down systematically. I looked at the stack trace from the crash, which clearly points to `blk_register_tracepoints` in `kernel/trace/blktrace.c:1332`. It seems the crash happens when `register_trace_block_*` calls fail, for example, due to an out-of-memory condition under fault injection, and the code uses `WARN_ON(ret)`.
The root cause here is evident. The `blk_register_tracepoints()` function was poorly written. It registered individual tracepoints and used `WARN_ON(ret)` for error reporting. It completely ignored potential registration errors.
The fix is straightforward, and the solution is to change `blk_register_tracepoints()` to return an integer error code. Proper error handling, including unwinding and propagating the error through its callers like `get_probe_ref()` and `blk_trace_setup_finalize()` is needed.
I'm confident in my diagnosis. The "blktrace: port to tracepoints" commit (`5f3ea37c7716`) is the culprit. That's where they introduced `blk_register_tracepoints` with the problematic `WARN_ON(ret)` and ignored registration errors.
So, let's call `set-results` with commit `5f3ea37c7716db4e894a480e0c18b24399595b6b`.
|
| 296/2 |
2026/08/31 22:10 |
tool |
set-results |
0m
Args: map[FixesHash:5f3ea37c7716db4e894a480e0c18b24399595b6b]
Results: map[FixesHash:5f3ea37c7716db4e894a480e0c18b24399595b6b]
|
| 297/1 |
2026/08/31 22:10 |
action |
format-fixes |
0m
Results: map[Fixes:map[AuthorEmail:acme@redhat.com AuthorName:Arnaldo Carvalho de Melo Hash:5f3ea37c7716db4e894a480e0c18b24399595b6b Title:blktrace: port to tracepoints]]
|
| 298/1 |
2026/08/31 22:10 |
action |
get-maintainers |
0m
Results: map[Recipients:[map[Email:axboe@kernel.dk Name:Jens Axboe To:true] map[Email:linux-block@vger.kernel.org Name: To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:linux-trace-kernel@vger.kernel.org Name: To:true] map[Email:mathieu.desnoyers@efficios.com Name:Mathieu Desnoyers To:false] map[Email:mhiramat@kernel.org Name:Masami Hiramatsu To:true] map[Email:rostedt@goodmis.org Name:Steven Rostedt To:true] map[Email:acme@redhat.com Name:Arnaldo Carvalho de Melo To:true]]]
|
| 299/1 |
2026/08/31 22:10 |
action |
get-recent-commits |
0m
Results: map[RecentCommits:blktrace: fix __this_cpu_read/write in preemptible context
Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
blk-mq: use NOIO context to prevent deadlock during debugfs creation
blktrace: Make init_blk_tracer() asynchronous
block: don't use strcpy to copy blockdev name
tracing: Allow tracer to add more than 32 options
blktrace: add support for REQ_OP_WRITE_ZEROES tracing
blktrace: for ftrace use correct trace format ver
blktrace: use debug print to report dropped events
blktrace: handle BLKTRACESETUP2 ioctl
blktrace: trace zone write plugging operations
blktrace: expose ZONE APPEND completions to blktrace
blktrace: add block trace commands for zone operations
blktrace: move ftrace blk_io_tracer to blk_io_trace2
blktrace: move trace_note to blk_io_trace2
blktrace: differentiate between blk_io_trace versions
blktrace: add definitions for struct blk_io_trace2
blktrace: pass blk_user_trace2 to setup functions
blktrace: add definitions for blk_user_trace_setup2
]
|
| 300/1 |
2026/08/31 22:10 |
agent |
description-generator |
0m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with writing a commit description for
a kernel bug fixing commit. The description should start with a one-line summary,
and then include description of the bug being fixed, and how it's fixed by the provided patch.
The one-line summary should describe the change being made, rather than mention the tool that
detected the bug.
The description must not contain lines starting with '#' because they will dropped by git as comments.
The description must not contain lines starting with '--' or '---' (including inline code diffs)
because they may confuse git/patch utilities.
Your final reply should contain only the text of the commit description.
The one-line summary must be not longer than 72 characters.
IMPORTANT: Do not wrap lines manually (e.g., at 80 characters); we will reformat the text
automatically, so keep paragraphs as single lines without newlines.
Generally try to phrase the description without mentioning syzkaller
(avoid phrases like "the bug was triggered by syzkaller" or "the bug was triggered by fuzzer", etc).
How the bug was triggered is generally an irrelevant detail.
Any bug triggered by a fuzzer can also be triggered by a malicious user, or a buggy program.
If the crash is reported by a sanitizer (e.g., KASAN, KMSAN, lockdep), include the relevant
parts of the sanitizer output to illustrate the problem. Exclude less relevant sections,
as the stack trace can be very long. Describe the execution path that leads to the manifestation
of the kernel bug.
If the patch removes the WARN_ON macro, refer to the fact that WARN_ON
must not be used for conditions that can legitimately happen, and that pr_err
should be used instead if necessary.
Don't assume that panic_on_warn is set, and that WARNINGs are fatal.
While panic_on_warn may be set when the bug was reproduced, it's generally not set on production systems.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
------------[ cut here ]------------
ret
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline], CPU#1: syz.0.17/6119
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492, CPU#1: syz.0.17/6119
Modules linked in:
CPU: 1 UID: 0 PID: 6119 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Code: c3 31 ff 89 c6 e8 39 42 f7 ff 85 db 0f 85 00 01 00 00 e8 2c 3d f7 ff 48 c7 c7 00 7f bd 8e 5b e9 af 77 db 09 e8 1a 3d f7 ff 90 <0f> 0b 90 e9 e8 fc ff ff e8 0c 3d f7 ff 90 0f 0b 90 e9 07 fd ff ff
RSP: 0018:ffffc9000355fb10 EFLAGS: 00010293
RAX: ffffffff81ce06d6 RBX: 00000000fffffff4 RCX: ffff888114150000
RDX: 0000000000000000 RSI: 00000000fffffff4 RDI: 0000000000000000
RBP: ffffc9000355fc40 R08: ffffc9000355fa47 R09: 1ffff920006abf48
R10: dffffc0000000000 R11: fffff520006abf49 R12: ffff88810888c508
R13: dffffc0000000000 R14: ffff888103f8c638 R15: 0000000000002000
FS: 00007fc861b426c0(0000) GS:ffff8882e873e000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2ed24008 CR3: 00000001fdd32000 CR4: 0000000000352ef0
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
new_sync_write fs/read_write.c:595 [inline]
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc860b9e159
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fc861b42028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fc860e25fa0 RCX: 00007fc860b9e159
RDX: 0000000000000081 RSI: 00002000000002c0 RDI: 0000000000000003
RBP: 00007fc861b42090 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fc860e26038 R14: 00007fc860e25fa0 R15: 00007ffd54a588d8
</TASK>
The explanation of the root cause of the bug is:
The root cause of the crash is that `blk_register_tracepoints()` uses `WARN_ON(ret)` to check the return values of `register_trace_block_*()` functions. These tracepoint registration functions allocate memory for the probe array and can fail with `-ENOMEM` (e.g., under memory pressure or fault injection, as seen in the syzbot report). When they fail, `WARN_ON()` triggers a kernel panic if `panic_on_warn` is set.
Furthermore, `blk_register_tracepoints()` currently ignores the error and continues, leaving the tracepoints in a partially registered state. Later, when tracing is stopped, `blk_unregister_tracepoints()` unconditionally unregisters all tracepoints. Unregistering a tracepoint that was not successfully registered causes `tracepoint_remove_func()` to return `-ENOENT`, which triggers another `WARN_ON_ONCE` inside `tracepoint_remove_func()`.
To fix this, we need to properly handle the registration failures by returning the error, unregistering the successfully registered tracepoints, and propagating the error up the call stack to fail the blktrace setup.
### Fix Details
1. **Change `blk_register_tracepoints()` to return an `int` and handle errors:**
Instead of `WARN_ON(ret)`, check the return value of each `register_trace_*()` call. If it fails, use `goto` labels to unregister the successfully registered tracepoints in reverse order, and return the error.
```c
static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
if (ret)
return ret;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
if (ret)
goto err_issue;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
if (ret)
goto err_merge;
// ... (do this for all 18 tracepoints) ...
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
if (ret)
goto err_rq_remap;
return 0;
err_rq_remap:
unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
// ... (unregister labels in reverse order) ...
err_merge:
unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
err_issue:
unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
return ret;
}
```
2. **Propagate the error through `get_probe_ref()`:**
```c
static int get_probe_ref(void)
{
int ret = 0;
mutex_lock(&blk_probe_mutex);
if (++blk_probes_ref == 1) {
ret = blk_register_tracepoints();
if (ret)
blk_probes_ref--;
}
mutex_unlock(&blk_probe_mutex);
return ret;
}
```
3. **Propagate the error through `blk_trace_setup_finalize()`:**
```c
static int blk_trace_setup_finalize(struct request_queue *q,
char *name, int version,
struct blk_trace *bt,
struct blk_user_trace_setup2 *buts)
{
int ret;
// ... existing code ...
bt->trace_state = Blktrace_setup;
ret = get_probe_ref();
if (ret)
return ret;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
}
```
4. **Handle the error in the callers of `blk_trace_setup_finalize()`:**
In `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, check the return value of `blk_trace_setup_finalize()`. If it fails, clean up the allocated `bt` and return the error:
```c
ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
if (ret) {
blk_trace_free(q, bt);
blk_debugfs_unlock(q, memflags);
return ret;
}
```
5. **Handle the error in `blk_trace_setup_queue()`:**
```c
static int blk_trace_setup_queue(struct request_queue *q,
struct block_device *bdev)
{
// ... existing code ...
blk_trace_setup_lba(bt, bdev);
ret = get_probe_ref();
if (ret)
goto free_bt;
rcu_assign_pointer(q->blk_trace, bt);
return 0;
free_bt:
blk_trace_free(q, bt);
return ret;
}
```
The diff of the bug fix is:
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 8cd2520b4..c2324298c 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -60,7 +60,7 @@ static struct tracer_flags blk_tracer_flags = {
static DEFINE_MUTEX(blk_probe_mutex);
static int blk_probes_ref;
-static void blk_register_tracepoints(void);
+static int blk_register_tracepoints(void);
static void blk_unregister_tracepoints(void);
static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int cpu,
@@ -485,12 +485,18 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt)
kfree(bt);
}
-static void get_probe_ref(void)
+static int get_probe_ref(void)
{
+ int ret = 0;
+
mutex_lock(&blk_probe_mutex);
- if (++blk_probes_ref == 1)
- blk_register_tracepoints();
+ if (++blk_probes_ref == 1) {
+ ret = blk_register_tracepoints();
+ if (ret)
+ blk_probes_ref--;
+ }
mutex_unlock(&blk_probe_mutex);
+ return ret;
}
static void put_probe_ref(void)
@@ -727,12 +733,14 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,
return ERR_PTR(ret);
}
-static void blk_trace_setup_finalize(struct request_queue *q,
- char *name, int version,
- struct blk_trace *bt,
- struct blk_user_trace_setup2 *buts)
+static int blk_trace_setup_finalize(struct request_queue *q,
+ char *name, int version,
+ struct blk_trace *bt,
+ struct blk_user_trace_setup2 *buts)
{
+ int ret;
+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2);
/*
@@ -755,8 +763,12 @@ static void blk_trace_setup_finalize(struct request_queue *q,
bt->pid = buts->pid;
bt->trace_state = Blktrace_setup;
+ ret = get_probe_ref();
+ if (ret)
+ return ret;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
+ return 0;
}
int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
@@ -792,7 +804,12 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
strscpy(buts.name, buts2.name, BLKTRACE_BDEV_SIZE);
blk_debugfs_unlock(q, memflags);
@@ -810,6 +827,7 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
struct blk_user_trace_setup2 buts2;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&buts2, arg, sizeof(buts2)))
return -EFAULT;
@@ -827,7 +845,12 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 2, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2, sizeof(buts2))) {
@@ -846,6 +869,7 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;
unsigned int memflags;
+ int ret;
if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
return -EFAULT;
@@ -869,7 +893,12 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
blk_debugfs_unlock(q, memflags);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ ret = blk_trace_setup_finalize(q, name, 1, bt, &buts2);
+ if (ret) {
+ blk_trace_free(q, bt);
+ blk_debugfs_unlock(q, memflags);
+ return ret;
+ }
blk_debugfs_unlock(q, memflags);
if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
@@ -1324,49 +1353,108 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len)
}
EXPORT_SYMBOL_GPL(blk_add_driver_data);
-static void blk_register_tracepoints(void)
+static int blk_register_tracepoints(void)
{
int ret;
ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out;
ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_insert;
ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_issue;
ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_merge;
ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_requeue;
ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_rq_complete;
ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_complete;
ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_backmerge;
ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_frontmerge;
ret = register_trace_block_getrq(blk_add_trace_getrq, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_queue;
ret = register_trace_blk_zone_append_update_request_bio(
blk_add_trace_zone_update_request, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_getrq;
ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_update_request;
ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug,
NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_plug;
ret = register_trace_block_plug(blk_add_trace_plug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_zone_unplug;
ret = register_trace_block_unplug(blk_add_trace_unplug, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_plug;
ret = register_trace_block_split(blk_add_trace_split, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_unplug;
ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_split;
ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL);
- WARN_ON(ret);
+ if (ret)
+ goto out_bio_remap;
+
+ return 0;
+
+out_bio_remap:
+ unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL);
+out_split:
+ unregister_trace_block_split(blk_add_trace_split, NULL);
+out_unplug:
+ unregister_trace_block_unplug(blk_add_trace_unplug, NULL);
+out_plug:
+ unregister_trace_block_plug(blk_add_trace_plug, NULL);
+out_zone_unplug:
+ unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL);
+out_zone_plug:
+ unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL);
+out_zone_update_request:
+ unregister_trace_blk_zone_append_update_request_bio(
+ blk_add_trace_zone_update_request, NULL);
+out_getrq:
+ unregister_trace_block_getrq(blk_add_trace_getrq, NULL);
+out_bio_queue:
+ unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL);
+out_bio_frontmerge:
+ unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL);
+out_bio_backmerge:
+ unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL);
+out_bio_complete:
+ unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL);
+out_rq_complete:
+ unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL);
+out_rq_requeue:
+ unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL);
+out_rq_merge:
+ unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL);
+out_rq_issue:
+ unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL);
+out_rq_insert:
+ unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL);
+ tracepoint_synchronize_unregister();
+out:
+ return ret;
}
static void blk_unregister_tracepoints(void)
@@ -1916,8 +2004,11 @@ static int blk_trace_setup_queue(struct request_queue *q,
blk_trace_setup_lba(bt, bdev);
+ ret = get_probe_ref();
+ if (ret)
+ goto free_bt;
+
rcu_assign_pointer(q->blk_trace, bt);
- get_probe_ref();
return 0;
free_bt:
Additional description of the patch:
The crash occurred because `blk_register_tracepoints()` used `WARN_ON(ret)` on `register_trace_*()` calls. Tracepoint registration functions allocate memory for probe arrays and can legitimately fail with `-ENOMEM` (e.g. under memory pressure or fault injection). Using `WARN_ON()` in this situation triggered kernel panics when `panic_on_warn` was set. Furthermore, ignoring the return value left tracepoints in a partially registered state, leading to subsequent warnings or errors during unregistration.
### Changes Made
1. **Error handling and rollback in `blk_register_tracepoints()`**:
- Changed `blk_register_tracepoints()` to return an `int`.
- Removed `WARN_ON(ret)` for all 18 tracepoints.
- Added sequential error checks and a symmetric `goto` rollback path that unregisters previously registered tracepoints in reverse order and invokes `tracepoint_synchronize_unregister()` before returning the error code.
2. **Reference counter handling in `get_probe_ref()`**:
- Changed `get_probe_ref()` to return an `int`.
- If `blk_register_tracepoints()` fails when initializing the first probe reference (`blk_probes_ref == 1`), `blk_probes_ref` is decremented back to 0 before releasing `blk_probe_mutex` and propagating the error.
3. **Error propagation in `blk_trace_setup_finalize()`**:
- Changed `blk_trace_setup_finalize()` to return an `int`.
- Called `get_probe_ref()` before assigning `rcu_assign_pointer(q->blk_trace, bt)`.
- Propagated the error code to the caller.
4. **Resource cleanup in setup callers**:
- In `blk_trace_setup()`, `blk_trace_setup2()`, and `compat_blk_trace_setup()`, checked the return value of `blk_trace_setup_finalize()`. If setup fails, freed the allocated `blk_trace` structure using `blk_trace_free(q, bt)` and released debugfs locks before returning the error.
- In `blk_trace_setup_queue()`, checked `get_probe_ref()` before assigning `q->blk_trace`, jumping to `free_bt` on failure.
Here are summaries of recent commits that touched the same files.
Format the summary line consistently with these, look how prefixes
are specified, letter capitalization, style, etc.
blktrace: fix __this_cpu_read/write in preemptible context
Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
blk-mq: use NOIO context to prevent deadlock during debugfs creation
blktrace: Make init_blk_tracer() asynchronous
block: don't use strcpy to copy blockdev name
tracing: Allow tracer to add more than 32 options
blktrace: add support for REQ_OP_WRITE_ZEROES tracing
blktrace: for ftrace use correct trace format ver
blktrace: use debug print to report dropped events
blktrace: handle BLKTRACESETUP2 ioctl
blktrace: trace zone write plugging operations
blktrace: expose ZONE APPEND completions to blktrace
blktrace: add block trace commands for zone operations
blktrace: move ftrace blk_io_tracer to blk_io_trace2
blktrace: move trace_note to blk_io_trace2
blktrace: differentiate between blk_io_trace versions
blktrace: add definitions for struct blk_io_trace2
blktrace: pass blk_user_trace2 to setup functions
blktrace: add definitions for blk_user_trace_setup2
Reply: blktrace: handle tracepoint registration failures
In blk_register_tracepoints(), register_trace_*() functions are called with
WARN_ON(ret). Tracepoint registration allocates memory for probe arrays and
can legitimately fail with -ENOMEM under memory pressure. WARN_ON() must
not be used for conditions that can legitimately happen.
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints
kernel/trace/blktrace.c:1332 [inline]
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470
kernel/trace/blktrace.c:492
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
Furthermore, blk_register_tracepoints() ignores registration errors and
continues, leaving tracepoints in a partially registered state. When
blktrace is later stopped, blk_unregister_tracepoints() unconditionally
attempts to unregister all tracepoints, which fails with -ENOENT and
triggers an additional warning in tracepoint_remove_func().
Fix this by removing WARN_ON() and properly handling registration failures
in blk_register_tracepoints(). If any registration fails, unwinding is
performed by unregistering previously registered tracepoints in reverse
order, synchronizing tracepoint unregistration, and returning the error
code. In addition, propagate the error through get_probe_ref(),
blk_trace_setup_finalize(), and the setup entry points (blk_trace_setup(),
blk_trace_setup2(), compat_blk_trace_setup(), and blk_trace_setup_queue()),
properly cleaning up allocated resources on failure.
|
| 301/2 |
2026/08/31 22:10 |
llm |
description-generator |
0m
Model:
Tokens:
input: 11537
output: 653
thoughts: 3055
Thoughts: **blktrace: handle tracepoint registration failures**
In `blk_register_tracepoints()`, `register_trace_*()` functions are called with `WARN_ON(ret)`. Tracepoint registration functions allocate memory for probe arrays and can legitimately fail with `-ENOMEM` under memory pressure. `WARN_ON()` must not be used for conditions that can legitimately happen.
```
WARNING: kernel/trace/blktrace.c:1332 at blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
WARNING: kernel/trace/blktrace.c:1332 at get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
RIP: 0010:blk_register_tracepoints kernel/trace/blktrace.c:1332 [inline]
RIP: 0010:get_probe_ref+0x377/0x470 kernel/trace/blktrace.c:492
Call Trace:
<TASK>
blk_trace_setup_queue kernel/trace/blktrace.c:1920 [inline]
sysfs_blk_trace_attr_store+0xb1d/0x11e0 kernel/trace/blktrace.c:2116
kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345
vfs_write+0x612/0xba0 fs/read_write.c:687
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_64+0x155/0x510 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
```
Furthermore, `blk_register_tracepoints()` ignores registration errors and continues, leaving tracepoints in a partially registered state. When blktrace is later stopped, `blk_unregister_tracepoints()` unconditionally attempts to unregister all tracepoints, which fails with `-ENOENT` and triggers an additional `WARN_ON_ONCE()` in `tracepoint_remove_func()`.
Fix this by removing `WARN_ON()` and properly handling registration failures in `blk_register_tracepoints()`. If any registration fails, previously registered tracepoints are unregistered in reverse order and the error code is returned. `get_probe_ref()`, `blk_trace_setup_finalize()`, and the blktrace setup entry points (`blk_trace_setup()`, `blk_trace_setup2()`, `compat_blk_trace_setup()`, and `blk_trace_setup_queue()`) are updated to propagate the error and clean up allocated resources.
|