All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/kexec: Make kexec work in 5-level paging mode
@ 2018-01-29 11:08 ` Kirill A. Shutemov
  0 siblings, 0 replies; 11+ messages in thread
From: Kirill A. Shutemov @ 2018-01-29 11:08 UTC (permalink / raw)
  To: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin
  Cc: Borislav Petkov, linux-mm, linux-kernel, Kirill A. Shutemov

I've missed that we need to change relocate_kernel() to set CR4.LA57
flag if the kernel has 5-level paging enabled.

I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
enabled 5-level paging from previous CR4 value. This way the code is
ready for boot-time switching between paging modes.

Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via CONFIG_X86_5LEVEL=y")
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Baoquan He <bhe@redhat.com>
---
 arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
index 307d3bac5f04..11eda21eb697 100644
--- a/arch/x86/kernel/relocate_kernel_64.S
+++ b/arch/x86/kernel/relocate_kernel_64.S
@@ -68,6 +68,9 @@ relocate_kernel:
 	movq	%cr4, %rax
 	movq	%rax, CR4(%r11)
 
+	/* Save CR4. Required to enable the right paging mode later. */
+	movq	%rax, %r13
+
 	/* zero out flags, and disable interrupts */
 	pushq $0
 	popfq
@@ -126,8 +129,13 @@ identity_mapped:
 	/*
 	 * Set cr4 to a known state:
 	 *  - physical address extension enabled
+	 *  - 5-level paging, if it was enabled before
 	 */
 	movl	$X86_CR4_PAE, %eax
+	testq	$X86_CR4_LA57, %r13
+	jz	1f
+	orl	$X86_CR4_LA57, %eax
+1:
 	movq	%rax, %cr4
 
 	jmp 1f
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH] x86/kexec: Make kexec work in 5-level paging mode
@ 2018-01-29 11:08 ` Kirill A. Shutemov
  0 siblings, 0 replies; 11+ messages in thread
From: Kirill A. Shutemov @ 2018-01-29 11:08 UTC (permalink / raw)
  To: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin
  Cc: Borislav Petkov, linux-mm, linux-kernel, Kirill A. Shutemov

I've missed that we need to change relocate_kernel() to set CR4.LA57
flag if the kernel has 5-level paging enabled.

I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
enabled 5-level paging from previous CR4 value. This way the code is
ready for boot-time switching between paging modes.

Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via CONFIG_X86_5LEVEL=y")
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-by: Baoquan He <bhe@redhat.com>
---
 arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
index 307d3bac5f04..11eda21eb697 100644
--- a/arch/x86/kernel/relocate_kernel_64.S
+++ b/arch/x86/kernel/relocate_kernel_64.S
@@ -68,6 +68,9 @@ relocate_kernel:
 	movq	%cr4, %rax
 	movq	%rax, CR4(%r11)
 
+	/* Save CR4. Required to enable the right paging mode later. */
+	movq	%rax, %r13
+
 	/* zero out flags, and disable interrupts */
 	pushq $0
 	popfq
@@ -126,8 +129,13 @@ identity_mapped:
 	/*
 	 * Set cr4 to a known state:
 	 *  - physical address extension enabled
+	 *  - 5-level paging, if it was enabled before
 	 */
 	movl	$X86_CR4_PAE, %eax
+	testq	$X86_CR4_LA57, %r13
+	jz	1f
+	orl	$X86_CR4_LA57, %eax
+1:
 	movq	%rax, %cr4
 
 	jmp 1f
-- 
2.15.1

--
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] 11+ messages in thread

* Re: [PATCH] x86/kexec: Make kexec work in 5-level paging mode
  2018-01-29 11:08 ` Kirill A. Shutemov
@ 2018-01-29 11:19   ` Baoquan He
  -1 siblings, 0 replies; 11+ messages in thread
From: Baoquan He @ 2018-01-29 11:19 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin,
	Borislav Petkov, linux-mm, linux-kernel

On 01/29/18 at 02:08pm, Kirill A. Shutemov wrote:
> I've missed that we need to change relocate_kernel() to set CR4.LA57
> flag if the kernel has 5-level paging enabled.
> 
> I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
> enabled 5-level paging from previous CR4 value. This way the code is
> ready for boot-time switching between paging modes.
> 
> Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via CONFIG_X86_5LEVEL=y")
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Reported-by: Baoquan He <bhe@redhat.com>

Thanks, Kirill.

