From: David Hildenbrand <david@redhat.com>
To: Vlastimil Babka <vbabka@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Jann Horn <jannh@google.com>, Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Colin Cross <ccross@google.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/4] mm, madvise: extract mm code from prctl_set_vma() to mm/madvise.c
Date: Tue, 24 Jun 2025 16:04:12 +0200 [thread overview]
Message-ID: <5f5b83ae-8482-4eea-9df0-55871c30375b@redhat.com> (raw)
In-Reply-To: <20250624-anon_name_cleanup-v2-2-600075462a11@suse.cz>
On 24.06.25 15:03, Vlastimil Babka wrote:
> Setting anon_name is done via madvise_set_anon_name() and behaves a lot
> of like other madvise operations. However, apparently because madvise()
> has lacked the 4th argument and prctl() not, the userspace entry point
> has been implemented via prctl(PR_SET_VMA, ...) and handled first by
> prctl_set_vma().
>
> Currently prctl_set_vma() lives in kernel/sys.c but setting the
> vma->anon_name is mm-specific code so extract it to a new
> set_anon_vma_name() function under mm. mm/madvise.c seems to be the most
> straightforward place as that's where madvise_set_anon_name() lives.
> Stop declaring the latter in mm.h and instead declare
> set_anon_vma_name().
>
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> include/linux/mm.h | 14 +++++++-------
> kernel/sys.c | 50 +-------------------------------------------------
> mm/madvise.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
> 3 files changed, 58 insertions(+), 58 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 0e0549f3d681f6c7a78e8dfa341a810e5a8f96c1..ef40f68c1183d4c95016575a4ee0171e12df9ba4 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -4059,14 +4059,14 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping,
> #endif
>
> #ifdef CONFIG_ANON_VMA_NAME
> -int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
> - unsigned long len_in,
> - struct anon_vma_name *anon_name);
> +int set_anon_vma_name(unsigned long addr, unsigned long size,
> + const char __user *uname);
> #else
> -static inline int
> -madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
> - unsigned long len_in, struct anon_vma_name *anon_name) {
> - return 0;
> +static inline
> +int set_anon_vma_name(unsigned long addr, unsigned long size,
> + const char __user *uname)
> +{
> + return -EINVAL;
> }
> #endif
>
> diff --git a/kernel/sys.c b/kernel/sys.c
> index adc0de0aa364aebb23999f621717a5d32599921c..b153fb345ada28ea1a33386a32bcce9cb1b23475 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -2343,54 +2343,14 @@ int __weak arch_lock_shadow_stack_status(struct task_struct *t, unsigned long st
>
> #define PR_IO_FLUSHER (PF_MEMALLOC_NOIO | PF_LOCAL_THROTTLE)
>
> -#ifdef CONFIG_ANON_VMA_NAME
> -
> -#define ANON_VMA_NAME_MAX_LEN 80
> -#define ANON_VMA_NAME_INVALID_CHARS "\\`$[]"
> -
> -static inline bool is_valid_name_char(char ch)
> -{
> - /* printable ascii characters, excluding ANON_VMA_NAME_INVALID_CHARS */
> - return ch > 0x1f && ch < 0x7f &&
> - !strchr(ANON_VMA_NAME_INVALID_CHARS, ch);
> -}
> -
> static int prctl_set_vma(unsigned long opt, unsigned long addr,
> unsigned long size, unsigned long arg)
> {
> - struct mm_struct *mm = current->mm;
> - const char __user *uname;
> - struct anon_vma_name *anon_name = NULL;
> int error;
>
> switch (opt) {
> case PR_SET_VMA_ANON_NAME:
> - uname = (const char __user *)arg;
> - if (uname) {
> - char *name, *pch;
> -
> - name = strndup_user(uname, ANON_VMA_NAME_MAX_LEN);
> - if (IS_ERR(name))
> - return PTR_ERR(name);
> -
> - for (pch = name; *pch != '\0'; pch++) {
> - if (!is_valid_name_char(*pch)) {
> - kfree(name);
> - return -EINVAL;
> - }
> - }
> - /* anon_vma has its own copy */
> - anon_name = anon_vma_name_alloc(name);
> - kfree(name);
> - if (!anon_name)
> - return -ENOMEM;
> -
> - }
> -
> - mmap_write_lock(mm);
> - error = madvise_set_anon_name(mm, addr, size, anon_name);
> - mmap_write_unlock(mm);
> - anon_vma_name_put(anon_name);
> + error = set_anon_vma_name(addr, size, (const char __user *)arg);
At first I thought whether passing current->mm as an argument might make
it clearer on what we actually operate. But then, "anon_vma" might give
a good hint.
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-06-24 14:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 13:03 [PATCH v2 0/4] madvise anon_name cleanups Vlastimil Babka
2025-06-24 13:03 ` [PATCH v2 1/4] mm, madvise: simplify anon_name handling Vlastimil Babka
2025-06-24 13:58 ` David Hildenbrand
2025-06-24 14:28 ` Suren Baghdasaryan
2025-06-24 16:41 ` Vlastimil Babka
2025-06-24 16:38 ` Vlastimil Babka
2025-06-24 15:26 ` Lorenzo Stoakes
2025-06-24 16:42 ` Vlastimil Babka
2025-06-24 17:01 ` Vlastimil Babka
2025-06-24 13:03 ` [PATCH v2 2/4] mm, madvise: extract mm code from prctl_set_vma() to mm/madvise.c Vlastimil Babka
2025-06-24 14:04 ` David Hildenbrand [this message]
2025-06-24 14:31 ` Suren Baghdasaryan
2025-06-24 15:28 ` Lorenzo Stoakes
2025-06-24 13:03 ` [PATCH v2 3/4] mm, madvise: move madvise_set_anon_name() down the file Vlastimil Babka
2025-06-24 14:05 ` David Hildenbrand
2025-06-24 14:33 ` Suren Baghdasaryan
2025-06-24 16:46 ` Vlastimil Babka
2025-06-24 15:36 ` Lorenzo Stoakes
2025-06-24 17:02 ` Vlastimil Babka
2025-06-24 13:03 ` [PATCH v2 4/4] mm, madvise: use standard madvise locking in madvise_set_anon_name() Vlastimil Babka
2025-06-24 14:06 ` David Hildenbrand
2025-06-24 14:35 ` Suren Baghdasaryan
2025-06-24 15:45 ` Lorenzo Stoakes
2025-06-24 16:48 ` Vlastimil Babka
2025-06-24 17:03 ` Vlastimil Babka
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=5f5b83ae-8482-4eea-9df0-55871c30375b@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=ccross@google.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--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