diff mbox series

[v3,1/2] efi: Move grub_reboot() into kernel

Message ID 20170829160035.11987-2-agraf@suse.de
State New
Headers show
Series efi: Free memory on exit | expand

Commit Message

Alexander Graf Aug. 29, 2017, 4 p.m. UTC
The reboot function calls machine_fini() and then reboots the system.
Currently it lives in lib/ which means it gets compiled into the
reboot module which lives on the heap.

In a following patch, I want to free the heap on machine_fini()
though, so we would free the memory that the code is running in. That
obviously breaks with smarter UEFI implementations.

So this patch moves it into the core. That way we ensure that all
code running after machine_fini() in the UEFI case is running from
memory that got allocated (and gets deallocated) by the UEFI core.

Signed-off-by: Alexander Graf <agraf@suse.de>

---
 grub-core/Makefile.core.def | 9 +++++----
 include/grub/misc.h         | 3 ++-
 2 files changed, 7 insertions(+), 5 deletions(-)

-- 
2.12.3


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Comments

Leif Lindholm Aug. 29, 2017, 4:14 p.m. UTC | #1
On Tue, Aug 29, 2017 at 06:00:34PM +0200, Alexander Graf wrote:
> The reboot function calls machine_fini() and then reboots the system.

> Currently it lives in lib/ which means it gets compiled into the

> reboot module which lives on the heap.

> 

> In a following patch, I want to free the heap on machine_fini()

> though, so we would free the memory that the code is running in. That

> obviously breaks with smarter UEFI implementations.

> 

> So this patch moves it into the core. That way we ensure that all

> code running after machine_fini() in the UEFI case is running from

> memory that got allocated (and gets deallocated) by the UEFI core.

> 

> Signed-off-by: Alexander Graf <agraf@suse.de>

> ---

>  grub-core/Makefile.core.def | 9 +++++----

>  include/grub/misc.h         | 3 ++-

>  2 files changed, 7 insertions(+), 5 deletions(-)

> 

> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def

> index a65c27f7f..d01654b12 100644

> --- a/grub-core/Makefile.core.def

> +++ b/grub-core/Makefile.core.def

> @@ -235,6 +235,11 @@ kernel = {

>    arm64_efi = kern/arm64/efi/init.c;

>    arm64_efi = kern/efi/fdt.c;

>  

> +  ia64_efi = lib/efi/reboot.c;

> +  x86_64_efi = lib/efi/reboot.c;

> +  arm_efi = lib/efi/reboot.c;

> +  arm64_efi = lib/efi/reboot.c;

> +


Actually, if we're moving these (which I am all for), can we squash
this down to a single "efi =" line?

And as I am already in bikeshedding mode: if we move it into the
kernel image, should we also move the source file to
grub-core/kern/efi/?

/
    Leif

>    i386_pc = kern/i386/pc/init.c;

>    i386_pc = kern/i386/pc/mmap.c;

>    i386_pc = term/i386/pc/console.c;

> @@ -872,10 +877,6 @@ module = {

>    name = reboot;

>    i386 = lib/i386/reboot.c;

>    i386 = lib/i386/reboot_trampoline.S;

> -  ia64_efi = lib/efi/reboot.c;

> -  x86_64_efi = lib/efi/reboot.c;

> -  arm_efi = lib/efi/reboot.c;

> -  arm64_efi = lib/efi/reboot.c;

>    powerpc_ieee1275 = lib/ieee1275/reboot.c;

>    sparc64_ieee1275 = lib/ieee1275/reboot.c;

>    mips_arc = lib/mips/arc/reboot.c;

> diff --git a/include/grub/misc.h b/include/grub/misc.h

> index 2a9f87cc2..372f009e8 100644

> --- a/include/grub/misc.h

> +++ b/include/grub/misc.h

> @@ -396,7 +396,8 @@ grub_abs (int x)

>  }

>  

>  /* Reboot the machine.  */

> -#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS)

> +#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS) || \

> +    defined (GRUB_MACHINE_EFI)

>  void EXPORT_FUNC(grub_reboot) (void) __attribute__ ((noreturn));

>  #else

>  void grub_reboot (void) __attribute__ ((noreturn));

> -- 

> 2.12.3

> 

> 

> _______________________________________________

> Grub-devel mailing list

> Grub-devel@gnu.org

> https://lists.gnu.org/mailman/listinfo/grub-devel


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
diff mbox series

Patch

diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index a65c27f7f..d01654b12 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -235,6 +235,11 @@  kernel = {
   arm64_efi = kern/arm64/efi/init.c;
   arm64_efi = kern/efi/fdt.c;
 
+  ia64_efi = lib/efi/reboot.c;
+  x86_64_efi = lib/efi/reboot.c;
+  arm_efi = lib/efi/reboot.c;
+  arm64_efi = lib/efi/reboot.c;
+
   i386_pc = kern/i386/pc/init.c;
   i386_pc = kern/i386/pc/mmap.c;
   i386_pc = term/i386/pc/console.c;
@@ -872,10 +877,6 @@  module = {
   name = reboot;
   i386 = lib/i386/reboot.c;
   i386 = lib/i386/reboot_trampoline.S;
-  ia64_efi = lib/efi/reboot.c;
-  x86_64_efi = lib/efi/reboot.c;
-  arm_efi = lib/efi/reboot.c;
-  arm64_efi = lib/efi/reboot.c;
   powerpc_ieee1275 = lib/ieee1275/reboot.c;
   sparc64_ieee1275 = lib/ieee1275/reboot.c;
   mips_arc = lib/mips/arc/reboot.c;
diff --git a/include/grub/misc.h b/include/grub/misc.h
index 2a9f87cc2..372f009e8 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -396,7 +396,8 @@  grub_abs (int x)
 }
 
 /* Reboot the machine.  */
-#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS)
+#if defined (GRUB_MACHINE_EMU) || defined (GRUB_MACHINE_QEMU_MIPS) || \
+    defined (GRUB_MACHINE_EFI)
 void EXPORT_FUNC(grub_reboot) (void) __attribute__ ((noreturn));
 #else
 void grub_reboot (void) __attribute__ ((noreturn));