Commit 8b440327 authored by Ma Wupeng's avatar Ma Wupeng Committed by Jialin Zhang
Browse files

mm: mem_reliable: Initialize reliable_nr_page when mm_init()

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I6RKHX


CVE: NA

--------------------------------

After the fork operation, it is erroneous for the child process to have a
reliable page size twice that of its parent process.

Upon examining the mm_struct structure, it was discovered that
reliable_nr_page should be initialized to 0, similar to how RSS is
initialized during mm_init(). This particular problem that arises during
forking is merely one such example.

To resolve this issue, it is recommended to set reliable_nr_page to 0
during the mm_init() operation.

Fixes: d81e9624 ("proc: Count reliable memory usage of reliable tasks")
Signed-off-by: default avatarMa Wupeng <mawupeng1@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parent 9ef48343
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -135,6 +135,14 @@ static inline void reliable_page_counter(struct page *page,
	if (page_reliable(page))
		atomic_long_add(val, &mm->reliable_nr_page);
}

static inline void reliable_clear_page_counter(struct mm_struct *mm)
{
	if (!mem_reliable_is_enabled())
		return;

	atomic_long_set(&mm->reliable_nr_page, 0);
}
#else
#define reliable_enabled 0
#define pagecache_use_reliable_mem 0
@@ -178,6 +186,7 @@ static inline void reliable_page_counter(struct page *page,
		struct mm_struct *mm, int val) {}
static inline void reliable_report_usage(struct seq_file *m,
		struct mm_struct *mm) {}
static inline void reliable_clear_page_counter(struct mm_struct *mm) {}
#endif

#endif
+1 −0
Original line number Diff line number Diff line
@@ -1049,6 +1049,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
	atomic_set(&mm->has_pinned, 0);
	atomic64_set(&mm->pinned_vm, 0);
	memset(&mm->rss_stat, 0, sizeof(mm->rss_stat));
	reliable_clear_page_counter(mm);
	spin_lock_init(&mm->page_table_lock);
	spin_lock_init(&mm->arg_lock);
	mm_init_cpumask(mm);