* [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event
@ 2026-02-02 2:45 Keita Morisaki
2026-02-02 8:14 ` Peter Wang (王信友)
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Keita Morisaki @ 2026-02-02 2:45 UTC (permalink / raw)
To: Peter Wang, Chaotian Jing
Cc: Stanley Jhu, James E . J . Bottomley, Martin K . Petersen,
linux-scsi, linux-mediatek, linux-kernel, Keita Morisaki
The ufs_mtk_clk_scale trace event currently stores the address of the
name string directly via __field(const char *, name). This pointer may
become invalid after the module is unloaded, causing page faults when
the trace buffer is subsequently accessed.
This can occur because the MediaTek UFS driver can be configured as a
loadable module (tristate in Kconfig), meaning the name string passed
to the trace event may reside in module memory that becomes invalid
after module unload.
Fix this by using __string() and __assign_str() to copy the string
contents into the ring buffer instead of storing the pointer. This
ensures the trace data remains valid regardless of module state.
This change increases the memory usage for each ftrace entry by a few
bytes (clock names are typically 7-15 characters like "ufs_sel" or
"ufs_sel_max_src") compared to storing an 8-byte pointer.
Note that this change does not affect anything unless all of the
following conditions are met:
- CONFIG_SCSI_UFS_MEDIATEK is enabled
- ftrace tracing is enabled
- The ufs_mtk_clk_scale event is enabled in ftrace
Signed-off-by: Keita Morisaki <keita.morisaki@tier4.jp>
---
drivers/ufs/host/ufs-mediatek-trace.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/ufs/host/ufs-mediatek-trace.h b/drivers/ufs/host/ufs-mediatek-trace.h
index b5f2ec314..0df8ac843 100644
--- a/drivers/ufs/host/ufs-mediatek-trace.h
+++ b/drivers/ufs/host/ufs-mediatek-trace.h
@@ -33,19 +33,19 @@ TRACE_EVENT(ufs_mtk_clk_scale,
TP_ARGS(name, scale_up, clk_rate),
TP_STRUCT__entry(
- __field(const char*, name)
+ __string(name, name)
__field(bool, scale_up)
__field(unsigned long, clk_rate)
),
TP_fast_assign(
- __entry->name = name;
+ __assign_str(name);
__entry->scale_up = scale_up;
__entry->clk_rate = clk_rate;
),
TP_printk("ufs: clk (%s) scaled %s @ %lu",
- __entry->name,
+ __get_str(name),
__entry->scale_up ? "up" : "down",
__entry->clk_rate)
);
base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event
2026-02-02 2:45 [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event Keita Morisaki
@ 2026-02-02 8:14 ` Peter Wang (王信友)
2026-02-04 3:27 ` Martin K. Petersen
2026-02-08 2:01 ` Martin K. Petersen
2 siblings, 0 replies; 5+ messages in thread
From: Peter Wang (王信友) @ 2026-02-02 8:14 UTC (permalink / raw)
To: keita.morisaki, Chaotian Jing (井朝天)
Cc: linux-scsi, linux-mediatek, chu.stanley, James.Bottomley,
martin.petersen, linux-kernel
On Mon, 2026-02-02 at 11:45 +0900, Keita Morisaki wrote:
> The ufs_mtk_clk_scale trace event currently stores the address of the
> name string directly via __field(const char *, name). This pointer
> may
> become invalid after the module is unloaded, causing page faults when
> the trace buffer is subsequently accessed.
>
> This can occur because the MediaTek UFS driver can be configured as a
> loadable module (tristate in Kconfig), meaning the name string passed
> to the trace event may reside in module memory that becomes invalid
> after module unload.
>
> Fix this by using __string() and __assign_str() to copy the string
> contents into the ring buffer instead of storing the pointer. This
> ensures the trace data remains valid regardless of module state.
>
> This change increases the memory usage for each ftrace entry by a few
> bytes (clock names are typically 7-15 characters like "ufs_sel" or
> "ufs_sel_max_src") compared to storing an 8-byte pointer.
>
> Note that this change does not affect anything unless all of the
> following conditions are met:
> - CONFIG_SCSI_UFS_MEDIATEK is enabled
> - ftrace tracing is enabled
> - The ufs_mtk_clk_scale event is enabled in ftrace
>
> Signed-off-by: Keita Morisaki <keita.morisaki@tier4.jp>
> ---
> drivers/ufs/host/ufs-mediatek-trace.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/ufs/host/ufs-mediatek-trace.h
> b/drivers/ufs/host/ufs-mediatek-trace.h
> index b5f2ec314..0df8ac843 100644
> --- a/drivers/ufs/host/ufs-mediatek-trace.h
> +++ b/drivers/ufs/host/ufs-mediatek-trace.h
> @@ -33,19 +33,19 @@ TRACE_EVENT(ufs_mtk_clk_scale,
> TP_ARGS(name, scale_up, clk_rate),
>
> TP_STRUCT__entry(
> - __field(const char*, name)
> + __string(name, name)
> __field(bool, scale_up)
> __field(unsigned long, clk_rate)
> ),
>
> TP_fast_assign(
> - __entry->name = name;
> + __assign_str(name);
> __entry->scale_up = scale_up;
> __entry->clk_rate = clk_rate;
> ),
>
> TP_printk("ufs: clk (%s) scaled %s @ %lu",
> - __entry->name,
> + __get_str(name),
> __entry->scale_up ? "up" : "down",
> __entry->clk_rate)
> );
>
Hi Keita Morisaki,
Thank you for fixing this bug.
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event
2026-02-02 2:45 [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event Keita Morisaki
2026-02-02 8:14 ` Peter Wang (王信友)
@ 2026-02-04 3:27 ` Martin K. Petersen
2026-02-04 3:31 ` Keita Morisaki
2026-02-08 2:01 ` Martin K. Petersen
2 siblings, 1 reply; 5+ messages in thread
From: Martin K. Petersen @ 2026-02-04 3:27 UTC (permalink / raw)
To: Keita Morisaki
Cc: Peter Wang, Chaotian Jing, Stanley Jhu, James E . J . Bottomley,
Martin K . Petersen, linux-scsi, linux-mediatek, linux-kernel
Keita,
> The ufs_mtk_clk_scale trace event currently stores the address of the
> name string directly via __field(const char *, name). This pointer may
> become invalid after the module is unloaded, causing page faults when
> the trace buffer is subsequently accessed.
Applied to 6.20/scsi-staging, thanks!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event
2026-02-04 3:27 ` Martin K. Petersen
@ 2026-02-04 3:31 ` Keita Morisaki
0 siblings, 0 replies; 5+ messages in thread
From: Keita Morisaki @ 2026-02-04 3:31 UTC (permalink / raw)
To: martin.petersen
Cc: James.Bottomley, chaotian.jing, chu.stanley, keita.morisaki,
linux-kernel, linux-mediatek, linux-scsi, peter.wang
Hi Martin,
> Applied to 6.20/scsi-staging, thanks!
Thank you for the update! Greatful to contribute!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event
2026-02-02 2:45 [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event Keita Morisaki
2026-02-02 8:14 ` Peter Wang (王信友)
2026-02-04 3:27 ` Martin K. Petersen
@ 2026-02-08 2:01 ` Martin K. Petersen
2 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2026-02-08 2:01 UTC (permalink / raw)
To: Peter Wang, Chaotian Jing, Keita Morisaki
Cc: Martin K . Petersen, Stanley Jhu, James E . J . Bottomley,
linux-scsi, linux-mediatek, linux-kernel
On Mon, 02 Feb 2026 11:45:26 +0900, Keita Morisaki wrote:
> The ufs_mtk_clk_scale trace event currently stores the address of the
> name string directly via __field(const char *, name). This pointer may
> become invalid after the module is unloaded, causing page faults when
> the trace buffer is subsequently accessed.
>
> This can occur because the MediaTek UFS driver can be configured as a
> loadable module (tristate in Kconfig), meaning the name string passed
> to the trace event may reside in module memory that becomes invalid
> after module unload.
>
> [...]
Applied to 6.20/scsi-queue, thanks!
[1/1] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event
https://git.kernel.org/mkp/scsi/c/9672ed3de7d7
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-08 2:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-02 2:45 [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event Keita Morisaki
2026-02-02 8:14 ` Peter Wang (王信友)
2026-02-04 3:27 ` Martin K. Petersen
2026-02-04 3:31 ` Keita Morisaki
2026-02-08 2:01 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®