mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Peter Wang (王信友)" <peter.wang@mediatek.com>
To: "keita.morisaki@tier4.jp" <keita.morisaki@tier4.jp>,
	"Chaotian Jing (井朝天)" <Chaotian.Jing@mediatek.com>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"chu.stanley@gmail.com" <chu.stanley@gmail.com>,
	"James.Bottomley@HansenPartnership.com"
	<James.Bottomley@HansenPartnership.com>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] scsi: ufs: mediatek: Fix page faults in ufs_mtk_clk_scale trace event
Date: Mon, 2 Feb 2026 08:14:57 +0000	[thread overview]
Message-ID: <e02c66306c10dad50cee0cdf886948d8d448f0ca.camel@mediatek.com> (raw)
In-Reply-To: <20260202024526.122515-1-keita.morisaki@tier4.jp>

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>


  reply	other threads:[~2026-02-02  8:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-02  2:45 Keita Morisaki
2026-02-02  8:14 ` Peter Wang (王信友) [this message]
2026-02-04  3:27 ` Martin K. Petersen
2026-02-04  3:31   ` Keita Morisaki
2026-02-08  2:01 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e02c66306c10dad50cee0cdf886948d8d448f0ca.camel@mediatek.com \
    --to=peter.wang@mediatek.com \
    --cc=Chaotian.Jing@mediatek.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=chu.stanley@gmail.com \
    --cc=keita.morisaki@tier4.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®