All of lore.kernel.org
 help / color / mirror / Atom feed
From: Francis Laniel <flaniel@linux.microsoft.com>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Masami Hiramatsu <mhiramat@kernel.org>,
	linux-trace-kernel@vger.kernel.org,
	Richard Henderson <richard.henderson@linaro.org>,
	Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
	Matt Turner <mattst88@gmail.com>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	Helge Deller <deller@gmx.de>,
	"David S. Miller" <davem@davemloft.net>,
	Arnd Bergmann <arnd@arndb.de>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org,
	linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org,
	linux-arch@vger.kernel.org
Subject: Re: [RFC PATCH v1 1/1] tracing/kprobes: Return ENAMESVRLSYMS when func matches several symbols
Date: Thu, 24 Aug 2023 12:39:12 +0200	[thread overview]
Message-ID: <2695869.mvXUDI8C0e@pwmachine> (raw)
In-Reply-To: <20230824085355.4fdd6215f71b0fa5f443d76d@kernel.org>

Hi.

Le jeudi 24 août 2023, 01:53:55 CEST Masami Hiramatsu a écrit :
> Hi Francis,
> 
> On Wed, 23 Aug 2023 18:14:10 +0200
> 
> Francis Laniel <flaniel@linux.microsoft.com> wrote:
> > Previously to this commit, if func matches several symbols, a PMU kprobe
> > would be installed for the first matching address.
> > This could lead to some misunderstanding when some BPF code was never
> > called because it was attached to a function which was indeed not call,
> > because the effectively called one has no kprobes.
> > 
> > So, this commit introduces ENAMESVRLSYMS which is returned when func
> > matches several symbols.
> 
> The trace_kprobe part looks good to me.
> But sorry, I mislead you. I meant using an existing error code as a
> metaphor. EINVAL is used everywhere, so choose another error code, e.g.
> EADDRNOTAVAIL.

No problem, I was a bit in doubt regarding adding a new error code, but at 
least I learnt how to do it if one day I need to do so!
But yes, for this case, better to use an existing one!

> Also, can you add this check in __trace_kprobe_create()?
> I think right before below code, at that point, 'symbol' has the symbol
> name.
> 
>         trace_probe_log_set_index(0);
>         if (event) {
>                 ret = traceprobe_parse_event_name(&event, &group, gbuf,
>                                                   event - argv[0]);
>                 if (ret)
>                         goto parse_error;
>         }

Addressed in v2, thank you!

