ufs: core: add hba parameter to trace events
Subsystems (4)
PATCH v3 1/1 ufs: core: add hba parameter to trace events
From: Peter Wang <[email protected]>
Included the ufs_hba structure as a parameter in various trace events to provide more context and improve debugging capabilities. Also remove dev_name which can replace by dev_name(hba->dev).
V3:
- Remove dev_name entry form TP_STRUCT__entry() to reduce the size.
V2:
- Remove dev_name and replace it with dev_name(hba->dev).
--- drivers/ufs/core/ufs_trace.h | 135 ++++++++++++++++++----------------- drivers/ufs/core/ufshcd.c | 68 +++++++++--------- 2 files changed, 103 insertions(+), 100 deletions(-)
drivers/ufs/core/ufs_trace.h +69 -66
@@ -83,34 +83,34 @@ UFS_CMD_TRACE_TSF_TYPESTRACE_EVENT (ufshcd_clk_gating, - TP_PROTO(const char *dev_name, int state), + TP_PROTO(struct ufs_hba *hba, int state), -TP_ARGS (dev_name, state), +TP_ARGS (hba, state),TP_STRUCT__entry ( - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba)__field (int, state) ),TP_fast_assign ( - __assign_str(dev_name); + __entry->hba = hba; __entry->state = state; ),TP_printk ("%s: gating state changed to %s" , -__get_str (dev_name), +dev_name (__entry->hba->dev),__print_symbolic (__entry->state,UFSCHD_CLK_GATING_STATES )) ); TRACE_EVENT(ufshcd_clk_scaling, - TP_PROTO(const char *dev_name, const char *state, const char *clk, + TP_PROTO(struct ufs_hba *hba, const char *state, const char *clk, u32 prev_state, u32 curr_state), - TP_ARGS(dev_name, state, clk, prev_state, curr_state), + TP_ARGS(hba, state, clk, prev_state, curr_state), TP_STRUCT__entry( - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba) __string(state, state) __string(clk, clk) __field(u32, prev_state)
@@ -118,7 +118,7 @@ TRACE_EVENT(ufshcd_clk_scaling, ), TP_fast_assign( - __assign_str(dev_name); + __entry->hba = hba;__assign_str (state);__assign_str (clk); __entry->prev_state = prev_state;
@@ -126,80 +126,80 @@ TRACE_EVENT(ufshcd_clk_scaling, ),TP_printk ("%s: %s %s from %u to %u Hz" , -__get_str (dev_name),__get_str (state),__get_str (clk), +dev_name (__entry->hba->dev),__get_str (state),__get_str (clk), __entry->prev_state, __entry->curr_state) );TRACE_EVENT (ufshcd_auto_bkops_state, - TP_PROTO(const char *dev_name, const char *state), + TP_PROTO(struct ufs_hba *hba, const char *state), -TP_ARGS (dev_name, state), +TP_ARGS (hba, state),TP_STRUCT__entry ( - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba)__string (state, state) ),TP_fast_assign ( - __assign_str(dev_name); + __entry->hba = hba; __assign_str(state); ),TP_printk ("%s: auto bkops - %s" , -__get_str (dev_name),__get_str (state)) +dev_name (__entry->hba->dev),__get_str (state)) );DECLARE_EVENT_CLASS (ufshcd_profiling_template, - TP_PROTO(const char *dev_name, const char *profile_info, s64 time_us, + TP_PROTO(struct ufs_hba *hba, const char *profile_info, s64 time_us, int err), -TP_ARGS (dev_name, profile_info, time_us, err), +TP_ARGS (hba, profile_info, time_us, err),TP_STRUCT__entry ( - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba) __string(profile_info, profile_info) __field(s64, time_us)__field (int, err) ),TP_fast_assign ( - __assign_str(dev_name); + __entry->hba = hba; __assign_str(profile_info); __entry->time_us = time_us; __entry->err = err; ),TP_printk ("%s: %s: took %lld usecs, err %d" , -__get_str (dev_name),__get_str (profile_info), +dev_name (__entry->hba->dev),__get_str (profile_info), __entry->time_us, __entry->err) );DEFINE_EVENT (ufshcd_profiling_template, ufshcd_profile_hibern8, - TP_PROTO(const char *dev_name, const char *profile_info, s64 time_us, + TP_PROTO(struct ufs_hba *hba, const char *profile_info, s64 time_us, int err), -TP_ARGS (dev_name, profile_info, time_us, err)); +TP_ARGS (hba, profile_info, time_us, err));DEFINE_EVENT (ufshcd_profiling_template, ufshcd_profile_clk_gating, - TP_PROTO(const char *dev_name, const char *profile_info, s64 time_us, + TP_PROTO(struct ufs_hba *hba, const char *profile_info, s64 time_us, int err), -TP_ARGS (dev_name, profile_info, time_us, err)); +TP_ARGS (hba, profile_info, time_us, err));DEFINE_EVENT (ufshcd_profiling_template, ufshcd_profile_clk_scaling, - TP_PROTO(const char *dev_name, const char *profile_info, s64 time_us, + TP_PROTO(struct ufs_hba *hba, const char *profile_info, s64 time_us, int err), -TP_ARGS (dev_name, profile_info, time_us, err)); +TP_ARGS (hba, profile_info, time_us, err)); DECLARE_EVENT_CLASS(ufshcd_template, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), - TP_ARGS(dev_name, err, usecs, dev_state, link_state), + TP_ARGS(hba, err, usecs, dev_state, link_state), TP_STRUCT__entry( __field(s64, usecs) __field(int, err) - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba) __field(int, dev_state) __field(int, link_state) ),
@@ -207,14 +207,14 @@ DECLARE_EVENT_CLASS(ufshcd_template,TP_fast_assign ( __entry->usecs = usecs; __entry->err = err; -__assign_str (dev_name); + __entry->hba = hba; __entry->dev_state = dev_state; __entry->link_state = link_state; ), TP_printk( "%s: took %lld usecs, dev_state: %s, link_state: %s, err %d", - __get_str(dev_name), + dev_name(__entry->hba->dev), __entry->usecs, __print_symbolic(__entry->dev_state, UFS_PWR_MODES), __print_symbolic(__entry->link_state, UFS_LINK_STATES),
@@ -223,60 +223,62 @@ DECLARE_EVENT_CLASS(ufshcd_template, );DEFINE_EVENT (ufshcd_template, ufshcd_system_suspend, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state));DEFINE_EVENT (ufshcd_template, ufshcd_system_resume, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state));DEFINE_EVENT (ufshcd_template, ufshcd_runtime_suspend, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state));DEFINE_EVENT (ufshcd_template, ufshcd_runtime_resume, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state));DEFINE_EVENT (ufshcd_template, ufshcd_init, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state));DEFINE_EVENT (ufshcd_template, ufshcd_wl_suspend, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state));DEFINE_EVENT (ufshcd_template, ufshcd_wl_resume, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state));DEFINE_EVENT (ufshcd_template, ufshcd_wl_runtime_suspend, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state));DEFINE_EVENT (ufshcd_template, ufshcd_wl_runtime_resume, - TP_PROTO(const char *dev_name, int err, s64 usecs, + TP_PROTO(struct ufs_hba *hba, int err, s64 usecs, int dev_state, int link_state), -TP_ARGS (dev_name, err, usecs, dev_state, link_state)); +TP_ARGS (hba, err, usecs, dev_state, link_state)); TRACE_EVENT(ufshcd_command, - TP_PROTO(struct scsi_device *sdev, enum ufs_trace_str_t str_t, + TP_PROTO(struct scsi_device *sdev, struct ufs_hba *hba, + enum ufs_trace_str_t str_t, unsigned int tag, u32 doorbell, u32 hwq_id, int transfer_len, u32 intr, u64 lba, u8 opcode, u8 group_id), - TP_ARGS(sdev, str_t, tag, doorbell, hwq_id, transfer_len, intr, lba, + TP_ARGS(sdev, hba, str_t, tag, doorbell, hwq_id, transfer_len, intr, lba, opcode, group_id), TP_STRUCT__entry( __field(struct scsi_device *, sdev) + __field(struct ufs_hba *, hba) __field(enum ufs_trace_str_t, str_t) __field(unsigned int, tag) __field(u32, doorbell)
@@ -290,6 +292,7 @@ TRACE_EVENT(ufshcd_command,TP_fast_assign ( __entry->sdev = sdev; + __entry->hba = hba; __entry->str_t = str_t; __entry->tag = tag; __entry->doorbell = doorbell;
@@ -312,13 +315,13 @@ TRACE_EVENT(ufshcd_command, ); TRACE_EVENT(ufshcd_uic_command, - TP_PROTO(const char *dev_name, enum ufs_trace_str_t str_t, u32 cmd, + TP_PROTO(struct ufs_hba *hba, enum ufs_trace_str_t str_t, u32 cmd, u32 arg1, u32 arg2, u32 arg3), - TP_ARGS(dev_name, str_t, cmd, arg1, arg2, arg3), + TP_ARGS(hba, str_t, cmd, arg1, arg2, arg3), TP_STRUCT__entry( - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba) __field(enum ufs_trace_str_t, str_t) __field(u32, cmd) __field(u32, arg1)
@@ -327,7 +330,7 @@ TRACE_EVENT(ufshcd_uic_command, ), TP_fast_assign( - __assign_str(dev_name); + __entry->hba = hba; __entry->str_t = str_t; __entry->cmd = cmd; __entry->arg1 = arg1;
@@ -337,19 +340,19 @@ TRACE_EVENT(ufshcd_uic_command,TP_printk ("%s: %s: cmd: 0x%x, arg1: 0x%x, arg2: 0x%x, arg3: 0x%x" , -show_ufs_cmd_trace_str (__entry->str_t),__get_str (dev_name), +show_ufs_cmd_trace_str (__entry->str_t),dev_name (__entry->hba->dev), __entry->cmd, __entry->arg1, __entry->arg2, __entry->arg3 ) ); TRACE_EVENT(ufshcd_upiu, - TP_PROTO(const char *dev_name, enum ufs_trace_str_t str_t, void *hdr, + TP_PROTO(struct ufs_hba *hba, enum ufs_trace_str_t str_t, void *hdr, void *tsf, enum ufs_trace_tsf_t tsf_t), - TP_ARGS(dev_name, str_t, hdr, tsf, tsf_t), + TP_ARGS(hba, str_t, hdr, tsf, tsf_t), TP_STRUCT__entry( - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba) __field(enum ufs_trace_str_t, str_t) __array(unsigned char, hdr, 12) __array(unsigned char, tsf, 16)
@@ -357,7 +360,7 @@ TRACE_EVENT(ufshcd_upiu, ), TP_fast_assign( - __assign_str(dev_name); + __entry->hba = hba; __entry->str_t = str_t;memcpy (__entry->hdr, hdr,sizeof (__entry->hdr));memcpy (__entry->tsf, tsf,sizeof (__entry->tsf));
@@ -366,7 +369,7 @@ TRACE_EVENT(ufshcd_upiu,TP_printk ("%s: %s: HDR:%s, %s:%s" , -show_ufs_cmd_trace_str (__entry->str_t),__get_str (dev_name), +show_ufs_cmd_trace_str (__entry->str_t),dev_name (__entry->hba->dev),__print_hex (__entry->hdr,sizeof (__entry->hdr)),show_ufs_cmd_trace_tsf (__entry->tsf_t), __print_hex(__entry->tsf, sizeof(__entry->tsf))
@@ -375,22 +378,22 @@ TRACE_EVENT(ufshcd_upiu,TRACE_EVENT (ufshcd_exception_event, - TP_PROTO(const char *dev_name, u16 status), + TP_PROTO(struct ufs_hba *hba, u16 status), -TP_ARGS (dev_name, status), +TP_ARGS (hba, status),TP_STRUCT__entry ( - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba)__field (u16, status) ),TP_fast_assign ( - __assign_str(dev_name); + __entry->hba = hba; __entry->status = status; ),TP_printk ("%s: status 0x%x" , -__get_str (dev_name), __entry->status +dev_name (__entry->hba->dev), __entry->status ) );
drivers/ufs/core/ufshcd.c +34 -34
268 lines not on this page · raw message
Signature · 1 line
2.45.2
Quoted 3 lines · On 2/14/25 12:29 AM, [email protected] wrote:
Included the
ufs_hbastructure as a parameter in various trace events to provide more context and improve debugging capabilities. Also removedev_namewhich can replace bydev_name(hba->dev).
Quoted 4 lines · On Fri, 2025-02-14 at 16:29 +0800, [email protected] wrote:
From: Peter Wang <[email protected]>
Included the
ufs_hbastructure as a parameter in various trace events to provide more context and improve debugging capabilities.
From the patch commit message, it is no clear how you can use this change to get more infor and debug, since the content of the ftrace output is the same after this change. Because the device name (dev_name) is still being printed, but now it is derived dynamically from hba->dev instead of being stored as a string in the trace event.
I assume you mean to let bpf get more information from hba:
strust ufs hba *hba = ctx->hba;
If my assumption is correct, this purpose and intent should be prominently highlighted in patch commit message.
Kind regards,
Bean
Quoted 22 lines · Bean Huo
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 5 lines · On Fri, 2025-02-14 at 16:29 +0800, [email protected] wrote:
From: Peter Wang <[email protected]>
Included the
ufs_hbastructure as a parameter in various trace events
to provide more context and improve debugging capabilities.From the patch commit message, it is no clear how you can use this change to get more infor and debug, since the content of the ftrace output is the same after this change. Because the device name (
dev_name) is still being printed, but now it is derived dynamically fromhba->devinstead of being stored as a string in the trace event.I assume you mean to let bpf get more information from hba:
Quoted 8 lines
strust ufs hba *hba =
ctx->hba;If my assumption is correct, this purpose and intent should be prominently highlighted in patch commit message.
Kind regards,
Bean
Hi Bean,
The use of HBA varies depending on the debugging needs. When the tracepoint_probe_register is used to register a debug callback function, we can utilize the parameters of the HBA structure more efficiently to obtain the debug information we need.
As for what specific debug information is required, that depends on the individual needs. It depends on how the debugger wants to use it, so the method of use is not specifically mentioned in the commit message. However, in summary, it is a patch that enhances debugging efficiency.
Thanks.
Peter
Martin K. Petersen
AppliedQuoted 4 lines
Included the
ufs_hbastructure as a parameter in various trace events to provide more context and improve debugging capabilities. Also removedev_namewhich can replace bydev_name(hba->dev).
Applied to 6.15/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Martin K. Petersen
AppliedQuoted 8 lines · On Fri, 14 Feb 2025 16:29:36 +0800, [email protected] wrote:
Included the
ufs_hbastructure as a parameter in various trace events to provide more context and improve debugging capabilities. Also removedev_namewhich can replace bydev_name(hba->dev).V3:
- Removedev_nameentry formTP_STRUCT__entry()to reduce the size.[...]
Applied to 6.15/scsi-queue, thanks!
[1/1] ufs: core: add hba parameter to trace events
https://git.kernel.org/mkp/scsi/c/583e518e7100
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Steven Rostedt
maintainerQuoted 6 lines · On Fri, 14 Feb 2025 16:29:36 +0800 <[email protected]> wrote:
From: Peter Wang <[email protected]>
Included the
ufs_hbastructure as a parameter in various trace events to provide more context and improve debugging capabilities. Also removedev_namewhich can replace bydev_name(hba->dev).
Quoted 7 lines
V3:
- Removedev_nameentry formTP_STRUCT__entry()to reduce the size.V2:
- Removedev_nameand replace it withdev_name(hba->dev).
This patch needs to be reverted, as the above causes a bug.
Quoted 26 lines
Signed-off-by Peter Wang <[email protected]>--- drivers/ufs/core/ufs_trace.h | 135 ++++++++++++++++++----------------- drivers/ufs/core/ufshcd.c | 68 +++++++++--------- 2 files changed, 103 insertions(+), 100 deletions(-)drivers/ufs/core/ufs_trace.h +3
-3@@ -83,34 +83,34 @@ UFS_CMD_TRACE_TSF_TYPES TRACE_EVENT(ufshcd_clk_gating, - TP_PROTO(const char *dev_name, int state), + TP_PROTO(struct ufs_hba *hba, int state), - TP_ARGS(dev_name, state), + TP_ARGS(hba, state), TP_STRUCT__entry( - __string(dev_name, dev_name) + __field(struct ufs_hba *, hba) __field(int, state) ),
drivers/ufs/core/ufs_trace.h UFS_CMD_TRACE_TSF_TYPES · line 101
Quoted 10 lines
drivers/ufs/core/ufs_trace.h +2
-2TP_fast_assign ( - __assign_str(dev_name); + __entry->hba = hba; __entry->state = state; ), TP_printk("%s: gating state changed to %s", - __get_str(dev_name), + dev_name(__entry->hba->dev),
NO YOU CAN NOT DO THIS!!!!
The TP_fast_assign() happens when the trace event occurs. That is, where the trace_ufshcd_clk_gating() function is called.
The TP_printk() happens when a user reads the "trace" file. Which could be seconds, minutes, hours, days, even months later! There is absolutely no guarantee that the pointer to __entry->hba would be around. This would cause a crash of the kernel when the "trace" file is read.
I'm adding a boot up test to cause code like this to trigger a warning when the trace event is registered (how I found this bug):
drivers/ufs/core/ufs_trace.h UFS_CMD_TRACE_TSF_TYPES · line 103
Quoted 2 lines
drivers/ufs/core/ufs_trace.h +0
-0__print_symbolic(__entry->state, UFSCHD_CLK_GATING_STATES)) );
The same goes for the rest of this file.
-- Steve
Steven Rostedt
maintainerQuoted 6 lines · On Tue, 30 Jun 2026 16:56:12 -0400 Steven Rostedt <[email protected]> wrote:
Review
Quoted 4 lines
(quoted diff) +1
-1TP_printk("%s: gating state changed to %s", - __get_str(dev_name), + dev_name(__entry->hba->dev),NO YOU CAN NOT DO THIS!!!!
This is why you should always Cc [email protected] on any trace event updates. We look to catch bugs like this.
The below patch should fix it, and I'll send it as a proper patch soon:
drivers/ufs/core/ufs_trace.h +27 -9
@@ -89,16 +89,18 @@ TRACE_EVENT(ufshcd_clk_gating,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__field (int, state) ),TP_fast_assign ( + __assign_str(dev_name); __entry->hba = hba; __entry->state = state; ),TP_printk ("%s: gating state changed to %s" , -dev_name (__entry->hba->dev), +__get_str (dev_name),__print_symbolic (__entry->state,UFSCHD_CLK_GATING_STATES )) );
@@ -111,6 +113,7 @@ TRACE_EVENT(ufshcd_clk_scaling,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__string (state, state)__string (clk, clk) __field(u32, prev_state)
@@ -119,6 +122,7 @@ TRACE_EVENT(ufshcd_clk_scaling,TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name);__assign_str (state);__assign_str (clk); __entry->prev_state = prev_state;
@@ -126,7 +130,7 @@ TRACE_EVENT(ufshcd_clk_scaling, ),TP_printk ("%s: %s %s from %u to %u Hz" , -dev_name (__entry->hba->dev),__get_str (state),__get_str (clk), +__get_str (dev_name),__get_str (state),__get_str (clk), __entry->prev_state, __entry->curr_state) );
@@ -138,16 +142,18 @@ TRACE_EVENT(ufshcd_auto_bkops_state,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__string (state, state) ),TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name);__assign_str (state); ),TP_printk ("%s: auto bkops - %s" , -dev_name (__entry->hba->dev),__get_str (state)) +__get_str (dev_name),__get_str (state)) ); DECLARE_EVENT_CLASS(ufshcd_profiling_template,
@@ -158,6 +164,7 @@ DECLARE_EVENT_CLASS(ufshcd_profiling_template,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__string (profile_info, profile_info)__field (s64, time_us) __field(int, err)
@@ -165,13 +172,14 @@ DECLARE_EVENT_CLASS(ufshcd_profiling_template,TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name);__assign_str (profile_info); __entry->time_us = time_us; __entry->err = err; ),TP_printk ("%s: %s: took %lld usecs, err %d" , -dev_name (__entry->hba->dev),__get_str (profile_info), +__get_str (dev_name),__get_str (profile_info), __entry->time_us, __entry->err) );
@@ -200,6 +208,7 @@ DECLARE_EVENT_CLASS(ufshcd_template, __field(s64, usecs) __field(int, err) __field(struct ufs_hba *, hba) + __string(dev_name, dev_name(hba->dev)) __field(int, dev_state) __field(int, link_state) ),
@@ -208,13 +217,14 @@ DECLARE_EVENT_CLASS(ufshcd_template, __entry->usecs = usecs; __entry->err = err; __entry->hba = hba; +__assign_str (dev_name); __entry->dev_state = dev_state; __entry->link_state = link_state; ), TP_printk( "%s: took %lld usecs, dev_state: %s, link_state: %s, err %d", - dev_name(__entry->hba->dev), + __get_str(dev_name), __entry->usecs, __print_symbolic(__entry->dev_state, UFS_PWR_MODES), __print_symbolic(__entry->link_state, UFS_LINK_STATES),
@@ -279,6 +289,7 @@ TRACE_EVENT(ufshcd_command, TP_STRUCT__entry( __field(struct scsi_device *, sdev) __field(struct ufs_hba *, hba) + __string(dev_name, dev_name(&sdev->sdev_dev)) __field(enum ufs_trace_str_t, str_t) __field(unsigned int, tag) __field(u32, doorbell)
@@ -291,6 +302,7 @@ TRACE_EVENT(ufshcd_command, ), TP_fast_assign( + __assign_str(dev_name); __entry->sdev = sdev; __entry->hba = hba; __entry->str_t = str_t;
@@ -307,7 +319,7 @@ TRACE_EVENT(ufshcd_command,TP_printk ("%s: %s: tag: %u, DB: 0x%x, size: %d, IS: %u, LBA: %llu, opcode: 0x%x (%s), group_id: 0x%x, hwq_id: %d" ,show_ufs_cmd_trace_str (__entry->str_t), -dev_name (&__entry->sdev->sdev_dev), __entry->tag, +__get_str (dev_name), __entry->tag, __entry->doorbell, __entry->transfer_len, __entry->intr, __entry->lba, (u32 )__entry->opcode,str_opcode (__entry->opcode), (u32)__entry->group_id, __entry->hwq_id
@@ -322,6 +334,7 @@ TRACE_EVENT(ufshcd_uic_command,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev)) __field(enum ufs_trace_str_t, str_t)__field (u32, cmd) __field(u32, arg1)
@@ -331,6 +344,7 @@ TRACE_EVENT(ufshcd_uic_command,TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name); __entry->str_t = str_t; __entry->cmd = cmd; __entry->arg1 = arg1;
@@ -340,7 +354,7 @@ TRACE_EVENT(ufshcd_uic_command,TP_printk ("%s: %s: cmd: 0x%x, arg1: 0x%x, arg2: 0x%x, arg3: 0x%x" , -show_ufs_cmd_trace_str (__entry->str_t),dev_name (__entry->hba->dev), +show_ufs_cmd_trace_str (__entry->str_t),__get_str (dev_name), __entry->cmd, __entry->arg1, __entry->arg2, __entry->arg3 ) );
@@ -353,6 +367,7 @@ TRACE_EVENT(ufshcd_upiu,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev)) __field(enum ufs_trace_str_t, str_t) __array(unsigned char, hdr, 12) __array(unsigned char, tsf, 16)
@@ -361,6 +376,7 @@ TRACE_EVENT(ufshcd_upiu,TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name); __entry->str_t = str_t;memcpy (__entry->hdr, hdr,sizeof (__entry->hdr));memcpy (__entry->tsf, tsf,sizeof (__entry->tsf));
@@ -369,7 +385,7 @@ TRACE_EVENT(ufshcd_upiu,TP_printk ("%s: %s: HDR:%s, %s:%s" , -show_ufs_cmd_trace_str (__entry->str_t),dev_name (__entry->hba->dev), +show_ufs_cmd_trace_str (__entry->str_t),__get_str (dev_name),__print_hex (__entry->hdr,sizeof (__entry->hdr)),show_ufs_cmd_trace_tsf (__entry->tsf_t), __print_hex(__entry->tsf, sizeof(__entry->tsf))
@@ -384,16 +400,18 @@ TRACE_EVENT(ufshcd_exception_event,TP_STRUCT__entry (__field (struct ufs_hba *,hba ) + __string(dev_name, dev_name(hba->dev))__field (u16, status) ),TP_fast_assign ( __entry->hba = hba; +__assign_str (dev_name); __entry->status = status; ),TP_printk ("%s: status 0x%x" , -dev_name (__entry->hba->dev), __entry->status +__get_str (dev_name), __entry->status ) );
-- Steve
Quoted 8 lines · Steven Rostedt
Quoted 5 lines · On Tue, 30 Jun 2026 16:56:12 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 4 lines
TP_printk("%s: gating state changed to %s",
-__get_str(dev_name),
+dev_name(__entry->hba->dev),
Quoted 8 lines
Quoted 1 line
NO YOU CAN NOT DO THIS!!!!
This is why you should always Cc [email protected] on any trace event updates. We look to catch bugs like this.
The below patch should fix it, and I'll send it as a proper patch soon:
Hi Steven,
Thank you for the reminder and for fixing this bug. This was indeed not thoroughly considered.
However, I am curious: if the HBA is removed, implying that the storage would become unusable, might the system encounter an I/O hang or shutdown, potentially preventing its detection? Perhaps it's a theoretical issue that would not manifest in a real-world situation?
Thanks
Peter
Steven Rostedt
maintainerQuoted 5 lines · On Wed, 1 Jul 2026 06:11:37 +0000 Peter Wang (王信友) <[email protected]>…
However, I am curious: if the HBA is removed, implying that the storage would become unusable, might the system encounter an I/O hang or shutdown, potentially preventing its detection? Perhaps it's a theoretical issue that would not manifest in a real-world situation?
Note, it doesn't necessarily mean that the device itself was removed. The issue is that a pointer to an allocated descriptor is saved in the ring buffer.
Maybe once the device is created it will never go way. But what happens if for some reason the descriptor is freed and reallocated? Now the old descriptor pointer is still in the ring buffer.
What in the logic guarantees that the pointer will never be freed?
And lets say there is an issue and the hba is freed and you debug this by dumping the trace buffer via ftrace_dump_on_oops. Now the dump itself may crash and you don't have a way to debug what happened.
One other point that causes issues here. It makes user space tracing useless. Try tracing this with "trace-cmd record". These events will not be able to be parsed.
-- Steve
Quoted 27 lines · Steven Rostedt
Quoted 5 lines · On Wed, 1 Jul 2026 06:11:37 +0000 Peter Wang (王信友) <[email protected]>…
However, I am curious: if the HBA is removed, implying that the storage would become unusable, might the system encounter an I/O hang or shutdown, potentially preventing its detection? Perhaps it's a theoretical issue that would not manifest in a real-world situation?
Note, it doesn't necessarily mean that the device itself was removed. The
issue is that a pointer to an allocated descriptor is saved in the ring buffer.Maybe once the device is created it will never go way. But what happens if
for some reason the descriptor is freed and reallocated? Now the old descriptor pointer is still in the ring buffer.What in the logic guarantees that the pointer will never be freed?
And lets say there is an issue and the hba is freed and you debug this by
dumping the trace buffer viaftrace_dump_on_oops. Now the dump itself may
crash and you don't have a way to debug what happened.
Quoted 7 lines
One other point that causes issues here. It makes user space tracing useless. Try tracing this with "trace-cmd record". These events will not be
able to be parsed.-- Steve
Hi Steven,
Thank you for the detailed explanation. I have no further questions.
Thanks
Peter