Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Tom Rini
On Thu, Jan 12, 2023 at 12:35:15AM +0100, Heinrich Schuchardt wrote:
> 
> 
> On 1/11/23 23:59, Mark Kettenis wrote:
> > > From: Simon Glass 
> > > Date: Wed, 11 Jan 2023 14:08:27 -0700
> > 
> > Hi Simon,
> > 
> > > Hi Heinrich,
> > > 
> > > On Wed, 11 Jan 2023 at 11:03, Heinrich Schuchardt
> > >  wrote:
> > > > 
> > > > 
> > > > 
> > > > On 1/11/23 18:55, Simon Glass wrote:
> > > > > Hi Heinrich,
> > > > > 
> > > > > On Wed, 11 Jan 2023 at 09:59, Heinrich Schuchardt
> > > > >  wrote:
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > On 1/11/23 17:48, Simon Glass wrote:
> > > > > > > Hi,
> > > > > > > 
> > > > > > > On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:
> > > > > > > > 
> > > > > > > > On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt 
> > > > > > > > wrote:
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > On 1/11/23 01:15, Simon Glass wrote:
> > > > > > > > > > Hi Heinrich,
> > > > > > > > > > 
> > > > > > > > > > On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
> > > > > > > > > >  wrote:
> > > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > On 1/9/23 21:31, Simon Glass wrote:
> > > > > > > > > > > > Hi Mark,
> > > > > > > > > > > > 
> > > > > > > > > > > > On Mon, 9 Jan 2023 at 13:20, Mark Kettenis 
> > > > > > > > > > > >  wrote:
> > > > > > > > > > > > > 
> > > > > > > > > > > > > > From: Simon Glass 
> > > > > > > > > > > > > > Date: Mon, 9 Jan 2023 13:11:01 -0700
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > Hi Heinrich,
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > 
> > > > > > > > > > > > > > We need to fix how EFI does addresses. It seems to 
> > > > > > > > > > > > > > use them as
> > > > > > > > > > > > > > pointers but store them as u64 ?
> > > > > > > > > > > 
> > > > > > > > > > > That is similar to what you have been doing with physical 
> > > > > > > > > > > addresses.
> > > > > > > > > > > 
> > > > > > > > > > > > > 
> > > > > > > > > > > > > They're defined to a 64-bit unsigned integer by the 
> > > > > > > > > > > > > UEFI
> > > > > > > > > > > > > specification, so you can't change it.
> > > > > > > > > > > > 
> > > > > > > > > > > > I don't mean changing the spec, just changing the 
> > > > > > > > > > > > internal U-Boot
> > > > > > > > > > > > implementation, which is very confusing. This confusion 
> > > > > > > > > > > > is spreading
> > > > > > > > > > > > out, too.
> > > > > > > > > > > > 
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Simon
> > > > > > > > > > > 
> > > > > > > > > > > The real interesting thing is how memory should be 
> > > > > > > > > > > managed in U-Boot:
> > > > > > > > > > > 
> > > > > > > > > > > I would prefer to create a shared global memory 
> > > > > > > > > > > management on 4KiB page
> > > > > > > > > > > level used both for EFI and the rest of U-Boot.
> > > > > > > > > > 
> > > > > > > > > > Sounds good.
> > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > What EFI adds to the requirements is that you need more 
> > > > > > > > > > > than free
> > > > > > > > > > > (EfiConventionalMemory) and used memory. EFI knows 16 
> > > > > > > > > > > different types of
> > > > > > > > > > > memory usage (see enum efi_memory_type).
> > > > > > > > > > 
> > > > > > > > > > That's a shame. How much of this is legacy and how much is 
> > > > > > > > > > useful?
> > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > When loading a file (e.g. with the "load" command) this 
> > > > > > > > > > > should lead to a
> > > > > > > > > > > memory reservation. You should not be able to load a 
> > > > > > > > > > > second file into an
> > > > > > > > > > > overlapping memory area without releasing the allocated 
> > > > > > > > > > > memory first.
> > > > > > > > > > > 
> > > > > > > > > > > This would replace lmb which currently tries to 
> > > > > > > > > > > recalculate available
> > > > > > > > > > > memory ab initio again and again.
> > > > > > > > > > > 
> > > > > > > > > > > With managed memory we should be able to get rid of all 
> > > > > > > > > > > those constants
> > > > > > > > > > > like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and 
> > > > > > > > > > > instead use a
> > > > > > > > > > > register of named loaded files.
> > > > > > > > > > 
> > > > > > > > > > This is where standard boot comes in, since it knows what 
> > > > > > > > > > it has
> > > > > > > > > > loaded and has pointers to it.
> > > > > > > > > > 
> > > > > > > > > > I see a future where we don't use these commands when we 
> > > > > > > > > > want to save
> > > > > > > > > > space. It can save 300KB from the U-Boot size.
> > > > > > > > > > 
> > > > > > > > > > But this really has to come later, since there is so much 
> > > > > > > > > > churn already!
> > > > > > > > > > 
> > > > > > > > > > For now, please don't add EFI allocation into lmb..that is 
> > > > > > > > > > just odd.
> > > > > > > > > 
> > > > > > > > > It is not odd but necessary. Without it the Odr

Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Simon Glass
Hi Mark,

On Wed, 11 Jan 2023 at 15:59, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Wed, 11 Jan 2023 14:08:27 -0700
>
> Hi Simon,
>
> > Hi Heinrich,
> >
> > On Wed, 11 Jan 2023 at 11:03, Heinrich Schuchardt
> >  wrote:
> > >
> > >
> > >
> > > On 1/11/23 18:55, Simon Glass wrote:
> > > > Hi Heinrich,
> > > >
> > > > On Wed, 11 Jan 2023 at 09:59, Heinrich Schuchardt
> > > >  wrote:
> > > >>
> > > >>
> > > >>
> > > >> On 1/11/23 17:48, Simon Glass wrote:
> > > >>> Hi,
> > > >>>
> > > >>> On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:
> > > 
> > >  On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:
> > > >
> > > >
> > > > On 1/11/23 01:15, Simon Glass wrote:
> > > >> Hi Heinrich,
> > > >>
> > > >> On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
> > > >>  wrote:
> > > >>>
> > > >>>
> > > >>>
> > > >>> On 1/9/23 21:31, Simon Glass wrote:
> > >  Hi Mark,
> > > 
> > >  On Mon, 9 Jan 2023 at 13:20, Mark Kettenis 
> > >   wrote:
> > > >
> > > >> From: Simon Glass 
> > > >> Date: Mon, 9 Jan 2023 13:11:01 -0700
> > > >>
> > > >> Hi Heinrich,
> > > >>
> > > >>
> > > >> We need to fix how EFI does addresses. It seems to use them as
> > > >> pointers but store them as u64 ?
> > > >>>
> > > >>> That is similar to what you have been doing with physical 
> > > >>> addresses.
> > > >>>
> > > >
> > > > They're defined to a 64-bit unsigned integer by the UEFI
> > > > specification, so you can't change it.
> > > 
> > >  I don't mean changing the spec, just changing the internal U-Boot
> > >  implementation, which is very confusing. This confusion is 
> > >  spreading
> > >  out, too.
> > > 
> > >  Regards,
> > >  Simon
> > > >>>
> > > >>> The real interesting thing is how memory should be managed in 
> > > >>> U-Boot:
> > > >>>
> > > >>> I would prefer to create a shared global memory management on 
> > > >>> 4KiB page
> > > >>> level used both for EFI and the rest of U-Boot.
> > > >>
> > > >> Sounds good.
> > > >>
> > > >>>
> > > >>> What EFI adds to the requirements is that you need more than free
> > > >>> (EfiConventionalMemory) and used memory. EFI knows 16 different 
> > > >>> types of
> > > >>> memory usage (see enum efi_memory_type).
> > > >>
> > > >> That's a shame. How much of this is legacy and how much is useful?
> > > >>
> > > >>>
> > > >>> When loading a file (e.g. with the "load" command) this should 
> > > >>> lead to a
> > > >>> memory reservation. You should not be able to load a second file 
> > > >>> into an
> > > >>> overlapping memory area without releasing the allocated memory 
> > > >>> first.
> > > >>>
> > > >>> This would replace lmb which currently tries to recalculate 
> > > >>> available
> > > >>> memory ab initio again and again.
> > > >>>
> > > >>> With managed memory we should be able to get rid of all those 
> > > >>> constants
> > > >>> like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use 
> > > >>> a
> > > >>> register of named loaded files.
> > > >>
> > > >> This is where standard boot comes in, since it knows what it has
> > > >> loaded and has pointers to it.
> > > >>
> > > >> I see a future where we don't use these commands when we want to 
> > > >> save
> > > >> space. It can save 300KB from the U-Boot size.
> > > >>
> > > >> But this really has to come later, since there is so much churn 
> > > >> already!
> > > >>
> > > >> For now, please don't add EFI allocation into lmb..that is just 
> > > >> odd.
> > > >
> > > > It is not odd but necessary. Without it the Odroid C2 does not boot 
> > > > but
> > > > crashes.
> > > 
> > >  It's not Odroid C2, it's anything that with the bad luck to relocate
> > >  over the unprotected EFI structures.
> > > >>>
> > > >>> So can EFI use the lmb calls to reserve its memory? This patch is 
> > > >>> backwards.
> > > >>
> > > >> Simon, the EFI code can manage memory, LMB cannot.
> > > >>
> > > >> Every time something in U-Boot invokes LMB it recalculates reservations
> > > >> *ab initio*.
> > > >>
> > > >> You could use lib/efi_loader/efi_memory to replace LMB but not the 
> > > >> other
> > > >> way round.
> > > >>
> > > >> We should discard LMB and replace it by proper memory management.
> > > >
> > > > We have malloc() but in general this is not used (so far) except with
> > > > some parts of standard boot, and even there we are maintaining
> > > > compatibility with existing fdt_addr_r vars, etc.
> > >
> > > malloc() currently manages a portion of the memory defined by
> > > CONFIG_SYS_MALLOC_LEN. It cannot manage reserved memory. I don

Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Heinrich Schuchardt




