Re: [tip:x86/urgent] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

2017-12-07 Thread Kirill A. Shutemov
On Thu, Dec 07, 2017 at 01:40:42AM -0800, tip-bot for Kirill A. Shutemov wrote:
> diff --git a/arch/x86/boot/compressed/pgtable_64.c 
> b/arch/x86/boot/compressed/pgtable_64.c
> new file mode 100644
> index 000..b4469a3
> --- /dev/null
> +++ b/arch/x86/boot/compressed/pgtable_64.c
> @@ -0,0 +1,28 @@
> +#include 
> +
> +/*
> + * __force_order is used by special_insns.h asm code to force instruction
> + * serialization.
> + *
> + * It is not referenced from the code, but GCC < 5 with -fPIE would fail
> + * due to an undefined symbol. Define it to make these ancient GCCs work.
> + */
> +unsigned long __force_order;

There's no need in __force_order in arch/x86/boot/compressed/pagetable.c after
the change.

-- 
 Kirill A. Shutemov


Re: [tip:x86/urgent] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

2017-12-07 Thread Kirill A. Shutemov
On Thu, Dec 07, 2017 at 01:40:42AM -0800, tip-bot for Kirill A. Shutemov wrote:
> diff --git a/arch/x86/boot/compressed/pgtable_64.c 
> b/arch/x86/boot/compressed/pgtable_64.c
> new file mode 100644
> index 000..b4469a3
> --- /dev/null
> +++ b/arch/x86/boot/compressed/pgtable_64.c
> @@ -0,0 +1,28 @@
> +#include 
> +
> +/*
> + * __force_order is used by special_insns.h asm code to force instruction
> + * serialization.
> + *
> + * It is not referenced from the code, but GCC < 5 with -fPIE would fail
> + * due to an undefined symbol. Define it to make these ancient GCCs work.
> + */
> +unsigned long __force_order;

There's no need in __force_order in arch/x86/boot/compressed/pagetable.c after
the change.

-- 
 Kirill A. Shutemov


[tip:x86/urgent] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

2017-12-07 Thread tip-bot for Kirill A. Shutemov
Commit-ID:  08529078d8d9adf689bf39cc38d53979a0869970
Gitweb: https://git.kernel.org/tip/08529078d8d9adf689bf39cc38d53979a0869970
Author: Kirill A. Shutemov 
AuthorDate: Mon, 4 Dec 2017 15:40:55 +0300
Committer:  Thomas Gleixner 
CommitDate: Thu, 7 Dec 2017 10:34:39 +0100

x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

Prerequisite for fixing the current problem of instantaneous reboots when a
5-level paging kernel is booted on 4-level paging hardware.

At the same time this change prepares the decompression code to boot-time
switching between 4- and 5-level paging.

[ tglx: Folded the GCC < 5 fix. ]

Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via 
CONFIG_X86_5LEVEL=y")
Signed-off-by: Kirill A. Shutemov 
Signed-off-by: Thomas Gleixner 
Cc: Andi Kleen 
Cc: sta...@vger.kernel.org
Cc: Andy Lutomirski 
Cc: linux...@kvack.org
Cc: Cyrill Gorcunov 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Link: 
https://lkml.kernel.org/r/20171204124059.63515-2-kirill.shute...@linux.intel.com
---
 arch/x86/boot/compressed/Makefile |  1 +
 arch/x86/boot/compressed/head_64.S| 16 
 arch/x86/boot/compressed/pgtable_64.c | 28 
 3 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 1e9c322..f25e153 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -80,6 +80,7 @@ vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
 ifdef CONFIG_X86_64
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/pagetable.o
vmlinux-objs-y += $(obj)/mem_encrypt.o
+   vmlinux-objs-y += $(obj)/pgtable_64.o
 endif
 
 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
diff --git a/arch/x86/boot/compressed/head_64.S 
b/arch/x86/boot/compressed/head_64.S
index 20919b4..fc313e2 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -305,10 +305,18 @@ ENTRY(startup_64)
leaqboot_stack_end(%rbx), %rsp
 
 #ifdef CONFIG_X86_5LEVEL
