All of lore.kernel.org
 help / color / mirror / Atom feed
From: wangnan0@huawei.com (Wang Nan)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH v4 27/34] early kprobes on ftrace: kprobe_on_ftrace_get_old_insn()
Date: Wed, 4 Mar 2015 10:30:24 +0800	[thread overview]
Message-ID: <54F66E40.3010305@huawei.com> (raw)
In-Reply-To: <1425306312-3437-28-git-send-email-wangnan0@huawei.com>

On 2015/3/2 22:25, Wang Nan wrote:
> Newly introduced function kprobe_on_ftrace_get_old_insn() will be
> called by ftrace when ftrace generating call instruction. It is for
> retriving probed instructions which original nops are replaced by
> kprobe. FTRACE_FL_EARLY_KPROBES bit in rec->flags is cleared, so after
> calling kprobe_on_ftrace_get_old_insn() an ftrace record will not be
> treated as early kprobed.
> 
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> ---
>  include/linux/kprobes.h |  9 +++++++++
>  kernel/kprobes.c        | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index 5a5290f..2d78bbb 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -289,6 +289,8 @@ extern const unsigned char *arch_kprobe_on_ftrace_get_old_insn(struct kprobe *kp
>  
>  extern void init_kprobes_on_ftrace(void);
>  extern bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *rec);
> +extern const unsigned char *kprobe_on_ftrace_get_old_insn(struct dyn_ftrace *rec,
> +		const unsigned char *ftrace_nop, unsigned char *dest, size_t insn_size);
>  #else
>  static inline void init_kprobes_on_ftrace(void)
>  {
> @@ -299,6 +301,13 @@ static inline bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *_unused)
>  
>  	return false;
>  }
> +
> +static inline const unsigned char *
> +kprobe_on_ftrace_get_old_insn(struct dyn_ftrace *_unused,
> +		const unsigned char *ftrace_nop, unsigned char *_unused2, size_t _unused3)
> +{
> +	return ftrace_nop;
> +}
>  #endif // CONFIG_EARLY_KPROBES && CONFIG_KPROBES_ON_FTRACE
>  
>  #ifdef CONFIG_EARLY_KPROBES
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 20b6ab8..c504c1c 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2623,6 +2623,40 @@ bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *rec)
>  	return true;
>  }
>  
> +/* NOTE: caller must ensure holding kprobe_mutex */
> +const unsigned char *
> +kprobe_on_ftrace_get_old_insn(struct dyn_ftrace *rec,
> +		const unsigned char *ftrace_nop,
> +		unsigned char *dest, size_t insn_size)
> +{
> +	const unsigned char *ret;
> +	struct kprobe *kp;
> +	void *addr;
> +
> +	if (!(rec->flags & FTRACE_FL_EARLY_KPROBES))
> +		return ftrace_nop;
> +
> +	addr = (void *)rec->ip;
> +
> +	/*
> +	 * Note that get_kprobe always get the kprobe on table, for it
> +	 * KPROBE_FLAG_OPTIMIZED is reliable.
> +	 */
> +	kp = get_kprobe(addr);
> +
> +	if (!kp || !(kp->flags & KPROBE_FLAG_FTRACE_EARLY)) {
> +		mutex_unlock(&kprobe_mutex);

This mutex_unlock() is buggy. I'll fix it in next version.

> +		return ftrace_nop;
> +	}
> +
> +	ret = arch_kprobe_on_ftrace_get_old_insn(kp, ftrace_nop,
> +			dest, insn_size);
> +
> +	/* Only give one chance for kprobe to retrive old insn. */
> +	rec->flags &= ~FTRACE_FL_EARLY_KPROBES;
> +	return ret;
> +}
> +
>  void init_kprobes_on_ftrace(void)
>  {
>  	kprobes_on_ftrace_initialized = true;
> 

WARNING: multiple messages have this Message-ID (diff)
From: Wang Nan <wangnan0@huawei.com>
To: <rostedt@goodmis.org>, <masami.hiramatsu.pt@hitachi.com>,
	<mingo@elte.hu>, <linux@arm.linux.org.uk>, <tixy@linaro.org>
Cc: <lizefan@huawei.com>, <linux-kernel@vger.kernel.org>,
	<x86@kernel.org>, <linux-arm-kernel@lists.infradead.org>
Subject: Re: [RFC PATCH v4 27/34] early kprobes on ftrace: kprobe_on_ftrace_get_old_insn()
Date: Wed, 4 Mar 2015 10:30:24 +0800	[thread overview]
Message-ID: <54F66E40.3010305@huawei.com> (raw)
In-Reply-To: <1425306312-3437-28-git-send-email-wangnan0@huawei.com>

On 2015/3/2 22:25, Wang Nan wrote:
> Newly introduced function kprobe_on_ftrace_get_old_insn() will be
> called by ftrace when ftrace generating call instruction. It is for
> retriving probed instructions which original nops are replaced by
> kprobe. FTRACE_FL_EARLY_KPROBES bit in rec->flags is cleared, so after
> calling kprobe_on_ftrace_get_old_insn() an ftrace record will not be
> treated as early kprobed.
> 
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> ---
>  include/linux/kprobes.h |  9 +++++++++
>  kernel/kprobes.c        | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index 5a5290f..2d78bbb 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -289,6 +289,8 @@ extern const unsigned char *arch_kprobe_on_ftrace_get_old_insn(struct kprobe *kp
>  
>  extern void init_kprobes_on_ftrace(void);
>  extern bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *rec);
> +extern const unsigned char *kprobe_on_ftrace_get_old_insn(struct dyn_ftrace *rec,
> +		const unsigned char *ftrace_nop, unsigned char *dest, size_t insn_size);
>  #else
>  static inline void init_kprobes_on_ftrace(void)
>  {
> @@ -299,6 +301,13 @@ static inline bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *_unused)
>  
>  	return false;
>  }
> +
> +static inline const unsigned char *
> +kprobe_on_ftrace_get_old_insn(struct dyn_ftrace *_unused,
> +		const unsigned char *ftrace_nop, unsigned char *_unused2, size_t _unused3)
> +{
> +	return ftrace_nop;
> +}
>  #endif // CONFIG_EARLY_KPROBES && CONFIG_KPROBES_ON_FTRACE
>  
>  #ifdef CONFIG_EARLY_KPROBES
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 20b6ab8..c504c1c 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2623,6 +2623,40 @@ bool kprobe_fix_ftrace_make_nop(struct dyn_ftrace *rec)
>  	return true;
>  }
>  
> +/* NOTE: caller must ensure holding kprobe_mutex */
> +const unsigned char *
> +kprobe_on_ftrace_get_old_insn(struct dyn_ftrace *rec,
> +		const unsigned char *ftrace_nop,
> +		unsigned char *dest, size_t insn_size)
> +{
> +	const unsigned char *ret;
> +	struct kprobe *kp;
> +	void *addr;
> +
> +	if (!(rec->flags & FTRACE_FL_EARLY_KPROBES))
> +		return ftrace_nop;
> +
> +	addr = (void *)rec->ip;
> +
> +	/*
> +	 * Note that get_kprobe always get the kprobe on table, for it
> +	 * KPROBE_FLAG_OPTIMIZED is reliable.
> +	 */
> +	kp = get_kprobe(addr);
> +
> +	if (!kp || !(kp->flags & KPROBE_FLAG_FTRACE_EARLY)) {
> +		mutex_unlock(&kprobe_mutex);

This mutex_unlock() is buggy. I'll fix it in next version.

> +		return ftrace_nop;
> +	}
> +
> +	ret = arch_kprobe_on_ftrace_get_old_insn(kp, ftrace_nop,
> +			dest, insn_size);
> +
> +	/* Only give one chance for kprobe to retrive old insn. */
> +	rec->flags &= ~FTRACE_FL_EARLY_KPROBES;
> +	return ret;
> +}
> +
>  void init_kprobes_on_ftrace(void)
>  {
>  	kprobes_on_ftrace_initialized = true;
> 



  reply	other threads:[~2015-03-04  2:30 UTC|newest]

Thread overview: 100+ 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 ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 09/34] early kprobes: x86: " Wang Nan
2015-03-02 14:24   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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   ` Wang Nan
2015-03-02 14:24 ` [RFC PATCH v4 21/34] ftrace: sort ftrace entries earlier Wang Nan
2015-03-02 14:24   ` 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   ` Wang Nan
2015-03-02 14:25 ` [RFC PATCH v4 23/34] ftrace: notify kprobe when ftrace is initialized Wang Nan
2015-03-02 14:25   ` Wang Nan
2015-03-03 16:29   ` Petr Mladek
2015-03-03 16:29     ` Petr Mladek
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   ` 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   ` 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   ` 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-02 14:25   ` Wang Nan
2015-03-04  2:30   ` Wang Nan [this message]
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   ` 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   ` 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   ` 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   ` 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   ` 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   ` 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-02 14:25   ` 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   ` 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     ` 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     ` 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  5:09     ` Wang Nan
2015-03-03 17:06     ` Petr Mladek
2015-03-03 17:06       ` Petr Mladek
2015-03-04  2:24       ` Wang Nan
2015-03-04  2:24         ` Wang Nan
2015-03-04  3:36         ` Masami Hiramatsu
2015-03-04  3:36           ` Masami Hiramatsu
2015-03-04  4:39           ` Wang Nan
2015-03-04  4:39             ` Wang Nan
2015-03-04  5:59             ` Masami Hiramatsu
2015-03-04  5:59               ` Masami Hiramatsu
2015-03-04 11:22               ` Wang Nan
2015-03-04 11:22                 ` Wang Nan
2015-03-04 15:26                 ` Masami Hiramatsu
2015-03-04 15:26                   ` Masami Hiramatsu
2015-03-05  1:53                   ` Wang Nan
2015-03-05  1:53                     ` Wang Nan
2015-03-05  2:06                     ` 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=54F66E40.3010305@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.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 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.