On 1/11/23 23:59, Mark Kettenis wrote:

From: Simon Glass 
Date: Wed, 11 Jan 2023 14:08:27 -0700


Hi Simon,


Hi Heinrich,

On Wed, 11 Jan 2023 at 11:03, Heinrich Schuchardt
 wrote:




On 1/11/23 18:55, Simon Glass wrote:

Hi Heinrich,

On Wed, 11 Jan 2023 at 09:59, Heinrich Schuchardt
 wrote:




On 1/11/23 17:48, Simon Glass wrote:

Hi,

On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:


On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:



On 1/11/23 01:15, Simon Glass wrote:

Hi Heinrich,

On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
 wrote:




On 1/9/23 21:31, Simon Glass wrote:

Hi Mark,

On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  wrote:



From: Simon Glass 
Date: Mon, 9 Jan 2023 13:11:01 -0700

Hi Heinrich,


We need to fix how EFI does addresses. It seems to use them as
pointers but store them as u64 ?


That is similar to what you have been doing with physical addresses.



They're defined to a 64-bit unsigned integer by the UEFI
specification, so you can't change it.


I don't mean changing the spec, just changing the internal U-Boot
implementation, which is very confusing. This confusion is spreading
out, too.

Regards,
Simon


The real interesting thing is how memory should be managed in U-Boot:

I would prefer to create a shared global memory management on 4KiB page
level used both for EFI and the rest of U-Boot.


Sounds good.



What EFI adds to the requirements is that you need more than free
(EfiConventionalMemory) and used memory. EFI knows 16 different types of
memory usage (see enum efi_memory_type).


That's a shame. How much of this is legacy and how much is useful?



When loading a file (e.g. with the "load" command) this should lead to a
memory reservation. You should not be able to load a second file into an
overlapping memory area without releasing the allocated memory first.

This would replace lmb which currently tries to recalculate available
memory ab initio again and again.

With managed memory we should be able to get rid of all those constants
like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
register of named loaded files.


This is where standard boot comes in, since it knows what it has
loaded and has pointers to it.

I see a future where we don't use these commands when we want to save
space. It can save 300KB from the U-Boot size.

But this really has to come later, since there is so much churn already!

For now, please don't add EFI allocation into lmb..that is just odd.


It is not odd but necessary. Without it the Odroid C2 does not boot but
crashes.


It's not Odroid C2, it's anything that with the bad luck to relocate
over the unprotected EFI structures.


So can EFI use the lmb calls to reserve its memory? This patch is backwards.


Simon, the EFI code can manage memory, LMB cannot.

Every time something in U-Boot invokes LMB it recalculates reservations
*ab initio*.

You could use lib/efi_loader/efi_memory to replace LMB but not the other
way round.

We should discard LMB and replace it by proper memory management.


We have malloc() but in general this is not used (so far) except with
some parts of standard boot, and even there we are maintaining
compatibility with existing fdt_addr_r vars, etc.


malloc() currently manages a portion of the memory defined by
CONFIG_SYS_MALLOC_LEN. It cannot manage reserved memory. I don't know if
it can allocate from non-consecutive memory areas.


This depends on whether we do what you were talking about above, i.e.
get rid of the env vars and allocate things. One way to allocate would
be with malloc().


Almost certainly not a good idea.  There are all sorts of constraints
an things like the address where you load your kernel.  Something
like: "128M of memory, 2MB aligned not crossing a 1GB boundary".

Now *I* would argue that encoding the specific requirements of an OS
into U-Boot is the wrong approach to start with and that you're better
off having U-Boot load an OS-specific 2nd (or 3rd or 4th) stage loader
that loads the actual OS kernel.  Which is why providing an interface
like EFI that provides a lot of control over memory allocation is so
useful.


These 2nd stage boot loader are the EFI stubs of the different operating 
systems.


The non-EFI boot commands are used to call Linux' legacy entry point. We 
will have to manage the architecture specific rules in U-Boot. This 
requires a memory allocator to which we can pass an upper address and an 
alignment requirement.


Best regards

Heinrich




So what is the plan for this?


The next step should be a design document.


OK

Regards,
Simon



Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Mark Kettenis
> From: Simon Glass 
> Date: Wed, 11 Jan 2023 14:08:27 -0700

Hi Simon,

