Skip to contentSkip to conversation

mm/huge_memory: update file PUD counter before folio_put()

PATCH Applied Yin Tirui 5 participants 7 messages May 26 – May 27

Subsystems (3)
lore
Share & tools
lore

Yin Tirui

author
#0 lore raw

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().

Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")
---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +1 -1
index a5f4a48b7b77..9832ee910d5e 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

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. 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().

Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")

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
index a5f4a48b7b77..9832ee910d5e 100644
@@ -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

author
#2 lore raw
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. 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().

Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")
Quoted 6 lines

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?

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
index a5f4a48b7b77..9832ee910d5e 100644
@@ -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
#3 lore raw
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. 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().

Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")

Patch looks sane to me, so:

Quoted 8 lines
Quoted 4 lines

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

Yup, inevitably hit send and only then notice this :)

Cheers, Lorenzo

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Yin Tirui
Quoted 11 lines · Yin Tirui

__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().

Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")

---

Signature · 3 lines
Cheers,

David
reviewer Reviewed-by on v1 1/1
#5 lore raw
In reply to Yin Tirui
Quoted 11 lines · Yin Tirui

__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().

Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")

---

Thanks! Feel free to add:

reviewer Reviewed-by on v1 1/1
#6 lore raw
In reply to Yin Tirui
Quoted 11 lines · Yin Tirui

__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().

Fixes dbe54153296d ("mm/huge_memory: add vmf_insert_folio_pud()")

---

Quoted 18 lines
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +1 -1
index a5f4a48b7b77..9832ee910d5e 100644
@@ -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,