From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796326829; b=CIxX+qAMzxN+UgIvgLls/uRG+KSZwJZa22dROru/FRiLnlKucsIdfIBD7Ib/hK74NTgh 0g2MKJgJON5S3bFzR4CC/w96xhCm7wmhBfvNMZKOigW4hlZp5t5RWkajqH8nHFhvu6F0a CjQZtMXA9Fq+aOGgdG/NOV7Y1XyS3ZOnlfbgcJ6EMIfAv8RICZuDJ9kdyDJjaHbb2orGr Dof2B2rJrFZO5ry5uwaC6Uvbx+ungNJVuXd5zW3MqbmafupTygNt5Rb5my7F5zSZoW077 t4yJfebqJDF3o9NPxU/rw1TB3+4oZg8jpvXEXPKUNByhU3hRZsX/fsbKWZPaK5/XqEw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796326829; 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=PZzNPSsgbc54nT0Cyg0HwvcmBliBt32cZrblrnbf7OX6m+tn6I3WJI7ucKwkcRYsquHM r/2gtDsV4U85tFu6itmtGnKOeB9BJMotA75utMREej8GzvdRv5dO8lWSpYWAg58p6X2+l +sRqrtTArFhJtHKx9EGszqT5qiErAdgBXjyGeqGWNdzElpf2qmpQK+0U6M+xGH2qWBosd IdGx5trTNjCBDPMwgWlDwOaL/3apcP+Xl4Kaokg0WJHjYblMaIWVYJ5DFRhkVeBHGsbTZ hVJ3xvHHSs1DrBQxpdTJPqu/plmUOsJlU9OVqrPS0uRQlHUMilnoh7vey7LkpFgxPMg== 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.42 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 7493A60A3808 for ; Thu, 3 Dec 2026 19:40:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7493A60A3808 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-f42.google.com with SMTP id 5b1f17b1804b1-4bb6ba3b244so1015365e9.3 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=ztF6ZHdnBxlcp2OxvVF16k4VclnlFVlTr/j+MPacpZpljQYFyt/Fjgb/Bzq2wtctzL DRWQ3zzu++8l6lBHzom4hAa5BVHgYPtfXea/geQu5ZduvTwfLF2ajf8lMgV2MEz112UX gRxgMzIYO/1TxxibAQ4FQ5a/Bu3zG8p2LLPQc+FLQ3T6isxaT4F3LXfS7vJUfK4qIq55 LrHreLRd5Sia0fhVGhT4LdS3L/DCuLXxgQ4g8kRhb2BfdV6eZA/KXizRgL1b/B3tmf9M uXrR5OQbK00JJ6pvZ6yNAec0RNlOPbH+7dj5LFpZu+clx82E/Ejj79mqV3+MEUgMQDJT fjrw== X-Forwarded-Encrypted: i=1; AL+hErHrYHlYfsJFb1tQzh3OMagUg62dzZwOcEVziB2gbICdaVQakThHnqyjVIYubLlYTBNyRuRt6I300nvvo7NY12Olg3M=@vger.kernel.org X-Gm-Message-State: APuU4Z9uWmhMLOUdQKWkcC7EO30POw9falCo37+MTUT+yd5Hyuo9fd/R ulgPbEWpSuINtcbDruzJWMe/Jk0kgSyIu277raMnwF3t/U9VDEKm2RB8 X-Gm-Gg: AZFdTZf0a7FIhCEgx5FeLrR+9idFvwPjYr8jvd2pyte5pOzj4Po5H0wUnDbkH2vF9kH gH3Iybjp37iSoZ6gST/vbOxevw1k7i1JvfKN+a53Ro6xU8+/mMFn4Wd0/NQewGcizHwptYvS2Db pdkE7zbB/AjmnAw+4G0AJ6EUcxEevcIXWSChavvZhr/fb7Vvpfzwhk/w2VIl3UWxUUviXSkjYcw Dz4vgi804uL9a06hm5GnFriWZmsQIa17ZPoPaMqW/0halPKg9o1dC1M20UOl5T69yK1rmQvGeMb y0The8aSZy6pC6cdqkRsVWyP9eA1tz3WIFlrc3/YBJKXKu+67IAwCrNJGYbWX5omt7FQg0CQcwf BgmZCAyhMTWJT1a+epLfrEyGlkE1tTR++39HyKofPsdjuJZa4xjSe0PL/gYY13HPdK++oAu1+hU wrTlIGShfPEMH6GNn6+6CV+J2U/8PVixAztnKjRisFyrX0KJtnT5YATNqbu/oXRTfCiS9TyDXn0 QdOKqAuyur2MbjNNXuI0vUXbHRGjG6B9HBq0Mwp3++q3n9FF7pTBLTa3BJ1WgG1xBKVuw35Iq2I dHEjclOoxv9hm1HInoQZW7wbV1yU0UKWnCgB 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-trace-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