linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: mm: Drop duplicate check in pmd_trans_huge()
@ 2025-05-08  3:51 Gavin Shan
  2025-05-08  4:00 ` Dev Jain
  2025-05-08  5:44 ` Anshuman Khandual
  0 siblings, 2 replies; 4+ messages in thread
From: Gavin Shan @ 2025-05-08  3:51 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: linux-kernel, catalin.marinas, will, anshuman.khandual,
	ryan.roberts, gshan, peterx, joey.gouly, yangyicong, shan.gavin

pmd_val(pmd) is inclusive to pmd_present(pmd) since the PMD entry
value isn't zero when pmd_present() returns true. Just drop the
duplicate check done by pmd_val(pmd).

No functional changes intended.

Signed-off-by: Gavin Shan <gshan@redhat.com>
---
Found this by code inspection
---
 arch/arm64/include/asm/pgtable.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index d3b538be1500..2599b9b8666f 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -739,8 +739,7 @@ static inline int pmd_trans_huge(pmd_t pmd)
 	 * If pmd is present-invalid, pmd_table() won't detect it
 	 * as a table, so force the valid bit for the comparison.
 	 */
-	return pmd_val(pmd) && pmd_present(pmd) &&
-	       !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID));
+	return pmd_present(pmd) && !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID));
 }
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
-- 
2.49.0



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

* Re: [PATCH] arm64: mm: Drop duplicate check in pmd_trans_huge()
  2025-05-08  3:51 [PATCH] arm64: mm: Drop duplicate check in pmd_trans_huge() Gavin Shan
@ 2025-05-08  4:00 ` Dev Jain
  2025-05-08  5:44 ` Anshuman Khandual
  1 sibling, 0 replies; 4+ messages in thread
From: Dev Jain @ 2025-05-08  4:00 UTC (permalink / raw)
  To: Gavin Shan, linux-arm-kernel
  Cc: linux-kernel, catalin.marinas, will, anshuman.khandual,
	ryan.roberts, peterx, joey.gouly, yangyicong, shan.gavin



On 08/05/25 9:21 am, Gavin Shan wrote:
> pmd_val(pmd) is inclusive to pmd_present(pmd) since the PMD entry
> value isn't zero when pmd_present() returns true. Just drop the
> duplicate check done by pmd_val(pmd).
> 
> No functional changes intended.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
> Found this by code inspection
> ---
>   arch/arm64/include/asm/pgtable.h | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index d3b538be1500..2599b9b8666f 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -739,8 +739,7 @@ static inline int pmd_trans_huge(pmd_t pmd)
>   	 * If pmd is present-invalid, pmd_table() won't detect it
>   	 * as a table, so force the valid bit for the comparison.
>   	 */
> -	return pmd_val(pmd) && pmd_present(pmd) &&
> -	       !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID));
> +	return pmd_present(pmd) && !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID));
>   }
>   #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>   

LGTM

Reviewed-by: Dev Jain <dev.jain@arm.com>


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

* Re: [PATCH] arm64: mm: Drop duplicate check in pmd_trans_huge()
  2025-05-08  3:51 [PATCH] arm64: mm: Drop duplicate check in pmd_trans_huge() Gavin Shan
  2025-05-08  4:00 ` Dev Jain
@ 2025-05-08  5:44 ` Anshuman Khandual
  2025-05-08  8:56   ` Gavin Shan
  1 sibling, 1 reply; 4+ messages in thread
From: Anshuman Khandual @ 2025-05-08  5:44 UTC (permalink / raw)
  To: Gavin Shan, linux-arm-kernel
  Cc: linux-kernel, catalin.marinas, will, ryan.roberts, peterx,
	joey.gouly, yangyicong, shan.gavin

On 5/8/25 09:21, Gavin Shan wrote:
> pmd_val(pmd) is inclusive to pmd_present(pmd) since the PMD entry
> value isn't zero when pmd_present() returns true. Just drop the
> duplicate check done by pmd_val(pmd).

Agreed, pmd_val() is redundant here because a positive pmd_present()
also ensures a positive pmd_val().

#define pmd_present(pmd) pte_present(pmd_pte(pmd))
#define pte_present(pte) (pte_valid(pte) || pte_present_invalid(pte))

#define pte_valid(pte)           (!!(pte_val(pte) & PTE_VALID))
#define pte_present_invalid(pte) ((pte_val(pte) & (PTE_VALID |
				  PTE_PRESENT_INVALID)) == PTE_PRESENT_INVALID)

pte_present() cannot return positive here unless either of the flags
PTE_VALID or PTE_PRESENT_INVALID is set which implies pte_val() would
also return positive.

Probably it would be better to add the above details in the commit
message here as well.

The earlier commit skipped dropping pmd_val() in order to keep then
proposed change confined to just adding new pmd_table() check, even
though pmd_val() redundancy was evident as well which should have
been dropped there after.

d1770e909898 ("arm64/mm: Check pmd_table() in pmd_trans_huge()")

> 
> No functional changes intended.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
> Found this by code inspection
> ---
>  arch/arm64/include/asm/pgtable.h | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index d3b538be1500..2599b9b8666f 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -739,8 +739,7 @@ static inline int pmd_trans_huge(pmd_t pmd)
>  	 * If pmd is present-invalid, pmd_table() won't detect it
>  	 * as a table, so force the valid bit for the comparison.
>  	 */
> -	return pmd_val(pmd) && pmd_present(pmd) &&
> -	       !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID));
> +	return pmd_present(pmd) && !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID));
>  }
>  #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
> 
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>


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

* Re: [PATCH] arm64: mm: Drop duplicate check in pmd_trans_huge()
  2025-05-08  5:44 ` Anshuman Khandual
