mm/huge_memory: update file PUD counter before folio_put()
Subsystems (3)
PATCH 1/1 mm/huge_memory: update file PUD counter before folio_put()
__split_huge_pud_locked() updates the file/shmem RSS counter after dropping the PUD mapping's folio reference. If folio_put() drops the last reference, mm_counter_file() can later read freed folio state via folio_test_swapbacked().
Move the counter update before folio_put().
--- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +1 -1
@@ -3027,9 +3027,9 @@ static void __split_huge_pud_locked(struct vm_area_struct *vma, pud_t *pud,if (!folio_test_referenced (folio) &&pud_young (old_pud))folio_set_referenced (folio);folio_remove_rmap_pud (folio, page, vma); -folio_put (folio);add_mm_counter (vma->vm_mm,mm_counter_file (folio), -HPAGE_PUD_NR ); +folio_put (folio); } void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud,
Signature · 1 line
2.43.0
You sent this twice :)
Quoted 10 lines · Yin Tirui
__split_huge_pud_locked()updates the file/shmem RSS counter after dropping the PUD mapping's folio reference. Iffolio_put()drops the last reference,mm_counter_file()can later read freed folio state viafolio_test_swapbacked().Move the counter update before
folio_put().Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")Cc <[email protected]>Signed-off-by Yin Tirui <[email protected]>
Patch looks sane to me, so:
There seems to be an identical problem in __split_huge_pmd_locked() - could you do the same fix there?
Thanks, Lorenzo
Quoted 22 lines
--- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/huge_memory.c +1
-2@@ -3027,9 +3027,9 @@ static void __split_huge_pud_locked(struct vm_area_struct *vma, pud_t *pud,if (!folio_test_referenced (folio) &&pud_young (old_pud))folio_set_referenced (folio);folio_remove_rmap_pud (folio, page, vma); -folio_put (folio);add_mm_counter (vma->vm_mm,mm_counter_file (folio), -HPAGE_PUD_NR ); +folio_put (folio); } void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, --2.43.0
Quoted 13 lines · Lorenzo Stoakes
You sent this twice :)
Quoted 10 lines · Yin Tirui
__split_huge_pud_locked()updates the file/shmem RSS counter after dropping the PUD mapping's folio reference. Iffolio_put()drops the last reference,mm_counter_file()can later read freed folio state viafolio_test_swapbacked().Move the counter update before
folio_put().Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")Cc <[email protected]>Signed-off-by Yin Tirui <[email protected]>
Quoted 6 lines
Patch looks sane to me, so:
Reviewed-by Lorenzo Stoakes <[email protected]>There seems to be an identical problem in
__split_huge_pmd_locked()- could you do the same fix there?
I have already sent it as another separate patch.
https://lore.kernel.org/linux-mm/[email protected]/T/#u
Quoted 25 lines
Thanks, Lorenzo
Quoted 22 lines
--- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/huge_memory.c +1
-2@@ -3027,9 +3027,9 @@ static void __split_huge_pud_locked(struct vm_area_struct *vma, pud_t *pud,if (!folio_test_referenced (folio) &&pud_young (old_pud))folio_set_referenced (folio);folio_remove_rmap_pud (folio, page, vma); -folio_put (folio);add_mm_counter (vma->vm_mm,mm_counter_file (folio), -HPAGE_PUD_NR ); +folio_put (folio); } void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud, --2.43.0
Signature · 1 line
Yin Tirui
Quoted 3 lines · Yin Tirui
Quoted 1 line · Lorenzo Stoakes
You sent this twice :)
Yeah oops you didn't, that was just the PMD part!
(Also my mail client may now, ironically, duplicate a reply...)
Quoted 14 lines
Quoted 14 lines · Yin Tirui
Quoted 10 lines
__split_huge_pud_locked()updates the file/shmem RSS counter after dropping the PUD mapping's folio reference. Iffolio_put()drops the last reference,mm_counter_file()can later read freed folio state viafolio_test_swapbacked().Move the counter update before
folio_put().Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")Cc <[email protected]>Signed-off-by Yin Tirui <[email protected]>Patch looks sane to me, so:
Quoted 8 lines
Quoted 4 lines
Reviewed-by Lorenzo Stoakes <[email protected]>There seems to be an identical problem in
__split_huge_pmd_locked()- could you do the same fix there?I have already sent it as another separate patch.
Yup, inevitably hit send and only then notice this :)
Cheers, Lorenzo
Quoted 11 lines · Yin Tirui
__split_huge_pud_locked()updates the file/shmem RSS counter after dropping the PUD mapping's folio reference. Iffolio_put()drops the last reference,mm_counter_file()can later read freed folio state viafolio_test_swapbacked().Move the counter update before
folio_put().Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")Cc <[email protected]>Signed-off-by Yin Tirui <[email protected]>---
Signature · 3 lines
Cheers, David
Quoted 11 lines · Yin Tirui
__split_huge_pud_locked()updates the file/shmem RSS counter after dropping the PUD mapping's folio reference. Iffolio_put()drops the last reference,mm_counter_file()can later read freed folio state viafolio_test_swapbacked().Move the counter update before
folio_put().Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")Cc <[email protected]>Signed-off-by Yin Tirui <[email protected]>---
Thanks! Feel free to add:
Quoted 11 lines · Yin Tirui
__split_huge_pud_locked()updates the file/shmem RSS counter after dropping the PUD mapping's folio reference. Iffolio_put()drops the last reference,mm_counter_file()can later read freed folio state viafolio_test_swapbacked().Move the counter update before
folio_put().Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")Cc <[email protected]>Signed-off-by Yin Tirui <[email protected]>---
Quoted 18 lines
mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/huge_memory.c +1
-1@@ -3027,9 +3027,9 @@ static void __split_huge_pud_locked(struct vm_area_struct *vma, pud_t *pud,if (!folio_test_referenced (folio) &&pud_young (old_pud))folio_set_referenced (folio);folio_remove_rmap_pud (folio, page, vma); -folio_put (folio);add_mm_counter (vma->vm_mm,mm_counter_file (folio), -HPAGE_PUD_NR ); +folio_put (folio); } void __split_huge_pud(struct vm_area_struct *vma, pud_t *pud,