linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
	Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/5] powerpc: introduce a new helper to obtain function entry points
Date: Thu, 13 Apr 2017 13:32:21 +0900	[thread overview]
Message-ID: <20170413133221.a11fafe3f1f776517cce9663@kernel.org> (raw)
In-Reply-To: <0f8685ca8b0d0b467a0d5ae60e666558d85062ed.1491991939.git.naveen.n.rao@linux.vnet.ibm.com>

On Wed, 12 Apr 2017 16:28:26 +0530
"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote:

> kprobe_lookup_name() is specific to the kprobe subsystem and may not
> always return the function entry point (in a subsequent patch for
> KPROBES_ON_FTRACE).

If so, please move this patch into that series. It is hard to review
patches which requires for other series.

Thank you,

> For looking up function entry points, introduce a
> separate helper and use the same in optprobes.c
> 
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> ---
>  arch/powerpc/include/asm/code-patching.h | 37 ++++++++++++++++++++++++++++++++
>  arch/powerpc/kernel/optprobes.c          |  6 +++---
>  2 files changed, 40 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/include/asm/code-patching.h
> index 8ab937771068..3e994f404434 100644
> --- a/arch/powerpc/include/asm/code-patching.h
> +++ b/arch/powerpc/include/asm/code-patching.h
> @@ -12,6 +12,8 @@
>  
>  #include <asm/types.h>
>  #include <asm/ppc-opcode.h>
> +#include <linux/string.h>
> +#include <linux/kallsyms.h>
>  
>  /* Flags for create_branch:
>   * "b"   == create_branch(addr, target, 0);
> @@ -99,6 +101,41 @@ static inline unsigned long ppc_global_function_entry(void *func)
>  #endif
>  }
>  
> +/*
> + * Wrapper around kallsyms_lookup() to return function entry address:
> + * - For ABIv1, we lookup the dot variant.
> + * - For ABIv2, we return the local entry point.
> + */
> +static inline unsigned long ppc_kallsyms_lookup_name(const char *name)
> +{
> +	unsigned long addr;
> +#ifdef PPC64_ELF_ABI_v1
> +	/* check for dot variant */
> +	char dot_name[1 + KSYM_NAME_LEN];
> +	bool dot_appended = false;
> +	if (name[0] != '.') {
> +		dot_name[0] = '.';
> +		dot_name[1] = '\0';
> +		strncat(dot_name, name, KSYM_NAME_LEN - 2);
> +		dot_appended = true;
> +	} else {
> +		dot_name[0] = '\0';
> +		strncat(dot_name, name, KSYM_NAME_LEN - 1);
> +	}
> +	addr = kallsyms_lookup_name(dot_name);
> +	if (!addr && dot_appended)
> +		/* Let's try the original non-dot symbol lookup	*/
> +		addr = kallsyms_lookup_name(name);
> +#elif defined(PPC64_ELF_ABI_v2)
> +	addr = kallsyms_lookup_name(name);
> +	if (addr)
> +		addr = ppc_function_entry((void *)addr);
> +#else
> +	addr = kallsyms_lookup_name(name);
> +#endif
> +	return addr;
> +}
> +
>  #ifdef CONFIG_PPC64
>  /*
>   * Some instruction encodings commonly used in dynamic ftracing
> diff --git a/arch/powerpc/kernel/optprobes.c b/arch/powerpc/kernel/optprobes.c
> index ce81a322251c..ec60ed0d4aad 100644
> --- a/arch/powerpc/kernel/optprobes.c
> +++ b/arch/powerpc/kernel/optprobes.c
> @@ -243,10 +243,10 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *p)
>  	/*
>  	 * 2. branch to optimized_callback() and emulate_step()
>  	 */
> -	op_callback_addr = kprobe_lookup_name("optimized_callback", 0);
> -	emulate_step_addr = kprobe_lookup_name("emulate_step", 0);
> +	op_callback_addr = (kprobe_opcode_t *)ppc_kallsyms_lookup_name("optimized_callback");
> +	emulate_step_addr = (kprobe_opcode_t *)ppc_kallsyms_lookup_name("emulate_step");
>  	if (!op_callback_addr || !emulate_step_addr) {
> -		WARN(1, "kprobe_lookup_name() failed\n");
> +		WARN(1, "Unable to lookup optimized_callback()/emulate_step()\n");
>  		goto error;
>  	}
>  
> -- 
> 2.12.1
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2017-04-13  4:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-12 10:58 [PATCH v2 0/5] powerpc: a few kprobe fixes and refactoring Naveen N. Rao
2017-04-12 10:58 ` [PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function Naveen N. Rao
2017-04-13  3:09   ` Masami Hiramatsu
2017-04-18 12:52   ` David Laight
2017-04-19  8:08     ` Naveen N. Rao
2017-04-19  8:48       ` David Laight
2017-04-19 11:07         ` 'Naveen N. Rao'
2017-04-12 10:58 ` [PATCH v2 2/5] powerpc: kprobes: fix handling of function offsets on ABIv2 Naveen N. Rao
2017-04-13  4:28   ` Masami Hiramatsu
2017-04-12 10:58 ` [PATCH v2 3/5] powerpc: introduce a new helper to obtain function entry points Naveen N. Rao
2017-04-13  4:32   ` Masami Hiramatsu [this message]
2017-04-13  5:52     ` Naveen N. Rao
2017-04-12 10:58 ` [PATCH v2 4/5] powerpc: kprobes: factor out code to emulate instruction into a helper Naveen N. Rao
2017-04-13  4:34   ` Masami Hiramatsu
2017-04-13  5:53     ` Naveen N. Rao
2017-04-13  8:50     ` Naveen N. Rao
2017-04-12 10:58 ` [PATCH v2 5/5] powerpc: kprobes: emulate instructions on kprobe handler re-entry Naveen N. Rao
2017-04-13  4:37   ` Masami Hiramatsu
2017-04-13  5:53     ` Naveen N. Rao
2017-04-13  3:02 ` [PATCH v2 0/5] powerpc: a few kprobe fixes and refactoring Masami Hiramatsu
2017-04-13  5:50   ` Naveen N. Rao

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=20170413133221.a11fafe3f1f776517cce9663@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mingo@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=naveen.n.rao@linux.vnet.ibm.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;
as well as URLs for NNTP newsgroup(s).