> Hi Heinrich,
> 
> On Wed, 11 Jan 2023 at 11:03, Heinrich Schuchardt
>  wrote:
> >
> >
> >
> > On 1/11/23 18:55, Simon Glass wrote:
> > > Hi Heinrich,
> > >
> > > On Wed, 11 Jan 2023 at 09:59, Heinrich Schuchardt
> > >  wrote:
> > >>
> > >>
> > >>
> > >> On 1/11/23 17:48, Simon Glass wrote:
> > >>> Hi,
> > >>>
> > >>> On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:
> > 
> >  On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:
> > >
> > >
> > > On 1/11/23 01:15, Simon Glass wrote:
> > >> Hi Heinrich,
> > >>
> > >> On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
> > >>  wrote:
> > >>>
> > >>>
> > >>>
> > >>> On 1/9/23 21:31, Simon Glass wrote:
> >  Hi Mark,
> > 
> >  On Mon, 9 Jan 2023 at 13:20, Mark Kettenis 
> >   wrote:
> > >
> > >> From: Simon Glass 
> > >> Date: Mon, 9 Jan 2023 13:11:01 -0700
> > >>
> > >> Hi Heinrich,
> > >>
> > >>
> > >> We need to fix how EFI does addresses. It seems to use them as
> > >> pointers but store them as u64 ?
> > >>>
> > >>> That is similar to what you have been doing with physical addresses.
> > >>>
> > >
> > > They're defined to a 64-bit unsigned integer by the UEFI
> > > specification, so you can't change it.
> > 
> >  I don't mean changing the spec, just changing the internal U-Boot
> >  implementation, which is very confusing. This confusion is 
> >  spreading
> >  out, too.
> > 
> >  Regards,
> >  Simon
> > >>>
> > >>> The real interesting thing is how memory should be managed in 
> > >>> U-Boot:
> > >>>
> > >>> I would prefer to create a shared global memory management on 4KiB 
> > >>> page
> > >>> level used both for EFI and the rest of U-Boot.
> > >>
> > >> Sounds good.
> > >>
> > >>>
> > >>> What EFI adds to the requirements is that you need more than free
> > >>> (EfiConventionalMemory) and used memory. EFI knows 16 different 
> > >>> types of
> > >>> memory usage (see enum efi_memory_type).
> > >>
> > >> That's a shame. How much of this is legacy and how much is useful?
> > >>
> > >>>
> > >>> When loading a file (e.g. with the "load" command) this should lead 
> > >>> to a
> > >>> memory reservation. You should not be able to load a second file 
> > >>> into an
> > >>> overlapping memory area without releasing the allocated memory 
> > >>> first.
> > >>>
> > >>> This would replace lmb which currently tries to recalculate 
> > >>> available
> > >>> memory ab initio again and again.
> > >>>
> > >>> With managed memory we should be able to get rid of all those 
> > >>> constants
> > >>> like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
> > >>> register of named loaded files.
> > >>
> > >> This is where standard boot comes in, since it knows what it has
> > >> loaded and has pointers to it.
> > >>
> > >> I see a future where we don't use these commands when we want to save
> > >> space. It can save 300KB from the U-Boot size.
> > >>
> > >> But this really has to come later, since there is so much churn 
> > >> already!
> > >>
> > >> For now, please don't add EFI allocation into lmb..that is just odd.
> > >
> > > It is not odd but necessary. Without it the Odroid C2 does not boot 
> > > but
> > > crashes.
> > 
> >  It's not Odroid C2, it's anything that with the bad luck to relocate
> >  over the unprotected EFI structures.
> > >>>
> > >>> So can EFI use the lmb calls to reserve its memory? This patch is 
> > >>> backwards.
> > >>
> > >> Simon, the EFI code can manage memory, LMB cannot.
> > >>
> > >> Every time something in U-Boot invokes LMB it recalculates reservations
> > >> *ab initio*.
> > >>
> > >> You could use lib/efi_loader/efi_memory to replace LMB but not the other
> > >> way round.
> > >>
> > >> We should discard LMB and replace it by proper memory management.
> > >
> > > We have malloc() but in general this is not used (so far) except with
> > > some parts of standard boot, and even there we are maintaining
> > > compatibility with existing fdt_addr_r vars, etc.
> >
> > malloc() currently manages a portion of the memory defined by
> > CONFIG_SYS_MALLOC_LEN. It cannot manage reserved memory. I don't know if
> > it can allocate from non-consecutive memory areas.
> 
> This depends on whether we do what you were talking about above, i.e.
> get rid of the env vars and allocate things. One way to allocate would
> be with malloc().

Almost certainly not a good idea.  There are all sorts of constraints
an things like the address where you load your kernel.  Something
like: "128M of memory, 2MB ali

Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Simon Glass
Hi Heinrich,

On Wed, 11 Jan 2023 at 11:03, Heinrich Schuchardt
 wrote:
>
>
>
> On 1/11/23 18:55, Simon Glass wrote:
> > Hi Heinrich,
> >
> > On Wed, 11 Jan 2023 at 09:59, Heinrich Schuchardt
> >  wrote:
> >>
> >>
> >>
> >> On 1/11/23 17:48, Simon Glass wrote:
> >>> Hi,
> >>>
> >>> On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:
> 
>  On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:
> >
> >
> > On 1/11/23 01:15, Simon Glass wrote:
> >> Hi Heinrich,
> >>
> >> On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
> >>  wrote:
> >>>
> >>>
> >>>
> >>> On 1/9/23 21:31, Simon Glass wrote:
>  Hi Mark,
> 
>  On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  
>  wrote:
> >
> >> From: Simon Glass 
> >> Date: Mon, 9 Jan 2023 13:11:01 -0700
> >>
> >> Hi Heinrich,
> >>
> >>
> >> We need to fix how EFI does addresses. It seems to use them as
> >> pointers but store them as u64 ?
> >>>
> >>> That is similar to what you have been doing with physical addresses.
> >>>
> >
> > They're defined to a 64-bit unsigned integer by the UEFI
> > specification, so you can't change it.
> 
>  I don't mean changing the spec, just changing the internal U-Boot
>  implementation, which is very confusing. This confusion is spreading
>  out, too.
> 
>  Regards,
>  Simon
> >>>
> >>> The real interesting thing is how memory should be managed in U-Boot:
> >>>
> >>> I would prefer to create a shared global memory management on 4KiB 
> >>> page
> >>> level used both for EFI and the rest of U-Boot.
> >>
> >> Sounds good.
> >>
> >>>
> >>> What EFI adds to the requirements is that you need more than free
> >>> (EfiConventionalMemory) and used memory. EFI knows 16 different types 
> >>> of
> >>> memory usage (see enum efi_memory_type).
> >>
> >> That's a shame. How much of this is legacy and how much is useful?
> >>
> >>>
> >>> When loading a file (e.g. with the "load" command) this should lead 
> >>> to a
> >>> memory reservation. You should not be able to load a second file into 
> >>> an
> >>> overlapping memory area without releasing the allocated memory first.
> >>>
> >>> This would replace lmb which currently tries to recalculate available
> >>> memory ab initio again and again.
> >>>
> >>> With managed memory we should be able to get rid of all those 
> >>> constants
> >>> like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
> >>> register of named loaded files.
> >>
> >> This is where standard boot comes in, since it knows what it has
> >> loaded and has pointers to it.
> >>
> >> I see a future where we don't use these commands when we want to save
> >> space. It can save 300KB from the U-Boot size.
> >>
> >> But this really has to come later, since there is so much churn 
> >> already!
> >>
> >> For now, please don't add EFI allocation into lmb..that is just odd.
> >
> > It is not odd but necessary. Without it the Odroid C2 does not boot but
> > crashes.
> 
>  It's not Odroid C2, it's anything that with the bad luck to relocate
>  over the unprotected EFI structures.
> >>>
> >>> So can EFI use the lmb calls to reserve its memory? This patch is 
> >>> backwards.
> >>
> >> Simon, the EFI code can manage memory, LMB cannot.
> >>
> >> Every time something in U-Boot invokes LMB it recalculates reservations
> >> *ab initio*.
> >>
> >> You could use lib/efi_loader/efi_memory to replace LMB but not the other
> >> way round.
> >>
> >> We should discard LMB and replace it by proper memory management.
> >
> > We have malloc() but in general this is not used (so far) except with
> > some parts of standard boot, and even there we are maintaining
> > compatibility with existing fdt_addr_r vars, etc.
>
> malloc() currently manages a portion of the memory defined by
> CONFIG_SYS_MALLOC_LEN. It cannot manage reserved memory. I don't know if
> it can allocate from non-consecutive memory areas.

This depends on whether we do what you were talking about above, i.e.
get rid of the env vars and allocate things. One way to allocate would
be with malloc().

>
> >
> > So what is the plan for this?
>
> The next step should be a design document.

OK

Regards,
Simon


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Heinrich Schuchardt




On 1/11/23 18:55, Simon Glass wrote:

Hi Heinrich,

On Wed, 11 Jan 2023 at 09:59, Heinrich Schuchardt
 wrote:




On 1/11/23 17:48, Simon Glass wrote:

Hi,

On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:


On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:



On 1/11/23 01:15, Simon Glass wrote:

Hi Heinrich,

On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
 wrote:




On 1/9/23 21:31, Simon Glass wrote:

Hi Mark,

On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  wrote:



From: Simon Glass 
Date: Mon, 9 Jan 2023 13:11:01 -0700

Hi Heinrich,


We need to fix how EFI does addresses. It seems to use them as
pointers but store them as u64 ?


That is similar to what you have been doing with physical addresses.



They're defined to a 64-bit unsigned integer by the UEFI
specification, so you can't change it.


I don't mean changing the spec, just changing the internal U-Boot
implementation, which is very confusing. This confusion is spreading
out, too.

Regards,
Simon


The real interesting thing is how memory should be managed in U-Boot:

I would prefer to create a shared global memory management on 4KiB page
level used both for EFI and the rest of U-Boot.


