mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] arm64/hugetlb: Consistently use pud_sect_supported()
@ 2025-02-17  6:54 Anshuman Khandual
  2025-02-17 14:21 ` Ryan Roberts
  0 siblings, 1 reply; 3+ messages in thread
From: Anshuman Khandual @ 2025-02-17  6:54 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: ryan.roberts, Anshuman Khandual, Catalin Marinas, Will Deacon,
	linux-kernel

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

 arch/arm64/mm/hugetlbpage.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 98a2a0e64e25..5b7cfdba9c93 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,8 @@ 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)));
 		break;
 #endif
 	case CONT_PMD_SIZE:
-- 
2.30.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm64/hugetlb: Consistently use pud_sect_supported()
  2025-02-17  6:54 [PATCH] arm64/hugetlb: Consistently use pud_sect_supported() Anshuman Khandual
@ 2025-02-17 14:21 ` Ryan Roberts
  2025-02-18  4:02   ` Anshuman Khandual
  0 siblings, 1 reply; 3+ messages in thread
From: Ryan Roberts @ 2025-02-17 14:21 UTC (permalink / raw)
  To: Anshuman Khandual, linux-arm-kernel
  Cc: Catalin Marinas, Will Deacon, linux-kernel

On 17/02/2025 06:54, 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
> 
>  arch/arm64/mm/hugetlbpage.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> index 98a2a0e64e25..5b7cfdba9c93 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,8 @@ 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)));

If this was to get called with PUD_SIZE for a config that doesn't fold the PMD
and which pud_sect_supported() returns false, we will now return the entry
unmodified and will not emit the warning that the default case emits. I think we
should at least either modify the entry (so that it is safe) or emit the
warning. Doing neither seems less defensive than the current situation.

>  		break;
>  #endif
>  	case CONT_PMD_SIZE:


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm64/hugetlb: Consistently use pud_sect_supported()
  2025-02-17 14:21 ` Ryan Roberts
@ 2025-02-18  4:02   ` Anshuman Khandual
  0 siblings, 0 replies; 3+ messages in thread
From: Anshuman Khandual @ 2025-02-18  4:02 UTC (permalink / raw)
  To: Ryan Roberts, linux-arm-kernel; +Cc: Catalin Marinas, Will Deacon, linux-kernel



On 2/17/25 19:51, Ryan Roberts wrote:
> On 17/02/2025 06:54, 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
>>
>>  arch/arm64/mm/hugetlbpage.c | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
>> index 98a2a0e64e25..5b7cfdba9c93 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,8 @@ 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)));
> 
> If this was to get called with PUD_SIZE for a config that doesn't fold the PMD
> and which pud_sect_supported() returns false, we will now return the entry
> unmodified and will not emit the warning that the default case emits. I think we
> should at least either modify the entry (so that it is safe) or emit the
> warning. Doing neither seems less defensive than the current situation.

An warning can be added before breaking when pud_sect_supported() returns false
which will help inform the user that the page table entry did not get modified.

        switch (pagesize) {
#ifndef __PAGETABLE_PMD_FOLDED
        case PUD_SIZE:
                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

> 
>>  		break;
>>  #endif
>>  	case CONT_PMD_SIZE:
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-18  4:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-17  6:54 [PATCH] arm64/hugetlb: Consistently use pud_sect_supported() Anshuman Khandual
2025-02-17 14:21 ` Ryan Roberts
2025-02-18  4:02   ` Anshuman Khandual

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®