All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arch,x86: Skip setting align_offset for hugetlb mappings
@ 2026-06-01 12:50 Oscar Salvador
  2026-06-01 20:02 ` Andrew Morton
  2026-06-01 20:25 ` Dave Hansen
  0 siblings, 2 replies; 7+ messages in thread
From: Oscar Salvador @ 2026-06-01 12:50 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Dave Hansen, Borislav Petkov, Karsten Desler, linux-kernel,
	linux-mm, Oscar Salvador

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@soohrt.org>
Closes: https://lore.kernel.org/linux-mm/20260527143643.GO31091@soohrt.org/
Signed-off-by: Oscar Salvador <osalvador@suse.de>
---
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



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-06-04 20:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-01 12:50 [PATCH] arch,x86: Skip setting align_offset for hugetlb mappings Oscar Salvador
2026-06-01 20:02 ` Andrew Morton
2026-06-01 20:25 ` Dave Hansen
2026-06-02  5:02   ` Oscar Salvador (SUSE)
2026-06-02 13:26     ` Oscar Salvador (SUSE)
2026-06-04 14:51   ` Oscar Salvador (SUSE)
2026-06-04 20:38     ` Dave Hansen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.