Tested on qemu with la57 support, kexec works well. Kdump kernel can
boot into kernel, while there's a memory allocation failure during
boot which I am trying to fix. The reason is kdump kernel need reserve
as small memory as possible. Will post soon.

For this patch, feel free to add my Tested-by.

Tested-by: Baoquan He <bhe@redhat.com>

Thanks
Baoquan
> ---
>  arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
> index 307d3bac5f04..11eda21eb697 100644
> --- a/arch/x86/kernel/relocate_kernel_64.S
> +++ b/arch/x86/kernel/relocate_kernel_64.S
> @@ -68,6 +68,9 @@ relocate_kernel:
>  	movq	%cr4, %rax
>  	movq	%rax, CR4(%r11)
>  
> +	/* Save CR4. Required to enable the right paging mode later. */
> +	movq	%rax, %r13
> +
>  	/* zero out flags, and disable interrupts */
>  	pushq $0
>  	popfq
> @@ -126,8 +129,13 @@ identity_mapped:
>  	/*
>  	 * Set cr4 to a known state:
>  	 *  - physical address extension enabled
> +	 *  - 5-level paging, if it was enabled before
>  	 */
>  	movl	$X86_CR4_PAE, %eax
> +	testq	$X86_CR4_LA57, %r13
> +	jz	1f
> +	orl	$X86_CR4_LA57, %eax
> +1:
>  	movq	%rax, %cr4
>  
>  	jmp 1f
> -- 
> 2.15.1
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] x86/kexec: Make kexec work in 5-level paging mode
@ 2018-01-29 11:19   ` Baoquan He
  0 siblings, 0 replies; 11+ messages in thread
From: Baoquan He @ 2018-01-29 11:19 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin,
	Borislav Petkov, linux-mm, linux-kernel

On 01/29/18 at 02:08pm, Kirill A. Shutemov wrote:
> I've missed that we need to change relocate_kernel() to set CR4.LA57
> flag if the kernel has 5-level paging enabled.
> 
> I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
> enabled 5-level paging from previous CR4 value. This way the code is
> ready for boot-time switching between paging modes.
> 
> Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via CONFIG_X86_5LEVEL=y")
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Reported-by: Baoquan He <bhe@redhat.com>

Thanks, Kirill.

Tested on qemu with la57 support, kexec works well. Kdump kernel can
boot into kernel, while there's a memory allocation failure during
boot which I am trying to fix. The reason is kdump kernel need reserve
as small memory as possible. Will post soon.

For this patch, feel free to add my Tested-by.

Tested-by: Baoquan He <bhe@redhat.com>

Thanks
Baoquan
> ---
>  arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
> index 307d3bac5f04..11eda21eb697 100644
> --- a/arch/x86/kernel/relocate_kernel_64.S
> +++ b/arch/x86/kernel/relocate_kernel_64.S
> @@ -68,6 +68,9 @@ relocate_kernel:
>  	movq	%cr4, %rax
>  	movq	%rax, CR4(%r11)
>  
> +	/* Save CR4. Required to enable the right paging mode later. */
> +	movq	%rax, %r13
> +
>  	/* zero out flags, and disable interrupts */
>  	pushq $0
>  	popfq
> @@ -126,8 +129,13 @@ identity_mapped:
>  	/*
>  	 * Set cr4 to a known state:
>  	 *  - physical address extension enabled
> +	 *  - 5-level paging, if it was enabled before
>  	 */
>  	movl	$X86_CR4_PAE, %eax
> +	testq	$X86_CR4_LA57, %r13
> +	jz	1f
> +	orl	$X86_CR4_LA57, %eax
> +1:
>  	movq	%rax, %cr4
>  
>  	jmp 1f
> -- 
> 2.15.1
> 

--
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] 11+ messages in thread

* Re: [PATCH] x86/kexec: Make kexec work in 5-level paging mode
  2018-01-29 11:08 ` Kirill A. Shutemov
@ 2018-01-29 11:59   ` Matthew Wilcox
  -1 siblings, 0 replies; 11+ messages in thread
From: Matthew Wilcox @ 2018-01-29 11:59 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin,
	Borislav Petkov, linux-mm, linux-kernel

On Mon, Jan 29, 2018 at 02:08:45PM +0300, Kirill A. Shutemov wrote:
> I've missed that we need to change relocate_kernel() to set CR4.LA57
> flag if the kernel has 5-level paging enabled.
> 
> I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
> enabled 5-level paging from previous CR4 value. This way the code is
> ready for boot-time switching between paging modes.

Forgive me if I'm missing something ... can you kexec a 5-level kernel
from a 4-level kernel or vice versa?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] x86/kexec: Make kexec work in 5-level paging mode
@ 2018-01-29 11:59   ` Matthew Wilcox
  0 siblings, 0 replies; 11+ messages in thread
