linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Revert "mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge"
@ 2021-07-17 16:01 Jonathan Marek
  2021-07-20 12:33 ` Ard Biesheuvel
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Marek @ 2021-07-17 16:01 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Catalin Marinas, Will Deacon, Dave Hansen, Andy Lutomirski,
	Peter Zijlstra, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, Anshuman Khandual, Andrew Morton, Ard Biesheuvel,
	Mike Rapoport, Nicholas Piggin, Pavel Tatashin,
	Thomas Bogendoerfer, Aneesh Kumar K.V, Pekka Enberg,
	Steven Price, Christophe Leroy, Daniel Axtens, Huang Pei,
	Randy Dunlap, Bhaskar Chowdhury, open list

c742199a breaks arm64 for some configs because it stubs out functions which
should not have been stubbed out.

With 4K pages and ARM64_VA_BITS_39=y, the kernel crashes early on unmapped
1G pages in the linear map caused by pud_set_huge() in alloc_init_pud()
being stubbed out. Reverting c742199a fixes the crash.

Fixes: c742199a ("mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge")
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
---
 arch/arm64/mm/mmu.c     | 20 ++++++++------------
 arch/x86/mm/pgtable.c   | 34 +++++++++++++++-------------------
 include/linux/pgtable.h | 26 +-------------------------
 3 files changed, 24 insertions(+), 56 deletions(-)

diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index d745865084488..9ff0de1b2b93c 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1339,7 +1339,6 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
 	return dt_virt;
 }
 
-#if CONFIG_PGTABLE_LEVELS > 3
 int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
 {
 	pud_t new_pud = pfn_pud(__phys_to_pfn(phys), mk_pud_sect_prot(prot));
@@ -1354,16 +1353,6 @@ int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
 	return 1;
 }
 
-int pud_clear_huge(pud_t *pudp)
-{
-	if (!pud_sect(READ_ONCE(*pudp)))
-		return 0;
-	pud_clear(pudp);
-	return 1;
-}
-#endif
-
-#if CONFIG_PGTABLE_LEVELS > 2
 int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot)
 {
 	pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), mk_pmd_sect_prot(prot));
@@ -1378,6 +1367,14 @@ int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot)
 	return 1;
 }
 
+int pud_clear_huge(pud_t *pudp)
+{
+	if (!pud_sect(READ_ONCE(*pudp)))
+		return 0;
+	pud_clear(pudp);
+	return 1;
+}
+
 int pmd_clear_huge(pmd_t *pmdp)
 {
 	if (!pmd_sect(READ_ONCE(*pmdp)))
@@ -1385,7 +1382,6 @@ int pmd_clear_huge(pmd_t *pmdp)
 	pmd_clear(pmdp);
 	return 1;
 }
-#endif
 
 int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr)
 {
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 3364fe62b9037..3481b35cb4ec7 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -682,7 +682,6 @@ int p4d_clear_huge(p4d_t *p4d)
 }
 #endif
 
-#if CONFIG_PGTABLE_LEVELS > 3
 /**
  * pud_set_huge - setup kernel PUD mapping
  *
@@ -721,23 +720,6 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
 	return 1;
 }
 
-/**
- * pud_clear_huge - clear kernel PUD mapping when it is set
- *
- * Returns 1 on success and 0 on failure (no PUD map is found).
- */
-int pud_clear_huge(pud_t *pud)
-{
-	if (pud_large(*pud)) {
-		pud_clear(pud);
-		return 1;
-	}
-
-	return 0;
-}
-#endif
-
-#if CONFIG_PGTABLE_LEVELS > 2
 /**
  * pmd_set_huge - setup kernel PMD mapping
  *
@@ -768,6 +750,21 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
 	return 1;
 }
 
+/**
+ * pud_clear_huge - clear kernel PUD mapping when it is set
+ *
+ * Returns 1 on success and 0 on failure (no PUD map is found).
+ */
+int pud_clear_huge(pud_t *pud)
+{
+	if (pud_large(*pud)) {
+		pud_clear(pud);
+		return 1;
+	}
+
+	return 0;
+}
+
 /**
  * pmd_clear_huge - clear kernel PMD mapping when it is set
  *
@@ -782,7 +779,6 @@ int pmd_clear_huge(pmd_t *pmd)
 
 	return 0;
 }
-#endif
 
 #ifdef CONFIG_X86_64
 /**
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index d147480cdefc7..e24d2c992b112 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1397,34 +1397,10 @@ static inline int p4d_clear_huge(p4d_t *p4d)
 }
 #endif /* !__PAGETABLE_P4D_FOLDED */
 
-#ifndef __PAGETABLE_PUD_FOLDED
 int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot);
-int pud_clear_huge(pud_t *pud);
-#else
-static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
-{
-	return 0;
-}
-static inline int pud_clear_huge(pud_t *pud)
-{
-	return 0;
-}
-#endif /* !__PAGETABLE_PUD_FOLDED */
-
-#ifndef __PAGETABLE_PMD_FOLDED
 int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot);
+int pud_clear_huge(pud_t *pud);
 int pmd_clear_huge(pmd_t *pmd);
-#else
-static inline int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
-{
-	return 0;
-}
-static inline int pmd_clear_huge(pmd_t *pmd)
-{
-	return 0;
-}
-#endif /* !__PAGETABLE_PMD_FOLDED */
-
 int p4d_free_pud_page(p4d_t *p4d, unsigned long addr);
 int pud_free_pmd_page(pud_t *pud, unsigned long addr);
 int pmd_free_pte_page(pmd_t *pmd, unsigned long addr);
-- 
2.26.1


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

* Re: [PATCH] Revert "mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge"
  2021-07-17 16:01 [PATCH] Revert "mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge" Jonathan Marek
@ 2021-07-20 12:33 ` Ard Biesheuvel
  0 siblings, 0 replies; 2+ messages in thread
