From patchwork Tue Jun 18 22:45:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13703112 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 A0351C2BA1A for ; Tue, 18 Jun 2024 22:45:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EECE6B0349; Tue, 18 Jun 2024 18:45:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 474856B034A; Tue, 18 Jun 2024 18:45:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 314836B034B; Tue, 18 Jun 2024 18:45:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 037366B0349 for ; Tue, 18 Jun 2024 18:45:42 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7AB45160B7A for ; Tue, 18 Jun 2024 22:45:42 +0000 (UTC) X-FDA: 82245492924.12.52B466F Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id 22EBF40002 for ; Tue, 18 Jun 2024 22:45:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jkx+BEUm; spf=pass (imf11.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718750737; 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:in-reply-to:references:references:dkim-signature; bh=pr/fv0ckxhWR6mlagUsulw9zLq7bdT+8t88N5DpZzzA=; b=ad/R1oP416X2AUnpQqF871Gd0Z/YJA2sJAIvMunuN+d0OqX8qUV8Q27y7tL5hvUT0NocUY uKO6n6twurG/MEjdSUg48/Blcv9f03fFaQ2wL71akm7XjHet5YcoIzbc2HC9NqaYiJoq+O iiwZVixehoQc+fo2Fijlc2uqWG16P6o= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jkx+BEUm; spf=pass (imf11.hostedemail.com: domain of andrii@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718750737; a=rsa-sha256; cv=none; b=RnARTUPGYhCMHIvpUUo+bouI63csKapSQIf9mIoCZYeMdiIR2ohMFJFiN7je79VqCc7ZFd uMbj8jKzuUCkicTioy78dRioagHr5aFFFCMKgHd8tt1qfVnVn/2Qq1+aIimSpaeQ26f1W/ WW7mICifSKkswiSYpLXuESORHGVuETg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A6ECFCE1C43; Tue, 18 Jun 2024 22:45:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C94E8C4AF49; Tue, 18 Jun 2024 22:45:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718750735; bh=b8KoHPdCbnvChHG05PMTrqcngJcnOaTMuFGj6VIsl38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jkx+BEUmUtL0KzQE6yq+Z+VsGFwV14uAF6j7cuHLez9pT4S/raH5zqhjTuZWITNP6 pCtXdof9TOAFWXlw36uqcOMVvWrm27/sz5svx4waMOc72J6usnfPz2RHx5lwhvmQZd of/ebZN+uegBPTT0vwfGYzuaYEQKjzofmJkOnEV8wfIrGXVQU4C8GEKA/FXBNOAOGa TTE0HDNbT4QAkSaTQrSiWU317sb5eoAZGPGt/EjP4xSTO6cLTD6/yIO7hpf06HH1O0 WMvpuZBV2+9WYw6meBmD3YCJjPTRnluFM3qGfNBOp4HKBfvPqpYnMhvKkgRRPSf+g0 UPktbl6oSO0Yg== From: Andrii Nakryiko To: linux-fsdevel@vger.kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, gregkh@linuxfoundation.org, linux-mm@kvack.org, liam.howlett@oracle.com, surenb@google.com, rppt@kernel.org, adobriyan@gmail.com, Andrii Nakryiko Subject: [PATCH v5 1/6] fs/procfs: extract logic for getting VMA name constituents Date: Tue, 18 Jun 2024 15:45:20 -0700 Message-ID: <20240618224527.3685213-2-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240618224527.3685213-1-andrii@kernel.org> References: <20240618224527.3685213-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 22EBF40002 X-Stat-Signature: omytwr4ckzuw54q4b1dc4fsakh349jes X-HE-Tag: 1718750739-898 X-HE-Meta: U2FsdGVkX1+zSo6Xulip45jyonGPVn7rSX0quT5STeH4IiVNkYOEMWaVB0cxGm/WcTzVEbG0dusv4VtOA072wP3Yn1WIQod02YMXLQ31Tn3c3/FTeUVM3EDa/2Mp7MLoV0+YFbiiUuc5QxOszrS7CRVC1nBhYBBXbDsxY9KuI2ZU5ME94VhJHeQdZvCF80I5vKsYdXCqaWnP7IdcAM9bhxHWEJGp0k723qZj40w6FKqmE22FGpD9uNpuma9HhKKWyoULmquvcLZ7euUr+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ner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. seq_file-based logic has different methods to handle all three cases, but they are currently mixed in with extracting underlying sources of data. This patch splits this into data fetching and data formatting, so that data fetching can be reused later on. There should be no functional changes. Signed-off-by: Andrii Nakryiko --- fs/proc/task_mmu.c | 125 +++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 54 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 93fb2c61b154..507b7dc7c4c8 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -239,6 +239,67 @@ 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, @@ -262,17 +323,15 @@ static void show_vma_header_prefix(struct seq_file *m, static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma) { - struct anon_vma_name *anon_name = NULL; - struct mm_struct *mm = vma->vm_mm; - struct file *file = vma->vm_file; + const struct path *path; + const char *name_fmt, *name; vm_flags_t flags = vma->vm_flags; unsigned long ino = 0; unsigned long long pgoff = 0; unsigned long start, end; dev_t dev = 0; - const char *name = NULL; - if (file) { + if (vma->vm_file) { const struct inode *inode = file_user_inode(vma->vm_file); dev = inode->i_sb->s_dev; @@ -283,57 +342,15 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma) start = vma->vm_start; end = vma->vm_end; show_vma_header_prefix(m, start, end, flags, pgoff, dev, ino); - if (mm) - anon_name = anon_vma_name(vma); - /* - * Print the dentry name for named mappings, and a - * special [heap] marker for the heap: - */ - if (file) { + get_vma_name(vma, &path, &name, &name_fmt); + if (path) { seq_pad(m, ' '); - /* - * If user named this anon shared memory via - * prctl(PR_SET_VMA ..., use the provided name. - */ - if (anon_name) - seq_printf(m, "[anon_shmem:%s]", anon_name->name); - else - seq_path(m, file_user_path(file), "\n"); - goto done; - } - - if (vma->vm_ops && vma->vm_ops->name) { - name = vma->vm_ops->name(vma); - if (name) - goto done; - } - - name = arch_vma_name(vma); - if (!name) { - if (!mm) { - name = "[vdso]"; - goto done; - } - - if (vma_is_initial_heap(vma)) { - name = "[heap]"; - goto done; - } - - if (vma_is_initial_stack(vma)) { - name = "[stack]"; - goto done; - } - - if (anon_name) { - seq_pad(m, ' '); - seq_printf(m, "[anon:%s]", anon_name->name); - } - } - -done: - if (name) { + seq_path(m, path, "\n"); + } else if (name_fmt) { + seq_pad(m, ' '); + seq_printf(m, name_fmt, name); + } else if (name) { seq_pad(m, ' '); seq_puts(m, name); }