All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: Ard Biesheuvel <ardb+git@google.com>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, will@kernel.org,
	catalin.marinas@arm.com, mark.rutland@arm.com,
	Ard Biesheuvel <ardb@kernel.org>
Subject: Re: [PATCH v2 3/3] arm64/boot: Disallow BSS exports to startup code
Date: Thu, 8 May 2025 14:34:12 +0100	[thread overview]
Message-ID: <aByy1CFUieJQeofl@e129823.arm.com> (raw)
In-Reply-To: <20250508114328.2460610-8-ardb+git@google.com>

Hi Ard,

> From: Ard Biesheuvel <ardb@kernel.org>
>
> BSS might be uninitialized when entering the startup code, so forbid the
> use by the startup code of any variables that live after __bss_start in
> the linker map.
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  arch/arm64/kernel/image-vars.h  | 62 +++++++++++---------
>  arch/arm64/kernel/vmlinux.lds.S |  2 +
>  2 files changed, 35 insertions(+), 29 deletions(-)
>
> diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
> index c3b4c0479d5c..a928e0c0b45a 100644
> --- a/arch/arm64/kernel/image-vars.h
> +++ b/arch/arm64/kernel/image-vars.h
> @@ -10,6 +10,12 @@
>  #error This file should only be included in vmlinux.lds.S
>  #endif
>
> +#define PI_EXPORT_SYM(sym)		\
> +	__PI_EXPORT_SYM(sym, __pi_ ## sym, Cannot export BSS symbol sym to startup code)
> +#define __PI_EXPORT_SYM(sym, pisym, msg)\
> +	PROVIDE(pisym = sym);		\
> +	ASSERT((sym - KIMAGE_VADDR) < (__bss_start - KIMAGE_VADDR), #msg)
> +
>  PROVIDE(__efistub_primary_entry		= primary_entry);
>
>  /*
> @@ -36,37 +42,35 @@ PROVIDE(__pi___memcpy			= __pi_memcpy);
>  PROVIDE(__pi___memmove			= __pi_memmove);
>  PROVIDE(__pi___memset			= __pi_memset);
>
> -PROVIDE(__pi_id_aa64isar1_override	= id_aa64isar1_override);
> -PROVIDE(__pi_id_aa64isar2_override	= id_aa64isar2_override);
> -PROVIDE(__pi_id_aa64mmfr0_override	= id_aa64mmfr0_override);
> -PROVIDE(__pi_id_aa64mmfr1_override	= id_aa64mmfr1_override);
> -PROVIDE(__pi_id_aa64mmfr2_override	= id_aa64mmfr2_override);
> -PROVIDE(__pi_id_aa64pfr0_override	= id_aa64pfr0_override);
> -PROVIDE(__pi_id_aa64pfr1_override	= id_aa64pfr1_override);
> -PROVIDE(__pi_id_aa64smfr0_override	= id_aa64smfr0_override);
> -PROVIDE(__pi_id_aa64zfr0_override	= id_aa64zfr0_override);
> -PROVIDE(__pi_arm64_sw_feature_override	= arm64_sw_feature_override);
> -PROVIDE(__pi_arm64_use_ng_mappings	= arm64_use_ng_mappings);
> +PI_EXPORT_SYM(id_aa64isar1_override);
> +PI_EXPORT_SYM(id_aa64isar2_override);
> +PI_EXPORT_SYM(id_aa64mmfr0_override);
> +PI_EXPORT_SYM(id_aa64mmfr1_override);
> +PI_EXPORT_SYM(id_aa64mmfr2_override);
> +PI_EXPORT_SYM(id_aa64pfr0_override);
> +PI_EXPORT_SYM(id_aa64pfr1_override);
> +PI_EXPORT_SYM(id_aa64smfr0_override);
> +PI_EXPORT_SYM(id_aa64zfr0_override);
> +PI_EXPORT_SYM(arm64_sw_feature_override);
> +PI_EXPORT_SYM(arm64_use_ng_mappings);
>  #ifdef CONFIG_CAVIUM_ERRATUM_27456
> -PROVIDE(__pi_cavium_erratum_27456_cpus	= cavium_erratum_27456_cpus);
> -PROVIDE(__pi_is_midr_in_range_list	= is_midr_in_range_list);
> +PI_EXPORT_SYM(cavium_erratum_27456_cpus);
> +PI_EXPORT_SYM(is_midr_in_range_list);

small nit:
Would you rebase this patchset after
commit 117c3b21d3c7 ("arm64: Rework checks for broken Cavium HW in the PI code")?
Otherwise, I experience boot failure because of SCS related code:

  ffff80008009fbc0 <is_midr_in_range_list>:
  ffff80008009fbc0: d503245f   	bti	c
  ffff80008009fbc4: d503201f   	nop
  ffff80008009fbc8: d503201f   	nop
  ffff80008009fbcc: f800865e   	str	x30, [x18], #0x8 ---- (1)
  ffff80008009fbd0: d503233f   	paciasp
  ...

At pi phase, platform register initialized properly...
So it makes panic on (1).

Thanks!


>  #endif
> -PROVIDE(__pi__ctype			= _ctype);
> -PROVIDE(__pi_memstart_offset_seed	= memstart_offset_seed);
> -
> -PROVIDE(__pi_swapper_pg_dir		= swapper_pg_dir);
> -
> -PROVIDE(__pi__text			= _text);
> -PROVIDE(__pi__stext               	= _stext);
> -PROVIDE(__pi__etext               	= _etext);
> -PROVIDE(__pi___start_rodata       	= __start_rodata);
> -PROVIDE(__pi___inittext_begin     	= __inittext_begin);
> -PROVIDE(__pi___inittext_end       	= __inittext_end);
> -PROVIDE(__pi___initdata_begin     	= __initdata_begin);
> -PROVIDE(__pi___initdata_end       	= __initdata_end);
> -PROVIDE(__pi__data                	= _data);
> -PROVIDE(__pi___bss_start		= __bss_start);
> -PROVIDE(__pi__end			= _end);
> +PI_EXPORT_SYM(_ctype);
> +PI_EXPORT_SYM(memstart_offset_seed);
> +
> +PI_EXPORT_SYM(swapper_pg_dir);
> +
> +PI_EXPORT_SYM(_text);
> +PI_EXPORT_SYM(_stext);
> +PI_EXPORT_SYM(_etext);
> +PI_EXPORT_SYM(__start_rodata);
> +PI_EXPORT_SYM(__inittext_begin);
> +PI_EXPORT_SYM(__inittext_end);
> +PI_EXPORT_SYM(__initdata_begin);
> +PI_EXPORT_SYM(__initdata_end);
> +PI_EXPORT_SYM(_data);
>
>  #ifdef CONFIG_KVM
>
> diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
> index 466544c47dca..e4a525a865c1 100644
> --- a/arch/arm64/kernel/vmlinux.lds.S
> +++ b/arch/arm64/kernel/vmlinux.lds.S
> @@ -319,6 +319,7 @@ SECTIONS
>
>  	/* start of zero-init region */
>  	BSS_SECTION(SBSS_ALIGN, 0, 0)
> +	__pi___bss_start = __bss_start;
>
>  	. = ALIGN(PAGE_SIZE);
>  	__pi_init_pg_dir = .;
> @@ -332,6 +333,7 @@ SECTIONS
>  	. = ALIGN(SEGMENT_ALIGN);
>  	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
>  	_end = .;
> +	__pi__end = .;
>
>  	STABS_DEBUG
>  	DWARF_DEBUG
> --
> 2.49.0.987.g0cc8ee98dc-goog
>

--
Sincerely,
Yeoreum Yun


  reply	other threads:[~2025-05-08 14:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-08 11:43 [PATCH v2 0/3] arm64/boot: Forbid the use of BSS symbols in startup code Ard Biesheuvel
2025-05-08 11:43 ` [PATCH v2 1/3] arm64/boot: Move init_pgdir[] and init_idmap_pgdir[] into __pi_ namespace Ard Biesheuvel
2025-05-08 11:43 ` [PATCH v2 2/3] arm64/boot: Move global CPU override variables out of BSS Ard Biesheuvel
2025-05-08 11:43 ` [PATCH v2 3/3] arm64/boot: Disallow BSS exports to startup code Ard Biesheuvel
2025-05-08 13:34   ` Yeoreum Yun [this message]
2025-05-08 13:41     ` Yeoreum Yun
2025-05-09  6:43     ` Ard Biesheuvel
2025-05-08 13:47   ` kernel test robot
2025-05-09 17:10 ` [PATCH v2 0/3] arm64/boot: Forbid the use of BSS symbols in " Yeoreum Yun
2025-05-16 15:37 ` Will Deacon

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=aByy1CFUieJQeofl@e129823.arm.com \
    --to=yeoreum.yun@arm.com \
    --cc=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=will@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 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.