Sounds good.



What EFI adds to the requirements is that you need more than free
(EfiConventionalMemory) and used memory. EFI knows 16 different types of
memory usage (see enum efi_memory_type).


That's a shame. How much of this is legacy and how much is useful?



When loading a file (e.g. with the "load" command) this should lead to a
memory reservation. You should not be able to load a second file into an
overlapping memory area without releasing the allocated memory first.

This would replace lmb which currently tries to recalculate available
memory ab initio again and again.

With managed memory we should be able to get rid of all those constants
like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
register of named loaded files.


This is where standard boot comes in, since it knows what it has
loaded and has pointers to it.

I see a future where we don't use these commands when we want to save
space. It can save 300KB from the U-Boot size.

But this really has to come later, since there is so much churn already!

For now, please don't add EFI allocation into lmb..that is just odd.


It is not odd but necessary. Without it the Odroid C2 does not boot but
crashes.


It's not Odroid C2, it's anything that with the bad luck to relocate
over the unprotected EFI structures.


So can EFI use the lmb calls to reserve its memory? This patch is backwards.


Simon, the EFI code can manage memory, LMB cannot.

Every time something in U-Boot invokes LMB it recalculates reservations
*ab initio*.

You could use lib/efi_loader/efi_memory to replace LMB but not the other
way round.

We should discard LMB and replace it by proper memory management.


We have malloc() but in general this is not used (so far) except with
some parts of standard boot, and even there we are maintaining
compatibility with existing fdt_addr_r vars, etc.


malloc() currently manages a portion of the memory defined by 
CONFIG_SYS_MALLOC_LEN. It cannot manage reserved memory. I don't know if 
it can allocate from non-consecutive memory areas.




So what is the plan for this?


The next step should be a design document.

Best regards

Heinrich


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Simon Glass
Hi Heinrich,

On Wed, 11 Jan 2023 at 09:59, Heinrich Schuchardt
 wrote:
>
>
>
> On 1/11/23 17:48, Simon Glass wrote:
> > Hi,
> >
> > On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:
> >>
> >> On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:
> >>>
> >>>
> >>> On 1/11/23 01:15, Simon Glass wrote:
>  Hi Heinrich,
> 
>  On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
>   wrote:
> >
> >
> >
> > On 1/9/23 21:31, Simon Glass wrote:
> >> Hi Mark,
> >>
> >> On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  
> >> wrote:
> >>>
>  From: Simon Glass 
>  Date: Mon, 9 Jan 2023 13:11:01 -0700
> 
>  Hi Heinrich,
> 
> 
>  We need to fix how EFI does addresses. It seems to use them as
>  pointers but store them as u64 ?
> >
> > That is similar to what you have been doing with physical addresses.
> >
> >>>
> >>> They're defined to a 64-bit unsigned integer by the UEFI
> >>> specification, so you can't change it.
> >>
> >> I don't mean changing the spec, just changing the internal U-Boot
> >> implementation, which is very confusing. This confusion is spreading
> >> out, too.
> >>
> >> Regards,
> >> Simon
> >
> > The real interesting thing is how memory should be managed in U-Boot:
> >
> > I would prefer to create a shared global memory management on 4KiB page
> > level used both for EFI and the rest of U-Boot.
> 
>  Sounds good.
> 
> >
> > What EFI adds to the requirements is that you need more than free
> > (EfiConventionalMemory) and used memory. EFI knows 16 different types of
> > memory usage (see enum efi_memory_type).
> 
>  That's a shame. How much of this is legacy and how much is useful?
> 
> >
> > When loading a file (e.g. with the "load" command) this should lead to a
> > memory reservation. You should not be able to load a second file into an
> > overlapping memory area without releasing the allocated memory first.
> >
> > This would replace lmb which currently tries to recalculate available
> > memory ab initio again and again.
> >
> > With managed memory we should be able to get rid of all those constants
> > like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
> > register of named loaded files.
> 
>  This is where standard boot comes in, since it knows what it has
>  loaded and has pointers to it.
> 
>  I see a future where we don't use these commands when we want to save
>  space. It can save 300KB from the U-Boot size.
> 
>  But this really has to come later, since there is so much churn already!
> 
>  For now, please don't add EFI allocation into lmb..that is just odd.
> >>>
> >>> It is not odd but necessary. Without it the Odroid C2 does not boot but
> >>> crashes.
> >>
> >> It's not Odroid C2, it's anything that with the bad luck to relocate
> >> over the unprotected EFI structures.
> >
> > So can EFI use the lmb calls to reserve its memory? This patch is backwards.
>
> Simon, the EFI code can manage memory, LMB cannot.
>
> Every time something in U-Boot invokes LMB it recalculates reservations
> *ab initio*.
>
> You could use lib/efi_loader/efi_memory to replace LMB but not the other
> way round.
>
> We should discard LMB and replace it by proper memory management.

We have malloc() but in general this is not used (so far) except with
some parts of standard boot, and even there we are maintaining
compatibility with existing fdt_addr_r vars, etc.

So what is the plan for this?

Reviewed-by: Simon Glass 

Regards,
Simon


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Heinrich Schuchardt




On 1/11/23 18:40, Mark Kettenis wrote:

Date: Wed, 11 Jan 2023 17:59:27 +0100
From: Heinrich Schuchardt 

On 1/11/23 17:48, Simon Glass wrote:

Hi,

On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:


On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:



On 1/11/23 01:15, Simon Glass wrote:

Hi Heinrich,

On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
 wrote:




On 1/9/23 21:31, Simon Glass wrote:

Hi Mark,

On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  wrote:



From: Simon Glass 
Date: Mon, 9 Jan 2023 13:11:01 -0700

Hi Heinrich,


We need to fix how EFI does addresses. It seems to use them as
pointers but store them as u64 ?


That is similar to what you have been doing with physical addresses.



They're defined to a 64-bit unsigned integer by the UEFI
specification, so you can't change it.


I don't mean changing the spec, just changing the internal U-Boot
implementation, which is very confusing. This confusion is spreading
out, too.

Regards,
Simon


The real interesting thing is how memory should be managed in U-Boot:

I would prefer to create a shared global memory management on 4KiB page
level used both for EFI and the rest of U-Boot.


Sounds good.



What EFI adds to the requirements is that you need more than free
(EfiConventionalMemory) and used memory. EFI knows 16 different types of
memory usage (see enum efi_memory_type).


That's a shame. How much of this is legacy and how much is useful?



When loading a file (e.g. with the "load" command) this should lead to a
memory reservation. You should not be able to load a second file into an
overlapping memory area without releasing the allocated memory first.

This would replace lmb which currently tries to recalculate available
memory ab initio again and again.

With managed memory we should be able to get rid of all those constants
like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
register of named loaded files.


This is where standard boot comes in, since it knows what it has
loaded and has pointers to it.

I see a future where we don't use these commands when we want to save
space. It can save 300KB from the U-Boot size.

But this really has to come later, since there is so much churn already!

For now, please don't add EFI allocation into lmb..that is just odd.


It is not odd but necessary. Without it the Odroid C2 does not boot but
crashes.


It's not Odroid C2, it's anything that with the bad luck to relocate
over the unprotected EFI structures.


So can EFI use the lmb calls to reserve its memory? This patch is backwards.


Simon, the EFI code can manage memory, LMB cannot.

Every time something in U-Boot invokes LMB it recalculates reservations
*ab initio*.

You could use lib/efi_loader/efi_memory to replace LMB but not the other
way round.

We should discard LMB and replace it by proper memory management.


Actually LMB is fine.  It is the way it is used in U-Boot, where
subsystems each have their own struct lmb that is the problem.


That is what I meant with 'ab initio'.

LMB cannot replace EFIs memory management because in EFI we have more 
memory types than only free and reserved.


Having a limit on the number of  memory regions (CONFIG_LMB_MAX_REGIONS 
= 8 by default) is also a no-go for EFI.


Best regards

Heinrich



