From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796326828; b=pY13G3wvgnUhSZcmmazvP5Ow5V32ziMBo+H6oj4aetp7wAcNR6nUvvQ59CkER4jwP1Tx aa5ksbO/JnRr4T5TiK7/36ueP5i2sOzrUxtulIktorGfCPMkXa9rdIgpypCHKdGkaVkO5 /4CBh+aavMHRuSPPXjFGQx+erwjY0lFcvaI8hVxy8JeJNt09wcSumQMyne4SgmyRzHN5F zZGMSPlmCWpQcl6TNOhX4uMSu//AGvM0r49nizz+PDZGtXoExPtlZOsUeFmazXjaLRFuZ iievsz/v/SmyBYKOtW8dSbbILKfmrvAOktyULFm8/W0A6Y8n9MikqX8IJSEF7g/wk0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796326828; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=N7/MgIuD9ald+E09K4Sy9Q6ZZRgBlC/4IhOtvQvQ2V0=; b=MakhdGLxzYsR2miOoiF0Rvmv4gxB+UOHIjz7mHxXD0jciUpTsT2HomD5X5iFmOvFKZ8x Y80coDWeXaPkYwZLUBkKdI/mCDKPNYF3eFzeXZkwLxAs3j3bgBL1efmAZUGFnGPpy0AjM 33Ax2+Bac/5RffUHCJMl6OwJ1gdvNmt5dTh4cqL9i64aERhnNbGWLo0SD7rrEZN3FTSta BQOGXuJX3HQCUhy1gKgKZKcPaCkLKc09k838vdadaDksU/XVwvJbBGkgbelqUt+TDx+8G ShCUBIMbZBl7TrOdqgkTlv9LoQZXkZd4PXTaDPv2oOFhT5OmFX2Cz2LFJ3qB+D5Jh9w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="AaS6Gb/b"; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75A6360A3826 for ; Thu, 3 Dec 2026 19:40:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 75A6360A3826 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AaS6Gb/b Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4a207b02a2cso1107345e9.1 for ; Thu, 03 Dec 2026 11:40:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796326827; x=1796931627; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=N7/MgIuD9ald+E09K4Sy9Q6ZZRgBlC/4IhOtvQvQ2V0=; b=AaS6Gb/b6YVr9+a0wHVIrNHumTfyjh/YeRsTULbyZaDZ0HLTIWM2jtWQQg+zzglcmC PJlcJi6yyLZJ6d0kCiG6fEJIzcIqs+G2kKd5JXSQX7Egpih5jvlqJ9cjHOdESo3qg5ye OpcGA5aAPAM8juLoFGWOKvzKN3YtZZyWvCMwFu0aFMVuUy2lqluNHszx3KJPsvR+l0CN 7FgjL0NfGZEvq5vRcBs6CDmHgwRfFhts1ZPxDS9tJy0AY9p6/B9nwS73n6VnZt4NA2Tg bDvYcN0ir0ZNAKwEXyfIl/wp+VMHobVdh6m+wXrjnsCzGNZU+TlAILcxvo+w2Roii6S3 ES4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796326827; x=1796931627; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=N7/MgIuD9ald+E09K4Sy9Q6ZZRgBlC/4IhOtvQvQ2V0=; b=qkT8Ssr0l8ibF9iuCfjnZ0SAdse7kiciEqybIcvrhCGudawPwKVLR2b7udFq8yvzO7 lAumnKR3Rpn5mLxqfNYQ0O81Omdl2lRXF+1qGaWkalPU+YshENDO/Y5NQwP7madpeEM+ nhFnMDopwRVMmGW8z/az9mKwjaHiCTr+d4ubT4h+4Z6210Rcea2G4gDJWxwv5kpLR0xg +U0msjua1loWPVd+vRE75WH63269Ft9jD9oQ2CzRTMnf2VzYl4BhU6myMr2mZJIPvHaa Q235YFcxhLbmA4qtv7g3K4tBx8/V6d4Rk0T+/8mdvtvzHxC03it7+hXM52Ft3Zv+ANte K0tw== X-Forwarded-Encrypted: i=1; AL+hErGXEu6BLYf1xkPWdY7JM46lxVb8H7j5RO/C9W9/PTmeJQp0ARg83nt9ulLRhD0mQeFEL/ALUgXijJrdtdc=@vger.kernel.org X-Gm-Message-State: APuU4Z9s3+kSUZsZai47nNa4wHVv0GAkA4zEpqZSEBsMVB7Jg07HK/aN TKTufc7By1N9CjzgfjKT8tJBXZqnzuxOPFDA4MqS8nS0H/Un1ESjj0auCo+v0LHF X-Gm-Gg: AZFdTZfiowTVI1j2/XpehKlyqG1QxzAecvLCOSaN7cZWmWXBdPKVOM0YzbTcP5RtF1A TwgKwdEcwLsnnjMrdDeIvc3qhUQ3AypGQfl8R1mLE2V2VEjHxxT8+qR5ECreCU4Jo+l19ZTlQHa 9B4bHEVMrIh5MrIUSOCX3XNmfr8ESo7RoXLe8aO6gwWYxGVgk4aQDZXzJHPgVVFeaXnE8RBGw1j 7bmDLqir2Dzw8enWkbW+Ru0JMMa3r71lbqk9xTBT+LaYg7tkV7G2qN0uR6TvIxBQxcDD7XrJdRw sKR2BsNmB/OqeLPvvJhip+JCwvW7Mkb7/EK6THxQWunFIM/5aP4iG45Rwyr3d76SbAHmINcB/26 JNeg7yKyR7n/bnzrjpuFodunaegedEFuDo32m1s/XMkRNWv03wxbNUUse3IXtOpmn6SfJ+OIGOQ oiMYy3KBv2DifA6pmsoJ391C/JU8xh5xtg0T8PwpNYfiU55MyAUH8iiTkoKfW1e6g7XJeCcYp+V Bewhd6xrOysYsLxHoWWx8sOBUWAN9uKnZm/FmKEgsB/tk3M1UoFBKxsiNImjBvqjpP+GD7znNCL bpKqobyWKRutY++G12t2PigwFsRgeZR+uPhd X-Received: by 2002:a05:600d:6510:10b0:4a1:811c:8078 with SMTP id 5b1f17b1804b1-4bb8881de57mr636341915e9.26.1796326826841; Thu, 03 Dec 2026 11:40:26 -0800 (PST) Received: from localhost ([2a02:1210:8229:bc00:bc39:4d85:7ac0:a6f7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea09a2e7sm792255e9.2.2026.12.03.11.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 11:40:26 -0800 (PST) From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=A4rtschi?= To: Jens Axboe , linux-block@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Arnaldo Carvalho de Melo , Chaitanya Kulkarni , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+c54ded83396afee31eb1@syzkaller.appspotmail.com, syzbot+8672dcb9d10011c0a160@syzkaller.appspotmail.com Subject: [PATCH] blktrace: propagate tracepoint registration errors instead of warning Date: Thu, 3 Dec 2026 20:40:13 +0100 Message-ID: <20261203194013.1458370-1-linuxsatellite@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit blk_register_tracepoints() registers 18 tracepoint probes and only does WARN_ON(ret) when a registration fails. The tracepoint core already warns about every failure other than -ENOMEM, so the WARN_ON() in blktrace can only trigger on an allocation failure, which is a legitimate runtime error rather than a kernel bug. syzbot hits it with fault injection: WARNING: kernel/trace/blktrace.c:1330 at blk_register_tracepoints+0x33c/0x440 Call Trace: get_probe_ref kernel/trace/blktrace.c:493 [inline] blk_trace_setup_queue+0x269/0x300 kernel/trace/blktrace.c:1897 sysfs_blk_trace_attr_store+0x6e2/0xa20 kernel/trace/blktrace.c:2092 Besides the warning, the failure is ignored: the setup reports success while some of the probes are missing, and when tracing is disabled again, blk_unregister_tracepoints() also tries to remove the probes that were never added, which triggers a second warning in the tracepoint core: WARNING: kernel/tracepoint.c:369 at tracepoint_probe_unregister+0x85f/0xcd0 Unwind the already registered probes when a registration fails and return the error. Make get_probe_ref() propagate it and drop the reference it took, and take the probe reference before the trace is published: in blk_trace_setup_prepare(), whose error path already frees the blk_trace, and in blk_trace_setup_queue(). The blktrace setup then fails with -ENOMEM instead of silently running with missing tracepoints. Tested in QEMU on a loop device with fault injection (fail-nth with failslab/fail_page_alloc ignore-gfp-wait=N) on the sysfs, BLKTRACESETUP and BLKTRACESETUP2 paths: before the change both warnings trigger and the setup succeeds with missing probes; after it, the setup fails with -ENOMEM, no warnings are printed, and the blk tracer still records events afterwards. With two loop devices, failed setups on the second one leave tracing on the first intact, and the probe reference count returns to zero afterwards. syzbot's own C reproducers (/dev/sg, BLKTRACESETUP2) were not run. Triage, reproduction, the patch and this changelog were done with an AI coding assistant (Claude Opus 5.5). I reviewed the change and re-ran the tests above. Fixes: 5f3ea37c7716 ("blktrace: port to tracepoints") Reported-by: syzbot+c54ded83396afee31eb1@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c54ded83396afee31eb1 Reported-by: syzbot+8672dcb9d10011c0a160@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=8672dcb9d10011c0a160 Signed-off-by: Björn Bärtschi --- A similar change was proposed in 2023 [1] and stalled on the concern that it adds a lot of code. Since then it turned out that ignoring the error is not only a spurious warning: the setup succeeds with probes missing, and disabling the trace afterwards trips a second warning in the tracepoint core. The unwind follows tracing_sched_register() in kernel/trace/trace_sched_switch.c; taking the probe reference in blk_trace_setup_prepare() keeps the three ioctl callers unchanged. This touches a context line next to Johannes' ioprio series [2] (bt->flags in blk_trace_setup_finalize()); trivial to rebase either way. [1] https://lore.kernel.org/all/20230328094605.480557-1-zhengyejian1@huawei.com/ [2] https://lore.kernel.org/all/20261203092748.1960101-1-johannes.thumshirn@wdc.com/ kernel/trace/blktrace.c | 119 +++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 25 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 8cd2520b4c99..76af7fd67074 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) @@ -719,6 +725,10 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q, blk_trace_setup_lba(bt, bdev); + ret = get_probe_ref(); + if (ret) + goto err; + return bt; err: @@ -756,7 +766,6 @@ static void blk_trace_setup_finalize(struct request_queue *q, bt->trace_state = Blktrace_setup; rcu_assign_pointer(q->blk_trace, bt); - get_probe_ref(); } int blk_trace_setup(struct request_queue *q, char *name, dev_t dev, @@ -1324,49 +1333,106 @@ 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) + return ret; ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_rq_insert; ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_rq_issue; ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_rq_merge; ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_rq_requeue; ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_rq_complete; ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_bio_complete; ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_bio_backmerge; ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_bio_frontmerge; ret = register_trace_block_getrq(blk_add_trace_getrq, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_bio_queue; ret = register_trace_blk_zone_append_update_request_bio( blk_add_trace_zone_update_request, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_getrq; ret = register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL); - WARN_ON(ret); + if (ret) + goto unreg_blk_zone_append_update_request_bio; ret = register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL); - WARN_ON(ret); + if (ret) + goto unreg_disk_zone_wplug_add_bio; ret = register_trace_block_plug(blk_add_trace_plug, NULL); - WARN_ON(ret); + if (ret) + goto unreg_blk_zone_wplug_bio; ret = register_trace_block_unplug(blk_add_trace_unplug, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_plug; ret = register_trace_block_split(blk_add_trace_split, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_unplug; ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_split; ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); - WARN_ON(ret); + if (ret) + goto unreg_block_bio_remap; + return 0; + +unreg_block_bio_remap: + unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL); +unreg_block_split: + unregister_trace_block_split(blk_add_trace_split, NULL); +unreg_block_unplug: + unregister_trace_block_unplug(blk_add_trace_unplug, NULL); +unreg_block_plug: + unregister_trace_block_plug(blk_add_trace_plug, NULL); +unreg_blk_zone_wplug_bio: + unregister_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, NULL); +unreg_disk_zone_wplug_add_bio: + unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL); +unreg_blk_zone_append_update_request_bio: + unregister_trace_blk_zone_append_update_request_bio( + blk_add_trace_zone_update_request, NULL); +unreg_block_getrq: + unregister_trace_block_getrq(blk_add_trace_getrq, NULL); +unreg_block_bio_queue: + unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); +unreg_block_bio_frontmerge: + unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); +unreg_block_bio_backmerge: + unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL); +unreg_block_bio_complete: + unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL); +unreg_block_rq_complete: + unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); +unreg_block_rq_requeue: + unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); +unreg_block_rq_merge: + unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL); +unreg_block_rq_issue: + unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); +unreg_block_rq_insert: + unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL); + tracepoint_synchronize_unregister(); + return ret; } static void blk_unregister_tracepoints(void) @@ -1916,8 +1982,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: -- 2.43.0