From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3D17C433E1 for ; Fri, 21 Aug 2020 03:22:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6571C20738 for ; Fri, 21 Aug 2020 03:22:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Xzv+mLkk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6571C20738 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E3A7A8D0006; Thu, 20 Aug 2020 23:22:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE8768D0005; Thu, 20 Aug 2020 23:22:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAFEE8D0006; Thu, 20 Aug 2020 23:22:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id B28FC8D0005 for ; Thu, 20 Aug 2020 23:22:14 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 76C7E3634 for ; Fri, 21 Aug 2020 03:22:14 +0000 (UTC) X-FDA: 77173127388.14.mint68_3414e6227036 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 4CEC318229835 for ; Fri, 21 Aug 2020 03:22:14 +0000 (UTC) X-HE-Tag: mint68_3414e6227036 X-Filterd-Recvd-Size: 7264 Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 03:22:13 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id i19so223048lfj.8 for ; Thu, 20 Aug 2020 20:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5Q0VMxbfZlQfHI7FClENRr1rqpXQUnCZxjVxJHAkdOI=; b=Xzv+mLkk12VpjE83ky9aIwLo9RVMOrUH0WgXfyXkMmiH8GzTCnuUPpe64FDXVL/A5/ Um7oL4sVn9xUEdeq3mgKnKLQF0KTbDLfGhj7D236Rw0mFFvoFe5JEuyGzioyB5YFXqYt 4+S+gu5wQyIvb2V6AcUB7Nph7ZIvMYHy0PKq/0v8m/OXsXu908Y4cm0FWKbbhPzvO2UJ OLwX0vgeZK29knqswyPC5O3WZrNqJdGgRAyZTqxsBvpwam/F8Rp6XY8AjmrVFKs5M8y6 r5yo86oy46CmvxdGB3Jn0hexpRy//nSV0saX/ki7aVFu1GvqQ+W1LTYzMNGJ3UhOQCjh 829Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5Q0VMxbfZlQfHI7FClENRr1rqpXQUnCZxjVxJHAkdOI=; b=FXgo9DsEYJGDWc50MQP8GUQhFEU8KEzKllZxv7XW0kZvip8SzOIjMMjGvthKUyKSha oF5BzB5bwVfvaJZa2brj4BnuwKdPBsM96VLi/UjKY8vy8hN6rmvUGauKfxLkkGP0D13S ncxDQXBeAFw532cQ0UXBy5A0ZYK2FW0a83iSxCzuEptWHuw8eIumgPzIM6ButjcpMmrW dFSjsS52XA65gxktPgvmmf5au1RJsgzIKSmC3mPglbaWtPDDJBbDUfyEeJOLiOmj6ErH WAstiABtkD1TTfLhFa9ZEKRH9sTkcuEqKyzwIf0tj3zlVjxCk9azPaBaOqaD2pc56CZ9 2xWg== X-Gm-Message-State: AOAM53301PxyWbOGU1UJHP168rGjl8ttqa/gwXpuuaDLk+okHm+KYZ9Y s5sAAwMbXVd20MSD9pc2oJhh58CJIDyB0TgkCjGJjQ== X-Google-Smtp-Source: ABdhPJzhYh65YRBMCGHIXMfrdbtcXJrND+Em2jRR9HoI9/7ia3cvVlnO8dAFjuQ0wNp+DpeLPneV7WBppUIp6KiRXWQ= X-Received: by 2002:ac2:5979:: with SMTP id h25mr305887lfp.168.1597980132120; Thu, 20 Aug 2020 20:22:12 -0700 (PDT) MIME-Version: 1.0 References: <20200819141650.7462-1-sumit.semwal@linaro.org> <20200819141650.7462-3-sumit.semwal@linaro.org> <20200820075846.GA5033@dhcp22.suse.cz> In-Reply-To: From: Sumit Semwal Date: Fri, 21 Aug 2020 08:51:57 +0530 Message-ID: Subject: Re: [PATCH v5 2/2] mm: add a field to store names for private anonymous memory To: Colin Cross Cc: Michal Hocko , Andrew Morton , Linux-MM , lkml , Alexey Dobriyan , Jonathan Corbet , Mauro Carvalho Chehab , Kees Cook , Alexey Gladkov , Matthew Wilcox , Jason Gunthorpe , "Kirill A . Shutemov" , Michel Lespinasse , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Song Liu , Huang Ying , Vlastimil Babka , Yang Shi , chenqiwu , Mathieu Desnoyers , John Hubbard , Mike Christie , Bart Van Assche , Amit Pundir , Thomas Gleixner , Christian Brauner , Daniel Jordan , Adrian Reber , Nicolas Viennot , Al Viro , Thomas Cedeno , linux-fsdevel@vger.kernel.org, Pekka Enberg , Dave Hansen , Peter Zijlstra , Ingo Molnar , Oleg Nesterov , "Eric W. Biederman" , Jan Glauber , John Stultz , Rob Landley , Cyrill Gorcunov , "Serge E. Hallyn" , David Rientjes , Hugh Dickins , Mel Gorman , Robin Holt , Shaohua Li , Johannes Weiner , Minchan Kim Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4CEC318229835 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Colin, On Fri, 21 Aug 2020 at 04:58, Colin Cross wrote: > > On Thu, Aug 20, 2020 at 12:58 AM Michal Hocko 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.