Re: [PATCH 5/6] alpha: align hugetlb mappings in arch_get_unmapped_area()

From: Magnus Lindholm

Date: Wed Oct 07 2026 - 17:57:53 EST


Hi Matt,

On Tue, Oct 6, 2026 at 4:04 PM Matt Turner <mattst88@xxxxxxxxx> wrote:
>
> hugetlb_get_unmapped_area() does not align the address itself; it
> delegates to mm_get_unmapped_area_vmaflags(), and the huge page
> alignment is applied by generic_get_unmapped_area() and
> generic_get_unmapped_area_topdown() via info.align_mask.
>
> Alpha defines HAVE_ARCH_UNMAPPED_AREA and supplies its own
> arch_get_unmapped_area(), which never sets align_mask. An
> mmap(MAP_HUGETLB) with no address hint would therefore return a merely
> page-aligned address.
>
> Pass the file down to arch_get_unmapped_area_1() and set align_mask for
> hugetlbfs mappings, as x86, s390, sparc and loongarch already do. This
> is a no-op until alpha gains hugetlb support.
>
> Signed-off-by: Matt Turner <mattst88@xxxxxxxxx>
> ---
> arch/alpha/kernel/osf_sys.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
> index 7b6543d2cca3..61d806176213 100644
> --- a/arch/alpha/kernel/osf_sys.c
> +++ b/arch/alpha/kernel/osf_sys.c
> @@ -38,6 +38,7 @@
> #include <linux/namei.h>
> #include <linux/mount.h>
> #include <linux/uio.h>
> +#include <linux/hugetlb.h>
> #include <linux/vfs.h>
> #include <linux/rcupdate.h>
> #include <linux/slab.h>
> @@ -1201,14 +1202,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
> /* Get an address range which is currently unmapped. */
>
> static unsigned long
> -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
> - unsigned long limit)
> +arch_get_unmapped_area_1(struct file *filp, unsigned long addr,
> + unsigned long len, unsigned long limit)
> {
> struct vm_unmapped_area_info info = {};
>
> info.length = len;
> info.low_limit = addr;
> info.high_limit = limit;
> + if (filp && is_file_hugepages(filp))
> + info.align_mask = huge_page_mask_align(filp);
> return vm_unmapped_area(&info);
> }
>
> @@ -1236,19 +1239,20 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
> this feature should be incorporated into all ports? */
>
> if (addr) {
> - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
> + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len,
> + limit);
> if (addr != (unsigned long) -ENOMEM)
> return addr;
> }
>
> /* Next, try allocating at TASK_UNMAPPED_BASE. */
> - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
> + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(TASK_UNMAPPED_BASE),
> len, limit);
> if (addr != (unsigned long) -ENOMEM)
> return addr;
>
> /* Finally, try allocating in low memory. */
> - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
> + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit);
>
> return addr;
> }
>
> --
> 2.54.0
>

I tracked this down and I think Alpha needs this since 7bd3f1e1a9ae
("mm: make hugetlb mappings go through mm_get_unmapped_area_vmflags"),
v6.13; the same series did the equivalent for the generic code
(7f24cbc9c4d4) and for x86, s390, sparc and powerpc. LoongArch, which
also has its own arch_get_unmapped_area(), missed it and hit a BUG in
LTP hugefork02 until 3109d5ff484b ("LoongArch: Set hugetlb mmap base
address aligned with pmd size"). Maybe worth naming in the changelog,
either way nice fix!

On the UP2000+, MAP_HUGETLB mappings without an address hint come back
aligned to 64KB, 512KB and 4MB.

Reviewed-by: Magnus Lindholm <linmag7@xxxxxxxxx>
Tested-by: Magnus Lindholm <linmag7@xxxxxxxxx>