@ 2025-05-08  8:56   ` Gavin Shan
  0 siblings, 0 replies; 4+ messages in thread
From: Gavin Shan @ 2025-05-08  8:56 UTC (permalink / raw)
  To: Anshuman Khandual, linux-arm-kernel
  Cc: linux-kernel, catalin.marinas, will, ryan.roberts, peterx,
	joey.gouly, yangyicong, shan.gavin

On 5/8/25 3:44 PM, Anshuman Khandual wrote:
> On 5/8/25 09:21, Gavin Shan wrote:
>> pmd_val(pmd) is inclusive to pmd_present(pmd) since the PMD entry
>> value isn't zero when pmd_present() returns true. Just drop the
>> duplicate check done by pmd_val(pmd).
> 
> Agreed, pmd_val() is redundant here because a positive pmd_present()
> also ensures a positive pmd_val().
> 
> #define pmd_present(pmd) pte_present(pmd_pte(pmd))
> #define pte_present(pte) (pte_valid(pte) || pte_present_invalid(pte))
> 
> #define pte_valid(pte)           (!!(pte_val(pte) & PTE_VALID))
> #define pte_present_invalid(pte) ((pte_val(pte) & (PTE_VALID |
> 				  PTE_PRESENT_INVALID)) == PTE_PRESENT_INVALID)
> 
> pte_present() cannot return positive here unless either of the flags
> PTE_VALID or PTE_PRESENT_INVALID is set which implies pte_val() would
> also return positive.
> 
> Probably it would be better to add the above details in the commit
> message here as well.
> 

Thanks, I've squashed those details to v2, which was just posted.

> The earlier commit skipped dropping pmd_val() in order to keep then
> proposed change confined to just adding new pmd_table() check, even
> though pmd_val() redundancy was evident as well which should have
> been dropped there after.
> 
> d1770e909898 ("arm64/mm: Check pmd_table() in pmd_trans_huge()")
> 

Yes, agreed.

>>
>> No functional changes intended.
>>
>> Signed-off-by: Gavin Shan <gshan@redhat.com>
>> ---
>> Found this by code inspection
>> ---
>>   arch/arm64/include/asm/pgtable.h | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
>> index d3b538be1500..2599b9b8666f 100644
>> --- a/arch/arm64/include/asm/pgtable.h
>> +++ b/arch/arm64/include/asm/pgtable.h
>> @@ -739,8 +739,7 @@ static inline int pmd_trans_huge(pmd_t pmd)
>>   	 * If pmd is present-invalid, pmd_table() won't detect it
>>   	 * as a table, so force the valid bit for the comparison.
>>   	 */
>> -	return pmd_val(pmd) && pmd_present(pmd) &&
>> -	       !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID));
>> +	return pmd_present(pmd) && !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID));
>>   }
>>   #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>>
> Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
> 

Thanks,
Gavin



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

end of thread, other threads:[~2025-05-08  9:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-08  3:51 [PATCH] arm64: mm: Drop duplicate check in pmd_trans_huge() Gavin Shan
2025-05-08  4:00 ` Dev Jain
2025-05-08  5:44 ` Anshuman Khandual
2025-05-08  8:56   ` Gavin Shan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).