From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
Michael Ellerman <mpe@ellerman.id.au>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
Steve Capper <steve.capper@arm.com>,
Will Deacon <will.deacon@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v10 01/13] mm, hugetlbfs: Allow for "high" userspace addresses
Date: Tue, 3 May 2022 16:29:56 +0000 [thread overview]
Message-ID: <78cf869b-1b28-5a4a-682b-50162c978e6d@csgroup.eu> (raw)
In-Reply-To: <8b82565b407d04b6e6c4a564423a4e68bde6e39d.1649523076.git.christophe.leroy@csgroup.eu>
Le 09/04/2022 à 19:17, Christophe Leroy a écrit :
> This is a complement of f6795053dac8 ("mm: mmap: Allow for "high"
> userspace addresses") for hugetlb.
>
> This patch adds support for "high" userspace addresses that are
> optionally supported on the system and have to be requested via a hint
> mechanism ("high" addr parameter to mmap).
>
> Architectures such as powerpc and x86 achieve this by making changes to
> their architectural versions of hugetlb_get_unmapped_area() function.
> However, arm64 uses the generic version of that function.
>
> So take into account arch_get_mmap_base() and arch_get_mmap_end() in
> hugetlb_get_unmapped_area(). To allow that, move those two macros
> out of mm/mmap.c into include/linux/sched/mm.h
>
> If these macros are not defined in architectural code then they default
> to (TASK_SIZE) and (base) so should not introduce any behavioural
> changes to architectures that do not define them.
>
> For the time being, only ARM64 is affected by this change.
>
> From Catalin (ARM64):
> We should have fixed hugetlb_get_unmapped_area() as well when we
> added support for 52-bit VA. The reason for commit f6795053dac8 was to
> prevent normal mmap() from returning addresses above 48-bit by default
> as some user-space had hard assumptions about this.
>
> It's a slight ABI change if you do this for hugetlb_get_unmapped_area()
> but I doubt anyone would notice. It's more likely that the current
> behaviour would cause issues, so I'd rather have them consistent.
>
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> Cc: Steve Capper <steve.capper@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Fixes: f6795053dac8 ("mm: mmap: Allow for "high" userspace addresses")
> Cc: <stable@vger.kernel.org> # 5.0.x
> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
> Acked-by: Andrew Morton <akpm@linux-foundation.org>
This patch was merged in 5.18-rc4
See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5f24d5a579d1eace79d505b148808a850b417d4c
The rest of the series is to be merged via powerpc tree.
> ---
> v10:
> - Moved as first patch of the series so that it can be applied
> separately as a flag and be easily applied back on stable.
> - Added text from Catalin explaining why it is a fixup.
> ---
> fs/hugetlbfs/inode.c | 9 +++++----
> include/linux/sched/mm.h | 8 ++++++++
> mm/mmap.c | 8 --------
> 3 files changed, 13 insertions(+), 12 deletions(-)
>
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 99c7477cee5c..dd3a088db11d 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -206,7 +206,7 @@ hugetlb_get_unmapped_area_bottomup(struct file *file, unsigned long addr,
> info.flags = 0;
> info.length = len;
> info.low_limit = current->mm->mmap_base;
> - info.high_limit = TASK_SIZE;
> + info.high_limit = arch_get_mmap_end(addr);
> info.align_mask = PAGE_MASK & ~huge_page_mask(h);
> info.align_offset = 0;
> return vm_unmapped_area(&info);
> @@ -222,7 +222,7 @@ hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr,
> info.flags = VM_UNMAPPED_AREA_TOPDOWN;
> info.length = len;
> info.low_limit = max(PAGE_SIZE, mmap_min_addr);
> - info.high_limit = current->mm->mmap_base;
> + info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base);
> info.align_mask = PAGE_MASK & ~huge_page_mask(h);
> info.align_offset = 0;
> addr = vm_unmapped_area(&info);
> @@ -237,7 +237,7 @@ hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr,
> VM_BUG_ON(addr != -ENOMEM);
> info.flags = 0;
> info.low_limit = current->mm->mmap_base;
> - info.high_limit = TASK_SIZE;
> + info.high_limit = arch_get_mmap_end(addr);
> addr = vm_unmapped_area(&info);
> }
>
> @@ -251,6 +251,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
> struct mm_struct *mm = current->mm;
> struct vm_area_struct *vma;
> struct hstate *h = hstate_file(file);
> + const unsigned long mmap_end = arch_get_mmap_end(addr);
>
> if (len & ~huge_page_mask(h))
> return -EINVAL;
> @@ -266,7 +267,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
> if (addr) {
> addr = ALIGN(addr, huge_page_size(h));
> vma = find_vma(mm, addr);
> - if (TASK_SIZE - len >= addr &&
> + if (mmap_end - len >= addr &&
> (!vma || addr + len <= vm_start_gap(vma)))
> return addr;
> }
> diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
> index a80356e9dc69..1ad1f4bfa025 100644
> --- a/include/linux/sched/mm.h
> +++ b/include/linux/sched/mm.h
> @@ -136,6 +136,14 @@ static inline void mm_update_next_owner(struct mm_struct *mm)
> #endif /* CONFIG_MEMCG */
>
> #ifdef CONFIG_MMU
> +#ifndef arch_get_mmap_end
> +#define arch_get_mmap_end(addr) (TASK_SIZE)
> +#endif
> +
> +#ifndef arch_get_mmap_base
> +#define arch_get_mmap_base(addr, base) (base)
> +#endif
> +
> extern void arch_pick_mmap_layout(struct mm_struct *mm,
> struct rlimit *rlim_stack);
> extern unsigned long
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 3aa839f81e63..313b57d55a63 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2117,14 +2117,6 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info)
> return addr;
> }
>
> -#ifndef arch_get_mmap_end
> -#define arch_get_mmap_end(addr) (TASK_SIZE)
> -#endif
> -
> -#ifndef arch_get_mmap_base
> -#define arch_get_mmap_base(addr, base) (base)
> -#endif
> -
> /* Get an address range which is currently unmapped.
> * For shmat() with addr=0.
> *
next prev parent reply other threads:[~2022-05-03 16:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-09 17:17 [PATCH v10 00/13] Convert powerpc to default topdown mmap layout (v10) Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 01/13] mm, hugetlbfs: Allow for "high" userspace addresses Christophe Leroy
2022-05-03 16:29 ` Christophe Leroy [this message]
2022-04-09 17:17 ` [PATCH v10 02/13] mm: Allow arch specific arch_randomize_brk() with CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 03/13] mm, hugetlbfs: Allow an arch to always use generic versions of get_unmapped_area functions Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 04/13] mm: Add len and flags parameters to arch_get_mmap_end() Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 05/13] powerpc/mm: Move vma_mmu_pagesize() Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 06/13] powerpc/mm: Make slice specific to book3s/64 Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 07/13] powerpc/mm: Remove CONFIG_PPC_MM_SLICES Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 08/13] powerpc/mm: Use generic_get_unmapped_area() and call it from arch_get_unmapped_area() Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 09/13] powerpc/mm: Use generic_hugetlb_get_unmapped_area() Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 10/13] powerpc/mm: Move get_unmapped_area functions to slice.c Christophe Leroy
2022-05-23 12:27 ` Laurent Dufour
2022-05-23 15:18 ` Christophe Leroy
2022-05-23 16:44 ` Laurent Dufour
2022-04-09 17:17 ` [PATCH v10 11/13] powerpc/mm: Enable full randomisation of memory mappings Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 12/13] powerpc/mm: Convert to default topdown mmap layout Christophe Leroy
2022-04-09 17:17 ` [PATCH v10 13/13] powerpc: Simplify and move arch_randomize_brk() Christophe Leroy
2022-05-15 10:28 ` [PATCH v10 00/13] Convert powerpc to default topdown mmap layout (v10) Michael Ellerman
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=78cf869b-1b28-5a4a-682b-50162c978e6d@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
--cc=stable@vger.kernel.org \
--cc=steve.capper@arm.com \
--cc=will.deacon@arm.com \
/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).