mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nikolay Borisov <nik.borisov@suse.com>
To: Brian Gerst <brgerst@gmail.com>,
	linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>, Ard Biesheuvel <ardb@kernel.org>,
	Juergen Gross <jgross@suse.com>,
	Tom Lendacky <thomas.lendacky@amd.com>
Subject: Re: [PATCH 2/5] x86/boot/64: Clear BSS as early as possible
Date: Fri, 24 Jul 2026 14:04:39 +0300	[thread overview]
Message-ID: <12ca9e3c-3cd7-4081-a906-593dcceca85b@suse.com> (raw)
In-Reply-To: <20260724030256.232690-3-brgerst@gmail.com>



On 7/24/26 06:02, Brian Gerst wrote:
> Currently, the BSS section is not cleared until x86_64_start_kernel().
> Using unitialized BSS data before that point leads to difficult to debug
> problems.  Fix this by moving clear_bss() to as early as possible.
> 
> Signed-off-by: Brian Gerst <brgerst@gmail.com>

<snip>


> diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
> index 7ed5520dd52e..15ef5ea52b9a 100644
> --- a/arch/x86/kernel/head_64.S
> +++ b/arch/x86/kernel/head_64.S
> @@ -37,6 +37,8 @@
>   	.code64
>   SYM_CODE_START_NOALIGN(startup_64)
>   	UNWIND_HINT_END_OF_STACK
> +	cld
> +
>   	/*
>   	 * At this point the CPU runs in 64bit mode CS.L = 1 CS.D = 0,
>   	 * and someone has loaded an identity mapped page table
> @@ -61,6 +63,8 @@ SYM_CODE_START_NOALIGN(startup_64)
>   	/* Set up the stack for verify_cpu() */
>   	leaq	__top_init_kernel_stack(%rip), %rsp
>   
> +	call	clear_bss
> +
>   	/*
>   	 * Set up GSBASE.
>   	 * Note that on SMP the boot CPU uses the init data section until
> @@ -140,6 +144,22 @@ SYM_CODE_START_NOALIGN(startup_64)
>   	jmp	*.Lcommon_startup_64(%rip)
>   SYM_CODE_END(startup_64)
>   
> +SYM_FUNC_START(clear_bss)
> +	xorl	%eax, %eax
> +
> +	leaq	__bss_start(%rip), %rdi
> +	leaq	__bss_stop(%rip), %rcx
> +	subq	%rdi, %rcx
> +	rep stosb

Why not stosq (with appropriate adjustment to xor %rax, %rax as well)? 
The length is guaranteed to be multiple of page_size ergo 8 byte as well ?

> +
> +	leaq	__brk_base(%rip), %rdi
> +	leaq	__brk_limit(%rip), %rcx
> +	subq	%rdi, %rcx
> +	rep stosb
> +
> +	RET
> +SYM_FUNC_END(clear_bss)
> +
>   	__INITRODATA
>   SYM_DATA_LOCAL(.Lcommon_startup_64, .quad common_startup_64)
>   
> diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
> index 2c64b388f616..6aa13d19c0a4 100644
> --- a/arch/x86/xen/enlighten_pv.c
> +++ b/arch/x86/xen/enlighten_pv.c
> @@ -1334,8 +1334,6 @@ asmlinkage __visible void __init xen_start_kernel(struct start_info *si)
>   	if (!si)
>   		return;
>   
> -	clear_bss();
> -
>   	xen_start_info = si;
>   
>   	__text_gen_insn(&early_xen_iret_patch,
> diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
> index 5dad6c51cdc3..9b56659246fe 100644
> --- a/arch/x86/xen/xen-head.S
> +++ b/arch/x86/xen/xen-head.S
> @@ -31,6 +31,9 @@ SYM_CODE_START(startup_xen)
>   
>   	leaq	__top_init_kernel_stack(%rip), %rsp
>   
> +	movq	%rsi, %r15

Why is this change necessary, rsi is ont used in clear_bss ?
> +	call	clear_bss
> +
>   	/*
>   	 * Set up GSBASE.
>   	 * Note that, on SMP, the boot cpu uses init data section until
> @@ -41,7 +44,7 @@ SYM_CODE_START(startup_xen)
>   	xorl	%edx, %edx
>   	wrmsr
>   
> -	mov	%rsi, %rdi
> +	mov	%r15, %rdi
>   	call xen_start_kernel
>   SYM_CODE_END(startup_xen)
>   	__FINIT


  reply	other threads:[~2026-07-24 11:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  3:02 [PATCH 0/5] x86/boot: Early boot cleanups Brian Gerst
2026-07-24  3:02 ` [PATCH 1/5] x86/sme: Clear decrypted BSS separately Brian Gerst
2026-07-24 16:41   ` Tom Lendacky
2026-07-24 18:57     ` Brian Gerst
2026-07-24 19:56       ` Tom Lendacky
2026-07-24 21:06         ` Brian Gerst
2026-07-24  3:02 ` [PATCH 2/5] x86/boot/64: Clear BSS as early as possible Brian Gerst
2026-07-24 11:04   ` Nikolay Borisov [this message]
2026-07-24 11:34     ` Brian Gerst
2026-07-27 19:00       ` Brian Gerst
2026-07-24  3:02 ` [PATCH 3/5] x86/boot: Remove hardcoded boot_param constants Brian Gerst
2026-07-24 13:19   ` Nikolay Borisov
2026-07-24 18:22   ` Tom Lendacky
2026-07-24 19:03     ` Brian Gerst
2026-07-24  3:02 ` [PATCH 4/5] x86/boot/64: Remove copy_bootdata() call Brian Gerst
2026-07-24  3:02 ` [PATCH 5/5] x86/boot/64: Copy boot parameters and command line earlier Brian Gerst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12ca9e3c-3cd7-4081-a906-593dcceca85b@suse.com \
    --to=nik.borisov@suse.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome