From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Suren Baghdasaryan <surenb@google.com>,
Arnd Bergmann <arnd@arndb.de>,
Shakeel Butt <shakeel.butt@linux.dev>,
linux-api@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Minchan Kim <minchan@kernel.org>
Subject: [PATCH 0/2] unrestrict process_madvise() for current process
Date: Mon, 23 Sep 2024 17:03:55 +0100 [thread overview]
Message-ID: <cover.1727106751.git.lorenzo.stoakes@oracle.com> (raw)
The process_madvise() call was introduced in commit ecb8ac8b1f14
("mm/madvise: introduce process_madvise() syscall: an external memory
hinting API") as a means of performing madvise() operations on another
process.
However, as it provides the means by which to perform multiple madvise()
operations in a batch via an iovec, it is useful to utilise the same
interface for performing operations on the current process rather than a
remote one.
Using this interface targeting the current process is cumbersome - a pidfd
needs to be setup for the current pid, and we are limited to only a subset
of madvise() operations, a limitation sensible for manipulating remote
processes but not meaningful when manipulating the current one.
Commit 22af8caff7d1 ("mm/madvise: process_madvise() drop capability check
if same mm") removed the need for a caller invoking process_madvise() on
its own pidfd to possess the CAP_SYS_NICE capability, however this leaves
the restrictions on operation in place and the cumbersome need for a 'self
pidfd'.
This patch series eliminates both limitations:
1. The restriction on permitted operations is removed when operating
on the current process.
2. A new flag is introduced - PR_MADV_SELF - which eliminates the need for
a pidfd - if this flag is set, the pidfd argument is ignored and the
operation is simply applied to the current process.
Therefore a user can simply invoke:
process_madvise(0, iovec, n, MADV_..., PR_MADV_SELF);
And perform any madvise() operation they like on the n ranges specified by
the iovec parameter.
This series also introduces a series of self-tests for this feature
asserting that the flag functions as expected.
Lorenzo Stoakes (2):
mm/madvise: introduce PR_MADV_SELF flag to process_madvise()
selftests/mm: add test for process_madvise PR_MADV_SELF flag use
include/uapi/asm-generic/mman-common.h | 2 +
mm/madvise.c | 58 +++++++---
tools/testing/selftests/mm/.gitignore | 1 +
tools/testing/selftests/mm/Makefile | 1 +
tools/testing/selftests/mm/process_madvise.c | 115 +++++++++++++++++++
5 files changed, 161 insertions(+), 16 deletions(-)
create mode 100644 tools/testing/selftests/mm/process_madvise.c
--
2.46.0
next reply other threads:[~2024-09-23 16:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-23 16:03 Lorenzo Stoakes [this message]
2024-09-23 16:03 ` [PATCH 1/2] mm/madvise: introduce PR_MADV_SELF flag to process_madvise() Lorenzo Stoakes
2024-09-23 18:56 ` Shakeel Butt
2024-09-23 19:34 ` Lorenzo Stoakes
2024-09-23 21:49 ` Arnd Bergmann
2024-09-24 7:49 ` Lorenzo Stoakes
2024-09-23 21:20 ` kernel test robot
2024-09-23 21:30 ` kernel test robot
2024-09-24 3:15 ` kernel test robot
2024-09-24 8:47 ` Lorenzo Stoakes
2024-09-23 16:03 ` [PATCH 2/2] selftests/mm: add test for process_madvise PR_MADV_SELF flag use Lorenzo Stoakes
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=cover.1727106751.git.lorenzo.stoakes@oracle.com \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
/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