From: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Yang Shi <yang.shi@linux.alibaba.com>,
mhocko@kernel.org, willy@infradead.org,
ldufour@linux.vnet.ibm.com, kirill@shutemov.name,
akpm@linux-foundation.org, peterz@infradead.org,
mingo@redhat.com, acme@kernel.org,
alexander.shishkin@linux.intel.com, jolsa@redhat.com,
namhyung@kernel.org, linux-mm@kvack.org,
Oleg Nesterov <oleg@redhat.com>,
liu.song.a23@gmail.com, ravi.bangoria@linux.ibm.com,
linux-kernel@vger.kernel.org
Subject: Re: [RFC v8 PATCH 2/5] uprobes: introduce has_uprobes helper
Date: Wed, 22 Aug 2018 08:07:18 -0700 [thread overview]
Message-ID: <20180822150718.GB52756@linux.vnet.ibm.com> (raw)
In-Reply-To: <e7147e14-bc38-03d0-90a4-5e0ca7e40050@suse.cz>
* Vlastimil Babka <vbabka@suse.cz> [2018-08-22 12:55:59]:
> On 08/15/2018 08:49 PM, Yang Shi wrote:
> > We need check if mm or vma has uprobes in the following patch to check
> > if a vma could be unmapped with holding read mmap_sem. The checks and
> > pre-conditions used by uprobe_munmap() look just suitable for this
> > purpose.
> >
> > Extracting those checks into a helper function, has_uprobes().
> >
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Jiri Olsa <jolsa@redhat.com>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Cc: Vlastimil Babka <vbabka@suse.cz>
> > Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> > ---
> > include/linux/uprobes.h | 7 +++++++
> > kernel/events/uprobes.c | 23 ++++++++++++++++-------
> > 2 files changed, 23 insertions(+), 7 deletions(-)
> >
> > diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
> > index 0a294e9..418764e 100644
> > --- a/include/linux/uprobes.h
> > +++ b/include/linux/uprobes.h
> > @@ -149,6 +149,8 @@ struct uprobes_state {
> > extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
> > extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
> > void *src, unsigned long len);
> > +extern bool has_uprobes(struct vm_area_struct *vma, unsigned long start,
> > + unsigned long end);
> > #else /* !CONFIG_UPROBES */
> > struct uprobes_state {
> > };
> > @@ -203,5 +205,10 @@ static inline void uprobe_copy_process(struct task_struct *t, unsigned long flag
> > static inline void uprobe_clear_state(struct mm_struct *mm)
> > {
> > }
> > +static inline bool has_uprobes(struct vm_area_struct *vma, unsigned long start,
> > + unsgined long end)
> > +{
> > + return false;
> > +}
> > #endif /* !CONFIG_UPROBES */
> > #endif /* _LINUX_UPROBES_H */
> > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> > index aed1ba5..568481c 100644
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -1114,22 +1114,31 @@ int uprobe_mmap(struct vm_area_struct *vma)
> > return !!n;
> > }
> >
> > -/*
> > - * Called in context of a munmap of a vma.
> > - */
> > -void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
> > +bool
> > +has_uprobes(struct vm_area_struct *vma, unsigned long start, unsigned long end)
>
> The name is not really great...
I too feel the name is not apt.
Can you make this vma_has_uprobes and convert the current
vma_has_uprobes to __vma_has_uprobes?
>
> > {
> > if (no_uprobe_events() || !valid_vma(vma, false))
> > - return;
> > + return false;
> >
> > if (!atomic_read(&vma->vm_mm->mm_users)) /* called by mmput() ? */
> > - return;
> > + return false;
> >
> > if (!test_bit(MMF_HAS_UPROBES, &vma->vm_mm->flags) ||
> > test_bit(MMF_RECALC_UPROBES, &vma->vm_mm->flags))
>
> This means that vma might have uprobes, but since RECALC is already set,
> we don't need to set it again. That's different from "has uprobes".
>
> Perhaps something like vma_needs_recalc_uprobes() ?
>
> But I also worry there might be a race where we initially return false
> because of MMF_RECALC_UPROBES, then the flag is cleared while vma's
> still have uprobes, then we downgrade mmap_sem and skip uprobe_munmap().
> Should be checked if e.g. mmap_sem and vma visibility changes protects
> this case from happening.
That is a very good observation.
One think we can probably do is pass an extra parameter to
has_uprobes(), depending on which we should skip this check.
such that when we call from uprobes_munmap(), we continue as is
but when calling from do_munmap_zap_rlock(), we skip the check.
>
> > - return;
> > + return false;
> >
> > if (vma_has_uprobes(vma, start, end))
> > + return true;
> > +
> > + return false;
>
> Simpler:
> return vma_has_uprobes(vma, start, end);
>
> > +}
> > +
> > +/*
> > + * Called in context of a munmap of a vma.
> > + */
> > +void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
> > +{
> > + if (has_uprobes(vma, start, end))
> > set_bit(MMF_RECALC_UPROBES, &vma->vm_mm->flags);
> > }
--
Thanks and Regards
Srikar Dronamraju
next prev parent reply other threads:[~2018-08-22 15:07 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-15 18:49 [RFC v8 PATCH 0/5] mm: zap pages with read mmap_sem in munmap for large mapping Yang Shi
2018-08-15 18:49 ` [RFC v8 PATCH 1/5] mm: refactor do_munmap() to extract the common part Yang Shi
2018-08-15 18:49 ` [RFC v8 PATCH 2/5] uprobes: introduce has_uprobes helper Yang Shi
2018-08-22 10:55 ` Vlastimil Babka
2018-08-22 15:07 ` Srikar Dronamraju [this message]
2018-08-22 20:51 ` Yang Shi
2018-08-23 15:15 ` Oleg Nesterov
2018-08-23 16:07 ` Yang Shi
2018-08-15 18:49 ` [RFC v8 PATCH 3/5] mm: mmap: zap pages with read mmap_sem in munmap Yang Shi
2018-08-15 19:16 ` Matthew Wilcox
2018-08-15 21:09 ` Matthew Wilcox
2018-08-15 21:54 ` Yang Shi
2018-08-16 2:46 ` Matthew Wilcox
2018-08-16 6:11 ` Yang Shi
2018-08-22 11:11 ` Vlastimil Babka
2018-08-22 19:20 ` Yang Shi
2018-08-22 11:19 ` Vlastimil Babka
2018-08-22 20:45 ` Yang Shi
2018-08-22 21:10 ` Kirill A. Shutemov
2018-08-22 21:42 ` Dave Hansen
2018-08-22 21:56 ` Yang Shi
2018-08-22 22:03 ` Dave Hansen
2018-08-15 18:49 ` [RFC v8 PATCH 4/5] mm: unmap VM_HUGETLB mappings with optimized path Yang Shi
2018-08-15 18:49 ` [RFC v8 PATCH 5/5] mm: unmap VM_PFNMAP " Yang Shi
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=20180822150718.GB52756@linux.vnet.ibm.com \
--to=srikar@linux.vnet.ibm.com \
--cc=acme@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=kirill@shutemov.name \
--cc=ldufour@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liu.song.a23@gmail.com \
--cc=mhocko@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@linux.ibm.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=yang.shi@linux.alibaba.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).