Skip to contentSkip to conversation

Remove s390 sw-emulated hugepages and cleanup

PATCH In review Dominik Dingel 4 participants 10 messages May 28, 2015 – Jun 4, 2015

Subsystems (11)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 53eacbd..0844b78 100644
@@ -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
index a5ea8bc..9ac282b 100644
@@ -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
index b2c1542..f76791e 100644
@@ -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
#2 lore raw

PATCH 2/5 mm/hugetlb: remove unused arch hook prepare/release_hugepage

In reply to Dominik Dingel

With 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
index 290984b..a97958e 100644
@@ -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
#3 lore raw

PATCH 3/5 mm/hugetlb: remove arch_prepare/release_hugepage from arch headers

In reply to Dominik Dingel

Nobody 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
index 31bb7dc..7d26f6c 100644
@@ -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
index 734c17e..2fd9b14 100644
@@ -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
index ff1377b..ef65f02 100644
@@ -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
index f730b39..905ed42 100644
@@ -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
index 4a5bb54..982bc06 100644
@@ -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
index 4bbd3c8..7eac89b 100644
@@ -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
index b788a9b..ef489a5 100644
@@ -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
index 3130d76..139e711 100644
@@ -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
index 1abd00c..2fac5be 100644
@@ -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
index dab7a3a..f8a29d2 100644
@@ -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
reviewer Acked-by on v1 3/5
#5 lore raw

Re: [3/5] mm/hugetlb: remove arch_prepare/release_hugepage from arch headers

In reply to Dominik Dingel
Quoted 17 lines · Dominik Dingel

Nobody used these hooks so they were removed from common code, and can now be removed from the architectures.

arch/powerpc/include/asm/hugetlb.h +0 -2
index 4bbd3c8..7eac89b 100644
@@ -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

#6 lore raw

PATCH 4/5 s390/hugetlb: remove dead code for sw emulated huge pages

In reply to Dominik Dingel

We 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
index dfb542a..0130d03 100644
@@ -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
#7 lore raw

PATCH 5/5 s390/mm: forward check for huge pmds to pmd_large()

In reply to Dominik Dingel

We 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
index 999616b..a4b2f5e 100644
@@ -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
#8 lore raw
In reply to Dominik Dingel

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

#9 lore raw
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