arm64/mm: Redefine CONT_{PTE, PMD}_SHIFT
diff mbox series

Message ID 20200630062428.194235-1-gshan@redhat.com
State Mainlined
Commit a1634a542f74309f843742fa849208bb26e279e4
Headers show
Series
  • arm64/mm: Redefine CONT_{PTE, PMD}_SHIFT
Related show

Commit Message

Gavin Shan June 30, 2020, 6:24 a.m. UTC
Currently, the value of CONT_{PTE, PMD}_SHIFT is off from standard
{PAGE, PMD}_SHIFT. In turn, we have to consider adding {PAGE, PMD}_SHIFT
when using CONT_{PTE, PMD}_SHIFT in the function hugetlbpage_init().
It's a bit confusing.

This redefines CONT_{PTE, PMD}_SHIFT with {PAGE, PMD}_SHIFT included
so that the later values needn't be added when using the former ones
in function hugetlbpage_init(). Note that the values of CONT_{PTES, PMDS}
are unchanged.

Link: https://lkml.org/lkml/2020/5/6/190
Suggested-by: Will Deacon <will@kernel.org>
Signed-off-by: Gavin Shan <gshan@redhat.com>
---
 arch/arm64/include/asm/pgtable-hwdef.h | 16 ++++++++--------
 arch/arm64/mm/hugetlbpage.c            |  4 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

Comments

Anshuman Khandual June 30, 2020, 8:34 a.m. UTC | #1
On 06/30/2020 11:54 AM, Gavin Shan wrote:
> Currently, the value of CONT_{PTE, PMD}_SHIFT is off from standard
> {PAGE, PMD}_SHIFT. In turn, we have to consider adding {PAGE, PMD}_SHIFT
Right.

> when using CONT_{PTE, PMD}_SHIFT in the function hugetlbpage_init().

Could also be used here https://patchwork.kernel.org/patch/11630503/

> It's a bit confusing.
> 
> This redefines CONT_{PTE, PMD}_SHIFT with {PAGE, PMD}_SHIFT included
> so that the later values needn't be added when using the former ones
> in function hugetlbpage_init(). Note that the values of CONT_{PTES, PMDS}
> are unchanged.
> 
> Link: https://lkml.org/lkml/2020/5/6/190
> Suggested-by: Will Deacon <will@kernel.org>
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>  arch/arm64/include/asm/pgtable-hwdef.h | 16 ++++++++--------
>  arch/arm64/mm/hugetlbpage.c            |  4 ++--
>  2 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h
> index 9c91a8f93a0e..ce3d14abb360 100644
> --- a/arch/arm64/include/asm/pgtable-hwdef.h
> +++ b/arch/arm64/include/asm/pgtable-hwdef.h
> @@ -82,20 +82,20 @@
>   * Contiguous page definitions.
>   */
>  #ifdef CONFIG_ARM64_64K_PAGES
> -#define CONT_PTE_SHIFT		5
> -#define CONT_PMD_SHIFT		5
> +#define CONT_PTE_SHIFT		(5 + PAGE_SHIFT)
> +#define CONT_PMD_SHIFT		(5 + PMD_SHIFT)
>  #elif defined(CONFIG_ARM64_16K_PAGES)
> -#define CONT_PTE_SHIFT		7
> -#define CONT_PMD_SHIFT		5
> +#define CONT_PTE_SHIFT		(7 + PAGE_SHIFT)
> +#define CONT_PMD_SHIFT		(5 + PMD_SHIFT)
>  #else
> -#define CONT_PTE_SHIFT		4
> -#define CONT_PMD_SHIFT		4
> +#define CONT_PTE_SHIFT		(4 + PAGE_SHIFT)
> +#define CONT_PMD_SHIFT		(4 + PMD_SHIFT)
>  #endif
>  
> -#define CONT_PTES		(1 << CONT_PTE_SHIFT)
> +#define CONT_PTES		(1 << (CONT_PTE_SHIFT - PAGE_SHIFT))
>  #define CONT_PTE_SIZE		(CONT_PTES * PAGE_SIZE)
>  #define CONT_PTE_MASK		(~(CONT_PTE_SIZE - 1))
> -#define CONT_PMDS		(1 << CONT_PMD_SHIFT)
> +#define CONT_PMDS		(1 << (CONT_PMD_SHIFT - PMD_SHIFT))
>  #define CONT_PMD_SIZE		(CONT_PMDS * PMD_SIZE)
>  #define CONT_PMD_MASK		(~(CONT_PMD_SIZE - 1))
>  /* the the numerical offset of the PTE within a range of CONT_PTES */
> diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
> index 0a52ce46f020..c79084739096 100644
> --- a/arch/arm64/mm/hugetlbpage.c
> +++ b/arch/arm64/mm/hugetlbpage.c
> @@ -457,9 +457,9 @@ static int __init hugetlbpage_init(void)
>  #ifdef CONFIG_ARM64_4K_PAGES
>  	hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
>  #endif
> -	hugetlb_add_hstate((CONT_PMD_SHIFT + PMD_SHIFT) - PAGE_SHIFT);
> +	hugetlb_add_hstate(CONT_PMD_SHIFT - PAGE_SHIFT);
>  	hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT);
> -	hugetlb_add_hstate((CONT_PTE_SHIFT + PAGE_SHIFT) - PAGE_SHIFT);
> +	hugetlb_add_hstate(CONT_PTE_SHIFT - PAGE_SHIFT);
>  
>  	return 0;
>  }
> 

