diff mbox series

[v6,2/5] efi/boot.c: add file.need_to_free

Message ID 20200921115113.1278655-3-hudson@trmm.net (mailing list archive)
State Superseded
Headers show
Series efi: Unified Xen hypervisor/kernel/initrd images | expand

Commit Message

Trammell Hudson Sept. 21, 2020, 11:51 a.m. UTC
The config file, kernel, initrd, etc should only be freed if they
are allocated with the UEFI allocator.

Signed-off-by: Trammell Hudson <hudson@trmm.net>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/common/efi/boot.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Jan Beulich Sept. 29, 2020, 10:17 a.m. UTC | #1
On 21.09.2020 13:51, Trammell Hudson wrote:
> The config file, kernel, initrd, etc should only be freed if they
> are allocated with the UEFI allocator.
> 
> Signed-off-by: Trammell Hudson <hudson@trmm.net>
> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Strictly speaking with the changes done from v5 to v6 this tag
would have needed dropping. I guess Roger is fine with it being
kept, though.

> @@ -280,13 +281,13 @@ void __init noreturn blexit(const CHAR16 *str)
>      if ( !efi_bs )
>          efi_arch_halt();
>  
> -    if ( cfg.addr )
> +    if ( cfg.need_to_free )
>          efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
> -    if ( kernel.addr )
> +    if ( kernel.need_to_free )
>          efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size));
> -    if ( ramdisk.addr )
> +    if ( ramdisk.need_to_free )
>          efi_bs->FreePages(ramdisk.addr, PFN_UP(ramdisk.size));
> -    if ( xsm.addr )
> +    if ( xsm.need_to_free )
>          efi_bs->FreePages(xsm.addr, PFN_UP(xsm.size));
>  
>      efi_arch_blexit();

Doesn't this need similar changes in both efi_arch_blexit()?

