From patchwork Sat May 4 00:30:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13653688 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 50CE6C25B10 for ; Sat, 4 May 2024 00:30:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5FCB6B0089; Fri, 3 May 2024 20:30:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D10EB6B008C; Fri, 3 May 2024 20:30:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB0906B0095; Fri, 3 May 2024 20:30:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 96C9C6B0089 for ; Fri, 3 May 2024 20:30:14 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0CDBB801F1 for ; Sat, 4 May 2024 00:30:14 +0000 (UTC) X-FDA: 82078831548.08.1F39338 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 5CE4840018 for ; Sat, 4 May 2024 00:30:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=irYCdfxY; spf=pass (imf01.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 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=1714782612; 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=mLR6nTzoEqbjpMQV+qKzol6P628WFukhTh/ol7MsWXA=; b=pGbQySCE5VSoBMA7IP7HLiylDS5zIag+tVtD0tl4Hw4B7TYmO7SFrbjx6sL/tWfTlAwjND ueqG+HC2mCpoSHASgatctxuZOrrVeHoX3+mW2n8wTYt2nMyE5MZzdjGPI3luIfRSZmCWNZ qjVcI0/edEx/kaM58nA3AyTqeLCPOIs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=irYCdfxY; spf=pass (imf01.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 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=1714782612; a=rsa-sha256; cv=none; b=7RUTsNWts4r0eMGS7GJTt+BUGZGIDo7Ron+hPB3OKW6SUkJvx2xNdHl6Utx+AlyjpASZPD 7SUgquSSw4NgaHKqwiWp4Jl9YRFIOtzXoERIfQOm/XXSpyC9YVwT5yoHYt/W+9niwuv99U oHgzWpvaFtbHrp8XKun8FADXhHtFunw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A093361E38; Sat, 4 May 2024 00:30:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F0E4C116B1; Sat, 4 May 2024 00:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714782611; bh=OsmoaOeW12SHNusJpkc/eLJf6KgrIDQoVNy4kZW2PTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=irYCdfxYU679AgBBu/x1QTRLnZGEvoju3sMUjuymybtvTRyAXO34Tu5LrJt7S78GY OYoR1xjPv5idsNALPBfT7OYYvZAVRvGMyGBnqgsAFCh5iwoF6Zj9+pOMlsxs3vOp35 ImKr2la/Wynbx9YuuVLBqCV/jZZkBNJ4eDaZdYQbwS4A3J1cMls5s+EgtK5ozteiCq /tYaIw5mCGNRgjh3VARmvmzCzLCsA9n6fr/3fi0mORhOWDmjf8DQfjEiOYKVkIq2ts GlWEUVLdgIHoayTxpXLIO+ah6hUvLFFp4Ih08ljZbPW1C39TkwvEBJbUta+rtjK4Vl QEt+UszXK9gRg== 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, Andrii Nakryiko Subject: [PATCH 1/5] fs/procfs: extract logic for getting VMA name constituents Date: Fri, 3 May 2024 17:30:02 -0700 Message-ID: <20240504003006.3303334-2-andrii@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504003006.3303334-1-andrii@kernel.org> References: <20240504003006.3303334-1-andrii@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5CE4840018 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: x6s13tp9mouxuy8jqunyyyrixeyhnums X-HE-Tag: 1714782612-182271 X-HE-Meta: U2FsdGVkX1+v/82Y5H/Pw96AhqN0/p8T3dQEjI8UBkxfWM6YEKXQKyh5tvgPUthB7hKuIkHUW7V+ZgVg8fKJNI3QNUcliZjzRd4R+YLPbjsCatl7fLdqW+m+co5/Ism/vfnKfCgZ3dbYZ1Ngct5Owq6IHMdYMil01pRazEO58F2IP4+A9r4X1/9Jge7IM4S8kWah13pGzhanHrdmO5Xk3H4cKVQD2L7fX6xV0UYz+n8wxpDHKqLVUsK0dRiwwSm31f54AKgvVSrnAIwL9Y4wEi6dKIo6RwvibUqjMS51lzd2buXdi5eZD5nrJAmYDYjAstDkGOoiftPixtvsY+LhE9eO1SaUFVfI7o31VHPjMaAYeJieWjqM2VBNNhBEtiMnGd02r0gepfctby9aCcsBCEV0M7Gd9jRuJ968xn64LX63/QkH78Z4o3hEJrXva4Mm7DOVwJtZDzTArk4TaNhdTZkZAQ/AzlCvq0bW/5FWMH8pRO7kRaDVP/QWd3LsL1+q4xOgwFYGXaDZ5GlNwAY8ISqmXgK1izCJU4O3iA1QRvEBrUoOuU8yOwAsrISr4QkcgXcnZeoE20HJVg9kKnAVGsytT2mXhwPsOY5NdHduUjtQEGybJkrm4plcvIkSBs9JnwzBzK+5qZvzfTeWlPOvZzLB8Ek0GN45ehNOwqf37L7phTN8EwiwdIug9AZ6iaeezi/no2QdY7mEF+X4Bqw8UpkJ6zSk7lBjr2aYwoC7WAMMoBDxFbOGW/ta6mZz3DZOCot6yPbcWKAeWXaVbpixTVQZapnpC1AGGmGRTYMhCog8KbbY9MCrlMETnQfx3yNDE729nJcxf0wfcedSMxVBryyG6x1filGTdUil7adRq2pBzswmQceDR0L4/0K+Zu/bUU5F2wSOT1hkiq050uehu6aeZ0Si1neFdOirMvM8CwMQ23dQiDULjbHQ86UWGh3P+NZpXqlnMixliHkKUOT Qq9OvZso CSNHq1k49qbl/6KFjB+GcKfvK0bGFUaDokybHO9RTFoEK0MHXrMVCnzlHyRF9m1tDDHUosGgDOhrQn3hRjLz5R5XbyRTCY/by/peuXJDtuWxzEAgWwWRtb5Dog4jZuEdWc6DVxA21nQYJFjSSzShRd9nFHzAxS6mOyAbx2dl+FWLnCnRk6k47sXh1RO5gZJwySS4xWXyGr0qM2wPFLZNsiUAL4rMEpMWkxYva6FCxTuAJg74= 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: 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 e5a5f015ff03..8e503a1635b7 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); }