From: Matthew Wilcox @ 2018-01-29 11:59 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin,
	Borislav Petkov, linux-mm, linux-kernel

On Mon, Jan 29, 2018 at 02:08:45PM +0300, Kirill A. Shutemov wrote:
> I've missed that we need to change relocate_kernel() to set CR4.LA57
> flag if the kernel has 5-level paging enabled.
> 
> I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
> enabled 5-level paging from previous CR4 value. This way the code is
> ready for boot-time switching between paging modes.

Forgive me if I'm missing something ... can you kexec a 5-level kernel
from a 4-level kernel or vice versa?

--
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] 11+ messages in thread

* Re: [PATCH] x86/kexec: Make kexec work in 5-level paging mode
  2018-01-29 11:19   ` Baoquan He
@ 2018-01-29 13:00     ` Baoquan He
  -1 siblings, 0 replies; 11+ messages in thread
From: Baoquan He @ 2018-01-29 13:00 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin,
	Borislav Petkov, linux-mm, linux-kernel

On 01/29/18 at 07:19pm, Baoquan He wrote:
> On 01/29/18 at 02:08pm, Kirill A. Shutemov wrote:
> > I've missed that we need to change relocate_kernel() to set CR4.LA57
> > flag if the kernel has 5-level paging enabled.
> > 
> > I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
> > enabled 5-level paging from previous CR4 value. This way the code is
> > ready for boot-time switching between paging modes.
> > 
> > Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via CONFIG_X86_5LEVEL=y")
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > Reported-by: Baoquan He <bhe@redhat.com>
> 
> Thanks, Kirill.
> 
> Tested on qemu with la57 support, kexec works well. Kdump kernel can
> boot into kernel, while there's a memory allocation failure during
> boot which I am trying to fix. The reason is kdump kernel need reserve
> as small memory as possible. Will post soon.

By the way, the kdump failure can be worked around by increasing
crashkernel memory, then kdump kernel can still work well. So this patch
is necessary fix for kexec/kdump.

> 
> For this patch, feel free to add my Tested-by.
> 
> Tested-by: Baoquan He <bhe@redhat.com>
> 
> Thanks
> Baoquan
> > ---
> >  arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
> > index 307d3bac5f04..11eda21eb697 100644
> > --- a/arch/x86/kernel/relocate_kernel_64.S
> > +++ b/arch/x86/kernel/relocate_kernel_64.S
> > @@ -68,6 +68,9 @@ relocate_kernel:
> >  	movq	%cr4, %rax
> >  	movq	%rax, CR4(%r11)
> >  
> > +	/* Save CR4. Required to enable the right paging mode later. */
> > +	movq	%rax, %r13
> > +
> >  	/* zero out flags, and disable interrupts */
> >  	pushq $0
> >  	popfq
> > @@ -126,8 +129,13 @@ identity_mapped:
> >  	/*
> >  	 * Set cr4 to a known state:
> >  	 *  - physical address extension enabled
> > +	 *  - 5-level paging, if it was enabled before
> >  	 */
> >  	movl	$X86_CR4_PAE, %eax
> > +	testq	$X86_CR4_LA57, %r13
> > +	jz	1f
> > +	orl	$X86_CR4_LA57, %eax
> > +1:
> >  	movq	%rax, %cr4
> >  
> >  	jmp 1f
> > -- 
> > 2.15.1
> > 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] x86/kexec: Make kexec work in 5-level paging mode
@ 2018-01-29 13:00     ` Baoquan He
  0 siblings, 0 replies; 11+ messages in thread
From: Baoquan He @ 2018-01-29 13:00 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Ingo Molnar, x86, Thomas Gleixner, H. Peter Anvin,
	Borislav Petkov, linux-mm, linux-kernel

On 01/29/18 at 07:19pm, Baoquan He wrote:
> On 01/29/18 at 02:08pm, Kirill A. Shutemov wrote:
> > I've missed that we need to change relocate_kernel() to set CR4.LA57
> > flag if the kernel has 5-level paging enabled.
> > 
> > I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
> > enabled 5-level paging from previous CR4 value. This way the code is
> > ready for boot-time switching between paging modes.
> > 
> > Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via CONFIG_X86_5LEVEL=y")
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > Reported-by: Baoquan He <bhe@redhat.com>
> 
> Thanks, Kirill.
> 
> Tested on qemu with la57 support, kexec works well. Kdump kernel can
> boot into kernel, while there's a memory allocation failure during
> boot which I am trying to fix. The reason is kdump kernel need reserve
> as small memory as possible. Will post soon.

By the way, the kdump failure can be worked around by increasing
crashkernel memory, then kdump kernel can still work well. So this patch
is necessary fix for kexec/kdump.

> 
> For this patch, feel free to add my Tested-by.
> 
> Tested-by: Baoquan He <bhe@redhat.com>
> 
> Thanks
> Baoquan
> > ---
> >  arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
> > index 307d3bac5f04..11eda21eb697 100644
> > --- a/arch/x86/kernel/relocate_kernel_64.S
> > +++ b/arch/x86/kernel/relocate_kernel_64.S
> > @@ -68,6 +68,9 @@ relocate_kernel:
> >  	movq	%cr4, %rax
> >  	movq	%rax, CR4(%r11)
> >  
> > +	/* Save CR4. Required to enable the right paging mode later. */
> > +	movq	%rax, %r13
> > +
> >  	/* zero out flags, and disable interrupts */
> >  	pushq $0
> >  	popfq
> > @@ -126,8 +129,13 @@ identity_mapped:
> >  	/*
> >  	 * Set cr4 to a known state:
> >  	 *  - physical address extension enabled
> > +	 *  - 5-level paging, if it was enabled before
> >  	 */
> >  	movl	$X86_CR4_PAE, %eax
> > +	testq	$X86_CR4_LA57, %r13
> > +	jz	1f
> > +	orl	$X86_CR4_LA57, %eax
> > +1:
> >  	movq	%rax, %cr4
> >  
> >  	jmp 1f
> > -- 
> > 2.15.1
> > 

--
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] 11+ messages in thread

* Re: [PATCH] x86/kexec: Make kexec work in 5-level paging mode
  2018-01-29 11:59   ` Matthew Wilcox
