All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting
@ 2019-02-06 11:52 Kirill A. Shutemov
  2019-02-06 15:21 ` Borislav Petkov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Kirill A. Shutemov @ 2019-02-06 11:52 UTC (permalink / raw)
  To: tglx, mingo, bp, hpa, dave.hansen
  Cc: x86, linux-kernel, Kirill A. Shutemov, Kyle D Pelton, Wei Huang

RDMSR in the trampoline code overrides EDX, but we use the register to
indicate if 5-level paging has to enabled. It leads to failure to boot
on a 5-level paging machine.

Preserve EDX on the stack while we are dealing with EFER.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fixes: b677dfae5aa1 ("x86/boot/compressed/64: Set EFER.LME=1 in 32-bit trampoline before returning to long mode")
Reported-by: Kyle D Pelton <kyle.d.pelton@intel.com>
Cc: Wei Huang <wei@redhat.com>
---
 arch/x86/boot/compressed/head_64.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index f105ae8651c9..f62e347862cc 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -602,10 +602,12 @@ ENTRY(trampoline_32bit_src)
 3:
 	/* Set EFER.LME=1 as a precaution in case hypervsior pulls the rug */
 	pushl	%ecx
+	pushl	%edx
 	movl	$MSR_EFER, %ecx
 	rdmsr
 	btsl	$_EFER_LME, %eax
 	wrmsr
+	popl	%edx
 	popl	%ecx
 
 	/* Enable PAE and LA57 (if required) paging modes */
-- 
2.20.1


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

* Re: [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting
  2019-02-06 11:52 [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting Kirill A. Shutemov
@ 2019-02-06 15:21 ` Borislav Petkov
  2019-02-06 15:47   ` Kirill A. Shutemov
  2019-02-06 18:04 ` [tip:x86/urgent] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting tip-bot for Kirill A. Shutemov
  2019-02-06 19:50 ` [PATCH] " Wei Huang
  2 siblings, 1 reply; 7+ messages in thread
From: Borislav Petkov @ 2019-02-06 15:21 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: tglx, mingo, hpa, dave.hansen, x86, linux-kernel, Kyle D Pelton,
	Wei Huang

On Wed, Feb 06, 2019 at 02:52:53PM +0300, Kirill A. Shutemov wrote:
> RDMSR in the trampoline code overrides EDX, but we use the register to
> indicate if 5-level paging has to enabled. It leads to failure to boot
> on a 5-level paging machine.
> 
> Preserve EDX on the stack while we are dealing with EFER.

Comment says:

 * Non zero RDX on return means we need to enable 5-level paging.

Is that per-chance refering to struct paging_config which
paging_prepare() returns and on that return rdx contains
paging_config.l5_required which is 1 when 5 level is to be enabled?

If so, is that written somewhere explicitly? Because it is not
immediately clear at least to me why that RDX is live...

Thx.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

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

* Re: [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting
  2019-02-06 15:21 ` Borislav Petkov
@ 2019-02-06 15:47   ` Kirill A. Shutemov
  2019-02-06 18:11     ` Borislav Petkov
  2019-02-06 18:13     ` [tip:x86/cleanups] x86/boot/compressed/64: Explain paging_prepare()'s return value tip-bot for Kirill A. Shutemov
  0 siblings, 2 replies; 7+ messages in thread
From: Kirill A. Shutemov @ 2019-02-06 15:47 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: tglx, mingo, hpa, dave.hansen, x86, linux-kernel, Kyle D Pelton,
	Wei Huang

On Wed, Feb 06, 2019 at 03:21:41PM +0000, Borislav Petkov wrote:
> On Wed, Feb 06, 2019 at 02:52:53PM +0300, Kirill A. Shutemov wrote:
> > RDMSR in the trampoline code overrides EDX, but we use the register to
> > indicate if 5-level paging has to enabled. It leads to failure to boot
> > on a 5-level paging machine.
> > 
> > Preserve EDX on the stack while we are dealing with EFER.
> 
> Comment says:
> 
>  * Non zero RDX on return means we need to enable 5-level paging.
> 
> Is that per-chance refering to struct paging_config which
> paging_prepare() returns and on that return rdx contains
> paging_config.l5_required which is 1 when 5 level is to be enabled?

Yes.

> If so, is that written somewhere explicitly? Because it is not
> immediately clear at least to me why that RDX is live...

What about this:

From d43b9d157c574baf782f6d9982fe6f2c1f918c0e Mon Sep 17 00:00:00 2001
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Date: Wed, 6 Feb 2019 18:29:08 +0300
Subject: [PATCH] x86/boot/compressed/64: Fix confusing comment for
 paging_config()

paging_prepare() returns two-quadword structure which lands
into RDX:RAX:
  - Address of the trampoline is returned in RAX.
  - Non zero RDX means trampoline needs to enable 5-level paging.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 arch/x86/boot/compressed/head_64.S | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index f62e347862cc..87509a3f00f4 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -358,8 +358,11 @@ ENTRY(startup_64)
 	 * paging_prepare() sets up the trampoline and checks if we need to
 	 * enable 5-level paging.
 	 *
-	 * Address of the trampoline is returned in RAX.
-	 * Non zero RDX on return means we need to enable 5-level paging.
+	 * paging_prepare() returns two-quadword structure which lands
+	 * into RDX:RAX:
+	 *   - Address of the trampoline is returned in RAX.
+	 *   - Non zero RDX means trampoline needs to enable 5-level
+	 *     paging.
 	 *
 	 * RSI holds real mode data and needs to be preserved across
 	 * this function call.
@@ -565,7 +568,7 @@ adjust_got:
  *
  * RDI contains the return address (might be above 4G).
  * ECX contains the base address of the trampoline memory.
- * Non zero RDX on return means we need to enable 5-level paging.
+ * Non zero RDX means trampoline needs to enable 5-level paging.
  */
 ENTRY(trampoline_32bit_src)
 	/* Set up data and stack segments */
-- 
 Kirill A. Shutemov

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

* [tip:x86/urgent] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting
  2019-02-06 11:52 [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting Kirill A. Shutemov
  2019-02-06 15:21 ` Borislav Petkov