-   /* Check if 5-level paging has already enabled */
-   movq%cr4, %rax
-   testl   $X86_CR4_LA57, %eax
-   jnz lvl5
+   /*
+* Check if we need to enable 5-level paging.
+* RSI holds real mode data and need to be preserved across
+* a function call.
+*/
+   pushq   %rsi
+   calll5_paging_required
+   popq%rsi
+
+   /* If l5_paging_required() returned zero, we're done here. */
+   cmpq$0, %rax
+   je  lvl5
 
/*
 * At this point we are in long mode with 4-level paging enabled,
diff --git a/arch/x86/boot/compressed/pgtable_64.c 
b/arch/x86/boot/compressed/pgtable_64.c
new file mode 100644
index 000..b4469a3
--- /dev/null
+++ b/arch/x86/boot/compressed/pgtable_64.c
@@ -0,0 +1,28 @@
+#include 
+
+/*
+ * __force_order is used by special_insns.h asm code to force instruction
+ * serialization.
+ *
+ * It is not referenced from the code, but GCC < 5 with -fPIE would fail
+ * due to an undefined symbol. Define it to make these ancient GCCs work.
+ */
+unsigned long __force_order;
+
+int l5_paging_required(void)
+{
+   /* Check if leaf 7 is supported. */
+
+   if (native_cpuid_eax(0) < 7)
+   return 0;
+
+   /* Check if la57 is supported. */
+   if (!(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31
+   return 0;
+
+   /* Check if 5-level paging has already been enabled. */
+   if (native_read_cr4() & X86_CR4_LA57)
+   return 0;
+
+   return 1;
+}


[tip:x86/urgent] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

2017-12-07 Thread tip-bot for Kirill A. Shutemov
Commit-ID:  08529078d8d9adf689bf39cc38d53979a0869970
Gitweb: https://git.kernel.org/tip/08529078d8d9adf689bf39cc38d53979a0869970
Author: Kirill A. Shutemov 
AuthorDate: Mon, 4 Dec 2017 15:40:55 +0300
Committer:  Thomas Gleixner 
CommitDate: Thu, 7 Dec 2017 10:34:39 +0100

x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

Prerequisite for fixing the current problem of instantaneous reboots when a
5-level paging kernel is booted on 4-level paging hardware.

At the same time this change prepares the decompression code to boot-time
switching between 4- and 5-level paging.

[ tglx: Folded the GCC < 5 fix. ]

Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via 
CONFIG_X86_5LEVEL=y")
Signed-off-by: Kirill A. Shutemov 
Signed-off-by: Thomas Gleixner 
Cc: Andi Kleen 
Cc: sta...@vger.kernel.org
Cc: Andy Lutomirski 
Cc: linux...@kvack.org
Cc: Cyrill Gorcunov 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Link: 
https://lkml.kernel.org/r/20171204124059.63515-2-kirill.shute...@linux.intel.com
---
 arch/x86/boot/compressed/Makefile |  1 +
 arch/x86/boot/compressed/head_64.S| 16 
 arch/x86/boot/compressed/pgtable_64.c | 28 
 3 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 1e9c322..f25e153 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -80,6 +80,7 @@ vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
 ifdef CONFIG_X86_64
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/pagetable.o
vmlinux-objs-y += $(obj)/mem_encrypt.o
+   vmlinux-objs-y += $(obj)/pgtable_64.o
 endif
 
 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
diff --git a/arch/x86/boot/compressed/head_64.S 
b/arch/x86/boot/compressed/head_64.S
index 20919b4..fc313e2 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -305,10 +305,18 @@ ENTRY(startup_64)
leaqboot_stack_end(%rbx), %rsp
 
 #ifdef CONFIG_X86_5LEVEL
-   /* Check if 5-level paging has already enabled */
-   movq%cr4, %rax
-   testl   $X86_CR4_LA57, %eax
-   jnz lvl5
+   /*
+* Check if we need to enable 5-level paging.
+* RSI holds real mode data and need to be preserved across
+* a function call.
+*/
+   pushq   %rsi
+   calll5_paging_required
+   popq%rsi
+
+   /* If l5_paging_required() returned zero, we're done here. */
+   cmpq$0, %rax
+   je  lvl5
 
/*
 * At this point we are in long mode with 4-level paging enabled,
diff --git a/arch/x86/boot/compressed/pgtable_64.c 
b/arch/x86/boot/compressed/pgtable_64.c
new file mode 100644
index 000..b4469a3
--- /dev/null
+++ b/arch/x86/boot/compressed/pgtable_64.c
@@ -0,0 +1,28 @@
+#include 
+
+/*
+ * __force_order is used by special_insns.h asm code to force instruction
+ * serialization.
+ *
+ * It is not referenced from the code, but GCC < 5 with -fPIE would fail
+ * due to an undefined symbol. Define it to make these ancient GCCs work.
+ */
+unsigned long __force_order;
+
+int l5_paging_required(void)
+{
+   /* Check if leaf 7 is supported. */
+
+   if (native_cpuid_eax(0) < 7)
+   return 0;
+
+   /* Check if la57 is supported. */
+   if (!(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31
+   return 0;
+
+   /* Check if 5-level paging has already been enabled. */
+   if (native_read_cr4() & X86_CR4_LA57)
+   return 0;
+
+   return 1;
+}


[tip:x86/urgent] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

2017-12-04 Thread tip-bot for Kirill A. Shutemov
Commit-ID:  10c9a5346f7200f5150608742075470612f9eadb
Gitweb: https://git.kernel.org/tip/10c9a5346f7200f5150608742075470612f9eadb
Author: Kirill A. Shutemov 
AuthorDate: Mon, 4 Dec 2017 15:40:55 +0300
Committer:  Thomas Gleixner 
CommitDate: Mon, 4 Dec 2017 21:14:34 +0100

x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

Prerequisite for fixing the current problem of instantaneous reboots when a
5-level paging kernel is booted on 4-level paging hardware.

At the same time this change prepares the decompression code to boot-time
switching between 4- and 5-level paging.

Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via 
CONFIG_X86_5LEVEL=y")
Signed-off-by: Kirill A. Shutemov 
Signed-off-by: Thomas Gleixner 
Cc: Andi Kleen 
Cc: sta...@vger.kernel.org
Cc: Andy Lutomirski 
Cc: linux...@kvack.org
Cc: Cyrill Gorcunov 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Link: 
https://lkml.kernel.org/r/20171204124059.63515-2-kirill.shute...@linux.intel.com

---
 arch/x86/boot/compressed/Makefile |  1 +
 arch/x86/boot/compressed/head_64.S| 16 
 arch/x86/boot/compressed/pgtable_64.c | 18 ++
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 1e9c322..f25e153 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -80,6 +80,7 @@ vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
 ifdef CONFIG_X86_64
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/pagetable.o
vmlinux-objs-y += $(obj)/mem_encrypt.o
+   vmlinux-objs-y += $(obj)/pgtable_64.o
 endif
 
 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
diff --git a/arch/x86/boot/compressed/head_64.S 
b/arch/x86/boot/compressed/head_64.S
index 20919b4..fc313e2 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -305,10 +305,18 @@ ENTRY(startup_64)
leaqboot_stack_end(%rbx), %rsp
 
 #ifdef CONFIG_X86_5LEVEL
-   /* Check if 5-level paging has already enabled */
-   movq%cr4, %rax
-   testl   $X86_CR4_LA57, %eax
-   jnz lvl5
+   /*
+* Check if we need to enable 5-level paging.
+* RSI holds real mode data and need to be preserved across
+* a function call.
+*/
+   pushq   %rsi
+   calll5_paging_required
+   popq%rsi
+
+   /* If l5_paging_required() returned zero, we're done here. */
+   cmpq$0, %rax
+   je  lvl5
 
/*
 * At this point we are in long mode with 4-level paging enabled,
diff --git a/arch/x86/boot/compressed/pgtable_64.c 
b/arch/x86/boot/compressed/pgtable_64.c
new file mode 100644
index 000..7bcf03b
--- /dev/null
+++ b/arch/x86/boot/compressed/pgtable_64.c
@@ -0,0 +1,18 @@
+#include 
+
+int l5_paging_required(void)
+{
+   /* Check if leaf 7 is supported. */
+   if (native_cpuid_eax(0) < 7)
+   return 0;
+
+   /* Check if la57 is supported. */
+   if (!(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31
+   return 0;
+
+   /* Check if 5-level paging has already been enabled. */
+   if (native_read_cr4() & X86_CR4_LA57)
+   return 0;
+
+   return 1;
+}


[tip:x86/urgent] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

2017-12-04 Thread tip-bot for Kirill A. Shutemov
Commit-ID:  10c9a5346f7200f5150608742075470612f9eadb
Gitweb: https://git.kernel.org/tip/10c9a5346f7200f5150608742075470612f9eadb
Author: Kirill A. Shutemov 
AuthorDate: Mon, 4 Dec 2017 15:40:55 +0300
Committer:  Thomas Gleixner 
CommitDate: Mon, 4 Dec 2017 21:14:34 +0100

x86/boot/compressed/64: Detect and handle 5-level paging at boot-time

Prerequisite for fixing the current problem of instantaneous reboots when a
5-level paging kernel is booted on 4-level paging hardware.

At the same time this change prepares the decompression code to boot-time
switching between 4- and 5-level paging.

Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via 
CONFIG_X86_5LEVEL=y")
Signed-off-by: Kirill A. Shutemov 
Signed-off-by: Thomas Gleixner 
Cc: Andi Kleen 
Cc: sta...@vger.kernel.org
Cc: Andy Lutomirski 
Cc: linux...@kvack.org
Cc: Cyrill Gorcunov 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Link: 
https://lkml.kernel.org/r/20171204124059.63515-2-kirill.shute...@linux.intel.com

---
 arch/x86/boot/compressed/Makefile |  1 +
 arch/x86/boot/compressed/head_64.S| 16 
 arch/x86/boot/compressed/pgtable_64.c | 18 ++
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 1e9c322..f25e153 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -80,6 +80,7 @@ vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/kaslr.o
 ifdef CONFIG_X86_64
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/pagetable.o
vmlinux-objs-y += $(obj)/mem_encrypt.o
+   vmlinux-objs-y += $(obj)/pgtable_64.o
 endif
 
 $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
diff --git a/arch/x86/boot/compressed/head_64.S 
b/arch/x86/boot/compressed/head_64.S
index 20919b4..fc313e2 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -305,10 +305,18 @@ ENTRY(startup_64)
leaqboot_stack_end(%rbx), %rsp
 
 #ifdef CONFIG_X86_5LEVEL
-   /* Check if 5-level paging has already enabled */
-   movq%cr4, %rax
-   testl   $X86_CR4_LA57, %eax
-   jnz lvl5
+   /*
+* Check if we need to enable 5-level paging.
+* RSI holds real mode data and need to be preserved across
+* a function call.
+*/
+   pushq   %rsi
+   calll5_paging_required
+   popq%rsi
+
+   /* If l5_paging_required() returned zero, we're done here. */
+   cmpq$0, %rax
+   je  lvl5
 
/*
 * At this point we are in long mode with 4-level paging enabled,
diff --git a/arch/x86/boot/compressed/pgtable_64.c 
b/arch/x86/boot/compressed/pgtable_64.c
new file mode 100644
index 000..7bcf03b
--- /dev/null
+++ b/arch/x86/boot/compressed/pgtable_64.c
@@ -0,0 +1,18 @@
+#include 
+
+int l5_paging_required(void)
+{
+   /* Check if leaf 7 is supported. */
+   if (native_cpuid_eax(0) < 7)
+   return 0;
+
+   /* Check if la57 is supported. */
+   if (!(native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31
+   return 0;
+
+   /* Check if 5-level paging has already been enabled. */
+   if (native_read_cr4() & X86_CR4_LA57)
+   return 0;
+
+   return 1;
+}