From: Petr Mladek <pmladek@suse.cz>
To: Wang Nan <wangnan0@huawei.com>
Cc: rostedt@goodmis.org, masami.hiramatsu.pt@hitachi.com,
mingo@elte.hu, linux@arm.linux.org.uk, tixy@linaro.org,
lizefan@huawei.com, linux-kernel@vger.kernel.org, x86@kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [RFC PATCH v4 23/34] ftrace: notify kprobe when ftrace is initialized.
Date: Tue, 3 Mar 2015 17:29:24 +0100 [thread overview]
Message-ID: <20150303162924.GF3703@dhcp128.suse.cz> (raw)
In-Reply-To: <1425306312-3437-24-git-send-email-wangnan0@huawei.com>
On Mon 2015-03-02 22:25:01, Wang Nan wrote:
> Makes ftrace calls init_kprobes_on_ftrace() when ftrace_init()
> finished. Before this call, marks kprobes on ftrace with
> 'KPROBE_FLAG_FTRACE_EARLY' instead of 'KPROBE_FLAG_FTRACE' to make
> kprobe not to kprobe treats these kprobes as ftrace kprobes.
>
> Following patches should convert such kprobes into kprobes on ftrace.
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> ---
> include/linux/kprobes.h | 11 +++++++++++
> kernel/kprobes.c | 17 ++++++++++++++++-
> kernel/trace/ftrace.c | 2 ++
> 3 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index bb2b2c6..96dc842 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -130,6 +130,8 @@ struct kprobe {
> * this flag is only for optimized_kprobe.
> */
> #define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */
> +/* probe will use ftrace, but ftrace is not ready when registering */
> +#define KPROBE_FLAG_FTRACE_EARLY 16
>
> /* Has this kprobe gone ? */
> static inline int kprobe_gone(struct kprobe *p)
> @@ -269,6 +271,14 @@ extern void show_registers(struct pt_regs *regs);
> extern void kprobes_inc_nmissed_count(struct kprobe *p);
> extern bool arch_within_kprobe_blacklist(unsigned long addr);
>
> +#if defined(CONFIG_EARLY_KPROBES) && defined(CONFIG_KPROBES_ON_FTRACE)
> +extern void init_kprobes_on_ftrace(void);
> +#else
> +static inline void init_kprobes_on_ftrace(void)
> +{
> +}
> +#endif // CONFIG_EARLY_KPROBES && CONFIG_KPROBES_ON_FTRACE
> +
> #ifdef CONFIG_EARLY_KPROBES
>
> #define NR_EARLY_KPROBES_SLOTS CONFIG_NR_EARLY_KPROBES_SLOTS
> @@ -453,6 +463,7 @@ extern int proc_kprobes_optimization_handler(struct ctl_table *table,
> extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
> struct ftrace_ops *ops, struct pt_regs *regs);
> extern int arch_prepare_kprobe_ftrace(struct kprobe *p);
> +
> #endif
>
> int arch_check_ftrace_location(struct kprobe *p);
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 4b7b20a..b5e13ba 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -69,6 +69,11 @@
>
> static int kprobes_initialized;
> static int kprobes_blacklist_initialized;
> +#if defined(CONFIG_KPROBES_ON_FTRACE) && defined(CONFIG_EARLY_KPROBES)
> +static bool kprobes_on_ftrace_initialized __read_mostly = false;
> +#else
> +# define kprobes_on_ftrace_initialized false
> +#endif
>
> bool kprobes_is_early(void)
> {
> @@ -1497,7 +1502,10 @@ int __weak arch_check_ftrace_location(struct kprobe *p)
> /* Given address is not on the instruction boundary */
> if ((unsigned long)p->addr != ftrace_addr)
> return -EILSEQ;
> - p->flags |= KPROBE_FLAG_FTRACE;
> + if (unlikely(!kprobes_on_ftrace_initialized))
> + p->flags |= KPROBE_FLAG_FTRACE_EARLY;
> + else
> + p->flags |= KPROBE_FLAG_FTRACE;
> #else /* !CONFIG_KPROBES_ON_FTRACE */
> return -EINVAL;
> #endif
> @@ -2574,3 +2582,10 @@ module_init(init_kprobes);
>
> /* defined in arch/.../kernel/kprobes.c */
> EXPORT_SYMBOL_GPL(jprobe_return);
> +
> +#if defined(CONFIG_KPROBES_ON_FTRACE) && defined(CONFIG_EARLY_KPROBES)
> +void init_kprobes_on_ftrace(void)
> +{
> + kprobes_on_ftrace_initialized = true;
This flag is later used to decide whether the location is modified by
ftrace or by kprobe, see https://lkml.org/lkml/2015/3/3/4
Therefore you need to convert the probes and set the flag atomically. By
other words, you need to set this flag at the end of
convert_early_kprobes_on_ftrace() when you still hold kprobe_mutex.
Or you need to take the mutex already in init_kprobes_on_frace()
around both changes.
Note that I check only this aspect of this patchset because it was
affected by my fix of the kprobe recovery code.
Best Regards,
Petr
> +}
> +#endif
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 7fa88d0..5cb0269 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -23,6 +23,7 @@
> #include <linux/kthread.h>
> #include <linux/uaccess.h>
> #include <linux/bsearch.h>
> +#include <linux/kprobes.h>
> #include <linux/module.h>
> #include <linux/ftrace.h>
> #include <linux/sysctl.h>
> @@ -5022,6 +5023,7 @@ void __init ftrace_init(void)
> if (ret)
> pr_warning("Failed to register trace ftrace module exit notifier\n");
>
> + init_kprobes_on_ftrace();
> set_ftrace_early_filters();
>
> return;
> --
> 1.8.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2015-03-03 16:29 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-02 14:24 [RFC PATCH v4 00/34] Early kprobe: enable kprobes at very early booting stage Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 01/34] x86, traps: Enable DEBUG_STACK after cpu_init() for TRAP_DB/BP Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 02/34] x86, traps: separate set_intr_gate() and cleanup early_trap_init() Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 03/34] x86, traps: install gates using IST after cpu_init() Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 04/34] early kprobes: within_kprobe_blacklist_early() early Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 05/34] early kprobes: introduce kprobe_is_early for futher early kprobe use Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 06/34] early kprobes: enable kprobe smoke test for early kprobes Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 07/34] early kprobes: init kprobes at very early stage Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 08/34] early kprobes: ARM: add definition for vmlinux.lds use Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 09/34] early kprobes: x86: " Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 10/34] early kprobes: introduce early kprobes related code area Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 11/34] early kprobes: introduces macros for allocing early kprobe resources Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 12/34] early kprobes: allows __alloc_insn_slot() from early kprobes slots Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 13/34] early kprobes: alloc optimized kprobe before memory system is ready Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 14/34] early kprobes: use stop_machine() based x86 optimizer Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 15/34] early kprobes: use stop_machine() based optimization method for early kprobes Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 16/34] early kprobes: perhibit probing at early kprobe reserved area Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 17/34] early kprobes: run kprobes smoke test for early kprobes Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 18/34] early kprobes: add CONFIG_EARLY_KPROBES option Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 19/34] ftrace: don't update record flags if code modification fail Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 20/34] ftrace/x86: Ensure rec->flags no change when failure occures Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 21/34] ftrace: sort ftrace entries earlier Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 22/34] ftrace: allow search ftrace addr before ftrace fully inited Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 23/34] ftrace: notify kprobe when ftrace is initialized Wang Nan
2015-03-03 16:29 ` Petr Mladek [this message]
2015-03-02 14:25 ` [RFC PATCH v4 24/34] early kprobes on ftrace: introduce x86 arch_fix_ftrace_early_kprobe() Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 25/34] ftrace: don't fire ftrace_bug if the instruction is taken by early kprobes Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 26/34] early kprobes on ftrace: x86: arch code for retrieving kprobed instruction Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 27/34] early kprobes on ftrace: kprobe_on_ftrace_get_old_insn() Wang Nan
2015-03-04 2:30 ` Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 28/34] ftrace: x86: get old instruction from early kprobes when make call Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 29/34] ftrace: x86: call kprobe_int3_handler() in ftrace int3 handler Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 30/34] early kprobes: convert early kprobes on ftrace to ftrace Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 31/34] early kprobes: enable early kprobes for x86 Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 32/34] early kprobes: enable 'ekprobe=' cmdline option for early kprobes Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 33/34] ftrace: enable make ftrace nop before ftrace_init() Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 34/34] early kprobes: enable optimization of kprobes on ftrace before ftrace is ready Wang Nan
2015-03-03 5:09 ` [PATCH 0/3] early kprobes: Fix bug in unregistering early kprobe before kprobe " Wang Nan
2015-03-03 5:09 ` [PATCH 1/3] early kprobes: make kprobes_on_ftrace_initialized public available Wang Nan
2015-03-03 5:09 ` [PATCH 2/3] ftrace/x86: don't return error if other makes a same code change Wang Nan
2015-03-03 5:09 ` [PATCH 3/3] early kprobes: x86: don't try to recover ftraced instruction before ftrace get ready Wang Nan
2015-03-03 17:06 ` Petr Mladek
2015-03-04 2:24 ` Wang Nan
2015-03-04 3:36 ` Masami Hiramatsu
2015-03-04 4:39 ` Wang Nan
2015-03-04 5:59 ` Masami Hiramatsu
2015-03-04 11:22 ` Wang Nan
2015-03-04 15:26 ` Masami Hiramatsu
2015-03-05 1:53 ` Wang Nan
2015-03-05 2:06 ` Wang Nan
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=20150303162924.GF3703@dhcp128.suse.cz \
--to=pmladek@suse.cz \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=lizefan@huawei.com \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=tixy@linaro.org \
--cc=wangnan0@huawei.com \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®