linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Christoph Hellwig <hch@infradead.org>,
	"Darrick J. Wong" <djwong@kernel.org>,
	linux-xfs@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	Dan Carpenter <dan.carpenter@linaro.org>,
	Julia Lawall <Julia.Lawall@inria.fr>
Subject: Re: [PATCH] xfs: fix file_path handling in tracepoints
Date: Thu, 11 Jul 2024 22:03:17 -0700	[thread overview]
Message-ID: <ZpC5FTEvLDbCije6@infradead.org> (raw)
In-Reply-To: <20240711211754.316de618@gandalf.local.home>

On Thu, Jul 11, 2024 at 09:17:54PM -0400, Steven Rostedt wrote:
> That "f->f_path.dentry" is a dereference of the passed in pointer. If we
> did that in the TP_printk(), then it would dereference that file pointer
> saved by the trace. This would happen at some time later from when the file
> pointer was saved. That is, it will dereference the pointer when the user
> reads the trace, not when the trace occurred. This could be seconds,
> minutes, hours, days even months later! So %pD would not work there.

Indeed.  I'm so used to these useful format strings that I keep
forgetting about them doing non-trivial things.

Which also brings up that it would be good if we had some kind of static
checker that detects usage of these magic %p extensions in the trace
macros and warns about them.

> 		__dynamic_array(char, pathname, snprintf(NULL, 0, "%pD", xf->file) + 1);
> 
> // This will allocated the space needed for the string
> 

> 		sprintf(__get_dynamic_array(pathname), "%pD", xf->file);
> 
> // and the above will copy it directly to that location.
> // It assumes the value of the first snprintf() will be the same as the second.
> 

> 		  (char *)__get_dynamic_array(pathname),
> 
> // for accessing the string, although yes, __get_str(pathname) would work,
> // but that's more by luck than design.

That sounds pretty cool, but except for the dynamic sizing doesn't
really buy us much over the version Darrick proposed, right?

> Looking at this file, I noticed that you have some open coded __string_len()
> fields. Why not just use that? In fact, I think I even found a bug:
> 
> There's a:
> 		memcpy(__get_str(name), name, name->len);
> 
> Where I think it should have been:
> 
> 		memcpy(__get_str(name), name->name, name->len);
> 
> Hmm, I should make sure that __string() and __string_len() are passed in
> strings. As this is a common bug.
> 
> I can make this a formal patch if you like. Although, I haven't even tried
> compile testing it ;-)

Without having compiled it either, this looks sensible to me.  As XFS
was one of the earliest adopters of event tracing I suspect these
predate the string helpers.


  reply	other threads:[~2024-07-12  5:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-11 16:01 [PATCH] xfs: fix file_path handling in tracepoints Christoph Hellwig
2024-07-12  1:17 ` Steven Rostedt
2024-07-12  5:03   ` Christoph Hellwig [this message]
2024-07-12 12:14     ` Steven Rostedt

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=ZpC5FTEvLDbCije6@infradead.org \
    --to=hch@infradead.org \
    --cc=Julia.Lawall@inria.fr \
    --cc=dan.carpenter@linaro.org \
    --cc=djwong@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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;
as well as URLs for NNTP newsgroup(s).