Jan
Roger Pau Monné Sept. 29, 2020, 10:45 a.m. UTC | #2
On Mon, Sep 21, 2020 at 07:51:10AM -0400, Trammell Hudson wrote:
> The config file, kernel, initrd, etc should only be freed if they
> are allocated with the UEFI allocator.
> 
> Signed-off-by: Trammell Hudson <hudson@trmm.net>
> Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
>  xen/common/efi/boot.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
> index 157fe0e8c5..c2ce0c7294 100644
> --- a/xen/common/efi/boot.c
> +++ b/xen/common/efi/boot.c
> @@ -102,6 +102,7 @@ union string {
>  
>  struct file {
>      UINTN size;
> +    bool need_to_free;
>      union {
>          EFI_PHYSICAL_ADDRESS addr;
>          char *str;
> @@ -280,13 +281,13 @@ void __init noreturn blexit(const CHAR16 *str)
>      if ( !efi_bs )
>          efi_arch_halt();
>  
> -    if ( cfg.addr )
> +    if ( cfg.need_to_free )

If you drop the addr check here...

>          efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
> -    if ( kernel.addr )
> +    if ( kernel.need_to_free )
>          efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size));
> -    if ( ramdisk.addr )
> +    if ( ramdisk.need_to_free )
>          efi_bs->FreePages(ramdisk.addr, PFN_UP(ramdisk.size));
> -    if ( xsm.addr )
> +    if ( xsm.need_to_free )
>          efi_bs->FreePages(xsm.addr, PFN_UP(xsm.size));
>  
>      efi_arch_blexit();
> @@ -581,6 +582,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
>      }
>      else
>      {
> +        file->need_to_free = true;

... I think you need to clear need_to_free if AllocatePages fails?

Thanks, Roger.
Jan Beulich Sept. 29, 2020, 11 a.m. UTC | #3
On 29.09.2020 12:45, Roger Pau Monné wrote:
> On Mon, Sep 21, 2020 at 07:51:10AM -0400, Trammell Hudson wrote:
>> --- a/xen/common/efi/boot.c
>> +++ b/xen/common/efi/boot.c
>> @@ -102,6 +102,7 @@ union string {
>>  
>>  struct file {
>>      UINTN size;
>> +    bool need_to_free;
>>      union {
>>          EFI_PHYSICAL_ADDRESS addr;
>>          char *str;
>> @@ -280,13 +281,13 @@ void __init noreturn blexit(const CHAR16 *str)
>>      if ( !efi_bs )
>>          efi_arch_halt();
>>  
>> -    if ( cfg.addr )
>> +    if ( cfg.need_to_free )
> 
> If you drop the addr check here...
> 
>>          efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
>> -    if ( kernel.addr )
>> +    if ( kernel.need_to_free )
>>          efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size));
>> -    if ( ramdisk.addr )
>> +    if ( ramdisk.need_to_free )
>>          efi_bs->FreePages(ramdisk.addr, PFN_UP(ramdisk.size));
>> -    if ( xsm.addr )
>> +    if ( xsm.need_to_free )
>>          efi_bs->FreePages(xsm.addr, PFN_UP(xsm.size));
>>  
>>      efi_arch_blexit();
>> @@ -581,6 +582,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
>>      }
>>      else
>>      {
>> +        file->need_to_free = true;
> 
> ... I think you need to clear need_to_free if AllocatePages fails?

But this has been moved to the success path, or am I overlooking
anything?

Jan
Roger Pau Monné Sept. 29, 2020, 11:06 a.m. UTC | #4
On Tue, Sep 29, 2020 at 01:00:06PM +0200, Jan Beulich wrote:
> On 29.09.2020 12:45, Roger Pau Monné wrote:
> > On Mon, Sep 21, 2020 at 07:51:10AM -0400, Trammell Hudson wrote:
> >> --- a/xen/common/efi/boot.c
> >> +++ b/xen/common/efi/boot.c
> >> @@ -102,6 +102,7 @@ union string {
> >>  
> >>  struct file {
> >>      UINTN size;
> >> +    bool need_to_free;
> >>      union {
> >>          EFI_PHYSICAL_ADDRESS addr;
> >>          char *str;
> >> @@ -280,13 +281,13 @@ void __init noreturn blexit(const CHAR16 *str)
> >>      if ( !efi_bs )
> >>          efi_arch_halt();
> >>  
> >> -    if ( cfg.addr )
> >> +    if ( cfg.need_to_free )
> > 
> > If you drop the addr check here...
> > 
> >>          efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
> >> -    if ( kernel.addr )
> >> +    if ( kernel.need_to_free )
> >>          efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size));
> >> -    if ( ramdisk.addr )
> >> +    if ( ramdisk.need_to_free )
> >>          efi_bs->FreePages(ramdisk.addr, PFN_UP(ramdisk.size));
> >> -    if ( xsm.addr )
> >> +    if ( xsm.need_to_free )
> >>          efi_bs->FreePages(xsm.addr, PFN_UP(xsm.size));
> >>  
> >>      efi_arch_blexit();
> >> @@ -581,6 +582,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
> >>      }
> >>      else
> >>      {
> >> +        file->need_to_free = true;
> > 
> > ... I think you need to clear need_to_free if AllocatePages fails?
> 
> But this has been moved to the success path, or am I overlooking
> anything?

Oh yes, sorry, somehow I looked at the wrong context. Please ignore my
comment.

Roger.
Trammell Hudson Sept. 29, 2020, 5:53 p.m. UTC | #5
On Tuesday, September 29, 2020 6:17 AM, Jan Beulich <jbeulich@suse.com> wrote:
> On 21.09.2020 13:51, Trammell Hudson wrote:
> [...]
> > Reviewed-by: Roger Pau Monné roger.pau@citrix.com
>
> Strictly speaking with the changes done from v5 to v6 this tag
> would have needed dropping. I guess Roger is fine with it being
> kept, though.

Ok.

> [...]
> Doesn't this need similar changes in both efi_arch_blexit()?

It does -- I had missed that there was a place to free them
and had assumed that they were just leaked.  Fixed in v7.

--
Trammell
diff mbox series

Patch

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 157fe0e8c5..c2ce0c7294 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -102,6 +102,7 @@  union string {
 
 struct file {
     UINTN size;
+    bool need_to_free;
     union {
         EFI_PHYSICAL_ADDRESS addr;
         char *str;
@@ -280,13 +281,13 @@  void __init noreturn blexit(const CHAR16 *str)
     if ( !efi_bs )
         efi_arch_halt();
 
-    if ( cfg.addr )
+    if ( cfg.need_to_free )
         efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size));
-    if ( kernel.addr )
+    if ( kernel.need_to_free )
         efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size));
-    if ( ramdisk.addr )
+    if ( ramdisk.need_to_free )
         efi_bs->FreePages(ramdisk.addr, PFN_UP(ramdisk.size));
-    if ( xsm.addr )
+    if ( xsm.need_to_free )
         efi_bs->FreePages(xsm.addr, PFN_UP(xsm.size));
 
     efi_arch_blexit();
@@ -581,6 +582,7 @@  static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
     }
     else
     {
+        file->need_to_free = true;
         file->size = size;
         if ( file != &cfg )
         {