mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: oskar.andero@sonymobile.com
Cc: linux-kernel@vger.kernel.org, davem@davemloft.net,
	anil.s.keshavamurthy@intel.com, ananth@in.ibm.com,
	radovan.lekanovic@sonymobile.com, bjorn.davidsson@sonymobile.com,
	Toby Collett <toby.collett@sonymobile.com>,
	"yrl.pp-manager.tt@hitachi.com" <yrl.pp-manager.tt@hitachi.com>
Subject: Re: [PATCH 1/4] kprobes: delay blacklist symbol lookup until we actually need it
Date: Thu, 04 Apr 2013 15:44:10 +0900	[thread overview]
Message-ID: <515D213A.2080707@hitachi.com> (raw)
In-Reply-To: <1364977734-32267-2-git-send-email-oskar.andero@sonymobile.com>

(2013/04/03 17:28), oskar.andero@sonymobile.com wrote:
>  
> +/* it can take some time ( > 100ms ) to initialise the
> + * blacklist so we delay this until we actually need it
> + */
> +static void init_kprobe_blacklist(void)
> +{
> +	int i;
> +	unsigned long offset = 0, size = 0;
> +	char *modname, namebuf[128];
> +	const char *symbol_name;
> +	void *addr;
> +	struct kprobe_blackpoint *kb;
> +
> +	/*
> +	 * Lookup and populate the kprobe_blacklist.
> +	 *
> +	 * Unlike the kretprobe blacklist, we'll need to determine
> +	 * the range of addresses that belong to the said functions,
> +	 * since a kprobe need not necessarily be at the beginning
> +	 * of a function.
> +	 */
> +	for (kb = kprobe_blacklist; kb->name != NULL; kb++) {
> +		kprobe_lookup_name(kb->name, addr);
> +		if (!addr)
> +			continue;
> +
> +		kb->start_addr = (unsigned long)addr;
> +		symbol_name = kallsyms_lookup(kb->start_addr,
> +				&size, &offset, &modname, namebuf);
> +		if (!symbol_name)
> +			kb->range = 0;
> +		else
> +			kb->range = size;
> +	}
> +
> +	if (kretprobe_blacklist_size) {
> +		/* lookup the function address from its name */
> +		for (i = 0; kretprobe_blacklist[i].name != NULL; i++) {
> +			kprobe_lookup_name(kretprobe_blacklist[i].name,
> +					   kretprobe_blacklist[i].addr);
> +			if (!kretprobe_blacklist[i].addr)
> +				printk("kretprobe: lookup failed: %s\n",
> +				       kretprobe_blacklist[i].name);
> +		}
> +	}
> +	kprobe_blacklist_initialized = 1;
> +}
> +
>  #ifdef __ARCH_WANT_KPROBES_INSN_SLOT
>  /*
>   * kprobe->ainsn.insn points to the copy of the instruction to be
> @@ -1331,6 +1379,9 @@ static int __kprobes in_kprobes_functions(unsigned long addr)
>  	if (addr >= (unsigned long)__kprobes_text_start &&
>  	    addr < (unsigned long)__kprobes_text_end)
>  		return -EINVAL;
> +
> +	if (!kprobe_blacklist_initialized)
> +		init_kprobe_blacklist();
>  	/*
>  	 * If there exists a kprobe_blacklist, verify and
>  	 * fail any probe registration in the prohibited area
> @@ -1816,6 +1867,8 @@ int __kprobes register_kretprobe(struct kretprobe *rp)
>  	void *addr;
>  
>  	if (kretprobe_blacklist_size) {
> +		if (!kprobe_blacklist_initialized)
> +			init_kprobe_blacklist();

Joonsoo reminds me that these calling points are not protected by kprobe_mutex,
thus we have to do something for avoiding concurrent initialization.

Perhaps, the easiest way is to protect init_kprobe_blacklist() by kprobe_mutex
and check kprobe_blacklist_initialized again in the top of that.

Thank you,

-- 
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com



  reply	other threads:[~2013-04-04  6:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-03  8:28 [PATCH 0/4] kprobes: split blacklist into common and arch oskar.andero
2013-04-03  8:28 ` [PATCH 1/4] kprobes: delay blacklist symbol lookup until we actually need it oskar.andero
2013-04-04  6:44   ` Masami Hiramatsu [this message]
2013-04-04  7:57     ` Oskar Andero
2013-04-03  8:28 ` [PATCH 2/4] kprobes: split blacklist into common and arch oskar.andero
2013-04-04  6:17   ` Masami Hiramatsu
2013-04-04 11:49     ` Oskar Andero
2013-04-03  8:28 ` [PATCH 3/4] kprobes: move x86-specific blacklist symbols to arch directory oskar.andero
2013-04-03  8:28 ` [PATCH 4/4] kprobes: replace printk with pr_-functions oskar.andero
2013-04-04  6:19   ` Masami Hiramatsu
2013-04-04 11:32 ` [PATCH 0/4] kprobes: split blacklist into common and arch Vineet Gupta
2013-04-04 11:41   ` Oskar Andero

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=515D213A.2080707@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=ananth@in.ibm.com \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=bjorn.davidsson@sonymobile.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oskar.andero@sonymobile.com \
    --cc=radovan.lekanovic@sonymobile.com \
    --cc=toby.collett@sonymobile.com \
    --cc=yrl.pp-manager.tt@hitachi.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

Powered by JetHome