* [PATCHv3 1/5] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time
[not found] <20171204124059.63515-1-kirill.shutemov@linux.intel.com>
@ 2017-12-04 12:40 ` Kirill A. Shutemov
2017-12-04 20:29 ` Thomas Gleixner
2017-12-04 12:40 ` [PATCHv3 2/5] x86/boot/compressed/64: Print error if 5-level paging is not supported Kirill A. Shutemov
1 sibling, 1 reply; 5+ messages in thread
From: Kirill A. Shutemov @ 2017-12-04 12:40 UTC (permalink / raw)
To: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin
Cc: Linus Torvalds, Andy Lutomirski, Cyrill Gorcunov, Borislav Petkov,
Andi Kleen, linux-mm, linux-kernel, Kirill A. Shutemov, stable
This patch prepare decompression code to boot-time switching between 4-
and 5-level paging.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: <stable@vger.kernel.org> [4.14+]
---
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(-)
create mode 100644 arch/x86/boot/compressed/pgtable_64.c
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 1e9c322e973a..f25e1530e064 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 20919b4f3133..fc313e29fe2c 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -305,10 +305,18 @@ ENTRY(startup_64)
leaq boot_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
+ call l5_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 000000000000..eed3a2c3b577
--- /dev/null
+++ b/arch/x86/boot/compressed/pgtable_64.c
@@ -0,0 +1,18 @@
+#include <asm/processor.h>
+
+int l5_paging_required(void)
+{
+ /* Check i 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;
+}
--
2.15.0
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCHv3 2/5] x86/boot/compressed/64: Print error if 5-level paging is not supported
[not found] <20171204124059.63515-1-kirill.shutemov@linux.intel.com>
2017-12-04 12:40 ` [PATCHv3 1/5] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time Kirill A. Shutemov
@ 2017-12-04 12:40 ` Kirill A. Shutemov
2017-12-04 19:31 ` Borislav Petkov
1 sibling, 1 reply; 5+ messages in thread
From: Kirill A. Shutemov @ 2017-12-04 12:40 UTC (permalink / raw)
To: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin
Cc: Linus Torvalds, Andy Lutomirski, Cyrill Gorcunov, Borislav Petkov,
Andi Kleen, linux-mm, linux-kernel, Kirill A. Shutemov, stable
We cannot proceed booting if the machine doesn't support the paging mode
kernel was compiled for.
Getting error the usual way -- via validate_cpu() -- is not going to
work. We need to enable appropriate paging mode before that, otherwise
kernel would triple-fault during KASLR setup.
This code will go away once we get support for boot-time switching
between paging modes.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: <stable@vger.kernel.org> [4.14+]
---
arch/x86/boot/compressed/misc.c | 16 ++++++++++++++++
arch/x86/boot/compressed/pgtable_64.c | 2 +-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index b50c42455e25..f7f8d9f76e15 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -169,6 +169,16 @@ void __puthex(unsigned long value)
}
}
+static int l5_supported(void)
+{
+ /* Check if leaf 7 is supported. */
+ if (native_cpuid_eax(0) < 7)
+ return 0;
+
+ /* Check if la57 is supported. */
+ return native_cpuid_ecx(7) & (1 << (X86_FEATURE_LA57 & 31));
+}
+
#if CONFIG_X86_NEED_RELOCS
static void handle_relocations(void *output, unsigned long output_len,
unsigned long virt_addr)
@@ -362,6 +372,12 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
console_init();
debug_putstr("early console in extract_kernel\n");
+ if (IS_ENABLED(CONFIG_X86_5LEVEL) && !l5_supported()) {
+ error("This linux kernel as configured requires 5-level paging\n"
+ "This CPU does not support the required 'cr4.la57' feature\n"
+ "Unable to boot - please use a kernel appropriate for your CPU\n");
+ }
+
free_mem_ptr = heap; /* Heap */
free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c
index eed3a2c3b577..7bcf03b376da 100644
--- a/arch/x86/boot/compressed/pgtable_64.c
+++ b/arch/x86/boot/compressed/pgtable_64.c
@@ -2,7 +2,7 @@
int l5_paging_required(void)
{
- /* Check i leaf 7 is supported. */
+ /* Check if leaf 7 is supported. */
if (native_cpuid_eax(0) < 7)
return 0;
--
2.15.0
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCHv3 2/5] x86/boot/compressed/64: Print error if 5-level paging is not supported
2017-12-04 12:40 ` [PATCHv3 2/5] x86/boot/compressed/64: Print error if 5-level paging is not supported Kirill A. Shutemov
@ 2017-12-04 19:31 ` Borislav Petkov
0 siblings, 0 replies; 5+ messages in thread
From: Borislav Petkov @ 2017-12-04 19:31 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin, Linus Torvalds,
Andy Lutomirski, Cyrill Gorcunov, Andi Kleen, linux-mm,
linux-kernel, stable
On Mon, Dec 04, 2017 at 03:40:56PM +0300, Kirill A. Shutemov wrote:
> We cannot proceed booting if the machine doesn't support the paging mode
> kernel was compiled for.
>
> Getting error the usual way -- via validate_cpu() -- is not going to
> work. We need to enable appropriate paging mode before that, otherwise
> kernel would triple-fault during KASLR setup.
>
> This code will go away once we get support for boot-time switching
> between paging modes.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: <stable@vger.kernel.org> [4.14+]
> ---
> arch/x86/boot/compressed/misc.c | 16 ++++++++++++++++
> arch/x86/boot/compressed/pgtable_64.c | 2 +-
> 2 files changed, 17 insertions(+), 1 deletion(-)
Reported-and-tested-by: Borislav Petkov <bp@suse.de>
--
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCHv3 1/5] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time
2017-12-04 12:40 ` [PATCHv3 1/5] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time Kirill A. Shutemov
@ 2017-12-04 20:29 ` Thomas Gleixner
2017-12-04 21:15 ` Kirill A. Shutemov
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Gleixner @ 2017-12-04 20:29 UTC (permalink / raw)
To: Kirill A. Shutemov
Cc: Ingo Molnar, x86, H. Peter Anvin, Linus Torvalds, Andy Lutomirski,
Cyrill Gorcunov, Borislav Petkov, Andi Kleen, linux-mm,
linux-kernel, stable
On Mon, 4 Dec 2017, Kirill A. Shutemov wrote:
> This patch prepare decompression code to boot-time switching between 4-
> and 5-level paging.
This is the very wrong reason for tagging this commit stable.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: <stable@vger.kernel.org> [4.14+]
Adding cc stable requires a Fixes tag as well.
> +int l5_paging_required(void)
> +{
> + /* Check i leaf 7 is supported. */
So you introduce the typo here and then you fix it in the next patch which
is the actual bug fix as an completely unrelated hunk.
-- a/arch/x86/boot/compressed/pgtable_64.c
+++ b/arch/x86/boot/compressed/pgtable_64.c
@@ -2,7 +2,7 @@
int l5_paging_required(void)
{
- /* Check i leaf 7 is supported. */
+ /* Check if leaf 7 is supported. */
That's just careless and sloppy.
I fixed it up once more along with the lousy changelogs because this crap,
which you not even thought about addressing it when shoving your 5-level
support into 4.14 needs to be fixed.
I'm really tired of your sloppiness. You waste everyones time just by
ignoring feedback and continuing to do what you think is enough. Works for
me is _NOT_ enough for kernel development.
I'm not even looking at the rest of the series unless someone else has the
stomach to do so and sends a Reviewed-by.
Alternatively you can sit down and look at the changelogs and the code and
figure out whether it matches what I told you over and over. Once you think
it does, then please feel free to resend it, but be sure that I'm going to
apply the most restrictive crap filter on anything which comes from you
from now on.
Thanks,
tglx
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCHv3 1/5] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time
2017-12-04 20:29 ` Thomas Gleixner
@ 2017-12-04 21:15 ` Kirill A. Shutemov
0 siblings, 0 replies; 5+ messages in thread
From: Kirill A. Shutemov @ 2017-12-04 21:15 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Kirill A. Shutemov, Ingo Molnar, x86, H. Peter Anvin,
Linus Torvalds, Andy Lutomirski, Cyrill Gorcunov, Borislav Petkov,
Andi Kleen, linux-mm, linux-kernel, stable
On Mon, Dec 04, 2017 at 09:29:45PM +0100, Thomas Gleixner wrote:
> On Mon, 4 Dec 2017, Kirill A. Shutemov wrote:
>
> > This patch prepare decompression code to boot-time switching between 4-
> > and 5-level paging.
>
> This is the very wrong reason for tagging this commit stable.
>
> >
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > Cc: <stable@vger.kernel.org> [4.14+]
>
> Adding cc stable requires a Fixes tag as well.
>
> > +int l5_paging_required(void)
> > +{
> > + /* Check i leaf 7 is supported. */
>
> So you introduce the typo here and then you fix it in the next patch which
> is the actual bug fix as an completely unrelated hunk.
>
> -- a/arch/x86/boot/compressed/pgtable_64.c
> +++ b/arch/x86/boot/compressed/pgtable_64.c
> @@ -2,7 +2,7 @@
>
> int l5_paging_required(void)
> {
> - /* Check i leaf 7 is supported. */
> + /* Check if leaf 7 is supported. */
>
> That's just careless and sloppy.
>
> I fixed it up once more along with the lousy changelogs because this crap,
> which you not even thought about addressing it when shoving your 5-level
> support into 4.14 needs to be fixed.
>
> I'm really tired of your sloppiness. You waste everyones time just by
> ignoring feedback and continuing to do what you think is enough. Works for
> me is _NOT_ enough for kernel development.
Sorry. I screwed it up.
I'll do my best to not waste your time again.
> I'm not even looking at the rest of the series unless someone else has the
> stomach to do so and sends a Reviewed-by.
>
> Alternatively you can sit down and look at the changelogs and the code and
> figure out whether it matches what I told you over and over. Once you think
> it does, then please feel free to resend it, but be sure that I'm going to
> apply the most restrictive crap filter on anything which comes from you
> from now on.
Fair enough. I'll recheck everything in the morning and send them again.
Thanks,
and sorry again for wasting your time.
--
Kirill A. Shutemov
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-12-04 21:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20171204124059.63515-1-kirill.shutemov@linux.intel.com>
2017-12-04 12:40 ` [PATCHv3 1/5] x86/boot/compressed/64: Detect and handle 5-level paging at boot-time Kirill A. Shutemov
2017-12-04 20:29 ` Thomas Gleixner
2017-12-04 21:15 ` Kirill A. Shutemov
2017-12-04 12:40 ` [PATCHv3 2/5] x86/boot/compressed/64: Print error if 5-level paging is not supported Kirill A. Shutemov
2017-12-04 19:31 ` Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox