U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Simon Glass <sjg@chromium.org>
Cc: Sughosh Ganu <sughosh.ganu@linaro.org>,
	u-boot@lists.denx.de,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Marek Vasut <marex@denx.de>,
	Mark Kettenis <mark.kettenis@xs4all.nl>,
	Fabio Estevam <festevam@gmail.com>,
	Michal Simek <michal.simek@amd.com>
Subject: Re: [RFC PATCH v2 13/48] lmb: make LMB memory map persistent and global
Date: Mon, 15 Jul 2024 11:58:33 -0600	[thread overview]
Message-ID: <20240715175833.GL38804@bill-the-cat> (raw)
In-Reply-To: <CAFLszThVsbLLLDnCyhObLbj=zMjXnzX8ncOxT8TfPkOi05GOPw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 8732 bytes --]

On Mon, Jul 15, 2024 at 12:39:35PM +0100, Simon Glass wrote:
> Hi Sughosh,
> 
> On Mon, 15 Jul 2024 at 10:48, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> >
> > hi Simon,
> >
> > On Sat, 13 Jul 2024 at 20:46, Simon Glass <sjg@chromium.org> wrote:
> > >
> > > Hi Sughosh,
> > >
> > > On Thu, 4 Jul 2024 at 08:36, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> > > >
> > > > The current LMB API's for allocating and reserving memory use a
> > > > per-caller based memory view. Memory allocated by a caller can then be
> > > > overwritten by another caller. Make these allocations and reservations
> > > > persistent using the alloced list data structure.
> > > >
> > > > Two alloced lists are declared -- one for the available(free) memory,
> > > > and one for the used memory. Once full, the list can then be extended
> > > > at runtime.
> > > >
> > > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > > > ---
> > > > Changes since V1:
> > > > * Use alloced list structure for the available and reserved memory
> > > >   lists instead of static arrays.
> > > > * Corresponding changes in the code made as a result of the above
> > > >   change.
> > > > * Rename the reserved memory list as 'used'.
> > > >
> > > >  include/lmb.h |  77 +++--------
> > > >  lib/lmb.c     | 346 ++++++++++++++++++++++++++++++--------------------
> > > >  2 files changed, 224 insertions(+), 199 deletions(-)
> > > >
> > > > diff --git a/include/lmb.h b/include/lmb.h
> > > > index 99fcf5781f..27cdb18c37 100644
> > > > --- a/include/lmb.h
> > > > +++ b/include/lmb.h
> > > > @@ -24,78 +24,18 @@ enum lmb_flags {
> > > >  };
> > > >
> > > >  /**
> > > > - * struct lmb_property - Description of one region.
> > > > + * struct lmb_region - Description of one region.
> > > >   *
> > > >   * @base:      Base address of the region.
> > > >   * @size:      Size of the region
> > > >   * @flags:     memory region attributes
> > > >   */
> > > > -struct lmb_property {
> > > > +struct lmb_region {
> > > >         phys_addr_t base;
> > > >         phys_size_t size;
> > > >         enum lmb_flags flags;
> > > >  };
> > > >
> > > > -/*
> > > > - * For regions size management, see LMB configuration in KConfig
> > > > - * all the #if test are done with CONFIG_LMB_USE_MAX_REGIONS (boolean)
> > > > - *
> > > > - * case 1. CONFIG_LMB_USE_MAX_REGIONS is defined (legacy mode)
> > > > - *         => CONFIG_LMB_MAX_REGIONS is used to configure the region size,
> > > > - *         directly in the array lmb_region.region[], with the same
> > > > - *         configuration for memory and reserved regions.
> > > > - *
> > > > - * case 2. CONFIG_LMB_USE_MAX_REGIONS is not defined, the size of each
> > > > - *         region is configurated *independently* with
> > > > - *         => CONFIG_LMB_MEMORY_REGIONS: struct lmb.memory_regions
> > > > - *         => CONFIG_LMB_RESERVED_REGIONS: struct lmb.reserved_regions
> > > > - *         lmb_region.region is only a pointer to the correct buffer,
> > > > - *         initialized in lmb_init(). This configuration is useful to manage
> > > > - *         more reserved memory regions with CONFIG_LMB_RESERVED_REGIONS.
> > > > - */
> > > > -
> > > > -/**
> > > > - * struct lmb_region - Description of a set of region.
> > > > - *
> > > > - * @cnt: Number of regions.
> > > > - * @max: Size of the region array, max value of cnt.
> > > > - * @region: Array of the region properties
> > > > - */
> > > > -struct lmb_region {
> > > > -       unsigned long cnt;
> > > > -       unsigned long max;
> > > > -#if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
> > > > -       struct lmb_property region[CONFIG_LMB_MAX_REGIONS];
> > > > -#else
> > > > -       struct lmb_property *region;
> > > > -#endif
> > > > -};
> > > > -
> > > > -/**
> > > > - * struct lmb - Logical memory block handle.
> > > > - *
> > > > - * Clients provide storage for Logical memory block (lmb) handles.
> > > > - * The content of the structure is managed by the lmb library.
> > > > - * A lmb struct is  initialized by lmb_init() functions.
> > > > - * The lmb struct is passed to all other lmb APIs.
> > > > - *
> > > > - * @memory: Description of memory regions.
> > > > - * @reserved: Description of reserved regions.
> > > > - * @memory_regions: Array of the memory regions (statically allocated)
> > > > - * @reserved_regions: Array of the reserved regions (statically allocated)
> > > > - */
> > > > -struct lmb {
> > > > -       struct lmb_region memory;
> > > > -       struct lmb_region reserved;
> > > > -#if !IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
> > > > -       struct lmb_property memory_regions[CONFIG_LMB_MEMORY_REGIONS];
> > > > -       struct lmb_property reserved_regions[CONFIG_LMB_RESERVED_REGIONS];
> > > > -#endif
> > > > -};
> > > > -
> > > > -void lmb_init_and_reserve(struct bd_info *bd, void *fdt_blob);
> > > > -void lmb_init_and_reserve_range(phys_addr_t base, phys_size_t size,
> > > > -                               void *fdt_blob);
> > > >  long lmb_add(phys_addr_t base, phys_size_t size);
> > > >  long lmb_reserve(phys_addr_t base, phys_size_t size);
> > > >  /**
> > > > @@ -134,6 +74,19 @@ void board_lmb_reserve(void);
> > > >  void arch_lmb_reserve(void);
> > > >  void arch_lmb_reserve_generic(ulong sp, ulong end, ulong align);
> > > >
> > > > +/**
> > > > + * lmb_mem_regions_init() - Initialise the LMB memory
> > > > + *
> > > > + * Initialise the LMB subsystem related data structures. There are two
> > > > + * alloced lists that are initialised, one for the free memory, and one
> > > > + * for the used memory.
> > > > + *
> > > > + * Initialise the two lists as part of board init.
> > > > + *
> > > > + * Return: 0 if OK, -ve on failure.
> > > > + */
> > > > +int lmb_mem_regions_init(void);
> > > > +
> > > >  #endif /* __KERNEL__ */
> > > >
> > > >  #endif /* _LINUX_LMB_H */
> > > > diff --git a/lib/lmb.c b/lib/lmb.c
> > > > index 80945e3cae..a46bc8a7a3 100644
> > > > --- a/lib/lmb.c
> > > > +++ b/lib/lmb.c
> > > > @@ -6,6 +6,7 @@
> > > >   * Copyright (C) 2001 Peter Bergner.
> > > >   */
> > > >
> > > > +#include <alist.h>
> > > >  #include <efi_loader.h>
> > > >  #include <image.h>
> > > >  #include <mapmem.h>
> > > > @@ -15,24 +16,30 @@
> > > >
> > > >  #include <asm/global_data.h>
> > > >  #include <asm/sections.h>
> > > > +#include <linux/kernel.h>
> > > >
> > > >  DECLARE_GLOBAL_DATA_PTR;
> > > >
> > > >  #define LMB_ALLOC_ANYWHERE     0
> > > > +#define LMB_ALIST_INITIAL_SIZE 4
> > > >
> > > > -static void lmb_dump_region(struct lmb_region *rgn, char *name)
> > > > +struct alist lmb_free_mem;
> > > > +struct alist lmb_used_mem;
> > >
> > > I think these should be in a struct, e.g. struct lmb, allocated with
> > > malloc() and pointed to by gd->lmb so we can avoid making the tests
> > > destructive, and allow use of lmb in SPL.
> >
> > Can you elaborate on the point of allowing use of lmb in SPL. Why
> > would the current design not work in SPL ? I tested this on the
> > sandbox SPL variant, and the two lists do get initialised as part of
> > the SPL initialisation routine. Is there some corner-case that I am
> > not considering ?
> 
> Just that some boards don't have their BSS available until later on in
> SPL. In general we try to avoid local variables with driver model...I
> think lmb should be the same, particularly as there it is fairly cheap
> to allocate a struct with malloc().

We also have limited malloc space, in those cases. But, yes, we likely
need LMB available to use earlier in the SPL case now than we did
before, so malloc is likely better, as Simon suggests.

> > Also, regarding putting the lmb structure pointer as part of gd, iirc
> > Tom had a different opinion on this. Tom, can you please chime in here
> > ?
> 
> or you could point to the discussion?

It was in reply to the last posting of this series.

While there's a strong implication that tests in post/ (as it is short
for 'power on self test') need to be non-destructive, that's not the
case for test/ code.

