arch/arm64/mm/hugetlbpage.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
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.
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 V2:
- Added an warning when PUD_SIZE is requested but not supported per Ryan
Changes in V1:
https://lore.kernel.org/all/20250217065414.49489-1-anshuman.khandual@arm.com/
arch/arm64/mm/hugetlbpage.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 98a2a0e64e25..1d89599a20d7 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,7 +366,10 @@ 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())
+ entry = pud_pte(pud_mkhuge(pte_pud(entry)));
+ else
+ pr_warn("%s: pud huge page not supported\n", __func__);
break;
#endif
case CONT_PMD_SIZE:
--
2.30.2
On 18/02/2025 11:36, 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.
>
> 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 V2:
>
> - Added an warning when PUD_SIZE is requested but not supported per Ryan
>
> Changes in V1:
>
> https://lore.kernel.org/all/20250217065414.49489-1-anshuman.khandual@arm.com/
>
> arch/arm64/mm/hugetlbpage.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> index 98a2a0e64e25..1d89599a20d7 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,7 +366,10 @@ 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())
> + entry = pud_pte(pud_mkhuge(pte_pud(entry)));
> + else
> + pr_warn("%s: pud huge page not supported\n", __func__);
> break;
> #endif
> case CONT_PMD_SIZE:
Personally, I think something like this is cleaner than having 2 warnings:
pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
{
size_t pagesize = 1UL << shift;
switch (pagesize) {
#ifndef __PAGETABLE_PMD_FOLDED
case PUD_SIZE:
if (pud_sect_supported())
return pud_pte(pud_mkhuge(pte_pud(entry)));
break;
#endif
case CONT_PMD_SIZE:
return pmd_pte(pmd_mkhuge(pmd_mkcont(pte_pmd(entry))));
case PMD_SIZE:
return pmd_pte(pmd_mkhuge(pte_pmd(entry)));
case CONT_PTE_SIZE:
return pte_mkcont(entry);
}
pr_warn("%s: unrecognized huge page size 0x%lx\n",
__func__, pagesize);
return entry;
}
Thanks,
Ryan
On 2/18/25 19:31, Ryan Roberts wrote:
> On 18/02/2025 11:36, 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.
>>
>> 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 V2:
>>
>> - Added an warning when PUD_SIZE is requested but not supported per Ryan
>>
>> Changes in V1:
>>
>> https://lore.kernel.org/all/20250217065414.49489-1-anshuman.khandual@arm.com/
>>
>> arch/arm64/mm/hugetlbpage.c | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
>> index 98a2a0e64e25..1d89599a20d7 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,7 +366,10 @@ 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())
>> + entry = pud_pte(pud_mkhuge(pte_pud(entry)));
>> + else
>> + pr_warn("%s: pud huge page not supported\n", __func__);
>> break;
>> #endif
>> case CONT_PMD_SIZE:
>
> Personally, I think something like this is cleaner than having 2 warnings:
>
> pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
> {
> size_t pagesize = 1UL << shift;
>
> switch (pagesize) {
> #ifndef __PAGETABLE_PMD_FOLDED
> case PUD_SIZE:
> if (pud_sect_supported())
> return pud_pte(pud_mkhuge(pte_pud(entry)));
> break;
> #endif
> case CONT_PMD_SIZE:
> return pmd_pte(pmd_mkhuge(pmd_mkcont(pte_pmd(entry))));
> case PMD_SIZE:
> return pmd_pte(pmd_mkhuge(pte_pmd(entry)));
> case CONT_PTE_SIZE:
> return pte_mkcont(entry);
A "default" entry is needed here for the switch statement above. But that
could be just a simple break statement.
> }
>
> pr_warn("%s: unrecognized huge page size 0x%lx\n",
> __func__, pagesize);
> return entry;
> }
Initially thought about that, but wondered if "unsupported" should be called
out as "unrecognized" instead. But that's a trivial detail. So I will do the
changes as suggested.
© 2016 - 2025 Red Hat, Inc.