@ 2019-02-06 18:04 ` tip-bot for Kirill A. Shutemov
  2019-02-06 19:50 ` [PATCH] " Wei Huang
  2 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Kirill A. Shutemov @ 2019-02-06 18:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: kyle.d.pelton, mingo, x86, hpa, linux-kernel, bp, wei, mingo,
	tglx, kirill.shutemov

Commit-ID:  45b13b424faafb81c8c44541f093a682fdabdefc
Gitweb:     https://git.kernel.org/tip/45b13b424faafb81c8c44541f093a682fdabdefc
Author:     Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
AuthorDate: Wed, 6 Feb 2019 14:52:53 +0300
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Wed, 6 Feb 2019 18:56:18 +0100

x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting

RDMSR in the trampoline code overwrites EDX but that register is used
to indicate whether 5-level paging has to be enabled and if clobbered,
leads to failure to boot on a 5-level paging machine.

Preserve EDX on the stack while we are dealing with EFER.

Fixes: b677dfae5aa1 ("x86/boot/compressed/64: Set EFER.LME=1 in 32-bit trampoline before returning to long mode")
Reported-by: Kyle D Pelton <kyle.d.pelton@intel.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: dave.hansen@linux.intel.com
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Huang <wei@redhat.com>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190206115253.1907-1-kirill.shutemov@linux.intel.com
---
 arch/x86/boot/compressed/head_64.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index f105ae8651c9..f62e347862cc 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -602,10 +602,12 @@ ENTRY(trampoline_32bit_src)
 3:
 	/* Set EFER.LME=1 as a precaution in case hypervsior pulls the rug */
 	pushl	%ecx
+	pushl	%edx
 	movl	$MSR_EFER, %ecx
 	rdmsr
 	btsl	$_EFER_LME, %eax
 	wrmsr
+	popl	%edx
 	popl	%ecx
 
 	/* Enable PAE and LA57 (if required) paging modes */

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

