commit:     7ebd3d5eb40bc16b8efe35e288abc36fb859c16c
Author:     Mike Pagano <mpagano <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 26 22:44:00 2024 +0000
Commit:     Mike Pagano <mpagano <AT> gentoo <DOT> org>
CommitDate: Fri Jan 26 22:44:00 2024 +0000
URL:        https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=7ebd3d5e

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

Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>

 0000_README                                  |  4 ++
 1800_mm-32-bit-huge-page-alignment-fix.patch | 57 ++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/0000_README b/0000_README
index 34a20863..19339793 100644
--- a/0000_README
+++ b/0000_README
@@ -63,6 +63,10 @@ Patch:  1730_parisc-Disable-prctl.patch
 From:    
https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git
 Desc:    prctl: Temporarily disable prctl(PR_SET_MDWE) on parisc
 
+Patch:  1800_mm-32-bit-huge-page-alignment-fix.patch
+From:   
https://lore.kernel.org/all/[email protected]/T/
+Desc:   mm: huge_memory: don't force huge page alignment on 32 bit
+
 Patch:  1805_mm-disable-CONFIG-PER-VMA-LOCK-by-def.patch
 From:   https://lore.kernel.org/all/[email protected]/
 Desc:   mm: disable CONFIG_PER_VMA_LOCK by default until its fixed

diff --git a/1800_mm-32-bit-huge-page-alignment-fix.patch 
b/1800_mm-32-bit-huge-page-alignment-fix.patch
new file mode 100644
index 00000000..5ad5d49b
--- /dev/null
+++ b/1800_mm-32-bit-huge-page-alignment-fix.patch
@@ -0,0 +1,57 @@
+From: Yang Shi @ 2024-01-18 13:35 UTC (permalink / raw)
+  To: jirislaby, surenb, riel, willy, cl, akpm; +Cc: yang, linux-mm, 
linux-kernel
+
+From: Yang Shi <[email protected]>
+
+The 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/cahblzkqa1scba10yjwtta2mkcsok5+m1bthsdl8rovuq2xx...@mail.gmail.com/T/#mf211643a0427f8d6495b5b53f8132f453d60ab95
+[2] 
https://lore.kernel.org/linux-mm/cahblzkqa1scba10yjwtta2mkcsok5+m1bthsdl8rovuq2xx...@mail.gmail.com/T/#me93dff2ccbd9902c3e395e1c022fb454e48ecb1d
+
+Fixes: efa7df3e3bb5 ("mm: align larger anonymous mappings on THP boundaries")
+Reported-by: Jiri Slaby <[email protected]>
+Reported-by: Suren Baghdasaryan <[email protected]>
+Tested-by: Jiri Slaby <[email protected]>
+Tested-by: Suren Baghdasaryan <[email protected]>
+Cc: Rik van Riel <[email protected]>
+Cc: Matthew Wilcox <[email protected]>
+Cc: Christopher Lameter <[email protected]>
+Signed-off-by: Yang Shi <[email protected]>
+---
+ mm/huge_memory.c | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/mm/huge_memory.c b/mm/huge_memory.c
+index 94ef5c02b459..e9fbaccbe0c0 100644
+--- a/mm/huge_memory.c
++++ b/mm/huge_memory.c
+@@ -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>
+@@ -811,6 +812,14 @@ static unsigned long __thp_get_unmapped_area(struct file 
*filp,
+       loff_t off_align = round_up(off, size);
+       unsigned long len_pad, ret;
+ 
++      /*
++       * It doesn't make too much sense to froce huge page alignment on
++       * 32 bit system or compat userspace due to the contrained virtual
++       * address space and address entropy.
++       */
++      if (IS_ENABLED(CONFIG_32BIT) || in_compat_syscall())
++              return 0;
++
+       if (off_end <= off_align || (off_end - off_align) < size)
+               return 0;
+ 
+-- 
+2.41.0

Reply via email to