Commit 82f151b6 authored by Yang Shi's avatar Yang Shi Committed by Kefeng Wang
Browse files

mm: huge_memory: don't force huge page alignment on 32 bit

mainline inclusion
from mainline-v6.8-rc3
commit 4ef9ad19e17676b9ef071309bc62020e2373705d
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9H84X
CVE: NA

-------------------------------------------------

commit efa7df3e3bb5 ("mm: align larger anonymous mappings on THP
boundaries") caused two issues [1] [2] reported on 32 bit system or compat
userspace.

It doesn't make too much sense to force huge page alignment on 32 bit
system due to the constrained virtual address space.

[1] https://lore.kernel.org/linux-mm/d0a136a0-4a31-46bc-adf4-2db109a61672@kernel.org/
[2] https://lore.kernel.org/linux-mm/CAJuCfpHXLdQy1a2B6xN2d7quTYwg2OoZseYPZTRpU0eHHKD-sQ@mail.gmail.com/

Link: https://lkml.kernel.org/r/20240118180505.2914778-1-shy828301@gmail.com


Fixes: efa7df3e3bb5 ("mm: align larger anonymous mappings on THP boundaries")
Signed-off-by: default avatarYang Shi <yang@os.amperecomputing.com>
Reported-by: default avatarJiri Slaby <jirislaby@kernel.org>
Reported-by: default avatarSuren Baghdasaryan <surenb@google.com>
Tested-by: default avatarJiri Slaby <jirislaby@kernel.org>
Tested-by: default avatarSuren Baghdasaryan <surenb@google.com>
Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Christopher Lameter <cl@linux.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 4ef9ad19e17676b9ef071309bc62020e2373705d)
Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
parent ed7f8bc0
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <linux/page_owner.h>
#include <linux/sched/sysctl.h>
#include <linux/memory-tiers.h>
#include <linux/compat.h>

#include <asm/tlb.h>
#include <asm/pgalloc.h>
@@ -784,6 +785,9 @@ static unsigned long __thp_get_unmapped_area(struct file *filp,
	loff_t off_align = round_up(off, size);
	unsigned long len_pad, ret;

	if (IS_ENABLED(CONFIG_32BIT) || in_compat_syscall())
		return 0;

	if (off_end <= off_align || (off_end - off_align) < size)
		return 0;