mirror of
https://github.com/hardkernel/linux.git
synced 2026-03-25 12:00:22 +09:00
BACKPORT: mm/damon/ops-common: atomically test and clear young on ptes and pmds
commitc11d34fa13upstream. It is racy to non-atomically read a pte, then clear the young bit, then write it back as this could discard dirty information. Further, it is bad practice to directly set a pte entry within a table. Instead clearing young must go through the arch-provided helper, ptep_test_and_clear_young() to ensure it is modified atomically and to give the arch code visibility and allow it to check (and potentially modify) the operation. Link: https://lkml.kernel.org/r/20230602092949.545577-3-ryan.roberts@arm.com Fixes:3f49584b26("mm/damon: implement primitives for the virtual memory address spaces"). Change-Id: I592151dc02b7f9e3aaa50aab65c4373f4d1671fd Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Reviewed-by: Zi Yan <ziy@nvidia.com> Reviewed-by: SeongJae Park <sj@kernel.org> Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Lorenzo Stoakes <lstoakes@gmail.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Cc: Yu Zhao <yuzhao@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: SeongJae Park <sj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit7eeed3ed1a) Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
@@ -28,9 +28,9 @@ static bool __damon_pa_mkold(struct page *page, struct vm_area_struct *vma,
|
||||
while (page_vma_mapped_walk(&pvmw)) {
|
||||
addr = pvmw.address;
|
||||
if (pvmw.pte)
|
||||
damon_ptep_mkold(pvmw.pte, vma->vm_mm, addr);
|
||||
damon_ptep_mkold(pvmw.pte, vma, addr);
|
||||
else
|
||||
damon_pmdp_mkold(pvmw.pmd, vma->vm_mm, addr);
|
||||
damon_pmdp_mkold(pvmw.pmd, vma, addr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ struct page *damon_get_page(unsigned long pfn)
|
||||
return page;
|
||||
}
|
||||
|
||||
void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr)
|
||||
void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr)
|
||||
{
|
||||
bool referenced = false;
|
||||
struct page *page = damon_get_page(pte_pfn(*pte));
|
||||
@@ -41,13 +41,11 @@ void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr)
|
||||
if (!page)
|
||||
return;
|
||||
|
||||
if (pte_young(*pte)) {
|
||||
if (ptep_test_and_clear_young(vma, addr, pte))
|
||||
referenced = true;
|
||||
*pte = pte_mkold(*pte);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MMU_NOTIFIER
|
||||
if (mmu_notifier_clear_young(mm, addr, addr + PAGE_SIZE))
|
||||
if (mmu_notifier_clear_young(vma->vm_mm, addr, addr + PAGE_SIZE))
|
||||
referenced = true;
|
||||
#endif /* CONFIG_MMU_NOTIFIER */
|
||||
|
||||
@@ -58,7 +56,7 @@ void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr)
|
||||
put_page(page);
|
||||
}
|
||||
|
||||
void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, unsigned long addr)
|
||||
void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr)
|
||||
{
|
||||
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
||||
bool referenced = false;
|
||||
@@ -67,13 +65,11 @@ void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, unsigned long addr)
|
||||
if (!page)
|
||||
return;
|
||||
|
||||
if (pmd_young(*pmd)) {
|
||||
if (pmdp_test_and_clear_young(vma, addr, pmd))
|
||||
referenced = true;
|
||||
*pmd = pmd_mkold(*pmd);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MMU_NOTIFIER
|
||||
if (mmu_notifier_clear_young(mm, addr,
|
||||
if (mmu_notifier_clear_young(vma->vm_mm, addr,
|
||||
addr + ((1UL) << HPAGE_PMD_SHIFT)))
|
||||
referenced = true;
|
||||
#endif /* CONFIG_MMU_NOTIFIER */
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
struct page *damon_get_page(unsigned long pfn);
|
||||
|
||||
void damon_ptep_mkold(pte_t *pte, struct mm_struct *mm, unsigned long addr);
|
||||
void damon_pmdp_mkold(pmd_t *pmd, struct mm_struct *mm, unsigned long addr);
|
||||
void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr);
|
||||
void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr);
|
||||
|
||||
int damon_pageout_score(struct damon_ctx *c, struct damon_region *r,
|
||||
struct damos *s);
|
||||
|
||||
Reference in New Issue
Block a user