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,DKIMWL_WL_HIGH, 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 3B0B1C433E3 for ; Thu, 20 Aug 2020 23:28:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CBFE2207DE for ; Thu, 20 Aug 2020 23:28:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=android.com header.i=@android.com header.b="J9h9TRFg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBFE2207DE Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=android.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 405628D0003; Thu, 20 Aug 2020 19:28:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 38F7B8D0001; Thu, 20 Aug 2020 19:28:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 22F7D8D0003; Thu, 20 Aug 2020 19:28:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id 07AD08D0001 for ; Thu, 20 Aug 2020 19:28:23 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7647A181AEF07 for ; Thu, 20 Aug 2020 23:28:22 +0000 (UTC) X-FDA: 77172538044.16.curve12_4611d9727034 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 47F84100E6903 for ; Thu, 20 Aug 2020 23:28:22 +0000 (UTC) X-HE-Tag: curve12_4611d9727034 X-Filterd-Recvd-Size: 7015 Received: from mail-vs1-f65.google.com (mail-vs1-f65.google.com [209.85.217.65]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Aug 2020 23:28:21 +0000 (UTC) Received: by mail-vs1-f65.google.com with SMTP id v138so1046821vsv.7 for ; Thu, 20 Aug 2020 16:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=besgYgO83xKU8LYxmFaS/RVPIK0hF0qjdpJtokV2B1M=; b=J9h9TRFg9YT+1qV5MJUiFpfCZxzrPmoifchN8ipubI/DK0N6Xa34zi1fV8rye3M6IZ q3xcl0DWK2g5+Da+JLVcaFwRmP4QoJTj1UM23Sh7hkyQ5aBOtsn9TdYGva2MouT50BVG qsGIBUtlsh58pbo796NllsjkKlO/u+65ZcIM9Sqdz1xA/Qkh+uaToCgLAlnT6Kq9gShO RTT+HrBDkpipJMlyd5dPFx0h5kxr27YDeHE8hcO+2B4XR6ftCPlaSschqeTGplNO7VD1 Nv3Pz2IFFGB2Ab6EY1FwwSTYrwm5YcjhWIJhrAlYsyb/pGGJWJASlhx4YVt0FlpGIW00 gRVg== 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=besgYgO83xKU8LYxmFaS/RVPIK0hF0qjdpJtokV2B1M=; b=PwH5HV8Y+mfbDuHeDUpyah+BIZ2vdSKs52Lo5aQ6kG2zsJNrnuhCLo1j20olt+2M1F uNI3lwyJgfmo8W0TCLzsvEZzgnM/W9YDijTsvoBM7JmHOmpFHEidc2WbuXHddMdfbdAJ psswTSsj8S3JefOezty6PYfbh1kYZB6rO71C712Tl6h+tcLPtMhGB0/Kt60O7CtfFlCJ u975l6tY+MYbL0t7qiEucMgD5+TDxoieUQg8WftBky7BHm9BsiKIfCnck8Dfamv5PMYK AwZW9eWbeuO+Jz2WJT2F3EwHXlEPXIHuBmPqxQJGBc9DYS4oU+xzHspBs5JrD/LEZ2V7 fugQ== X-Gm-Message-State: AOAM530vryaJii3PePH+plHdhqjNaQThLxXqdnel3KCqJB/m9aHoiwI1 la4NkLHzwaW2Gd11ypDxGMfx7IdTfVvFit1zLi3BVA== X-Google-Smtp-Source: ABdhPJxxRasQWuOtwuiyjSS3KHuqVLhhvJoj/g94ccC2LbME716nYU4f17KiqyDmFIwGFLJiMT42HrsaGXiJJ5+F9TQ= X-Received: by 2002:a67:f787:: with SMTP id j7mr253008vso.79.1597966100853; Thu, 20 Aug 2020 16:28:20 -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: <20200820075846.GA5033@dhcp22.suse.cz> From: Colin Cross Date: Thu, 20 Aug 2020 16:28:09 -0700 Message-ID: Subject: Re: [PATCH v5 2/2] mm: add a field to store names for private anonymous memory To: Michal Hocko Cc: Sumit Semwal , 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 , Thomas Hellstrom , 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 , Rik van Riel , Mel Gorman , Tang Chen , Robin Holt , Shaohua Li , Sasha Levin , Johannes Weiner , Minchan Kim Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 47F84100E6903 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: 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. [1] https://android.googlesource.com/kernel/common/+/60500a42286de35f00d2a195f2021bcc029f11a1%5E%21/#F1