@ 2018-01-29 13:48     ` Kirill A. Shutemov
  -1 siblings, 0 replies; 11+ messages in thread
From: Kirill A. Shutemov @ 2018-01-29 13:48 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Kirill A. Shutemov, Ingo Molnar, x86, Thomas Gleixner,
	H. Peter Anvin, Borislav Petkov, linux-mm, linux-kernel

On Mon, Jan 29, 2018 at 03:59:27AM -0800, Matthew Wilcox wrote:
> On Mon, Jan 29, 2018 at 02:08:45PM +0300, Kirill A. Shutemov wrote:
> > I've missed that we need to change relocate_kernel() to set CR4.LA57
> > flag if the kernel has 5-level paging enabled.
> > 
> > I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
> > enabled 5-level paging from previous CR4 value. This way the code is
> > ready for boot-time switching between paging modes.
> 
> Forgive me if I'm missing something ... can you kexec a 5-level kernel
> from a 4-level kernel or vice versa?

With this patch you can kexec from 4-to-5 and from 5-to-5 in addition to
current 4-to-4. 4-to-5 basically takes the same path as UEFI boot in new
kernel.

I think I will be able to make 5-to-4 work too, when boot-time switching
code will be upstream, assuming both kernels are build from the tree with
boot-time switching support and the new kernel is loaded below 128TiB.

For 5-to-4, kernel decompression code of the new kernel starts on 5-level
paging identity mapping constructed by caller. Decompression code then
would switch over to 4-level paging via 32-bit trampoline (we cannot
switch between 4- and 5-level paging directly) and proceed as in normal
boot.

Let me check.

-- 
 Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] x86/kexec: Make kexec work in 5-level paging mode
@ 2018-01-29 13:48     ` Kirill A. Shutemov
  0 siblings, 0 replies; 11+ messages in thread
From: Kirill A. Shutemov @ 2018-01-29 13:48 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Kirill A. Shutemov, Ingo Molnar, x86, Thomas Gleixner,
	H. Peter Anvin, Borislav Petkov, linux-mm, linux-kernel

On Mon, Jan 29, 2018 at 03:59:27AM -0800, Matthew Wilcox wrote:
> On Mon, Jan 29, 2018 at 02:08:45PM +0300, Kirill A. Shutemov wrote:
> > I've missed that we need to change relocate_kernel() to set CR4.LA57
> > flag if the kernel has 5-level paging enabled.
> > 
> > I avoided to use ifdef CONFIG_X86_5LEVEL here and inferred if we need to
> > enabled 5-level paging from previous CR4 value. This way the code is
> > ready for boot-time switching between paging modes.
> 
> Forgive me if I'm missing something ... can you kexec a 5-level kernel
> from a 4-level kernel or vice versa?

