From: Steven Rostedt <rostedt@goodmis.org>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, 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>,
"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 7/9] fprobe: Add exit_handler support
Date: Tue, 25 Jan 2022 12:08:04 -0500 [thread overview]
Message-ID: <20220125120804.595afd8b@gandalf.local.home> (raw)
In-Reply-To: <164311277634.1933078.2632008023256564980.stgit@devnote2>
On Tue, 25 Jan 2022 21:12:56 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:
> Add exit_handler to fprobe. fprobe + rethook allows us
> to hook the kernel function return without fgraph tracer.
> Eventually, the fgraph tracer will be generic array based
> return hooking and fprobe may use it if user requests.
> Since both array-based approach and list-based approach
> have Pros and Cons, (e.g. memory consumption v.s. less
> missing events) it is better to keep both but fprobe
> will provide the same exit-handler interface.
Again the 55 character width ;-)
>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
> Changes in v5:
> - Add dependency for HAVE_RETHOOK.
> Changes in v4:
> - Check fprobe is disabled in the exit handler.
> Changes in v3:
> - Make sure to clear rethook->data before free.
> - Handler checks the data is not NULL.
> - Free rethook only if the rethook is using.
> ---
> @@ -82,6 +117,7 @@ static int convert_func_addresses(struct fprobe *fp)
> */
> int register_fprobe(struct fprobe *fp)
> {
> + unsigned int i, size;
> int ret;
>
> if (!fp || !fp->nentry || (!fp->syms && !fp->addrs) ||
> @@ -96,10 +132,29 @@ int register_fprobe(struct fprobe *fp)
> fp->ops.func = fprobe_handler;
> fp->ops.flags = FTRACE_OPS_FL_SAVE_REGS;
>
> + /* Initialize rethook if needed */
> + if (fp->exit_handler) {
> + size = fp->nentry * num_possible_cpus() * 2;
> + fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler);
Shouldn't we check if fp->rethook succeeded to be allocated?
> + for (i = 0; i < size; i++) {
> + struct rethook_node *node;
> +
> + node = kzalloc(sizeof(struct fprobe_rethook_node), GFP_KERNEL);
> + if (!node) {
> + rethook_free(fp->rethook);
> + ret = -ENOMEM;
> + goto out;
> + }
> + rethook_add_node(fp->rethook, node);
> + }
> + } else
> + fp->rethook = NULL;
> +
> ret = ftrace_set_filter_ips(&fp->ops, fp->addrs, fp->nentry, 0, 0);
> if (!ret)
> ret = register_ftrace_function(&fp->ops);
>
> +out:
> if (ret < 0 && fp->syms) {
> kfree(fp->addrs);
> fp->addrs = NULL;
> @@ -125,8 +180,16 @@ int unregister_fprobe(struct fprobe *fp)
> return -EINVAL;
>
> ret = unregister_ftrace_function(&fp->ops);
> + if (ret < 0)
> + return ret;
If we fail to unregister the fp->ops, we do not free the allocated nodes
above?
-- Steve
>
> - if (!ret && fp->syms) {
> + if (fp->rethook) {
> + /* Make sure to clear rethook->data before freeing. */
> + WRITE_ONCE(fp->rethook->data, NULL);
> + barrier();
> + rethook_free(fp->rethook);
> + }
> + if (fp->syms) {
> kfree(fp->addrs);
> fp->addrs = NULL;
> }
next prev parent reply other threads:[~2022-01-25 17:10 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
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 [this message]
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=20220125120804.595afd8b@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=andrii@kernel.org \
--cc=anil.s.keshavamurthy@intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=john.fastabend@gmail.com \
--cc=jolsa@redhat.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=naveen.n.rao@linux.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.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®