From: Sumit Semwal <sumit.semwal@linaro.org>
To: Colin Cross <ccross@android.com>
Cc: "Michal Hocko" <mhocko@suse.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
Linux-MM <linux-mm@kvack.org>,
lkml <linux-kernel@vger.kernel.org>,
"Alexey Dobriyan" <adobriyan@gmail.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
"Kees Cook" <keescook@chromium.org>,
"Alexey Gladkov" <gladkov.alexey@gmail.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
"Michel Lespinasse" <walken@google.com>,
"Michal Koutný" <mkoutny@suse.com>,
"Song Liu" <songliubraving@fb.com>,
"Huang Ying" <ying.huang@intel.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Yang Shi" <yang.shi@linux.alibaba.com>,
chenqiwu <chenqiwu@xiaomi.com>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"John Hubbard" <jhubbard@nvidia.com>,
"Mike Christie" <mchristi@redhat.com>,
"Bart Van Assche" <bvanassche@acm.org>,
"Amit Pundir" <amit.pundir@linaro.org>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Christian Brauner" <christian.brauner@ubuntu.com>,
"Daniel Jordan" <daniel.m.jordan@oracle.com>,
"Adrian Reber" <areber@redhat.com>,
"Nicolas Viennot" <Nicolas.Viennot@twosigma.com>,
"Al Viro" <viro@zeniv.linux.org.uk>,
"Thomas Cedeno" <thomascedeno@google.com>,
linux-fsdevel@vger.kernel.org,
"Pekka Enberg" <penberg@kernel.org>,
"Dave Hansen" <dave.hansen@intel.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@kernel.org>,
"Oleg Nesterov" <oleg@redhat.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
"Jan Glauber" <jan.glauber@gmail.com>,
"John Stultz" <john.stultz@linaro.org>,
"Rob Landley" <rob@landley.net>,
"Cyrill Gorcunov" <gorcunov@openvz.org>,
"Serge E. Hallyn" <serge.hallyn@ubuntu.com>,
"David Rientjes" <rientjes@google.com>,
"Hugh Dickins" <hughd@google.com>, "Mel Gorman" <mgorman@suse.de>,
"Robin Holt" <holt@sgi.com>, "Shaohua Li" <shli@fusionio.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Minchan Kim" <minchan@kernel.org>
Subject: Re: [PATCH v5 2/2] mm: add a field to store names for private anonymous memory
Date: Fri, 21 Aug 2020 08:51:57 +0530 [thread overview]
Message-ID: <CAO_48GFBWQXuFBDbYVsn84S120vSZD-Mbwv_iASYd9E=bj9Hrw@mail.gmail.com> (raw)
In-Reply-To: <CAMbhsRRBdt2BZp5CgkC=cDQpbsogh=0z523hfeHVFZkfLjbySw@mail.gmail.com>
Hi Colin,
On Fri, 21 Aug 2020 at 04:58, Colin Cross <ccross@android.com> wrote:
>
> On Thu, Aug 20, 2020 at 12:58 AM Michal Hocko <mhocko@suse.com> wrote:
> >
> > On Wed 19-08-20 19:46:50, Sumit Semwal wrote:
> > [...]
> > > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> > > index 5066b0251ed8..136fd3c3ad7b 100644
> > > --- a/fs/proc/task_mmu.c
> > > +++ b/fs/proc/task_mmu.c
> > > @@ -97,6 +97,21 @@ unsigned long task_statm(struct mm_struct *mm,
> > > return mm->total_vm;
> > > }
> > >
> > > +static void seq_print_vma_name(struct seq_file *m, struct vm_area_struct *vma)
> > > +{
> > > + struct mm_struct *mm = vma->vm_mm;
> > > + char anon_name[NAME_MAX + 1];
> > > + int n;
> > > +
> > > + n = access_remote_vm(mm, (unsigned long)vma_anon_name(vma),
> > > + anon_name, NAME_MAX, 0);
> > > + if (n > 0) {
> > > + seq_puts(m, "[anon:");
> > > + seq_write(m, anon_name, strnlen(anon_name, n));
> > > + seq_putc(m, ']');
> > > + }
> > > +}
> > > +
> > > #ifdef CONFIG_NUMA
> > > /*
> > > * Save get_task_policy() for show_numa_map().
> > > @@ -319,8 +334,15 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
> > > goto done;
> > > }
> > >
> > > - if (is_stack(vma))
> > > + if (is_stack(vma)) {
> > > name = "[stack]";
> > > + goto done;
> > > + }
> > > +
> > > + if (vma_anon_name(vma)) {
> > > + seq_pad(m, ' ');
> > > + seq_print_vma_name(m, vma);
> > > + }
> > > }
> >
> > How can be this safe? access_remote_vm requires mmap_sem (non exlusive).
> > The same is the case for show_map_vma. So what would happen if a task
> > sets its own name? IIRC semaphore code doesn't allow read lock nesting
> > because any exclusive lock request in the mean time would block further
> > readers. Or is this allowed?
>
> Good catch. The version of this patch that has been in use the
> Android kernel since 2015 [1] doesn't have this issue because it
> doesn't use access_remote_vm, it calls get_user_pages_remote directly.
> This would need to call a version of access_remote_vm that assumes the
> mmap_sem is already held.
Indeed. so does it sound ok to add an access_remote_vma_mmap_lockheld() version?
>
> [1] https://android.googlesource.com/kernel/common/+/60500a42286de35f00d2a195f2021bcc029f11a1%5E%21/#F1
Best,
Sumit.
next prev parent reply other threads:[~2020-08-21 3:22 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-19 14:16 [PATCH v5 0/2] Anonymous VMA naming patches Sumit Semwal
2020-08-19 14:16 ` [PATCH v5 1/2] mm: rearrange madvise code to allow for reuse Sumit Semwal
2020-08-19 14:16 ` [PATCH v5 2/2] mm: add a field to store names for private anonymous memory Sumit Semwal
2020-08-19 14:37 ` Michal Hocko
2020-08-19 15:02 ` Matthew Wilcox
2020-08-19 17:48 ` Sumit Semwal
2020-08-20 15:46 ` Oleg Nesterov
2020-08-19 17:14 ` kernel test robot
2020-08-19 17:42 ` kernel test robot
2020-08-20 7:58 ` Michal Hocko
2020-08-20 23:28 ` Colin Cross
2020-08-21 3:21 ` Sumit Semwal [this message]
2020-08-21 7:24 ` Michal Hocko
2020-08-21 7:53 ` Michal Hocko
2020-08-21 8:02 ` Sumit Semwal
2020-08-20 16:00 ` Oleg Nesterov
2020-08-20 21:15 ` Kees Cook
2020-08-21 3:15 ` Sumit Semwal
2020-08-21 3:14 ` Sumit Semwal
2020-08-20 21:40 ` Cyrill Gorcunov
2020-08-20 21:45 ` Colin Cross
2020-08-20 22:15 ` Cyrill Gorcunov
2020-08-20 23:51 ` Colin Cross
2020-08-21 7:05 ` Cyrill Gorcunov
2020-08-20 21:45 ` Dave Hansen
2020-08-20 21:59 ` Cyrill Gorcunov
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='CAO_48GFBWQXuFBDbYVsn84S120vSZD-Mbwv_iASYd9E=bj9Hrw@mail.gmail.com' \
--to=sumit.semwal@linaro.org \
--cc=Nicolas.Viennot@twosigma.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=amit.pundir@linaro.org \
--cc=areber@redhat.com \
--cc=bvanassche@acm.org \
--cc=ccross@android.com \
--cc=chenqiwu@xiaomi.com \
--cc=christian.brauner@ubuntu.com \
--cc=corbet@lwn.net \
--cc=daniel.m.jordan@oracle.com \
--cc=dave.hansen@intel.com \
--cc=ebiederm@xmission.com \
--cc=gladkov.alexey@gmail.com \
--cc=gorcunov@openvz.org \
--cc=hannes@cmpxchg.org \
--cc=holt@sgi.com \
--cc=hughd@google.com \
--cc=jan.glauber@gmail.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=john.stultz@linaro.org \
--cc=keescook@chromium.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mchehab+huawei@kernel.org \
--cc=mchristi@redhat.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=mingo@kernel.org \
--cc=mkoutny@suse.com \
--cc=oleg@redhat.com \
--cc=penberg@kernel.org \
--cc=peterz@infradead.org \
--cc=rientjes@google.com \
--cc=rob@landley.net \
--cc=serge.hallyn@ubuntu.com \
--cc=shli@fusionio.com \
--cc=songliubraving@fb.com \
--cc=tglx@linutronix.de \
--cc=thomascedeno@google.com \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=walken@google.com \
--cc=willy@infradead.org \
--cc=yang.shi@linux.alibaba.com \
--cc=ying.huang@intel.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).