From: Wang Wensheng <wangwensheng4(a)huawei.com>
ascend inclusion
category: bugfix
bugzilla: NA
CVE: NA
---------------------------
To avoid mmap vspace reserved for sharepool, we currently change the
high_limit to MMAP_SHARE_POOL_START in arch_get_unmapped_area() and
arch_get_unmapped_area_topdown(). In mmap-topdown scene, this make the
start address of mmap being always MMAP_SHARE_POOL_START. ASLR got
broken.
To fix this, this patch set the mm->mmap_base based on
MMAP_SHARE_POOL_START instead of STACK_TOP in topdown scene.
Fixes: 4bdd5c21793e ("ascend: memory: introduce do_mm_populate and hugetlb_insert_hugepage")
Signed-off-by: Wang Wensheng <wangwensheng4(a)huawei.com>
Reviewed-by: Weilong Chen <chenweilong(a)huawei.com>
Reviewed-by: Ding Tianhong <dingtianhong(a)huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang(a)huawei.com>
---
arch/arm64/mm/mmap.c | 6 +++++-
include/linux/share_pool.h | 4 ++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c
index 157f2caa13516..aca257158611f 100644
--- a/arch/arm64/mm/mmap.c
+++ b/arch/arm64/mm/mmap.c
@@ -28,6 +28,7 @@
#include <linux/io.h>
#include <linux/personality.h>
#include <linux/random.h>
+#include <linux/share_pool.h>
#include <asm/cputype.h>
@@ -80,7 +81,10 @@ static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack)
else if (gap > MAX_GAP)
gap = MAX_GAP;
- return PAGE_ALIGN(STACK_TOP - gap - rnd);
+ if (sp_is_enabled())
+ return ALIGN_DOWN(MMAP_SHARE_POOL_START - rnd, PAGE_SIZE);
+ else
+ return PAGE_ALIGN(STACK_TOP - gap - rnd);
}
/*
diff --git a/include/linux/share_pool.h b/include/linux/share_pool.h
index 9650f257b3ad7..9557a8be46677 100644
--- a/include/linux/share_pool.h
+++ b/include/linux/share_pool.h
@@ -130,8 +130,6 @@ struct sp_proc_stat {
atomic64_t k2u_size;
};
-#ifdef CONFIG_ASCEND_SHARE_POOL
-
#define MAP_SHARE_POOL 0x100000
#define MMAP_TOP_4G_SIZE 0x100000000UL
@@ -148,6 +146,8 @@ struct sp_proc_stat {
#define MMAP_SHARE_POOL_START (MMAP_SHARE_POOL_END - MMAP_SHARE_POOL_SIZE)
#define MMAP_SHARE_POOL_16G_START (MMAP_SHARE_POOL_END - MMAP_SHARE_POOL_DVPP_SIZE)
+#ifdef CONFIG_ASCEND_SHARE_POOL
+
static inline void sp_init_mm(struct mm_struct *mm)
{
mm->sp_group = NULL;
--
2.25.1