public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel•org>
To: Jiri Olsa <jolsa@redhat•com>
Cc: Alexei Starovoitov <ast@kernel•org>,
	Daniel Borkmann <daniel@iogearbox•net>,
	Andrii Nakryiko <andrii@kernel•org>,
	netdev@vger•kernel.org, bpf@vger•kernel.org,
	lkml <linux-kernel@vger•kernel.org>,
	Martin KaFai Lau <kafai@fb•com>, Song Liu <songliubraving@fb•com>,
	Yonghong Song <yhs@fb•com>,
	John Fastabend <john.fastabend@gmail•com>,
	KP Singh <kpsingh@chromium•org>,
	Steven Rostedt <rostedt@goodmis•org>,
	"Naveen N . Rao" <naveen.n.rao@linux•ibm.com>,
	Anil S Keshavamurthy <anil.s.keshavamurthy@intel•com>,
	"David S . Miller" <davem@davemloft•net>
Subject: Re: [PATCH v5 2/9] fprobe: Add ftrace based probe APIs
Date: Wed, 26 Jan 2022 11:50:22 +0900	[thread overview]
Message-ID: <20220126115022.fda21a3face4e97684f5bab9@kernel.org> (raw)
In-Reply-To: <YfA9aC5quQNc89Hc@krava>

On Tue, 25 Jan 2022 19:11:52 +0100
Jiri Olsa <jolsa@redhat•com> wrote:

> On Tue, Jan 25, 2022 at 05:41:24PM +0100, Jiri Olsa wrote:
> > On Tue, Jan 25, 2022 at 09:11:57PM +0900, Masami Hiramatsu wrote:
> > 
> > SNIP
> > 
> > > +
> > > +/* Convert ftrace location address from symbols */
> > > +static int convert_func_addresses(struct fprobe *fp)
> > > +{
> > > +	unsigned long addr, size;
> > > +	unsigned int i;
> > > +
> > > +	/* Convert symbols to symbol address */
> > > +	if (fp->syms) {
> > > +		fp->addrs = kcalloc(fp->nentry, sizeof(*fp->addrs), GFP_KERNEL);
> > > +		if (!fp->addrs)
> > > +			return -ENOMEM;
> > > +
> > > +		for (i = 0; i < fp->nentry; i++) {
> > > +			fp->addrs[i] = kallsyms_lookup_name(fp->syms[i]);
> > > +			if (!fp->addrs[i])	/* Maybe wrong symbol */
> > > +				goto error;
> > > +		}
> > > +	}
> > > +
> > > +	/* Convert symbol address to ftrace location. */
> > > +	for (i = 0; i < fp->nentry; i++) {
> > > +		if (!kallsyms_lookup_size_offset(fp->addrs[i], &size, NULL))
> > > +			size = MCOUNT_INSN_SIZE;
> > > +		addr = ftrace_location_range(fp->addrs[i], fp->addrs[i] + size);
> > 
> > you need to substract 1 from 'end' in here, as explained in
> > __within_notrace_func comment:
> > 
> >         /*
> >          * Since ftrace_location_range() does inclusive range check, we need
> >          * to subtract 1 byte from the end address.
> >          */
> > 
> > like in the patch below

Good catch, I missed that point.

> > also this convert is for archs where address from kallsyms does not match
> > the real attach addresss, like for arm you mentioned earlier, right?

Yes, that's right.

> > 
> > could we have that arch specific, so we don't have extra heavy search
> > loop for archs that do not need it?

Hmm, is that so heavy? Even though, this kind of convertion is better
to be implemented in the arch-specific ftrace. They may know the
best way to do, because the offset is fixed for each arch.

> 
> one more question..
> 
> I'm adding support for user to pass function symbols to bpf fprobe link
> and I thought I'd pass symbols array to register_fprobe, but I'd need to
> copy the whole array of strings from user space first, which could take
> lot of memory considering attachment of 10k+ functions
> 
> so I'm thinking better way is to resolve symbols already in bpf fprobe
> link code and pass just addresses to register_fprobe

That is OK. Fprobe accepts either ::syms or ::addrs.

> 
> I assume you want to keep symbol interface, right? could we have some
> flag ensuring the conversion code is skipped, so we don't go through
> it twice?

Yeah, we still have many unused bits in fprobe::flags. :)

Thank you,

> in any case I need addresses before I call register_fprobe, because
> of the bpf cookies setup
> 
> thanks,
> jirka
> 


-- 
Masami Hiramatsu <mhiramat@kernel•org>

  reply	other threads:[~2022-01-26  2:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-25 12:11 [PATCH v5 0/9] fprobe: Introduce fprobe function entry/exit probe Masami Hiramatsu
2022-01-25 12:11 ` [PATCH v5 1/9] ftrace: Add ftrace_set_filter_ips function Masami Hiramatsu
2022-01-25 16:06   ` Steven Rostedt
2022-01-25 16:46     ` Jiri Olsa
2022-01-28  2:05       ` Masami Hiramatsu
2022-01-28  9:37         ` Jiri Olsa
2022-01-25 12:11 ` [PATCH v5 2/9] fprobe: Add ftrace based probe APIs Masami Hiramatsu
2022-01-25 16:21   ` Steven Rostedt
2022-01-26  9:06     ` Masami Hiramatsu
2022-01-25 16:41   ` Jiri Olsa
2022-01-25 18:11     ` Jiri Olsa
2022-01-26  2:50       ` Masami Hiramatsu [this message]
2022-01-26 15:59         ` Masami Hiramatsu
2022-01-26 18:39           ` Jiri Olsa
2022-01-25 12:12 ` [PATCH v5 3/9] rethook: Add a generic return hook Masami Hiramatsu
2022-01-25 16:46   ` Steven Rostedt
2022-01-26  0:10     ` Masami Hiramatsu
2022-01-26  5:29     ` Masami Hiramatsu
2022-01-25 12:12 ` [PATCH v5 4/9] rethook: x86: Add rethook x86 implementation Masami Hiramatsu
2022-01-25 12:12 ` [PATCH v5 5/9] ARM: rethook: Add rethook arm implementation Masami Hiramatsu
2022-01-25 12:12 ` [PATCH v5 6/9] arm64: rethook: Add arm64 rethook implementation Masami Hiramatsu
2022-01-25 12:12 ` [PATCH v5 7/9] fprobe: Add exit_handler support Masami Hiramatsu
2022-01-25 17:08   ` Steven Rostedt
2022-01-25 12:13 ` [PATCH v5 8/9] fprobe: Add sample program for fprobe Masami Hiramatsu
2022-01-25 12:13 ` [PATCH v5 9/9] docs: fprobe: Add fprobe description to ftrace-use.rst Masami Hiramatsu

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=20220126115022.fda21a3face4e97684f5bab9@kernel.org \
    --to=mhiramat@kernel$(echo .)org \
    --cc=andrii@kernel$(echo .)org \
    --cc=anil.s.keshavamurthy@intel$(echo .)com \
    --cc=ast@kernel$(echo .)org \
    --cc=bpf@vger$(echo .)kernel.org \
    --cc=daniel@iogearbox$(echo .)net \
    --cc=davem@davemloft$(echo .)net \
    --cc=john.fastabend@gmail$(echo .)com \
    --cc=jolsa@redhat$(echo .)com \
    --cc=kafai@fb$(echo .)com \
    --cc=kpsingh@chromium$(echo .)org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=naveen.n.rao@linux$(echo .)ibm.com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=rostedt@goodmis$(echo .)org \
    --cc=songliubraving@fb$(echo .)com \
    --cc=yhs@fb$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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