With this patch you can kexec from 4-to-5 and from 5-to-5 in addition to
current 4-to-4. 4-to-5 basically takes the same path as UEFI boot in new
kernel.

I think I will be able to make 5-to-4 work too, when boot-time switching
code will be upstream, assuming both kernels are build from the tree with
boot-time switching support and the new kernel is loaded below 128TiB.

For 5-to-4, kernel decompression code of the new kernel starts on 5-level
paging identity mapping constructed by caller. Decompression code then
would switch over to 4-level paging via 32-bit trampoline (we cannot
switch between 4- and 5-level paging directly) and proceed as in normal
boot.

Let me check.

-- 
 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] 11+ messages in thread

* [tip:x86/urgent] x86/kexec: Make kexec (mostly) work in 5-level paging mode
  2018-01-29 11:08 ` Kirill A. Shutemov
                   ` (2 preceding siblings ...)
  (?)
@ 2018-01-31  9:13 ` tip-bot for Kirill A. Shutemov
  -1 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Kirill A. Shutemov @ 2018-01-31  9:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: bp, hpa, kirill.shutemov, linux-kernel, peterz, bhe, tglx,
	torvalds, mingo

Commit-ID:  5bf30316991d5bcda046343ee77d823cf16fdd03
Gitweb:     https://git.kernel.org/tip/5bf30316991d5bcda046343ee77d823cf16fdd03
Author:     Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
AuthorDate: Mon, 29 Jan 2018 14:08:45 +0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 31 Jan 2018 08:39:40 +0100

x86/kexec: Make kexec (mostly) work in 5-level paging mode

Currently kexec() will crash when switching into a 5-level paging
enabled kernel.

I missed that we need to change relocate_kernel() to set CR4.LA57
flag if the kernel has 5-level paging enabled.

I avoided using #ifdef CONFIG_X86_5LEVEL here and inferred if we need to
enable 5-level paging from previous CR4 value. This way the code is
ready for boot-time switching between paging modes.

With this patch applied, in addition to kexec 4-to-4 which always worked,
we can kexec 4-to-5 and 5-to-5 - while 5-to-4 will need more work.

Reported-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Tested-by: Baoquan He <bhe@redhat.com>
Cc: <stable@vger.kernel.org> # v4.14+
Cc: Borislav Petkov <bp@suse.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-mm@kvack.org
Fixes: 77ef56e4f0fb ("x86: Enable 5-level paging support via CONFIG_X86_5LEVEL=y")
Link: http://lkml.kernel.org/r/20180129110845.26633-1-kirill.shutemov@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
index 307d3ba..11eda21e 100644
--- a/arch/x86/kernel/relocate_kernel_64.S
+++ b/arch/x86/kernel/relocate_kernel_64.S
@@ -68,6 +68,9 @@ relocate_kernel:
 	movq	%cr4, %rax
 	movq	%rax, CR4(%r11)
 
+	/* Save CR4. Required to enable the right paging mode later. */
+	movq	%rax, %r13
+
 	/* zero out flags, and disable interrupts */
 	pushq $0
 	popfq
@@ -126,8 +129,13 @@ identity_mapped:
 	/*
 	 * Set cr4 to a known state:
 	 *  - physical address extension enabled
+	 *  - 5-level paging, if it was enabled before
 	 */
 	movl	$X86_CR4_PAE, %eax
+	testq	$X86_CR4_LA57, %r13
+	jz	1f
+	orl	$X86_CR4_LA57, %eax
+1:
 	movq	%rax, %cr4
 
 	jmp 1f

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-01-31  9:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-29 11:08 [PATCH] x86/kexec: Make kexec work in 5-level paging mode Kirill A. Shutemov
2018-01-29 11:08 ` Kirill A. Shutemov
2018-01-29 11:19 ` Baoquan He
2018-01-29 11:19   ` Baoquan He
2018-01-29 13:00   ` Baoquan He
2018-01-29 13:00     ` Baoquan He
2018-01-29 11:59 ` Matthew Wilcox
2018-01-29 11:59   ` Matthew Wilcox
2018-01-29 13:48   ` Kirill A. Shutemov
2018-01-29 13:48     ` Kirill A. Shutemov
2018-01-31  9:13 ` [tip:x86/urgent] x86/kexec: Make kexec (mostly) " tip-bot for Kirill A. Shutemov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.