Skip to contentSkip to conversation

mm/khugepaged: don't check pmd value twice in collapse_pte_mapped_thp()

PATCH New Zach O'Keefe 1 participant 1 message Sep 27, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/khugepaged: don't check pmd value twice in collapse_pte_mapped_thp()

During the v3 -> v4 merge of series "mm: add file/shmem support to MADV_COLLAPSE", a line deletion was accidentally dropped, which left collapse_pte_mapped_thp() in state:

---8<---
<mmap_lock held exclusively>

result = find_pmd_or_thp_or_none(mm, haddr, &pmd);

<other checks that don't change "result" unless fail>

(*) if (find_pmd_or_thp_or_none(mm, haddr, &pmd) != SCAN_SUCCEED)

	result = find_pmd_or_thp_or_none(mm, haddr, &pmd);

	switch (result) {
		case SCAN_SUCCEED:

---8<---

Where (*) is the line that should have been deleted (note that this is still legal C). Since the selftests are still passing, this mistake highlights the fact that the second (intended) find_pmd_or_thp_or_none() isn't necessary: the first one is called with mmap_lock held exclusively, we don't drop the lock in this function, and "result" isn't changed between assignment and use in the switch-statement (except for failure paths which either return early or skip to "drop_hpage" label).

Remove the second (intended) find_pmd_or_thp_or_none() check, and the misplaced find_pmd_or_thp_or_none() if-statement line.

Fixes c27451af51cc ("mm/madvise: add file and shmem support to MADV_COLLAPSE")

---

Andrew, apologies about letting this sneak through (both the needless check, and the trivial merge error). Please consider taking into mm-unstable to clean things up there. Will try to catch these better in the future. Thank you.

 mm/khugepaged.c | 2 --
 1 file changed, 2 deletions(-)
mm/khugepaged.c +0 -2
index 6d2dfd96608a..c7699fabf302 100644
@@ -1463,8 +1463,6 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
 		goto drop_hpage;
 	}
 
-	if (find_pmd_or_thp_or_none(mm, haddr, &pmd) != SCAN_SUCCEED)
-	result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
 	switch (result) {
 	case SCAN_SUCCEED:
 		break;
Signature · 1 line
2.37.3.998.g577e59143f-goog