Skip to contentSkip to conversation

s390/mm: Use set_pmd() / set_pud() for hugetlb pagetable entries

PATCH In review Gerald Schaefer 3 participants 3 messages Jun 16 – Jun 18

Subsystems (2)
lore
Share & tools
lore

Gerald Schaefer

author maintainer
#0 lore raw

PATCH 1/1 s390/mm: Use set_pmd() / set_pud() for hugetlb pagetable entries

hugetlb code is known to view all pagetable entries as PTEs, instead of corresponding upper levels like PMD or PUD. For s390, with different pagetable entry layout for different levels, this requires some conversion action under the hood.

The converted PMD and PUD entries are then written via set_pte() function, but that might add some PTE-specific modifications. There is no functional problem with current code, and the clearing of _PAGE_UNUSED in set_pte(). Avoid future problems by using the set_pmd() and set_pud() functions instead.

---
 arch/s390/include/asm/hugetlb.h |  4 ++--
 arch/s390/mm/hugetlbpage.c      | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)
arch/s390/include/asm/hugetlb.h +2 -2
index e33a5b587ee4..02db08429b7c 100644
@@ -42,9 +42,9 @@ static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 				  pte_t *ptep, unsigned long sz)
 {
 	if ((pte_val(ptep_get(ptep)) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
-		set_pte(ptep, __pte(_REGION3_ENTRY_EMPTY));
+		set_pud((pud_t *)ptep, __pud(_REGION3_ENTRY_EMPTY));
 	else
-		set_pte(ptep, __pte(_SEGMENT_ENTRY_EMPTY));
+		set_pmd((pmd_t *)ptep, __pmd(_SEGMENT_ENTRY_EMPTY));
 }
 
 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/s390/mm/hugetlbpage.c +6 -4
index db35d8fe8609..f84aa9265430 100644
@@ -147,10 +147,12 @@ void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
 		if (likely(pte_present(pte)))
 			rste |= _REGION3_ENTRY_LARGE;
 		rste |= _REGION_ENTRY_TYPE_R3;
-	} else if (likely(pte_present(pte)))
-		rste |= _SEGMENT_ENTRY_LARGE;
-
-	set_pte(ptep, __pte(rste));
+		set_pud((pud_t *)ptep, __pud(rste));
+	} else {
+		if (likely(pte_present(pte)))
+			rste |= _SEGMENT_ENTRY_LARGE;
+		set_pmd((pmd_t *)ptep, __pmd(rste));
+	}
 }
 
 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Tue, 16 Jun 2026 19:46:27 +0200 Gerald Schaefer…

hugetlb code is known to view all pagetable entries as PTEs, instead of corresponding upper levels like PMD or PUD. For s390, with different pagetable entry layout for different levels, this requires some conversion action under the hood.

Quoted 7 lines

The converted PMD and PUD entries are then written via set_pte() function, but that might add some PTE-specific modifications. There is no functional problem with current code, and the clearing of _PAGE_UNUSED in set_pte(). Avoid future problems by using the set_pmd() and set_pud() functions instead.

Quoted 42 lines
---
 arch/s390/include/asm/hugetlb.h |  4 ++--
 arch/s390/mm/hugetlbpage.c      | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)
arch/s390/include/asm/hugetlb.h +2 -2
index e33a5b587ee4..02db08429b7c 100644
@@ -42,9 +42,9 @@ static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
 				  pte_t *ptep, unsigned long sz)
 {
 	if ((pte_val(ptep_get(ptep)) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
-		set_pte(ptep, __pte(_REGION3_ENTRY_EMPTY));
+		set_pud((pud_t *)ptep, __pud(_REGION3_ENTRY_EMPTY));
 	else
-		set_pte(ptep, __pte(_SEGMENT_ENTRY_EMPTY));
+		set_pmd((pmd_t *)ptep, __pmd(_SEGMENT_ENTRY_EMPTY));
 }
 
 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
arch/s390/mm/hugetlbpage.c +6 -4
index db35d8fe8609..f84aa9265430 100644
@@ -147,10 +147,12 @@ void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
 		if (likely(pte_present(pte)))
 			rste |= _REGION3_ENTRY_LARGE;
 		rste |= _REGION_ENTRY_TYPE_R3;
-	} else if (likely(pte_present(pte)))
-		rste |= _SEGMENT_ENTRY_LARGE;
-
-	set_pte(ptep, __pte(rste));
+		set_pud((pud_t *)ptep, __pud(rste));
+	} else {
+		if (likely(pte_present(pte)))
+			rste |= _SEGMENT_ENTRY_LARGE;
+		set_pmd((pmd_t *)ptep, __pmd(rste));
+	}
 }
 
 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Gerald Schaefer
Quoted 11 lines · Gerald Schaefer

hugetlb code is known to view all pagetable entries as PTEs, instead of corresponding upper levels like PMD or PUD. For s390, with different pagetable entry layout for different levels, this requires some conversion action under the hood.

The converted PMD and PUD entries are then written via set_pte() function, but that might add some PTE-specific modifications. There is no functional problem with current code, and the clearing of _PAGE_UNUSED in set_pte(). Avoid future problems by using the set_pmd() and set_pud() functions instead.

Quoted 5 lines
---
 arch/s390/include/asm/hugetlb.h |  4 ++--
 arch/s390/mm/hugetlbpage.c      | 10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

and applied, thanks!