From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Ye Bin <yebin10@huawei.com>
Cc: <rostedt@goodmis.org>, <mathieu.desnoyers@efficios.com>,
<linux-trace-kernel@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] tracing/probes: support '%pd' type for print struct dentry's name
Date: Fri, 19 Jan 2024 23:57:06 +0900 [thread overview]
Message-ID: <20240119235706.65ff7f6c9a7a6ad8a79934af@kernel.org> (raw)
In-Reply-To: <20240119013848.3111364-2-yebin10@huawei.com>
On Fri, 19 Jan 2024 09:38:46 +0800
Ye Bin <yebin10@huawei.com> wrote:
> Similar to '%pd' for printk, use 'pd' for print struct dentry's name.
No, please use '%pd' as a type instead.
>
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> ---
> kernel/trace/trace_probe.c | 38 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index 4dc74d73fc1d..460f98b85b1c 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -11,6 +11,7 @@
> */
> #define pr_fmt(fmt) "trace_probe: " fmt
>
> +#include <linux/dcache.h>
> #include <linux/bpf.h>
> #include "trace_btf.h"
>
> @@ -86,6 +87,8 @@ static const struct fetch_type probe_fetch_types[] = {
> "__data_loc char[]"),
> __ASSIGN_FETCH_TYPE("symstr", string, string, sizeof(u32), 1, 1,
> "__data_loc char[]"),
> + __ASSIGN_FETCH_TYPE("pd", string, string, sizeof(u32), 1, 1,
> + "__data_loc char[]"),
And you don't need to add a new type.
Similar to the preprocessor macro, this should be done before parsing the
args. See traceprobe_expand_meta_args(), you can scan the args and search
argument end with ':%pd'. If you find that, you can replace it with
"+0x%lx(%s):string". Then, you don't need any of these complex fetch type.
Thank you,
> /* Basic types */
> ASSIGN_FETCH_TYPE(u8, u8, 0),
> ASSIGN_FETCH_TYPE(u16, u16, 0),
> @@ -1090,6 +1093,25 @@ static int __parse_bitfield_probe_arg(const char *bf,
> return (BYTES_TO_BITS(t->size) < (bw + bo)) ? -EINVAL : 0;
> }
>
> +static char* traceprobe_expand_dentry(const char *argv)
> +{
> + #define DENTRY_EXPAND_LEN 7 /* +0xXX() */
> + char *new_argv;
> + int len = strlen(argv) + 1 + DENTRY_EXPAND_LEN;
> +
> + new_argv = kmalloc(len, GFP_KERNEL);
> + if (!new_argv)
> + return NULL;
> +
> + if (snprintf(new_argv, len, "+0x%lx(%s)",
> + offsetof(struct dentry, d_name.name), argv) >= len) {
> + kfree(new_argv);
> + return NULL;
> + }
> +
> + return new_argv;
> +}
> +
> /* String length checking wrapper */
> static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
> struct probe_arg *parg,
> @@ -1099,6 +1121,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
> char *t, *t2, *t3;
> int ret, len;
> char *arg;
> + char *org_arg = NULL;
>
> arg = kstrdup(argv, GFP_KERNEL);
> if (!arg)
> @@ -1182,6 +1205,16 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
> parg->count);
> }
>
> + if (!strcmp("pd", parg->type->name)) {
> + char *temp;
> +
> + temp = traceprobe_expand_dentry(arg);
> + if (!temp)
> + goto out;
> + org_arg = arg;
> + arg = temp;
> + }
> +
> code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL);
> if (!code)
> goto out;
> @@ -1243,6 +1276,10 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
> goto fail;
> }
> }
> +
> + if (!strcmp(parg->type->name, "pd"))
> + code++;
> +
> /* If op == DEREF, replace it with STRING */
> if (!strcmp(parg->type->name, "ustring") ||
> code->op == FETCH_OP_UDEREF)
> @@ -1321,6 +1358,7 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
> kfree(tmp);
> out:
> kfree(arg);
> + kfree(org_arg);
>
> return ret;
> }
> --
> 2.31.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2024-01-19 14:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-19 1:38 [PATCH 0/3] support '%pd' and '%pD' for print file name Ye Bin
2024-01-19 1:38 ` [PATCH 1/3] tracing/probes: support '%pd' type for print struct dentry's name Ye Bin
2024-01-19 14:57 ` Masami Hiramatsu [this message]
2024-01-20 0:59 ` kernel test robot
2024-01-20 6:27 ` kernel test robot
2024-01-19 1:38 ` [PATCH 2/3] tracing/probes: support '%pD' type for print struct file's name Ye Bin
2024-01-19 1:38 ` [PATCH 3/3] Documentation: tracing: add new type 'pd' and 'pD' for kprobe Ye Bin
2024-01-19 14:43 ` [PATCH 0/3] support '%pd' and '%pD' for print file name Masami Hiramatsu
2024-01-19 15:52 ` Steven Rostedt
2024-01-20 7:15 ` Masami Hiramatsu
2024-01-20 6:26 ` yebin (H)
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=20240119235706.65ff7f6c9a7a6ad8a79934af@kernel.org \
--to=mhiramat@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.org \
--cc=yebin10@huawei.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;
as well as URLs for NNTP newsgroup(s).