UPSTREAM: mm: multi-gen LRU: walk_pte_range() use pte_offset_map_rw_nolock()

In walk_pte_range(), we may modify the pte entry after holding the ptl, so
convert it to using pte_offset_map_rw_nolock().  At this time, the
pte_same() check is not performed after the ptl held, so we should get
pmdval and do pmd_same() check to ensure the stability of pmd entry.

Link: https://lkml.kernel.org/r/7e9c194a5efacc9609cfd31abb9c7df88b53b530.1727332572.git.zhengqi.arch@bytedance.com
Change-Id: I65441009411132541c617e713444dced83f04da1
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Reviewed-by: Muchun Song <muchun.song@linux.dev>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Peter Xu <peterx@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 2441774f2d2890940f2db21bbc264c7e2f56d1ae)
Bug: 393446550
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
Qi Zheng
2024-09-26 14:46:25 +08:00
committed by Treehugger Robot
parent d5d31cd5ce
commit bd3d1b5097
+8 -1
View File
@@ -3444,8 +3444,10 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
struct pglist_data *pgdat = lruvec_pgdat(walk->lruvec);
DEFINE_MAX_SEQ(walk->lruvec);
int old_gen, new_gen = lru_gen_from_seq(max_seq);
pmd_t pmdval;
pte = pte_offset_map_nolock(args->mm, pmd, start & PMD_MASK, &ptl);
pte = pte_offset_map_rw_nolock(args->mm, pmd, start & PMD_MASK, &pmdval,
&ptl);
if (!pte)
return false;
if (!spin_trylock(ptl)) {
@@ -3453,6 +3455,11 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
return false;
}
if (unlikely(!pmd_same(pmdval, pmdp_get_lockless(pmd)))) {
pte_unmap_unlock(pte, ptl);
return false;
}
arch_enter_lazy_mmu_mode();
restart:
for (i = pte_index(start), addr = start; addr != end; i++, addr += PAGE_SIZE) {