2019-06-19 05:12:31

by Alexandre Ghiti

[permalink] [raw]
Subject: [PATCH 0/8] Fix mmap base in bottom-up mmap

This series fixes the fallback of the top-down mmap: in case of
failure, a bottom-up scheme can be tried as a last resort between
the top-down mmap base and the stack, hoping for a large unused stack
limit.

Lots of architectures and even mm code start this fallback
at TASK_UNMAPPED_BASE, which is useless since the top-down scheme
already failed on the whole address space: instead, simply use
mmap_base.

Along the way, it allows to get rid of of mmap_legacy_base and
mmap_compat_legacy_base from mm_struct.

Note that arm and mips already implement this behaviour.

Alexandre Ghiti (8):
s390: Start fallback of top-down mmap at mm->mmap_base
sh: Start fallback of top-down mmap at mm->mmap_base
sparc: Start fallback of top-down mmap at mm->mmap_base
x86, hugetlbpage: Start fallback of top-down mmap at mm->mmap_base
mm: Start fallback top-down mmap at mm->mmap_base
parisc: Use mmap_base, not mmap_legacy_base, as low_limit for
bottom-up mmap
x86: Use mmap_*base, not mmap_*legacy_base, as low_limit for bottom-up
mmap
mm: Remove mmap_legacy_base and mmap_compat_legacy_code fields from
mm_struct

arch/parisc/kernel/sys_parisc.c | 8 +++-----
arch/s390/mm/mmap.c | 2 +-
arch/sh/mm/mmap.c | 2 +-
arch/sparc/kernel/sys_sparc_64.c | 2 +-
arch/sparc/mm/hugetlbpage.c | 2 +-
arch/x86/include/asm/elf.h | 2 +-
arch/x86/kernel/sys_x86_64.c | 4 ++--
arch/x86/mm/hugetlbpage.c | 7 ++++---
arch/x86/mm/mmap.c | 20 +++++++++-----------
include/linux/mm_types.h | 2 --
mm/debug.c | 4 ++--
mm/mmap.c | 2 +-
12 files changed, 26 insertions(+), 31 deletions(-)

--
2.20.1


2019-06-19 05:12:31

by Alexandre Ghiti

[permalink] [raw]
Subject: [PATCH 1/8] s390: Start fallback of top-down mmap at mm->mmap_base

In case of mmap failure in top-down mode, there is no need to go through
the whole address space again for the bottom-up fallback: the goal of this
fallback is to find, as a last resort, space between the top-down mmap base
and the stack, which is the only place not covered by the top-down mmap.

Signed-off-by: Alexandre Ghiti <[email protected]>
---
arch/s390/mm/mmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
index cbc718ba6d78..4a222969843b 100644
--- a/arch/s390/mm/mmap.c
+++ b/arch/s390/mm/mmap.c
@@ -166,7 +166,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
if (addr & ~PAGE_MASK) {
VM_BUG_ON(addr != -ENOMEM);
info.flags = 0;
- info.low_limit = TASK_UNMAPPED_BASE;
+ info.low_limit = mm->mmap_base;
info.high_limit = TASK_SIZE;
addr = vm_unmapped_area(&info);
if (addr & ~PAGE_MASK)
--
2.20.1

2019-06-19 05:13:27

by Alexandre Ghiti

[permalink] [raw]
Subject: [PATCH 3/8] sparc: Start fallback of top-down mmap at mm->mmap_base

In case of mmap failure in top-down mode, there is no need to go through
the whole address space again for the bottom-up fallback: the goal of this
fallback is to find, as a last resort, space between the top-down mmap base
and the stack, which is the only place not covered by the top-down mmap.

Signed-off-by: Alexandre Ghiti <[email protected]>
---
arch/sparc/kernel/sys_sparc_64.c | 2 +-
arch/sparc/mm/hugetlbpage.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index ccc88926bc00..ea1de1e5fa8d 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -206,7 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
if (addr & ~PAGE_MASK) {
VM_BUG_ON(addr != -ENOMEM);
info.flags = 0;
- info.low_limit = TASK_UNMAPPED_BASE;
+ info.low_limit = mm->mmap_base;
info.high_limit = STACK_TOP32;
addr = vm_unmapped_area(&info);
}
diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
index f78793a06bbd..9c67f805abc8 100644
--- a/arch/sparc/mm/hugetlbpage.c
+++ b/arch/sparc/mm/hugetlbpage.c
@@ -86,7 +86,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
if (addr & ~PAGE_MASK) {
VM_BUG_ON(addr != -ENOMEM);
info.flags = 0;
- info.low_limit = TASK_UNMAPPED_BASE;
+ info.low_limit = mm->mmap_base;
info.high_limit = STACK_TOP32;
addr = vm_unmapped_area(&info);
}
--
2.20.1

2019-06-19 05:15:05

by Alexandre Ghiti

[permalink] [raw]
Subject: [PATCH 4/8] x86, hugetlbpage: Start fallback of top-down mmap at mm->mmap_base

In case of mmap failure in top-down mode, there is no need to go through
the whole address space again for the bottom-up fallback: the goal of this
fallback is to find, as a last resort, space between the top-down mmap base
and the stack, which is the only place not covered by the top-down mmap.

Signed-off-by: Alexandre Ghiti <[email protected]>
---
arch/x86/mm/hugetlbpage.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
index fab095362c50..4b90339aef50 100644
--- a/arch/x86/mm/hugetlbpage.c
+++ b/arch/x86/mm/hugetlbpage.c
@@ -106,11 +106,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
{
struct hstate *h = hstate_file(file);
struct vm_unmapped_area_info info;
+ unsigned long mmap_base = get_mmap_base(0);

info.flags = VM_UNMAPPED_AREA_TOPDOWN;
info.length = len;
info.low_limit = PAGE_SIZE;
- info.high_limit = get_mmap_base(0);
+ info.high_limit = mmap_base;

/*
* If hint address is above DEFAULT_MAP_WINDOW, look for unmapped area
@@ -132,7 +133,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
if (addr & ~PAGE_MASK) {
VM_BUG_ON(addr != -ENOMEM);
info.flags = 0;
- info.low_limit = TASK_UNMAPPED_BASE;
+ info.low_limit = mmap_base;
info.high_limit = TASK_SIZE_LOW;
addr = vm_unmapped_area(&info);
}
--
2.20.1

2019-06-19 05:15:33

by Alexandre Ghiti

[permalink] [raw]
Subject: [PATCH 5/8] mm: Start fallback top-down mmap at mm->mmap_base

In case of mmap failure in top-down mode, there is no need to go through
the whole address space again for the bottom-up fallback: the goal of this
fallback is to find, as a last resort, space between the top-down mmap base
and the stack, which is the only place not covered by the top-down mmap.

Signed-off-by: Alexandre Ghiti <[email protected]>
---
mm/mmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index dedae10cb6e2..e563145c1ff4 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2185,7 +2185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr,
if (offset_in_page(addr)) {
VM_BUG_ON(addr != -ENOMEM);
info.flags = 0;
- info.low_limit = TASK_UNMAPPED_BASE;
+ info.low_limit = arch_get_mmap_base(addr, mm->mmap_base);
info.high_limit = mmap_end;
addr = vm_unmapped_area(&info);
}
--
2.20.1