From: Kalesh Singh <kaleshsingh@google.com>
To: ckoenig.leichtzumerken@gmail.com, christian.koenig@amd.com,
viro@zeniv.linux.org.uk, hch@infradead.org,
stephen.s.brennan@oracle.com, David.Laight@ACULAB.COM
Cc: ilkos@google.com, tjmercier@google.com, surenb@google.com,
kernel-team@android.com, Kalesh Singh <kaleshsingh@google.com>,
Jonathan Corbet <corbet@lwn.net>,
Sumit Semwal <sumit.semwal@linaro.org>,
Andrew Morton <akpm@linux-foundation.org>,
Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>,
Johannes Weiner <hannes@cmpxchg.org>,
Mike Rapoport <rppt@kernel.org>, Colin Cross <ccross@google.com>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Randy Dunlap <rdunlap@infradead.org>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org
Subject: [PATCH v2 0/2] procfs: Add file path and size to /proc/<pid>/fdinfo
Date: Thu, 23 Jun 2022 15:06:05 -0700 [thread overview]
Message-ID: <20220623220613.3014268-1-kaleshsingh@google.com> (raw)
Hi all,
This is v2 of the fdinfo patches. The main update is adding path
field only for files with anon inodes. Rebased on 5.19-rc3.
The previous cover letter is copied below for convenience.
Thanks,
Kalesh
-----------
Processes can pin shared memory by keeping a handle to it through a
file descriptor; for instance dmabufs, memfd, and ashmem (in Android).
In the case of a memory leak, to identify the process pinning the
memory, userspace needs to:
- Iterate the /proc/<pid>/fd/* for each process
- Do a readlink on each entry to identify the type of memory from
the file path.
- stat() each entry to get the size of the memory.
The file permissions on /proc/<pid>/fd/* only allows for the owner
or root to perform the operations above; and so is not suitable for
capturing the system-wide state in a production environment.
This issue was addressed for dmabufs by making /proc/*/fdinfo/*
accessible to a process with PTRACE_MODE_READ_FSCREDS credentials[1]
To allow the same kind of tracking for other types of shared memory,
add the following fields to /proc/<pid>/fdinfo/<fd>:
path - This allows identifying the type of memory based on common
prefixes: e.g. "/memfd...", "/dmabuf...", "/dev/ashmem..."
This was not an issued when dmabuf tracking was introduced
because the exp_name field of dmabuf fdinfo could be used
to distinguish dmabuf fds from other types.
size - To track the amount of memory that is being pinned.
dmabufs expose size as an additional field in fdinfo. Remove
this and make it a common field for all fds.
Access to /proc/<pid>/fdinfo is governed by PTRACE_MODE_READ_FSCREDS
-- the same as for /proc/<pid>/maps which also exposes the path and
size for mapped memory regions.
This allows for a system process with PTRACE_MODE_READ_FSCREDS to
account the pinned per-process memory via fdinfo.
Kalesh Singh (2):
procfs: Add 'size' to /proc/<pid>/fdinfo/
procfs: Add 'path' to /proc/<pid>/fdinfo/
Documentation/filesystems/proc.rst | 22 ++++++++++++++++++++--
drivers/dma-buf/dma-buf.c | 1 -
fs/libfs.c | 9 +++++++++
fs/proc/fd.c | 18 ++++++++++++++----
include/linux/fs.h | 1 +
5 files changed, 44 insertions(+), 7 deletions(-)
base-commit: a111daf0c53ae91e71fd2bfe7497862d14132e3e
--
2.37.0.rc0.161.g10f37bed90-goog
next reply other threads:[~2022-06-23 22:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-23 22:06 Kalesh Singh [this message]
2022-06-23 22:06 ` [PATCH v2 1/2] procfs: Add 'size' to /proc/<pid>/fdinfo/ Kalesh Singh
2022-06-28 11:53 ` Brian Foster
2022-06-28 22:38 ` Kalesh Singh
2022-06-29 12:23 ` Brian Foster
2022-06-29 20:43 ` Kalesh Singh
2022-06-30 11:48 ` Brian Foster
2022-06-30 12:03 ` Brian Foster
2022-06-30 21:30 ` Kalesh Singh
2022-06-23 22:06 ` [PATCH v2 2/2] procfs: Add 'path' " Kalesh Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220623220613.3014268-1-kaleshsingh@google.com \
--to=kaleshsingh@google.com \
--cc=David.Laight@ACULAB.COM \
--cc=akpm@linux-foundation.org \
--cc=ccross@google.com \
--cc=christian.koenig@amd.com \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=corbet@lwn.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=hannes@cmpxchg.org \
--cc=hch@infradead.org \
--cc=ilkos@google.com \
--cc=kernel-team@android.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mail@christoph.anton.mitterer.name \
--cc=paul.gortmaker@windriver.com \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=stephen.s.brennan@oracle.com \
--cc=sumit.semwal@linaro.org \
--cc=surenb@google.com \
--cc=tjmercier@google.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).