[PATCH v1] efi_loader: Handle GD_FLG_SKIP_RELOC

Varadarajan Narayanan quic_varada at quicinc.com
Tue Apr 1 08:46:45 CEST 2025


On Thu, Mar 27, 2025 at 11:22:58PM +0200, Ilias Apalodimas wrote:
> On Thu, 27 Mar 2025 at 08:12, Varadarajan Narayanan
> <quic_varada at quicinc.com> wrote:
> >
> > 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.
>
> I'll have a look at the relocation stuff, but off the top of my head,
> I don't remember.
>
> >
> > > > 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.
>
> Have you tried to call any runtime services -- e.g efival -l will dump
> all the EFI variables

Sorry for the delay. The test setup was busy. My U-boot doesn't seem to
have this command. Not sure if I'm missing some config.

	=> efival -l
	Unknown command 'efival' - try 'help'

However, 'efidebug boot dump' works. Does that suffice?

	=> efidebug boot dump
	Boot0000:
	attributes: A-- (0x00000001)
	  label: scsi 0
	  file_path:
	/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,7d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6b00000000000000)/Scsi(0,0)
	  data:
	    00000000: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2
	N.....YM....R,Y.
	Boot0001:
	attributes: A-- (0x00000001)
	  label: scsi 1
	  file_path:
	/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,7d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6b00000000000000)/Scsi(0,1)
	  data:
	    00000000: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2
	N.....YM....R,Y.
	Boot0002:
	attributes: A-- (0x00000001)
	  label: scsi 2
	  file_path:
	/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,7d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6b00000000000000)/Scsi(0,2)
	  data:
	    00000000: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2
	N.....YM....R,Y.
	Boot0003:
	attributes: A-- (0x00000001)
	  label: scsi 3
	  file_path:
	/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,7d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6b00000000000000)/Scsi(0,3)
	  data:
	    00000000: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2
	N.....YM....R,Y.
	Boot0004:
	attributes: A-- (0x00000001)
	  label: scsi 4
	  file_path:
	/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,7d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6b00000000000000)/Scsi(0,4)
	  data:
	    00000000: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2
	N.....YM....R,Y.
	Boot0005:
	attributes: A-- (0x00000001)
	  label: scsi 5
	  file_path:
	/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,7d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6b00000000000000)/Scsi(0,5)
	  data:
	    00000000: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2
	N.....YM....R,Y.
	Boot0006:
	attributes: A-- (0x00000001)
	  label: scsi 6
	  file_path:
	/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,7d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6b00000000000000)/Scsi(0,6)
	  data:
	    00000000: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2
	N.....YM....R,Y.
	Boot0007:
	attributes: A-- (0x00000001)
	  label: scsi 7
	  file_path:
	/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,7d00000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6b00000000000000)/Scsi(0,7)
	  data:
	    00000000: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2
	N.....YM....R,Y.

Thanks
Varada


More information about the U-Boot mailing list