Remove s390 sw-emulated hugepages and cleanup
Subsystems (11)
cover Remove s390 sw-emulated hugepages and cleanup
Hi everyone,
there is a potential bug with KVM and hugetlbfs if the hardware does not support hugepages (EDAT1).
We fix this by making EDAT1 a hard requirement for hugepages and therefore removing and simplifying code.
As s390, with the sw-emulated hugepages, was the only user of arch_prepare/release_hugepage I also removed theses calls from common and other architecture code.
Thanks,
Dominik
Dominik Dingel (5):
s390/mm: make hugepages_supported a boot time decision mm/hugetlb: remove unused arch hook prepare/release_hugepage mm/hugetlb: remove arch_prepare/release_hugepage from arch headers s390/hugetlb: remove dead code for sw emulated huge pages s390/mm: forward check for huge pmds to pmd_large()
arch/arm/include/asm/hugetlb.h | 9 ------ arch/arm64/include/asm/hugetlb.h | 9 ------ arch/ia64/include/asm/hugetlb.h | 9 ------ arch/metag/include/asm/hugetlb.h | 9 ------ arch/mips/include/asm/hugetlb.h | 9 ------ arch/powerpc/include/asm/hugetlb.h | 9 ------ arch/s390/include/asm/hugetlb.h | 3 -- arch/s390/include/asm/page.h | 8 ++--- arch/s390/kernel/setup.c | 2 ++ arch/s390/mm/hugetlbpage.c | 65 +++----------------------------------- arch/s390/mm/pgtable.c | 2 ++ arch/sh/include/asm/hugetlb.h | 9 ------ arch/sparc/include/asm/hugetlb.h | 9 ------ arch/tile/include/asm/hugetlb.h | 9 ------ arch/x86/include/asm/hugetlb.h | 9 ------ mm/hugetlb.c | 10 ------ 16 files changed, 12 insertions(+), 168 deletions(-)
Signature · 1 line
2.3.7
PATCH 1/5 s390/mm: make hugepages_supported a boot time decision
By dropping support for hugepages on machines which do not have the hardware feature EDAT1, we fix a potential s390 KVM bug.
The bug would happen if a guest is backed by hugetlbfs (not supported currently), but does not get pagetables with PGSTE.
This would lead to random memory overwrites.
--- arch/s390/include/asm/page.h | 8 ++++---- arch/s390/kernel/setup.c | 2 ++ arch/s390/mm/pgtable.c | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-)
arch/s390/include/asm/page.h +4 -4
@@ -17,7 +17,10 @@#define PAGE_DEFAULT_ACC 0#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4) -#define HPAGE_SHIFT 20 +#include <asm/setup.h> +#ifndef __ASSEMBLY__ + +extern unsigned int HPAGE_SHIFT ;#define HPAGE_SIZE (1UL << HPAGE_SHIFT)#define HPAGE_MASK (~(HPAGE_SIZE - 1))#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
@@ -27,9 +30,6 @@#define ARCH_HAS_PREPARE_HUGEPAGE #define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH -#include <asm/setup.h> -#ifndef __ASSEMBLY__ -static inline void storage_key_init_range (unsigned long start,unsigned long end) {#if PAGE_DEFAULT_KEY
arch/s390/kernel/setup.c +2 -0
@@ -915,6 +915,8 @@ void __init setup_arch(char **cmdline_p)*/ setup_hwcaps (); +HPAGE_SHIFT =MACHINE_HAS_HPAGE ?20 :0 ; +/* * Create kernel page tables and switch to virtual addressing. */
arch/s390/mm/pgtable.c +2 -0
@@ -36,6 +36,8 @@#endif +unsigned int HPAGE_SHIFT ; +unsigned long *crst_table_alloc (struct mm_struct *mm) {struct page *page =alloc_pages (GFP_KERNEL ,ALLOC_ORDER );
Signature · 1 line
2.3.7
PATCH 2/5 mm/hugetlb: remove unused arch hook prepare/release_hugepage
In reply to Dominik DingelWith s390 dropping support for emulated hugepages, the last user of arch_prepare_hugepage and arch_release_hugepage is gone.
--- mm/hugetlb.c | 10 ---------- 1 file changed, 10 deletions(-)
mm/hugetlb.c +0 -10
@@ -917,7 +917,6 @@ static void update_and_free_page(struct hstate *h, struct page *page)destroy_compound_gigantic_page (page,huge_page_order (h));free_gigantic_page (page,huge_page_order (h)); }else { -arch_release_hugepage (page);__free_pages (page,huge_page_order (h)); } }
@@ -1102,10 +1101,6 @@ static struct page *alloc_fresh_huge_page_node(struct hstate *h, int nid) __GFP_REPEAT|__GFP_NOWARN, huge_page_order(h));if (page) { -if (arch_prepare_hugepage (page)) { -__free_pages (page,huge_page_order (h)); -return NULL ; - }prep_new_huge_page (h, page, nid); }
@@ -1257,11 +1252,6 @@ static struct page *alloc_buddy_huge_page(struct hstate *h, int nid)htlb_alloc_mask (h)|__GFP_COMP|__GFP_THISNODE| __GFP_REPEAT|__GFP_NOWARN, huge_page_order(h)); -if (page &&arch_prepare_hugepage (page)) { -__free_pages (page,huge_page_order (h)); - page =NULL ; - } -spin_lock (&hugetlb_lock);if (page) {INIT_LIST_HEAD (&page->lru);
Signature · 1 line
2.3.7
PATCH 3/5 mm/hugetlb: remove arch_prepare/release_hugepage from arch headers
In reply to Dominik DingelNobody used these hooks so they were removed from common code, and can now be removed from the architectures.
--- arch/arm/include/asm/hugetlb.h | 9 --------- arch/arm64/include/asm/hugetlb.h | 9 --------- arch/ia64/include/asm/hugetlb.h | 9 --------- arch/metag/include/asm/hugetlb.h | 9 --------- arch/mips/include/asm/hugetlb.h | 9 --------- arch/powerpc/include/asm/hugetlb.h | 9 --------- arch/sh/include/asm/hugetlb.h | 9 --------- arch/sparc/include/asm/hugetlb.h | 9 --------- arch/tile/include/asm/hugetlb.h | 9 --------- arch/x86/include/asm/hugetlb.h | 9 --------- 10 files changed, 90 deletions(-)
arch/arm/include/asm/hugetlb.h +0 -9
@@ -63,15 +63,6 @@ static inline pte_t huge_pte_wrprotect(pte_t pte)return pte_wrprotect (pte); } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) {clear_bit (PG_dcache_clean, &page->flags);
arch/arm64/include/asm/hugetlb.h +0 -9
@@ -96,15 +96,6 @@ static inline pte_t huge_pte_wrprotect(pte_t pte)return pte_wrprotect (pte); } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) {clear_bit (PG_dcache_clean, &page->flags);
arch/ia64/include/asm/hugetlb.h +0 -9
@@ -65,15 +65,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
arch/metag/include/asm/hugetlb.h +0 -9
@@ -67,15 +67,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
arch/mips/include/asm/hugetlb.h +0 -9
@@ -110,15 +110,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
arch/powerpc/include/asm/hugetlb.h +0 -9
@@ -168,15 +168,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
arch/sh/include/asm/hugetlb.h +0 -9
@@ -79,15 +79,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) {clear_bit (PG_dcache_clean, &page->flags);
arch/sparc/include/asm/hugetlb.h +0 -9
@@ -78,15 +78,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
arch/tile/include/asm/hugetlb.h +0 -9
@@ -94,15 +94,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
arch/x86/include/asm/hugetlb.h +0 -9
@@ -80,15 +80,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{ -return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
Signature · 1 line
2.3.7
PATCH 4/5 s390/hugetlb: remove dead code for sw emulated huge pages
In reply to Dominik DingelWe now support only hugepages on hardware with EDAT1 support. So we remove the prepare/release_hugepage hooks and simplify set_huge_pte_at and huge_ptep_get.
--- arch/s390/include/asm/hugetlb.h | 3 --- arch/s390/mm/hugetlbpage.c | 60 +++-------------------------------------- 2 files changed, 3 insertions(+), 60 deletions(-)
arch/s390/include/asm/hugetlb.h +0 -3
@@ -37,9 +37,6 @@ static inline int prepare_hugepage_range(struct file *file,#define arch_clear_hugepage_flags (page) do { } while (0) -int arch_prepare_hugepage (struct page *page); -void arch_release_hugepage (struct page *page); -static inline void huge_pte_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) {
arch/s390/mm/hugetlbpage.c +3 -57
79 lines not on this page · raw message
Signature · 1 line
2.3.7
PATCH 5/5 s390/mm: forward check for huge pmds to pmd_large()
In reply to Dominik DingelWe already do the check in pmd_large, so we can just forward the call.
--- arch/s390/mm/hugetlbpage.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
arch/s390/mm/hugetlbpage.c +1 -4
@@ -135,10 +135,7 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)int pmd_huge (pmd_t pmd) { -if (!MACHINE_HAS_HPAGE ) -return 0 ; - -return !!(pmd_val (pmd) & _SEGMENT_ENTRY_LARGE); +return pmd_large (pmd); }int pud_huge (pud_t pud)
Signature · 1 line
2.3.7
Re: [PATCH 3/5] mm/hugetlb: remove arch_prepare/release_hugepage from arch headers
In reply to Dominik DingelOn Thu, May 28, 2015 at 01:52:35PM +0200, Dominik Dingel wrote:
Am 28.05.2015 um 13:52 schrieb Dominik Dingel:
Quoted 6 lines
Hi everyone,
there is a potential bug with KVM and hugetlbfs if the hardware does not support hugepages (EDAT1).
We fix this by making EDAT1 a hard requirement for hugepages and therefore removing and simplifying code.
The cleanup itself is nice and probably the right thing to do. Emulating large pages makes the code more complex and asks for trouble (as outlined above)
The only downside that I see is that z/VM as of today does not announce EDAT1 for its guests so the "emulated" large pages for hugetlbfs would be useful in that case. The current code allocates the page table only once and shares it for all mappers - which is useful for some big databases that spawn hundreds of processes with shared mappings of several hundred GBs. In these cases we do save a decent amount of page table memory.
Not sure if that case is actually important, though.
Christian
Quoted 12 lines · On Mon, 01 Jun 2015 09:35:57 +0200 Christian Borntraeger…
Am 28.05.2015 um 13:52 schrieb Dominik Dingel:
Quoted 6 lines
Hi everyone,
there is a potential bug with KVM and hugetlbfs if the hardware does not support hugepages (EDAT1).
We fix this by making EDAT1 a hard requirement for hugepages and therefore removing and simplifying code.The cleanup itself is nice and probably the right thing to do. Emulating large pages makes the code more complex and asks for trouble (as outlined above)
Quoted 7 lines
The only downside that I see is that z/VM as of today does not announce EDAT1 for its guests so the "emulated" large pages for hugetlbfs would be useful in that case. The current code allocates the page table only once and shares it for all mappers - which is useful for some big databases that spawn hundreds of processes with shared mappings of several hundred GBs. In these cases we do save a decent amount of page table memory.
To limit the damage done, we could always allocate page tables with pgstes for that case. That would allow one guest manipulating another guests storage keys,
but at least would prevent random memory overwrites in the host.
Another thing we could do, make software emulated large pages a kernel config option and only if KVM is not selected allow it, visa versa.
@Martin what do you think?
Thanks,
Dominik
Quoted 4 lines
Not sure if that case is actually important, though.
Christian
Re: [3/5] mm/hugetlb: remove arch_prepare/release_hugepage from arch headers
In reply to Dominik DingelQuoted 17 lines · Dominik Dingel
Nobody used these hooks so they were removed from common code, and can now be removed from the architectures.
Signed-off-by Dominik Dingel <[email protected]>Acked-by Ralf Baechle <[email protected]>arch/powerpc/include/asm/hugetlb.h +0
-2@@ -168,15 +168,6 @@ static inline pte_t huge_ptep_get(pte_t *ptep)return *ptep; } -static inline int arch_prepare_hugepage (struct page *page) -{
arch/powerpc/include/asm/hugetlb.h static inline pte_t huge_ptep_get(pte_t *ptep) · line 173
Quoted 10 lines
arch/powerpc/include/asm/hugetlb.h +0
-7-return 0 ; -} - -static inline void arch_release_hugepage (struct page *page) -{ -} -static inline void arch_clear_hugepage_flags (struct page *page) { }
cheers