> 
> Thank you,
> 
> > This way, user needs to use addr to remove the ambiguity.
> > 
> > Suggested-by: Masami Hiramatsu <mhiramat@kernel.org>
> > Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
> > Link:
> > https://lore.kernel.org/lkml/20230819101105.b0c104ae4494a7d1f2eea742@kern
> > el.org/ ---
> > 
> >  arch/alpha/include/uapi/asm/errno.h        |  2 ++
> >  arch/mips/include/uapi/asm/errno.h         |  2 ++
> >  arch/parisc/include/uapi/asm/errno.h       |  2 ++
> >  arch/sparc/include/uapi/asm/errno.h        |  2 ++
> >  include/uapi/asm-generic/errno.h           |  2 ++
> >  kernel/trace/trace_kprobe.c                | 26 ++++++++++++++++++++++
> >  tools/arch/alpha/include/uapi/asm/errno.h  |  2 ++
> >  tools/arch/mips/include/uapi/asm/errno.h   |  2 ++
> >  tools/arch/parisc/include/uapi/asm/errno.h |  2 ++
> >  tools/arch/sparc/include/uapi/asm/errno.h  |  2 ++
> >  tools/include/uapi/asm-generic/errno.h     |  2 ++
> >  11 files changed, 46 insertions(+)
> > 
> > diff --git a/arch/alpha/include/uapi/asm/errno.h
> > b/arch/alpha/include/uapi/asm/errno.h index 3d265f6babaf..3d9686d915f9
> > 100644
> > --- a/arch/alpha/include/uapi/asm/errno.h
> > +++ b/arch/alpha/include/uapi/asm/errno.h
> > @@ -125,4 +125,6 @@
> > 
> >  #define EHWPOISON	139	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	140	/* Name correspond to several symbols */
> > +
> > 
> >  #endif
> > 
> > diff --git a/arch/mips/include/uapi/asm/errno.h
> > b/arch/mips/include/uapi/asm/errno.h index 2fb714e2d6d8..1fd64ee7b629
> > 100644
> > --- a/arch/mips/include/uapi/asm/errno.h
> > +++ b/arch/mips/include/uapi/asm/errno.h
> > @@ -124,6 +124,8 @@
> > 
> >  #define EHWPOISON	168	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	169	/* Name correspond to several symbols */
> > +
> > 
> >  #define EDQUOT		1133	/* Quota exceeded */
> > 
> > diff --git a/arch/parisc/include/uapi/asm/errno.h
> > b/arch/parisc/include/uapi/asm/errno.h index 87245c584784..c7845ceece26
> > 100644
> > --- a/arch/parisc/include/uapi/asm/errno.h
> > +++ b/arch/parisc/include/uapi/asm/errno.h
> > @@ -124,4 +124,6 @@
> > 
> >  #define EHWPOISON	257	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	258	/* Name correspond to several symbols */
> > +
> > 
> >  #endif
> > 
> > diff --git a/arch/sparc/include/uapi/asm/errno.h
> > b/arch/sparc/include/uapi/asm/errno.h index 81a732b902ee..1ed065943bab
> > 100644
> > --- a/arch/sparc/include/uapi/asm/errno.h
> > +++ b/arch/sparc/include/uapi/asm/errno.h
> > @@ -115,4 +115,6 @@
> > 
> >  #define EHWPOISON	135	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	136	/* Name correspond to several symbols */
> > +
> > 
> >  #endif
> > 
> > diff --git a/include/uapi/asm-generic/errno.h
> > b/include/uapi/asm-generic/errno.h index cf9c51ac49f9..3d5d5740c8da
> > 100644
> > --- a/include/uapi/asm-generic/errno.h
> > +++ b/include/uapi/asm-generic/errno.h
> > @@ -120,4 +120,6 @@
> > 
> >  #define EHWPOISON	133	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	134	/* Name correspond to several symbols */
> > +
> > 
> >  #endif
> > 
> > diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> > index 23dba01831f7..53b66db1ff53 100644
> > --- a/kernel/trace/trace_kprobe.c
> > +++ b/kernel/trace/trace_kprobe.c
> > @@ -1699,6 +1699,16 @@ static int unregister_kprobe_event(struct
> > trace_kprobe *tk)> 
> >  }
> >  
> >  #ifdef CONFIG_PERF_EVENTS
> > 
> > +
> > +static int count_symbols(void *data, unsigned long unused)
> > +{
> > +	unsigned int *count = data;
> > +
> > +	(*count)++;
> > +
> > +	return 0;
> > +}
> > +
> > 
> >  /* create a trace_kprobe, but don't add it to global lists */
> >  struct trace_event_call *
> >  create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
> > 
> > @@ -1709,6 +1719,22 @@ create_local_trace_kprobe(char *func, void *addr,
> > unsigned long offs,> 
> >  	int ret;
> >  	char *event;
> > 
> > +	/*
> > +	 * If user specifies func, we check that the function name does not
> > +	 * correspond to several symbols.
> > +	 * If this is the case, we return with error code ENAMESVRLSYMS to
> > +	 * indicate the user he/she should use addr and offs rather than func 
to
> > +	 * remove the ambiguity.
> > +	 */
> > +	if (func) {
> > +		unsigned int count;
> > +
> > +		count = 0;
> > +		kallsyms_on_each_match_symbol(count_symbols, func, &count);
> > +		if (count > 1)
> > +			return ERR_PTR(-ENAMESVRLSYMS);
> > +	}
> > +
> > 
> >  	/*
> >  	
> >  	 * local trace_kprobes are not added to dyn_event, so they are never
> >  	 * searched in find_trace_kprobe(). Therefore, there is no concern of
> > 
> > diff --git a/tools/arch/alpha/include/uapi/asm/errno.h
> > b/tools/arch/alpha/include/uapi/asm/errno.h index
> > 3d265f6babaf..3d9686d915f9 100644
> > --- a/tools/arch/alpha/include/uapi/asm/errno.h
> > +++ b/tools/arch/alpha/include/uapi/asm/errno.h
> > @@ -125,4 +125,6 @@
> > 
> >  #define EHWPOISON	139	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	140	/* Name correspond to several symbols */
> > +
> > 
> >  #endif
> > 
> > diff --git a/tools/arch/mips/include/uapi/asm/errno.h
> > b/tools/arch/mips/include/uapi/asm/errno.h index
> > 2fb714e2d6d8..1fd64ee7b629 100644
> > --- a/tools/arch/mips/include/uapi/asm/errno.h
> > +++ b/tools/arch/mips/include/uapi/asm/errno.h
> > @@ -124,6 +124,8 @@
> > 
> >  #define EHWPOISON	168	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	169	/* Name correspond to several symbols */
> > +
> > 
> >  #define EDQUOT		1133	/* Quota exceeded */
> > 
> > diff --git a/tools/arch/parisc/include/uapi/asm/errno.h
> > b/tools/arch/parisc/include/uapi/asm/errno.h index
> > 87245c584784..c7845ceece26 100644
> > --- a/tools/arch/parisc/include/uapi/asm/errno.h
> > +++ b/tools/arch/parisc/include/uapi/asm/errno.h
> > @@ -124,4 +124,6 @@
> > 
> >  #define EHWPOISON	257	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	258	/* Name correspond to several symbols */
> > +
> > 
> >  #endif
> > 
> > diff --git a/tools/arch/sparc/include/uapi/asm/errno.h
> > b/tools/arch/sparc/include/uapi/asm/errno.h index
> > 81a732b902ee..1ed065943bab 100644
> > --- a/tools/arch/sparc/include/uapi/asm/errno.h
> > +++ b/tools/arch/sparc/include/uapi/asm/errno.h
> > @@ -115,4 +115,6 @@
> > 
> >  #define EHWPOISON	135	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	136	/* Name correspond to several symbols */
> > +
> > 
> >  #endif
> > 
> > diff --git a/tools/include/uapi/asm-generic/errno.h
> > b/tools/include/uapi/asm-generic/errno.h index cf9c51ac49f9..3d5d5740c8da
> > 100644
> > --- a/tools/include/uapi/asm-generic/errno.h
> > +++ b/tools/include/uapi/asm-generic/errno.h
> > @@ -120,4 +120,6 @@
> > 
> >  #define EHWPOISON	133	/* Memory page has hardware error */
> > 
> > +#define ENAMESVRLSYMS	134	/* Name correspond to several symbols */
> > +
> > 
> >  #endif
> > 
> > --
> > 2.34.1

Best regards.



      reply	other threads:[~2023-08-24 10:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23 16:14 [RFC PATCH v1 0/1] Return ENAMESVRLSYMS when func matches several symbols during PMU kprobe creation Francis Laniel
2023-08-23 16:14 ` [RFC PATCH v1 1/1] tracing/kprobes: Return ENAMESVRLSYMS when func matches several symbols Francis Laniel
2023-08-23 23:53   ` Masami Hiramatsu
2023-08-24 10:39     ` Francis Laniel [this message]

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=2695869.mvXUDI8C0e@pwmachine \
    --to=flaniel@linux.microsoft.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=deller@gmx.de \
    --cc=ink@jurassic.park.msu.ru \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mattst88@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=richard.henderson@linaro.org \
    --cc=rostedt@goodmis.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.