From patchwork Thu Aug 31 14:40:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 111446 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp111873qge; Thu, 31 Aug 2017 14:47:03 -0700 (PDT) X-Google-Smtp-Source: ADKCNb7hIhy3UvtnrEk1t4nrszkgczf+aDejNYR5JPLuaT0jmwRhuHr7QRduAk2BKHio/8s3Howq X-Received: by 10.200.11.5 with SMTP id e5mr9008518qti.336.1504216023232; Thu, 31 Aug 2017 14:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504216023; cv=none; d=google.com; s=arc-20160816; b=vp2QPSZyCG72tkDk59EtLko5y1Y7dNGfyskj40wLis+JcHPWO4oNIVPzc8JJcSCPeM xotVd+zXJoVKsN+y7e/iMBiP0TuDMEbu0XGvRaMaE21cgKV9Sioi+73HOPw8zh3CRCCh 5orIJiksALClkJmk1vB3Xht0EyC0RmUkFW6JO6sGjHEoaukwrvMl4ikmBFmdSIk1mLjK HLCjWqiTQCtJs++SqiLxRjWvA5fpSjtNVIe1IzF2pWPCDqUkeUJ2s9YREBQn5Y6ZdxIn c+XgOknhPGl6esBIH2mdXqa6wfCjul1veksVkiwg0vIxVP8Rw4XBYqrFDaS/7TsWjhFC RXkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:arc-authentication-results; bh=XkMT9Jr2KFJKBAKTt1/0xXM4nrp88i4Lzty76K8PyoY=; b=qXT/leKakcj39jt7cd2UWvLjwiowjya1KlpDf8yD/4Wyz2Aexh53X7pTLSSm4nUpf1 L7OMr235D71lT/MvrGi+kL3xkWMrpntgc7mQpnDQ1ztOOpe4czCCXOP69CTXZssRWvXH hbdfg+Lr1I8p7w/EX2D2L51wC/qoouLx4NXSr82rdXmP9D0o4n4xm2uVX0AYfcDudzzS xdKdtftCgzFVMogzqJk2DAHvmtQB2WT6GJq5KpJvrW68apZiO4jx6qnQtauh9safwZb5 CmqBDVC4JDc2+n/sDuGLUTAYJPXp2jiBzd2+1KCwRSI0VbqHTtojB9VvEJ6Xxm3lVyPH /Mhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p31si723591qtp.282.2017.08.31.14.47.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 31 Aug 2017 14:47:03 -0700 (PDT) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org Received: from localhost ([::1]:57632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnXIj-0001Nq-3Y for patch@linaro.org; Thu, 31 Aug 2017 17:47:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnXIW-0001LG-3A for grub-devel@gnu.org; Thu, 31 Aug 2017 17:46:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnXIR-0003bg-Ao for grub-devel@gnu.org; Thu, 31 Aug 2017 17:46:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:48943 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnXIR-0003bG-0z for grub-devel@gnu.org; Thu, 31 Aug 2017 17:46:43 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 66E14AF51; Thu, 31 Aug 2017 21:46:41 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v7 1/2] efi: Move grub_reboot() into kernel Date: Thu, 31 Aug 2017 16:40:18 +0200 Message-Id: <20170831144019.65588-2-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170831144019.65588-1-agraf@suse.de> References: <20170831144019.65588-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: Leif Lindholm , phcoder@gmail.com, mchang@suse.com, Daniel Kiper , elliott@hpe.com MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" 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 --- v3 -> v4: - Move grub_reboot to kern/efi/efi.c --- grub-core/Makefile.core.def | 4 ---- grub-core/kern/efi/efi.c | 9 +++++++++ grub-core/lib/efi/reboot.c | 33 --------------------------------- include/grub/misc.h | 3 ++- 4 files changed, 11 insertions(+), 38 deletions(-) delete mode 100644 grub-core/lib/efi/reboot.c -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index a65c27f7f..1cc4ce374 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -872,10 +872,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/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index d467785fc..708581fcb 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -155,6 +155,15 @@ grub_efi_get_loaded_image (grub_efi_handle_t image_handle) } void +grub_reboot (void) +{ + grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); + efi_call_4 (grub_efi_system_table->runtime_services->reset_system, + GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); + for (;;) ; +} + +void grub_exit (void) { grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); diff --git a/grub-core/lib/efi/reboot.c b/grub-core/lib/efi/reboot.c deleted file mode 100644 index 7de8bcb5d..000000000 --- a/grub-core/lib/efi/reboot.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2011 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -void -grub_reboot (void) -{ - grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); - efi_call_4 (grub_efi_system_table->runtime_services->reset_system, - GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL); - for (;;) ; -} 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));