So my thoughts are:
- Since there's only one list for real use, calls are cleaner if we
  aren't passing a pointer to the one and only thing everyone could use.
- I don't think we have a test case that's hindered by not doing this,
  only "now boot normally" may be harder/hindered.
- Taking things out of gd is usually good?

At the end of the day, if this is a big sticking point with the new
scheme, no, OK, we can go back to gd->lmb. I don't think we need it, but
I can't convince myself Everyone Else Is Wrong about it either.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

  reply	other threads:[~2024-07-15 17:58 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-04  7:34 [RFC PATCH v2 00/48] Make U-Boot memory reservations coherent Sughosh Ganu
2024-07-04  7:34 ` [RFC PATCH v2 01/48] malloc: Support testing with realloc() Sughosh Ganu
2024-07-04  7:34 ` [RFC PATCH v2 02/48] lib: Handle a special case with str_to_list() Sughosh Ganu
2024-07-04  7:34 ` [RFC PATCH v2 03/48] alist: Add support for an allocated pointer list Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 04/48] lib: Convert str_to_list() to use alist Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 05/48] alist: add a couple of helper functions Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 06/48] alist: add a function declaration for alist_expand_by() Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 07/48] lmb: remove the unused lmb_is_reserved() function Sughosh Ganu
2024-07-13 15:13   ` Simon Glass
2024-07-04  7:35 ` [RFC PATCH v2 08/48] lmb: staticize __lmb_alloc_base() Sughosh Ganu
2024-07-13 15:13   ` Simon Glass
2024-07-04  7:35 ` [RFC PATCH v2 09/48] lmb: remove call to lmb_init() Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-15  9:31     ` Sughosh Ganu
2024-07-15 11:39       ` Simon Glass
2024-07-16  6:30         ` Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 10/48] lmb: remove local instances of the lmb structure variable Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-15  9:29     ` Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 11/48] lmb: pass a flag to image_setup_libfdt() for lmb reservations Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-04  7:35 ` [RFC PATCH v2 12/48] lmb: allow for resizing lmb regions Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-15  9:27     ` Sughosh Ganu
2024-07-15 11:39       ` Simon Glass
2024-07-16  6:26         ` Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 13/48] lmb: make LMB memory map persistent and global Sughosh Ganu
2024-07-13 15:16   ` Simon Glass
2024-07-15  9:48     ` Sughosh Ganu
2024-07-15 11:39       ` Simon Glass
2024-07-15 17:58         ` Tom Rini [this message]
2024-07-15 19:32           ` Simon Glass
2024-07-04  7:35 ` [RFC PATCH v2 14/48] lmb: remove config symbols used for lmb region count Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-23  8:48   ` Ilias Apalodimas
2024-07-04  7:35 ` [RFC PATCH v2 15/48] test: lmb: remove the test for max regions Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-22 11:24   ` Ilias Apalodimas
2024-07-04  7:35 ` [RFC PATCH v2 16/48] lmb: config: add lmb config symbols for SPL Sughosh Ganu
2024-07-05 19:48   ` Tom Rini
2024-07-08 11:36     ` Sughosh Ganu
2024-07-08 14:46       ` Tom Rini
2024-07-13 15:15         ` Simon Glass
2024-07-04  7:35 ` [RFC PATCH v2 17/48] lmb: allow lmb module to be used in SPL Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-15  9:24     ` Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 18/48] lmb: introduce a function to add memory to the lmb memory map Sughosh Ganu
2024-07-08 14:11   ` Tom Rini
2024-07-04  7:35 ` [RFC PATCH v2 19/48] lmb: remove the lmb_init_and_reserve() function Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-22 12:27   ` Ilias Apalodimas
2024-07-04  7:35 ` [RFC PATCH v2 20/48] lmb: reserve common areas during board init Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-04  7:35 ` [RFC PATCH v2 21/48] lmb: remove lmb_init_and_reserve_range() function Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 22/48] lmb: init: initialise the lmb data structures during board init Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 23/48] lmb: use the BIT macro for lmb flags Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 24/48] lmb: add a common implementation of arch_lmb_reserve() Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 25/48] sandbox: spl: enable lmb in SPL Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 26/48] sandbox: iommu: remove lmb allocation in the driver Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 27/48] zynq: lmb: do not add to lmb map before relocation Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 28/48] test: cedit: use allocated address for reading file Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 29/48] test: lmb: tweak the tests for the persistent lmb memory map Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 30/48] test: lmb: run lmb tests only manually Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 31/48] test: lmb: add a separate class of unit tests for lmb Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 32/48] test: lmb: invoke the LMB unit tests from a separate script Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 33/48] test: bdinfo: dump the global LMB memory map Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 34/48] lmb: add versions of the lmb API with flags Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 35/48] lmb: add a flag to allow suppressing memory map change notification Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 36/48] efi: memory: use the lmb API's for allocating and freeing memory Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 37/48] event: add event to notify lmb memory map changes Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 38/48] lib: Kconfig: add a config symbol for getting lmb memory map updates Sughosh Ganu
2024-07-05 19:50   ` Tom Rini
2024-07-22 12:30     ` Ilias Apalodimas
2024-07-22 12:59       ` Sughosh Ganu
2024-07-23  7:09         ` Ilias Apalodimas
2024-07-23 12:42         ` Simon Glass
2024-07-23 14:20           ` Tom Rini
2024-07-24 14:37             ` Simon Glass
2024-07-24 14:52               ` Tom Rini
2024-07-24 15:40                 ` Simon Glass
2024-07-24 22:47                   ` Tom Rini
2024-07-25 23:32                     ` Simon Glass
2024-07-04  7:35 ` [RFC PATCH v2 39/48] add a function to check if an address is in RAM memory Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 40/48] lmb: notify of any changes to the LMB memory map Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 41/48] efi_memory: add an event handler to update " Sughosh Ganu
2024-07-13 15:16   ` Simon Glass
2024-07-15  9:39     ` Sughosh Ganu
2024-07-15 11:39       ` Simon Glass
2024-07-15 19:05         ` Tom Rini
2024-07-16  6:25           ` Sughosh Ganu
2024-07-16  7:09             ` Simon Glass
2024-07-16  8:35               ` Sughosh Ganu
2024-07-16 17:00             ` Tom Rini
2024-07-17  7:58               ` Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 42/48] ti: k3: remove efi_add_known_memory() function definition Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 43/48] layerscape: use the lmb API's to add RAM memory Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 44/48] x86: e820: use the lmb API for adding " Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 45/48] efi_memory: do not add RAM memory to the memory map Sughosh Ganu
2024-07-13 15:15   ` Simon Glass
2024-07-04  7:35 ` [RFC PATCH v2 46/48] lmb: mark the EFI runtime memory regions as reserved Sughosh Ganu
2024-07-13 15:16   ` Simon Glass
2024-07-15  9:41     ` Sughosh Ganu
2024-07-15 11:39       ` Simon Glass
2024-07-16  6:31         ` Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 47/48] test: event: update the expected event dump output Sughosh Ganu
2024-07-04  7:35 ` [RFC PATCH v2 48/48] temp: mx6sabresd: bump up the size limit of the board Sughosh Ganu
2024-07-05 18:36   ` Tom Rini
2024-07-08 14:02 ` [RFC PATCH v2 00/48] Make U-Boot memory reservations coherent Tom Rini
2024-07-22  6:28   ` Sughosh Ganu
2024-07-22 17:33     ` Tom Rini
2024-07-22 17:37       ` Sughosh Ganu
2024-07-23 12:47         ` Simon Glass
2024-07-23 14:48         ` Tom Rini
2024-07-23 14:51           ` Sughosh Ganu
2024-07-23 15:29             ` Tom Rini
2024-07-08 14:35 ` Tom Rini
2024-07-13 15:15   ` Simon Glass

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=20240715175833.GL38804@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=festevam@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=marex@denx.de \
    --cc=mark.kettenis@xs4all.nl \
    --cc=michal.simek@amd.com \
    --cc=sjg@chromium.org \
    --cc=sughosh.ganu@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox