All of lore.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>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/7] uprobes: introduce MMF_HAS_UPROBES
Date: Thu, 9 Aug 2012 19:02:51 +0530	[thread overview]
Message-ID: <20120809133251.GA26733@linux.vnet.ibm.com> (raw)
In-Reply-To: <20120808173747.GA13272@redhat.com>

* Oleg Nesterov <oleg@redhat.com> [2012-08-08 19:37:47]:

> Add the new MMF_HAS_UPROBES flag. It is set by install_breakpoint()
> and it is copied by dup_mmap(), uprobe_pre_sstep_notifier() checks
> it to avoid the slow path if the task was never probed. Perhaps it
> makes sense to check it in valid_vma(is_register => false) as well.
> 
> This needs the new dup_mmap()->uprobe_dup_mmap() hook. We can't use
> uprobe_reset_state() or put MMF_HAS_UPROBES into MMF_INIT_MASK, we
> need oldmm->mmap_sem to avoid the race with uprobe_register() or
> mmap() from another thread.
> 
> Currently we never clear this bit, it can be false-positive after
> uprobe_unregister() or uprobe_munmap() or if dup_mmap() hits the
> probed VM_DONTCOPY vma. But this is fine correctness-wise and has
> no effect unless the task hits the non-uprobe breakpoint.
> 

In which case, cant we just delete uprobe_munmap() altogether.

> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
>  include/linux/sched.h   |    2 ++
>  include/linux/uprobes.h |    5 +++++
>  kernel/events/uprobes.c |   22 +++++++++++++++++++++-
>  kernel/fork.c           |    1 +
>  4 files changed, 29 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index cbf3a71..c0fcfb7 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -441,6 +441,8 @@ extern int get_dumpable(struct mm_struct *mm);
>  #define MMF_VM_HUGEPAGE		17	/* set when VM_HUGEPAGE is set on vma */
>  #define MMF_EXE_FILE_CHANGED	18	/* see prctl_set_mm_exe_file() */
> 
> +#define MMF_HAS_UPROBES		19	/* might have uprobes */
> +
>  #define MMF_INIT_MASK		(MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK)
> 
>  struct sighand_struct {
> diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
> index 03ae547..4a37ab1 100644
> --- a/include/linux/uprobes.h
> +++ b/include/linux/uprobes.h
> @@ -108,6 +108,7 @@ extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_con
>  extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
>  extern int uprobe_mmap(struct vm_area_struct *vma);
>  extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end);
> +extern void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm);
>  extern void uprobe_free_utask(struct task_struct *t);
>  extern void uprobe_copy_process(struct task_struct *t);
>  extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
> @@ -138,6 +139,10 @@ static inline void
>  uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
>  {
>  }
> +static inline void
> +uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
> +{
> +}
>  static inline void uprobe_notify_resume(struct pt_regs *regs)
>  {
>  }
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 309309e..2a42319 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -649,6 +649,7 @@ static int
>  install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
>  			struct vm_area_struct *vma, unsigned long vaddr)
>  {
> +	bool first_uprobe;
>  	int ret;
> 
>  	/*
> @@ -680,7 +681,17 @@ install_breakpoint(struct uprobe *uprobe, struct mm_struct *mm,
>  		uprobe->flags |= UPROBE_COPY_INSN;
>  	}
> 
> +	/*
> +	 * set MMF_HAS_UPROBES in advance for uprobe_pre_sstep_notifier(),
> +	 * the task can hit this breakpoint right after __replace_page().
> +	 */
> +	first_uprobe = !test_bit(MMF_HAS_UPROBES, &mm->flags);
> +	if (first_uprobe)
> +		set_bit(MMF_HAS_UPROBES, &mm->flags);
> +
>  	ret = set_swbp(&uprobe->arch, mm, vaddr);
> +	if (ret && first_uprobe)
> +		clear_bit(MMF_HAS_UPROBES, &mm->flags);
> 
>  	return ret;
>  }
> @@ -1034,6 +1045,9 @@ void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned lon
>  	if (!atomic_read(&vma->vm_mm->mm_users)) /* called by mmput() ? */
>  		return;
> 
> +	if (!test_bit(MMF_HAS_UPROBES, &vma->vm_mm->flags))
> +		return;
> +

I am not sure whats the purpose of the above test 


>  	/* TODO: unmapping uprobe(s) will need more work */

and I am unable to think what more we would want to do here.

>  }
> 
> @@ -1144,6 +1158,12 @@ void uprobe_reset_state(struct mm_struct *mm)
>  	mm->uprobes_state.xol_area = NULL;
>  }
> 
> +void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
> +{
> +	if (test_bit(MMF_HAS_UPROBES, &oldmm->flags))
> +		set_bit(MMF_HAS_UPROBES, &newmm->flags);
> +}
> +
>  /*
>   *  - search for a free slot.
>   */
> @@ -1511,7 +1531,7 @@ int uprobe_pre_sstep_notifier(struct pt_regs *regs)
>  {
>  	struct uprobe_task *utask;
> 
> -	if (!current->mm)
> +	if (!current->mm || !test_bit(MMF_HAS_UPROBES, &current->mm->flags))
>  		return 0;
> 
>  	utask = current->utask;
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 0e419ab..ab970c3 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -350,6 +350,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
> 
>  	down_write(&oldmm->mmap_sem);
>  	flush_cache_dup_mm(oldmm);
> +	uprobe_dup_mmap(oldmm, mm);
>  	/*
>  	 * Not linked in yet - no deadlock potential:
>  	 */
> -- 
> 1.5.5.1
> 


  reply	other threads:[~2012-08-09 13:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-08 17:36 [PATCH 0/7] uprobes: kill uprobes_state->count, add MMF_HAS_UPROBES Oleg Nesterov
2012-08-08 17:37 ` [PATCH 1/7] uprobes: kill uprobes_state->count Oleg Nesterov
2012-08-13 13:18   ` Srikar Dronamraju
2012-08-08 17:37 ` [PATCH 2/7] uprobes: kill dup_mmap()->uprobe_mmap(), simplify uprobe_mmap/munmap Oleg Nesterov
2012-08-13 13:20   ` Srikar Dronamraju
2012-08-08 17:37 ` [PATCH 3/7] uprobes: change uprobe_mmap() to ignore the errors but check fatal_signal_pending() Oleg Nesterov
2012-08-13 13:21   ` Srikar Dronamraju
2012-08-08 17:37 ` [PATCH 4/7] uprobes: do not use -EEXIST in install_breakpoint() paths Oleg Nesterov
2012-08-13 13:21   ` Srikar Dronamraju
2012-08-08 17:37 ` [PATCH 5/7] uprobes: introduce MMF_HAS_UPROBES Oleg Nesterov
2012-08-09 13:32   ` Srikar Dronamraju [this message]
2012-08-09 14:17     ` Oleg Nesterov
2012-08-13 13:22   ` Srikar Dronamraju
2012-08-08 17:37 ` [PATCH 6/7] uprobes: fold uprobe_reset_state() into uprobe_dup_mmap() Oleg Nesterov
2012-08-13 13:23   ` Srikar Dronamraju
2012-08-08 17:37 ` [PATCH 7/7] uprobes: remove "verify" argument from set_orig_insn() Oleg Nesterov
2012-08-09 13:33   ` 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=20120809133251.GA26733@linux.vnet.ibm.com \
    --to=srikar@linux.vnet.ibm.com \
    --cc=ananth@in.ibm.com \
    --cc=anton@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=peterz@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.