2015-07-03 12:46:45

by Dominik Dingel

[permalink] [raw]
Subject: [PATCH 0/4] s390/mm: Fixup hugepage sw-emulated code removal

Heiko noticed that the current check for hugepage support on s390 is a little bit to
harsh as systems which do not support will crash.
The reason is that pageblock_order can now get negative when we set HPAGE_SHIFT to 0.
To avoid all this and to avoid opening another can of worms with enabling
HUGETLB_PAGE_SIZE_VARIABLE I think it would be best to simply allow architectures to
define their own hugepages_supported().

Thanks
Dominik

Dominik Dingel (4):
Revert "s390/mm: change HPAGE_SHIFT type to int"
Revert "s390/mm: make hugepages_supported a boot time decision"
mm: hugetlb: allow hugepages_supported to be architecture specific
s390/hugetlb: add hugepages_supported define

arch/s390/include/asm/hugetlb.h | 1 +
arch/s390/include/asm/page.h | 8 ++++----
arch/s390/kernel/setup.c | 2 --
arch/s390/mm/pgtable.c | 2 --
include/linux/hugetlb.h | 17 ++++++++---------
5 files changed, 13 insertions(+), 17 deletions(-)

--
2.3.8


2015-07-03 12:46:29

by Dominik Dingel

[permalink] [raw]
Subject: [PATCH 1/4] Revert "s390/mm: change HPAGE_SHIFT type to int"

This reverts commit cf54e2fce51c7ad2479fe8cf213a2ed618a8189b.
---
arch/s390/include/asm/page.h | 2 +-
arch/s390/mm/pgtable.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h
index dd34523..0844b78 100644
--- a/arch/s390/include/asm/page.h
+++ b/arch/s390/include/asm/page.h
@@ -20,7 +20,7 @@
#include <asm/setup.h>
#ifndef __ASSEMBLY__

-extern int HPAGE_SHIFT;
+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)
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 33082d0..16154720 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -31,7 +31,7 @@
#define ALLOC_ORDER 2
#define FRAG_MASK 0x03

-int HPAGE_SHIFT;
+unsigned int HPAGE_SHIFT;

