From patchwork Sun Sep 29 09:32:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 13814997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1369CF6497 for ; Sun, 29 Sep 2024 09:32:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A2BF6B00EC; Sun, 29 Sep 2024 05:32:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12AEB6B00EE; Sun, 29 Sep 2024 05:32:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE6E76B0110; Sun, 29 Sep 2024 05:32:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CE7546B00EC for ; Sun, 29 Sep 2024 05:32:28 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 40FEE12183C for ; Sun, 29 Sep 2024 09:32:28 +0000 (UTC) X-FDA: 82617260376.13.8D99B44 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf15.hostedemail.com (Postfix) with ESMTP id 8AD40A0004 for ; Sun, 29 Sep 2024 09:32:26 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dYFkjkKB; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of qiwuchen55@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=qiwuchen55@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727602308; a=rsa-sha256; cv=none; b=V++524URYofk71y6hNLvLKNSGq/sPBCi6NjUw2cJX+dmwVKNrX+EWp15GXoRjqygPpdrmd VkWlK2gi8FLRX8obQlRgQIEC/dMxjY5SNE8xQ/LXk9pQZXXu4Qm36RWKgxGAt3TJ1N7Ob9 6C8ffTupOlt8F2jcongo0rFenqxnYL0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dYFkjkKB; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of qiwuchen55@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=qiwuchen55@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727602308; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=8G8vjlEcJAcRlgU9O2sgDPR8dGgrmJLI9FzoAZcycRc=; b=omZ2madTlcyZunYtK+RJfs1tOK+InY0AseLuMTvt6T+HkyBe66Y5d0Xwp7P8kQaXr0KG6X I0exUCYeuogbZpOEawJCQFTiTLDNWMmltx4S9PX0s3+dAguj/WZyc/6wAubJKNGWJz+9xA BI4PZZbPhbPAxZTbFxBjeZo45LL9nN0= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2068acc8b98so36682855ad.3 for ; Sun, 29 Sep 2024 02:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727602345; x=1728207145; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8G8vjlEcJAcRlgU9O2sgDPR8dGgrmJLI9FzoAZcycRc=; b=dYFkjkKBK418WORLv105HPBfgpXbu8+4TRj3ErnK+TzxgH3rkJFgQUy18jmEUa9jHU QKltOAfQ+vvmQoIAAT7NX85OeRba8176zozJ5dpV5X0OHMMszCJxOeEjqLh5ESdHEQ6I gTI5z5K3/pHOxMoSn/TaoMLe2IWpcicRghqnrFkytV14Eu/uoe5NBzXfyNIllK9gIBj/ 8ZflE2CSHSnnrqo/aM9I0autBvGp3GFwinpPHWrj12uPXla7gNDBSrE/4tOdpfOdr++V BXOuARn2KSNefCQv+lAaLQxrLkqUae9iC5FLdzz513ze8r6EfR/uti0cYfxL4S+bjpYE MXYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727602345; x=1728207145; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8G8vjlEcJAcRlgU9O2sgDPR8dGgrmJLI9FzoAZcycRc=; b=xTWT+JmPAyBOGOWNSvLSS05HKCfOg/lxU/EVbSsvVWbcZxS8loiTnGZTZuy7CGqXRE hcs2+HhgsUWoDTormG7HtRwoHxj/aaFg7VN/d04ilc9As+gPFYS2tQNqzOkyj/3o0hon QjwwhqnRuaNsOJqPjooUzMl5H3gefvnLMo1vPeN8eFf+eriq6P/l+vQal4FcnJsuHyrM yiGQQrLzJyTpMvxegbONJkQQnQB8cPE4iSBTKEDbN4/5EsFlkbseBt6xAnbO70jVWsnZ d2kqkkz73mqF8pMU1Tq4+Zs3F94XIkLux+MV/6jSChGYAn7xwxbD35F+dko/jRcIyzWI XIkg== X-Gm-Message-State: AOJu0YysnOb3bV2dYboXfoIHw9JsVJGvlrkMI3DLIQA7JGohOPnv4NRt 7Hr42JKIGyGaQrHTrReXmImvqBDA4IJ9zx37bwZsM2Gxd8ofeVF0 X-Google-Smtp-Source: AGHT+IHcYVZL48MmizbvzEQtEXTVUF4S4kJXx594rPesOADkD0CKoqDiav+nNPgBOb/JBG60iWU/WQ== X-Received: by 2002:a17:902:eccd:b0:205:755c:dde6 with SMTP id d9443c01a7336-20b3776d5a3mr129546385ad.30.1727602345102; Sun, 29 Sep 2024 02:32:25 -0700 (PDT) Received: from localhost ([183.226.245.119]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e0d6a0sm37326325ad.169.2024.09.29.02.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Sep 2024 02:32:24 -0700 (PDT) From: "qiwu.chen" X-Google-Original-From: "qiwu.chen" To: akpm@linux-foundation.org, Liam.Howlett@oracle.com, vbabka@suse.cz, lorenzo.stoakes@oracle.com Cc: linux-mm@kvack.org, "qiwu.chen" Subject: [PATCH] mm: move get_vma_name() from procfs to mm tree Date: Sun, 29 Sep 2024 17:32:12 +0800 Message-Id: <20240929093212.40449-1-qiwu.chen@transsion.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 8AD40A0004 X-Rspamd-Server: rspam01 X-Stat-Signature: kcgimr1p8ybbuq96uhb9rrn68g7jxxni X-HE-Tag: 1727602346-770189 X-HE-Meta: U2FsdGVkX18EYG/3j+tL3XSL9eMTk2tEuTyn5QPVEskclV3kZSwiZxaEGnPGEP8sprOdWicu/gzQnLnsAb5UbrQ1chgdauNvHccCtt8QaLZUeEl2DxTPsI9nb0Pa7rm8xtUFDrV1wlwhFpyxG3CFSQlqsM1RTrU4VstnJgMGLAf8pqGesyBAHY19fZPJUGIRJsHlAveBlpAVHlJTREE6mo04sc6tlyPNtDj9G/zeawTl6s/Hq/eo02BIB6/DW7nHDa/UjTIULNdpWEQVx3Pjns84ql9pmLls8R7DhF4Cp/02W/VkwYJcsaErCpEkeHyWunwnGHTTzE0fiphY1/zJQ6kFGPt4pSXJYDFGo3vxfmXy0Gfll3/gpINk/fb3tQ1/F2s6k93V39Ml6Fa2fukCDN1upDN8QMkTV8QYuQkWcR9/qfsqDD1XuZluat0T+Z8kXegcwkLE0jjpyNak4AHxgzS7lrarHdFsD1Dg7I6wPD8qNAUkbktclX3cCJ7qM4CIYudTZxTJ1IETaH9ja9NMlSb4O8jzjUY/kfDA14AUdAWQ8aSiAmFilyoam3NaIT/5vVF2xXVNg08Akay4Z0i8SM7H95pcqic/PiHcIikDPaB/KB8l6jjKn+Jv7EVsF1vt+Ep+l2Hbb3Ho4XNv3GZTNHb5xvB7ZioS03FsbpEdD14L49WM1fbSyHU5dvyCXrKtXce9AZSr/ES9UE2lbExkH7LpEH4wF6LCtcn781SPeD730k01qt+kCMkpqnRz0Izi09B//+y71o1mbSpl6EppIW4rttm+5eLdhIWE7l6dRnT+I5MMgnvTfSZnavyn9IqKWZmDomn5HoFr6EOjEciai+ShytWsF5H9O0MXlUBDDE9qOHE/Ru7Pc5jU4hTkaiONknFIVKRIbnbB5ot85BTaefAEEs5GvdcwQhcDFIL7vVm7xovVIk7PZcOIMzor4QHcmp4/xUTl/xfBDbV4rLV +inkkZ18 DhwDEOSliCT3dk+VRIpFRBCelMNAkQLe8K7AcFrvFQG48ntawmiZUJ/GuNCSByfVMoAWWDW1DnJ1IWK9A840hL2ijhPIUlWvsssHAlx8K7a4Ecflrbnj4sjrN7amC2c3L0lptMc+WwxhUWeDKIh/DgNZCF26ditxgSP4ss4oyhP6/+QVmwqs74NN1pBxPzncbCz8HuebEydTNJmUQcnxybaXzVtwiSg0wWu8mMRv2ZL8B1dMEk+8uVo3geXYfEN0CIU44AczVI9RGjcrsbKvd91GL1pXvsIuHxNFakY4A/e1FyAZlapEH2sJJSo56qA/nBDoQaGoBK/my0JmiLz+v7lXz6ysbgA0cgDBLGLOq7YNmRq8nVXrn4rpUiMo+kayMXXHrlTOhLqg3LvQPFpqki4jOxkBMtyftrTEP 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: List-Subscribe: List-Unsubscribe: Commit acd4b2ecf3bb2 ("fs/procfs: extract logic for getting VMA name constituents") introduces a generic helper to get VMA name constituents. Currently, it's statically defined and referenced in fs/proc/task_mmu.c, which is not opened to users who want to query VMA name more efficiently. This patch moves get_vma_name() from procfs to mm/mmap.c, and export it for modules usage. There should be no functional changes. Signed-off-by: qiwu.chen --- fs/proc/task_mmu.c | 61 -------------------------------------- include/linux/mm.h | 2 ++ mm/mmap.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 61 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 72f14fd59c2d..7d414c39367a 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -240,67 +240,6 @@ static int do_maps_open(struct inode *inode, struct file *file, sizeof(struct proc_maps_private)); } -static void get_vma_name(struct vm_area_struct *vma, - const struct path **path, - const char **name, - const char **name_fmt) -{ - struct anon_vma_name *anon_name = vma->vm_mm ? anon_vma_name(vma) : NULL; - - *name = NULL; - *path = NULL; - *name_fmt = NULL; - - /* - * Print the dentry name for named mappings, and a - * special [heap] marker for the heap: - */ - if (vma->vm_file) { - /* - * If user named this anon shared memory via - * prctl(PR_SET_VMA ..., use the provided name. - */ - if (anon_name) { - *name_fmt = "[anon_shmem:%s]"; - *name = anon_name->name; - } else { - *path = file_user_path(vma->vm_file); - } - return; - } - - if (vma->vm_ops && vma->vm_ops->name) { - *name = vma->vm_ops->name(vma); - if (*name) - return; - } - - *name = arch_vma_name(vma); - if (*name) - return; - - if (!vma->vm_mm) { - *name = "[vdso]"; - return; - } - - if (vma_is_initial_heap(vma)) { - *name = "[heap]"; - return; - } - - if (vma_is_initial_stack(vma)) { - *name = "[stack]"; - return; - } - - if (anon_name) { - *name_fmt = "[anon:%s]"; - *name = anon_name->name; - return; - } -} - static void show_vma_header_prefix(struct seq_file *m, unsigned long start, unsigned long end, vm_flags_t flags, unsigned long long pgoff, diff --git a/include/linux/mm.h b/include/linux/mm.h index ecf63d2b0582..31abb857e11e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3418,6 +3418,8 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address); extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr); extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr, struct vm_area_struct **pprev); +extern void get_vma_name(struct vm_area_struct *vma, const struct path **path, + const char **name, const char **name_fmt); /* * Look up the first VMA which intersects the interval [start_addr, end_addr) diff --git a/mm/mmap.c b/mm/mmap.c index ee8f91eaadb9..d6ca383fc302 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -995,6 +995,80 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr, return vma; } +/** + * get_vma_name() - get VMA name with relevant pieces of data. + * @vma: The vma to check + * @path: The file path given to the vma + * @name: The vma name + * @name_fmt: The formatted vma name + * + * Extract generic logic to fetch relevant pieces of data to describe + * VMA name. This could be just some string (either special constant or + * user-provided), or a string with some formatted wrapping text (e.g., + * "[anon_shmem:]"), or, commonly, file path. + */ +void get_vma_name(struct vm_area_struct *vma, + const struct path **path, + const char **name, + const char **name_fmt) +{ + struct anon_vma_name *anon_name = vma->vm_mm ? anon_vma_name(vma) : NULL; + + *name = NULL; + *path = NULL; + *name_fmt = NULL; + + /* + * Print the dentry name for named mappings, and a + * special [heap] marker for the heap: + */ + if (vma->vm_file) { + /* + * If user named this anon shared memory via + * prctl(PR_SET_VMA ..., use the provided name. + */ + if (anon_name) { + *name_fmt = "[anon_shmem:%s]"; + *name = anon_name->name; + } else { + *path = file_user_path(vma->vm_file); + } + return; + } + + if (vma->vm_ops && vma->vm_ops->name) { + *name = vma->vm_ops->name(vma); + if (*name) + return; + } + + *name = arch_vma_name(vma); + if (*name) + return; + + if (!vma->vm_mm) { + *name = "[vdso]"; + return; + } + + if (vma_is_initial_heap(vma)) { + *name = "[heap]"; + return; + } + + if (vma_is_initial_stack(vma)) { + *name = "[stack]"; + return; + } + + if (anon_name) { + *name_fmt = "[anon:%s]"; + *name = anon_name->name; + return; + } +} +EXPORT_SYMBOL(get_vma_name); + /* * Verify that the stack growth is acceptable and * update accounting. This is shared with both the