From nobody Mon Feb 9 13:48:18 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 DE35931A57C; Mon, 20 Oct 2025 13:41:34 +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=1760967696; cv=none; b=CFb+4bMhoc4zr+WPF18cFd5eN5A0ELgW0Ktr/CGkDYlWd/Nyohz93D2Ie9O0tj8spklXqwbEaeoBX94KLJE6E4u5hvppVmis3z/DdabLE+KIXRoU0AciSmFHJXN6MZa79IWTWyTsEIA1aDYfaj8XYVU0+gY6XyOjwIFDwbWSnsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967696; c=relaxed/simple; bh=ksy8BgshONcRNaaYPA2330I5SQCjqAYhB28T8Qj0gmc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZeEfn1lNUMgVDuTE8j7x48+QlAL4Di2hejW3Zrh4dlNQ6sktKs4qcfm0BPFs90Kj5rUBPm3Ncqx368x0Qq7+x2VLB6FqgNfDDQZSxf7orfyahjo9FdmlwBgdoK/gJagauW/OFhCbEDjSqKR7EDchR7sOrz2K6VQ4POZ7Fd7jQMw= 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=a9XTaoR/; 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="a9XTaoR/" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967695; x=1792503695; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ksy8BgshONcRNaaYPA2330I5SQCjqAYhB28T8Qj0gmc=; b=a9XTaoR/BUHIBVx1zYcmHRrzVkt4B8mVX+KquJYOHdG2lfHbgS7o3t0n 68I+3KMRH4yO9pklE+KCGKqAZlr35GDNwV5AUCHZwN/orUu7dhobsqusv l/fROLzQMAAMTSUUc0XiJlvNXe3w5WsAtpu+sPUl/Jaw7R157PK145hFW c2L1zfkfZsJ/pPpYWv6xnv51WbFLVVbPXxBzMfYoz1yPShiwvZb3RIY8X E+WiNxUwDYjRIFcgCwBD+UUSyh9rQHgJ/uT4q/4+fPBCpDeVYjDdY2cHJ bVxMT2iT1w7uVAU3yNLtXPWk0P38clLBF6DJaKuFgecgnykQInvLYeYRy A==; X-CSE-ConnectionGUID: PDYYkpruTS6tohk+tbh3Xg== X-CSE-MsgGUID: vF/NfaegRsW5hyANDUqJ/w== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518614" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:41:35 +0800 IronPort-SDR: 68f63c0e_iCvjtP4832ENZ134+DLFEMn6UwBG/bPKtW/uUPDhXkmvxXN +NnFAa+YlVberqSeQTNINcw987HoTnkWgsxmbkg== 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; 20 Oct 2025 06:41:34 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06: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 v4 01/16] blktrace: only calculate trace length once Date: Mon, 20 Oct 2025 15:41:08 +0200 Message-ID: <20251020134123.119058-2-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 13:48:18 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 81BF831D399; Mon, 20 Oct 2025 13:41:39 +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=1760967701; cv=none; b=Ed1qEluby3t8WtLsqMLntWiIQGVo5Ly+b2+6yMLTj9LnPVpNlDh5pmnKT69RJVngFVA68S7hFUNiGXUGx8Sw+Q3VfLQHpWNBt+t5koqgYH4cmGYv9hMR3k67eibYESqyceGd9Wgl1TmVl735GPn4aUVLcGbbNxtI3QxwY0/uUNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967701; c=relaxed/simple; bh=yErRjf71H9zMBluMUonZMg66O7BNcka3G9hCyQbx+VU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O3R3XLDdNzn5VcQ0IwdWiXGvmlppN0RBHhYKwMMjD8uITEsXMReF5Y1eFS7gVSHbolomoqgXVBpiGnEZITrqU0SLRPQCnD4/OuptN+MrKLPVWC+DCp+CqwwwOspbeQ17iFNznGPxpRoe7f0WlVaMgWS9ODq6ymoLfiYKQ3QI5so= 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=LIsiaPf4; 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="LIsiaPf4" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967700; x=1792503700; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yErRjf71H9zMBluMUonZMg66O7BNcka3G9hCyQbx+VU=; b=LIsiaPf4fEkJ2RNnP0YXI08Kk0yhkXSg8/M4PKf9TEMlaEIAmcxQ36Cz bk6UmaQvd/hstDlgqDuOBw8ODK5XJokehCLgc58DEZ9e0KZj3FdmD2hHH TcUtst9KFdVyxH2W6c59f3jR7RTveU97cjbQsKTeR6PmfTS6PnlwWuBLc p/ERWw9rTWCUiStqwQxBtole8eaSTvD/AsZvgQrwRnv7ixddJFP7dN+DP i3S/MMCl3F8NEbZdHQgMR3jo/49bH2nS7a9pHU+QUw6IDz3UXjrKvuox6 xU8CN5mserk+X+gVUfst4yW6W79nePUTO6G0AM/X/XY42YDHD4OMl1xxZ w==; X-CSE-ConnectionGUID: 2uHyiqdrQY6kY7M3XnP6JQ== X-CSE-MsgGUID: tTkLtLXuRNuWmEQAAAmTXA== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518620" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:41:40 +0800 IronPort-SDR: 68f63c13_CAMPNdqJ99Am9tS1KF0WGkJdvzUD5hWzGrgyC88L21Hrssk xhmJuaXBagh7uZOwNuBSDqCxvn0lJbv1PffGkoA== 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; 20 Oct 2025 06:41:39 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:41:35 -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 v4 02/16] blktrace: factor out recording a blktrace event Date: Mon, 20 Oct 2025 15:41:09 +0200 Message-ID: <20251020134123.119058-3-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 13:48:18 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 2A05432038D; Mon, 20 Oct 2025 13:41:44 +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=1760967705; cv=none; b=s2rAEPjg6m/DNn5dlT7WYmHEJza15OlWdbihgrAmMJvwghTLPf88WMkcOTdkq3LutzbweJH7YfvGGvEmgWrNLVVkMOmqtXOh2TzoMN4snGPrLTqyIiBvWySQWAS41YZl6finforCNQ3frF4SsZvxFdBEYp5gIAnozuOUr2p5nzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967705; c=relaxed/simple; bh=aSKlpte3/6fimeQh+rQvxtI4gXBHXMXDuYzzfy+EVC0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sgGoFlfaljaAuRje+li0/9B6Nm+1fAbcTD5I70kDGWFtL5t8EFJSi40r4nV3Hm9h8dwZskb1bzJhx9XAfAMnMcGyy47oAL06f01BSJmFPH62BLPRBLhFDxsgEg1rpUBIqknzNUnwpLDbATFOfO+uB+aVI9xFIlB5xrjzUDQ2XHY= 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=VtzIwNzj; 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="VtzIwNzj" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967705; x=1792503705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aSKlpte3/6fimeQh+rQvxtI4gXBHXMXDuYzzfy+EVC0=; b=VtzIwNzjmPRj3EX9hsTTtEMPuJTV+TdjigVVl6xWIBDGFVdYfZ2NVNlq x7zN9/5A7u+w6tSVuTgCzf2wpdN6jLDxVy4u+8f9Xn4kvSK/JnqT4E2Fo FC5r687BvYlyqHRL3CMROssSFvF2iDl/sNcH0LdNsYZlqPG3HYcifU+eF XtK171HuuurAICfS4W4Ql/S1jmUJzVuCk7oY+4qxvxyINAigDegkWkcCD Pr6zhr/E2C9umrWq4HachsA0o5VnBLNYh6PTyHmU3e156WCbgYUbjdNX+ rJCGG6rDyiklFmoUPgSlZOinWhLsMjhWCB+WD1bO5212vLSgZj5h+xFbb A==; X-CSE-ConnectionGUID: xtfTvtFsTAW5SrlAXC8n4g== X-CSE-MsgGUID: 5OxWNyBFT1ennm+TKHjM/g== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518624" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:41:44 +0800 IronPort-SDR: 68f63c17_hURQxFZGUBSMTKCndty7ipHDtgf0bBK3Yr9IibrXnZRSMX5 LI0Ku4lmEfeUtWSz3buBUydZz3BwSB+goPmv5Hg== 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; 20 Oct 2025 06:41:44 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:41:40 -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 v4 03/16] blktrace: split out relaying a blktrace event Date: Mon, 20 Oct 2025 15:41:10 +0200 Message-ID: <20251020134123.119058-4-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 13:48:18 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 7926E320A10; Mon, 20 Oct 2025 13:41:48 +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=1760967709; cv=none; b=UBNO0YKgECrsaqjlJq6tQUCx4/1JQvz+voqn66iAE9SwO4ggjCx1aaIe2wBhYuwsCunPeT67zECElJjvSO4SBH/woyzlwQ+n0tdHmrYGl2iRiXhIkxnRr+z5RMC/WO541xMCYQqwo4AvODOfFi5HZ5dVL39OGLQoqAdIH8UNccg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967709; c=relaxed/simple; bh=cRZvJizN4tgFy915/GAfu4RFBsW6lFtvyycmhNBSCD4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NMJhd13bFtn4gkoywQylm4X3WsbnZ5mTJQXFC64XlyhcKUMbj/W9IcQnxJ4f5mn20tC+khu6f0c8aWlYzL0/gtWFw6iADVGiJUgUjt4EJ65Sb3pqRahPV7LUdJW6WEEIIhBG8LYt6VeckKkYbaIR3JOuT5xPj7+T3H3aIOlfTxY= 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=Eh1d5LWj; 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="Eh1d5LWj" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967709; x=1792503709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cRZvJizN4tgFy915/GAfu4RFBsW6lFtvyycmhNBSCD4=; b=Eh1d5LWj7os7KGmirPoauJjMkfNdLQKZqb25bR7Ggid4eL2O2EXPsstT gVouaPHxR2AdsxkT2alNNGiWjD+nbbnFxdq8gGYGnI6PnHf7q404ynG8L 49PwjCXzQ/jfjOmzGQhv+nMNlD5yxivYxlBbtOXaYUcykzObCnqpCk8H7 FItkp1Ot7r+7razgZyJ+ZE+oGzEedxa0xE5ZNICeJKiMrDvI/f8xrQ9Wf ZYCnhGCkrubzFZMNIURnJUOm0RWeq3cZYc2hSRoeFhygNDvP4cr027+yd zrDD+EkL+Vs2xLI7qos1hoJgePm2oRWnejgbSpsN2atpCExOg1wyr7rqn w==; X-CSE-ConnectionGUID: uDQYCGv3QpqWSLtqKg4UTg== X-CSE-MsgGUID: LQK60W2ARBaqgyeGH+QuGg== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518626" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:41:49 +0800 IronPort-SDR: 68f63c1c_Gh37I5uv5XLeLZb/7kTBchI8urzN+/OUDBJyLf4F8+7yG5P NjzR1wnbGLMYLVc7dEvfefJt2T1wThJtn3eO1oA== 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; 20 Oct 2025 06:41:48 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:41:44 -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 v4 04/16] blktrace: untangle if/else sequence in __blk_add_trace Date: Mon, 20 Oct 2025 15:41:11 +0200 Message-ID: <20251020134123.119058-5-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 13:48:18 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 11D1D320A10; Mon, 20 Oct 2025 13:41:53 +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=1760967714; cv=none; b=A0b3PejBywI3Ae/i7+gijPekicI1WV9w4P35Wqkae3sUCklgSirRcauqoehnNRgxhmm53ckElybhV1KICwGlshShnQOfkTUIDgHUHxY+KVZ3Y5fPVFQjaBqNqNa9xBpSgvGOXSNWnoLm8Pl4LztvKcUGfesv9UoW6Er2eK5m1wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967714; c=relaxed/simple; bh=mAUp0WL7pToU8KKdjl0PWb6H3xb1MjwU+oTRkb9kEfo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=atzqfcs8SB7ykRdbantWbUSTwFA+SR/ZLZROgo6qiYLXT7pzXFZKr9WCpFROYuBuICkdMVsqKZjI3t6VEXDRtfptUS/e9HgoCZNJcha7nB5aI1yT61TIhRyY8k17Pw8B50ev0mJy5nVFE//4hKGesVHV/QAn3x+Bi6HxPhte3nc= 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=o4yEQULl; 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="o4yEQULl" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967713; x=1792503713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mAUp0WL7pToU8KKdjl0PWb6H3xb1MjwU+oTRkb9kEfo=; b=o4yEQULltrGwrx2GzUnFQeVEfdiNJjeTiby/qIfEOTpUXjWuNPFdUYcC 71rkj6AJ8XHVWaLQAMVPOCjvoxeJat+aU0ijntCD2EXMTlmAmHVzML/p6 WYstabBG7Ek4D7FuL2IAoxmc9k8qFDIMbs37bFMvSRBKbCm6FEaSS6g+k FuR5bW+rqZOn8VYrsnHcIGHyvTrN4ESQdi5mXWAIx+TGJLYAswJpCNsmg dsjgr+hLAX21yIm9LErs7QFv/3ZSuLPb0JhHGIt32irqppI4nhHt3kse2 psVaOFq11kafeJKOCxNUo0+zBMtTnrEbO1bWpcz8oWVCgLeK+yMCxCMB3 g==; X-CSE-ConnectionGUID: yE0MXoMrT1WxT2bfHT9ivA== X-CSE-MsgGUID: WiPxkNovRAmWHXHXJlN3eQ== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518632" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:41:53 +0800 IronPort-SDR: 68f63c20_9XH3SRtFeHiXkKmCWytouQQS2iG2+QOcmB+fX2Bdn0F/vLh d9POzAsH3BI0JJ1kIN/HE7p4xUIP1Fe89BdkUbw== 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; 20 Oct 2025 06:41:53 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06: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 v4 05/16] blktrace: change the internal action to 64bit Date: Mon, 20 Oct 2025 15:41:12 +0200 Message-ID: <20251020134123.119058-6-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 13:48:18 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 8780E321426; Mon, 20 Oct 2025 13:41:57 +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=1760967719; cv=none; b=CQOVLhpduXamCAs9iyq9bI1BhAHfWg6yXQ3n685lsnuWggSp/THTt8QqJcunWfNBRWbHBtPLSj2biYTJKv73cZhzrYAOY0yeKngqwRNrSbKN3kEdtBwunXHml/kxXED2c4GYbuf460zgxGh4K5GamyA+sSbEMAkhSjF+fwsdMVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967719; c=relaxed/simple; bh=8L1b2wJ9wBWtj74+QVd0A4pXnfYy3vT3nTucHpYgAZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gbzv50/cKSNQiitj73as7ZooULO5sslaTQxSgL9Wm450djxA9EqorkfnTtY5D01w8ngzFzHLzB8lbrd4N6s+ca2OI3bKEFtvbOzpWNNBpYaovOHPSFpqs2cSMeF8lHMFXOQdf/zd0AXyuJ5uNjpJin8SOha87yadRm/6VzCrEiw= 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=S5Q8kqit; 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="S5Q8kqit" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967718; x=1792503718; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8L1b2wJ9wBWtj74+QVd0A4pXnfYy3vT3nTucHpYgAZU=; b=S5Q8kqithnEWi/z4xQH1ieZMKDd4NofMaMa0tCGNw9td3NHUI0MTV9gJ 5r/CdRaWw5I1YpFChbKV0qxdGMyKYVaSSlGC8TQFxIaXn9Igni0qluXTZ R0Jya3n9M3JhlzyCDDFvuu3ESceQn7Kb4w828tGg5Bog6untpnCj30r7i V2fDUNotG5BPq1mPaglAcULayN72huuMcYLnR+e5PL18cKH1pwdYAYWjo qQPVkn4sVQkUCmnMqYEBHBjVg2hscBCKf/x0mBk9lo3jVMBhrM5tycXOg 15bSgOOKHos7pnx6ErnZeFlsHZvlhfqCwD5TvUHHr/nli+0ucRBoSJ/F9 w==; X-CSE-ConnectionGUID: 5MfK+7LRSrC87yrcKiUwXA== X-CSE-MsgGUID: HSYC80jzQruquTNnEaFDug== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518636" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:41:57 +0800 IronPort-SDR: 68f63c25_7LNtPb8JUx/SwH4ou8FQ/3OkxcsHrhUvc4QBSm6vmtQ7VBI mKQpdN18nSAbo+eGW9g+n5WtqOiZexv/2FlsUsw== 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; 20 Oct 2025 06:41:57 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:41: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 v4 06/16] blktrace: split do_blk_trace_setup into two functions Date: Mon, 20 Oct 2025 15:41:13 +0200 Message-ID: <20251020134123.119058-7-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 13:48:18 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 D6D68322740; Mon, 20 Oct 2025 13:42:01 +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=1760967723; cv=none; b=bZ+8c1Sm/D6VHeZEFx88P6BN+4vEzMvds74wkrTgJ0NwPiL2HKj5r3odOA88Hv9ZlTlzf5arKLTqjvotdKjMQOWgLlExocTu2oiWnjA8Acz4S5s8aZJ/oA8K7FCD4QN5tqhTGQvMQ8CprsVtbC4Ix02Ff8YUkuA4zJ859z/0Nfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967723; c=relaxed/simple; bh=2pV7GzYdMScrmif7cvlowSHBO8110VklUY8PhnhIh1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e/yVGfNc/6ZxTgu3bYqOPpUhi9P6MLxnzOEJR0hp7rrFjl5B4ObzunQZN31Ab1QcVOb8YeDYtFF5LCphCiBNYuWrJdjQdqnAu1lVQa6hmrIkGzAxCpXIonTnnC9K7rZ8J9RO8L493pTccGr7bkMGPi++c74D6ien08LyzwYdRJE= 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=Ies3WJm7; 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="Ies3WJm7" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967722; x=1792503722; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2pV7GzYdMScrmif7cvlowSHBO8110VklUY8PhnhIh1Q=; b=Ies3WJm7rW9ecYAChNJDDclbe3jlLvB8CmLRGHSB/TRPmNBsiHl6oPdP ycyEdcQVdlflP03w8NIXeYsVjLpstOoECgo1SgLPTcFZYqFzCqZRw7Gx/ /2IMGo0EHKB1BEunxWKMpeVZIubxRv55eKYXaWPuaoJKj0RQNJ2QHQ3p+ yyfK+Z9alGfaH/Ud7dKWb+2PrOLsRuprcV5nqwjt2/WeV9g8dYDcl6uvV UlhM6ysbo0rqqi9b36/CUQOG3vK6kpsuw+dc33Hq3FizT1J/fPOQPZ/xE EOFBhi+bSqrP3doyebJkdgKUWEUmFXidxgYBV3Uu5Nth/jvpGKfRqoCYy A==; X-CSE-ConnectionGUID: EdNidgTGSWehrqm8cm2Jsw== X-CSE-MsgGUID: 5y0jXk1wQbOkubX5amTNMg== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518643" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:02 +0800 IronPort-SDR: 68f63c29_j7u0UNhYfOpwQqC1XQhqV1FMW4Ls9KB06cs2hzdgleZzAPe CsYA51nDR9UkHp6w04hIOgWGYb4ndf7ame4lJ3A== 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; 20 Oct 2025 06:42:01 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:41:57 -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 v4 07/16] blktrace: add definitions for blk_user_trace_setup2 Date: Mon, 20 Oct 2025 15:41:14 +0200 Message-ID: <20251020134123.119058-8-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 13:48:18 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 5B4233233F4; Mon, 20 Oct 2025 13:42:06 +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=1760967728; cv=none; b=u7RNU/QlJxCmm5VQUa8lCmW+j9ZFCF9Ex2Z5WBFRLrl0auwiQdB+/iZwdLcioLywvuKqxE0nDseN1sSRcuxkY4UiJoie/Podi4hzOSK186FNdh90QWbBHpTtgkYwxnVYFMyOmEhIVx0W5TjEt5LGTPgqS8aQzUohQnx8jhn9+BE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967728; c=relaxed/simple; bh=R5PB1bbLFZ2JbMWYAnMJ4DTuf+ynX10cGzq4pq6nXpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y+rviUo+8yWtQbVmaDAojY+CuxGLN5H6PJhjzJjS09XZaT2VyocbZqSLWe1v3sCY7xe99T9CfJOcZnsemQjtPgmpSJUyo3d1ROI7QZISjwVmVYa0gZGXwme4PKSr+X6voh+InlM0jRFSULp+fXjFtolygqWu82K5kWoy9cPLfKk= 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=i7Gg78pp; 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="i7Gg78pp" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967727; x=1792503727; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R5PB1bbLFZ2JbMWYAnMJ4DTuf+ynX10cGzq4pq6nXpk=; b=i7Gg78pp+C0X22dXO8z7I07r6Nor6INyt8W1/ybJDnHM/pvRnwyjnZvV MX1b20YZfrUjf7savorw7HNjK8lkW7pQEyIrg4i1Rh2ONJo5CmbQYQTdd w26rvbdLpSTsq+4G/HSWmjJxXmA83aYQNQQn5PYS5VNvez1a3x5Lxaaww kfnnxVxoo4XuTo731gHTgWubcOGtgevmrSxO2eaZ8xPlj56Sdlb9Z+MEF 2fHKIMGpBdzvRVdhiqaaimBUMiK2xnsCHD4GDEEjyMpa5bAdV2FBqraiA NohkKY5QJH7Ql3BqXq7UqpjA76U4+JFu50ZGZwSmIF4zmgTue8ob3+kGt A==; X-CSE-ConnectionGUID: n0m2XdHRSn6DWK8v0QIMEg== X-CSE-MsgGUID: drqEj5kdRP+TsAbodQ1EDw== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518646" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:06 +0800 IronPort-SDR: 68f63c2e_4IJWXwFGzS1KW5zkNkx8CdRDVXCPRtrQpPf4j5xSEeIHxaB L8wtK5melpp6EEpC4zCTCY+PLjE2B8msiXMED2Q== 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; 20 Oct 2025 06:42:06 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:42:02 -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 v4 08/16] blktrace: pass blk_user_trace2 to setup functions Date: Mon, 20 Oct 2025 15:41:15 +0200 Message-ID: <20251020134123.119058-9-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 13:48:18 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 A761C31A072; Mon, 20 Oct 2025 13:42:10 +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=1760967732; cv=none; b=lhRda2KzizCpy0I9NsDoFRSnI1l6HiFF249+l2yqTOiIBSwEaslxMtngy51aBpMamUSKozu0JEct7XanzZCkFFxVFM3LOqW49rd8R7OJuUdz3ygpMVDgZ8rrOe1BgBckKfD0pRj2o6/E5Q0URCg5KuffdAu+sXzVloYzjimf/Ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967732; c=relaxed/simple; bh=iZB/n1Ds7E99ZFQKBXaAj5GJS2t+No+GlM3Q5V3jT+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KU5IJQRTJra0n7yltduNOTffeUZ3PtWBjTKjoXztUB3mYHQdQPf9Npj8AgXz6dlbY94dnmFCwhx1BppERTKGxlZzaCL0GnR32se8TyGqlk4aIPUF6wLzZC96qIfuGATty62XxthpOnS1kOO7QG6QLSRg6cVT1af4DAk5r7gUFT4= 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=KH8czoig; 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="KH8czoig" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967731; x=1792503731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iZB/n1Ds7E99ZFQKBXaAj5GJS2t+No+GlM3Q5V3jT+0=; b=KH8czoigtBZl1mJJTJMpKjBcY3NJnfhDJBP6UtdJhA3V5cW2d7OHWGkr milGDJg6wFcGrF2O8BQb59sHpNdcaKk/+cid5Z1ijSl4d2uL7lQ/tVlmU MvdjUT3fxEafcygZcEMcGiDB/cjnzU9JSkyq2jl38vdnstppcongGfQpq BBgelu+HE7qTojPLxt5zw9XT80ugJQxcysqHf7zlzJpjlzMTiO3AXlK6e ZGEWEvrI9Vv8v/OI3DFLZ6Rpmf1g8bMsIbRFVor3+qR5vPm3aoK0WFyYO 5fnL6uBML62Jhisuet1fyi/c/ctV8Del2Zzw4mxKLyLfBt3tc+LPuJmPJ g==; X-CSE-ConnectionGUID: /JpE5pm8Tnyu4rX9ZkeJHg== X-CSE-MsgGUID: qCdOPnOHTv6ia6SUDKe56g== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518651" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:11 +0800 IronPort-SDR: 68f63c32_Rj82fTvz8BtTBul00RQfz0+wr593tLOFPc5wSDiNCY0k6nW +f2g2OxXwZt4CCJLxS1+rgjXicx+CYw5sSTgOag== 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; 20 Oct 2025 06:42:10 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:42:06 -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 v4 09/16] blktrace: add definitions for struct blk_io_trace2 Date: Mon, 20 Oct 2025 15:41:16 +0200 Message-ID: <20251020134123.119058-10-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen --- 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..3a771b9802aa 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 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 13:48:18 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 3DD6532779B; Mon, 20 Oct 2025 13:42:15 +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=1760967736; cv=none; b=utqd8JFCvsa+KSEccXAGgb5p9Jh5PIpT2j4oGhmEWB+vE03dc/ruWRq3CcPPgnjxevA3WVQZaTyaDnqvSfTaMjeVRZpX+cuTLYFDWAF9ghyF0qndC1LpRq3CCfJJcLqmcSc1lBlWvuVV2eqz+qQyrJsMPSSXV6gqtxKebqrkLkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967736; c=relaxed/simple; bh=RO+2yCpb40QjzkLafpQDfbLu3NGrWhJ+S2FUBqNx35Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qIL7qRCCvCL4o/ak9+TKfpyzAB52ZKPmu83jmlzO2FHnQ8gNBMbYYhBsaNBWv8TxWsAZSGPBcy6CaRcrlvWHyeqsrhcqiXO4GuJpqFlQ5n4tsQx19JJY5UiHHWQc1Hc0bqTs5/5DApOpIGlA8DZQlV+kuXa0/KP9mdfolhyGDHI= 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=AU/dNqLV; 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="AU/dNqLV" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967736; x=1792503736; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RO+2yCpb40QjzkLafpQDfbLu3NGrWhJ+S2FUBqNx35Q=; b=AU/dNqLVO5Q14MWePYqHRPN2aGGLBnq4+Y446XdNKfHAxuFYhtnGHsFx PtPUglLFOcJrHudqIc5t5nYU0S3n2jJz9GLFNKqEeXoW1nYhDWhHxEtN1 +ZYzrgZjcJpetlZoIhNcSupbeb/U8D/6ttkyMOYKHxXoa0zNPAb5A64LR ytD8amIcgiNxQ0Wg35bFWxDKDEUbXMy6iYOOORpHZxUBEPoNgPvahvNa2 QIU23yX+LJZldPLF3RY6nA6Fs5QJwxze0KhjqXNcPoNDnzdzWs4MVMl+3 +aeOYAG2eu/r2V2yLkyS48BghPgDuKjkskg5+S3dUHGG0BXm0qc4mMtzG g==; X-CSE-ConnectionGUID: WqI5xkj/RR2wF4QipuJ+Vg== X-CSE-MsgGUID: 121s3fO9REWyoFdv8uKa9Q== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518657" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:15 +0800 IronPort-SDR: 68f63c36_E6iPDBSO5IyNYzIDTHY50t+ALqbGWSRfl4oB7YT6igMoNaQ fTjzSnmnITAh4C2cBC536Un4Anc4SU+XK1RnwbQ== 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; 20 Oct 2025 06:42:15 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:42:11 -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 v4 10/16] blktrace: differentiate between blk_io_trace versions Date: Mon, 20 Oct 2025 15:41:17 +0200 Message-ID: <20251020134123.119058-11-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen --- kernel/trace/blktrace.c | 62 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 185f19c9f772..074a7d77158c 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. */ @@ -146,8 +202,8 @@ static void trace_note(struct blk_trace *bt, pid_t pid,= u64 action, if (!bt->rchan) return; =20 - relay_blktrace_event(bt, 0, pid, cpu, 0, 0, action, 0, cgid, - cgid_len, (void *)data, len); + relay_blktrace_event(bt, 0, pid, cpu, 0, 0, action, 0, cgid, cgid_len, + (void *)data, len); } =20 /* --=20 2.51.0 From nobody Mon Feb 9 13:48:18 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 8B447328625; Mon, 20 Oct 2025 13:42:19 +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=1760967741; cv=none; b=GEiBZ4eH36WcfVZ4DsZW+aBPwltR8XFW4wcfpOM3HS93HRu3Y7RZBsAcEJSQH0iiIqG/KBul4IpdvoCLQ4n0fYXYr8nJi4Eoq9keQavcCKpZGJHc4Ajyb5pN363ZYPiPB4a7XqT6CJa+HJDuFfgFkd+28b+RI7pFj0ifRJ8MPTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967741; c=relaxed/simple; bh=OdfjZtE4yrZPklJRJdAbMW23KQKawKbqo1RInESKj3k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cp1MEY5vaKzqpc9Mui0ClsrQS5OlekfRUmg9pbwmzYm7NUDGRT9sLvYVSd/XCw/sBBFl2nDtgOyR0r4/DdWx6RPHOI8e595NcBJC8XX63jqF/klQBwzJzxju2vSf+YQ40jEAPfjH4OY6b9Kew74pIiufiGoCmJpb1aUCTEFaeBQ= 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=oaKf5m/c; 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="oaKf5m/c" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967740; x=1792503740; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OdfjZtE4yrZPklJRJdAbMW23KQKawKbqo1RInESKj3k=; b=oaKf5m/cu/+ikClh7tooesyQjDphqfxDvibc475aauQeBC26B+9wYp0u NukHWc3iTEXdKNwu9sZuM+nifrju39cKppun41KwFUdrAacUB64YcxNQ4 wpvGoIxhghp6Ct3bzcm/3L1j2jIRON8bfknsxgoQwsQduY25hiSfNH767 rAcA0LtfQ4geXCFHCboPtH+52uR3MBIf6AhaY7Dtnqxr9DRgS6f/Fw8HD i6s+oZqcEJM43WqocT56sHwB8Wt93OhX027dTAb2rupz6/CTWNBtKDNtx u1oc2sTUXHDG+gFhMM+c1dXK7Q32ZJ5EregHnQh+6WifM62krLHxOlXlK A==; X-CSE-ConnectionGUID: Q+OpfOvlQ+WGT0H7Din4tQ== X-CSE-MsgGUID: 98nyvdNxS6GU2NTHHAtjfQ== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518659" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:20 +0800 IronPort-SDR: 68f63c3b_GBf19eEcKD69xYEIibUJZKSSAyytyei0+yNNegYZVS7u9kb gF010qsHjGOw8OoK5uFONG/pCJwvX688zPn10Sg== 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; 20 Oct 2025 06:42:19 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:42:15 -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 v4 11/16] blktrace: move trace_note to blk_io_trace2 Date: Mon, 20 Oct 2025 15:41:18 +0200 Message-ID: <20251020134123.119058-12-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen --- 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 074a7d77158c..756d2c7dfdf2 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 13:48:18 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 E1369328B57; Mon, 20 Oct 2025 13:42:23 +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=1760967745; cv=none; b=ApnNSWdIbjaz12YxpZ2LFYsDb/vBuNCR1gOdKlLLHx75I0+ezhyYnN7C0JGyuk/kP5qIOGYqAZ7GbUFQWToaHIZKYAORPqKa8fwnznQo2afrL4ish7rcorMMp5N79i/lgzef2+MYUZfO0zQZd4KiZDWE4JXbs6MJxs7L8Z2/QSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967745; c=relaxed/simple; bh=9fyo4x15I5nOU+yV4Ur/7W1Z4uAKxE2toCSFZxXkOwA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JM47N8S9Pz+SJnNQVMaGwVNI0gYZds3u9ujWy8HgL0dCJl4qwC2H0xKQfoyB4bEQZd62yzBmIW0kTWKM6G7jxhVyi19p8IeZ4aJJkcm6y1WHOImA3gz8L+T+nJekI9E+GY3ImWjvsZGaIej5OQWK4qdC8d9rydg3jo2EMzCCoCQ= 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=IEnVSMco; 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="IEnVSMco" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967744; x=1792503744; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9fyo4x15I5nOU+yV4Ur/7W1Z4uAKxE2toCSFZxXkOwA=; b=IEnVSMcoOZRG6xixNJgJST+WVafdcmFF20zB2BIK7+B/Z8PJl2XnQChM b1ruamuU9NC5JXhh4gp8C6tQ4Si/fGyw6ELbJHJOsz60VmKj6swNnLRPD /Nc7Dd0r42XhBL9K0/AjCgI30iFYOo7i90DIh34hBZX2r9nLTT8gTvF6W wqFl6R5wNCqweJn3ihlenC6oow0Z6No2ulsuOS1k53L2/70gxs1Kgadi9 MGJ3SU+OD4MYNsl757w8mye4+Wq6zxE4dggkSx9yJ6Zls0YoZNMm8NQe9 34Aej5gHw/zNdvNwsgskRBOmWRLtCE0B8ydyRTG1f+nyDLB0AShwCfGaf w==; X-CSE-ConnectionGUID: d2BqNXT3T1iOmjAP1yfjIA== X-CSE-MsgGUID: f0rrhf6cRieKacebQ4z36A== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518665" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:24 +0800 IronPort-SDR: 68f63c3f_IoIeyfsA9whCqSWs6KqBXC4VHa9t6mpHRqE64J0z2rSALIQ L88+bcNzMOTQcVFH9A4yGxMKx+uw02og9fWdgwQ== 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; 20 Oct 2025 06:42:23 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:42:20 -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 v4 12/16] blktrace: move ftrace blk_io_tracer to blk_io_trace2 Date: Mon, 20 Oct 2025 15:41:19 +0200 Message-ID: <20251020134123.119058-13-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Damien Le Moal Reviewed-by: Martin K. Petersen --- 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 756d2c7dfdf2..8ffb218e9fb7 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 13:48:18 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 4AF27328B7B; Mon, 20 Oct 2025 13:42:28 +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=1760967749; cv=none; b=gCXEODx9rN1YYYbge9pmdofL43Wx3amvICfz1negTRMXvTlztDM9SQp2MWjk5elbm3B9e5TZCmwZYwGHFWdVaZH0jvaYG27VIVw532IGAqlqulO0Bcg3K+yAYuu2TwaXX+aKEJZ9DwIw9yPbr4/kLvr7HGhIk3xoJTlIzNJcPIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967749; c=relaxed/simple; bh=4Vc1bqhgksAhocQcTB57MIcEHnq1YQ2loxnl4lmFJ8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hAZXjKYmYNrz/dtTdBe8FHUCItXgeVH/g9hlM/RGVQfXLMy9uYKXa9iwflODEZM/dtWtlG6M2AUAL3sjEzDYdpW1pZKxyAVB7v8Y4Jb/ZbDKCBN09aSN0pJXt2j3ximFFozfY6Xo5zKCPQoM+A0kOg9cvTJW2s3/LFLEFH6ioZA= 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=p65y8kcE; 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="p65y8kcE" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967749; x=1792503749; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4Vc1bqhgksAhocQcTB57MIcEHnq1YQ2loxnl4lmFJ8w=; b=p65y8kcEBZdIkKAuSsyS7QVPXEuj/aAqAnC2T9A7KJ1zrBY+httd/8rF FsbpbxU0DcwqKKcB+Mm8x5LIJ5eSIXWeL7nYLsWAOs4tilGTwYCwBkr7Z KplW0lzfzrND6dMObPcvg6LFAPV2TkDRneK9TRfiHhAQiAvnyilhILDHV q8ekemslMVuy3D/r+lE3SwGZLN2T+vjrpChtXkIAWQzALRoXGp7IV5ZLV Nt5eJdEnlcqDXHVeX1fAiQij8QYjMTMLQKMWh2Cb1O0X7mXyWvBjmyKjE zP+31/LUHiwMKyKOKeyubYP+Yl3e9f36vR/oLLlKP3gvT4ErOHi1Neh1f A==; X-CSE-ConnectionGUID: Hg11s+NgRMS49x85/gX4Lg== X-CSE-MsgGUID: Kw3W6No8TUa5xD9hlwbqrA== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518672" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:28 +0800 IronPort-SDR: 68f63c44_H9yFNYC5hvEFdW4d9qvUU4MiYWFwnw1aq3m/s9RbSvMwe9b dxaot4t8laAKNtpZIqS4DXo05ad++YgvX9hvurA== 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; 20 Oct 2025 06:42:28 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:42: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 v4 13/16] blktrace: add block trace commands for zone operations Date: Mon, 20 Oct 2025 15:41:20 +0200 Message-ID: <20251020134123.119058-14-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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. Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- include/uapi/linux/blktrace_api.h | 13 +++++++++++-- kernel/trace/blktrace.c | 28 ++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/blktrace_api.h b/include/uapi/linux/blktrac= e_api.h index 3a771b9802aa..925f78af939e 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 8ffb218e9fb7..e8effb6cb393 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,31 @@ 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 + WARN_ON_ONCE(bt->version =3D=3D 1 && + (what >> BLK_TC_SHIFT) > BLK_TC_END_V1); + if (cgid) what |=3D __BLK_TA_CGROUP; =20 @@ -386,8 +407,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 13:48:18 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 A4B98329C52; Mon, 20 Oct 2025 13:42:32 +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=1760967754; cv=none; b=elgLYUFuQBaJAbGDbP2Vbl79yb0pCyAq3xQHxKS9Omk289j1MKpWgVckwTE1NkTW9SPRSPTBIDXexiKM2tkpYouqd5wnX6+613wGb25/7v3dIfszBnsm+sDNSl3fiO7Ma76K6oHASHn9MHiip3zGuBrYjR5PgfdVwKpSMulhcNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967754; c=relaxed/simple; bh=4BZU4ae3v+trGuRWLJAjp1+03O0MIvPY3ejsJ44x7qo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QIcnFk9HafFpLhSzhqo8xfkiDP/Avw5HoimIqt94AUVJk7qKRwmPI06C4Ir7soOOPNbYyvYMpOeDIS64kiQNilRgtOakNSEqHxGBlbw9qTY0SAkBOmiG0AkLumXi3HGED+jFyNygPOwwAGb0E6WZsjDgGg6q65vTKNsc1CWV7Sw= 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=EJFiZ3P/; 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="EJFiZ3P/" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967753; x=1792503753; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4BZU4ae3v+trGuRWLJAjp1+03O0MIvPY3ejsJ44x7qo=; b=EJFiZ3P/Fb8Gysu3KtWc44cmIk593MV7xZM3eziwO5nJDRid8OWvO5B8 xpCKGZJXvx6dFp0Cb69oKLPD+dK8iIt8Wz83BiiIL1KkDQBRvx7cvbf9r 0b7LWEs0ImvWDU5YiTDOpJcJSLqUFNjS1HsjU6JIzV6hC5CTusxb1iPdf 6Z7uer4EtFlytJIvvL5nxTOin3DlGf+JxZjpWPyszLVxtncCXfqk6Eq0e OwkeTU4PrgOZT0Sez9xOxxS2EfNzBq68SLwecSQIA0jS315cHKQfnqpMQ r4qBJM5sEC08Y3wUjze3UKzdnRBmtefdPySo2pa0Wr5YOzQcg+yrdjKf4 A==; X-CSE-ConnectionGUID: rYZNMJ67RpG+/wkiNHqBvg== X-CSE-MsgGUID: S7IQrHcHQ7OoD3zlvMmKag== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518675" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:33 +0800 IronPort-SDR: 68f63c48_3n+GmQEEQ0NXQnyZjjqKdLOnohBjyGdgUT393iOtMo8Xhjk AYxtT9sgV8DewCQ/0m+oXv8W3+CIhwP27biDP8A== 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; 20 Oct 2025 06:42:32 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:42:28 -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 v4 14/16] blktrace: expose ZONE APPEND completions to blktrace Date: Mon, 20 Oct 2025 15:41:21 +0200 Message-ID: <20251020134123.119058-15-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 925f78af939e..bf41e34df3c8 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 e8effb6cb393..68a657a1ccf8 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -977,6 +977,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 @@ -1207,6 +1223,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); @@ -1226,6 +1245,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 13:48:18 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 EDABF329C78; Mon, 20 Oct 2025 13:42:36 +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=1760967758; cv=none; b=nfceQAnl3BrGeMG+LRBTY3XhBWBKbdPss7AH+aFQE+n+IPnJAGFcyjTBxETPagFbpd1H3ZmI5+5biY+Xja3VWCoQfCQOvxmrw8c4fUft55TY7PjLmxOd0JF3eR4at5VmuBfYZdfIHuLtdRl81DQgopQFftmchKf2KX9JOGtCoBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967758; c=relaxed/simple; bh=0nrXNfD460Mtl1MFFAMvJzwRfMU2OVIxJ2qFN/mJW+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V6saC58099aJJgKRQxZM/kQ+nKVxeTtHOfj1iS4nZ2ZSI22fm7TpT1QG8It2J717niP6dPhHlSE7jpVhxTiTZjDzyBVLP9u7veb4UKmBEzI+C1yJjaNXcggqMC4FEuwx2E/h//gYWEuawRMHbnuJJDguDGYVJNvXC+Ya1yA8dNg= 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=ZCrYfVsm; 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="ZCrYfVsm" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967757; x=1792503757; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0nrXNfD460Mtl1MFFAMvJzwRfMU2OVIxJ2qFN/mJW+s=; b=ZCrYfVsmTS+fBSZnmP0AD3OFMBij/xVUFAhSamOTQkhJb4lHaEIp6EE4 DBr/ehxSSxroKNgZfaSh1StfssGFcpgXD0uKmvawx603+zVRq+sDI3scc vH+MWJe95GBVbVqpAmI8C2lPn178OUl4p0zYHXVIgDHwh5Wf9ufQTrU6H r/GXxsqpi3FRLzzDMyjAIEmS3jPL5D05EMdq4t1hOS/OP1R1Du7mnUNAb Pq5aB+pTXMsEcB1+7bT8xzisAid8bRfroZrYgBYpSbuaBEPxz17srqoFk mf089mAaFMh1ud3QIJvziGX6PFOYev3ogNWXQR5jPw5FrEtPyYg0/iMyU w==; X-CSE-ConnectionGUID: wxObZOJUQdu/W6PH3SMPnA== X-CSE-MsgGUID: k0i2bynzS8OhXmQj0Da5Ow== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518683" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:37 +0800 IronPort-SDR: 68f63c4c_/Id36soLxXbCOrMp0ddXQ3HvNhl6CTBrr5p1vI5tyRW2uSt 2SRw5Nhx0lBW31lVk/y4+qpA09I/3+kaQnuJA8Q== 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; 20 Oct 2025 06:42:36 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06: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 v4 15/16] blktrace: trace zone write plugging operations Date: Mon, 20 Oct 2025 15:41:22 +0200 Message-ID: <20251020134123.119058-16-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 bf41e34df3c8..63de5fb07553 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 68a657a1ccf8..75994671d7ee 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -1083,6 +1083,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; @@ -1226,6 +1257,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); @@ -1245,6 +1282,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 13:48:18 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 482AB320CC9; Mon, 20 Oct 2025 13:42:41 +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=1760967762; cv=none; b=dT7CEgFYty41L1ZbxqtDWGwW1WM+NO2TlxkIOwJ2zbjzD+6zagUQrxb66W6CyorATNY2kNuzix9f/1s3JPV9AAcFEd7HQ7pMKeD+XsEoXmkbOSGEDhjICZRIB/8q5IMat5S6IuIroXCn600lIV+QjcF7i8SBsMfXD/N3qFM5CFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760967762; c=relaxed/simple; bh=NYIcWPB3HB87TMKzTL0Sak6CDFuBEJcCgrUOwcRT2ss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BsIByOcOw5HCNVAyBZBFZ6rZje64d6SNPSnHbWyydhep9TMiKLKY42oTjUFStKCrL63oepys5KHNhUwuc6O9M7W7AkFlNbnhiq2OZgg2fK03Eu6dqDCV95osJ3TMd0L4G1FopfZAEKcvW5huMwy9sOU6RsoTo0JlsDBrsUhCqEc= 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=jlN+RZE9; 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="jlN+RZE9" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1760967762; x=1792503762; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NYIcWPB3HB87TMKzTL0Sak6CDFuBEJcCgrUOwcRT2ss=; b=jlN+RZE9BDBd3mWVEhKUFyW//oYwVy/TmUczXOWBKHzoD5nrPf3uIKoQ oC1quyn9Wk2w+u93BoL9vK/yRBsEhDpF35jOnayZSLnljRReHWGzj3/fv 07kfaUnAjWUKffRHRdruFzswFQIPlWCYQPCALLyBuP0NRC2WmH09ugZHF q2dwwnjtbjLl7DtUkfEXv5DhWKQnF1HyOdW3gcdtyDK3/7j6gI1wOQ5+g noKCligjOb+kk1GvnX8UchRNHcKXhgIkQACwoDXrJhBfyTh5QLhDAmon5 YTy3n2JvR++3UL4cHPpIPID7s+8BW7JNBjR7Ewxwasmaf/EJUKJ4bs2yR A==; X-CSE-ConnectionGUID: 3MUKF46ORVi4889FyiVJlg== X-CSE-MsgGUID: jL2x8eHaSpOBPi37QVUnAg== X-IronPort-AV: E=Sophos;i="6.19,242,1754928000"; d="scan'208";a="134518687" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep03.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Oct 2025 21:42:41 +0800 IronPort-SDR: 68f63c50_2OxoRKbsNO9+K43s5AxCyO2gry8KeD4uyHUV/lDBjW+sFS3 aBDYdHzrpzU9sj1JMjF0IHc3DLtL9JEOR8ymuNA== 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; 20 Oct 2025 06:42:41 -0700 WDCIronportException: Internal Received: from 1pgdl13.ad.shared (HELO neo.fritz.box) ([10.224.28.46]) by uls-op-cesaip02.wdc.com with ESMTP; 20 Oct 2025 06:42: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 v4 16/16] blktrace: handle BLKTRACESETUP2 ioctl Date: Mon, 20 Oct 2025 15:41:23 +0200 Message-ID: <20251020134123.119058-17-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251020134123.119058-1-johannes.thumshirn@wdc.com> References: <20251020134123.119058-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 Signed-off-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- 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 75994671d7ee..c4f0b84482ca 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -748,6 +748,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, @@ -838,6 +870,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