public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	Anton Arapov <anton@redhat.com>, Frank Eigler <fche@redhat.com>,
	Josh Stone <jistone@redhat.com>,
	"Suzuki K. Poulose" <suzuki@in.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] uprobes: Rationalize the usage of filter_chain()
Date: Thu, 3 Jan 2013 17:26:13 +0530	[thread overview]
Message-ID: <20130103115613.GD8140@linux.vnet.ibm.com> (raw)
In-Reply-To: <20121228181310.GA6138@redhat.com>

* Oleg Nesterov <oleg@redhat.com> [2012-12-28 19:13:10]:

> filter_chain() was added into install_breakpoint/remove_breakpoint to
> simplify the initial changes but this is sub-optimal.
> 
> This patch shifts the callsite to the callers, register_for_each_vma()
> and uprobe_mmap(). This way:
> 
> - It will be easier to add the new arguments. This is the main reason,
>   we can do more optimizations later.
> 
> - register_for_each_vma(is_register => true) can be optimized, we only
>   need to consult the new consumer. The previous consumers were already
>   asked when they called uprobe_register().
> 
> This patch also moves the MMF_HAS_UPROBES check from remove_breakpoint(),
> this allows to avoid the potentionally costly filter_chain(). Note that
> register_for_each_vma(is_register => false) doesn't really need to take
> >consumer_rwsem, but I don't think it makes sense to optimize this and
> introduce filter_chain_lockless().
> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>

> ---
>  kernel/events/uprobes.c |   44 +++++++++++++++++++++-----------------------
>  1 files changed, 21 insertions(+), 23 deletions(-)
> 
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 105ac0d..60b0a90 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -579,6 +579,11 @@ static int prepare_uprobe(struct uprobe *uprobe, struct file *file,
>  	return ret;
>  }
> 
> +static inline bool consumer_filter(struct uprobe_consumer *uc)
> +{
> +	return true; /* TODO: !uc->filter || uc->filter(...) */
> +}
> +
>  static bool filter_chain(struct uprobe *uprobe)
>  {
>  	struct uprobe_consumer *uc;
> @@ -586,8 +591,7 @@ static bool filter_chain(struct uprobe *uprobe)
> 
>  	down_read(&uprobe->consumer_rwsem);
>  	for (uc = uprobe->consumers; uc; uc = uc->next) {
> -		/* TODO: ret = uc->filter(...) */
> -		ret = true;
> +		ret = consumer_filter(uc);
>  		if (ret)
>  			break;
>  	}
> @@ -603,15 +607,6 @@ install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
>  	bool first_uprobe;
>  	int ret;
> 
> -	/*
> -	 * If probe is being deleted, unregister thread could be done with
> -	 * the vma-rmap-walk through. Adding a probe now can be fatal since
> -	 * nobody will be able to cleanup. But in this case filter_chain()
> -	 * must return false, all consumers have gone away.
> -	 */
> -	if (!filter_chain(uprobe))
> -		return 0;
> -
>  	ret = prepare_uprobe(uprobe, vma->vm_file, mm, vaddr);
>  	if (ret)
>  		return ret;
> @@ -636,12 +631,6 @@ install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
>  static int
>  remove_breakpoint(struct uprobe *uprobe, struct mm_struct *mm, unsigned long vaddr)
>  {
> -	if (!test_bit(MMF_HAS_UPROBES, &mm->flags))
> -		return 0;
> -
> -	if (filter_chain(uprobe))
> -		return 0;
> -
>  	set_bit(MMF_RECALC_UPROBES, &mm->flags);
>  	return set_orig_insn(&uprobe->arch, mm, vaddr);
>  }
> @@ -781,10 +770,14 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
>  		    vaddr_to_offset(vma, info->vaddr) != uprobe->offset)
>  			goto unlock;
> 
> -		if (is_register)
> -			err = install_breakpoint(uprobe, mm, vma, info->vaddr);
> -		else
> -			err |= remove_breakpoint(uprobe, mm, info->vaddr);
> +		if (is_register) {
> +			/* consult only the "caller", new consumer. */
> +			if (consumer_filter(uprobe->consumers))
> +				err = install_breakpoint(uprobe, mm, vma, info->vaddr);
> +		} else if (test_bit(MMF_HAS_UPROBES, &mm->flags)) {
> +			if (!filter_chain(uprobe))
> +				err |= remove_breakpoint(uprobe, mm, info->vaddr);
> +		}
> 
>   unlock:
>  		up_write(&mm->mmap_sem);
> @@ -968,9 +961,14 @@ int uprobe_mmap(struct vm_area_struct *vma)
> 
>  	mutex_lock(uprobes_mmap_hash(inode));
>  	build_probe_list(inode, vma, vma->vm_start, vma->vm_end, &tmp_list);
> -
> +	/*
> +	 * We can race with uprobe_unregister(), this uprobe can be already
> +	 * removed. But in this case filter_chain() must return false, all
> +	 * consumers have gone away.
> +	 */
>  	list_for_each_entry_safe(uprobe, u, &tmp_list, pending_list) {
> -		if (!fatal_signal_pending(current)) {
> +		if (!fatal_signal_pending(current) &&
> +		    filter_chain(uprobe)) {
>  			unsigned long vaddr = offset_to_vaddr(vma, uprobe->offset);
>  			install_breakpoint(uprobe, vma->vm_mm, vma, vaddr);
>  		}
> -- 
> 1.5.5.1
> 


  reply	other threads:[~2013-01-03 11:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-28 18:12 [PATCH 0/2] uprobes: pre-filtering Oleg Nesterov
2012-12-28 18:13 ` [PATCH 1/2] uprobes: Rationalize the usage of filter_chain() Oleg Nesterov
2013-01-03 11:56   ` Srikar Dronamraju [this message]
2012-12-28 18:13 ` [PATCH 2/2] uprobes: Reintroduce uprobe_consumer->filter() Oleg Nesterov
2013-01-03 11:56   ` Srikar Dronamraju

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=20130103115613.GD8140@linux.vnet.ibm.com \
    --to=srikar@linux.vnet.ibm.com \
    --cc=ananth@in.ibm.com \
    --cc=anton@redhat.com \
    --cc=fche@redhat.com \
    --cc=jistone@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=suzuki@in.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