Also note that I'm using LMB in a upcoming patch for the Apple DART
IOMMU to manage device virtual addresses.  In that case having a a
separate struct lmb actually makes sense since the device virtual
address spaces are completely separate from eachother and from the
physical address space.  So don't remove it just yet ;).


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Mark Kettenis
> Date: Wed, 11 Jan 2023 17:59:27 +0100
> From: Heinrich Schuchardt 
> 
> On 1/11/23 17:48, Simon Glass wrote:
> > Hi,
> > 
> > On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:
> >>
> >> On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:
> >>>
> >>>
> >>> On 1/11/23 01:15, Simon Glass wrote:
>  Hi Heinrich,
> 
>  On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
>   wrote:
> >
> >
> >
> > On 1/9/23 21:31, Simon Glass wrote:
> >> Hi Mark,
> >>
> >> On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  
> >> wrote:
> >>>
>  From: Simon Glass 
>  Date: Mon, 9 Jan 2023 13:11:01 -0700
> 
>  Hi Heinrich,
> 
> 
>  We need to fix how EFI does addresses. It seems to use them as
>  pointers but store them as u64 ?
> >
> > That is similar to what you have been doing with physical addresses.
> >
> >>>
> >>> They're defined to a 64-bit unsigned integer by the UEFI
> >>> specification, so you can't change it.
> >>
> >> I don't mean changing the spec, just changing the internal U-Boot
> >> implementation, which is very confusing. This confusion is spreading
> >> out, too.
> >>
> >> Regards,
> >> Simon
> >
> > The real interesting thing is how memory should be managed in U-Boot:
> >
> > I would prefer to create a shared global memory management on 4KiB page
> > level used both for EFI and the rest of U-Boot.
> 
>  Sounds good.
> 
> >
> > What EFI adds to the requirements is that you need more than free
> > (EfiConventionalMemory) and used memory. EFI knows 16 different types of
> > memory usage (see enum efi_memory_type).
> 
>  That's a shame. How much of this is legacy and how much is useful?
> 
> >
> > When loading a file (e.g. with the "load" command) this should lead to a
> > memory reservation. You should not be able to load a second file into an
> > overlapping memory area without releasing the allocated memory first.
> >
> > This would replace lmb which currently tries to recalculate available
> > memory ab initio again and again.
> >
> > With managed memory we should be able to get rid of all those constants
> > like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
> > register of named loaded files.
> 
>  This is where standard boot comes in, since it knows what it has
>  loaded and has pointers to it.
> 
>  I see a future where we don't use these commands when we want to save
>  space. It can save 300KB from the U-Boot size.
> 
>  But this really has to come later, since there is so much churn already!
> 
>  For now, please don't add EFI allocation into lmb..that is just odd.
> >>>
> >>> It is not odd but necessary. Without it the Odroid C2 does not boot but
> >>> crashes.
> >>
> >> It's not Odroid C2, it's anything that with the bad luck to relocate
> >> over the unprotected EFI structures.
> > 
> > So can EFI use the lmb calls to reserve its memory? This patch is backwards.
> 
> Simon, the EFI code can manage memory, LMB cannot.
> 
> Every time something in U-Boot invokes LMB it recalculates reservations 
> *ab initio*.
> 
> You could use lib/efi_loader/efi_memory to replace LMB but not the other 
> way round.
> 
> We should discard LMB and replace it by proper memory management.

Actually LMB is fine.  It is the way it is used in U-Boot, where
subsystems each have their own struct lmb that is the problem.

Also note that I'm using LMB in a upcoming patch for the Apple DART
IOMMU to manage device virtual addresses.  In that case having a a
separate struct lmb actually makes sense since the device virtual
address spaces are completely separate from eachother and from the
physical address space.  So don't remove it just yet ;).


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Heinrich Schuchardt




On 1/11/23 17:48, Simon Glass wrote:

Hi,

On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:


On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:



On 1/11/23 01:15, Simon Glass wrote:

Hi Heinrich,

On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
 wrote:




On 1/9/23 21:31, Simon Glass wrote:

Hi Mark,

On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  wrote:



From: Simon Glass 
Date: Mon, 9 Jan 2023 13:11:01 -0700

Hi Heinrich,


We need to fix how EFI does addresses. It seems to use them as
pointers but store them as u64 ?


That is similar to what you have been doing with physical addresses.



They're defined to a 64-bit unsigned integer by the UEFI
specification, so you can't change it.


I don't mean changing the spec, just changing the internal U-Boot
implementation, which is very confusing. This confusion is spreading
out, too.

Regards,
Simon


The real interesting thing is how memory should be managed in U-Boot:

I would prefer to create a shared global memory management on 4KiB page
level used both for EFI and the rest of U-Boot.


Sounds good.



What EFI adds to the requirements is that you need more than free
(EfiConventionalMemory) and used memory. EFI knows 16 different types of
memory usage (see enum efi_memory_type).


That's a shame. How much of this is legacy and how much is useful?



When loading a file (e.g. with the "load" command) this should lead to a
memory reservation. You should not be able to load a second file into an
overlapping memory area without releasing the allocated memory first.

This would replace lmb which currently tries to recalculate available
memory ab initio again and again.

With managed memory we should be able to get rid of all those constants
like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
register of named loaded files.


This is where standard boot comes in, since it knows what it has
loaded and has pointers to it.

I see a future where we don't use these commands when we want to save
space. It can save 300KB from the U-Boot size.

But this really has to come later, since there is so much churn already!

For now, please don't add EFI allocation into lmb..that is just odd.


It is not odd but necessary. Without it the Odroid C2 does not boot but
crashes.


It's not Odroid C2, it's anything that with the bad luck to relocate
over the unprotected EFI structures.


So can EFI use the lmb calls to reserve its memory? This patch is backwards.


Simon, the EFI code can manage memory, LMB cannot.

Every time something in U-Boot invokes LMB it recalculates reservations 
*ab initio*.


You could use lib/efi_loader/efi_memory to replace LMB but not the other 
way round.


We should discard LMB and replace it by proper memory management.

Best regards

Heinrich


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Simon Glass
Hi,

On Wed, 11 Jan 2023 at 06:59, Tom Rini  wrote:
>
> On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:
> >
> >
> > On 1/11/23 01:15, Simon Glass wrote:
> > > Hi Heinrich,
> > >
> > > On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
> > >  wrote:
> > > >
> > > >
> > > >
> > > > On 1/9/23 21:31, Simon Glass wrote:
> > > > > Hi Mark,
> > > > >
> > > > > On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  
> > > > > wrote:
> > > > > >
> > > > > > > From: Simon Glass 
> > > > > > > Date: Mon, 9 Jan 2023 13:11:01 -0700
> > > > > > >
> > > > > > > Hi Heinrich,
> > > > > > >
> > > > > > >
> > > > > > > We need to fix how EFI does addresses. It seems to use them as
> > > > > > > pointers but store them as u64 ?
> > > >
> > > > That is similar to what you have been doing with physical addresses.
> > > >
> > > > > >
> > > > > > They're defined to a 64-bit unsigned integer by the UEFI
> > > > > > specification, so you can't change it.
> > > > >
> > > > > I don't mean changing the spec, just changing the internal U-Boot
> > > > > implementation, which is very confusing. This confusion is spreading
> > > > > out, too.
> > > > >
> > > > > Regards,
> > > > > Simon
> > > >
> > > > The real interesting thing is how memory should be managed in U-Boot:
> > > >
> > > > I would prefer to create a shared global memory management on 4KiB page
> > > > level used both for EFI and the rest of U-Boot.
> > >
> > > Sounds good.
> > >
> > > >
> > > > What EFI adds to the requirements is that you need more than free
> > > > (EfiConventionalMemory) and used memory. EFI knows 16 different types of
> > > > memory usage (see enum efi_memory_type).
> > >
> > > That's a shame. How much of this is legacy and how much is useful?
> > >
> > > >
> > > > When loading a file (e.g. with the "load" command) this should lead to a
> > > > memory reservation. You should not be able to load a second file into an
> > > > overlapping memory area without releasing the allocated memory first.
> > > >
> > > > This would replace lmb which currently tries to recalculate available
> > > > memory ab initio again and again.
> > > >
> > > > With managed memory we should be able to get rid of all those constants
> > > > like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
> > > > register of named loaded files.
> > >
> > > This is where standard boot comes in, since it knows what it has
> > > loaded and has pointers to it.
> > >
> > > I see a future where we don't use these commands when we want to save
> > > space. It can save 300KB from the U-Boot size.
> > >
> > > But this really has to come later, since there is so much churn already!
> > >
> > > For now, please don't add EFI allocation into lmb..that is just odd.
> >
> > It is not odd but necessary. Without it the Odroid C2 does not boot but
> > crashes.
>
> It's not Odroid C2, it's anything that with the bad luck to relocate
> over the unprotected EFI structures.

