[PATCH v1] efi_loader: Handle GD_FLG_SKIP_RELOC

Varadarajan Narayanan quic_varada at quicinc.com
Thu Mar 27 07:11:58 CET 2025


On Wed, Mar 26, 2025 at 09:28:04AM +0200, Ilias Apalodimas wrote:
> Hi Varadarajan
>
> On Wed, 26 Mar 2025 at 07:47, Varadarajan Narayanan
> <quic_varada at quicinc.com> wrote:
> >
> > If the EFI runtime services pointers are relocated even though
> > relocation is skipped, it corrupts some other data resulting in some
> > unexpected behaviour.
> >
> > In this specific case, it overwrote some page table entries resulting in
> > the device memory address range's mappings getting removed. Eventually,
> > after the completion of efi_runtime_relocate(), when a driver tries to
> > access its device's registers it crashes since the mappings are absent.
>
> How were those page table entries added?

initr_caches ->
	enable_caches ->
		setup_pgtables (arch/arm/mach-snapdragon/board.c)

> The runtime service relocation might have overwritten those now, but
> since they are not in protected memory this can happen arbitrarily.

To avoid relocating U-Boot, I had OR'ed GD_FLG_SKIP_RELOC to gd->flags
in init_sequence_f -> mach_cpu_init(). Hope that is the right place and
way to do it.

> > Signed-off-by: Varadarajan Narayanan <quic_varada at quicinc.com>
> > ---
> >  common/board_r.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/common/board_r.c b/common/board_r.c
> > index 179259b00de..1dd3b96c2de 100644
> > --- a/common/board_r.c
> > +++ b/common/board_r.c
> > @@ -169,7 +169,8 @@ static int initr_reloc_global_data(void)
> >          */
> >         efi_save_gd();
> >
> > -       efi_runtime_relocate(gd->relocaddr, NULL);
> > +       if (!(gd->flags & GD_FLG_SKIP_RELOC))
> > +               efi_runtime_relocate(gd->relocaddr, NULL);
>
> Have you tested booting with EFI with this change?

Yes, tested this with both GD_FLG_SKIP_RELOC set and not set.

Used the command 'bootefi bootmgr' and Linux is able to boot.

Thanks
Varada


More information about the U-Boot mailing list