arch: fix has_transparent_hugepage()
authorHugh Dickins <hughd@google.com>
Fri, 20 May 2016 00:13:00 +0000 (17:13 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 20 May 2016 02:12:14 +0000 (19:12 -0700)
I've just discovered that the useful-sounding has_transparent_hugepage()
is actually an architecture-dependent minefield: on some arches it only
builds if CONFIG_TRANSPARENT_HUGEPAGE=y, on others it's also there when
not, but on some of those (arm and arm64) it then gives the wrong
answer; and on mips alone it's marked __init, which would crash if
called later (but so far it has not been called later).

Straighten this out: make it available to all configs, with a sensible
default in asm-generic/pgtable.h, removing its definitions from those
arches (arc, arm, arm64, sparc, tile) which are served by the default,
adding #define has_transparent_hugepage has_transparent_hugepage to
those (mips, powerpc, s390, x86) which need to override the default at
runtime, and removing the __init from mips (but maybe that kind of code
should be avoided after init: set a static variable the first time it's
called).

Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Andres Lagar-Cavilla <andreslc@google.com>
Cc: Yang Shi <yang.shi@linaro.org>
Cc: Ning Qu <quning@gmail.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Acked-by: Vineet Gupta <vgupta@synopsys.com> [arch/arc]
Acked-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> [arch/s390]
Acked-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
12 files changed:
arch/arc/include/asm/hugepage.h
arch/arm/include/asm/pgtable-3level.h
arch/arm64/include/asm/pgtable.h
arch/mips/include/asm/pgtable.h
arch/mips/mm/tlb-r4k.c
arch/powerpc/include/asm/book3s/64/pgtable.h
arch/powerpc/include/asm/pgtable.h
arch/s390/include/asm/pgtable.h
arch/sparc/include/asm/pgtable_64.h
arch/tile/include/asm/pgtable.h
arch/x86/include/asm/pgtable.h
include/asm-generic/pgtable.h

index 7afe3356b770287d30fba05c7c6d16db531efa43..317ff773e1ca5f4de6e7ab03dc1c9f184426a2d2 100644 (file)
@@ -61,8 +61,6 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
 extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
                                 pmd_t *pmd);
 
-#define has_transparent_hugepage() 1
-
 /* Generic variants assume pgtable_t is struct page *, hence need for these */
 #define __HAVE_ARCH_PGTABLE_DEPOSIT
 extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
index dc46398bc3a528ccf51fb01cdabd143036df10de..fa70db7c714b605ff98e4efeb264c944214aabab 100644 (file)
@@ -281,11 +281,6 @@ static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
        flush_pmd_entry(pmdp);
 }
 
-static inline int has_transparent_hugepage(void)
-{
-       return 1;
-}
-
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_PGTABLE_3LEVEL_H */
index 2da46ae9c991e3fbbfd8337b39738b7b467789b3..a7ac45a03dd0f043eec6cd99878941785e54b01b 100644 (file)
@@ -314,11 +314,6 @@ static inline int pmd_protnone(pmd_t pmd)
 
 #define set_pmd_at(mm, addr, pmdp, pmd)        set_pte_at(mm, addr, (pte_t *)pmdp, pmd_pte(pmd))
 
-static inline int has_transparent_hugepage(void)
-{
-       return 1;
-}
-
 #define __pgprot_modify(prot,mask,bits) \
        __pgprot((pgprot_val(prot) & ~(mask)) | (bits))
 
index 9a4fe0133ff1c7d82685d426dc1a91b371a972a6..f53a7e3a4dd9ce0cab5731316cfc21c87a5690b7 100644 (file)
@@ -468,6 +468,7 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma,
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 
+#define has_transparent_hugepage has_transparent_hugepage
 extern int has_transparent_hugepage(void);
 
 static inline int pmd_trans_huge(pmd_t pmd)