Ran through some basic tests on 4K/16K/64K.

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Catalin Marinas July 3, 2020, 5:15 p.m. UTC | #2
On Tue, 30 Jun 2020 16:24:28 +1000, Gavin Shan wrote:
> Currently, the value of CONT_{PTE, PMD}_SHIFT is off from standard
> {PAGE, PMD}_SHIFT. In turn, we have to consider adding {PAGE, PMD}_SHIFT
> when using CONT_{PTE, PMD}_SHIFT in the function hugetlbpage_init().
> It's a bit confusing.
> 
> This redefines CONT_{PTE, PMD}_SHIFT with {PAGE, PMD}_SHIFT included
> so that the later values needn't be added when using the former ones
> in function hugetlbpage_init(). Note that the values of CONT_{PTES, PMDS}
> are unchanged.

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

[1/1] arm64/mm: Redefine CONT_{PTE, PMD}_SHIFT
      https://git.kernel.org/arm64/c/a1634a542f74

Patch
diff mbox series

diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h
index 9c91a8f93a0e..ce3d14abb360 100644
--- a/arch/arm64/include/asm/pgtable-hwdef.h
+++ b/arch/arm64/include/asm/pgtable-hwdef.h
@@ -82,20 +82,20 @@ 
  * Contiguous page definitions.
  */
 #ifdef CONFIG_ARM64_64K_PAGES
-#define CONT_PTE_SHIFT		5
-#define CONT_PMD_SHIFT		5
+#define CONT_PTE_SHIFT		(5 + PAGE_SHIFT)
+#define CONT_PMD_SHIFT		(5 + PMD_SHIFT)
 #elif defined(CONFIG_ARM64_16K_PAGES)
-#define CONT_PTE_SHIFT		7
-#define CONT_PMD_SHIFT		5
+#define CONT_PTE_SHIFT		(7 + PAGE_SHIFT)
+#define CONT_PMD_SHIFT		(5 + PMD_SHIFT)
 #else
-#define CONT_PTE_SHIFT		4
-#define CONT_PMD_SHIFT		4
+#define CONT_PTE_SHIFT		(4 + PAGE_SHIFT)
+#define CONT_PMD_SHIFT		(4 + PMD_SHIFT)
 #endif
 
-#define CONT_PTES		(1 << CONT_PTE_SHIFT)
+#define CONT_PTES		(1 << (CONT_PTE_SHIFT - PAGE_SHIFT))
 #define CONT_PTE_SIZE		(CONT_PTES * PAGE_SIZE)
 #define CONT_PTE_MASK		(~(CONT_PTE_SIZE - 1))
-#define CONT_PMDS		(1 << CONT_PMD_SHIFT)
+#define CONT_PMDS		(1 << (CONT_PMD_SHIFT - PMD_SHIFT))
 #define CONT_PMD_SIZE		(CONT_PMDS * PMD_SIZE)
 #define CONT_PMD_MASK		(~(CONT_PMD_SIZE - 1))
 /* the the numerical offset of the PTE within a range of CONT_PTES */
diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c
index 0a52ce46f020..c79084739096 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -457,9 +457,9 @@  static int __init hugetlbpage_init(void)
 #ifdef CONFIG_ARM64_4K_PAGES
 	hugetlb_add_hstate(PUD_SHIFT - PAGE_SHIFT);
 #endif
-	hugetlb_add_hstate((CONT_PMD_SHIFT + PMD_SHIFT) - PAGE_SHIFT);
+	hugetlb_add_hstate(CONT_PMD_SHIFT - PAGE_SHIFT);
 	hugetlb_add_hstate(PMD_SHIFT - PAGE_SHIFT);
-	hugetlb_add_hstate((CONT_PTE_SHIFT + PAGE_SHIFT) - PAGE_SHIFT);
+	hugetlb_add_hstate(CONT_PTE_SHIFT - PAGE_SHIFT);
 
 	return 0;
 }