* [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
@ 2024-12-11 23:27 Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 01/16] mm: Introduce generic_mmap_hint() Kalesh Singh
` (17 more replies)
0 siblings, 18 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Hi all,
This is v2 othe the arch_mmap_hint() series.
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate most of the error handling in arch_mmap_hint().
- Patch 16 ("mm: Fallback to generic_mmap_hint()") was folded into
Patch 2 ("mm: x86: Introduce arch_mmap_hint()")
v1: https://lore.kernel.org/r/20241210024119.2488608-1-kaleshsingh@google.com/
=======
This series introduces arch_mmap_hint() to handle allocating VA space
for the hint address.
Patches 1-16 introduce this new helper and Patch 17 uses it to fix the
issue of mmap hint being ignored in some cases due to THP alignment [1]
[1] https://lore.kernel.org/r/20241118214650.3667577-1-kaleshsingh@google.com/
Thanks,
Kalesh
Kalesh Singh (16):
mm: Introduce generic_mmap_hint()
mm: x86: Introduce arch_mmap_hint()
mm: arm: Introduce arch_mmap_hint()
mm: alpha: Introduce arch_mmap_hint()
mm: arc: Use generic_mmap_hint()
mm: csky: Introduce arch_mmap_hint()
mm: loongarch: Introduce arch_mmap_hint()
mm: mips: Introduce arch_align_mmap_hint()
mm: parisc: Introduce arch_align_mmap_hint()
mm: s390: Use generic_mmap_hint()
mm: sh: Introduce arch_mmap_hint()
mm: sparc32: Introduce arch_mmap_hint()
mm: sparc64: Introduce arch_mmap_hint()
mm: xtensa: Introduce arch_mmap_hint()
mm: powerpc: Introduce arch_mmap_hint()
mm: Respect mmap hint before THP alignment if allocation is possible
arch/alpha/include/asm/pgtable.h | 1 +
arch/alpha/kernel/osf_sys.c | 31 +++---
arch/arc/include/asm/pgtable.h | 1 +
arch/arc/mm/mmap.c | 43 +++++----
arch/arm/include/asm/pgtable.h | 1 +
arch/arm/mm/mmap.c | 107 +++++++++------------
arch/csky/abiv1/inc/abi/pgtable-bits.h | 1 +
arch/csky/abiv1/mmap.c | 68 +++++++------
arch/loongarch/include/asm/pgtable.h | 1 +
arch/loongarch/mm/mmap.c | 49 +++++-----
arch/mips/include/asm/pgtable.h | 1 +
arch/mips/mm/mmap.c | 50 +++++-----
arch/parisc/include/asm/pgtable.h | 1 +
arch/parisc/kernel/sys_parisc.c | 53 +++++-----
arch/powerpc/include/asm/book3s/64/slice.h | 1 +
arch/powerpc/mm/book3s64/slice.c | 31 ++++++
arch/s390/include/asm/pgtable.h | 1 +
arch/s390/mm/mmap.c | 51 +++++-----
arch/sh/include/asm/pgtable.h | 1 +
arch/sh/mm/mmap.c | 83 ++++++----------
arch/sparc/include/asm/pgtable_32.h | 1 +
arch/sparc/include/asm/pgtable_64.h | 1 +
arch/sparc/kernel/sys_sparc_32.c | 33 ++++---
arch/sparc/kernel/sys_sparc_64.c | 96 +++++++-----------
arch/x86/include/asm/pgtable_64.h | 1 +
arch/x86/kernel/sys_x86_64.c | 64 ++++++------
arch/xtensa/kernel/syscall.c | 31 ++++--
include/linux/sched/mm.h | 9 ++
mm/huge_memory.c | 17 ++--
mm/mmap.c | 86 +++++++++++------
30 files changed, 491 insertions(+), 424 deletions(-)
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 01/16] mm: Introduce generic_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-12 20:08 ` Yang Shi
2024-12-11 23:27 ` [PATCH mm-unstable v2 02/16] mm: x86: Introduce arch_mmap_hint() Kalesh Singh
` (16 subsequent siblings)
17 siblings, 1 reply; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Consolidate the hint searches from both directions (topdown and
bottomup) into generic_mmap_hint().
No functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
include/linux/sched/mm.h | 4 +++
mm/mmap.c | 76 ++++++++++++++++++++++++----------------
2 files changed, 50 insertions(+), 30 deletions(-)
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index 928a626725e6..edeec19d1708 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -201,6 +201,10 @@ unsigned long mm_get_unmapped_area_vmflags(struct mm_struct *mm,
unsigned long flags,
vm_flags_t vm_flags);
+unsigned long generic_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags);
+
unsigned long
generic_get_unmapped_area(struct file *filp, unsigned long addr,
unsigned long len, unsigned long pgoff,
diff --git a/mm/mmap.c b/mm/mmap.c
index df9154b15ef9..382b4eac5406 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -620,6 +620,47 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info)
return addr;
}
+/*
+ * Look up unmapped area at the requested hint addr
+ *
+ * NOTE: MAP_FIXED is also handled here since it's a special case of
+ * enforcing the hint address.
+ *
+ * Returns:
+ * ERR_VALUE: If the requested mapping is not valid
+ * 0: If there isn't a sufficiently large hole at the hint addr.
+ * addr: If sufficient VA space is available at the hint address;
+ * or MAP_FIXED was specified.
+ */
+unsigned long generic_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ struct mm_struct *mm = current->mm;
+ struct vm_area_struct *vma, *prev;
+ const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
+
+ /* requested length too big for entire address space */
+ if (len > mmap_end - mmap_min_addr)
+ return -ENOMEM;
+
+ if (flags & MAP_FIXED)
+ return addr;
+
+ if (!addr)
+ return 0;
+
+ addr = PAGE_ALIGN(addr);
+ vma = find_vma_prev(mm, addr, &prev);
+ if (mmap_end - len >= addr && addr >= mmap_min_addr &&
+ (!vma || addr + len <= vm_start_gap(vma)) &&
+ (!prev || addr >= vm_end_gap(prev)))
+ return addr;
+
+ /* Fallback to VA space search */
+ return 0;
+}
+
/* Get an address range which is currently unmapped.
* For shmat() with addr=0.
*
@@ -637,25 +678,13 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr,
unsigned long flags, vm_flags_t vm_flags)
{
struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma, *prev;
struct vm_unmapped_area_info info = {};
const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
- if (len > mmap_end - mmap_min_addr)
- return -ENOMEM;
-
- if (flags & MAP_FIXED)
+ addr = generic_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
return addr;
- if (addr) {
- addr = PAGE_ALIGN(addr);
- vma = find_vma_prev(mm, addr, &prev);
- if (mmap_end - len >= addr && addr >= mmap_min_addr &&
- (!vma || addr + len <= vm_start_gap(vma)) &&
- (!prev || addr >= vm_end_gap(prev)))
- return addr;
- }
-
info.length = len;
info.low_limit = mm->mmap_base;
info.high_limit = mmap_end;
@@ -685,27 +714,14 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
unsigned long len, unsigned long pgoff,
unsigned long flags, vm_flags_t vm_flags)
{
- struct vm_area_struct *vma, *prev;
struct mm_struct *mm = current->mm;
struct vm_unmapped_area_info info = {};
const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
- /* requested length too big for entire address space */
- if (len > mmap_end - mmap_min_addr)
- return -ENOMEM;
-
- if (flags & MAP_FIXED)
- return addr;
-
/* requesting a specific address */
- if (addr) {
- addr = PAGE_ALIGN(addr);
- vma = find_vma_prev(mm, addr, &prev);
- if (mmap_end - len >= addr && addr >= mmap_min_addr &&
- (!vma || addr + len <= vm_start_gap(vma)) &&
- (!prev || addr >= vm_end_gap(prev)))
- return addr;
- }
+ addr = generic_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
info.length = len;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 02/16] mm: x86: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 01/16] mm: Introduce generic_mmap_hint() Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 03/16] mm: arm: " Kalesh Singh
` (15 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce x86 arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Fallback to generic_mmap_hint() if an architecture doesn't
provide HAVE_ARCH_MMAP_HINT.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate most of the error handling in arch_mmap_hint().
- Fallback to generic_mmap_hint() if arch_mmap_hint() is not provided.
arch/x86/include/asm/pgtable_64.h | 1 +
arch/x86/kernel/sys_x86_64.c | 64 +++++++++++++++----------------
include/linux/sched/mm.h | 5 +++
mm/mmap.c | 9 +++++
4 files changed, 45 insertions(+), 34 deletions(-)
diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index d1426b64c1b9..4472fd0040c3 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -245,6 +245,7 @@ extern void cleanup_highmap(void);
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
#define PAGE_AGP PAGE_KERNEL_NOCACHE
#define HAVE_PAGE_AGP 1
diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
index 776ae6fa7f2d..008c6d19bd02 100644
--- a/arch/x86/kernel/sys_x86_64.c
+++ b/arch/x86/kernel/sys_x86_64.c
@@ -123,31 +123,44 @@ static inline unsigned long stack_guard_placement(vm_flags_t vm_flags)
return 0;
}
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ unsigned long begin, end;
+
+ find_start_end(addr, flags, &begin, &end);
+
+ /* requested length too big for entire address space */
+ if (len > end || len > TASK_SIZE)
+ return -ENOMEM;
+
+ /* No address checking. See comment at mmap_address_hint_valid() */
+ if (flags & MAP_FIXED)
+ return addr;
+
+ addr = PAGE_ALIGN(addr);
+
+ /* Fallback to VA space search? */
+ if (!mmap_address_hint_valid(addr, len))
+ return 0;
+
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
unsigned long
arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len,
unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags)
{
- struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma;
struct vm_unmapped_area_info info = {};
unsigned long begin, end;
- if (flags & MAP_FIXED)
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
return addr;
find_start_end(addr, flags, &begin, &end);
- if (len > end)
- return -ENOMEM;
-
- if (addr) {
- addr = PAGE_ALIGN(addr);
- vma = find_vma(mm, addr);
- if (end - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
-
info.length = len;
info.low_limit = begin;
info.high_limit = end;
@@ -168,34 +181,17 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr0,
unsigned long len, unsigned long pgoff,
unsigned long flags, vm_flags_t vm_flags)
{
- struct vm_area_struct *vma;
- struct mm_struct *mm = current->mm;
unsigned long addr = addr0;
struct vm_unmapped_area_info info = {};
- /* requested length too big for entire address space */
- if (len > TASK_SIZE)
- return -ENOMEM;
-
- /* No address checking. See comment at mmap_address_hint_valid() */
- if (flags & MAP_FIXED)
- return addr;
-
/* for MAP_32BIT mappings we force the legacy mmap base */
if (!in_32bit_syscall() && (flags & MAP_32BIT))
goto bottomup;
/* requesting a specific address */
- if (addr) {
- addr &= PAGE_MASK;
- if (!mmap_address_hint_valid(addr, len))
- goto get_unmapped_area;
-
- vma = find_vma(mm, addr);
- if (!vma || addr + len <= vm_start_gap(vma))
- return addr;
- }
-get_unmapped_area:
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
info.length = len;
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index edeec19d1708..f4143703f234 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -205,6 +205,11 @@ unsigned long generic_mmap_hint(struct file *filp, unsigned long addr,
unsigned long len, unsigned long pgoff,
unsigned long flags);
+/* See generic_mmap_hint() */
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags);
+
unsigned long
generic_get_unmapped_area(struct file *filp, unsigned long addr,
unsigned long len, unsigned long pgoff,
diff --git a/mm/mmap.c b/mm/mmap.c
index 382b4eac5406..76dd6acdf051 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -705,6 +705,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
}
#endif
+#ifndef HAVE_ARCH_MMAP_HINT
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+#endif
+
/*
* This mmap-allocator allocates new areas top-down from below the
* stack's low limit (the base):
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 03/16] mm: arm: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 01/16] mm: Introduce generic_mmap_hint() Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 02/16] mm: x86: Introduce arch_mmap_hint() Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 04/16] mm: alpha: " Kalesh Singh
` (14 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce arm arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/arm/include/asm/pgtable.h | 1 +
arch/arm/mm/mmap.c | 107 ++++++++++++++-------------------
2 files changed, 46 insertions(+), 62 deletions(-)
diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index be91e376df79..1433b3ff4caa 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -330,6 +330,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte)
*/
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
#endif /* !__ASSEMBLY__ */
diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
index 3dbb383c26d5..15e7e4348af7 100644
--- a/arch/arm/mm/mmap.c
+++ b/arch/arm/mm/mmap.c
@@ -17,6 +17,41 @@
((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \
(((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ bool aliasing = cache_is_vipt_aliasing();
+ bool do_align;
+
+ /* requested length too big for entire address space */
+ if (len > TASK_SIZE)
+ return -ENOMEM;
+
+ /*
+ * We enforce the MAP_FIXED case.
+ */
+ if (flags & MAP_FIXED) {
+ if (aliasing && flags & MAP_SHARED &&
+ (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
+ return -EINVAL;
+ return addr;
+ }
+
+ /*
+ * We only need to do colour alignment if either the I or D
+ * caches alias.
+ */
+ do_align = aliasing && (filp || (flags & MAP_SHARED));
+
+ if (do_align)
+ addr = COLOUR_ALIGN(addr, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
+
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
/*
* We need to ensure that shared mappings are correctly aligned to
* avoid aliasing issues with VIPT caches. We need to ensure that
@@ -32,42 +67,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
unsigned long flags, vm_flags_t vm_flags)
{
struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma;
- int do_align = 0;
- int aliasing = cache_is_vipt_aliasing();
struct vm_unmapped_area_info info = {};
+ bool aliasing = cache_is_vipt_aliasing();
+ bool do_align;
- /*
- * We only need to do colour alignment if either the I or D
- * caches alias.
- */
- if (aliasing)
- do_align = filp || (flags & MAP_SHARED);
-
- /*
- * We enforce the MAP_FIXED case.
- */
- if (flags & MAP_FIXED) {
- if (aliasing && flags & MAP_SHARED &&
- (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
- return -EINVAL;
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
return addr;
- }
-
- if (len > TASK_SIZE)
- return -ENOMEM;
- if (addr) {
- if (do_align)
- addr = COLOUR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
-
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+ do_align = aliasing && (filp || (flags & MAP_SHARED));
info.length = len;
info.low_limit = mm->mmap_base;
@@ -82,42 +90,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
const unsigned long len, const unsigned long pgoff,
const unsigned long flags, vm_flags_t vm_flags)
{
- struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
unsigned long addr = addr0;
- int do_align = 0;
- int aliasing = cache_is_vipt_aliasing();
struct vm_unmapped_area_info info = {};
+ bool aliasing = cache_is_vipt_aliasing();
+ bool do_align;
- /*
- * We only need to do colour alignment if either the I or D
- * caches alias.
- */
- if (aliasing)
- do_align = filp || (flags & MAP_SHARED);
-
- /* requested length too big for entire address space */
- if (len > TASK_SIZE)
- return -ENOMEM;
-
- if (flags & MAP_FIXED) {
- if (aliasing && flags & MAP_SHARED &&
- (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
- return -EINVAL;
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
return addr;
- }
- /* requesting a specific address */
- if (addr) {
- if (do_align)
- addr = COLOUR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+ do_align = aliasing && (filp || (flags & MAP_SHARED));
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
info.length = len;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 04/16] mm: alpha: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (2 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 03/16] mm: arm: " Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 05/16] mm: arc: Use generic_mmap_hint() Kalesh Singh
` (13 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce alpha arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- Consolidate error handling in arch_mmap_hint().
arch/alpha/include/asm/pgtable.h | 1 +
arch/alpha/kernel/osf_sys.c | 31 ++++++++++++++++++++-----------
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
index 635f0a5f5bbd..372885a01abd 100644
--- a/arch/alpha/include/asm/pgtable.h
+++ b/arch/alpha/include/asm/pgtable.h
@@ -362,5 +362,6 @@ extern void paging_init(void);
/* We have our own get_unmapped_area to cope with ADDR_LIMIT_32BIT. */
#define HAVE_ARCH_UNMAPPED_AREA
+#define HAVE_ARCH_MMAP_HINT
#endif /* _ALPHA_PGTABLE_H */
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 86185021f75a..308f832732dc 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1225,10 +1225,9 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
return vm_unmapped_area(&info);
}
-unsigned long
-arch_get_unmapped_area(struct file *filp, unsigned long addr,
- unsigned long len, unsigned long pgoff,
- unsigned long flags, vm_flags_t vm_flags)
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
{
unsigned long limit;
@@ -1241,8 +1240,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
if (len > limit)
return -ENOMEM;
- if (flags & MAP_FIXED)
- return addr;
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
+unsigned long
+arch_get_unmapped_area(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags, vm_flags_t vm_flags)
+{
+ unsigned long limit;
/* First, see if the given suggestion fits.
@@ -1253,12 +1259,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
That said, I can see the use in being able to suggest not
merely specific addresses, but regions of memory -- perhaps
this feature should be incorporated into all ports? */
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
- if (addr) {
- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
- if (addr != (unsigned long) -ENOMEM)
- return addr;
- }
+ /* "32 bit" actually means 31 bit, since pointers sign extend. */
+ if (current->personality & ADDR_LIMIT_32BIT)
+ limit = 0x80000000;
+ else
+ limit = TASK_SIZE;
/* Next, try allocating at TASK_UNMAPPED_BASE. */
addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 05/16] mm: arc: Use generic_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (3 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 04/16] mm: alpha: " Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-12 21:13 ` Liam R. Howlett
2024-12-11 23:27 ` [PATCH mm-unstable v2 06/16] mm: csky: Introduce arch_mmap_hint() Kalesh Singh
` (12 subsequent siblings)
17 siblings, 1 reply; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce arc arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/arc/include/asm/pgtable.h | 1 +
arch/arc/mm/mmap.c | 43 +++++++++++++++++-----------------
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/arch/arc/include/asm/pgtable.h b/arch/arc/include/asm/pgtable.h
index 4cf45a99fd79..af3210ea4888 100644
--- a/arch/arc/include/asm/pgtable.h
+++ b/arch/arc/include/asm/pgtable.h
@@ -28,6 +28,7 @@ extern pgd_t swapper_pg_dir[] __aligned(PAGE_SIZE);
/* to cope with aliasing VIPT cache */
#define HAVE_ARCH_UNMAPPED_AREA
+#define HAVE_ARCH_MMAP_HINT
#endif /* __ASSEMBLY__ */
diff --git a/arch/arc/mm/mmap.c b/arch/arc/mm/mmap.c
index 2185afe8d59f..df01d4d9964b 100644
--- a/arch/arc/mm/mmap.c
+++ b/arch/arc/mm/mmap.c
@@ -14,6 +14,26 @@
#include <asm/cacheflush.h>
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ if (len > TASK_SIZE)
+ return -ENOMEM;
+
+ /*
+ * We enforce the MAP_FIXED case.
+ */
+ if (flags & MAP_FIXED) {
+ if (flags & MAP_SHARED &&
+ (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
+ return -EINVAL;
+ return addr;
+ }
+
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
/*
* Ensure that shared mappings are correctly aligned to
* avoid aliasing issues with VIPT caches.
@@ -27,30 +47,11 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
unsigned long flags, vm_flags_t vm_flags)
{
struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma;
struct vm_unmapped_area_info info = {};
- /*
- * We enforce the MAP_FIXED case.
- */
- if (flags & MAP_FIXED) {
- if (flags & MAP_SHARED &&
- (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
- return -EINVAL;
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
return addr;
- }
-
- if (len > TASK_SIZE)
- return -ENOMEM;
-
- if (addr) {
- addr = PAGE_ALIGN(addr);
-
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
info.length = len;
info.low_limit = mm->mmap_base;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 06/16] mm: csky: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (4 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 05/16] mm: arc: Use generic_mmap_hint() Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-12 21:40 ` Liam R. Howlett
2024-12-11 23:27 ` [PATCH mm-unstable v2 07/16] mm: loongarch: " Kalesh Singh
` (11 subsequent siblings)
17 siblings, 1 reply; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce csky arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/csky/abiv1/inc/abi/pgtable-bits.h | 1 +
arch/csky/abiv1/mmap.c | 68 ++++++++++++++------------
2 files changed, 38 insertions(+), 31 deletions(-)
diff --git a/arch/csky/abiv1/inc/abi/pgtable-bits.h b/arch/csky/abiv1/inc/abi/pgtable-bits.h
index ae7a2f76dd42..c346a9fcb522 100644
--- a/arch/csky/abiv1/inc/abi/pgtable-bits.h
+++ b/arch/csky/abiv1/inc/abi/pgtable-bits.h
@@ -51,5 +51,6 @@
((offset) << 10)})
#define HAVE_ARCH_UNMAPPED_AREA
+#define HAVE_ARCH_MMAP_HINT
#endif /* __ASM_CSKY_PGTABLE_BITS_H */
diff --git a/arch/csky/abiv1/mmap.c b/arch/csky/abiv1/mmap.c
index 1047865e82a9..0c5c51a081e4 100644
--- a/arch/csky/abiv1/mmap.c
+++ b/arch/csky/abiv1/mmap.c
@@ -13,6 +13,39 @@
((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \
(((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ bool do_align;
+
+ if (len > TASK_SIZE)
+ return -ENOMEM;
+
+ /*
+ * We only need to do colour alignment if either the I or D
+ * caches alias.
+ */
+ do_align = filp || (flags & MAP_SHARED);
+
+ /*
+ * We enforce the MAP_FIXED case.
+ */
+ if (flags & MAP_FIXED) {
+ if (flags & MAP_SHARED &&
+ (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
+ return -EINVAL;
+ return addr;
+ }
+
+ if (do_align)
+ addr = COLOUR_ALIGN(addr, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
+
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
/*
* We need to ensure that shared mappings are correctly aligned to
* avoid aliasing issues with VIPT caches. We need to ensure that
@@ -27,8 +60,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
unsigned long flags, vm_flags_t vm_flags)
{
struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma;
- int do_align = 0;
+ bool do_align;
struct vm_unmapped_area_info info = {
.length = len,
.low_limit = mm->mmap_base,
@@ -36,37 +68,11 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
.align_offset = pgoff << PAGE_SHIFT
};
- /*
- * We only need to do colour alignment if either the I or D
- * caches alias.
- */
- do_align = filp || (flags & MAP_SHARED);
-
- /*
- * We enforce the MAP_FIXED case.
- */
- if (flags & MAP_FIXED) {
- if (flags & MAP_SHARED &&
- (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
- return -EINVAL;
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
return addr;
- }
-
- if (len > TASK_SIZE)
- return -ENOMEM;
-
- if (addr) {
- if (do_align)
- addr = COLOUR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
-
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+ do_align = filp || (flags & MAP_SHARED);
info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
return vm_unmapped_area(&info);
}
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 07/16] mm: loongarch: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (5 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 06/16] mm: csky: Introduce arch_mmap_hint() Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 08/16] mm: mips: Introduce arch_align_mmap_hint() Kalesh Singh
` (10 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce loongarch arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/loongarch/include/asm/pgtable.h | 1 +
arch/loongarch/mm/mmap.c | 49 +++++++++++++++-------------
2 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
index da346733a1da..326a6c4b7488 100644
--- a/arch/loongarch/include/asm/pgtable.h
+++ b/arch/loongarch/include/asm/pgtable.h
@@ -624,6 +624,7 @@ static inline long pmd_protnone(pmd_t pmd)
*/
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
#endif /* !__ASSEMBLY__ */
diff --git a/arch/loongarch/mm/mmap.c b/arch/loongarch/mm/mmap.c
index 914e82ff3f65..9e57bb27642f 100644
--- a/arch/loongarch/mm/mmap.c
+++ b/arch/loongarch/mm/mmap.c
@@ -17,15 +17,11 @@
enum mmap_allocation_direction {UP, DOWN};
-static unsigned long arch_get_unmapped_area_common(struct file *filp,
- unsigned long addr0, unsigned long len, unsigned long pgoff,
- unsigned long flags, enum mmap_allocation_direction dir)
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
{
- struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma;
- unsigned long addr = addr0;
- int do_color_align;
- struct vm_unmapped_area_info info = {};
+ bool do_color_align;
if (unlikely(len > TASK_SIZE))
return -ENOMEM;
@@ -45,22 +41,31 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
return addr;
}
- do_color_align = 0;
- if (filp || (flags & MAP_SHARED))
- do_color_align = 1;
+ do_color_align = filp || (flags & MAP_SHARED);
+
+ if (do_color_align)
+ addr = COLOUR_ALIGN(addr, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
+
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
+static unsigned long arch_get_unmapped_area_common(struct file *filp,
+ unsigned long addr0, unsigned long len, unsigned long pgoff,
+ unsigned long flags, enum mmap_allocation_direction dir)
+{
+ struct mm_struct *mm = current->mm;
+ unsigned long addr = addr0;
+ bool do_color_align;
+ struct vm_unmapped_area_info info = {};
/* requesting a specific address */
- if (addr) {
- if (do_color_align)
- addr = COLOUR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
-
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
+
+ do_color_align = filp || (flags & MAP_SHARED);
info.length = len;
info.align_mask = do_color_align ? (PAGE_MASK & SHM_ALIGN_MASK) : 0;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 08/16] mm: mips: Introduce arch_align_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (6 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 07/16] mm: loongarch: " Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 09/16] mm: parisc: " Kalesh Singh
` (9 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce mips arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/mips/include/asm/pgtable.h | 1 +
arch/mips/mm/mmap.c | 50 ++++++++++++++++++---------------
2 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
index c29a551eb0ca..837f25624369 100644
--- a/arch/mips/include/asm/pgtable.h
+++ b/arch/mips/include/asm/pgtable.h
@@ -766,5 +766,6 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
*/
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
#endif /* _ASM_PGTABLE_H */
diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
index 5d2a1225785b..ee9f675190f1 100644
--- a/arch/mips/mm/mmap.c
+++ b/arch/mips/mm/mmap.c
@@ -26,15 +26,11 @@ EXPORT_SYMBOL(shm_align_mask);
enum mmap_allocation_direction {UP, DOWN};
-static unsigned long arch_get_unmapped_area_common(struct file *filp,
- unsigned long addr0, unsigned long len, unsigned long pgoff,
- unsigned long flags, enum mmap_allocation_direction dir)
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
{
- struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma;
- unsigned long addr = addr0;
- int do_color_align;
- struct vm_unmapped_area_info info = {};
+ bool do_color_align;
if (unlikely(len > TASK_SIZE))
return -ENOMEM;
@@ -54,22 +50,32 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
return addr;
}
- do_color_align = 0;
- if (filp || (flags & MAP_SHARED))
- do_color_align = 1;
+ do_color_align = filp || (flags & MAP_SHARED);
+
+ if (do_color_align)
+ addr = COLOUR_ALIGN(addr, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
+
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
+
+static unsigned long arch_get_unmapped_area_common(struct file *filp,
+ unsigned long addr0, unsigned long len, unsigned long pgoff,
+ unsigned long flags, enum mmap_allocation_direction dir)
+{
+ struct mm_struct *mm = current->mm;
+ unsigned long addr = addr0;
+ struct vm_unmapped_area_info info = {};
+ bool do_color_align;
/* requesting a specific address */
- if (addr) {
- if (do_color_align)
- addr = COLOUR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
-
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
+
+ do_color_align = filp || (flags & MAP_SHARED);
info.length = len;
info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 09/16] mm: parisc: Introduce arch_align_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (7 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 08/16] mm: mips: Introduce arch_align_mmap_hint() Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 10/16] mm: s390: Use generic_mmap_hint() Kalesh Singh
` (8 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce parisc arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/parisc/include/asm/pgtable.h | 1 +
arch/parisc/kernel/sys_parisc.c | 53 +++++++++++++++++--------------
2 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
index babf65751e81..73987357c78e 100644
--- a/arch/parisc/include/asm/pgtable.h
+++ b/arch/parisc/include/asm/pgtable.h
@@ -505,6 +505,7 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
#define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
index f852fe274abe..c1702d481e33 100644
--- a/arch/parisc/kernel/sys_parisc.c
+++ b/arch/parisc/kernel/sys_parisc.c
@@ -96,24 +96,16 @@ unsigned long mmap_upper_limit(struct rlimit *rlim_stack)
enum mmap_allocation_direction {UP, DOWN};
-static unsigned long arch_get_unmapped_area_common(struct file *filp,
- unsigned long addr, unsigned long len, unsigned long pgoff,
- unsigned long flags, enum mmap_allocation_direction dir)
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
{
- struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma, *prev;
unsigned long filp_pgoff;
- int do_color_align;
- struct vm_unmapped_area_info info = {
- .length = len
- };
+ bool do_color_align;
if (unlikely(len > TASK_SIZE))
return -ENOMEM;
- do_color_align = 0;
- if (filp || (flags & MAP_SHARED))
- do_color_align = 1;
filp_pgoff = GET_FILP_PGOFF(filp);
if (flags & MAP_FIXED) {
@@ -128,18 +120,33 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
return addr;
}
- if (addr) {
- if (do_color_align)
- addr = COLOR_ALIGN(addr, filp_pgoff, pgoff);
- else
- addr = PAGE_ALIGN(addr);
+ do_color_align = filp || (flags & MAP_SHARED);
- vma = find_vma_prev(mm, addr, &prev);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)) &&
- (!prev || addr >= vm_end_gap(prev)))
- return addr;
- }
+ if (do_color_align)
+ addr = COLOR_ALIGN(addr, filp_pgoff, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
+
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
+static unsigned long arch_get_unmapped_area_common(struct file *filp,
+ unsigned long addr, unsigned long len, unsigned long pgoff,
+ unsigned long flags, enum mmap_allocation_direction dir)
+{
+ struct mm_struct *mm = current->mm;
+ unsigned long filp_pgoff;
+ bool do_color_align;
+ struct vm_unmapped_area_info info = {
+ .length = len
+ };
+
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
+
+ filp_pgoff = GET_FILP_PGOFF(filp);
+ do_color_align = filp || (flags & MAP_SHARED);
info.align_mask = do_color_align ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
info.align_offset = shared_align_offset(filp_pgoff, pgoff);
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 10/16] mm: s390: Use generic_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (8 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 09/16] mm: parisc: " Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 11/16] mm: sh: Introduce arch_mmap_hint() Kalesh Singh
` (7 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce s390 arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/s390/include/asm/pgtable.h | 1 +
arch/s390/mm/mmap.c | 51 +++++++++++++++------------------
2 files changed, 24 insertions(+), 28 deletions(-)
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 48268095b0a3..eaecb558ab9b 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1997,6 +1997,7 @@ extern void s390_reset_cmma(struct mm_struct *mm);
/* s390 has a private copy of get unmapped area to deal with cache synonyms */
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
#define pmd_pgtable(pmd) \
((pgtable_t)__va(pmd_val(pmd) & -sizeof(pte_t)*PTRS_PER_PTE))
diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
index 33f3504be90b..8afb046605c9 100644
--- a/arch/s390/mm/mmap.c
+++ b/arch/s390/mm/mmap.c
@@ -83,28 +83,33 @@ static int get_align_mask(struct file *filp, unsigned long flags)
return 0;
}
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ /* requested length too big for entire address space */
+ if (len > TASK_SIZE - mmap_min_addr)
+ return -ENOMEM;
+
+ if (flags & MAP_FIXED)
+ return addr;
+
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
unsigned long len, unsigned long pgoff,
unsigned long flags, vm_flags_t vm_flags)
{
struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma;
struct vm_unmapped_area_info info = {};
- if (len > TASK_SIZE - mmap_min_addr)
- return -ENOMEM;
-
- if (flags & MAP_FIXED)
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (IS_ERR_VALUE(addr))
+ return addr;
+ if (addr)
goto check_asce_limit;
- if (addr) {
- addr = PAGE_ALIGN(addr);
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- goto check_asce_limit;
- }
-
info.length = len;
info.low_limit = mm->mmap_base;
info.high_limit = TASK_SIZE;
@@ -123,25 +128,15 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, unsigned long ad
unsigned long len, unsigned long pgoff,
unsigned long flags, vm_flags_t vm_flags)
{
- struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
struct vm_unmapped_area_info info = {};
- /* requested length too big for entire address space */
- if (len > TASK_SIZE - mmap_min_addr)
- return -ENOMEM;
-
- if (flags & MAP_FIXED)
- goto check_asce_limit;
-
/* requesting a specific address */
- if (addr) {
- addr = PAGE_ALIGN(addr);
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- goto check_asce_limit;
- }
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (IS_ERR_VALUE(addr))
+ return addr;
+ if (addr)
+ goto check_asce_limit;
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
info.length = len;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 11/16] mm: sh: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (9 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 10/16] mm: s390: Use generic_mmap_hint() Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 12/16] mm: sparc32: " Kalesh Singh
` (6 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce sh arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/sh/include/asm/pgtable.h | 1 +
arch/sh/mm/mmap.c | 83 ++++++++++++++---------------------
2 files changed, 33 insertions(+), 51 deletions(-)
diff --git a/arch/sh/include/asm/pgtable.h b/arch/sh/include/asm/pgtable.h
index 729f5c6225fb..072dbe038808 100644
--- a/arch/sh/include/asm/pgtable.h
+++ b/arch/sh/include/asm/pgtable.h
@@ -149,5 +149,6 @@ static inline bool pte_access_permitted(pte_t pte, bool write)
/* arch/sh/mm/mmap.c */
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
#endif /* __ASM_SH_PGTABLE_H */
diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
index c442734d9b0c..ebda962e8c4e 100644
--- a/arch/sh/mm/mmap.c
+++ b/arch/sh/mm/mmap.c
@@ -51,14 +51,14 @@ static inline unsigned long COLOUR_ALIGN(unsigned long addr,
return base + off;
}
-unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
- unsigned long len, unsigned long pgoff, unsigned long flags,
- vm_flags_t vm_flags)
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
{
- struct mm_struct *mm = current->mm;
- struct vm_area_struct *vma;
- int do_colour_align;
- struct vm_unmapped_area_info info = {};
+ bool do_colour_align;
+
+ if (unlikely(len > TASK_SIZE))
+ return -ENOMEM;
if (flags & MAP_FIXED) {
/* We do not accept a shared mapping if it would violate
@@ -70,24 +70,29 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
return addr;
}
- if (unlikely(len > TASK_SIZE))
- return -ENOMEM;
+ do_colour_align = filp || (flags & MAP_SHARED);
- do_colour_align = 0;
- if (filp || (flags & MAP_SHARED))
- do_colour_align = 1;
+ if (do_colour_align)
+ addr = COLOUR_ALIGN(addr, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
- if (addr) {
- if (do_colour_align)
- addr = COLOUR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+
+unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff, unsigned long flags,
+ vm_flags_t vm_flags)
+{
+ struct vm_unmapped_area_info info = {};
+ bool do_colour_align;
+
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
+
+ do_colour_align = filp || (flags & MAP_SHARED);
info.length = len;
info.low_limit = TASK_UNMAPPED_BASE;
@@ -102,41 +107,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
const unsigned long len, const unsigned long pgoff,
const unsigned long flags, vm_flags_t vm_flags)
{
- struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
unsigned long addr = addr0;
- int do_colour_align;
struct vm_unmapped_area_info info = {};
+ bool do_colour_align;
- if (flags & MAP_FIXED) {
- /* We do not accept a shared mapping if it would violate
- * cache aliasing constraints.
- */
- if ((flags & MAP_SHARED) &&
- ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask))
- return -EINVAL;
+ /* requesting a specific address */
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
return addr;
- }
- if (unlikely(len > TASK_SIZE))
- return -ENOMEM;
-
- do_colour_align = 0;
- if (filp || (flags & MAP_SHARED))
- do_colour_align = 1;
-
- /* requesting a specific address */
- if (addr) {
- if (do_colour_align)
- addr = COLOUR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
-
- vma = find_vma(mm, addr);
- if (TASK_SIZE - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+ do_colour_align = filp || (flags & MAP_SHARED);
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
info.length = len;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 12/16] mm: sparc32: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (10 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 11/16] mm: sh: Introduce arch_mmap_hint() Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 13/16] mm: sparc64: " Kalesh Singh
` (5 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce sparc32 arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
If a sufficiently sized hole doesn't exist at the hint address,
fallback to searching the entire valid VA space instead of only
the VA space above the hint address.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/sparc/include/asm/pgtable_32.h | 1 +
arch/sparc/kernel/sys_sparc_32.c | 33 +++++++++++++++++++----------
2 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
index 62bcafe38b1f..95084c4d0b01 100644
--- a/arch/sparc/include/asm/pgtable_32.h
+++ b/arch/sparc/include/asm/pgtable_32.h
@@ -437,6 +437,7 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma,
/* We provide our own get_unmapped_area to cope with VA holes for userland */
#define HAVE_ARCH_UNMAPPED_AREA
+#define HAVE_ARCH_MMAP_HINT
#define pmd_pgtable(pmd) ((pgtable_t)__pmd_page(pmd))
diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
index fb31bc0c5b48..0cc717755417 100644
--- a/arch/sparc/kernel/sys_sparc_32.c
+++ b/arch/sparc/kernel/sys_sparc_32.c
@@ -40,13 +40,17 @@ SYSCALL_DEFINE0(getpagesize)
return PAGE_SIZE; /* Possibly older binaries want 8192 on sun4's? */
}
-unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags)
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
{
- struct vm_unmapped_area_info info = {};
- bool file_hugepage = false;
+ bool file_hugepage;
+
+ /* See asm-sparc/uaccess.h */
+ if (len > TASK_SIZE - PAGE_SIZE)
+ return -ENOMEM;
- if (filp && is_file_hugepages(filp))
- file_hugepage = true;
+ file_hugepage = filp && is_file_hugepages(filp);
if (flags & MAP_FIXED) {
/* We do not accept a shared mapping if it would violate
@@ -58,14 +62,21 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
return addr;
}
- /* See asm-sparc/uaccess.h */
- if (len > TASK_SIZE - PAGE_SIZE)
- return -ENOMEM;
- if (!addr)
- addr = TASK_UNMAPPED_BASE;
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
+unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len,
+ unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags)
+{
+ struct vm_unmapped_area_info info = {};
+ bool file_hugepage = false;
+
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
info.length = len;
- info.low_limit = addr;
+ info.low_limit = TASK_UNMAPPED_BASE;
info.high_limit = TASK_SIZE;
if (!file_hugepage) {
info.align_mask = (flags & MAP_SHARED) ?
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 13/16] mm: sparc64: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (11 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 12/16] mm: sparc32: " Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 14/16] mm: xtensa: " Kalesh Singh
` (4 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce sparc64 arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/sparc/include/asm/pgtable_64.h | 1 +
arch/sparc/kernel/sys_sparc_64.c | 96 +++++++++++------------------
2 files changed, 37 insertions(+), 60 deletions(-)
diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
index 2b7f358762c1..f24a4eb2777b 100644
--- a/arch/sparc/include/asm/pgtable_64.h
+++ b/arch/sparc/include/asm/pgtable_64.h
@@ -1148,6 +1148,7 @@ static inline bool pte_access_permitted(pte_t pte, bool write)
*/
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
/* We provide a special get_unmapped_area for framebuffer mmaps to try and use
* the largest alignment possible such that larget PTEs can be used.
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index c5a284df7b41..e44d55b30a84 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -98,17 +98,19 @@ static unsigned long get_align_mask(struct file *filp, unsigned long flags)
return 0;
}
-unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags)
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
{
- struct mm_struct *mm = current->mm;
- struct vm_area_struct * vma;
- unsigned long task_size = TASK_SIZE;
- int do_color_align;
- struct vm_unmapped_area_info info = {};
- bool file_hugepage = false;
+ unsigned long task_size;
+ bool do_color_align;
+ bool file_hugepage;
- if (filp && is_file_hugepages(filp))
- file_hugepage = true;
+ task_size = test_thread_flag(TIF_32BIT) ? STACK_TOP32 : TASK_SIZE;
+ if (unlikely(len > task_size || len >= VA_EXCLUDE_START))
+ return -ENOMEM;
+
+ file_hugepage = filp && is_file_hugepages(filp);
if (flags & MAP_FIXED) {
/* We do not accept a shared mapping if it would violate
@@ -120,26 +122,29 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
return addr;
}
- if (test_thread_flag(TIF_32BIT))
- task_size = STACK_TOP32;
- if (unlikely(len > task_size || len >= VA_EXCLUDE_START))
- return -ENOMEM;
+ do_color_align = (filp || (flags & MAP_SHARED)) && !file_hugepage;
- do_color_align = 0;
- if ((filp || (flags & MAP_SHARED)) && !file_hugepage)
- do_color_align = 1;
+ if (do_color_align)
+ addr = COLOR_ALIGN(addr, pgoff);
+ else
+ addr = PAGE_ALIGN(addr);
- if (addr) {
- if (do_color_align)
- addr = COLOR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
- vma = find_vma(mm, addr);
- if (task_size - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len,
+ unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags)
+{
+ struct vm_unmapped_area_info info = {};
+ unsigned long task_size;
+ bool file_hugepage;
+
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
+
+ task_size = test_thread_flag(TIF_32BIT) ? STACK_TOP32 : TASK_SIZE;
+ file_hugepage = filp && is_file_hugepages(filp);
info.length = len;
info.low_limit = TASK_UNMAPPED_BASE;
@@ -164,49 +169,20 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
const unsigned long len, const unsigned long pgoff,
const unsigned long flags, vm_flags_t vm_flags)
{
- struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
- unsigned long task_size = STACK_TOP32;
unsigned long addr = addr0;
- int do_color_align;
struct vm_unmapped_area_info info = {};
- bool file_hugepage = false;
+ bool file_hugepage;
/* This should only ever run for 32-bit processes. */
BUG_ON(!test_thread_flag(TIF_32BIT));
- if (filp && is_file_hugepages(filp))
- file_hugepage = true;
-
- if (flags & MAP_FIXED) {
- /* We do not accept a shared mapping if it would violate
- * cache aliasing constraints.
- */
- if (!file_hugepage && (flags & MAP_SHARED) &&
- ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
- return -EINVAL;
- return addr;
- }
-
- if (unlikely(len > task_size))
- return -ENOMEM;
-
- do_color_align = 0;
- if ((filp || (flags & MAP_SHARED)) && !file_hugepage)
- do_color_align = 1;
-
/* requesting a specific address */
- if (addr) {
- if (do_color_align)
- addr = COLOR_ALIGN(addr, pgoff);
- else
- addr = PAGE_ALIGN(addr);
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
- vma = find_vma(mm, addr);
- if (task_size - len >= addr &&
- (!vma || addr + len <= vm_start_gap(vma)))
- return addr;
- }
+ file_hugepage = filp && is_file_hugepages(filp);
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
info.length = len;
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 14/16] mm: xtensa: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (12 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 13/16] mm: sparc64: " Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 15/16] mm: powerpc: " Kalesh Singh
` (3 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce xtensa arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
If a sufficiently sized hole doesn't exist at the hint address,
fallback to searching the entire valid VA space instead of only
the VA space above the hint address.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
Changes in v2:
- MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
special case of the hint addr being "enforced", per Yang Shi.
- Consolidate error handling in arch_mmap_hint().
arch/xtensa/kernel/syscall.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/arch/xtensa/kernel/syscall.c b/arch/xtensa/kernel/syscall.c
index dc54f854c2f5..6bbe10c2a633 100644
--- a/arch/xtensa/kernel/syscall.c
+++ b/arch/xtensa/kernel/syscall.c
@@ -54,12 +54,12 @@ asmlinkage long xtensa_fadvise64_64(int fd, int advice,
}
#ifdef CONFIG_MMU
-unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
- unsigned long len, unsigned long pgoff, unsigned long flags,
- vm_flags_t vm_flags)
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
{
- struct vm_area_struct *vmm;
- struct vma_iterator vmi;
+ if (len > TASK_SIZE)
+ return -ENOMEM;
if (flags & MAP_FIXED) {
/* We do not accept a shared mapping if it would violate
@@ -71,16 +71,27 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
return addr;
}
- if (len > TASK_SIZE)
- return -ENOMEM;
- if (!addr)
- addr = TASK_UNMAPPED_BASE;
-
if (flags & MAP_SHARED)
addr = COLOUR_ALIGN(addr, pgoff);
else
addr = PAGE_ALIGN(addr);
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+}
+
+unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff, unsigned long flags,
+ vm_flags_t vm_flags)
+{
+ struct vm_area_struct *vmm;
+ struct vma_iterator vmi;
+
+ addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
+ if (addr)
+ return addr;
+
+ addr = TASK_UNMAPPED_BASE;
+
vma_iter_init(&vmi, current->mm, addr);
for_each_vma(vmi, vmm) {
/* At this point: (addr < vmm->vm_end). */
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 15/16] mm: powerpc: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (13 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 14/16] mm: xtensa: " Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 16/16] mm: Respect mmap hint before THP alignment if allocation is possible Kalesh Singh
` (2 subsequent siblings)
17 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Introduce powerpc arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
This is a preparatory patch, no functional change is introduced.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
arch/powerpc/include/asm/book3s/64/slice.h | 1 +
arch/powerpc/mm/book3s64/slice.c | 31 ++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/arch/powerpc/include/asm/book3s/64/slice.h b/arch/powerpc/include/asm/book3s/64/slice.h
index 5fbe18544cbd..89f629080e90 100644
--- a/arch/powerpc/include/asm/book3s/64/slice.h
+++ b/arch/powerpc/include/asm/book3s/64/slice.h
@@ -10,6 +10,7 @@
#endif
#define HAVE_ARCH_UNMAPPED_AREA
#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
+#define HAVE_ARCH_MMAP_HINT
#endif
#define SLICE_LOW_SHIFT 28
diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c
index bc9a39821d1c..b4067c57c778 100644
--- a/arch/powerpc/mm/book3s64/slice.c
+++ b/arch/powerpc/mm/book3s64/slice.c
@@ -647,6 +647,37 @@ static int file_to_psize(struct file *file)
}
#endif
+static unsigned long slice_mmap_hint(unsigned long addr, unsigned long len,
+ unsigned long flags, unsigned int psize)
+{
+ unsigned long hint_addr = slice_get_unmapped_area(addr, len, flags, psize, 0);
+
+ if (IS_ERR_VALUE(hint_addr) || hint_addr == PAGE_ALIGN(addr))
+ return hint_addr;
+
+ return 0;
+}
+
+unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
+ unsigned long len, unsigned long pgoff,
+ unsigned long flags)
+{
+ unsigned int psize;
+
+ if (!addr)
+ return 0;
+
+ if (radix_enabled())
+ return generic_mmap_hint(filp, addr, len, pgoff, flags);
+
+ if (filp && is_file_hugepages(filp))
+ psize = file_to_psize(filp);
+ else
+ psize = mm_ctx_user_psize(¤t->mm->context);
+
+ return slice_mmap_hint(addr, len, flags, psize);
+}
+
unsigned long arch_get_unmapped_area(struct file *filp,
unsigned long addr,
unsigned long len,
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH mm-unstable v2 16/16] mm: Respect mmap hint before THP alignment if allocation is possible
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (14 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 15/16] mm: powerpc: " Kalesh Singh
@ 2024-12-11 23:27 ` Kalesh Singh
2024-12-12 20:11 ` Yang Shi
2024-12-12 21:02 ` [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Liam R. Howlett
2024-12-12 22:01 ` Matthew Wilcox
17 siblings, 1 reply; 31+ messages in thread
From: Kalesh Singh @ 2024-12-11 23:27 UTC (permalink / raw)
To: akpm, vbabka, yang, riel, david, minchan, jyescas
Cc: linux, tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Kalesh Singh
Commit 249608ee4713 ("mm: respect mmap hint address when aligning for THP")
fallsback to PAGE_SIZE alignment instead of THP alignment
for anonymous mapping as long as a hint address is provided by the user
-- even if we weren't able to allocate the unmapped area at the hint
address in the end.
This was done to address the immediate regression in anonymous mappings
where the hint address were being ignored in some cases; due to commit
efa7df3e3bb5 ("mm: align larger anonymous mappings on THP boundaries").
It was later pointed out that this issue also existed for file-backed
mappings from file systems that use thp_get_unmapped_area() for their
.get_unmapped_area() file operation.
The same fix was not applied for file-backed mappings since it would
mean any mmap requests that provide a hint address would be only
PAGE_SIZE-aligned regardless of whether allocation was successful at
the hint address or not.
Instead, use arch_mmap_hint() to first attempt allocation at the hint
address and fallback to THP alignment if there isn't sufficient VA space
to satisfy the allocation at the hint address.
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
mm/huge_memory.c | 17 ++++++++++-------
mm/mmap.c | 1 -
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 2da5520bfe24..426761a30aff 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1097,6 +1097,16 @@ static unsigned long __thp_get_unmapped_area(struct file *filp,
loff_t off_align = round_up(off, size);
unsigned long len_pad, ret, off_sub;
+ /*
+ * If allocation at the address hint succeeds; respect the hint and
+ * don't try to align to THP boundary;
+ *
+ * Or if an the requested extent is invalid return the error immediately.
+ */
+ addr = arch_mmap_hint(filp, addr, len, off, flags);
+ if (addr)
+ return addr;
+
if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall())
return 0;
@@ -1117,13 +1127,6 @@ static unsigned long __thp_get_unmapped_area(struct file *filp,
if (IS_ERR_VALUE(ret))
return 0;
- /*
- * Do not try to align to THP boundary if allocation at the address
- * hint succeeds.
- */
- if (ret == addr)
- return addr;
-
off_sub = (off - ret) & (size - 1);
if (test_bit(MMF_TOPDOWN, ¤t->mm->flags) && !off_sub)
diff --git a/mm/mmap.c b/mm/mmap.c
index 76dd6acdf051..3286fdff26f2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -814,7 +814,6 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
if (get_area) {
addr = get_area(file, addr, len, pgoff, flags);
} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && !file
- && !addr /* no hint */
&& IS_ALIGNED(len, PMD_SIZE)) {
/* Ensures that larger anonymous mappings are THP aligned. */
addr = thp_get_unmapped_area_vmflags(file, addr, len,
--
2.47.0.338.g60cca15819-goog
^ permalink raw reply related [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 01/16] mm: Introduce generic_mmap_hint()
2024-12-11 23:27 ` [PATCH mm-unstable v2 01/16] mm: Introduce generic_mmap_hint() Kalesh Singh
@ 2024-12-12 20:08 ` Yang Shi
0 siblings, 0 replies; 31+ messages in thread
From: Yang Shi @ 2024-12-12 20:08 UTC (permalink / raw)
To: Kalesh Singh
Cc: akpm, vbabka, yang, riel, david, minchan, jyescas, linux,
tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm
On Wed, Dec 11, 2024 at 3:28 PM Kalesh Singh <kaleshsingh@google.com> wrote:
>
> Consolidate the hint searches from both directions (topdown and
> bottomup) into generic_mmap_hint().
>
> No functional change is introduced.
>
> Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
> ---
>
> Changes in v2:
> - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
> special case of the hint addr being "enforced", per Yang Shi.
> - Consolidate error handling in arch_mmap_hint().
Reviewed-by: Yang Shi <shy828301@gmail.com>
>
> include/linux/sched/mm.h | 4 +++
> mm/mmap.c | 76 ++++++++++++++++++++++++----------------
> 2 files changed, 50 insertions(+), 30 deletions(-)
>
> diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
> index 928a626725e6..edeec19d1708 100644
> --- a/include/linux/sched/mm.h
> +++ b/include/linux/sched/mm.h
> @@ -201,6 +201,10 @@ unsigned long mm_get_unmapped_area_vmflags(struct mm_struct *mm,
> unsigned long flags,
> vm_flags_t vm_flags);
>
> +unsigned long generic_mmap_hint(struct file *filp, unsigned long addr,
> + unsigned long len, unsigned long pgoff,
> + unsigned long flags);
> +
> unsigned long
> generic_get_unmapped_area(struct file *filp, unsigned long addr,
> unsigned long len, unsigned long pgoff,
> diff --git a/mm/mmap.c b/mm/mmap.c
> index df9154b15ef9..382b4eac5406 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -620,6 +620,47 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info)
> return addr;
> }
>
> +/*
> + * Look up unmapped area at the requested hint addr
> + *
> + * NOTE: MAP_FIXED is also handled here since it's a special case of
> + * enforcing the hint address.
> + *
> + * Returns:
> + * ERR_VALUE: If the requested mapping is not valid
> + * 0: If there isn't a sufficiently large hole at the hint addr.
> + * addr: If sufficient VA space is available at the hint address;
> + * or MAP_FIXED was specified.
> + */
> +unsigned long generic_mmap_hint(struct file *filp, unsigned long addr,
> + unsigned long len, unsigned long pgoff,
> + unsigned long flags)
> +{
> + struct mm_struct *mm = current->mm;
> + struct vm_area_struct *vma, *prev;
> + const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
> +
> + /* requested length too big for entire address space */
> + if (len > mmap_end - mmap_min_addr)
> + return -ENOMEM;
> +
> + if (flags & MAP_FIXED)
> + return addr;
> +
> + if (!addr)
> + return 0;
> +
> + addr = PAGE_ALIGN(addr);
> + vma = find_vma_prev(mm, addr, &prev);
> + if (mmap_end - len >= addr && addr >= mmap_min_addr &&
> + (!vma || addr + len <= vm_start_gap(vma)) &&
> + (!prev || addr >= vm_end_gap(prev)))
> + return addr;
> +
> + /* Fallback to VA space search */
> + return 0;
> +}
> +
> /* Get an address range which is currently unmapped.
> * For shmat() with addr=0.
> *
> @@ -637,25 +678,13 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr,
> unsigned long flags, vm_flags_t vm_flags)
> {
> struct mm_struct *mm = current->mm;
> - struct vm_area_struct *vma, *prev;
> struct vm_unmapped_area_info info = {};
> const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
>
> - if (len > mmap_end - mmap_min_addr)
> - return -ENOMEM;
> -
> - if (flags & MAP_FIXED)
> + addr = generic_mmap_hint(filp, addr, len, pgoff, flags);
> + if (addr)
> return addr;
>
> - if (addr) {
> - addr = PAGE_ALIGN(addr);
> - vma = find_vma_prev(mm, addr, &prev);
> - if (mmap_end - len >= addr && addr >= mmap_min_addr &&
> - (!vma || addr + len <= vm_start_gap(vma)) &&
> - (!prev || addr >= vm_end_gap(prev)))
> - return addr;
> - }
> -
> info.length = len;
> info.low_limit = mm->mmap_base;
> info.high_limit = mmap_end;
> @@ -685,27 +714,14 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
> unsigned long len, unsigned long pgoff,
> unsigned long flags, vm_flags_t vm_flags)
> {
> - struct vm_area_struct *vma, *prev;
> struct mm_struct *mm = current->mm;
> struct vm_unmapped_area_info info = {};
> const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
>
> - /* requested length too big for entire address space */
> - if (len > mmap_end - mmap_min_addr)
> - return -ENOMEM;
> -
> - if (flags & MAP_FIXED)
> - return addr;
> -
> /* requesting a specific address */
> - if (addr) {
> - addr = PAGE_ALIGN(addr);
> - vma = find_vma_prev(mm, addr, &prev);
> - if (mmap_end - len >= addr && addr >= mmap_min_addr &&
> - (!vma || addr + len <= vm_start_gap(vma)) &&
> - (!prev || addr >= vm_end_gap(prev)))
> - return addr;
> - }
> + addr = generic_mmap_hint(filp, addr, len, pgoff, flags);
> + if (addr)
> + return addr;
>
> info.flags = VM_UNMAPPED_AREA_TOPDOWN;
> info.length = len;
> --
> 2.47.0.338.g60cca15819-goog
>
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 16/16] mm: Respect mmap hint before THP alignment if allocation is possible
2024-12-11 23:27 ` [PATCH mm-unstable v2 16/16] mm: Respect mmap hint before THP alignment if allocation is possible Kalesh Singh
@ 2024-12-12 20:11 ` Yang Shi
0 siblings, 0 replies; 31+ messages in thread
From: Yang Shi @ 2024-12-12 20:11 UTC (permalink / raw)
To: Kalesh Singh
Cc: akpm, vbabka, yang, riel, david, minchan, jyescas, linux,
tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm
On Wed, Dec 11, 2024 at 3:31 PM Kalesh Singh <kaleshsingh@google.com> wrote:
>
> Commit 249608ee4713 ("mm: respect mmap hint address when aligning for THP")
> fallsback to PAGE_SIZE alignment instead of THP alignment
> for anonymous mapping as long as a hint address is provided by the user
> -- even if we weren't able to allocate the unmapped area at the hint
> address in the end.
>
> This was done to address the immediate regression in anonymous mappings
> where the hint address were being ignored in some cases; due to commit
> efa7df3e3bb5 ("mm: align larger anonymous mappings on THP boundaries").
>
> It was later pointed out that this issue also existed for file-backed
> mappings from file systems that use thp_get_unmapped_area() for their
> .get_unmapped_area() file operation.
>
> The same fix was not applied for file-backed mappings since it would
> mean any mmap requests that provide a hint address would be only
> PAGE_SIZE-aligned regardless of whether allocation was successful at
> the hint address or not.
>
> Instead, use arch_mmap_hint() to first attempt allocation at the hint
> address and fallback to THP alignment if there isn't sufficient VA space
> to satisfy the allocation at the hint address.
>
> Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
Reviewed-by: Yang Shi <shy828301@gmail.com>
> ---
> mm/huge_memory.c | 17 ++++++++++-------
> mm/mmap.c | 1 -
> 2 files changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 2da5520bfe24..426761a30aff 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -1097,6 +1097,16 @@ static unsigned long __thp_get_unmapped_area(struct file *filp,
> loff_t off_align = round_up(off, size);
> unsigned long len_pad, ret, off_sub;
>
> + /*
> + * If allocation at the address hint succeeds; respect the hint and
> + * don't try to align to THP boundary;
> + *
> + * Or if an the requested extent is invalid return the error immediately.
> + */
> + addr = arch_mmap_hint(filp, addr, len, off, flags);
> + if (addr)
> + return addr;
> +
> if (!IS_ENABLED(CONFIG_64BIT) || in_compat_syscall())
> return 0;
>
> @@ -1117,13 +1127,6 @@ static unsigned long __thp_get_unmapped_area(struct file *filp,
> if (IS_ERR_VALUE(ret))
> return 0;
>
> - /*
> - * Do not try to align to THP boundary if allocation at the address
> - * hint succeeds.
> - */
> - if (ret == addr)
> - return addr;
> -
> off_sub = (off - ret) & (size - 1);
>
> if (test_bit(MMF_TOPDOWN, ¤t->mm->flags) && !off_sub)
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 76dd6acdf051..3286fdff26f2 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -814,7 +814,6 @@ __get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
> if (get_area) {
> addr = get_area(file, addr, len, pgoff, flags);
> } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && !file
> - && !addr /* no hint */
> && IS_ALIGNED(len, PMD_SIZE)) {
> /* Ensures that larger anonymous mappings are THP aligned. */
> addr = thp_get_unmapped_area_vmflags(file, addr, len,
> --
> 2.47.0.338.g60cca15819-goog
>
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (15 preceding siblings ...)
2024-12-11 23:27 ` [PATCH mm-unstable v2 16/16] mm: Respect mmap hint before THP alignment if allocation is possible Kalesh Singh
@ 2024-12-12 21:02 ` Liam R. Howlett
2024-12-12 22:51 ` Lorenzo Stoakes
2024-12-12 22:01 ` Matthew Wilcox
17 siblings, 1 reply; 31+ messages in thread
From: Liam R. Howlett @ 2024-12-12 21:02 UTC (permalink / raw)
To: Kalesh Singh
Cc: akpm, lorenzo.stoakes, vbabka, yang, riel, david, minchan,
jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm
+ Lorenzo
Can you please Cc the people listed in the maintainers on the files you
are submitting against? You seemed to Cc everyone but the mmap.c file
maintainers?
* Kalesh Singh <kaleshsingh@google.com> [241211 18:28]:
> Hi all,
>
> This is v2 othe the arch_mmap_hint() series.
>
> Changes in v2:
> - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
> special case of the hint addr being "enforced", per Yang Shi.
> - Consolidate most of the error handling in arch_mmap_hint().
> - Patch 16 ("mm: Fallback to generic_mmap_hint()") was folded into
> Patch 2 ("mm: x86: Introduce arch_mmap_hint()")
>
> v1: https://lore.kernel.org/r/20241210024119.2488608-1-kaleshsingh@google.com/
>
> =======
>
> This series introduces arch_mmap_hint() to handle allocating VA space
> for the hint address.
Why? Could we get more details in your cover letter please? This
entire email has as much detail as the subject line.
I don't want more arch_ anything. If we can do this in a more generic
way, then we should.
>
> Patches 1-16 introduce this new helper and Patch 17 uses it to fix the
> issue of mmap hint being ignored in some cases due to THP alignment [1]
>
> [1] https://lore.kernel.org/r/20241118214650.3667577-1-kaleshsingh@google.com/
>
> Thanks,
> Kalesh
>
>
> Kalesh Singh (16):
> mm: Introduce generic_mmap_hint()
> mm: x86: Introduce arch_mmap_hint()
> mm: arm: Introduce arch_mmap_hint()
> mm: alpha: Introduce arch_mmap_hint()
> mm: arc: Use generic_mmap_hint()
> mm: csky: Introduce arch_mmap_hint()
> mm: loongarch: Introduce arch_mmap_hint()
> mm: mips: Introduce arch_align_mmap_hint()
> mm: parisc: Introduce arch_align_mmap_hint()
> mm: s390: Use generic_mmap_hint()
> mm: sh: Introduce arch_mmap_hint()
> mm: sparc32: Introduce arch_mmap_hint()
> mm: sparc64: Introduce arch_mmap_hint()
> mm: xtensa: Introduce arch_mmap_hint()
> mm: powerpc: Introduce arch_mmap_hint()
> mm: Respect mmap hint before THP alignment if allocation is possible
>
> arch/alpha/include/asm/pgtable.h | 1 +
> arch/alpha/kernel/osf_sys.c | 31 +++---
> arch/arc/include/asm/pgtable.h | 1 +
> arch/arc/mm/mmap.c | 43 +++++----
> arch/arm/include/asm/pgtable.h | 1 +
> arch/arm/mm/mmap.c | 107 +++++++++------------
> arch/csky/abiv1/inc/abi/pgtable-bits.h | 1 +
> arch/csky/abiv1/mmap.c | 68 +++++++------
> arch/loongarch/include/asm/pgtable.h | 1 +
> arch/loongarch/mm/mmap.c | 49 +++++-----
> arch/mips/include/asm/pgtable.h | 1 +
> arch/mips/mm/mmap.c | 50 +++++-----
> arch/parisc/include/asm/pgtable.h | 1 +
> arch/parisc/kernel/sys_parisc.c | 53 +++++-----
> arch/powerpc/include/asm/book3s/64/slice.h | 1 +
> arch/powerpc/mm/book3s64/slice.c | 31 ++++++
> arch/s390/include/asm/pgtable.h | 1 +
> arch/s390/mm/mmap.c | 51 +++++-----
> arch/sh/include/asm/pgtable.h | 1 +
> arch/sh/mm/mmap.c | 83 ++++++----------
> arch/sparc/include/asm/pgtable_32.h | 1 +
> arch/sparc/include/asm/pgtable_64.h | 1 +
> arch/sparc/kernel/sys_sparc_32.c | 33 ++++---
> arch/sparc/kernel/sys_sparc_64.c | 96 +++++++-----------
> arch/x86/include/asm/pgtable_64.h | 1 +
> arch/x86/kernel/sys_x86_64.c | 64 ++++++------
> arch/xtensa/kernel/syscall.c | 31 ++++--
> include/linux/sched/mm.h | 9 ++
> mm/huge_memory.c | 17 ++--
> mm/mmap.c | 86 +++++++++++------
> 30 files changed, 491 insertions(+), 424 deletions(-)
>
> --
> 2.47.0.338.g60cca15819-goog
>
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 05/16] mm: arc: Use generic_mmap_hint()
2024-12-11 23:27 ` [PATCH mm-unstable v2 05/16] mm: arc: Use generic_mmap_hint() Kalesh Singh
@ 2024-12-12 21:13 ` Liam R. Howlett
0 siblings, 0 replies; 31+ messages in thread
From: Liam R. Howlett @ 2024-12-12 21:13 UTC (permalink / raw)
To: Kalesh Singh
Cc: akpm, vbabka, lorenzo.stoakes, yang, riel, david, minchan,
jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm
* Kalesh Singh <kaleshsingh@google.com> [241211 18:28]:
> Introduce arc arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
> This is a preparatory patch, no functional change is introduced.
You have changed the order of the map fixed check and the len check.
I *think* what you have done is correct, but your comment is certainly
wrong.
Your generic call also has more checks than exist in this version of the
code - which, again is probably good, but a functional change surely?
>
> Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
> ---
>
> Changes in v2:
> - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
> special case of the hint addr being "enforced", per Yang Shi.
> - Consolidate error handling in arch_mmap_hint().
>
> arch/arc/include/asm/pgtable.h | 1 +
> arch/arc/mm/mmap.c | 43 +++++++++++++++++-----------------
> 2 files changed, 23 insertions(+), 21 deletions(-)
>
> diff --git a/arch/arc/include/asm/pgtable.h b/arch/arc/include/asm/pgtable.h
> index 4cf45a99fd79..af3210ea4888 100644
> --- a/arch/arc/include/asm/pgtable.h
> +++ b/arch/arc/include/asm/pgtable.h
> @@ -28,6 +28,7 @@ extern pgd_t swapper_pg_dir[] __aligned(PAGE_SIZE);
>
> /* to cope with aliasing VIPT cache */
> #define HAVE_ARCH_UNMAPPED_AREA
> +#define HAVE_ARCH_MMAP_HINT
>
> #endif /* __ASSEMBLY__ */
>
> diff --git a/arch/arc/mm/mmap.c b/arch/arc/mm/mmap.c
> index 2185afe8d59f..df01d4d9964b 100644
> --- a/arch/arc/mm/mmap.c
> +++ b/arch/arc/mm/mmap.c
> @@ -14,6 +14,26 @@
>
> #include <asm/cacheflush.h>
>
> +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
> + unsigned long len, unsigned long pgoff,
> + unsigned long flags)
> +{
> + if (len > TASK_SIZE)
> + return -ENOMEM;
> +
> + /*
> + * We enforce the MAP_FIXED case.
> + */
> + if (flags & MAP_FIXED) {
> + if (flags & MAP_SHARED &&
> + (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
> + return -EINVAL;
> + return addr;
> + }
> +
> + return generic_mmap_hint(filp, addr, len, pgoff, flags);
> +}
> +
> /*
> * Ensure that shared mappings are correctly aligned to
> * avoid aliasing issues with VIPT caches.
> @@ -27,30 +47,11 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
> unsigned long flags, vm_flags_t vm_flags)
> {
> struct mm_struct *mm = current->mm;
> - struct vm_area_struct *vma;
> struct vm_unmapped_area_info info = {};
>
> - /*
> - * We enforce the MAP_FIXED case.
> - */
> - if (flags & MAP_FIXED) {
> - if (flags & MAP_SHARED &&
> - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
> - return -EINVAL;
> + addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
> + if (addr)
> return addr;
> - }
> -
> - if (len > TASK_SIZE)
> - return -ENOMEM;
> -
> - if (addr) {
> - addr = PAGE_ALIGN(addr);
> -
> - vma = find_vma(mm, addr);
> - if (TASK_SIZE - len >= addr &&
> - (!vma || addr + len <= vm_start_gap(vma)))
> - return addr;
> - }
>
> info.length = len;
> info.low_limit = mm->mmap_base;
> --
> 2.47.0.338.g60cca15819-goog
>
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 06/16] mm: csky: Introduce arch_mmap_hint()
2024-12-11 23:27 ` [PATCH mm-unstable v2 06/16] mm: csky: Introduce arch_mmap_hint() Kalesh Singh
@ 2024-12-12 21:40 ` Liam R. Howlett
2024-12-13 1:39 ` Andrew Morton
0 siblings, 1 reply; 31+ messages in thread
From: Liam R. Howlett @ 2024-12-12 21:40 UTC (permalink / raw)
To: Kalesh Singh
Cc: akpm, lorenzo.stoakes, vbabka, yang, riel, david, minchan,
jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm
* Kalesh Singh <kaleshsingh@google.com> [241211 18:28]:
> Introduce csky arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
> This is a preparatory patch, no functional change is introduced.
This also looks like it has changed the validation order and potentially
introduced functional changes?
All these stem from the same cloned code (sparc32 iirc), but were not
updated when the cloned code was updated. This is why I am against
arch_* code. We should find a better way to unify the code so that
there is nothing different. You seem to have gotten some of the shared
code together, but some still exists.
In the addresses, there are upper and lower limits, and sometimes
"colours". Could we not just define the upper/lower limits in each arch
and if colour is used? Maybe this is complicated with 32/64 handled
both in the 64 bit code.
Is there any plan to unite this code further?
We have had errors for many years in cloned but not updated code. I
really wish there was more information in the cover letter on what is
going on here. I'd like to try and reduce the arch_ code to, basically
nothing.
I was also disappointed that I wasn't Cc'ed because I've spent a lot of
time in this code and this area. I am probably the last one to crawl
through and change any of this.
>
> Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
> ---
>
> Changes in v2:
> - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
> special case of the hint addr being "enforced", per Yang Shi.
> - Consolidate error handling in arch_mmap_hint().
>
> arch/csky/abiv1/inc/abi/pgtable-bits.h | 1 +
> arch/csky/abiv1/mmap.c | 68 ++++++++++++++------------
> 2 files changed, 38 insertions(+), 31 deletions(-)
>
> diff --git a/arch/csky/abiv1/inc/abi/pgtable-bits.h b/arch/csky/abiv1/inc/abi/pgtable-bits.h
> index ae7a2f76dd42..c346a9fcb522 100644
> --- a/arch/csky/abiv1/inc/abi/pgtable-bits.h
> +++ b/arch/csky/abiv1/inc/abi/pgtable-bits.h
> @@ -51,5 +51,6 @@
> ((offset) << 10)})
>
> #define HAVE_ARCH_UNMAPPED_AREA
> +#define HAVE_ARCH_MMAP_HINT
>
> #endif /* __ASM_CSKY_PGTABLE_BITS_H */
> diff --git a/arch/csky/abiv1/mmap.c b/arch/csky/abiv1/mmap.c
> index 1047865e82a9..0c5c51a081e4 100644
> --- a/arch/csky/abiv1/mmap.c
> +++ b/arch/csky/abiv1/mmap.c
> @@ -13,6 +13,39 @@
> ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \
> (((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
>
> +unsigned long arch_mmap_hint(struct file *filp, unsigned long addr,
> + unsigned long len, unsigned long pgoff,
> + unsigned long flags)
> +{
> + bool do_align;
> +
> + if (len > TASK_SIZE)
> + return -ENOMEM;
> +
> + /*
> + * We only need to do colour alignment if either the I or D
> + * caches alias.
> + */
> + do_align = filp || (flags & MAP_SHARED);
> +
> + /*
> + * We enforce the MAP_FIXED case.
> + */
> + if (flags & MAP_FIXED) {
> + if (flags & MAP_SHARED &&
> + (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
> + return -EINVAL;
> + return addr;
> + }
> +
> + if (do_align)
> + addr = COLOUR_ALIGN(addr, pgoff);
> + else
> + addr = PAGE_ALIGN(addr);
> +
> + return generic_mmap_hint(filp, addr, len, pgoff, flags);
> +}
> +
> /*
> * We need to ensure that shared mappings are correctly aligned to
> * avoid aliasing issues with VIPT caches. We need to ensure that
> @@ -27,8 +60,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
> unsigned long flags, vm_flags_t vm_flags)
> {
> struct mm_struct *mm = current->mm;
> - struct vm_area_struct *vma;
> - int do_align = 0;
> + bool do_align;
> struct vm_unmapped_area_info info = {
> .length = len,
> .low_limit = mm->mmap_base,
> @@ -36,37 +68,11 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
> .align_offset = pgoff << PAGE_SHIFT
> };
>
> - /*
> - * We only need to do colour alignment if either the I or D
> - * caches alias.
> - */
This seems like useful information to keep around?
> - do_align = filp || (flags & MAP_SHARED);
> -
> - /*
> - * We enforce the MAP_FIXED case.
> - */
> - if (flags & MAP_FIXED) {
> - if (flags & MAP_SHARED &&
> - (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
> - return -EINVAL;
> + addr = arch_mmap_hint(filp, addr, len, pgoff, flags);
> + if (addr)
> return addr;
> - }
> -
> - if (len > TASK_SIZE)
> - return -ENOMEM;
> -
> - if (addr) {
> - if (do_align)
> - addr = COLOUR_ALIGN(addr, pgoff);
> - else
> - addr = PAGE_ALIGN(addr);
> -
> - vma = find_vma(mm, addr);
> - if (TASK_SIZE - len >= addr &&
> - (!vma || addr + len <= vm_start_gap(vma)))
> - return addr;
> - }
>
> + do_align = filp || (flags & MAP_SHARED);
> info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
> return vm_unmapped_area(&info);
> }
> --
> 2.47.0.338.g60cca15819-goog
>
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
` (16 preceding siblings ...)
2024-12-12 21:02 ` [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Liam R. Howlett
@ 2024-12-12 22:01 ` Matthew Wilcox
17 siblings, 0 replies; 31+ messages in thread
From: Matthew Wilcox @ 2024-12-12 22:01 UTC (permalink / raw)
To: Kalesh Singh
Cc: akpm, vbabka, yang, riel, david, minchan, jyescas, linux,
tsbogend, James.Bottomley, ysato, dalias, glaubitz, davem,
andreas, tglx, bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas,
jason.andryuk, leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm
On Wed, Dec 11, 2024 at 03:27:38PM -0800, Kalesh Singh wrote:
> Hi all,
>
> This is v2 othe the arch_mmap_hint() series.
>
> Changes in v2:
> - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
> special case of the hint addr being "enforced", per Yang Shi.
> - Consolidate most of the error handling in arch_mmap_hint().
> - Patch 16 ("mm: Fallback to generic_mmap_hint()") was folded into
> Patch 2 ("mm: x86: Introduce arch_mmap_hint()")
>
> v1: https://lore.kernel.org/r/20241210024119.2488608-1-kaleshsingh@google.com/
>
> =======
>
> This series introduces arch_mmap_hint() to handle allocating VA space
> for the hint address.
But why? You're basically forcing me to read the entire series to
figure out what you're doing and why. I decline.
> Patches 1-16 introduce this new helper and Patch 17 uses it to fix the
> issue of mmap hint being ignored in some cases due to THP alignment [1]
>
> [1] https://lore.kernel.org/r/20241118214650.3667577-1-kaleshsingh@google.com/
>
> Thanks,
> Kalesh
>
>
> Kalesh Singh (16):
> mm: Introduce generic_mmap_hint()
> mm: x86: Introduce arch_mmap_hint()
> mm: arm: Introduce arch_mmap_hint()
> mm: alpha: Introduce arch_mmap_hint()
> mm: arc: Use generic_mmap_hint()
> mm: csky: Introduce arch_mmap_hint()
> mm: loongarch: Introduce arch_mmap_hint()
> mm: mips: Introduce arch_align_mmap_hint()
> mm: parisc: Introduce arch_align_mmap_hint()
> mm: s390: Use generic_mmap_hint()
> mm: sh: Introduce arch_mmap_hint()
> mm: sparc32: Introduce arch_mmap_hint()
> mm: sparc64: Introduce arch_mmap_hint()
> mm: xtensa: Introduce arch_mmap_hint()
> mm: powerpc: Introduce arch_mmap_hint()
> mm: Respect mmap hint before THP alignment if allocation is possible
>
> arch/alpha/include/asm/pgtable.h | 1 +
> arch/alpha/kernel/osf_sys.c | 31 +++---
> arch/arc/include/asm/pgtable.h | 1 +
> arch/arc/mm/mmap.c | 43 +++++----
> arch/arm/include/asm/pgtable.h | 1 +
> arch/arm/mm/mmap.c | 107 +++++++++------------
> arch/csky/abiv1/inc/abi/pgtable-bits.h | 1 +
> arch/csky/abiv1/mmap.c | 68 +++++++------
> arch/loongarch/include/asm/pgtable.h | 1 +
> arch/loongarch/mm/mmap.c | 49 +++++-----
> arch/mips/include/asm/pgtable.h | 1 +
> arch/mips/mm/mmap.c | 50 +++++-----
> arch/parisc/include/asm/pgtable.h | 1 +
> arch/parisc/kernel/sys_parisc.c | 53 +++++-----
> arch/powerpc/include/asm/book3s/64/slice.h | 1 +
> arch/powerpc/mm/book3s64/slice.c | 31 ++++++
> arch/s390/include/asm/pgtable.h | 1 +
> arch/s390/mm/mmap.c | 51 +++++-----
> arch/sh/include/asm/pgtable.h | 1 +
> arch/sh/mm/mmap.c | 83 ++++++----------
> arch/sparc/include/asm/pgtable_32.h | 1 +
> arch/sparc/include/asm/pgtable_64.h | 1 +
> arch/sparc/kernel/sys_sparc_32.c | 33 ++++---
> arch/sparc/kernel/sys_sparc_64.c | 96 +++++++-----------
> arch/x86/include/asm/pgtable_64.h | 1 +
> arch/x86/kernel/sys_x86_64.c | 64 ++++++------
> arch/xtensa/kernel/syscall.c | 31 ++++--
> include/linux/sched/mm.h | 9 ++
> mm/huge_memory.c | 17 ++--
> mm/mmap.c | 86 +++++++++++------
> 30 files changed, 491 insertions(+), 424 deletions(-)
>
> --
> 2.47.0.338.g60cca15819-goog
>
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-12 21:02 ` [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Liam R. Howlett
@ 2024-12-12 22:51 ` Lorenzo Stoakes
2024-12-13 1:36 ` Andrew Morton
0 siblings, 1 reply; 31+ messages in thread
From: Lorenzo Stoakes @ 2024-12-12 22:51 UTC (permalink / raw)
To: Liam R. Howlett, Kalesh Singh, akpm, vbabka, yang, riel, david,
minchan, jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm,
Jann Horn
NACK.
Resend this _as an RFC_, _with the correct maintainers and reviewers cc'd_.
You've fundamentally violated kernel process and etiquette. I'd be more
forgiving, but this is at v2 and you've not cc'd KEY people. Twice. This is
totally unacceptable. See [0] if you are unsure of how to do so.
You've also sent a 16 patch series (!) immediately prior to the holidays
(!!) introducing an arch hook (!!!), which is strictly something we want to
try to avoid or lessen in future, which you'd know, had you followed basic
kernel etiquette and process and cc'd us on v1.
Any discussion that will be had here with others we won't be cc'd on, it's
16 patches, this isn't workable.
I'm on holiday from next week, it's not really fair to put this all on Liam
immediately prior to Christmas, so let's just examine this as an RFC first.
I hate to think that I need to set lei rules to catch stuff like this, but
clearly, I do. I will be updating these to check on all relevant
files. Sigh.
[0]: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#select-the-recipients-for-your-patch
On Thu, Dec 12, 2024 at 04:02:31PM -0500, Liam R. Howlett wrote:
>
> + Lorenzo
>
> Can you please Cc the people listed in the maintainers on the files you
> are submitting against? You seemed to Cc everyone but the mmap.c file
> maintainers?
Thanks Liam.
Also +Jann, another reviewer Kalesh missed (he only got Vlastimil and
Andrew so 2/5... of those required...)
>
>
> * Kalesh Singh <kaleshsingh@google.com> [241211 18:28]:
> > Hi all,
> >
> > This is v2 othe the arch_mmap_hint() series.
> >
> > Changes in v2:
> > - MAP_FIXED case is also handled in arch_mmap_hint() since this is just a
> > special case of the hint addr being "enforced", per Yang Shi.
> > - Consolidate most of the error handling in arch_mmap_hint().
> > - Patch 16 ("mm: Fallback to generic_mmap_hint()") was folded into
> > Patch 2 ("mm: x86: Introduce arch_mmap_hint()")
> >
> > v1: https://lore.kernel.org/r/20241210024119.2488608-1-kaleshsingh@google.com/
> >
> > =======
> >
> > This series introduces arch_mmap_hint() to handle allocating VA space
> > for the hint address.
>
> Why? Could we get more details in your cover letter please? This
> entire email has as much detail as the subject line.
Yes the cover letter is ridiculously small for what that is doing.
>
> I don't want more arch_ anything. If we can do this in a more generic
> way, then we should.
ENTIRELY agreed.
>
> >
> > Patches 1-16 introduce this new helper and Patch 17 uses it to fix the
> > issue of mmap hint being ignored in some cases due to THP alignment [1]
> >
> > [1] https://lore.kernel.org/r/20241118214650.3667577-1-kaleshsingh@google.com/
> >
> > Thanks,
> > Kalesh
> >
> >
> > Kalesh Singh (16):
> > mm: Introduce generic_mmap_hint()
> > mm: x86: Introduce arch_mmap_hint()
> > mm: arm: Introduce arch_mmap_hint()
> > mm: alpha: Introduce arch_mmap_hint()
> > mm: arc: Use generic_mmap_hint()
> > mm: csky: Introduce arch_mmap_hint()
> > mm: loongarch: Introduce arch_mmap_hint()
> > mm: mips: Introduce arch_align_mmap_hint()
> > mm: parisc: Introduce arch_align_mmap_hint()
> > mm: s390: Use generic_mmap_hint()
> > mm: sh: Introduce arch_mmap_hint()
> > mm: sparc32: Introduce arch_mmap_hint()
> > mm: sparc64: Introduce arch_mmap_hint()
> > mm: xtensa: Introduce arch_mmap_hint()
> > mm: powerpc: Introduce arch_mmap_hint()
> > mm: Respect mmap hint before THP alignment if allocation is possible
> >
> > arch/alpha/include/asm/pgtable.h | 1 +
> > arch/alpha/kernel/osf_sys.c | 31 +++---
> > arch/arc/include/asm/pgtable.h | 1 +
> > arch/arc/mm/mmap.c | 43 +++++----
> > arch/arm/include/asm/pgtable.h | 1 +
> > arch/arm/mm/mmap.c | 107 +++++++++------------
> > arch/csky/abiv1/inc/abi/pgtable-bits.h | 1 +
> > arch/csky/abiv1/mmap.c | 68 +++++++------
> > arch/loongarch/include/asm/pgtable.h | 1 +
> > arch/loongarch/mm/mmap.c | 49 +++++-----
> > arch/mips/include/asm/pgtable.h | 1 +
> > arch/mips/mm/mmap.c | 50 +++++-----
> > arch/parisc/include/asm/pgtable.h | 1 +
> > arch/parisc/kernel/sys_parisc.c | 53 +++++-----
> > arch/powerpc/include/asm/book3s/64/slice.h | 1 +
> > arch/powerpc/mm/book3s64/slice.c | 31 ++++++
> > arch/s390/include/asm/pgtable.h | 1 +
> > arch/s390/mm/mmap.c | 51 +++++-----
> > arch/sh/include/asm/pgtable.h | 1 +
> > arch/sh/mm/mmap.c | 83 ++++++----------
> > arch/sparc/include/asm/pgtable_32.h | 1 +
> > arch/sparc/include/asm/pgtable_64.h | 1 +
> > arch/sparc/kernel/sys_sparc_32.c | 33 ++++---
> > arch/sparc/kernel/sys_sparc_64.c | 96 +++++++-----------
> > arch/x86/include/asm/pgtable_64.h | 1 +
> > arch/x86/kernel/sys_x86_64.c | 64 ++++++------
> > arch/xtensa/kernel/syscall.c | 31 ++++--
> > include/linux/sched/mm.h | 9 ++
> > mm/huge_memory.c | 17 ++--
> > mm/mmap.c | 86 +++++++++++------
> > 30 files changed, 491 insertions(+), 424 deletions(-)
Yuck. Is this copy/paste really necessary...
> >
> > --
> > 2.47.0.338.g60cca15819-goog
> >
> >
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-12 22:51 ` Lorenzo Stoakes
@ 2024-12-13 1:36 ` Andrew Morton
2024-12-13 8:59 ` Lorenzo Stoakes
0 siblings, 1 reply; 31+ messages in thread
From: Andrew Morton @ 2024-12-13 1:36 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Liam R. Howlett, Kalesh Singh, vbabka, yang, riel, david, minchan,
jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm,
Jann Horn
On Thu, 12 Dec 2024 22:51:34 +0000 Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
> You've fundamentally violated kernel process and etiquette. I'd be more
> forgiving, but this is at v2 and you've not cc'd KEY people. Twice. This is
> totally unacceptable. See [0] if you are unsure of how to do so.
This feels excessive to me. linux-mm averages a mere 140 mesages/day
and it seems reasonable to assume that key people are spending their 5
minutes to scroll through the email subjects.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 06/16] mm: csky: Introduce arch_mmap_hint()
2024-12-12 21:40 ` Liam R. Howlett
@ 2024-12-13 1:39 ` Andrew Morton
0 siblings, 0 replies; 31+ messages in thread
From: Andrew Morton @ 2024-12-13 1:39 UTC (permalink / raw)
To: Liam R. Howlett
Cc: Kalesh Singh, lorenzo.stoakes, vbabka, yang, riel, david, minchan,
jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm
On Thu, 12 Dec 2024 16:40:10 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote:
> * Kalesh Singh <kaleshsingh@google.com> [241211 18:28]:
> > Introduce csky arch_mmap_hint() and define HAVE_ARCH_MMAP_HINT.
> > This is a preparatory patch, no functional change is introduced.
>
> This also looks like it has changed the validation order and potentially
> introduced functional changes?
>
> All these stem from the same cloned code (sparc32 iirc), but were not
> updated when the cloned code was updated. This is why I am against
> arch_* code. We should find a better way to unify the code so that
> there is nothing different. You seem to have gotten some of the shared
> code together, but some still exists.
>
> In the addresses, there are upper and lower limits, and sometimes
> "colours". Could we not just define the upper/lower limits in each arch
> and if colour is used? Maybe this is complicated with 32/64 handled
> both in the 64 bit code.
>
> Is there any plan to unite this code further?
>
> We have had errors for many years in cloned but not updated code. I
> really wish there was more information in the cover letter on what is
> going on here. I'd like to try and reduce the arch_ code to, basically
> nothing.
>
> I was also disappointed that I wasn't Cc'ed because I've spent a lot of
> time in this code and this area. I am probably the last one to crawl
> through and change any of this.
Thanks, I removed this version of this series from mm-unstable.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-13 1:36 ` Andrew Morton
@ 2024-12-13 8:59 ` Lorenzo Stoakes
2024-12-13 15:06 ` Kalesh Singh
0 siblings, 1 reply; 31+ messages in thread
From: Lorenzo Stoakes @ 2024-12-13 8:59 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam R. Howlett, Kalesh Singh, vbabka, yang, riel, david, minchan,
jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm,
Jann Horn
On Thu, Dec 12, 2024 at 05:36:09PM -0800, Andrew Morton wrote:
> On Thu, 12 Dec 2024 22:51:34 +0000 Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
>
> > You've fundamentally violated kernel process and etiquette. I'd be more
> > forgiving, but this is at v2 and you've not cc'd KEY people. Twice. This is
> > totally unacceptable. See [0] if you are unsure of how to do so.
>
> This feels excessive to me. linux-mm averages a mere 140 mesages/day
> and it seems reasonable to assume that key people are spending their 5
> minutes to scroll through the email subjects.
In practice we did all miss it, and I don't think it's unreasonable to ask
people to run get_maintainers.pl to avoid this.
In any case, I truly do think this series works better as RFC, I mean Liam
has already voiced the kind of disagreements I share with it, and we need
to rethink how to approach it in general.
So if this is simply sent as RFC with the correct cc's (and ideally with
some review feedback applied - a better cover letter, etc.) then it makes
everything easier.
As mentioned the timing is unfortunate here, this is a series we really
want to make sure is properly reviewed before any chance of merge so again
this points to RFC being the way forward.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-13 8:59 ` Lorenzo Stoakes
@ 2024-12-13 15:06 ` Kalesh Singh
2024-12-13 15:16 ` Lorenzo Stoakes
0 siblings, 1 reply; 31+ messages in thread
From: Kalesh Singh @ 2024-12-13 15:06 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Andrew Morton, Liam R. Howlett, vbabka, yang, riel, david,
minchan, jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm,
Jann Horn
On Fri, Dec 13, 2024 at 4:00 AM Lorenzo Stoakes
<lorenzo.stoakes@oracle.com> wrote:
>
> On Thu, Dec 12, 2024 at 05:36:09PM -0800, Andrew Morton wrote:
> > On Thu, 12 Dec 2024 22:51:34 +0000 Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
> >
> > > You've fundamentally violated kernel process and etiquette. I'd be more
> > > forgiving, but this is at v2 and you've not cc'd KEY people. Twice. This is
> > > totally unacceptable. See [0] if you are unsure of how to do so.
> >
> > This feels excessive to me. linux-mm averages a mere 140 mesages/day
> > and it seems reasonable to assume that key people are spending their 5
> > minutes to scroll through the email subjects.
>
> In practice we did all miss it, and I don't think it's unreasonable to ask
> people to run get_maintainers.pl to avoid this.
>
> In any case, I truly do think this series works better as RFC, I mean Liam
> has already voiced the kind of disagreements I share with it, and we need
> to rethink how to approach it in general.
>
> So if this is simply sent as RFC with the correct cc's (and ideally with
> some review feedback applied - a better cover letter, etc.) then it makes
> everything easier.
>
> As mentioned the timing is unfortunate here, this is a series we really
> want to make sure is properly reviewed before any chance of merge so again
> this points to RFC being the way forward.
Hi everyone,
Sorry for the delayed response -- I was traveling and didn’t have
access to email.
Thank you for the feedback. I realize I missed some key reviewers in
the CC list for this patch.
When I ran get_maintainer.pl, it returned a large list of recipients.
To avoid over-CC’ing people (which has been an issue for me in the
past), I tried to trim it down to maintainers and a few others I
thought would be interested. Clearly, I got it wrong and missed some
key folks. That was not my intention, and I’ll make sure to fix it
when I resend the patch as an RFC.
On the technical side, Liam is right that the copy-pasted arch code
has inconsistencies (missing checks, order of checks, ...). I agree
there’s room for further consolidation. I’ll take another stab at it
and resend it as an RFC with an updated cover letter, as Lorenzo and
others suggested.
Thanks,
Kalesh
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-13 15:06 ` Kalesh Singh
@ 2024-12-13 15:16 ` Lorenzo Stoakes
2024-12-13 16:45 ` Liam R. Howlett
0 siblings, 1 reply; 31+ messages in thread
From: Lorenzo Stoakes @ 2024-12-13 15:16 UTC (permalink / raw)
To: Kalesh Singh
Cc: Andrew Morton, Liam R. Howlett, vbabka, yang, riel, david,
minchan, jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm,
Jann Horn
On Fri, Dec 13, 2024 at 10:06:55AM -0500, Kalesh Singh wrote:
> On Fri, Dec 13, 2024 at 4:00 AM Lorenzo Stoakes
> <lorenzo.stoakes@oracle.com> wrote:
> >
> > On Thu, Dec 12, 2024 at 05:36:09PM -0800, Andrew Morton wrote:
> > > On Thu, 12 Dec 2024 22:51:34 +0000 Lorenzo Stoakes <lorenzo.stoakes@oracle.com> wrote:
> > >
> > > > You've fundamentally violated kernel process and etiquette. I'd be more
> > > > forgiving, but this is at v2 and you've not cc'd KEY people. Twice. This is
> > > > totally unacceptable. See [0] if you are unsure of how to do so.
> > >
> > > This feels excessive to me. linux-mm averages a mere 140 mesages/day
> > > and it seems reasonable to assume that key people are spending their 5
> > > minutes to scroll through the email subjects.
> >
> > In practice we did all miss it, and I don't think it's unreasonable to ask
> > people to run get_maintainers.pl to avoid this.
> >
> > In any case, I truly do think this series works better as RFC, I mean Liam
> > has already voiced the kind of disagreements I share with it, and we need
> > to rethink how to approach it in general.
> >
> > So if this is simply sent as RFC with the correct cc's (and ideally with
> > some review feedback applied - a better cover letter, etc.) then it makes
> > everything easier.
> >
> > As mentioned the timing is unfortunate here, this is a series we really
> > want to make sure is properly reviewed before any chance of merge so again
> > this points to RFC being the way forward.
>
> Hi everyone,
>
> Sorry for the delayed response -- I was traveling and didn’t have
> access to email.
Ack.
>
> Thank you for the feedback. I realize I missed some key reviewers in
> the CC list for this patch.
> When I ran get_maintainer.pl, it returned a large list of recipients.
> To avoid over-CC’ing people (which has been an issue for me in the
> past), I tried to trim it down to maintainers and a few others I
> thought would be interested. Clearly, I got it wrong and missed some
> key folks. That was not my intention, and I’ll make sure to fix it
> when I resend the patch as an RFC.
Sure thanks :) Much appreciated. Sorry to be so curt there, just I think
important to underline.
We just want to make sure we can find a way to get this series sorted out
so we can get it merged in a form that makes sense overall, ultimately! :)
>
> On the technical side, Liam is right that the copy-pasted arch code
> has inconsistencies (missing checks, order of checks, ...). I agree
> there’s room for further consolidation. I’ll take another stab at it
> and resend it as an RFC with an updated cover letter, as Lorenzo and
> others suggested.
The most useful thing here as well to help us understand would be to write
more in the cover letter to expand on what it is you ultimately what to
achieve here - it seems like an extension on the existing THP work on a
per-arch basis (I may be wrong)? So adding more detail would be super
useful here! :)
We do hope to avoid arch hooks if at all possible explicitly for the reason
that they can be applied at unfortunate times in terms of locking/whether
the objects in question are fully/partially instantiated, VMA visibility
etc. etc. based on having had issues in these areas before.
Also if a hook means 'anything' can happen at a certain point, it means we
can't make any assumptions about what has/hasn't and have to account for
anything which seriously complicates things.
Ideally we'd find a means to achieve the same thing while also exposing us
as little as possible to what may be mutated.
>
> Thanks,
> Kalesh
Thanks!
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-13 15:16 ` Lorenzo Stoakes
@ 2024-12-13 16:45 ` Liam R. Howlett
2024-12-13 17:08 ` Kalesh Singh
0 siblings, 1 reply; 31+ messages in thread
From: Liam R. Howlett @ 2024-12-13 16:45 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: Kalesh Singh, Andrew Morton, vbabka, yang, riel, david, minchan,
jyescas, linux, tsbogend, James.Bottomley, ysato, dalias,
glaubitz, davem, andreas, tglx, bp, dave.hansen, x86, chris,
jcmvbkbc, bhelgaas, jason.andryuk, leitao, linux-alpha,
linux-kernel, linux-snps-arc, linux-arm-kernel, linux-csky,
loongarch, linux-mips, linux-parisc, linuxppc-dev, linux-s390,
linux-sh, sparclinux, linux-mm, kernel-team, android-mm,
Jann Horn
* Lorenzo Stoakes <lorenzo.stoakes@oracle.com> [241213 10:16]:
> On Fri, Dec 13, 2024 at 10:06:55AM -0500, Kalesh Singh wrote:
> > On Fri, Dec 13, 2024 at 4:00 AM Lorenzo Stoakes
> > <lorenzo.stoakes@oracle.com> wrote:
...
> >
> > On the technical side, Liam is right that the copy-pasted arch code
> > has inconsistencies (missing checks, order of checks, ...). I agree
> > there’s room for further consolidation. I’ll take another stab at it
> > and resend it as an RFC with an updated cover letter, as Lorenzo and
> > others suggested.
Thanks. Can you please include what platforms you have tested in your
cover letter (and level of testing - booting, running something, etc).
If you have not tested them, then it might be worth it to have it as an
RFC to point this out - at least initially. Some of these are very
difficult to set up for testing, but it is also possible that you did
that and the maintainers/people who usually test these things will
assume it's fine if you don't spell out what's going on.
>
> The most useful thing here as well to help us understand would be to write
> more in the cover letter to expand on what it is you ultimately what to
> achieve here - it seems like an extension on the existing THP work on a
> per-arch basis (I may be wrong)? So adding more detail would be super
> useful here! :)
>
> We do hope to avoid arch hooks if at all possible explicitly for the reason
> that they can be applied at unfortunate times in terms of locking/whether
> the objects in question are fully/partially instantiated, VMA visibility
> etc. etc. based on having had issues in these areas before.
>
> Also if a hook means 'anything' can happen at a certain point, it means we
> can't make any assumptions about what has/hasn't and have to account for
> anything which seriously complicates things.
>
> Ideally we'd find a means to achieve the same thing while also exposing us
> as little as possible to what may be mutated.
Yes, I'm not sure of what your plans are, but I would like to see all of
these custom functions removed, if at all possible.
Thanks,
Liam
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint()
2024-12-13 16:45 ` Liam R. Howlett
@ 2024-12-13 17:08 ` Kalesh Singh
0 siblings, 0 replies; 31+ messages in thread
From: Kalesh Singh @ 2024-12-13 17:08 UTC (permalink / raw)
To: Liam R. Howlett, Lorenzo Stoakes, Kalesh Singh, Andrew Morton,
vbabka, yang, riel, david, minchan, jyescas, linux, tsbogend,
James.Bottomley, ysato, dalias, glaubitz, davem, andreas, tglx,
bp, dave.hansen, x86, chris, jcmvbkbc, bhelgaas, jason.andryuk,
leitao, linux-alpha, linux-kernel, linux-snps-arc,
linux-arm-kernel, linux-csky, loongarch, linux-mips, linux-parisc,
linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-mm,
kernel-team, android-mm, Jann Horn
On Fri, Dec 13, 2024 at 11:45 AM 'Liam R. Howlett' via kernel-team
<kernel-team@android.com> wrote:
>
> * Lorenzo Stoakes <lorenzo.stoakes@oracle.com> [241213 10:16]:
> > On Fri, Dec 13, 2024 at 10:06:55AM -0500, Kalesh Singh wrote:
> > > On Fri, Dec 13, 2024 at 4:00 AM Lorenzo Stoakes
> > > <lorenzo.stoakes@oracle.com> wrote:
>
> ...
>
> > >
> > > On the technical side, Liam is right that the copy-pasted arch code
> > > has inconsistencies (missing checks, order of checks, ...). I agree
> > > there’s room for further consolidation. I’ll take another stab at it
> > > and resend it as an RFC with an updated cover letter, as Lorenzo and
> > > others suggested.
>
> Thanks. Can you please include what platforms you have tested in your
> cover letter (and level of testing - booting, running something, etc).
>
> If you have not tested them, then it might be worth it to have it as an
> RFC to point this out - at least initially. Some of these are very
> difficult to set up for testing, but it is also possible that you did
> that and the maintainers/people who usually test these things will
> assume it's fine if you don't spell out what's going on.
>
I build-tested most of these except (csky and loongarch) and ran
android runtime (ART) tests on arm64 and x86. I can try to spin up a
few of the others and will add it to the description.
> >
> > The most useful thing here as well to help us understand would be to write
> > more in the cover letter to expand on what it is you ultimately what to
> > achieve here - it seems like an extension on the existing THP work on a
> > per-arch basis (I may be wrong)? So adding more detail would be super
> > useful here! :)
> >
> > We do hope to avoid arch hooks if at all possible explicitly for the reason
> > that they can be applied at unfortunate times in terms of locking/whether
> > the objects in question are fully/partially instantiated, VMA visibility
> > etc. etc. based on having had issues in these areas before.
> >
> > Also if a hook means 'anything' can happen at a certain point, it means we
> > can't make any assumptions about what has/hasn't and have to account for
> > anything which seriously complicates things.
> >
> > Ideally we'd find a means to achieve the same thing while also exposing us
> > as little as possible to what may be mutated.
>
>
> Yes, I'm not sure of what your plans are, but I would like to see all of
> these custom functions removed, if at all possible.
Initially I think we can remove the mmap hint portion of the logic;
and follow up with removing arch_get_unmapped_area[_topdown](). Some
of those may not make sense to consolidate e.g. powerpc's
slice_get_unmapped_area() which doesn't share much in common with the
rest.
Thanks,
Kalesh
>
> Thanks,
> Liam
>
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com.
>
^ permalink raw reply [flat|nested] 31+ messages in thread
end of thread, other threads:[~2024-12-13 17:08 UTC | newest]
Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11 23:27 [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 01/16] mm: Introduce generic_mmap_hint() Kalesh Singh
2024-12-12 20:08 ` Yang Shi
2024-12-11 23:27 ` [PATCH mm-unstable v2 02/16] mm: x86: Introduce arch_mmap_hint() Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 03/16] mm: arm: " Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 04/16] mm: alpha: " Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 05/16] mm: arc: Use generic_mmap_hint() Kalesh Singh
2024-12-12 21:13 ` Liam R. Howlett
2024-12-11 23:27 ` [PATCH mm-unstable v2 06/16] mm: csky: Introduce arch_mmap_hint() Kalesh Singh
2024-12-12 21:40 ` Liam R. Howlett
2024-12-13 1:39 ` Andrew Morton
2024-12-11 23:27 ` [PATCH mm-unstable v2 07/16] mm: loongarch: " Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 08/16] mm: mips: Introduce arch_align_mmap_hint() Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 09/16] mm: parisc: " Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 10/16] mm: s390: Use generic_mmap_hint() Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 11/16] mm: sh: Introduce arch_mmap_hint() Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 12/16] mm: sparc32: " Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 13/16] mm: sparc64: " Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 14/16] mm: xtensa: " Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 15/16] mm: powerpc: " Kalesh Singh
2024-12-11 23:27 ` [PATCH mm-unstable v2 16/16] mm: Respect mmap hint before THP alignment if allocation is possible Kalesh Singh
2024-12-12 20:11 ` Yang Shi
2024-12-12 21:02 ` [PATCH mm-unstable v2 00/16] mm: Introduce arch_mmap_hint() Liam R. Howlett
2024-12-12 22:51 ` Lorenzo Stoakes
2024-12-13 1:36 ` Andrew Morton
2024-12-13 8:59 ` Lorenzo Stoakes
2024-12-13 15:06 ` Kalesh Singh
2024-12-13 15:16 ` Lorenzo Stoakes
2024-12-13 16:45 ` Liam R. Howlett
2024-12-13 17:08 ` Kalesh Singh
2024-12-12 22:01 ` Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).