* Re: [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting
  2019-02-06 15:47   ` Kirill A. Shutemov
@ 2019-02-06 18:11     ` Borislav Petkov
  2019-02-06 18:13     ` [tip:x86/cleanups] x86/boot/compressed/64: Explain paging_prepare()'s return value tip-bot for Kirill A. Shutemov
  1 sibling, 0 replies; 7+ messages in thread
From: Borislav Petkov @ 2019-02-06 18:11 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: tglx, mingo, hpa, dave.hansen, x86, linux-kernel, Kyle D Pelton,
	Wei Huang

On Wed, Feb 06, 2019 at 06:47:57PM +0300, Kirill A. Shutemov wrote:
> What about this:

Yap, thanks!

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

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

* [tip:x86/cleanups] x86/boot/compressed/64: Explain paging_prepare()'s return value
  2019-02-06 15:47   ` Kirill A. Shutemov
  2019-02-06 18:11     ` Borislav Petkov
@ 2019-02-06 18:13     ` tip-bot for Kirill A. Shutemov
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot for Kirill A. Shutemov @ 2019-02-06 18:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: wei, bp, mingo, kirill.shutemov, mingo, hpa, kyle.d.pelton,
	linux-kernel, tglx, x86

Commit-ID:  82434d23f36de42f70925f70d645ed3b1394361b
Gitweb:     https://git.kernel.org/tip/82434d23f36de42f70925f70d645ed3b1394361b
Author:     Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
AuthorDate: Wed, 6 Feb 2019 18:29:08 +0300
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Wed, 6 Feb 2019 19:08:34 +0100

x86/boot/compressed/64: Explain paging_prepare()'s return value

paging_prepare() returns a two-quadword structure which lands
into RDX:RAX:

  - Address of the trampoline is returned in RAX.
  - Non zero RDX means trampoline needs to enable 5-level paging.

Document that explicitly.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: dave.hansen@linux.intel.com
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kyle D Pelton <kyle.d.pelton@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Huang <wei@redhat.com>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190206154756.matwldebbxkmlnae@black.fi.intel.com
---
 arch/x86/boot/compressed/head_64.S | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index b27b338d2f6d..73b9d7e91a9c 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -358,8 +358,11 @@ ENTRY(startup_64)
 	 * paging_prepare() sets up the trampoline and checks if we need to
 	 * enable 5-level paging.
 	 *
-	 * Address of the trampoline is returned in RAX.
-	 * Non zero RDX on return means we need to enable 5-level paging.
+	 * paging_prepare() returns a two-quadword structure which lands
+	 * into RDX:RAX:
+	 *   - Address of the trampoline is returned in RAX.
+	 *   - Non zero RDX means trampoline needs to enable 5-level
+	 *     paging.
 	 *
 	 * RSI holds real mode data and needs to be preserved across
 	 * this function call.
@@ -565,7 +568,7 @@ adjust_got:
  *
  * RDI contains the return address (might be above 4G).
  * ECX contains the base address of the trampoline memory.
- * Non zero RDX on return means we need to enable 5-level paging.
+ * Non zero RDX means trampoline needs to enable 5-level paging.
  */
 ENTRY(trampoline_32bit_src)
 	/* Set up data and stack segments */

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

* Re: [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting
  2019-02-06 11:52 [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting Kirill A. Shutemov
  2019-02-06 15:21 ` Borislav Petkov
  2019-02-06 18:04 ` [tip:x86/urgent] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting tip-bot for Kirill A. Shutemov
@ 2019-02-06 19:50 ` Wei Huang
  2 siblings, 0 replies; 7+ messages in thread
From: Wei Huang @ 2019-02-06 19:50 UTC (permalink / raw)
  To: Kirill A. Shutemov, tglx, mingo, bp, hpa, dave.hansen
  Cc: x86, linux-kernel, Kyle D Pelton



On 2/6/19 5:52 AM, Kirill A. Shutemov wrote:
> RDMSR in the trampoline code overrides EDX, but we use the register to
> indicate if 5-level paging has to enabled. It leads to failure to boot
> on a 5-level paging machine.
> 
> Preserve EDX on the stack while we are dealing with EFER.
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Fixes: b677dfae5aa1 ("x86/boot/compressed/64: Set EFER.LME=1 in 32-bit trampoline before returning to long mode")
> Reported-by: Kyle D Pelton <kyle.d.pelton@intel.com>
> Cc: Wei Huang <wei@redhat.com>
> ---
>  arch/x86/boot/compressed/head_64.S | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
> index f105ae8651c9..f62e347862cc 100644
> --- a/arch/x86/boot/compressed/head_64.S
> +++ b/arch/x86/boot/compressed/head_64.S
> @@ -602,10 +602,12 @@ ENTRY(trampoline_32bit_src)
>  3:
>  	/* Set EFER.LME=1 as a precaution in case hypervsior pulls the rug */
>  	pushl	%ecx
> +	pushl	%edx
>  	movl	$MSR_EFER, %ecx
>  	rdmsr
>  	btsl	$_EFER_LME, %eax
>  	wrmsr
> +	popl	%edx
>  	popl	%ecx
>  
>  	/* Enable PAE and LA57 (if required) paging modes */
> 

Oops, rdmsr indeed corrupts EDX.

Acked-by: Wei Huang <wei@redhat.com>


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

end of thread, other threads:[~2019-02-06 19:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-06 11:52 [PATCH] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting Kirill A. Shutemov
2019-02-06 15:21 ` Borislav Petkov
2019-02-06 15:47   ` Kirill A. Shutemov
2019-02-06 18:11     ` Borislav Petkov
2019-02-06 18:13     ` [tip:x86/cleanups] x86/boot/compressed/64: Explain paging_prepare()'s return value tip-bot for Kirill A. Shutemov
2019-02-06 18:04 ` [tip:x86/urgent] x86/boot/compressed/64: Do not corrupt EDX on EFER.LME=1 setting tip-bot for Kirill A. Shutemov
2019-02-06 19:50 ` [PATCH] " Wei Huang

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.