linux-stable/mm/damon
Baolin Wang e77f4ddc7e mm/damon: validate if the pmd entry is present before accessing
commit c8b9aff419 upstream.

pmd_huge() is used to validate if the pmd entry is mapped by a huge page,
also including the case of non-present (migration or hwpoisoned) pmd entry
on arm64 or x86 architectures.  This means that pmd_pfn() can not get the
correct pfn number for a non-present pmd entry, which will cause
damon_get_page() to get an incorrect page struct (also may be NULL by
pfn_to_online_page()), making the access statistics incorrect.

This means that the DAMON may make incorrect decision according to the
incorrect statistics, for example, DAMON may can not reclaim cold page
in time due to this cold page was regarded as accessed mistakenly if
DAMOS_PAGEOUT operation is specified.

Moreover it does not make sense that we still waste time to get the page
of the non-present entry.  Just treat it as not-accessed and skip it,
which maintains consistency with non-present pte level entries.

So add pmd entry present validation to fix the above issues.

Link: https://lkml.kernel.org/r/58b1d1f5fbda7db49ca886d9ef6783e3dcbbbc98.1660805030.git.baolin.wang@linux.alibaba.com
Fixes: 3f49584b26 ("mm/damon: implement primitives for the virtual memory address spaces")
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Muchun Song <songmuchun@bytedance.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-10-24 09:56:48 +02:00
..
core-test.h mm/damon/core-test: add a kunit test case for ops registration 2022-04-29 14:37:00 -07:00
core.c mm/damon/vaddr: move 'damon_set_regions()' to core 2022-05-13 07:20:08 -07:00
dbgfs-test.h mm/damon/dbgfs-test: fix is_target_id() change 2022-03-22 15:57:12 -07:00
dbgfs.c mm/damon/dbgfs: fix memory leak when using debugfs_lookup() 2022-10-05 10:40:44 +02:00
Kconfig mm/damon: implement a minimal stub for sysfs-based DAMON interface 2022-03-22 15:57:13 -07:00
Makefile mm/damon: implement a minimal stub for sysfs-based DAMON interface 2022-03-22 15:57:13 -07:00
ops-common.c mm: damon: use HPAGE_PMD_SIZE 2022-05-19 14:08:55 -07:00
ops-common.h mm/damon: rename damon_primitives to damon_operations 2022-03-22 15:57:12 -07:00
paddr.c mm: damon: use HPAGE_PMD_SIZE 2022-05-19 14:08:55 -07:00
reclaim.c mm/damon/reclaim: fix potential memory leak in damon_reclaim_init() 2022-08-17 15:16:15 +02:00
sysfs.c damon/sysfs: fix possible memleak on damon_sysfs_add_target 2022-10-05 10:40:55 +02:00
vaddr-test.h mm/damon/vaddr: remove damon_va_apply_three_regions() 2022-05-13 07:20:08 -07:00
vaddr.c mm/damon: validate if the pmd entry is present before accessing 2022-10-24 09:56:48 +02:00