So can EFI use the lmb calls to reserve its memory? This patch is backwards.

Regards,
Simon

>
> --
> Tom


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-11 Thread Tom Rini
On Wed, Jan 11, 2023 at 08:43:37AM +0100, Heinrich Schuchardt wrote:
> 
> 
> On 1/11/23 01:15, Simon Glass wrote:
> > Hi Heinrich,
> > 
> > On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
> >  wrote:
> > > 
> > > 
> > > 
> > > On 1/9/23 21:31, Simon Glass wrote:
> > > > Hi Mark,
> > > > 
> > > > On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  
> > > > wrote:
> > > > > 
> > > > > > From: Simon Glass 
> > > > > > Date: Mon, 9 Jan 2023 13:11:01 -0700
> > > > > > 
> > > > > > Hi Heinrich,
> > > > > > 
> > > > > > 
> > > > > > We need to fix how EFI does addresses. It seems to use them as
> > > > > > pointers but store them as u64 ?
> > > 
> > > That is similar to what you have been doing with physical addresses.
> > > 
> > > > > 
> > > > > They're defined to a 64-bit unsigned integer by the UEFI
> > > > > specification, so you can't change it.
> > > > 
> > > > I don't mean changing the spec, just changing the internal U-Boot
> > > > implementation, which is very confusing. This confusion is spreading
> > > > out, too.
> > > > 
> > > > Regards,
> > > > Simon
> > > 
> > > The real interesting thing is how memory should be managed in U-Boot:
> > > 
> > > I would prefer to create a shared global memory management on 4KiB page
> > > level used both for EFI and the rest of U-Boot.
> > 
> > Sounds good.
> > 
> > > 
> > > What EFI adds to the requirements is that you need more than free
> > > (EfiConventionalMemory) and used memory. EFI knows 16 different types of
> > > memory usage (see enum efi_memory_type).
> > 
> > That's a shame. How much of this is legacy and how much is useful?
> > 
> > > 
> > > When loading a file (e.g. with the "load" command) this should lead to a
> > > memory reservation. You should not be able to load a second file into an
> > > overlapping memory area without releasing the allocated memory first.
> > > 
> > > This would replace lmb which currently tries to recalculate available
> > > memory ab initio again and again.
> > > 
> > > With managed memory we should be able to get rid of all those constants
> > > like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
> > > register of named loaded files.
> > 
> > This is where standard boot comes in, since it knows what it has
> > loaded and has pointers to it.
> > 
> > I see a future where we don't use these commands when we want to save
> > space. It can save 300KB from the U-Boot size.
> > 
> > But this really has to come later, since there is so much churn already!
> > 
> > For now, please don't add EFI allocation into lmb..that is just odd.
> 
> It is not odd but necessary. Without it the Odroid C2 does not boot but
> crashes.

It's not Odroid C2, it's anything that with the bad luck to relocate
over the unprotected EFI structures.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-10 Thread Heinrich Schuchardt




On 1/11/23 01:15, Simon Glass wrote:

Hi Heinrich,

On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
 wrote:




On 1/9/23 21:31, Simon Glass wrote:

Hi Mark,

On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  wrote:



From: Simon Glass 
Date: Mon, 9 Jan 2023 13:11:01 -0700

Hi Heinrich,


We need to fix how EFI does addresses. It seems to use them as
pointers but store them as u64 ?


That is similar to what you have been doing with physical addresses.



They're defined to a 64-bit unsigned integer by the UEFI
specification, so you can't change it.


I don't mean changing the spec, just changing the internal U-Boot
implementation, which is very confusing. This confusion is spreading
out, too.

Regards,
Simon


The real interesting thing is how memory should be managed in U-Boot:

I would prefer to create a shared global memory management on 4KiB page
level used both for EFI and the rest of U-Boot.


Sounds good.



What EFI adds to the requirements is that you need more than free
(EfiConventionalMemory) and used memory. EFI knows 16 different types of
memory usage (see enum efi_memory_type).


That's a shame. How much of this is legacy and how much is useful?



When loading a file (e.g. with the "load" command) this should lead to a
memory reservation. You should not be able to load a second file into an
overlapping memory area without releasing the allocated memory first.

This would replace lmb which currently tries to recalculate available
memory ab initio again and again.

With managed memory we should be able to get rid of all those constants
like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
register of named loaded files.


This is where standard boot comes in, since it knows what it has
loaded and has pointers to it.

I see a future where we don't use these commands when we want to save
space. It can save 300KB from the U-Boot size.

But this really has to come later, since there is so much churn already!

For now, please don't add EFI allocation into lmb..that is just odd.


It is not odd but necessary. Without it the Odroid C2 does not boot but 
crashes.


Best regards

Heinrich


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-10 Thread Simon Glass
Hi Heinrich,

On Mon, 9 Jan 2023 at 13:53, Heinrich Schuchardt
 wrote:
>
>
>
> On 1/9/23 21:31, Simon Glass wrote:
> > Hi Mark,
> >
> > On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  wrote:
> >>
> >>> From: Simon Glass 
> >>> Date: Mon, 9 Jan 2023 13:11:01 -0700
> >>>
> >>> Hi Heinrich,
> >>>
> >>>
> >>> We need to fix how EFI does addresses. It seems to use them as
> >>> pointers but store them as u64 ?
>
> That is similar to what you have been doing with physical addresses.
>
> >>
> >> They're defined to a 64-bit unsigned integer by the UEFI
> >> specification, so you can't change it.
> >
> > I don't mean changing the spec, just changing the internal U-Boot
> > implementation, which is very confusing. This confusion is spreading
> > out, too.
> >
> > Regards,
> > Simon
>
> The real interesting thing is how memory should be managed in U-Boot:
>
> I would prefer to create a shared global memory management on 4KiB page
> level used both for EFI and the rest of U-Boot.

Sounds good.

>
> What EFI adds to the requirements is that you need more than free
> (EfiConventionalMemory) and used memory. EFI knows 16 different types of
> memory usage (see enum efi_memory_type).

That's a shame. How much of this is legacy and how much is useful?

>
> When loading a file (e.g. with the "load" command) this should lead to a
> memory reservation. You should not be able to load a second file into an
> overlapping memory area without releasing the allocated memory first.
>
> This would replace lmb which currently tries to recalculate available
> memory ab initio again and again.
>
> With managed memory we should be able to get rid of all those constants
> like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a
> register of named loaded files.

This is where standard boot comes in, since it knows what it has
loaded and has pointers to it.

I see a future where we don't use these commands when we want to save
space. It can save 300KB from the U-Boot size.

But this really has to come later, since there is so much churn already!

For now, please don't add EFI allocation into lmb..that is just odd.

Regards,
Simon


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-09 Thread Heinrich Schuchardt




On 1/9/23 21:31, Simon Glass wrote:

Hi Mark,

On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  wrote:



From: Simon Glass 
Date: Mon, 9 Jan 2023 13:11:01 -0700

Hi Heinrich,


We need to fix how EFI does addresses. It seems to use them as
pointers but store them as u64 ?


That is similar to what you have been doing with physical addresses.



They're defined to a 64-bit unsigned integer by the UEFI
specification, so you can't change it.


I don't mean changing the spec, just changing the internal U-Boot
implementation, which is very confusing. This confusion is spreading
out, too.

Regards,
Simon


The real interesting thing is how memory should be managed in U-Boot:

I would prefer to create a shared global memory management on 4KiB page 
level used both for EFI and the rest of U-Boot.


