[RFC PATCH 2/7] mm: Add {pmd,pud}_huge_lock helper
From: Oscar Salvador
Date: Sun Apr 12 2026 - 13:44:59 EST
HugeTLB and THP use the same lock for pud and pmd,
so create two helpers that can be directly used by both of them,
as they will be used in the generic pagewalkers.
Signed-off-by: Oscar Salvador <osalvador@xxxxxxx>
---
include/linux/mm_inline.h | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
index fa2d6ba811b5..3ac77b50e91f 100644
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -655,4 +655,36 @@ static inline size_t num_pages_contiguous(struct page **pages, size_t nr_pages)
return i;
}
+static inline spinlock_t *pmd_huge_lock(pmd_t *pmd, struct vm_area_struct *vma)
+{
+ spinlock_t *ptl;
+
+ if (pmd_present(*pmd) || !pmd_none(*pmd)) {
+ ptl = pmd_lock(vma->vm_mm, pmd);
+ if (pmd_present(*pmd) && pmd_leaf(*pmd))
+ return ptl;
+ else if (!pmd_present(*pmd) && !pmd_none(*pmd))
+ return ptl;
+ spin_unlock(ptl);
+ }
+
+ return NULL;
+}
+
+static inline spinlock_t *pud_huge_lock(pud_t *pud, struct vm_area_struct *vma)
+{
+ spinlock_t *ptl;
+
+ if (pud_present(*pud) || !pud_none(*pud)) {
+ ptl = pud_lock(vma->vm_mm, pud);
+ if (pud_present(*pud) && pud_leaf(*pud))
+ return ptl;
+ else if (!pud_present(*pud) && !pud_none(*pud))
+ return ptl;
+ spin_unlock(ptl);
+ }
+
+ return NULL;
+}
+
#endif
--
2.35.3