From 27950a7e92610688df5351d1e2ed03c4eb94b310 Mon Sep 17 00:00:00 2001 From: yuhui317 Date: Fri, 24 Jun 2022 15:11:27 +0800 Subject: [PATCH 1/3] mm: purgeable memory wp page bugfix Bugfix: wp_page Issue: #I5DAY5 Signed-off-by: yuhui317 --- mm/Kconfig | 2 +- mm/memory.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/Kconfig b/mm/Kconfig index ad8cd862359e..c39f868947e3 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -961,7 +961,7 @@ config RSS_THRESHOLD config MEM_PURGEABLE bool "Purgeable memory feature" default n - depends on ARCH_USES_HIGH_VMA_FLAGS + select ARCH_USES_HIGH_VMA_FLAGS help Support purgeable pages for process diff --git a/mm/memory.c b/mm/memory.c index 73231717b75c..6e040c1f2591 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2916,6 +2916,11 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) */ ptep_clear_flush_notify(vma, vmf->address, vmf->pte); page_add_new_anon_rmap(new_page, vma, vmf->address, false); + if (vma->vm_flags & VM_PURGEABLE) { + pr_info("set wp new page %lx purgeable\n", page_to_pfn(new_page)); + SetPagePurgeable(new_page); + uxpte_set_present(vma, vmf->address); + } lru_cache_add_inactive_or_unevictable(new_page, vma); /* * We call the notify macro here because, when using secondary @@ -3635,10 +3640,12 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) page_add_new_anon_rmap(page, vma, vmf->address, false); if (vma->vm_flags & VM_PURGEABLE) { SetPagePurgeable(page); - uxpte_set_present(vma, vmf->address); } lru_cache_add_inactive_or_unevictable(page, vma); setpte: + if (vma->vm_flags & VM_PURGEABLE) { + uxpte_set_present(vma, vmf->address); + } set_pte_at(vma->vm_mm, vmf->address, vmf->pte, entry); /* No need to invalidate - it was non-present before */ -- Gitee From 6a403e7716e7433b68ef40232034cc559b1b9204 Mon Sep 17 00:00:00 2001 From: yuhui317 Date: Fri, 24 Jun 2022 15:50:15 +0800 Subject: [PATCH 2/3] Review: remove {} Bugfix: wp_page Issue: #I5DAY5 Signed-off-by: yuhui317 --- mm/memory.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 6e040c1f2591..582776bec124 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3638,14 +3638,14 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES); page_add_new_anon_rmap(page, vma, vmf->address, false); - if (vma->vm_flags & VM_PURGEABLE) { + if (vma->vm_flags & VM_PURGEABLE) SetPagePurgeable(page); - } + lru_cache_add_inactive_or_unevictable(page, vma); setpte: - if (vma->vm_flags & VM_PURGEABLE) { + if (vma->vm_flags & VM_PURGEABLE) uxpte_set_present(vma, vmf->address); - } + set_pte_at(vma->vm_mm, vmf->address, vmf->pte, entry); /* No need to invalidate - it was non-present before */ -- Gitee From 3d148a41710314343c90682d5015f0c963f1ee47 Mon Sep 17 00:00:00 2001 From: lijiawei Date: Fri, 24 Jun 2022 20:12:59 +0800 Subject: [PATCH 3/3] mm: using the default unified print style for meminfo ohos inclusion category: bugfix issue: #I5DAY5 CVE: NA ------------------------------------ Using the default unified style to show purgeable mem info. And correct the pin-count to avoid confusion. Signed-off-by: Chengke Wang Signed-off-by: lijiawei --- fs/proc/meminfo.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 55de0309b4b0..f20ed52c78c2 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -41,12 +41,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v) unsigned long pages[NR_LRU_LISTS]; unsigned long sreclaimable, sunreclaim; int lru; - unsigned long nr_purgeable_active = 0; - unsigned long nr_purgeable_inactive = 0; + unsigned long nr_purg_active = 0; + unsigned long nr_purg_inactive = 0; #ifdef CONFIG_MEM_PURGEABLE - unsigned long nr_purgeable_pined = 0; - - purg_pages_info(NULL, &nr_purgeable_pined); + unsigned long nr_purg_pined = 0; #endif si_meminfo(&i); @@ -62,8 +60,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v) pages[lru] = global_node_page_state(NR_LRU_BASE + lru); #ifdef CONFIG_MEM_PURGEABLE - nr_purgeable_active = pages[LRU_ACTIVE_PURGEABLE]; - nr_purgeable_inactive = pages[LRU_INACTIVE_PURGEABLE]; + nr_purg_active = pages[LRU_ACTIVE_PURGEABLE]; + nr_purg_inactive = pages[LRU_INACTIVE_PURGEABLE]; + purg_pages_info(NULL, &nr_purg_pined); + nr_purg_pined = min(nr_purg_pined, nr_purg_active + nr_purg_inactive); #endif available = si_mem_available(); @@ -78,18 +78,18 @@ static int meminfo_proc_show(struct seq_file *m, void *v) show_val_kb(m, "SwapCached: ", total_swapcache_pages()); show_val_kb(m, "Active: ", pages[LRU_ACTIVE_ANON] + pages[LRU_ACTIVE_FILE] + - nr_purgeable_active); + nr_purg_active); show_val_kb(m, "Inactive: ", pages[LRU_INACTIVE_ANON] + pages[LRU_INACTIVE_FILE] + - nr_purgeable_inactive); + nr_purg_inactive); show_val_kb(m, "Active(anon): ", pages[LRU_ACTIVE_ANON]); show_val_kb(m, "Inactive(anon): ", pages[LRU_INACTIVE_ANON]); show_val_kb(m, "Active(file): ", pages[LRU_ACTIVE_FILE]); show_val_kb(m, "Inactive(file): ", pages[LRU_INACTIVE_FILE]); #ifdef CONFIG_MEM_PURGEABLE - show_val_kb(m, "Active(purgeable): ", nr_purgeable_active); - show_val_kb(m, "Inactive(purgeable): ", nr_purgeable_inactive); - show_val_kb(m, "Pined(purgeable): ", nr_purgeable_pined); + show_val_kb(m, "Active(purg): ", nr_purg_active); + show_val_kb(m, "Inactive(purg): ", nr_purg_inactive); + show_val_kb(m, "Pined(purg): ", nr_purg_pined); #endif show_val_kb(m, "Unevictable: ", pages[LRU_UNEVICTABLE]); show_val_kb(m, "Mlocked: ", global_zone_page_state(NR_MLOCK)); -- Gitee