Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934630AbcHJUv0 (ORCPT ); Wed, 10 Aug 2016 16:51:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55562 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933098AbcHJSLj (ORCPT ); Wed, 10 Aug 2016 14:11:39 -0400 Date: Wed, 10 Aug 2016 17:42:54 +0200 From: Mateusz Guzik To: Robert Foss Cc: akpm@linux-foundation.org, keescook@chromium.org, viro@zeniv.linux.org.uk, gorcunov@openvz.org, john.stultz@linaro.org, plaguedbypenguins@gmail.com, sonnyrao@chromium.org, adobriyan@gmail.com, jdanis@google.com, calvinowens@fb.com, jann@thejh.net, mhocko@suse.com, koct9i@gmail.com, vbabka@suse.cz, n-horiguchi@ah.jp.nec.com, kirill.shutemov@linux.intel.com, ldufour@linux.vnet.ibm.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, Ben Zhang , Bryan Freed , Filipe Brandenburger Subject: Re: [PACTH v1] mm, proc: Implement /proc//totmaps Message-ID: <20160810154253.zcf2lmydewxifeat@mguzik> References: <1470758743-17685-1-git-send-email-robert.foss@collabora.com> <20160809162946.gznxgsgfzndinkay@mguzik> <8475f2bc-7375-08d6-9fa5-435cfbf763e8@collabora.com> <54a4277a-dbc8-0815-6fc8-d3c11d2a930c@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <54a4277a-dbc8-0815-6fc8-d3c11d2a930c@collabora.com> User-Agent: Mutt/1.6.0.1 (2016-04-01) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 10 Aug 2016 15:43:05 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 10, 2016 at 11:39:12AM -0400, Robert Foss wrote: > > > On 2016-08-09 04:17 PM, Robert Foss wrote: > > > > +static int totmaps_proc_show(struct seq_file *m, void *data) > > > > +{ > > > > + struct proc_maps_private *priv = m->private; > > > > + struct mm_struct *mm; > > > > + struct vm_area_struct *vma; > > > > + struct mem_size_stats *mss_sum = priv->mss; > > > > + > > > > + /* reference to priv->task already taken */ > > > > + /* but need to get the mm here because */ > > > > + /* task could be in the process of exiting */ > > > > + mm = get_task_mm(priv->task); > > > > + if (!mm || IS_ERR(mm)) > > > > + return -EINVAL; > > > > + > > > > > > That's not how it's done in smaps. > > > > Alright, I'll have to look into the difference between this approach and > > the smaps one. > > > I had a look at show_smaps(), and it's not entirely clear to me what the > advantage of doing it show_smaps() way. > > mm = get_task_mm(priv->task) is needed to iterate through all of the > mappings. Is there a preferable way of doing that? In the other part of the mail I stated smaps goes to proc_maps_open which has: priv->mm = proc_mem_open(inode, PTRACE_MODE_READ); This gives you stable access to mm and all needed permission checks. Then, in the read routine you can just: if (!atomic_inc_not_zero(&mm->mm_users)) goto thats_it; See smaps routines or e.g. environ_read. -- Mateusz Guzik