Re: [tip:x86/mm] x86/boot/64: Rewrite startup_64() in C

From: Kirill A. Shutemov
Date: Tue Apr 11 2017 - 08:36:30 EST


On Tue, Apr 11, 2017 at 10:54:41AM +0200, Ingo Molnar wrote:
>
> * tip-bot for Kirill A. Shutemov <tipbot@xxxxxxxxx> wrote:
>
> > Commit-ID: 10ee822ec8c53f3987d969ce98b2686323a7fc2a
> > Gitweb: http://git.kernel.org/tip/10ee822ec8c53f3987d969ce98b2686323a7fc2a
> > Author: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
> > AuthorDate: Thu, 6 Apr 2017 17:00:59 +0300
> > Committer: Ingo Molnar <mingo@xxxxxxxxxx>
> > CommitDate: Tue, 11 Apr 2017 08:57:37 +0200
> >
> > x86/boot/64: Rewrite startup_64() in C
> >
> > The patch converts most of the startup_64 logic from assembly to C.
> >
> > This is preparation for 5-level paging enabling.
> >
> > No change in functionality.
> >
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
> > Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> > Cc: Andy Lutomirski <luto@xxxxxxxxxxxxxx>
> > Cc: Dave Hansen <dave.hansen@xxxxxxxxx>
> > Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> > Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> > Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> > Cc: linux-arch@xxxxxxxxxxxxxxx
> > Cc: linux-mm@xxxxxxxxx
> > Link: http://lkml.kernel.org/r/20170406140106.78087-2-kirill.shutemov@xxxxxxxxxxxxxxx
> > [ Small typo fixes. ]
> > Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
> > ---
> > arch/x86/kernel/head64.c | 81 ++++++++++++++++++++++++++++++++++++++++-
> > arch/x86/kernel/head_64.S | 93 +----------------------------------------------
> > 2 files changed, 81 insertions(+), 93 deletions(-)
>
> Hm, so I had to zap this commit as it broke booting on a 64-bit Intel and an AMD
> system as well, with defconfig-ish kernels.

The fixup is below. Maybe there's better more idiomatic way, but I'm not
really into assembly.

Basically, we need to preserve %rsi across call __startup_64.

I will post whole thing again once we sort out what to do with the reset
of assembly code I've touched. Or you can apply the fixup, if you feel to.

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 9656c5951b98..1432d530fa35 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -73,7 +73,9 @@ startup_64:
call verify_cpu

leaq _text(%rip), %rdi
+ pushq %rsi
call __startup_64
+ popq %rsi

movq $(early_level4_pgt - __START_KERNEL_map), %rax
jmp 1f
--
Kirill A. Shutemov