From nobody Mon Feb 9 12:04:09 2026 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AC3633EB01; Wed, 22 Oct 2025 11:41:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133291; cv=none; b=WHF/g/VMOlUk8UJ5kMLaUz3ALzNAMMlXKLCUaB2j7Nk5YmdnwftH8m4QuGLlsoa0KahYdVDxNO8/IBB2LSFqn5jUsEltYVsHXjEYsiHQs6NBER0iQNeWbgZQOhUBsqWxdDjAFI6v0LfwdzG2tYZ274dEbO7/BJg0RNAap7ZWCJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133291; c=relaxed/simple; bh=ADgSVbzcBq0V5YuQtV/YJ3D05FWKwC8OY4ZG3MiehRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=INjQCEp4kKGLRGVy0yvKa0uOEiGwo0XA0AWus6D7jTuWCABjsto9F2N1Gn70gyyMUkgl42xNgXwbHbsKKmXlyHPKlhmCg7VnMscnzn7ULhmOTv4Ki8pSzGWHJ9FBR9YoBt2SdZN+rDarp5f978Fxa9p8Jfo0Nzt84xkOailclGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=g0/fIfVx; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="g0/fIfVx" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133290; x=1792669290; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ADgSVbzcBq0V5YuQtV/YJ3D05FWKwC8OY4ZG3MiehRk=; b=g0/fIfVxrJovzoXaiNlwzeNBkzWdnHaCKOtNPgx7cyrwKO48XJ0jO44y XMUUSQe8VJKbATmyuDz1j3xC7+CxN8dIMi7cLe+efEYReuvDY7Qj+LzmK 6v/7dFDYqDnRNrkfLezw5VOC19wYHBIW0q8oIWLor4yFADbT1o3HPgchy 8oa8RzJjxPRZiGj/K0pRJogIVviKW9PVxkMU/QWvwmzoeP9wNuC5tiieg ETqTahv9pj+BA6QYCwM0wP6KEEwMLA61Hs4tu9SlPQk3X2w6nSwtmhp1M 4WT3TSzpjAlqJ7IxPjhMwwakajcIT4IomOugtlWq2iAlUhK1PSWzf82Yj g==; X-CSE-ConnectionGUID: zJI2/K99SUyIiJuWvst3BA== X-CSE-MsgGUID: LVjD4RmGT7ShTTIjvvAXAA== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="133361403" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:41:29 +0800 IronPort-SDR: 68f8c2e9_EXR0otZSTKDKSo0qtQhGpY8087xHMYWP68lM1Ff9PchOLAm e4Ohg912l6Bu/X5W0YxI4XfqGwH0SdUkQuVWJ/w== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:41:29 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:41:24 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 01/16] blktrace: only calculate trace length once Date: Wed, 22 Oct 2025 13:41:00 +0200 Message-ID: <20251022114115.213865-2-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" De-duplicate the calculation of the trace length instead of doing the calculation twice, once for calling trace_buffer_lock_reserve() and once for calling relay_reserve(). Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 6941145b5058..bc4b885f2cec 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -76,13 +76,14 @@ static void trace_note(struct blk_trace *bt, pid_t pid,= int action, int cpu =3D smp_processor_id(); bool blk_tracer =3D blk_tracer_enabled; ssize_t cgid_len =3D cgid ? sizeof(cgid) : 0; + size_t trace_len; =20 + trace_len =3D sizeof(*t) + cgid_len + len; if (blk_tracer) { buffer =3D blk_tr->array_buffer.buffer; trace_ctx =3D tracing_gen_ctx_flags(0); event =3D trace_buffer_lock_reserve(buffer, TRACE_BLK, - sizeof(*t) + len + cgid_len, - trace_ctx); + trace_len, trace_ctx); if (!event) return; t =3D ring_buffer_event_data(event); @@ -92,7 +93,7 @@ static void trace_note(struct blk_trace *bt, pid_t pid, i= nt action, if (!bt->rchan) return; =20 - t =3D relay_reserve(bt->rchan, sizeof(*t) + len + cgid_len); + t =3D relay_reserve(bt->rchan, trace_len); if (t) { t->magic =3D BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; t->time =3D ktime_to_ns(ktime_get()); @@ -228,6 +229,7 @@ static void __blk_add_trace(struct blk_trace *bt, secto= r_t sector, int bytes, bool blk_tracer =3D blk_tracer_enabled; ssize_t cgid_len =3D cgid ? sizeof(cgid) : 0; const enum req_op op =3D opf & REQ_OP_MASK; + size_t trace_len; =20 if (unlikely(bt->trace_state !=3D Blktrace_running && !blk_tracer)) return; @@ -250,14 +252,14 @@ static void __blk_add_trace(struct blk_trace *bt, sec= tor_t sector, int bytes, return; cpu =3D raw_smp_processor_id(); =20 + trace_len =3D sizeof(*t) + pdu_len + cgid_len; if (blk_tracer) { tracing_record_cmdline(current); =20 buffer =3D blk_tr->array_buffer.buffer; trace_ctx =3D tracing_gen_ctx_flags(0); event =3D trace_buffer_lock_reserve(buffer, TRACE_BLK, - sizeof(*t) + pdu_len + cgid_len, - trace_ctx); + trace_len, trace_ctx); if (!event) return; t =3D ring_buffer_event_data(event); @@ -273,7 +275,7 @@ static void __blk_add_trace(struct blk_trace *bt, secto= r_t sector, int bytes, * from coming in and stepping on our toes. */ local_irq_save(flags); - t =3D relay_reserve(bt->rchan, sizeof(*t) + pdu_len + cgid_len); + t =3D relay_reserve(bt->rchan, trace_len); if (t) { sequence =3D per_cpu_ptr(bt->sequence, cpu); =20 --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6ACD33EB1A; Wed, 22 Oct 2025 11:41:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133304; cv=none; b=tX91jmw4Klo8dhz/ymmDQRnWOcaWcZ2q3OUeD1YN5ZKZb12xvGrMcqMdzo47VsH4PsgzF6a6+53UQ/znSBnaWRAX1k0IiXNrqXNn0jinlwVLUDh6NTnKWUQ3C+E3Uvjef1cK0SLhTChL8b3RPZIT15XdkLwiKn+gkruAps7hnII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133304; c=relaxed/simple; bh=gv+dFYy3s4VK7ov7yAgwFpwK0TaZXEebgZ82qqjBYbg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UTmlnwCn132TuAqpUXbKvFPfQQECXhwTnUJmtCYmI4zGhuhTam6B4iIt3zjp87WmLks7ZrldfkL8eaTuyeNGllVPVWB6DatDR6jG2HhCAOcl2rbQ7dnXhZmqDmXcU5MSYiftZRxTzmmEKonGDIiKb4YTouJry3Obq/7a3ZbFI4Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=n6dA+vwQ; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="n6dA+vwQ" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133302; x=1792669302; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gv+dFYy3s4VK7ov7yAgwFpwK0TaZXEebgZ82qqjBYbg=; b=n6dA+vwQCcEX3G0zJZfwyTKKlQii3Y5e6FqpdPPvqSVOyQxHFJeBttcz YkutHe5d9zZaLilfL8iHlcWos43pGbKFqJE2NSvyF/OQCqn8O2LehNbu+ 41Ycp67YTEK/AmwVTwu/+EkKOWCrnc7zt3YgVeZgOJYnw1Dw1/YKtodAo ML5olydlgPFxzAYx8lJceNnj/RoYIYFdhGbzPWyRXegeCeAWL6Jx6S2PK Zfd5a3IkqzuLt+ymsQLgfiB9+CtM7cp/cMUaTl6h3beebN1sl+OiZfqOk utOSsMgppZjg1JemRG2z1uhw/TbEX62FzisBgfyAeJwdp1+g477EAY9xp g==; X-CSE-ConnectionGUID: VQrw5gm2QC2HhbFueSYJsw== X-CSE-MsgGUID: n07Vk2FmSce54aCGh/R7dg== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="134941203" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:41:36 +0800 IronPort-SDR: 68f8c2f0_4BCMyvjNg6/DSvmsKCnaJ9M9t1oIn4IWsLyUy9FyvQf3/Cn 7fKYvtDtdoJyNJ6Zyq9TuV8dMMvFiJ6wW0uXHeA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:41:36 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:41:30 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 02/16] blktrace: factor out recording a blktrace event Date: Wed, 22 Oct 2025 13:41:01 +0200 Message-ID: <20251022114115.213865-3-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out the recording of a blktrace event into its own function, deduplicating the code. This also enables recording different versions of the blktrace protocol later on. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 89 +++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index bc4b885f2cec..25a0a1b09747 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -63,6 +63,34 @@ static int blk_probes_ref; static void blk_register_tracepoints(void); static void blk_unregister_tracepoints(void); =20 +static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int c= pu, + sector_t sector, int bytes, u32 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 + * generic trace_entry, filled by tracing_generic_entry_update, + * but for the trace_event->bin() synthesizer benefit we do it + * here too. + */ + t->cpu =3D cpu; + t->pid =3D pid; + + t->sector =3D sector; + t->bytes =3D bytes; + t->action =3D what; + t->device =3D dev; + t->error =3D error; + t->pdu_len =3D pdu_len + cgid_len; + + if (cgid_len) + memcpy((void *)t + sizeof(*t), &cgid, cgid_len); + if (pdu_len) + memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len); +} + /* * Send out a notify message. */ @@ -87,7 +115,12 @@ static void trace_note(struct blk_trace *bt, pid_t pid,= int action, if (!event) return; t =3D ring_buffer_event_data(event); - goto record_it; + record_blktrace_event(t, pid, cpu, 0, 0, + action | (cgid ? __BLK_TN_CGROUP : 0), + bt->dev, 0, cgid, cgid_len, (void *)data, + len); + trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); + return; } =20 if (!bt->rchan) @@ -97,18 +130,11 @@ static void trace_note(struct blk_trace *bt, pid_t pid= , int action, if (t) { t->magic =3D BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; t->time =3D ktime_to_ns(ktime_get()); -record_it: - t->device =3D bt->dev; - t->action =3D action | (cgid ? __BLK_TN_CGROUP : 0); - t->pid =3D pid; - t->cpu =3D cpu; - t->pdu_len =3D len + cgid_len; - if (cgid_len) - memcpy((void *)t + sizeof(*t), &cgid, cgid_len); - memcpy((void *) t + sizeof(*t) + cgid_len, data, len); - - if (blk_tracer) - trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); + + record_blktrace_event(t, pid, cpu, 0, 0, + action | (cgid ? __BLK_TN_CGROUP : 0), + bt->dev, 0, cgid, cgid_len, (void *)data, + len); } } =20 @@ -263,7 +289,12 @@ static void __blk_add_trace(struct blk_trace *bt, sect= or_t sector, int bytes, if (!event) return; t =3D ring_buffer_event_data(event); - goto record_it; + + record_blktrace_event(t, pid, cpu, sector, bytes, what, bt->dev, + error, cgid, cgid_len, pdu_data, pdu_len); + + trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); + return; } =20 if (unlikely(tsk->btrace_seq !=3D blktrace_seq)) @@ -282,32 +313,10 @@ static void __blk_add_trace(struct blk_trace *bt, sec= tor_t sector, int bytes, t->magic =3D BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; t->sequence =3D ++(*sequence); t->time =3D ktime_to_ns(ktime_get()); -record_it: - /* - * These two are not needed in ftrace as they are in the - * generic trace_entry, filled by tracing_generic_entry_update, - * but for the trace_event->bin() synthesizer benefit we do it - * here too. - */ - t->cpu =3D cpu; - t->pid =3D pid; - - t->sector =3D sector; - t->bytes =3D bytes; - t->action =3D what; - t->device =3D bt->dev; - t->error =3D error; - t->pdu_len =3D pdu_len + cgid_len; - - if (cgid_len) - memcpy((void *)t + sizeof(*t), &cgid, cgid_len); - if (pdu_len) - memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len); - - if (blk_tracer) { - trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); - return; - } + + record_blktrace_event(t, pid, cpu, sector, bytes, what, + bt->dev, error, cgid, cgid_len, + pdu_data, pdu_len); } =20 local_irq_restore(flags); --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7440933F8BA; Wed, 22 Oct 2025 11:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133305; cv=none; b=BJguzeRtURKfumFaTtoJw71iP0X4q9/wffcz7yONEtingHNA9NFxhYmed1UmYG+qorFGRQyxiBq9FYL41NiR7/aFvtuFN0GRvKJG3E8x1wwlryB1YBWdbD8iZ5gRXVHXL8L0z/FNNAqwVY2Be5YfaYw63yd2Wx+kDdDu8u9omQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133305; c=relaxed/simple; bh=gvMcnJErKmeoJEU+g5e8MFYI7VZaM80fU3zGf4bO3+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nLFMBnHa/LR/e/0wNnMKFC3us87uj2h/NFQCBVUkNdGmjdNX/MP47KIFFWq68vcFB3xd/ms+/9xnkm1bsjflmsd+9Jip6e/8mIrT2WSDm2PG5Id+uMhrXUvEjL+Svm7A5xPAJiUCy7XqFiijWCR8/4+4a1Hala+InpB74fj0Ii0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=TyL346i4; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="TyL346i4" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133303; x=1792669303; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gvMcnJErKmeoJEU+g5e8MFYI7VZaM80fU3zGf4bO3+M=; b=TyL346i4SMGVtrpTfhS91OpVnqHuzm5Dvl6PjC+pWz8mTPOR1kjt/fXN ZUsWqKlxDahGdnAS7KgO1IuQI3BoH0OTcY5bgQ6uEs/7GRR7AjQPv1FTI vZKWof2ARw6FtTUovDMkIzmCl/N5w/01a7kMQE8smUTxxyB0178TNgmAt XHsnHz8UvMpLYr4QFeumJEY1Jygk2k9hfv++6A0nfFK/iu5BbfSUs9d1i Y0Q7sMojeiXHi8uKefXxyvhlcTmRv8002crd+BNiTRuM6rUe4cILVWvoI A8cGJsPgyrt6RH2W2VicmBOt0iitlBhB9+i0Bg9NByLckSBFVJyLn6KzR w==; X-CSE-ConnectionGUID: +QuadXNWR1Sp+Zb5E/tvVA== X-CSE-MsgGUID: BMjOiv4FRyqpiYzJd3jukw== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="134941205" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:41:42 +0800 IronPort-SDR: 68f8c2f6_+oTo46p5OhQOdU3711zeFZLq5YYR2rq1g7A/ZNYQ6YdQiq4 io+GwKdUxvEsAIf2n9vVr4fg7rKmZc96v/D98cg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:41:42 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:41:37 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 03/16] blktrace: split out relaying a blktrace event Date: Wed, 22 Oct 2025 13:41:02 +0200 Message-ID: <20251022114115.213865-4-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Split out the code relaying a blktrace event to user-space using relayfs. This enables adding a second version supporting a new version of the protocol. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 60 ++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 25a0a1b09747..51745832c713 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -91,6 +91,26 @@ static void record_blktrace_event(struct blk_io_trace *t= , pid_t pid, int cpu, memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len); } =20 +static void relay_blktrace_event(struct blk_trace *bt, unsigned long seque= nce, + pid_t pid, int cpu, sector_t sector, int bytes, + u32 what, int error, u64 cgid, + ssize_t cgid_len, void *pdu_data, int pdu_len) +{ + struct blk_io_trace *t; + size_t trace_len =3D sizeof(*t) + pdu_len + cgid_len; + + t =3D relay_reserve(bt->rchan, trace_len); + if (!t) + return; + + t->magic =3D BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; + t->sequence =3D sequence; + t->time =3D ktime_to_ns(ktime_get()); + + record_blktrace_event(t, pid, cpu, sector, bytes, what, bt->dev, error, + cgid, cgid_len, pdu_data, pdu_len); +} + /* * Send out a notify message. */ @@ -126,16 +146,9 @@ static void trace_note(struct blk_trace *bt, pid_t pid= , int action, if (!bt->rchan) return; =20 - t =3D relay_reserve(bt->rchan, trace_len); - if (t) { - t->magic =3D BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; - t->time =3D ktime_to_ns(ktime_get()); - - record_blktrace_event(t, pid, cpu, 0, 0, - action | (cgid ? __BLK_TN_CGROUP : 0), - bt->dev, 0, cgid, cgid_len, (void *)data, - len); - } + relay_blktrace_event(bt, 0, pid, cpu, 0, 0, + action | (cgid ? __BLK_TN_CGROUP : 0), 0, cgid, + cgid_len, (void *)data, len); } =20 /* @@ -246,7 +259,6 @@ static void __blk_add_trace(struct blk_trace *bt, secto= r_t sector, int bytes, struct task_struct *tsk =3D current; struct ring_buffer_event *event =3D NULL; struct trace_buffer *buffer =3D NULL; - struct blk_io_trace *t; unsigned long flags =3D 0; unsigned long *sequence; unsigned int trace_ctx =3D 0; @@ -278,20 +290,21 @@ static void __blk_add_trace(struct blk_trace *bt, sec= tor_t sector, int bytes, return; cpu =3D raw_smp_processor_id(); =20 - trace_len =3D sizeof(*t) + pdu_len + cgid_len; if (blk_tracer) { tracing_record_cmdline(current); =20 buffer =3D blk_tr->array_buffer.buffer; trace_ctx =3D tracing_gen_ctx_flags(0); + trace_len =3D sizeof(struct blk_io_trace) + pdu_len + cgid_len; event =3D trace_buffer_lock_reserve(buffer, TRACE_BLK, trace_len, trace_ctx); if (!event) return; - t =3D ring_buffer_event_data(event); =20 - record_blktrace_event(t, pid, cpu, sector, bytes, what, bt->dev, - error, cgid, cgid_len, pdu_data, pdu_len); + record_blktrace_event(ring_buffer_event_data(event), + pid, cpu, sector, bytes, what, bt->dev, + error, cgid, cgid_len, pdu_data, + pdu_len); =20 trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); return; @@ -306,19 +319,10 @@ static void __blk_add_trace(struct blk_trace *bt, sec= tor_t sector, int bytes, * from coming in and stepping on our toes. */ local_irq_save(flags); - t =3D relay_reserve(bt->rchan, trace_len); - if (t) { - sequence =3D per_cpu_ptr(bt->sequence, cpu); - - t->magic =3D BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; - t->sequence =3D ++(*sequence); - t->time =3D ktime_to_ns(ktime_get()); - - record_blktrace_event(t, pid, cpu, sector, bytes, what, - bt->dev, error, cgid, cgid_len, - pdu_data, pdu_len); - } - + sequence =3D per_cpu_ptr(bt->sequence, cpu); + (*sequence)++; + relay_blktrace_event(bt, *sequence, pid, cpu, sector, bytes, what, + error, cgid, cgid_len, pdu_data, pdu_len); local_irq_restore(flags); } =20 --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2FEB33FE29; Wed, 22 Oct 2025 11:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133312; cv=none; b=oql9iMMoe++vTiGgwx5GPWUIq31a06ekqtMy5DX44/0QfKcXH/BFQ9CzNIKuxba2cLDTNnA5JdHjjxmQXoWij/RJ8rYwVJLClA+mx9V28ShQfil3s5A1XVg4lHBf8HvAYIcLcmzPwj7DR671qLe9a6Rq/6jiXARyknNmBPCzGz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133312; c=relaxed/simple; bh=6UqJq2BMhc+A1IyyPDtrogLrG71nL4mSKTyglrkvdQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=th8Lx8K4eQmW7E0WCQnKN9isqJfn+Nc3smdtAtlKjFrzqtwXcWZ1K/MB4nS2gM8XXRS5LRDbVBnnA2/9TY39uAqDFn1UxEah8RRlfwwLcj5KrbGCv8+O8uvhMugATHc9B0REkR0u8W7UrGPfH2nY4TEaDpp3uKD6fZVL6dYjggs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=GLKNrGhz; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="GLKNrGhz" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133310; x=1792669310; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6UqJq2BMhc+A1IyyPDtrogLrG71nL4mSKTyglrkvdQU=; b=GLKNrGhzCVGyGGbrqQ1joehRhazdOmrGijCAIT8oogTMT+0pFJJNUYL3 jgZlZAmnfmg4w3YwMj8GZwZtZvHuJkgwqPqwSeKUuqGweCbRcJuzW2sjc 1aEpaIrMjY0iC9JdaKTVNSi8cscyFzpT55CltPeC+wdG91Fm4O9OYUyKs MOIUxnc48hNazgCn0lGdJERoFfARxzVtmUIt5ukYcWCMMmUUJkNi37Itw XGXFGaDg4p6QQN3iaR6TADYgKSixuwsjADTPPmqZRY5tIZJFvhrias2mK p8L2p7OW5sbyivymFAqi6djpHj7sDYBHt4TslRQNn9Cf42dREOJrFKYkx A==; X-CSE-ConnectionGUID: 41vOPZEyTT6kTYhzpxwwCA== X-CSE-MsgGUID: ohx/GmI4SHum7TEDWQMqtg== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="133361422" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:41:49 +0800 IronPort-SDR: 68f8c2fd_ApjH2wFii9jCPTTysdtHZI1LY/rYNRwHryMoPgue9ZoeggU OPEtiWrLAln279TR+yDG4DC6Dvcq7ZsYZLuIzGA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:41:49 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:41:43 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 04/16] blktrace: untangle if/else sequence in __blk_add_trace Date: Wed, 22 Oct 2025 13:41:03 +0200 Message-ID: <20251022114115.213865-5-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Untangle the if/else sequence setting the trace action in __blk_add_trace() and turn it into a switch statement for better extensibility. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 51745832c713..11e264f67851 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -278,10 +278,19 @@ static void __blk_add_trace(struct blk_trace *bt, sec= tor_t sector, int bytes, what |=3D MASK_TC_BIT(opf, META); what |=3D MASK_TC_BIT(opf, PREFLUSH); what |=3D MASK_TC_BIT(opf, FUA); - if (op =3D=3D REQ_OP_DISCARD || op =3D=3D REQ_OP_SECURE_ERASE) + + switch (op) { + case REQ_OP_DISCARD: + case REQ_OP_SECURE_ERASE: what |=3D BLK_TC_ACT(BLK_TC_DISCARD); - if (op =3D=3D REQ_OP_FLUSH) + break; + case REQ_OP_FLUSH: what |=3D BLK_TC_ACT(BLK_TC_FLUSH); + break; + default: + break; + } + if (cgid) what |=3D __BLK_TA_CGROUP; =20 --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9793A340DA5; Wed, 22 Oct 2025 11:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133317; cv=none; b=iZA49ubI8fCUF5RwOo/sJ8ilHy8CA25QV0Aoqc/J4mr+Xk5YOz/x13NJMF2gkfE45C4qv4idy+DSAfFjaoff+0R7hvBpWguBymCqlq5xawT++Vcqf+P2xRyWJjWHjPdjw5xp2w1eiaw/YSt8RS0NpI1h/2tyt/bzsyydRvxaeuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133317; c=relaxed/simple; bh=vP0ejefhX06ARC5GUWCgLZK36fXmQPZMkH2ll9176xg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uk76hxiMWJnoH5SmEiSefJ9F1wRC/5l+Fd6uzuuMSKUh0xuHzS/9gmqmb8an6c7AgYsOausAuVYlicrL5+QHMrIUPn94G1tYetASvcbe7rA+q5stJQJTe+PW+Rq5grS2jDmgnnvJTh0aPljqYHhqbNA8CfKBo2NbvGRyaDqcS+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=WYctQU2Y; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="WYctQU2Y" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133315; x=1792669315; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vP0ejefhX06ARC5GUWCgLZK36fXmQPZMkH2ll9176xg=; b=WYctQU2Y1jfaZt5aOGJ5FOgfFCb0iEVGDVeyOP+YRGQ+0Omufh0Kq8P0 oS6bojI/U6b/b0bq/47yF9IsfX9+Tmv5nPaNjBG9xtYWUM5WZNU9x0T+j EMw8o+Y8befz37AqyBXH3nd6tcC/O/PCM/CyBD1cDcRH7NrMsbvd6pOsX lMARjbIqmbbUIyS2puXK3j1HSHiGyF3zLhYXy/Q3N+uRDQIAYkFN57dq6 1tppjiZitkQ8NmA1N0T1rd63UYTsO3fNolJ6amwyVTFzDhqRa6LKjbfqJ 7Y/jNYCcmut2JPoMSsNeFCk8wT0gzO5gGw2ocRQgu7qlKzuEs+TRP07+Q g==; X-CSE-ConnectionGUID: crqDarSOQk6j/CTcDPj4Kg== X-CSE-MsgGUID: hfFcJfDeTnCwptGyQUvcag== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="133361425" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:41:55 +0800 IronPort-SDR: 68f8c303_7yswm5UxcQJ/yxzH/XARJWQpzWIHMPS45TQZb8zooYzNkQL 4K5XJae5vtw4TAB2v/cWmFEt3ZvQm0fsfnQyMGw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:41:55 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:41:49 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 05/16] blktrace: change the internal action to 64bit Date: Wed, 22 Oct 2025 13:41:04 +0200 Message-ID: <20251022114115.213865-6-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change the internal use of the action in blktrace to 64bit. Although for now only the lower 32bits will be used. With the upcoming version 2 of the blktrace user-space protocol the upper 32bit will also be utilized. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 11e264f67851..15d6788700ca 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -64,7 +64,7 @@ static void blk_register_tracepoints(void); static void blk_unregister_tracepoints(void); =20 static void record_blktrace_event(struct blk_io_trace *t, pid_t pid, int c= pu, - sector_t sector, int bytes, u32 what, + sector_t sector, int bytes, u64 what, dev_t dev, int error, u64 cgid, ssize_t cgid_len, void *pdu_data, int pdu_len) =20 @@ -80,7 +80,7 @@ static void record_blktrace_event(struct blk_io_trace *t,= pid_t pid, int cpu, =20 t->sector =3D sector; t->bytes =3D bytes; - t->action =3D what; + t->action =3D lower_32_bits(what); t->device =3D dev; t->error =3D error; t->pdu_len =3D pdu_len + cgid_len; @@ -93,7 +93,7 @@ static void record_blktrace_event(struct blk_io_trace *t,= pid_t pid, int cpu, =20 static void relay_blktrace_event(struct blk_trace *bt, unsigned long seque= nce, pid_t pid, int cpu, sector_t sector, int bytes, - u32 what, int error, u64 cgid, + u64 what, int error, u64 cgid, ssize_t cgid_len, void *pdu_data, int pdu_len) { struct blk_io_trace *t; @@ -114,7 +114,7 @@ static void relay_blktrace_event(struct blk_trace *bt, = unsigned long sequence, /* * Send out a notify message. */ -static void trace_note(struct blk_trace *bt, pid_t pid, int action, +static void trace_note(struct blk_trace *bt, pid_t pid, u64 action, const void *data, size_t len, u64 cgid) { struct blk_io_trace *t; @@ -127,6 +127,7 @@ static void trace_note(struct blk_trace *bt, pid_t pid,= int action, size_t trace_len; =20 trace_len =3D sizeof(*t) + cgid_len + len; + action =3D lower_32_bits(action | (cgid ? __BLK_TN_CGROUP : 0)); if (blk_tracer) { buffer =3D blk_tr->array_buffer.buffer; trace_ctx =3D tracing_gen_ctx_flags(0); @@ -136,9 +137,8 @@ static void trace_note(struct blk_trace *bt, pid_t pid,= int action, return; t =3D ring_buffer_event_data(event); record_blktrace_event(t, pid, cpu, 0, 0, - action | (cgid ? __BLK_TN_CGROUP : 0), - bt->dev, 0, cgid, cgid_len, (void *)data, - len); + action, bt->dev, 0, cgid, cgid_len, + (void *)data, len); trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); return; } @@ -146,8 +146,7 @@ static void trace_note(struct blk_trace *bt, pid_t pid,= int action, if (!bt->rchan) return; =20 - relay_blktrace_event(bt, 0, pid, cpu, 0, 0, - action | (cgid ? __BLK_TN_CGROUP : 0), 0, cgid, + relay_blktrace_event(bt, 0, pid, cpu, 0, 0, action, 0, cgid, cgid_len, (void *)data, len); } =20 @@ -222,7 +221,7 @@ void __blk_trace_note_message(struct blk_trace *bt, } EXPORT_SYMBOL_GPL(__blk_trace_note_message); =20 -static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector, +static int act_log_check(struct blk_trace *bt, u64 what, sector_t sector, pid_t pid) { if (((bt->act_mask << BLK_TC_SHIFT) & what) =3D=3D 0) @@ -253,7 +252,7 @@ static const u32 ddir_act[2] =3D { BLK_TC_ACT(BLK_TC_RE= AD), * blk_io_trace structure and places it in a per-cpu subbuffer. */ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int byt= es, - const blk_opf_t opf, u32 what, int error, + const blk_opf_t opf, u64 what, int error, int pdu_len, void *pdu_data, u64 cgid) { struct task_struct *tsk =3D current; @@ -311,9 +310,9 @@ static void __blk_add_trace(struct blk_trace *bt, secto= r_t sector, int bytes, return; =20 record_blktrace_event(ring_buffer_event_data(event), - pid, cpu, sector, bytes, what, bt->dev, - error, cgid, cgid_len, pdu_data, - pdu_len); + pid, cpu, sector, bytes, + what, bt->dev, error, cgid, cgid_len, + pdu_data, pdu_len); =20 trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); return; @@ -330,8 +329,9 @@ static void __blk_add_trace(struct blk_trace *bt, secto= r_t sector, int bytes, local_irq_save(flags); sequence =3D per_cpu_ptr(bt->sequence, cpu); (*sequence)++; - relay_blktrace_event(bt, *sequence, pid, cpu, sector, bytes, what, - error, cgid, cgid_len, pdu_data, pdu_len); + relay_blktrace_event(bt, *sequence, pid, cpu, sector, bytes, + lower_32_bits(what), error, cgid, cgid_len, + pdu_data, pdu_len); local_irq_restore(flags); } =20 @@ -818,7 +818,7 @@ blk_trace_request_get_cgid(struct request *rq) * **/ static void blk_add_trace_rq(struct request *rq, blk_status_t error, - unsigned int nr_bytes, u32 what, u64 cgid) + unsigned int nr_bytes, u64 what, u64 cgid) { struct blk_trace *bt; =20 @@ -882,7 +882,7 @@ static void blk_add_trace_rq_complete(void *ignore, str= uct request *rq, * **/ static void blk_add_trace_bio(struct request_queue *q, struct bio *bio, - u32 what, int error) + u64 what, int error) { struct blk_trace *bt; =20 @@ -948,7 +948,7 @@ static void blk_add_trace_unplug(void *ignore, struct r= equest_queue *q, bt =3D rcu_dereference(q->blk_trace); if (bt) { __be64 rpdu =3D cpu_to_be64(depth); - u32 what; + u64 what; =20 if (explicit) what =3D BLK_TA_UNPLUG_IO; --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 675EA341665; Wed, 22 Oct 2025 11:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133322; cv=none; b=WeNxKLc6NLqruTUfz3QTXFWH8ZAPftqOQPdi5IjdLcG2djoTCx+iGdL+bTMU+ZTPUWSN901BzMYAHxC79EQGPUoPWzEM96ntgdavoARnB3p7mZu1/SdJ5TjRl9bDrlgbv2yqHeEOLrY5s5fKOXwjX09/PN65T38vySuLF9W3AhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133322; c=relaxed/simple; bh=CMWz8k5N389mFEAOrl+B0ZkalXYJ8znl0A0OMErx4Wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j6s5ojuTBvrypmEsWc4yg337nn+jTaC0nFv8rxx9m/lgKVx90OnD0dnS09v2IWFcF9Uo0gvLx9oSDBOe3szR1et0/8k5/AAaUmOLfc1xuRpTZS3ek43sSaLH91WwakfyN4UJzQm5y8Q63FLgFz5BVJr+RGjHCeCG/x5U8MjLbzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=kRGizCFY; arc=none smtp.client-ip=216.71.154.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="kRGizCFY" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133320; x=1792669320; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CMWz8k5N389mFEAOrl+B0ZkalXYJ8znl0A0OMErx4Wo=; b=kRGizCFYPVw50J+T/HE4U/ZJ0Cwjiwk1QIEabv9FcYWl+JHcup65fEIe WXMJJha7Az5Re+iZ/kzZWVhguMLAwGh3Hm0PphgICXY/AnkWv+9gd1d7T 0g1bNy5IhZ26PqiiBPqQ6MTaUfffKY/AizZrdrrXtxss87zX95gBE9ozC lDLvwCq/cDAR76xKyWlnX+Q6RcL8zzl0fvWDyPyHsPLLuaxRwC1b80Uur Bhtep0haDQdkx0BTcBZ6q2CVCHJXJ/XOigsL9dw2XoJHTy/QkOUnoErE3 UpKnlFqMdtRJOZCCRqTgrSQ/cFM3Hy4HsAcx8p98716MM9s6xR891RdK4 g==; X-CSE-ConnectionGUID: OAGcVelvRZOmExYvAxXuvQ== X-CSE-MsgGUID: Dks3DyA1SkeXodDH0wETCg== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="133361431" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:00 +0800 IronPort-SDR: 68f8c308_cQO1Mf9y23lFoPdXlkckSWnEVK8WMLwvv3flBdlBNoNNcTT nkNbKMxHf/5AL2MK3lAwNXFYS1Qe6eJAmBQDzJg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:00 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:41:56 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 06/16] blktrace: split do_blk_trace_setup into two functions Date: Wed, 22 Oct 2025 13:41:05 +0200 Message-ID: <20251022114115.213865-7-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 94 ++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 38 deletions(-) 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 d= ev, - 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 =3D NULL; struct dentry *dir =3D NULL; @@ -528,31 +529,19 @@ static int do_blk_trace_setup(struct request_queue *q= , char *name, dev_t dev, =20 lockdep_assert_held(&q->debugfs_mutex); =20 - 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); } =20 bt =3D kzalloc(sizeof(*bt), GFP_KERNEL); if (!bt) - return -ENOMEM; + return ERR_PTR(-ENOMEM); =20 ret =3D -ENOMEM; bt->sequence =3D 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 =3D q->debugfs_dir; else - bt->dir =3D dir =3D debugfs_create_dir(buts->name, blk_debugfs_root); + bt->dir =3D dir =3D debugfs_create_dir(name, blk_debugfs_root); =20 /* * 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 =3D -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); =20 - bt->rchan =3D relay_open("trace", dir, buts->buf_size, - buts->buf_nr, &blk_relay_callbacks, bt); + bt->rchan =3D relay_open("trace", dir, buf_size, buf_nr, + &blk_relay_callbacks, bt); if (!bt->rchan) goto err; =20 + 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 =3D buts->act_mask; if (!bt->act_mask) bt->act_mask =3D (u16) -1; =20 - blk_trace_setup_lba(bt, bdev); - /* overwrite with user settings */ if (buts->start_lba) bt->start_lba =3D buts->start_lba; @@ -615,12 +624,6 @@ static int do_blk_trace_setup(struct request_queue *q,= char *name, dev_t dev, =20 rcu_assign_pointer(q->blk_trace, bt); get_probe_ref(); - - ret =3D 0; -err: - if (ret) - blk_trace_free(q, bt); - return ret; } =20 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 *na= me, dev_t dev, char __user *arg) { struct blk_user_trace_setup buts; + struct blk_trace *bt; int ret; =20 ret =3D copy_from_user(&buts, arg, sizeof(buts)); if (ret) return -EFAULT; =20 + if (!buts.buf_size || !buts.buf_nr) + return -EINVAL; + mutex_lock(&q->debugfs_mutex); - ret =3D do_blk_trace_setup(q, name, dev, bdev, &buts); + bt =3D 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; =20 if (copy_to_user(arg, &buts, sizeof(buts))) { blk_trace_remove(q); @@ -655,11 +666,14 @@ static int compat_blk_trace_setup(struct request_queu= e *q, char *name, { struct blk_user_trace_setup buts; struct compat_blk_user_trace_setup cbuts; - int ret; + struct blk_trace *bt; =20 if (copy_from_user(&cbuts, arg, sizeof(cbuts))) return -EFAULT; =20 + if (!cbuts.buf_size || !cbuts.buf_nr) + return -EINVAL; + buts =3D (struct blk_user_trace_setup) { .act_mask =3D cbuts.act_mask, .buf_size =3D cbuts.buf_size, @@ -670,10 +684,14 @@ static int compat_blk_trace_setup(struct request_queu= e *q, char *name, }; =20 mutex_lock(&q->debugfs_mutex); - ret =3D do_blk_trace_setup(q, name, dev, bdev, &buts); + bt =3D 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; =20 if (copy_to_user(arg, &buts.name, ARRAY_SIZE(buts.name))) { blk_trace_remove(q); --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C49E33F8DC; Wed, 22 Oct 2025 11:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133334; cv=none; b=X7MKrcXfq6BhHdeG0DrULmqxY83EtdSGoFzGdP/Fn9JmjG1bbiEgv35xXZTq7zq9KxB9BryafLx8S4w6zMUCZowxYO/lMjlnLY3yDyXoPQTj/d6oIL48mQ1jzCW6TMiNDdwjhsbzvWBR5UEyrLwNn/OWe9dqh5SbA40FqxcgZH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133334; c=relaxed/simple; bh=iq2X3nOgnodZJ+8DGg7jgGlCzZQ9MPo4YQTwgSs3PUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dmtqr4sc/ge6a1FRG8PRqoRp8yUxIeX/xWxLHWzL5RJAmNSc8Yh9tziolZsl6n9fj92IsAxI77+D45sLMXcw7Y/nEOcWkYZcuzvdp1iPhETPhFjZ/72bF6wNiDvLi8nKgweQoViDooK6frXPfG9OG+Nfr9C//HW0prVMfHVLTBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=j7Ziv9R9; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="j7Ziv9R9" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133333; x=1792669333; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iq2X3nOgnodZJ+8DGg7jgGlCzZQ9MPo4YQTwgSs3PUw=; b=j7Ziv9R9mu1hpugb61dzqHUxV2iKN2nTDDZsLZz8U8OMQt/UK/ajWRpN rcKaTceEyDWxdLdutXwwgiHILY5GrUslC3d3b5uAfxk0nqMMhX3g7Y0Bp FwIeEM+EqP1TUjT1eoQ27YD3IxaR1UVXH/1fWSYFYOw5z6qB9pokS5fdE +PaHH0PPtQP9L1wvuEGA0/U6uOkqdkXkFU9ZUrezPqmcyOevsW3uUMmCN pO2wvwFUzjxbmwlJq8zqPZiACM5dvC7+A+/hDS9nlmDya+IZvKJGIGAsa jJqg9ufa3NDZ2c4r/n3qmaFb9hi11UVVfdMLIv+Rv1zHnW+JgLKv3Ph+A g==; X-CSE-ConnectionGUID: 8e1Lg5WwTxWGWi8wTjv5HQ== X-CSE-MsgGUID: so8vYTkZSQq7G3s96BLwIw== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="134645048" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:07 +0800 IronPort-SDR: 68f8c30e_l9Eyavs5yy3th084WWVfCb0Yta9BVigben/0R/smoCUSYnZ VLrWXLDIOgol8ES/FgT/lnTQW50Mp1zdTkTALqw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:06 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:01 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 07/16] blktrace: add definitions for blk_user_trace_setup2 Date: Wed, 22 Oct 2025 13:41:06 +0200 Message-ID: <20251022114115.213865-8-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add definitions for a version 2 of the blk_user_trace_setup ioctl. This new ioctl will enable a different struct layout of the binary data passed to user-space when using a new version of the blktrace utility requesting the new struct layout. Reviewed-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- include/uapi/linux/blktrace_api.h | 16 ++++++++++++++++ include/uapi/linux/fs.h | 1 + kernel/trace/blktrace.c | 3 +++ 3 files changed, 20 insertions(+) diff --git a/include/uapi/linux/blktrace_api.h b/include/uapi/linux/blktrac= e_api.h index 1bfb635e309b..a6958708d477 100644 --- a/include/uapi/linux/blktrace_api.h +++ b/include/uapi/linux/blktrace_api.h @@ -129,6 +129,7 @@ enum { }; =20 #define BLKTRACE_BDEV_SIZE 32 +#define BLKTRACE_BDEV_SIZE2 64 =20 /* * User setup structure passed with BLKTRACESETUP @@ -143,4 +144,19 @@ struct blk_user_trace_setup { __u32 pid; }; =20 +/* + * User setup structure passed with BLKTRACESETUP2 + */ +struct blk_user_trace_setup2 { + char name[BLKTRACE_BDEV_SIZE2]; /* output */ + __u64 act_mask; /* input */ + __u32 buf_size; /* input */ + __u32 buf_nr; /* input */ + __u64 start_lba; + __u64 end_lba; + __u32 pid; + __u32 flags; /* currently unused */ + __u64 reserved[11]; +}; + #endif /* _UAPIBLKTRACE_H */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index beb4c2d1e41c..957ce3343a4f 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -300,6 +300,7 @@ struct file_attr { #define BLKGETDISKSEQ _IOR(0x12,128,__u64) /* 130-136 are used by zoned block device ioctls (uapi/linux/blkzoned.h) */ /* 137-141 are used by blk-crypto ioctls (uapi/linux/blk-crypto.h) */ +#define BLKTRACESETUP2 _IOWR(0x12, 142, struct blk_user_trace_setup2) =20 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */ diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index df90422ae613..c31b8f433116 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -1601,6 +1601,9 @@ static int __init init_blk_tracer(void) return 1; } =20 + BUILD_BUG_ON(__alignof__(struct blk_user_trace_setup2) % + __alignof__(long)); + return 0; } =20 --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 818C733FE2E; Wed, 22 Oct 2025 11:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133336; cv=none; b=sErDKJHhNYSIxwv/mm8PENRAH5hObBZBJ9gVMyaqeOpAMm5SiT8iiLDD9rx22mc5MEDi8iIRWcW0XmYlI6I3d9ecku28QC8Gnls1SCKTPTOLn8RSgC3SAEKhAXYkWySYTLjFZmlveRk8wcdsXSvGtqzW4nPCTCqYqdFTYv7vJ8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133336; c=relaxed/simple; bh=168ia+hdpRO/sFAwkDBCIsxq3ROnt6Lp/jc2ZZmovJ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JrjtyX53YlfBlq3HU7QDzw/nAYLCyEsKiQFsrjW1lzkscmFmlpOMdIbHgHoYDu5S6WdETYdeWKXQmJE8TYCNqNkfIA+V1oE9r9Y4Dzo4J2INESF3smOon1WvQ1cLXgUq935bjcezDAyJHCLjPXC0ym5WOaZKpyiqPk5C+Z6tnJs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=oBwTlm3/; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="oBwTlm3/" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133334; x=1792669334; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=168ia+hdpRO/sFAwkDBCIsxq3ROnt6Lp/jc2ZZmovJ8=; b=oBwTlm3/Mq6+RW9AYMDb5ClmmFdGKOEvcbb8AVmEhYsaLg4KYG6tLTwo 7J80AUye9STR7dZdSQpBTGXWsTT7GkhpwSmRYrvOZuDSCnjHBMGuCl8A5 4DAY3fBQJLDBsyQojaAe2wAYAwGNCFWWuN13BTK6/Pvx3a63/KpOPuExX kQN3DsDgApXVoBH56CSNZ5dQ9gdcndWyvsjjfpWa3Wz/LLEMTMhjDKxxc 5pfJzG4yc54reJt2drYOLePJbAVfkwVZnAWzlEJ1Vm5aSM7MRGihSDVn0 LIS6/6HHko2/dLDxP4nPrf9wVRkc51CegJj1LkJ+quBSav3gOHM8CrVw0 g==; X-CSE-ConnectionGUID: J8126GWaS026rNoRFxR2nA== X-CSE-MsgGUID: VPSO+7GjT9qFeEqqYVIgtw== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="134941231" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:13 +0800 IronPort-SDR: 68f8c315_HAab86HSQTie9NFQKxWzlNtGwOZQOl9+SVhCrAyeHWmWwgD sADrW9HRUGpvcQpv4WiF8f5eIFYm8nUo7GEvuWA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep03.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:14 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:07 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 08/16] blktrace: pass blk_user_trace2 to setup functions Date: Wed, 22 Oct 2025 13:41:07 +0200 Message-ID: <20251022114115.213865-9-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass struct blk_user_trace_setup2 to blktrace_setup_finalize(). This prepares for the incoming extension of the blktrace protocol with a 64bit act_mask. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- include/linux/blktrace_api.h | 3 ++- kernel/trace/blktrace.c | 31 ++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h index 122c62e561fc..05c8754456aa 100644 --- a/include/linux/blktrace_api.h +++ b/include/linux/blktrace_api.h @@ -14,11 +14,12 @@ #include =20 struct blk_trace { + int version; int trace_state; struct rchan *rchan; unsigned long __percpu *sequence; unsigned char __percpu *msg_data; - u16 act_mask; + u64 act_mask; u64 start_lba; u64 end_lba; u32 pid; diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index c31b8f433116..d1532df84cc8 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -597,11 +597,12 @@ static struct blk_trace *blk_trace_setup_prepare(stru= ct request_queue *q, } =20 static void blk_trace_setup_finalize(struct request_queue *q, - char *name, struct blk_trace *bt, - struct blk_user_trace_setup *buts) + char *name, int version, + struct blk_trace *bt, + struct blk_user_trace_setup2 *buts) =20 { - strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE); + strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE2); =20 /* * some device names have larger paths - convert the slashes @@ -609,6 +610,7 @@ static void blk_trace_setup_finalize(struct request_que= ue *q, */ strreplace(buts->name, '/', '_'); =20 + bt->version =3D version; bt->act_mask =3D buts->act_mask; if (!bt->act_mask) bt->act_mask =3D (u16) -1; @@ -630,6 +632,7 @@ 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; int ret; @@ -641,6 +644,15 @@ int blk_trace_setup(struct request_queue *q, char *nam= e, dev_t dev, if (!buts.buf_size || !buts.buf_nr) return -EINVAL; =20 + buts2 =3D (struct blk_user_trace_setup2) { + .act_mask =3D buts.act_mask, + .buf_size =3D buts.buf_size, + .buf_nr =3D buts.buf_nr, + .start_lba =3D buts.start_lba, + .end_lba =3D buts.end_lba, + .pid =3D buts.pid, + }; + mutex_lock(&q->debugfs_mutex); bt =3D blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr, bdev); @@ -648,7 +660,8 @@ int blk_trace_setup(struct request_queue *q, char *name= , dev_t dev, mutex_unlock(&q->debugfs_mutex); return PTR_ERR(bt); } - blk_trace_setup_finalize(q, name, bt, &buts); + blk_trace_setup_finalize(q, name, 1, bt, &buts2); + strcpy(buts.name, buts2.name); mutex_unlock(&q->debugfs_mutex); =20 if (copy_to_user(arg, &buts, sizeof(buts))) { @@ -664,7 +677,7 @@ 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_setup buts; + struct blk_user_trace_setup2 buts2; struct compat_blk_user_trace_setup cbuts; struct blk_trace *bt; =20 @@ -674,7 +687,7 @@ static int compat_blk_trace_setup(struct request_queue = *q, char *name, if (!cbuts.buf_size || !cbuts.buf_nr) return -EINVAL; =20 - buts =3D (struct blk_user_trace_setup) { + buts2 =3D (struct blk_user_trace_setup2) { .act_mask =3D cbuts.act_mask, .buf_size =3D cbuts.buf_size, .buf_nr =3D cbuts.buf_nr, @@ -684,16 +697,16 @@ static int compat_blk_trace_setup(struct request_queu= e *q, char *name, }; =20 mutex_lock(&q->debugfs_mutex); - bt =3D blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr, + bt =3D blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr, bdev); if (IS_ERR(bt)) { mutex_unlock(&q->debugfs_mutex); return PTR_ERR(bt); } - blk_trace_setup_finalize(q, name, bt, &buts); + blk_trace_setup_finalize(q, name, 1, bt, &buts2); mutex_unlock(&q->debugfs_mutex); =20 - if (copy_to_user(arg, &buts.name, ARRAY_SIZE(buts.name))) { + if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) { blk_trace_remove(q); return -EFAULT; } --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A1A833FE30; Wed, 22 Oct 2025 11:42:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133348; cv=none; b=oknzKJ71gEwYAu69zNxgPcYw5uJlowz4Csg7TBtZczr4+QBCaollNmGwdw3/FFpG/dBEo3Nw5Q6skzMmi6MquemV7u8nzS6TfvAdiSe9IepMOS6jW9ngzSUicaJMib/BMF25daBpbvrcves26HjTXKSxWLWl5bKqU0/3gvHSeaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133348; c=relaxed/simple; bh=AuIHhNtYt14BLpZyopQ9lNncTR/cskfIc/vi+rtUyXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YlURIbACYYo6ksko3RuNZGy5Y9N7oGJYIRBfzLNdqgElFj+u7lf5bwkuOVlOBkkPlNfgONtxAy/j0eit+4QjA6uePUTajxzWdK5mNjVDQQvrGZA1MiMnHVNgcBY5nTj1tlNCW8sIN7UEfGKoTTDYGzpo02iuHHoL5zzaUO00rLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=mDQkV9o9; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="mDQkV9o9" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133347; x=1792669347; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AuIHhNtYt14BLpZyopQ9lNncTR/cskfIc/vi+rtUyXQ=; b=mDQkV9o9by74JRFr32pC2ko1DeHRylIszlsjAQ1/CucHMnYKSS/s8ULu StTJG9lISD92V7Ex6/b0ZsCPww8FERvWrl7wcCnjiFyOi/U3tfpGCmfbW 3/zsi0uAM8gIlhm+OXx1GElcj10sa78v9SQsDQtYA3IRdNMX5xY+Jj0U9 1tPTkhCuz5JhCpvJ9JlgWFV4sW3PET6fSoI7mHMgXN7eWdnB4tpVVLuTO qW3Trp2pn+o4W4wAEEUPNxtyZxaSTU2oiVlSXDU79p6v/G9rvhL65JXOv SSokRJWCvcLu0OEAMS+t3qzwBzPb3s3Dk0/oMagunyAxQfoGC5efZQ6Ja g==; X-CSE-ConnectionGUID: ACheWtIERxOCH8WRufAp6w== X-CSE-MsgGUID: WJkgUl/4SimyjQfAGPRCOQ== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="130696092" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:21 +0800 IronPort-SDR: 68f8c31c_DEq8zXQGo6h4wh/QUewre8MIlaW0s4l3B/p8PoYCzq1giu4 Y5nWwVapXNqNMDFfTk2L/WV5n6M1gY/Po9ftSbA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep03.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:20 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:14 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 09/16] blktrace: add definitions for struct blk_io_trace2 Date: Wed, 22 Oct 2025 13:41:08 +0200 Message-ID: <20251022114115.213865-10-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add definitions for the extended version of the blktrace protocol using a wider action type to be able to record new actions in the kernel. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- include/uapi/linux/blktrace_api.h | 16 ++++++++++++++++ kernel/trace/blktrace.c | 1 + 2 files changed, 17 insertions(+) diff --git a/include/uapi/linux/blktrace_api.h b/include/uapi/linux/blktrac= e_api.h index a6958708d477..9f9834d76e00 100644 --- a/include/uapi/linux/blktrace_api.h +++ b/include/uapi/linux/blktrace_api.h @@ -94,6 +94,7 @@ enum blktrace_notify { =20 #define BLK_IO_TRACE_MAGIC 0x65617400 #define BLK_IO_TRACE_VERSION 0x07 +#define BLK_IO_TRACE2_VERSION 0x08 =20 /* * The trace itself @@ -113,6 +114,21 @@ struct blk_io_trace { /* cgroup id will be stored here if exists */ }; =20 +struct blk_io_trace2 { + __u32 magic; /* MAGIC << 8 | BLK_IO_TRACE2_VERSION */ + __u32 sequence; /* event number */ + __u64 time; /* in nanoseconds */ + __u64 sector; /* disk offset */ + __u32 bytes; /* transfer length */ + __u32 pid; /* who did it */ + __u64 action; /* what happened */ + __u32 device; /* device number */ + __u32 cpu; /* on what cpu did it happen */ + __u16 error; /* completion error */ + __u16 pdu_len; /* length of data after this trace */ + __u8 pad[12]; + /* cgroup id will be stored here if it exists */ +}; /* * The remap event */ diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index d1532df84cc8..185f19c9f772 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -1616,6 +1616,7 @@ static int __init init_blk_tracer(void) =20 BUILD_BUG_ON(__alignof__(struct blk_user_trace_setup2) % __alignof__(long)); + BUILD_BUG_ON(__alignof__(struct blk_io_trace2) % __alignof__(long)); =20 return 0; } --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5960133EB1A; Wed, 22 Oct 2025 11:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133349; cv=none; b=UUb9f5c20lqbEzzScdTjRReswwx+K9conEjjf2b0707tukLufJ2KmgGSQOTczPh5knQzAwKoUs4h7nGphVc3IVpK3XIu1AuQAcDmnXHPfn36bhjuUE4YuTbkVSZgyphG62Ukj5q1O8aCHG0I0GR7S/FjCwGBs88hXE1DKRqyOjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133349; c=relaxed/simple; bh=037FbZQmDVubQU4lKjBcgHnjO77xnBw5gmh0v/JuuxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uiwgz9yLayBj8p632SNHpN8JAwzG+iIgkuTYHe/EXqZWkWfIc5czb138jBVDGuGu24E9ftxzh+G0U+uBoCPo9tF9LRxpM8CUhM9OmdJ/lmUFVau5Dc+muy1111pmoG9EzmubcPGvQfjAoxytmWmY47sZzD47+Qw9Gnc1H1FtL+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=kdx6LKwK; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="kdx6LKwK" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133348; x=1792669348; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=037FbZQmDVubQU4lKjBcgHnjO77xnBw5gmh0v/JuuxI=; b=kdx6LKwKLPuLfnhm8X2Q1/Dia4gQMdMX48egOYPjfbkIJ/lBLV91K5x6 EMdVNwiD/KPZ1JQXgwEmJt+/SnhOn4LRY3/ODrVJ5qAI2WcTNo8uAYsHK ebUJNKE+CM0QJbJTtLzBHMY0TzQh9DiaSYC9Ob7Z8ZS2v4hSojgTi9fN+ C/q6OzkW8Ej3Lq5JPoykbJz4cBCk/rtf/r+C+WnQoQVhgcWHGUc/yos+h OHH2Z56JzbRGmKP/PYLKJ5ZxPCf35NyYNfoMhPd4mxAC7J1kfm391cMaY cYME/DBE5iHtu5AiyEZGTqDkI/nck0LQRzGdZhz+E050ykXVTmQI0+ehJ w==; X-CSE-ConnectionGUID: RgQB2KMhQ1+K5fhHR3+zew== X-CSE-MsgGUID: OnpNB9Q4RyKvf14aiIAVFQ== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="134645063" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:27 +0800 IronPort-SDR: 68f8c322_+XAqUIoGQQDrbz8X3tKKNlwqqU0p4Mb7/hBdUft2SFNwttH TcrVTU+inse3Lpo0eL/DIIneoNl1UTGdKfwFJKw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep03.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:26 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:21 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 10/16] blktrace: differentiate between blk_io_trace versions Date: Wed, 22 Oct 2025 13:41:09 +0200 Message-ID: <20251022114115.213865-11-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Differentiate between blk_io_trace and blk_io_trace2 when relaying to user-space depending on which version has been requested by the blktrace utility. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 58 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 185f19c9f772..5f8ecf88a196 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -91,7 +91,29 @@ static void record_blktrace_event(struct blk_io_trace *t= , pid_t pid, int cpu, memcpy((void *)t + sizeof(*t) + cgid_len, pdu_data, pdu_len); } =20 -static void relay_blktrace_event(struct blk_trace *bt, unsigned long seque= nce, +static void record_blktrace_event2(struct blk_io_trace2 *t2, pid_t pid, in= t 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) +{ + t2->pid =3D pid; + t2->cpu =3D cpu; + + t2->sector =3D sector; + t2->bytes =3D bytes; + t2->action =3D what; + t2->device =3D dev; + t2->error =3D error; + t2->pdu_len =3D pdu_len + cgid_len; + + if (cgid_len) + memcpy((void *)t2 + sizeof(*t2), &cgid, cgid_len); + if (pdu_len) + memcpy((void *)t2 + sizeof(*t2) + cgid_len, pdu_data, pdu_len); +} + +static void relay_blktrace_event1(struct blk_trace *bt, unsigned long sequ= ence, pid_t pid, int cpu, sector_t sector, int bytes, u64 what, int error, u64 cgid, ssize_t cgid_len, void *pdu_data, int pdu_len) @@ -111,6 +133,40 @@ static void relay_blktrace_event(struct blk_trace *bt,= unsigned long sequence, cgid, cgid_len, pdu_data, pdu_len); } =20 +static void relay_blktrace_event2(struct blk_trace *bt, unsigned long sequ= ence, + pid_t pid, int cpu, sector_t sector, + int bytes, u64 what, int error, u64 cgid, + ssize_t cgid_len, void *pdu_data, int pdu_len) +{ + struct blk_io_trace2 *t; + size_t trace_len =3D sizeof(struct blk_io_trace2) + pdu_len + cgid_len; + + t =3D relay_reserve(bt->rchan, trace_len); + if (!t) + return; + + t->magic =3D BLK_IO_TRACE_MAGIC | BLK_IO_TRACE2_VERSION; + t->sequence =3D sequence; + t->time =3D ktime_to_ns(ktime_get()); + + record_blktrace_event2(t, pid, cpu, sector, bytes, what, bt->dev, error, + cgid, cgid_len, pdu_data, pdu_len); +} + +static void relay_blktrace_event(struct blk_trace *bt, unsigned long seque= nce, + pid_t pid, int cpu, sector_t sector, int bytes, + u64 what, int error, u64 cgid, + ssize_t cgid_len, void *pdu_data, int pdu_len) +{ + if (bt->version =3D=3D 2) + return relay_blktrace_event2(bt, sequence, pid, cpu, sector, + bytes, what, error, cgid, cgid_len, + pdu_data, pdu_len); + return relay_blktrace_event1(bt, sequence, pid, cpu, sector, bytes, + lower_32_bits(what), error, cgid, cgid_len, + pdu_data, pdu_len); +} + /* * Send out a notify message. */ --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D8D733EB1A; Wed, 22 Oct 2025 11:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133355; cv=none; b=aNcVEbHPDYjHTiRejg3UGH+gJmSpPzCSw7JHeM7qF+wlg039G8E/R5liZ+jpk41QVpS46HIINki42/eYb74SWZwyDumcxF1YEzBxmDIcDZfASpzas5PX/npvhth7gc0CV1S+LSPUNfooktT7cFJnydCz9sE/2CF8aTmZ0e9hSqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133355; c=relaxed/simple; bh=Tg+InoiUkixMTHRjKqO+3LE4IbRDh+1Zw8VhpQekT20=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rb3dgRsg1Q/qY246Jx/WCfsJvMkyDM8g9wOmQKDoIMYTfb2EIot9E0xLWqYD0NSRwLNZMp2k7PV7XGpEw3UbxJozpnvTmbtK5lAJYHM3TodKODL9u5pGfFGM4PZWzZMY7+/48OgGHfEslznl5uE0xFysvKwmAC+omEZK51BKZ2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=gHnbhSC8; arc=none smtp.client-ip=68.232.141.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="gHnbhSC8" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133353; x=1792669353; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tg+InoiUkixMTHRjKqO+3LE4IbRDh+1Zw8VhpQekT20=; b=gHnbhSC8iVPeRKFxloCickHG7Vs53KMSlvurQamWVytKLmbk4jrsMP53 Wq5gn9nU8r5Hk/twcMqbMFpJTpt3jvp1HpASeFnqZJOwRn4K47Fs5yBBn 7LYpgBz4p7l3nQ97wL4aGZFFVxEGsI5uuNJvr1jJ2x4zDhwyqEw4iPvQF g+o8GJYyB5F1cvhR78DTzStOSOnuxbIgNpkYKqGPFmcB+mRegINoQ8wYi bxmXXrZvVese3Qkzh7M0JTyeTCJc37YUovgM2SfK6D0Ab71t4LZIzJvkD b8DoiSYgCzo5hFQrgH7jzDOUrDze25N0Lo0L9n1eO5xZq7lxy7HUqla69 A==; X-CSE-ConnectionGUID: j6t1p72fRS+p2e4ReBqImQ== X-CSE-MsgGUID: l4LFWQDVT3ehXxIHnbSTew== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="133602971" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:32 +0800 IronPort-SDR: 68f8c328_JjQpdq0BI8qfTDBgrZOvMLqw94bT0V61Scd27TnviZQvSHO +5onhUwG0/oVhO8Oj89aFmKAAINPhL0r9ltMQeQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep03.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:32 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:27 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 11/16] blktrace: move trace_note to blk_io_trace2 Date: Wed, 22 Oct 2025 13:41:10 +0200 Message-ID: <20251022114115.213865-12-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move trace_note() to the new blk_io_trace2 infrastructure. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 5f8ecf88a196..08c7be671c47 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -173,18 +173,18 @@ static void relay_blktrace_event(struct blk_trace *bt= , unsigned long sequence, static void trace_note(struct blk_trace *bt, pid_t pid, u64 action, const void *data, size_t len, u64 cgid) { - struct blk_io_trace *t; struct ring_buffer_event *event =3D NULL; struct trace_buffer *buffer =3D NULL; unsigned int trace_ctx =3D 0; int cpu =3D smp_processor_id(); bool blk_tracer =3D blk_tracer_enabled; ssize_t cgid_len =3D cgid ? sizeof(cgid) : 0; - size_t trace_len; =20 - trace_len =3D sizeof(*t) + cgid_len + len; action =3D lower_32_bits(action | (cgid ? __BLK_TN_CGROUP : 0)); if (blk_tracer) { + struct blk_io_trace2 *t; + size_t trace_len =3D sizeof(*t) + cgid_len + len; + buffer =3D blk_tr->array_buffer.buffer; trace_ctx =3D tracing_gen_ctx_flags(0); event =3D trace_buffer_lock_reserve(buffer, TRACE_BLK, @@ -192,9 +192,9 @@ static void trace_note(struct blk_trace *bt, pid_t pid,= u64 action, if (!event) return; t =3D ring_buffer_event_data(event); - record_blktrace_event(t, pid, cpu, 0, 0, - action, bt->dev, 0, cgid, cgid_len, - (void *)data, len); + record_blktrace_event2(t, pid, cpu, 0, 0, + action, bt->dev, 0, cgid, cgid_len, + (void *)data, len); trace_buffer_unlock_commit(blk_tr, buffer, event, trace_ctx); return; } @@ -359,7 +359,7 @@ static void __blk_add_trace(struct blk_trace *bt, secto= r_t sector, int bytes, =20 buffer =3D blk_tr->array_buffer.buffer; trace_ctx =3D tracing_gen_ctx_flags(0); - trace_len =3D sizeof(struct blk_io_trace) + pdu_len + cgid_len; + trace_len =3D sizeof(struct blk_io_trace2) + pdu_len + cgid_len; event =3D trace_buffer_lock_reserve(buffer, TRACE_BLK, trace_len, trace_ctx); if (!event) --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7532341654; Wed, 22 Oct 2025 11:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133360; cv=none; b=LNh/Qg54T38fbovGd/O+tFsiTsR7jLMkWTiU/l+5xnQS8CHSJE7JMqjN2s9oAunn93xGDUCNu8MbsRAlv9bVpPb+5YBTzg4fvAJqbymBUQmLH/tV2bQ+CffmKAzKDpSeG8mOvh9hNmhb+8tIdXziCjnimvFR52K6WUg+acmvvZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133360; c=relaxed/simple; bh=LFEizxCvFbQ0Ntn9zhfflmElENDRtO31yhPsdgpW0ZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GKRiRMhJ6hAKJc+ubUqZQX01LcifGoobAa/9Qw5FdqqrQN4KBr17zu22YeZLyK3n6MDKp04jDum4XxA+ZEX5/Dd+fjf5+GnFYFypLWu20wDE2slILLFHvema9nipQs/qwcVMbmcMYkzXlMD346cSHqpGdz7N5I3lfasUxFYpEfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=f/Q3Apko; arc=none smtp.client-ip=68.232.141.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="f/Q3Apko" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133359; x=1792669359; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LFEizxCvFbQ0Ntn9zhfflmElENDRtO31yhPsdgpW0ZM=; b=f/Q3ApkobRysMVJj8uOdFvN3Bv3amTNuj+0jc3H5m2awp0/QK7tJK6uS OhnGiVpxwmtzVz87lM66WLIEri6XzaF0B59FLIBtQzs6+2JEKo1kCiMbi xcd9fqtAhWEh6CcQEYEMuzrSuNLTyKPwmfdAPse+5VXx9Ylv4/qB5EtVl L09gdVizxYhcC7imtDUEod6gwuxlfOrg4iBWZ7bOlp+qe9fTjif440dHG lwW8wn78K7rkmZV3jvAbrG2wVx+OmaKwGvCwihmNXvBH2f5mEytsuQ8gu iuu5vaBw6Gl6CpkLmnLbxCe5In/Rr8A0eG87hS56W6VMSSKru6p0kOY3R Q==; X-CSE-ConnectionGUID: 7zoU02V7QSSXe18sbQlJSA== X-CSE-MsgGUID: 7g3tZjDrSp2cHmIlJW5uiA== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="133602974" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:38 +0800 IronPort-SDR: 68f8c32e_tOjQ7NbQsSvG8iHjkjl5tWqwKQ36GD85JjwMPzfZGbyoibA Y5KRApgxtD8JqLG9CUxjvqzI5RdUjqzTOIG96FQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep03.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:38 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:33 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 12/16] blktrace: move ftrace blk_io_tracer to blk_io_trace2 Date: Wed, 22 Oct 2025 13:41:11 +0200 Message-ID: <20251022114115.213865-13-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move ftrace's blk_io_tracer to the new blk_io_trace2 infrastructure. Reviewed-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- kernel/trace/blktrace.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 08c7be671c47..49f73cb3cb33 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -1224,7 +1224,7 @@ static void blk_unregister_tracepoints(void) * struct blk_io_tracer formatting routines */ =20 -static void fill_rwbs(char *rwbs, const struct blk_io_trace *t) +static void fill_rwbs(char *rwbs, const struct blk_io_trace2 *t) { int i =3D 0; int tc =3D t->action >> BLK_TC_SHIFT; @@ -1259,9 +1259,9 @@ static void fill_rwbs(char *rwbs, const struct blk_io= _trace *t) } =20 static inline -const struct blk_io_trace *te_blk_io_trace(const struct trace_entry *ent) +const struct blk_io_trace2 *te_blk_io_trace(const struct trace_entry *ent) { - return (const struct blk_io_trace *)ent; + return (const struct blk_io_trace2 *)ent; } =20 static inline const void *pdu_start(const struct trace_entry *ent, bool ha= s_cg) @@ -1320,7 +1320,7 @@ static void blk_log_action_classic(struct trace_itera= tor *iter, const char *act, unsigned long long ts =3D iter->ts; unsigned long nsec_rem =3D do_div(ts, NSEC_PER_SEC); unsigned secs =3D (unsigned long)ts; - const struct blk_io_trace *t =3D te_blk_io_trace(iter->ent); + const struct blk_io_trace2 *t =3D te_blk_io_trace(iter->ent); =20 fill_rwbs(rwbs, t); =20 @@ -1334,7 +1334,7 @@ static void blk_log_action(struct trace_iterator *ite= r, const char *act, bool has_cg) { char rwbs[RWBS_LEN]; - const struct blk_io_trace *t =3D te_blk_io_trace(iter->ent); + const struct blk_io_trace2 *t =3D te_blk_io_trace(iter->ent); =20 fill_rwbs(rwbs, t); if (has_cg) { @@ -1555,7 +1555,7 @@ static enum print_line_t print_one_line(struct trace_= iterator *iter, { struct trace_array *tr =3D iter->tr; struct trace_seq *s =3D &iter->seq; - const struct blk_io_trace *t; + const struct blk_io_trace2 *t; u16 what; bool long_act; blk_log_action_t *log_action; @@ -1592,8 +1592,8 @@ static enum print_line_t blk_trace_event_print(struct= trace_iterator *iter, static void blk_trace_synthesize_old_trace(struct trace_iterator *iter) { struct trace_seq *s =3D &iter->seq; - struct blk_io_trace *t =3D (struct blk_io_trace *)iter->ent; - const int offset =3D offsetof(struct blk_io_trace, sector); + struct blk_io_trace2 *t =3D (struct blk_io_trace2 *)iter->ent; + const int offset =3D offsetof(struct blk_io_trace2, sector); struct blk_io_trace old =3D { .magic =3D BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION, .time =3D iter->ts, --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 014A733F8BD; Wed, 22 Oct 2025 11:42:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133368; cv=none; b=Mm+TD/u7gjyYm4gICt7LlJe0sLKWSsq5AfyvyIudQYmlRMXl2Nu3aFnviYqJtueGhajVf+5vqxvpT2x4xzWVQmmbHL75CZBHto85PNdNUoYc8Tuk9rHXv1/07LXiRQgWZGL4iqUQgLUXr9ve9OKBGv1nvux1/ejsZsqqkf7xPgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133368; c=relaxed/simple; bh=mFiBi3Qc+9B/JELtOoFO2CfJzbXZg5Eb/g44EpfjJA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=myJLNVSGFM36vTQr32qVze6LwHfTZhzQHk1DNtDt1jOnNKvkD9YI2QgglckIXNwGCSj4/j4tMzc0NzUauImSUeMdieBl8+Q2VFkb8xMli6rOaJg6YhD7lNpnPcq09L5De5x4YcR3E/XKnBrn2vlhdNoGx7r/G7JrnTwXLyslsGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=Npv+1xFZ; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Npv+1xFZ" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133367; x=1792669367; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mFiBi3Qc+9B/JELtOoFO2CfJzbXZg5Eb/g44EpfjJA8=; b=Npv+1xFZmWPD17A1dD6d7tD9WehX4XNvqFey/igpGD7BvUhHxl3+6Ckj UxU0LP6gApiZG1TgyAG9+O1767EAHecE1oCN8nr2hGasmN+ZejypfKwuc kpIvuJ+jP8+ppm4sG3dO7wuZoKaeXZ560wEKGsBX+j1s6NrwI9IHXakhT 0vsVYNgTvFaF4qMoZfE0om24Pv7yQl9qoEVxKgN2TpqYKVhfNsyzQbuyg BzGkUAQb+aLA0Yil32JA4CXXjQXyxWTGWqh1luxoH5cyxL+O7q9A1F1+1 bpgHT70xjLV/4KQAP07DmFk8DW5n2Bs+SJtb+ySeEyi1wc+ZRrGliJUWc w==; X-CSE-ConnectionGUID: 3YHVlVeKRQGLUgP238SrnA== X-CSE-MsgGUID: JSi7Vd8uR9aiyLZ4Tudk2w== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="130696117" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:47 +0800 IronPort-SDR: 68f8c336_usCoP6zDQEjjaS/RO2wkPDu/2egN5/E0Lx/Md+J4kgu1b6g suuD7Y37j9uUlZy+lYhi7mBjZS+L4dVahcn46QQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:46 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:39 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 13/16] blktrace: add block trace commands for zone operations Date: Wed, 22 Oct 2025 13:41:12 +0200 Message-ID: <20251022114115.213865-14-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add block trace commands for zone operations. These commands can only be handled with version 2 of the blktrace protocol. For version 1, warn if a command that does not fit into the 16 bits reserved for the command in this version is passed in. Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn Reviewed-by: Damien Le Moal --- include/uapi/linux/blktrace_api.h | 13 +++++++++++-- kernel/trace/blktrace.c | 29 +++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/blktrace_api.h b/include/uapi/linux/blktrac= e_api.h index 9f9834d76e00..190a3c5ab0a0 100644 --- a/include/uapi/linux/blktrace_api.h +++ b/include/uapi/linux/blktrace_api.h @@ -26,11 +26,20 @@ enum blktrace_cat { BLK_TC_DRV_DATA =3D 1 << 14, /* binary per-driver data */ BLK_TC_FUA =3D 1 << 15, /* fua requests */ =20 - BLK_TC_END =3D 1 << 15, /* we've run out of bits! */ + BLK_TC_END_V1 =3D 1 << 15, /* we've run out of bits! */ + + BLK_TC_ZONE_APPEND =3D 1ull << 16, /* zone append */ + BLK_TC_ZONE_RESET =3D 1ull << 17, /* zone reset */ + BLK_TC_ZONE_RESET_ALL =3D 1ull << 18, /* zone reset all */ + BLK_TC_ZONE_FINISH =3D 1ull << 19, /* zone finish */ + BLK_TC_ZONE_OPEN =3D 1ull << 20, /* zone open */ + BLK_TC_ZONE_CLOSE =3D 1ull << 21, /* zone close */ + + BLK_TC_END_V2 =3D 1ull << 21, }; =20 #define BLK_TC_SHIFT (16) -#define BLK_TC_ACT(act) ((act) << BLK_TC_SHIFT) +#define BLK_TC_ACT(act) ((u64)(act) << BLK_TC_SHIFT) =20 /* * Basic trace actions diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 49f73cb3cb33..fb5935885abc 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -163,8 +163,8 @@ static void relay_blktrace_event(struct blk_trace *bt, = unsigned long sequence, bytes, what, error, cgid, cgid_len, pdu_data, pdu_len); return relay_blktrace_event1(bt, sequence, pid, cpu, sector, bytes, - lower_32_bits(what), error, cgid, cgid_len, - pdu_data, pdu_len); + what, error, cgid, cgid_len, pdu_data, + pdu_len); } =20 /* @@ -342,10 +342,32 @@ static void __blk_add_trace(struct blk_trace *bt, sec= tor_t sector, int bytes, case REQ_OP_FLUSH: what |=3D BLK_TC_ACT(BLK_TC_FLUSH); break; + case REQ_OP_ZONE_APPEND: + what |=3D BLK_TC_ACT(BLK_TC_ZONE_APPEND); + break; + case REQ_OP_ZONE_RESET: + what |=3D BLK_TC_ACT(BLK_TC_ZONE_RESET); + break; + case REQ_OP_ZONE_RESET_ALL: + what |=3D BLK_TC_ACT(BLK_TC_ZONE_RESET_ALL); + break; + case REQ_OP_ZONE_FINISH: + what |=3D BLK_TC_ACT(BLK_TC_ZONE_FINISH); + break; + case REQ_OP_ZONE_OPEN: + what |=3D BLK_TC_ACT(BLK_TC_ZONE_OPEN); + break; + case REQ_OP_ZONE_CLOSE: + what |=3D BLK_TC_ACT(BLK_TC_ZONE_CLOSE); + break; default: break; } =20 + if (WARN_ON_ONCE(bt->version =3D=3D 1 && + (what >> BLK_TC_SHIFT) > BLK_TC_END_V1)) + return; + if (cgid) what |=3D __BLK_TA_CGROUP; =20 @@ -386,8 +408,7 @@ static void __blk_add_trace(struct blk_trace *bt, secto= r_t sector, int bytes, sequence =3D per_cpu_ptr(bt->sequence, cpu); (*sequence)++; relay_blktrace_event(bt, *sequence, pid, cpu, sector, bytes, - lower_32_bits(what), error, cgid, cgid_len, - pdu_data, pdu_len); + what, error, cgid, cgid_len, pdu_data, pdu_len); local_irq_restore(flags); } =20 --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70CE734166B; Wed, 22 Oct 2025 11:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133381; cv=none; b=gf5RyUDPtxfsdlhUIoGmOcqI2qmUi9FLiA1Uo7p8rSrNRRs0AFR/CBy2VUmSTe9WehegzO9dDw1ow8AcTMAoj1IzrKPErz6Pu+tT6cTKVRPT70+iy6AJVFd0kVEFZOL6+tZ/fpQUo8DcyqMpEv8d8JlvI/RytiPwobolvQ6/J+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133381; c=relaxed/simple; bh=AZUu7x0EKt0EjHUbPBNmDDgqo1onCFunbAVf6KTHHJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nLGebG6V+0HPCr91Efc+ykd0+Jg1R9AEmvD+unFFoeiABSEPuvPLI5R+WKep9XpU3YCEa/AxyweJuQuma5PF2I5z3HqfbcVcDKlLbbxWQgcHpQlx0h426S4rEcaqdAUjzc+mW/QouUMxX9qa0W91qmnRlguQOzdwnkp35Dxkv1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=YjtNgJOr; arc=none smtp.client-ip=216.71.153.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="YjtNgJOr" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133379; x=1792669379; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AZUu7x0EKt0EjHUbPBNmDDgqo1onCFunbAVf6KTHHJM=; b=YjtNgJOrywU986Xbk4FZ+S1K4cKWUAkfctLiYTX32BxPME9GeOh+L5bk +P8xSRha5Hg7OV/EH483/10D5U4CmrhrbX6ygg1HFICdJfSydL91TaIqu TM7YcvYfY2MLk3j24+YGLcklHmCBJZhosdA3AqtZBeR9CaW1BqwSO+4Tk 8BGtjvIFnRbpqA68r364vPUzG2OoIE916FLGbM6IICrv4DSUAI5o0ZQ0K yGH/TFdFk8Vq0MS/uwmKyy+jnKWK+Mb8zeE6QwFZLC2urx2CN/56ZPQvz 2DlD7AjcNK3tFvjSWa0fvV87ZtG7ResCpzrdZIYZqnwpECeRxrgZRaiaD Q==; X-CSE-ConnectionGUID: zVkSq77ORAGyaNEUdQF2uA== X-CSE-MsgGUID: 1W4infycQYWSElr+yuZynw== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="133700779" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:52 +0800 IronPort-SDR: 68f8c33c_d3GRU/L7vk5pRjntpGdbqwHg3fR8AQNRr9SEwXDCkWCfXnG DpdEFtUwH6SvDfpSVKWQdGujCYXuel3lRHPlIdg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep03.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:53 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:47 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 14/16] blktrace: expose ZONE APPEND completions to blktrace Date: Wed, 22 Oct 2025 13:41:13 +0200 Message-ID: <20251022114115.213865-15-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Expose ZONE APPEND completions as a block trace completion action to blktrace. As tracing of zoned block commands needs the upper 32bit of the widened 64bit action, only add traces to blktrace if user-space has requested version 2 of the blktrace protocol. Reviewed-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- include/uapi/linux/blktrace_api.h | 3 +++ kernel/trace/blktrace.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/uapi/linux/blktrace_api.h b/include/uapi/linux/blktrac= e_api.h index 190a3c5ab0a0..289872e51fc5 100644 --- a/include/uapi/linux/blktrace_api.h +++ b/include/uapi/linux/blktrace_api.h @@ -97,6 +97,9 @@ enum blktrace_notify { #define BLK_TA_ABORT (__BLK_TA_ABORT | BLK_TC_ACT(BLK_TC_QUEUE)) #define BLK_TA_DRV_DATA (__BLK_TA_DRV_DATA | BLK_TC_ACT(BLK_TC_DRV_DATA)) =20 +#define BLK_TA_ZONE_APPEND (__BLK_TA_COMPLETE |\ + BLK_TC_ACT(BLK_TC_ZONE_APPEND)) + #define BLK_TN_PROCESS (__BLK_TN_PROCESS | BLK_TC_ACT(BLK_TC_NOTIFY)) #define BLK_TN_TIMESTAMP (__BLK_TN_TIMESTAMP | BLK_TC_ACT(BLK_TC_NOTIFY)) #define BLK_TN_MESSAGE (__BLK_TN_MESSAGE | BLK_TC_ACT(BLK_TC_NOTIFY)) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index fb5935885abc..c83577096607 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -978,6 +978,22 @@ static void blk_add_trace_rq_complete(void *ignore, st= ruct request *rq, blk_trace_request_get_cgid(rq)); } =20 +static void blk_add_trace_zone_update_request(void *ignore, struct request= *rq) +{ + struct blk_trace *bt; + + rcu_read_lock(); + bt =3D rcu_dereference(rq->q->blk_trace); + if (likely(!bt) || bt->version < 2) { + rcu_read_unlock(); + return; + } + rcu_read_unlock(); + + blk_add_trace_rq(rq, 0, blk_rq_bytes(rq), BLK_TA_ZONE_APPEND, + blk_trace_request_get_cgid(rq)); +} + /** * blk_add_trace_bio - Add a trace for a bio oriented action * @q: queue the io is for @@ -1208,6 +1224,9 @@ static void blk_register_tracepoints(void) WARN_ON(ret); ret =3D register_trace_block_getrq(blk_add_trace_getrq, NULL); WARN_ON(ret); + ret =3D register_trace_blk_zone_append_update_request_bio( + blk_add_trace_zone_update_request, NULL); + WARN_ON(ret); ret =3D register_trace_block_plug(blk_add_trace_plug, NULL); WARN_ON(ret); ret =3D register_trace_block_unplug(blk_add_trace_unplug, NULL); @@ -1227,6 +1246,8 @@ static void blk_unregister_tracepoints(void) 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_append_update_request_bio( + blk_add_trace_zone_update_request, NULL); unregister_trace_block_getrq(blk_add_trace_getrq, NULL); unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A0AC33F8B7; Wed, 22 Oct 2025 11:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133381; cv=none; b=ejvFi7XJ+ApXbT9i/IgeymOFcMLUZfDxa5HlhPn4jwyM5hzFzI9o5ILbSmSoKqrluYmiS09lRv2xTFpKZjeMFh4MCEuG4pmvxzi1mtJA1mSLr7dVFs+cXK6u1CbLtiXjJczxHBwbfn4pgqA5vX0nkAyJjo5EtOV8Elp/23YQgsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133381; c=relaxed/simple; bh=As/CEf46/YeYB07VYuH9bVF61eSWzmj8AZoCzaoE0TA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hG+nm9xPKcG82oBSXXTD0kuwwLRz4pUVO00Du1MXFuyHFq+IaJKvM460Q9fmLDKWzl8RXpBhjzkGE/VDuvy6UItoTRXGATo4Vbvwi0gT4ZSkoayaeUXgVyVQ4xR0FRYwbYDX4COARwWkKYmZ+y4v+MoAGREzui2MIFXwBmu7WHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=bH7JCXy+; arc=none smtp.client-ip=68.232.141.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="bH7JCXy+" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133379; x=1792669379; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=As/CEf46/YeYB07VYuH9bVF61eSWzmj8AZoCzaoE0TA=; b=bH7JCXy+xHGbNGcfHo0sCUxdWR3yj42b6nLQdjgVg40KRnmXtsaOzU6k rA1KJIwAonLjPOl8nsRsbJsJSBaJBJ9sW4roiCgvPQ3/tfzdrQdhldmhy Y3SbmaS3ecVAtHLYEnFzw1WKAIeIBdt5sjFdZLQz1WmEsfxw1v+GrtC55 8xbemVUHuWzqS1PMbezNwSqNQKcji0Qbe4f71xiDY7jLIC/CnoUPtFcTm vMgAnsXtRwQqzf7ZPyp6ECxb2peOHnkl9mBZUIGEPPLBVIbcOCqXtXcIR ZYVTy8/nbXp0jP+3XGAyYBSMzhIMKEfmJa03LFo30PccRu0De6RbirADs w==; X-CSE-ConnectionGUID: z/2z3r6CRHmu9kOgt2X5/g== X-CSE-MsgGUID: j9akQGNeRKSWpVoQetOTOQ== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="133602992" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:42:59 +0800 IronPort-SDR: 68f8c342_5bVtdsHGfYzWaqwGJXcCW8imSbxe6AOxWyhLQGyCCY+a01h G1L13LK+MF7C/0nrxBgGwy4L9yeeJ6tkhpksBbg== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep03.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:42:59 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:53 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 15/16] blktrace: trace zone write plugging operations Date: Wed, 22 Oct 2025 13:41:14 +0200 Message-ID: <20251022114115.213865-16-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Trace zone write plugging operations on block devices. As tracing of zoned block commands needs the upper 32bit of the widened 64bit action, only add traces to blktrace if user-space has requested version 2 of the blktrace protocol. Reviewed-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- include/uapi/linux/blktrace_api.h | 5 ++++ kernel/trace/blktrace.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/uapi/linux/blktrace_api.h b/include/uapi/linux/blktrac= e_api.h index 289872e51fc5..30f3d2589365 100644 --- a/include/uapi/linux/blktrace_api.h +++ b/include/uapi/linux/blktrace_api.h @@ -62,6 +62,8 @@ enum blktrace_act { __BLK_TA_REMAP, /* bio was remapped */ __BLK_TA_ABORT, /* request aborted */ __BLK_TA_DRV_DATA, /* driver-specific binary data */ + __BLK_TA_ZONE_PLUG, /* zone write plug was plugged */ + __BLK_TA_ZONE_UNPLUG, /* zone write plug was unplugged */ __BLK_TA_CGROUP =3D 1 << 8, /* from a cgroup*/ }; =20 @@ -99,6 +101,9 @@ enum blktrace_notify { =20 #define BLK_TA_ZONE_APPEND (__BLK_TA_COMPLETE |\ BLK_TC_ACT(BLK_TC_ZONE_APPEND)) +#define BLK_TA_ZONE_PLUG (__BLK_TA_ZONE_PLUG | BLK_TC_ACT(BLK_TC_QUEUE)) +#define BLK_TA_ZONE_UNPLUG (__BLK_TA_ZONE_UNPLUG |\ + BLK_TC_ACT(BLK_TC_QUEUE)) =20 #define BLK_TN_PROCESS (__BLK_TN_PROCESS | BLK_TC_ACT(BLK_TC_NOTIFY)) #define BLK_TN_TIMESTAMP (__BLK_TN_TIMESTAMP | BLK_TC_ACT(BLK_TC_NOTIFY)) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index c83577096607..6bfe1b36a1d3 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -1084,6 +1084,37 @@ static void blk_add_trace_unplug(void *ignore, struc= t request_queue *q, rcu_read_unlock(); } =20 +static void blk_add_trace_zone_plug(void *ignore, struct request_queue *q, + unsigned int zno, sector_t sector, + unsigned int sectors) +{ + struct blk_trace *bt; + + rcu_read_lock(); + bt =3D rcu_dereference(q->blk_trace); + if (bt && bt->version >=3D 2) + __blk_add_trace(bt, sector, sectors << SECTOR_SHIFT, 0, + BLK_TA_ZONE_PLUG, 0, 0, NULL, 0); + rcu_read_unlock(); + + return; +} + +static void blk_add_trace_zone_unplug(void *ignore, struct request_queue *= q, + unsigned int zno, sector_t sector, + unsigned int sectors) +{ + struct blk_trace *bt; + + rcu_read_lock(); + bt =3D rcu_dereference(q->blk_trace); + if (bt && bt->version >=3D 2) + __blk_add_trace(bt, sector, sectors << SECTOR_SHIFT, 0, + BLK_TA_ZONE_UNPLUG, 0, 0, NULL, 0); + rcu_read_unlock(); + return; +} + static void blk_add_trace_split(void *ignore, struct bio *bio, unsigned in= t pdu) { struct request_queue *q =3D bio->bi_bdev->bd_disk->queue; @@ -1227,6 +1258,12 @@ static void blk_register_tracepoints(void) ret =3D register_trace_blk_zone_append_update_request_bio( blk_add_trace_zone_update_request, NULL); WARN_ON(ret); + ret =3D register_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, + NULL); + WARN_ON(ret); + ret =3D register_trace_blk_zone_wplug_bio(blk_add_trace_zone_unplug, + NULL); + WARN_ON(ret); ret =3D register_trace_block_plug(blk_add_trace_plug, NULL); WARN_ON(ret); ret =3D register_trace_block_unplug(blk_add_trace_unplug, NULL); @@ -1246,6 +1283,8 @@ static void blk_unregister_tracepoints(void) 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); + unregister_trace_disk_zone_wplug_add_bio(blk_add_trace_zone_plug, NULL); unregister_trace_blk_zone_append_update_request_bio( blk_add_trace_zone_update_request, NULL); unregister_trace_block_getrq(blk_add_trace_getrq, NULL); --=20 2.51.0 From nobody Mon Feb 9 12:04:09 2026 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9437345CA1; Wed, 22 Oct 2025 11:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133386; cv=none; b=lImxGnm5cANyzVgkXqN8God0g0U4QeBVC3JIail5+PQDxOQ5LAOxspEWAAfkQsk4HR0VG9PesiPiydtd/X9WE8QzWWbZwbz0ZoX7MdKY8hv5kBGYclR+zy4VC2pEFPk2I3+3+4YGgEA4NMVGFdhAtKDNdETx65IwqZybEP2O2TM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761133386; c=relaxed/simple; bh=nuPM7Ims9XfiDccmx6xBBK0GR6s3US0OLE3P/QcDg8k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a4C3wHkWt2hp6fn+YUf56tbtl865s8oaagGTck3LmvMn3j+HSvQmCLt1ZwrfoixkQ4bt3FraTMxAszmm80xLV10Tv1xl64QNcJtIhiJbyIUr6ap4dD+9EqKCUA14f7n7QeAcbmhK9HwvOV2gwwgG8x4WAxAJO7BXawR8bs+5CfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=nDtYjm93; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nDtYjm93" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1761133385; x=1792669385; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nuPM7Ims9XfiDccmx6xBBK0GR6s3US0OLE3P/QcDg8k=; b=nDtYjm93VotPlPhT3wqXMHWYGQRgKtAhaTK8nJBF+ZR4UptDiVms/HUB MJQsgNQ9agPy6ptQ9CKywndizOe1+dyI4/YOvWAMpXz0bjvbw675dLHdr 0OWIuk6m3hNfgXYUWTJRncS0YLGNlbn9JOuBcHdsxrYwSErlfmjCjT0CZ 07EKj/TqneJV8AiILj4ixjDGE5uhn5hfb/VqsM19UyBz1CHvLe8v+ITU1 KGkL3fjGb2af41zO5/es7nVH3I0o5NJFgvweVfpTknwH3byU72tjt1/hK rZyH+8E/ZfiAgVtV+gRsUbdJoYh0/INu32ICYuTqVUCDdVlsXMEFINytP A==; X-CSE-ConnectionGUID: gMo9gPvEQryJP+s2By3lWw== X-CSE-MsgGUID: 0notKVw1QA+n7QTV6ixlzg== X-IronPort-AV: E=Sophos;i="6.19,247,1754928000"; d="scan'208";a="130696134" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 Oct 2025 19:43:05 +0800 IronPort-SDR: 68f8c348_5Sf2xFUuJuRopBsy7lCYperkU2r40Juu9MuPn64eu8EBK5H 8OoKuuGUh2QkALvPneSSg5AebWCaaLuvcBjyjeA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep03.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 22 Oct 2025 04:43:04 -0700 WDCIronportException: Internal Received: from unknown (HELO neo.wdc.com) ([10.224.28.49]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Oct 2025 04:42:59 -0700 From: Johannes Thumshirn To: axboe@kernel.dk Cc: chaitanyak@nvidia.com, dlemoal@kernel.org, hare@suse.de, hch@lst.de, john.g.garry@oracle.com, linux-block@vger.kernel.org, linux-btrace@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, martin.petersen@oracle.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, naohiro.aota@wdc.com, rostedt@goodmis.org, shinichiro.kawasaki@wdc.com, Johannes Thumshirn Subject: [PATCH v5 16/16] blktrace: handle BLKTRACESETUP2 ioctl Date: Wed, 22 Oct 2025 13:41:15 +0200 Message-ID: <20251022114115.213865-17-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251022114115.213865-1-johannes.thumshirn@wdc.com> References: <20251022114115.213865-1-johannes.thumshirn@wdc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Handle the BLKTRACESETUP2 ioctl, requesting an extended version of the blktrace protocol from user-space. Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen Signed-off-by: Johannes Thumshirn --- block/ioctl.c | 1 + kernel/trace/blktrace.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index d7489a56b33c..3927ca4707d0 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -691,6 +691,7 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsi= gned long arg) =20 /* Incompatible alignment on i386 */ case BLKTRACESETUP: + case BLKTRACESETUP2: return blk_trace_ioctl(bdev, cmd, argp); default: break; diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 6bfe1b36a1d3..6ad3807a5b73 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -749,6 +749,38 @@ int blk_trace_setup(struct request_queue *q, char *nam= e, dev_t dev, } EXPORT_SYMBOL_GPL(blk_trace_setup); =20 +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; + + if (copy_from_user(&buts2, arg, sizeof(buts2))) + return -EFAULT; + + if (!buts2.buf_size || !buts2.buf_nr) + return -EINVAL; + + if (buts2.flags !=3D 0) + return -EINVAL; + + mutex_lock(&q->debugfs_mutex); + bt =3D blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr, + bdev); + if (IS_ERR(bt)) { + mutex_unlock(&q->debugfs_mutex); + return PTR_ERR(bt); + } + blk_trace_setup_finalize(q, name, 2, bt, &buts2); + mutex_unlock(&q->debugfs_mutex); + + 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, @@ -839,6 +871,10 @@ int blk_trace_ioctl(struct block_device *bdev, unsigne= d cmd, char __user *arg) char b[BDEVNAME_SIZE]; =20 switch (cmd) { + case BLKTRACESETUP2: + snprintf(b, sizeof(b), "%pg", bdev); + ret =3D blk_trace_setup2(q, b, bdev->bd_dev, bdev, arg); + break; case BLKTRACESETUP: snprintf(b, sizeof(b), "%pg", bdev); ret =3D blk_trace_setup(q, b, bdev->bd_dev, bdev, arg); --=20 2.51.0