From: Ard Biesheuvel @ 2021-07-20 12:33 UTC (permalink / raw)
  To: Jonathan Marek
  Cc: Linux ARM, Catalin Marinas, Will Deacon, Dave Hansen,
	Andy Lutomirski, Peter Zijlstra, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, Anshuman Khandual, Andrew Morton, Mike Rapoport,
	Nicholas Piggin, Pavel Tatashin, Thomas Bogendoerfer,
	Aneesh Kumar K.V, Pekka Enberg, Steven Price, Christophe Leroy,
	Daniel Axtens, Huang Pei, Randy Dunlap, Bhaskar Chowdhury,
	open list

On Sat, 17 Jul 2021 at 18:06, Jonathan Marek <jonathan@marek.ca> wrote:
>
> c742199a breaks arm64 for some configs because it stubs out functions which
> should not have been stubbed out.
>
> With 4K pages and ARM64_VA_BITS_39=y, the kernel crashes early on unmapped
> 1G pages in the linear map caused by pud_set_huge() in alloc_init_pud()
> being stubbed out. Reverting c742199a fixes the crash.
>
> Fixes: c742199a ("mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge")
> Signed-off-by: Jonathan Marek <jonathan@marek.ca>

(replying here because some cc'ees were dropped from Christophe's
reply and the thread that followed it - unfortunately, lore does not
seem to have captured any of that discussion either)

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  arch/arm64/mm/mmu.c     | 20 ++++++++------------
>  arch/x86/mm/pgtable.c   | 34 +++++++++++++++-------------------
>  include/linux/pgtable.h | 26 +-------------------------
>  3 files changed, 24 insertions(+), 56 deletions(-)
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index d745865084488..9ff0de1b2b93c 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -1339,7 +1339,6 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
>         return dt_virt;
>  }
>
> -#if CONFIG_PGTABLE_LEVELS > 3
>  int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
>  {
>         pud_t new_pud = pfn_pud(__phys_to_pfn(phys), mk_pud_sect_prot(prot));
> @@ -1354,16 +1353,6 @@ int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
>         return 1;
>  }
>
> -int pud_clear_huge(pud_t *pudp)
> -{
> -       if (!pud_sect(READ_ONCE(*pudp)))
> -               return 0;
> -       pud_clear(pudp);
> -       return 1;
> -}
> -#endif
> -
> -#if CONFIG_PGTABLE_LEVELS > 2
>  int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot)
>  {
>         pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), mk_pmd_sect_prot(prot));
> @@ -1378,6 +1367,14 @@ int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot)
>         return 1;
>  }
>
> +int pud_clear_huge(pud_t *pudp)
> +{
> +       if (!pud_sect(READ_ONCE(*pudp)))
> +               return 0;
> +       pud_clear(pudp);
> +       return 1;
> +}
> +
>  int pmd_clear_huge(pmd_t *pmdp)
>  {
>         if (!pmd_sect(READ_ONCE(*pmdp)))
> @@ -1385,7 +1382,6 @@ int pmd_clear_huge(pmd_t *pmdp)
>         pmd_clear(pmdp);
>         return 1;
>  }
> -#endif
>
>  int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr)
>  {
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index 3364fe62b9037..3481b35cb4ec7 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -682,7 +682,6 @@ int p4d_clear_huge(p4d_t *p4d)
>  }
>  #endif
>
> -#if CONFIG_PGTABLE_LEVELS > 3
>  /**
>   * pud_set_huge - setup kernel PUD mapping
>   *
> @@ -721,23 +720,6 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
>         return 1;
>  }
>
> -/**
> - * pud_clear_huge - clear kernel PUD mapping when it is set
> - *
> - * Returns 1 on success and 0 on failure (no PUD map is found).
> - */
> -int pud_clear_huge(pud_t *pud)
> -{
> -       if (pud_large(*pud)) {
> -               pud_clear(pud);
> -               return 1;
> -       }
> -
> -       return 0;
> -}
> -#endif
> -
> -#if CONFIG_PGTABLE_LEVELS > 2
>  /**
>   * pmd_set_huge - setup kernel PMD mapping
>   *
> @@ -768,6 +750,21 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
>         return 1;
>  }
>
> +/**
> + * pud_clear_huge - clear kernel PUD mapping when it is set
> + *
> + * Returns 1 on success and 0 on failure (no PUD map is found).
> + */
> +int pud_clear_huge(pud_t *pud)
> +{
> +       if (pud_large(*pud)) {
> +               pud_clear(pud);
> +               return 1;
> +       }
> +
> +       return 0;
> +}
> +
>  /**
>   * pmd_clear_huge - clear kernel PMD mapping when it is set
>   *
> @@ -782,7 +779,6 @@ int pmd_clear_huge(pmd_t *pmd)
>
>         return 0;
>  }
> -#endif
>
>  #ifdef CONFIG_X86_64
>  /**
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index d147480cdefc7..e24d2c992b112 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -1397,34 +1397,10 @@ static inline int p4d_clear_huge(p4d_t *p4d)
>  }
>  #endif /* !__PAGETABLE_P4D_FOLDED */
>
> -#ifndef __PAGETABLE_PUD_FOLDED
>  int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot);
> -int pud_clear_huge(pud_t *pud);
> -#else
> -static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
> -{
> -       return 0;
> -}
> -static inline int pud_clear_huge(pud_t *pud)
> -{
> -       return 0;
> -}
> -#endif /* !__PAGETABLE_PUD_FOLDED */
> -
> -#ifndef __PAGETABLE_PMD_FOLDED
>  int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot);
> +int pud_clear_huge(pud_t *pud);
>  int pmd_clear_huge(pmd_t *pmd);
> -#else
> -static inline int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)
> -{
> -       return 0;
> -}
> -static inline int pmd_clear_huge(pmd_t *pmd)
> -{
> -       return 0;
> -}
> -#endif /* !__PAGETABLE_PMD_FOLDED */
> -
>  int p4d_free_pud_page(p4d_t *p4d, unsigned long addr);
>  int pud_free_pmd_page(pud_t *pud, unsigned long addr);
>  int pmd_free_pte_page(pmd_t *pmd, unsigned long addr);
> --
> 2.26.1
>

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

end of thread, other threads:[~2021-07-20 12:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-17 16:01 [PATCH] Revert "mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge" Jonathan Marek
2021-07-20 12:33 ` Ard Biesheuvel

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).