What EFI adds to the requirements is that you need more than free 
(EfiConventionalMemory) and used memory. EFI knows 16 different types of 
memory usage (see enum efi_memory_type).


When loading a file (e.g. with the "load" command) this should lead to a 
memory reservation. You should not be able to load a second file into an 
overlapping memory area without releasing the allocated memory first.


This would replace lmb which currently tries to recalculate available 
memory ab initio again and again.


With managed memory we should be able to get rid of all those constants 
like $loadaddr, $fdt_addr_r, $kernel_addr_r, etc. and instead use a 
register of named loaded files.


Best regards

Heinrich


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-09 Thread Simon Glass
Hi Mark,

On Mon, 9 Jan 2023 at 13:20, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Mon, 9 Jan 2023 13:11:01 -0700
> >
> > Hi Heinrich,
> >
> > On Thu, 5 Jan 2023 at 13:25, Heinrich Schuchardt
> >  wrote:
> > >
> > > Add reservations for all EFI memory areas that are not
> > > EFI_CONVENTIONAL_MEMORY.
> > >
> > > Signed-off-by: Heinrich Schuchardt 
> > > ---
> > > v2:
> > > use efi_get_memory_map_alloc()
> > > ---
> > >  lib/lmb.c | 36 
> > >  1 file changed, 36 insertions(+)
> > >
> > > diff --git a/lib/lmb.c b/lib/lmb.c
> > > index c599608fa3..ec790760db 100644
> > > --- a/lib/lmb.c
> > > +++ b/lib/lmb.c
> > > @@ -7,7 +7,9 @@
> > >   */
> > >
> > >  #include 
> > > +#include 
> > >  #include 
> > > +#include 
> > >  #include 
> > >  #include 
> > >  #include 
> > > @@ -153,6 +155,37 @@ void arch_lmb_reserve_generic(struct lmb *lmb, ulong 
> > > sp, ulong end, ulong align)
> > > }
> > >  }
> > >
> > > +/**
> > > + * efi_lmb_reserve() - add reservations for EFI memory
> > > + *
> > > + * Add reservations for all EFI memory areas that are not
> > > + * EFI_CONVENTIONAL_MEMORY.
> > > + *
> > > + * @lmb:   lmb environment
> > > + * Return: 0 on success, 1 on failure
> > > + */
> > > +static __maybe_unused int efi_lmb_reserve(struct lmb *lmb)
> > > +{
> > > +   struct efi_mem_desc *memmap = NULL, *map;
> > > +   efi_uintn_t i, map_size = 0;
> > > +   efi_status_t ret;
> > > +
> > > +   ret = efi_get_memory_map_alloc(&map_size, &memmap);
> > > +   if (ret != EFI_SUCCESS)
> > > +   return 1;
> > > +
> > > +   for (i = 0, map = memmap; i < map_size / sizeof(*map); ++map, 
> > > ++i) {
> > > +   if (map->type != EFI_CONVENTIONAL_MEMORY)
> > > +   lmb_reserve(lmb,
> > > +   map_to_sysmem((void *)(uintptr_t)
> > > + map->physical_start),
> >
> > We need to fix how EFI does addresses. It seems to use them as
> > pointers but store them as u64 ?
>
> They're defined to a 64-bit unsigned integer by the UEFI
> specification, so you can't change it.

I don't mean changing the spec, just changing the internal U-Boot
implementation, which is very confusing. This confusion is spreading
out, too.

Regards,
Simon


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-09 Thread Mark Kettenis
> From: Simon Glass 
> Date: Mon, 9 Jan 2023 13:11:01 -0700
> 
> Hi Heinrich,
> 
> On Thu, 5 Jan 2023 at 13:25, Heinrich Schuchardt
>  wrote:
> >
> > Add reservations for all EFI memory areas that are not
> > EFI_CONVENTIONAL_MEMORY.
> >
> > Signed-off-by: Heinrich Schuchardt 
> > ---
> > v2:
> > use efi_get_memory_map_alloc()
> > ---
> >  lib/lmb.c | 36 
> >  1 file changed, 36 insertions(+)
> >
> > diff --git a/lib/lmb.c b/lib/lmb.c
> > index c599608fa3..ec790760db 100644
> > --- a/lib/lmb.c
> > +++ b/lib/lmb.c
> > @@ -7,7 +7,9 @@
> >   */
> >
> >  #include 
> > +#include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -153,6 +155,37 @@ void arch_lmb_reserve_generic(struct lmb *lmb, ulong 
> > sp, ulong end, ulong align)
> > }
> >  }
> >
> > +/**
> > + * efi_lmb_reserve() - add reservations for EFI memory
> > + *
> > + * Add reservations for all EFI memory areas that are not
> > + * EFI_CONVENTIONAL_MEMORY.
> > + *
> > + * @lmb:   lmb environment
> > + * Return: 0 on success, 1 on failure
> > + */
> > +static __maybe_unused int efi_lmb_reserve(struct lmb *lmb)
> > +{
> > +   struct efi_mem_desc *memmap = NULL, *map;
> > +   efi_uintn_t i, map_size = 0;
> > +   efi_status_t ret;
> > +
> > +   ret = efi_get_memory_map_alloc(&map_size, &memmap);
> > +   if (ret != EFI_SUCCESS)
> > +   return 1;
> > +
> > +   for (i = 0, map = memmap; i < map_size / sizeof(*map); ++map, ++i) {
> > +   if (map->type != EFI_CONVENTIONAL_MEMORY)
> > +   lmb_reserve(lmb,
> > +   map_to_sysmem((void *)(uintptr_t)
> > + map->physical_start),
> 
> We need to fix how EFI does addresses. It seems to use them as
> pointers but store them as u64 ?

They're defined to a 64-bit unsigned integer by the UEFI
specification, so you can't change it.


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-09 Thread Simon Glass
Hi Heinrich,

On Thu, 5 Jan 2023 at 13:25, Heinrich Schuchardt
 wrote:
>
> Add reservations for all EFI memory areas that are not
> EFI_CONVENTIONAL_MEMORY.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
> use efi_get_memory_map_alloc()
> ---
>  lib/lmb.c | 36 
>  1 file changed, 36 insertions(+)
>
> diff --git a/lib/lmb.c b/lib/lmb.c
> index c599608fa3..ec790760db 100644
> --- a/lib/lmb.c
> +++ b/lib/lmb.c
> @@ -7,7 +7,9 @@
>   */
>
>  #include 
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -153,6 +155,37 @@ void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, 
> ulong end, ulong align)
> }
>  }
>
> +/**
> + * efi_lmb_reserve() - add reservations for EFI memory
> + *
> + * Add reservations for all EFI memory areas that are not
> + * EFI_CONVENTIONAL_MEMORY.
> + *
> + * @lmb:   lmb environment
> + * Return: 0 on success, 1 on failure
> + */
> +static __maybe_unused int efi_lmb_reserve(struct lmb *lmb)
> +{
> +   struct efi_mem_desc *memmap = NULL, *map;
> +   efi_uintn_t i, map_size = 0;
> +   efi_status_t ret;
> +
> +   ret = efi_get_memory_map_alloc(&map_size, &memmap);
> +   if (ret != EFI_SUCCESS)
> +   return 1;
> +
> +   for (i = 0, map = memmap; i < map_size / sizeof(*map); ++map, ++i) {
> +   if (map->type != EFI_CONVENTIONAL_MEMORY)
> +   lmb_reserve(lmb,
> +   map_to_sysmem((void *)(uintptr_t)
> + map->physical_start),

We need to fix how EFI does addresses. It seems to use them as
pointers but store them as u64 ?

> +   map->num_pages * EFI_PAGE_SIZE);
> +   }
> +   efi_free_pool(memmap);
> +
> +   return 0;
> +}
> +
>  static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
>  {
> arch_lmb_reserve(lmb);
> @@ -160,6 +193,9 @@ static void lmb_reserve_common(struct lmb *lmb, void 
> *fdt_blob)
>
> if (CONFIG_IS_ENABLED(OF_LIBFDT) && fdt_blob)
> boot_fdt_add_mem_rsv_regions(lmb, fdt_blob);
> +
> +   if (CONFIG_IS_ENABLED(EFI_LOADER))

This sort of thing puts EFI code into the LMB thing. Instead, EFI
should provide the memory map to LMB so it can do the right thing.

Here you are not just reserving things, but actually doing an EFI allocation!??

> +   efi_lmb_reserve(lmb);
>  }
>
>  /* Initialize the struct, add memory and call arch/board reserve functions */
> --
> 2.37.2
>