unsigned long *crst_table_alloc(struct mm_struct *mm)
{
--
2.3.8

2015-07-03 12:47:37

by Dominik Dingel

[permalink] [raw]
Subject: [PATCH 2/4] Revert "s390/mm: make hugepages_supported a boot time decision"

This reverts commit bea41197ead3e03308bdd10c11db3ce91ae5c8ab.
---
arch/s390/include/asm/page.h | 8 ++++----
arch/s390/kernel/setup.c | 2 --
arch/s390/mm/pgtable.c | 2 --
3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/s390/include/asm/page.h b/arch/s390/include/asm/page.h
index 0844b78..53eacbd 100644
--- a/arch/s390/include/asm/page.h
+++ b/arch/s390/include/asm/page.h
@@ -17,10 +17,7 @@
#define PAGE_DEFAULT_ACC 0
#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)

-#include <asm/setup.h>
-#ifndef __ASSEMBLY__
-
-extern unsigned int HPAGE_SHIFT;
+#define HPAGE_SHIFT 20
#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
#define HPAGE_MASK (~(HPAGE_SIZE - 1))
#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
@@ -30,6 +27,9 @@ extern unsigned int HPAGE_SHIFT;
#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
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index f7f027c..ca070d2 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -885,8 +885,6 @@ 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.
*/
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 16154720..b33f661 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -31,8 +31,6 @@
#define ALLOC_ORDER 2
#define FRAG_MASK 0x03

-unsigned int HPAGE_SHIFT;
-
unsigned long *crst_table_alloc(struct mm_struct *mm)
{
struct page *page = alloc_pages(GFP_KERNEL, ALLOC_ORDER);
--
2.3.8

2015-07-03 12:47:07

by Dominik Dingel

[permalink] [raw]
Subject: [PATCH 3/4] mm: hugetlb: allow hugepages_supported to be architecture specific

s390 has a constant hugepage size, by setting HPAGE_SHIFT we also
change e.g. the pageblock_order, which should be independent in
respect to hugepage support.

With this patch every architecture is free to define how to check
for hugepage support.

Signed-off-by: Dominik Dingel <[email protected]>
---
include/linux/hugetlb.h | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 2050261..d891f94 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -460,15 +460,14 @@ static inline spinlock_t *huge_pte_lockptr(struct hstate *h,
return &mm->page_table_lock;
}

-static inline bool hugepages_supported(void)
-{
- /*
- * Some platform decide whether they support huge pages at boot
- * time. On these, such as powerpc, HPAGE_SHIFT is set to 0 when
- * there is no such support
- */
- return HPAGE_SHIFT != 0;
-}
+#ifndef hugepages_supported
+/*
+ * Some platform decide whether they support huge pages at boot
+ * time. Some of them, such as powerpc, set HPAGE_SHIFT to 0
+ * when there is no such support
+ */
+#define hugepages_supported() (HPAGE_SHIFT != 0)
+#endif

#else /* CONFIG_HUGETLB_PAGE */
struct hstate {};
--
2.3.8

2015-07-03 12:46:57

by Dominik Dingel

[permalink] [raw]
Subject: [PATCH 4/4] s390/hugetlb: add hugepages_supported define

On s390 we only can enable hugepages if the underlying hardware/hypervisor
also does support this. Common code now would assume this to be signaled
by setting HPAGE_SHIFT to 0. But on s390, where we only support one
hugepage size, there is a link between HPAGE_SHIFT and pageblock_order.

So instead of setting HPAGE_SHIFT to 0, we will implement the check for the
hardware capability.

Signed-off-by: Dominik Dingel <[email protected]>
---
arch/s390/include/asm/hugetlb.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h
index 0130d03..d9be7c0 100644
--- a/arch/s390/include/asm/hugetlb.h
+++ b/arch/s390/include/asm/hugetlb.h
@@ -14,6 +14,7 @@

#define is_hugepage_only_range(mm, addr, len) 0
#define hugetlb_free_pgd_range free_pgd_range
+#define hugepages_supported() (MACHINE_HAS_HPAGE)

void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
pte_t *ptep, pte_t pte);
--
2.3.8

2015-07-06 08:05:36

by Martin Schwidefsky

[permalink] [raw]
Subject: Re: [PATCH 0/4] s390/mm: Fixup hugepage sw-emulated code removal

On Fri, 3 Jul 2015 14:46:05 +0200
Dominik Dingel <[email protected]> wrote:

> Heiko noticed that the current check for hugepage support on s390 is a little bit to
> harsh as systems which do not support will crash.
> The reason is that pageblock_order can now get negative when we set HPAGE_SHIFT to 0.
> To avoid all this and to avoid opening another can of worms with enabling
> HUGETLB_PAGE_SIZE_VARIABLE I think it would be best to simply allow architectures to
> define their own hugepages_supported().
>
> Thanks
> Dominik
>
> Dominik Dingel (4):
> Revert "s390/mm: change HPAGE_SHIFT type to int"
> Revert "s390/mm: make hugepages_supported a boot time decision"
> mm: hugetlb: allow hugepages_supported to be architecture specific
> s390/hugetlb: add hugepages_supported define
>
> arch/s390/include/asm/hugetlb.h | 1 +
> arch/s390/include/asm/page.h | 8 ++++----
> arch/s390/kernel/setup.c | 2 --
> arch/s390/mm/pgtable.c | 2 --
> include/linux/hugetlb.h | 17 ++++++++---------
> 5 files changed, 13 insertions(+), 17 deletions(-)

To have an architecture override for hugepages_supported is imho the
cleaner approach compared to the HPAGE_SHIFT tricks. I would have
preferred to use a __weak function but the #ifndef solution is fine
with me as well.

Acked-by: Martin Schwidefsky <[email protected]>

--
blue skies,
Martin.

"Reality continues to ruin my life." - Calvin.