[PATCH] arch,x86: Skip setting align_offset for hugetlb mappings
From: Oscar Salvador
Date: Mon Jun 01 2026 - 08:58:25 EST
On x86, arch_get_unmapped_area{_topdown} set align_offset in order to avoid
cache aliasing on I$ on AMD family 15h when 'align_va_addr' is enabled.
Prior to commit 7bd3f1e1a9ae ("mm: make hugetlb mappings go through mm_get_unmapped_area_vmflags"),
we did not have to worry about that because hugetlb specific code did not set
align_offset, but above commit got rid of hugetlb specific code and started to route
hugetlb mappings through the generic interface.
Doing that has the effect of handling non-aligned hugetlb mappings to userspace,
which is plain wrong.
So, skip setting align_offset if we are dealing with a hugetlb mapping.
Fixes: 7bd3f1e1a9ae ("mm: make hugetlb mappings go through mm_get_unmapped_area_vmflags")
Reported-by: Karsten Desler <kdesler@xxxxxxxxxx>
Closes: https://lore.kernel.org/linux-mm/20260527143643.GO31091@xxxxxxxxxx/
Signed-off-by: Oscar Salvador <osalvador@xxxxxxx>
---
So, let me say two things:
1) Karsten tested below patch and reported it was working fine for him.
Did not stamp his Tested-by though, because it was not explicitly provided.
2) This is a hack, I know, and I should probably be flagellated for this but
since this is a regression, I went for the quick/easy-to-apply fix, so it can
be easily backported.
Having said that, I already made my mind to fix this in a better way, which would
involve getting rid of hugetlb-specific code and do the masking off as we do for
THP, but for that I need to refactor the code and that would not be so easy
to backported. Just so you understand the reasoning behind.
---
arch/x86/kernel/sys_x86_64.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
index 776ae6fa7f2d..60f876dce8e5 100644
--- a/arch/x86/kernel/sys_x86_64.c
+++ b/arch/x86/kernel/sys_x86_64.c
@@ -157,7 +157,12 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len,
}
if (filp) {
info.align_mask = get_align_mask(filp);
- info.align_offset += get_align_bits();
+ /*
+ * Hugepages must remain hugepage-aligned, so skip adding an offset
+ * in case we enabled 'align_va_addr'.
+ */
+ if (!is_file_hugepages(filp))
+ info.align_offset += get_align_bits();
}
return vm_unmapped_area(&info);
@@ -222,7 +227,12 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr0,
if (filp) {
info.align_mask = get_align_mask(filp);
- info.align_offset += get_align_bits();
+ /*
+ * Hugepages must remain hugepage-aligned, so skip adding an offset
+ * in case we enabled 'align_va_addr'.
+ */
+ if (!is_file_hugepages(filp))
+ info.align_offset += get_align_bits();
}
addr = vm_unmapped_area(&info);
if (!(addr & ~PAGE_MASK))
--
2.35.3