Regards,
Simon


Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-08 Thread Ilias Apalodimas
On Thu, Jan 05, 2023 at 09:25:36PM +0100, Heinrich Schuchardt wrote:
> Add reservations for all EFI memory areas that are not
> EFI_CONVENTIONAL_MEMORY.
> 
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
>   use efi_get_memory_map_alloc()
> ---
>  lib/lmb.c | 36 
>  1 file changed, 36 insertions(+)
> 
> diff --git a/lib/lmb.c b/lib/lmb.c
> index c599608fa3..ec790760db 100644
> --- a/lib/lmb.c
> +++ b/lib/lmb.c
> @@ -7,7 +7,9 @@
>   */
>  
>  #include 
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -153,6 +155,37 @@ void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, 
> ulong end, ulong align)
>   }
>  }
>  
> +/**
> + * efi_lmb_reserve() - add reservations for EFI memory
> + *
> + * Add reservations for all EFI memory areas that are not
> + * EFI_CONVENTIONAL_MEMORY.
> + *
> + * @lmb: lmb environment
> + * Return:   0 on success, 1 on failure
> + */
> +static __maybe_unused int efi_lmb_reserve(struct lmb *lmb)
> +{
> + struct efi_mem_desc *memmap = NULL, *map;
> + efi_uintn_t i, map_size = 0;
> + efi_status_t ret;
> +
> + ret = efi_get_memory_map_alloc(&map_size, &memmap);
> + if (ret != EFI_SUCCESS)
> + return 1;
> +
> + for (i = 0, map = memmap; i < map_size / sizeof(*map); ++map, ++i) {
> + if (map->type != EFI_CONVENTIONAL_MEMORY)
> + lmb_reserve(lmb,
> + map_to_sysmem((void *)(uintptr_t)
> +   map->physical_start),
> + map->num_pages * EFI_PAGE_SIZE);
> + }
> + efi_free_pool(memmap);
> +
> + return 0;
> +}
> +
>  static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
>  {
>   arch_lmb_reserve(lmb);
> @@ -160,6 +193,9 @@ static void lmb_reserve_common(struct lmb *lmb, void 
> *fdt_blob)
>  
>   if (CONFIG_IS_ENABLED(OF_LIBFDT) && fdt_blob)
>   boot_fdt_add_mem_rsv_regions(lmb, fdt_blob);
> +
> + if (CONFIG_IS_ENABLED(EFI_LOADER))
> + efi_lmb_reserve(lmb);
>  }
>  
>  /* Initialize the struct, add memory and call arch/board reserve functions */
> -- 
> 2.37.2
> 
Reviewed-by: Ilias Apalodimas 



Re: [PATCH v2 3/3] lmb: consider EFI memory map

2023-01-06 Thread Vagrant Cascadian
On 2023-01-05, Heinrich Schuchardt wrote:
> Add reservations for all EFI memory areas that are not
> EFI_CONVENTIONAL_MEMORY.
>
> Signed-off-by: Heinrich Schuchardt 

Tested on odroid-c2, fixes booting from extlinux.conf and boot.scr using
booti, and still works using EFI boot as well.

Thanks!

Tested-by: Vagrant Cascadian 

live well,
  vagrant

> ---
> v2:
>   use efi_get_memory_map_alloc()
> ---
>  lib/lmb.c | 36 
>  1 file changed, 36 insertions(+)
>
> diff --git a/lib/lmb.c b/lib/lmb.c
> index c599608fa3..ec790760db 100644
> --- a/lib/lmb.c
> +++ b/lib/lmb.c
> @@ -7,7 +7,9 @@
>   */
>  
>  #include 
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -153,6 +155,37 @@ void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, 
> ulong end, ulong align)
>   }
>  }
>  
> +/**
> + * efi_lmb_reserve() - add reservations for EFI memory
> + *
> + * Add reservations for all EFI memory areas that are not
> + * EFI_CONVENTIONAL_MEMORY.
> + *
> + * @lmb: lmb environment
> + * Return:   0 on success, 1 on failure
> + */
> +static __maybe_unused int efi_lmb_reserve(struct lmb *lmb)
> +{
> + struct efi_mem_desc *memmap = NULL, *map;
> + efi_uintn_t i, map_size = 0;
> + efi_status_t ret;
> +
> + ret = efi_get_memory_map_alloc(&map_size, &memmap);
> + if (ret != EFI_SUCCESS)
> + return 1;
> +
> + for (i = 0, map = memmap; i < map_size / sizeof(*map); ++map, ++i) {
> + if (map->type != EFI_CONVENTIONAL_MEMORY)
> + lmb_reserve(lmb,
> + map_to_sysmem((void *)(uintptr_t)
> +   map->physical_start),
> + map->num_pages * EFI_PAGE_SIZE);
> + }
> + efi_free_pool(memmap);
> +
> + return 0;
> +}
> +
>  static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
>  {
>   arch_lmb_reserve(lmb);
> @@ -160,6 +193,9 @@ static void lmb_reserve_common(struct lmb *lmb, void 
> *fdt_blob)
>  
>   if (CONFIG_IS_ENABLED(OF_LIBFDT) && fdt_blob)
>   boot_fdt_add_mem_rsv_regions(lmb, fdt_blob);
> +
> + if (CONFIG_IS_ENABLED(EFI_LOADER))
> + efi_lmb_reserve(lmb);
>  }
>  
>  /* Initialize the struct, add memory and call arch/board reserve functions */


signature.asc
Description: PGP signature


[PATCH v2 3/3] lmb: consider EFI memory map

2023-01-05 Thread Heinrich Schuchardt
Add reservations for all EFI memory areas that are not
EFI_CONVENTIONAL_MEMORY.

Signed-off-by: Heinrich Schuchardt 
---
v2:
use efi_get_memory_map_alloc()
---
 lib/lmb.c | 36 
 1 file changed, 36 insertions(+)

diff --git a/lib/lmb.c b/lib/lmb.c
index c599608fa3..ec790760db 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -7,7 +7,9 @@
  */
 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -153,6 +155,37 @@ void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, 
ulong end, ulong align)
}
 }
 
+/**
+ * efi_lmb_reserve() - add reservations for EFI memory
+ *
+ * Add reservations for all EFI memory areas that are not
+ * EFI_CONVENTIONAL_MEMORY.
+ *
+ * @lmb:   lmb environment
+ * Return: 0 on success, 1 on failure
+ */
+static __maybe_unused int efi_lmb_reserve(struct lmb *lmb)
+{
+   struct efi_mem_desc *memmap = NULL, *map;
+   efi_uintn_t i, map_size = 0;
+   efi_status_t ret;
+
+   ret = efi_get_memory_map_alloc(&map_size, &memmap);
+   if (ret != EFI_SUCCESS)
+   return 1;
+
+   for (i = 0, map = memmap; i < map_size / sizeof(*map); ++map, ++i) {
+   if (map->type != EFI_CONVENTIONAL_MEMORY)
+   lmb_reserve(lmb,
+   map_to_sysmem((void *)(uintptr_t)
+ map->physical_start),
+   map->num_pages * EFI_PAGE_SIZE);
+   }
+   efi_free_pool(memmap);
+
+   return 0;
+}
+
 static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
 {
arch_lmb_reserve(lmb);
@@ -160,6 +193,9 @@ static void lmb_reserve_common(struct lmb *lmb, void 
*fdt_blob)
 
if (CONFIG_IS_ENABLED(OF_LIBFDT) && fdt_blob)
boot_fdt_add_mem_rsv_regions(lmb, fdt_blob);
+
+   if (CONFIG_IS_ENABLED(EFI_LOADER))
+   efi_lmb_reserve(lmb);
 }
 
 /* Initialize the struct, add memory and call arch/board reserve functions */
-- 
2.37.2