index c17d7627f872bffd148dc093386a3cf8efd4ebd8..2d93b63cf8300e17c4ad08e46a043c8a7b014cb9 100644 (file)
@@ -400,19 +400,20 @@ void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 
-int __init has_transparent_hugepage(void)
+int has_transparent_hugepage(void)
 {
-       unsigned int mask;
-       unsigned long flags;
-
-       local_irq_save(flags);
-       write_c0_pagemask(PM_HUGE_MASK);
-       back_to_back_c0_hazard();
-       mask = read_c0_pagemask();
-       write_c0_pagemask(PM_DEFAULT_MASK);
+       static unsigned int mask = -1;
 
-       local_irq_restore(flags);
+       if (mask == -1) {       /* first call comes during __init */
+               unsigned long flags;
 
+               local_irq_save(flags);
+               write_c0_pagemask(PM_HUGE_MASK);
+               back_to_back_c0_hazard();
+               mask = read_c0_pagemask();
+               write_c0_pagemask(PM_DEFAULT_MASK);
+               local_irq_restore(flags);
+       }
        return mask == PM_HUGE_MASK;
 }
 
index 77d3ce05798e34e9a9e7ab8bdbca1d90ae5174a7..8fe6f6b48aa56c074c483e6d06b6fe620efaea08 100644 (file)
@@ -219,6 +219,7 @@ extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
                       pmd_t *pmdp, pmd_t pmd);
 extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
                                 pmd_t *pmd);
+#define has_transparent_hugepage has_transparent_hugepage
 extern int has_transparent_hugepage(void);
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
index 47897a30982d6aee476c5be51c7e81ada53158a5..ee09e99097f026ed1a8c3242cf20b447504c109b 100644 (file)
@@ -65,7 +65,6 @@ extern int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
                       struct page **pages, int *nr);
 #ifndef CONFIG_TRANSPARENT_HUGEPAGE
 #define pmd_large(pmd)         0
-#define has_transparent_hugepage() 0
 #endif
 pte_t *__find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,
                                   bool *is_thp, unsigned *shift);
index 2f66645587a2a134d9d2a304ae6508fedfc1fd8a..18d2beb89340a6deeb4e9cdb48cca5a27b23155d 100644 (file)
@@ -1223,6 +1223,7 @@ static inline int pmd_trans_huge(pmd_t pmd)
        return pmd_val(pmd) & _SEGMENT_ENTRY_LARGE;
 }
 
+#define has_transparent_hugepage has_transparent_hugepage
 static inline int has_transparent_hugepage(void)
 {
        return MACHINE_HAS_HPAGE ? 1 : 0;
index f089cfa249f335b419de702333ddc341e7e3acc3..93ce0ada3c63fe1dfbd918125d7663886a78031d 100644 (file)
@@ -681,8 +681,6 @@ static inline unsigned long pmd_trans_huge(pmd_t pmd)
        return pte_val(pte) & _PAGE_PMD_HUGE;
 }
 
-#define has_transparent_hugepage() 1
-
 static inline pmd_t pmd_mkold(pmd_t pmd)
 {
        pte_t pte = __pte(pmd_val(pmd));
index 96cecf55522ef492f1afbdd143ca80536d63d31d..2a26cc4fefc27fda65d15be3b3a0b719231ad609 100644 (file)
@@ -487,7 +487,6 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
 }
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-#define has_transparent_hugepage() 1
 #define pmd_trans_huge pmd_huge_page
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
index f86491a7bc9dd1c8c96f52f28b9befd0ff59d6ea..1a27396b6ea04df12b2cff8930341320e7a4a819 100644 (file)
@@ -181,6 +181,7 @@ static inline int pmd_trans_huge(pmd_t pmd)
        return (pmd_val(pmd) & (_PAGE_PSE|_PAGE_DEVMAP)) == _PAGE_PSE;
 }
 
+#define has_transparent_hugepage has_transparent_hugepage
 static inline int has_transparent_hugepage(void)
 {
        return boot_cpu_has(X86_FEATURE_PSE);
index 9401f4819891177e64ebfa488fb9b9d9b96e00be..d4458b6dbfb48831c833b203edc058f6f4a9e847 100644 (file)
@@ -806,4 +806,12 @@ static inline int pmd_clear_huge(pmd_t *pmd)
 #define io_remap_pfn_range remap_pfn_range
 #endif
 
+#ifndef has_transparent_hugepage
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+#define has_transparent_hugepage() 1
+#else
+#define has_transparent_hugepage() 0
+#endif
+#endif
+
 #endif /* _ASM_GENERIC_PGTABLE_H */