Re: [PATCH] x86/efi: defer freeing of boot services memory
From: Mike Rapoport
Date: Tue Feb 24 2026 - 04:29:11 EST
On Mon, Feb 23, 2026 at 01:18:41PM +0100, Ard Biesheuvel wrote:
> On Mon, 23 Feb 2026, at 12:40, Mike Rapoport wrote:
> > On Mon, Feb 23, 2026 at 12:17:22PM +0100, Ard Biesheuvel wrote:
> >>
> >> > I wasn't sure it's Ok to only unmap them, but leave in efi.memmap, that's
> >> > why I didn't use the existing EFI memory map.
> >> >
> >> > Now thinking about it, if the unmapping can happen later, maybe we'll just
> >> > move the entire efi_free_boot_services() to an initcall?
> >>
> >> As long as it is pre-SMP, as that code also contains a quirk to allocate
> >> the real mode trampoline if all memory below 1 MB is used for boot
> >> services.
> >
> > initcall is long after SMP. It the real mode trampoline allocation is the
> > only thing that should happen pre-SMP?
>
> early_initcall() should be early enough, those run before SMP init.
I don't think so. All initcalls run quite late in boot, early ones just run
before the others.
> >> But actually, that should be a separate quirk to begin with, rather than
> >> being integrated into an unrelated function that happens to iterate over
> >> the boot services regions. The only problem, I guess, is that
> >> memblock_reserve()'ing that sub-1MB region in the old location in the
> >> ordinary way would cause it to be freed again in the initcall?
> >
> > Right now we anyway don't free anything below 1M, I don't see why it should
> > change.
> >
> >> But yes, in general I think it is fine to unmap those regions from the
> >> EFI page tables during an initcall.
> >
> > Thanks for confirming. I'll look into extracting the allocation of the real
> > mode trampoline to a separate quirk and then making the entire
> > efi_free_boot_services() an initcall.
There's another issue with making the entire efi_free_boot_services() an
initcall. It updates efi.memmap without any synchronization and if it'll
run after SMP init, there might be a concurrent access to the efi.memmap.
It seems to me that to be on the safe side the simplest and easiest for
backporting is to stick with my original version.
> Thanks!
--
Sincerely yours,
Mike.