ascend inclusion category: Feature bugzilla: https://gitee.com/openeuler/kernel/issues/I7YF5R
---------------------------------------------
Change the mmap_base in mm_struct and check the limit in get_unmapped_area.
Signed-off-by: Wang Wensheng wangwensheng4@huawei.com --- mm/mmap.c | 7 +++++++ mm/util.c | 4 ++++ 2 files changed, 11 insertions(+)
diff --git a/mm/mmap.c b/mm/mmap.c index 486a5cb91285..bff71a766e0a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -47,6 +47,7 @@ #include <linux/oom.h> #include <linux/sched/mm.h> #include <linux/ksm.h> +#include <linux/share_pool.h>
#ifdef CONFIG_GMEM #include <linux/vm_object.h> @@ -146,6 +147,7 @@ static void remove_vma(struct vm_area_struct *vma, bool unreachable) if (vma->vm_file) fput(vma->vm_file); mpol_put(vma_policy(vma)); + sp_area_drop(vma); if (unreachable) __vm_area_free(vma); else @@ -974,6 +976,10 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, if (vm_flags & VM_SPECIAL) return NULL;
+ /* don't merge this kind of vma as sp_area couldn't be merged */ + if (sp_check_vm_share_pool(vm_flags)) + return NULL; + /* Does the input range span an existing VMA? (cases 5 - 8) */ curr = find_vma_intersection(mm, prev ? prev->vm_end : 0, end);
@@ -1725,6 +1731,7 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) { unsigned long addr;
+ sp_area_work_around(info); if (info->flags & VM_UNMAPPED_AREA_TOPDOWN) addr = unmapped_area_topdown(info); else diff --git a/mm/util.c b/mm/util.c index 6593ad7b84ee..cfbd5bec0cf8 100644 --- a/mm/util.c +++ b/mm/util.c @@ -24,6 +24,7 @@ #include <linux/sizes.h> #include <linux/compat.h> #include <linux/page-flags.h> +#include <linux/share_pool.h>
#include <linux/uaccess.h>
@@ -428,6 +429,9 @@ static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) else if (gap > MAX_GAP) gap = MAX_GAP;
+ if (sp_is_enabled()) + return ALIGN_DOWN(MMAP_SHARE_POOL_START - rnd, PAGE_SIZE); + return PAGE_ALIGN(STACK_TOP - gap - rnd); }