diff mbox series

[V3] arm64/hugetlb: Consistently use pud_sect_supported()

Message ID 20250220050534.799645-1-anshuman.khandual@arm.com (mailing list archive)
State New
Headers show
Series [V3] arm64/hugetlb: Consistently use pud_sect_supported() | expand

Commit Message

Anshuman Khandual Feb. 20, 2025, 5:05 a.m. UTC
Let's be consistent in using pud_sect_supported() for PUD_SIZE sized pages.
Hence change hugetlb_mask_last_page() and arch_make_huge_pte() as required.
Also re-arranged the switch statement for a common warning message.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
This patch applies on v6.14-rc3

Changes in V3:

- Re-arranged the switch statement for a common warning message per Ryan

Changes in V2:

https://lore.kernel.org/linux-arm-kernel/20250218113639.475947-1-anshuman.khandual@arm.com/

- Added an warning when PUD_SIZE is requested but not supported per Ryan

Changes in V1:

https://lore.kernel.org/linux-arm-kernel/20250217065414.49489-1-anshuman.khandual@arm.com/

 arch/arm64/mm/hugetlbpage.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

Ryan Roberts Feb. 25, 2025, 2:54 p.m. UTC | #1
On 20/02/2025 05:05, Anshuman Khandual wrote:
> Let's be consistent in using pud_sect_supported() for PUD_SIZE sized pages.
> Hence change hugetlb_mask_last_page() and arch_make_huge_pte() as required.
> Also re-arranged the switch statement for a common warning message.

Thanks, Anshuman, this looks much cleaner now, to my eye at least.

> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>

Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>

> ---
> This patch applies on v6.14-rc3
> 
> Changes in V3:
> 
> - Re-arranged the switch statement for a common warning message per Ryan
> 
> Changes in V2:
> 
> https://lore.kernel.org/linux-arm-kernel/20250218113639.475947-1-anshuman.khandual@arm.com/
> 
> - Added an warning when PUD_SIZE is requested but not supported per Ryan
> 
> Changes in V1:
> 
> https://lore.kernel.org/linux-arm-kernel/20250217065414.49489-1-anshuman.khandual@arm.com/
> 
>  arch/arm64/mm/hugetlbpage.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> index 98a2a0e64e25..fd7448bb8c80 100644
> --- a/arch/arm64/mm/hugetlbpage.c
> +++ b/arch/arm64/mm/hugetlbpage.c
> @@ -342,7 +342,9 @@ unsigned long hugetlb_mask_last_page(struct hstate *h)
>  	switch (hp_size) {
>  #ifndef __PAGETABLE_PMD_FOLDED
>  	case PUD_SIZE:
> -		return PGDIR_SIZE - PUD_SIZE;
> +		if (pud_sect_supported())
> +			return PGDIR_SIZE - PUD_SIZE;
> +		break;
>  #endif
>  	case CONT_PMD_SIZE:
>  		return PUD_SIZE - CONT_PMD_SIZE;
> @@ -364,23 +366,21 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
>  	switch (pagesize) {
>  #ifndef __PAGETABLE_PMD_FOLDED
>  	case PUD_SIZE:
> -		entry = pud_pte(pud_mkhuge(pte_pud(entry)));
> +		if (pud_sect_supported())
> +			return pud_pte(pud_mkhuge(pte_pud(entry)));
>  		break;
>  #endif
>  	case CONT_PMD_SIZE:
> -		entry = pmd_pte(pmd_mkcont(pte_pmd(entry)));
> -		fallthrough;
> +		return pmd_pte(pmd_mkhuge(pmd_mkcont(pte_pmd(entry))));
>  	case PMD_SIZE:
> -		entry = pmd_pte(pmd_mkhuge(pte_pmd(entry)));
> -		break;
> +		return pmd_pte(pmd_mkhuge(pte_pmd(entry)));
>  	case CONT_PTE_SIZE:
> -		entry = pte_mkcont(entry);
> -		break;
> +		return pte_mkcont(entry);
>  	default:
> -		pr_warn("%s: unrecognized huge page size 0x%lx\n",
> -			__func__, pagesize);
>  		break;
>  	}
> +	pr_warn("%s: unrecognized huge page size 0x%lx\n",
> +		__func__, pagesize);
>  	return entry;
>  }
>
Catalin Marinas March 5, 2025, 7:33 p.m. UTC | #2
On Thu, 20 Feb 2025 10:35:34 +0530, Anshuman Khandual wrote:
> Let's be consistent in using pud_sect_supported() for PUD_SIZE sized pages.
> Hence change hugetlb_mask_last_page() and arch_make_huge_pte() as required.
> Also re-arranged the switch statement for a common warning message.
> 
> 

Applied to arm64 (for-next/pgtable-cleanups), thanks!

[1/1] arm64/hugetlb: Consistently use pud_sect_supported()
      https://git.kernel.org/arm64/c/34e8e63a6dc1
diff mbox series

Patch

diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 98a2a0e64e25..fd7448bb8c80 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -342,7 +342,9 @@  unsigned long hugetlb_mask_last_page(struct hstate *h)
 	switch (hp_size) {
 #ifndef __PAGETABLE_PMD_FOLDED
 	case PUD_SIZE:
-		return PGDIR_SIZE - PUD_SIZE;
+		if (pud_sect_supported())
+			return PGDIR_SIZE - PUD_SIZE;
+		break;
 #endif
 	case CONT_PMD_SIZE:
 		return PUD_SIZE - CONT_PMD_SIZE;
@@ -364,23 +366,21 @@  pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
 	switch (pagesize) {
 #ifndef __PAGETABLE_PMD_FOLDED
 	case PUD_SIZE:
-		entry = pud_pte(pud_mkhuge(pte_pud(entry)));
+		if (pud_sect_supported())
+			return pud_pte(pud_mkhuge(pte_pud(entry)));
 		break;
 #endif
 	case CONT_PMD_SIZE:
-		entry = pmd_pte(pmd_mkcont(pte_pmd(entry)));
-		fallthrough;
+		return pmd_pte(pmd_mkhuge(pmd_mkcont(pte_pmd(entry))));
 	case PMD_SIZE:
-		entry = pmd_pte(pmd_mkhuge(pte_pmd(entry)));
-		break;
+		return pmd_pte(pmd_mkhuge(pte_pmd(entry)));
 	case CONT_PTE_SIZE:
-		entry = pte_mkcont(entry);
-		break;
+		return pte_mkcont(entry);
 	default:
-		pr_warn("%s: unrecognized huge page size 0x%lx\n",
-			__func__, pagesize);
 		break;
 	}
+	pr_warn("%s: unrecognized huge page size 0x%lx\n",
+		__func__, pagesize);
 	return entry;
 }