[RFC PATCH v2 41/48] efi_memory: add an event handler to update memory map

Sughosh Ganu sughosh.ganu at linaro.org
Wed Jul 17 09:58:45 CEST 2024


On Tue, 16 Jul 2024 at 22:30, Tom Rini <trini at konsulko.com> wrote:
>
> On Tue, Jul 16, 2024 at 11:55:10AM +0530, Sughosh Ganu wrote:
> > On Tue, 16 Jul 2024 at 00:35, Tom Rini <trini at konsulko.com> wrote:
> > >
> > > On Mon, Jul 15, 2024 at 12:39:32PM +0100, Simon Glass wrote:
> > > > Hi Sughosh,
> > > >
> > > > On Mon, 15 Jul 2024 at 10:39, Sughosh Ganu <sughosh.ganu at linaro.org> wrote:
> > > > >
> > > > > hi Simon,
> > > > >
> > > > > On Sat, 13 Jul 2024 at 20:46, Simon Glass <sjg at chromium.org> wrote:
> > > > > >
> > > > > > Hi Sughosh,
> > > > > >
> > > > > > On Thu, 4 Jul 2024 at 08:38, Sughosh Ganu <sughosh.ganu at linaro.org> wrote:
> > > > > > >
> > > > > > > There are events that would be used to notify other interested modules
> > > > > > > of any changes in available and occupied memory. This would happen
> > > > > > > when a module allocates or reserves memory, or frees up memory. These
> > > > > > > changes in memory map should be notified to other interested modules
> > > > > > > so that the allocated memory does not get overwritten. Add an event
> > > > > > > handler in the EFI memory module to update the EFI memory map
> > > > > > > accordingly when such changes happen. As a consequence, any subsequent
> > > > > > > memory request would honour the updated memory map and only available
> > > > > > > memory would be allocated from.
> > > > > > >
> > > > > > > Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
> > > > > > > ---
> > > > > > > Changes since V1:
> > > > > > > * Handle the addition of memory to the LMB memory map.
> > > > > > > * Pass the overlap_only_ram parameter to the efi_add_memory_map_pg()
> > > > > > >   based on the type of operation.
> > > > > > >
> > > > > > >  lib/efi_loader/Kconfig      |  1 +
> > > > > > >  lib/efi_loader/efi_memory.c | 34 ++++++++++++++++++++++++++++++++++
> > > > > > >  2 files changed, 35 insertions(+)
> > > > > > >
> > > > > >
> > > > > > This is getting complicated and I don't believe it is needed.
> > > > > >
> > > > > > EFI should not be allocating memory 'in free space' until it starts
> > > > > > up. For the very few (if any) cases where it does, it can do an lmb
> > > > > > allocation.
> > > > >
> > > > > EFI memory module is not allocating memory at all now. This patch is
> > > > > adding an event handler for updating the EFI memory map, whenever the
> > > > > LMB memory map changes. All the EFI allocations are now being routed
> > > > > through the LMB API's.
> > > >
> > > > OK
> > > >
> > > > >
> > > > > >
> > > > > > As to the lmb allocations themselves, EFI can simply call look through
> > > > > > the lmb list and call efi_add_memory_map_pg() for each entry, when it
> > > > > > is ready to boot. There is no need to do it earlier.
> > > > >
> > > > > So in this case, I believe that rather than adding code in multiple
> > > > > places where the EFI memory module would have to get the LMB map and
> > > > > then update it's own, I think it is easier to update the EFI memory
> > > > > map as and when the LMB map gets updated. Else, we have a scenario
> > > > > where the EFI memory map would have to be updated as part of the EFI
> > > > > memory map dump function, as well as before the EFI boot. Any new code
> > > > > that would be subsequently introduced that might have a similar
> > > > > requirement would then be needed to keep this point in mind(to get the
> > > > > memory map from LMB).
> > > >
> > > > That doesn't hold water in my eyes. I actually like the idea of the
> > > > EFI memory map being set up before booting. It should be done in a
> > > > single function called from one place, just before booting. Well, I
> > > > suppose it could be called from the memory-map-dump function too. But
> > > > it should be pretty simple...just add some pre-defined things and then
> > > > add the lmb records. You can even write a unit test for it.
> > > >
> > > > >
> > > > > This is not an OS file-system kind of an operation where performance
> > > > > is critical, nor is this event(LMB memory map update) going to happen
> > > > > very frequently. So I believe that it would be better to keep the EFI
> > > > > memory map updated along with the LMB one.
> > > >
> > > > I really don't like that idea at all. One table is enough for use by
> > > > U-Boot. The EFI one is needed for booting. Keeping them in sync as
> > > > U-Boot is running is not necessary, just invites bugs and makes the
> > > > whole thing harder to test.
> > >
> > > Doesn't that ignore the issue of EFI being re-entrant to us? Or no,
> > > because you're suggesting we only update the EFI map before entering the
> > > EFI loader, not strictly "booting the OS"? In which case, maybe that
> > > does end up being both cleaner and smaller? I'm not sure.
> >
> > And that is my concern here about having to update the EFI map at
> > multiple call points, instead of keeping it updated -- I feel this is
> > more prone to being buggy. And to add to this, there might be code
> > paths added subsequently which might need an updated EFI map where
> > this gets missed. The only downside to the current design is that it
> > might be slower since the EFI map gets updated on every change to the
> > LMB map. But I am not sure if the LMB map changes are going to be that
> > frequent.
>
> To me the question really is, do we have a single entry point to the EFI
> loader that must always be used (and is before EFI loader must know for
> sure it has up to date memory reservations) or are there two or more
> points? If there's two or more points then yes, your current approach is
> best as we don't want to introduce problems down the line. If there's
> one (which is what I hope), then we can just make that entry point be
> where the resync happens.

There are a couple of places where the memory map gets used, one from
the external get_memory_map API, and one from the 'efidebug memmap'
command. But they do call the same internal function to get the memory
map. So that function can be the common point of getting the current
memory map from lmb. This will mean that we expose the lmb structures
into the efi memory module. I will put out an implementation and we
can see about it at that point. This will be part of the second part
of the patches that I will be sending. Will work on getting the lmb
patches out first.

-sughosh
>
> --
> Tom


More information about the U-Boot mailing list