From patchwork Mon Jan 12 13:29:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 42962 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CE7CC2055F for ; Mon, 12 Jan 2015 13:31:44 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id q1sf13367389lam.2 for ; Mon, 12 Jan 2015 05:31:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=OGOANaLf2g8akac6O7P7VCgJ90bWqccdQ8LtUXtRgHQ=; b=PZouv/ZEhjFEgEmfTwo0Dt9vZP86Y15JFZMsaqh6fO8yjPDn724ETJvlpfmKyFbKoK ZB1iEbBpaMZV2H3rYda7EqgEqSbKRBppHA5vwj7WiMWEB1bLZnLOPcLqoz10quz7Ld7m ufWbHeq0hbk6DtmZdjwOZb4sMqmZKr9/lONFYnScf9R5eMQ2WWON7YBMF6aI1yp38BGo /2fiKliPvjqZazmWM/vWaGzT1ehN5ZIGHR1qj0Frdk0VC5EGuiyiiY3QAqoKyFmMPuod UGHa5CeXpL4COaxUc6vFz4g659vDf6O8HlTH31eYy9ufH5q4I5wTMjC8z8U5LJu5q4gJ k1Xg== X-Gm-Message-State: ALoCoQkO+uz0ar3eMLF0qg5owh1aIETH6pBmomPtttfEXcdpmpAHkIltXVhYgJ5QWR0dvl7nyeMA X-Received: by 10.112.133.98 with SMTP id pb2mr1116557lbb.2.1421069503809; Mon, 12 Jan 2015 05:31:43 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.67 with SMTP id g3ls656056lab.25.gmail; Mon, 12 Jan 2015 05:31:43 -0800 (PST) X-Received: by 10.112.50.239 with SMTP id f15mr36121342lbo.31.1421069503607; Mon, 12 Jan 2015 05:31:43 -0800 (PST) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id p4si21280884lag.35.2015.01.12.05.31.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 Jan 2015 05:31:43 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id pn19so24337881lab.9 for ; Mon, 12 Jan 2015 05:31:43 -0800 (PST) X-Received: by 10.152.234.35 with SMTP id ub3mr36687599lac.70.1421069503500; Mon, 12 Jan 2015 05:31:43 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp1079105lbb; Mon, 12 Jan 2015 05:31:42 -0800 (PST) X-Received: by 10.67.7.225 with SMTP id df1mr44706147pad.48.1421069501729; Mon, 12 Jan 2015 05:31:41 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ri11si23406489pbb.33.2015.01.12.05.31.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jan 2015 05:31:41 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YAf4h-0001R4-Jw; Mon, 12 Jan 2015 13:30:31 +0000 Received: from mail-we0-f170.google.com ([74.125.82.170]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YAf4c-0000D8-6s for linux-arm-kernel@lists.infradead.org; Mon, 12 Jan 2015 13:30:28 +0000 Received: by mail-we0-f170.google.com with SMTP id w61so18975411wes.1 for ; Mon, 12 Jan 2015 05:30:01 -0800 (PST) X-Received: by 10.194.92.235 with SMTP id cp11mr25639463wjb.112.1421069397498; Mon, 12 Jan 2015 05:29:57 -0800 (PST) Received: from ards-macbook-pro.local ([197.129.155.24]) by mx.google.com with ESMTPSA id et4sm21650591wjd.15.2015.01.12.05.29.55 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 Jan 2015 05:29:56 -0800 (PST) From: Ard Biesheuvel To: matt.fleming@intel.com, linux-efi@vger.kernel.org, leif.lindholm@linaro.org, roy.franz@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64/efi: efistub: apply __init annotation Date: Mon, 12 Jan 2015 13:29:51 +0000 Message-Id: <1421069391-6902-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150112_053026_474044_C2B94FD9 X-CRM114-Status: GOOD ( 11.77 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.170 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.170 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This ensures all stub component are freed when the kernel proper is done booting, by prefixing the names of all ELF sections that have the SHF_ALLOC attribute with ".init". This approach ensures that even implicitly emitted allocated data (like initializer values and string literals) are covered. At the same time, remove some __init annotations in the stub that have now become redundant, and add the __init annotation to handle_kernel_image which will trigger a section mismatch without it. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-stub.c | 14 +++++++------- drivers/firmware/efi/libstub/Makefile | 15 +++++++++++++++ drivers/firmware/efi/libstub/arm-stub.c | 8 ++++---- drivers/firmware/efi/libstub/efi-stub-helper.c | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c index d27dd982ff26..f5374065ad53 100644 --- a/arch/arm64/kernel/efi-stub.c +++ b/arch/arm64/kernel/efi-stub.c @@ -13,13 +13,13 @@ #include #include -efi_status_t handle_kernel_image(efi_system_table_t *sys_table, - unsigned long *image_addr, - unsigned long *image_size, - unsigned long *reserve_addr, - unsigned long *reserve_size, - unsigned long dram_base, - efi_loaded_image_t *image) +efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table, + unsigned long *image_addr, + unsigned long *image_size, + unsigned long *reserve_addr, + unsigned long *reserve_size, + unsigned long dram_base, + efi_loaded_image_t *image) { efi_status_t status; unsigned long kernel_size, kernel_memsize = 0; diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index b14bc2b9fb4d..4e7de244c663 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -24,3 +24,18 @@ lib-y := efi-stub-helper.o lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o CFLAGS_fdt.o += -I$(srctree)/scripts/dtc/libfdt/ + +# +# arm64 puts the stub in the kernel proper, which will unnecessarily retain all +# code indefinitely unless it is annotated as __init/__initdata/__initconst etc. +# So let's apply the __init annotations at the section level, by prefixing +# the section names directly. This will ensure that even all the inline string +# literals are covered. +# +lib-$(CONFIG_ARM64) := $(addsuffix .init,$(lib-y)) + +OBJCOPYFLAGS := --prefix-alloc-sections=.init +$(obj)/%.o.init: $(obj)/%.o FORCE + $(call if_changed,objcopy) + +.PRECIOUS: $(obj)/%.o diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index e2432b39b6df..dcae482a9a17 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -17,10 +17,10 @@ #include "efistub.h" -static int __init efi_secureboot_enabled(efi_system_table_t *sys_table_arg) +static int efi_secureboot_enabled(efi_system_table_t *sys_table_arg) { - static efi_guid_t const var_guid __initconst = EFI_GLOBAL_VARIABLE_GUID; - static efi_char16_t const var_name[] __initconst = { + static efi_guid_t const var_guid = EFI_GLOBAL_VARIABLE_GUID; + static efi_char16_t const var_name[] = { 'S', 'e', 'c', 'u', 'r', 'e', 'B', 'o', 'o', 't', 0 }; efi_get_variable_t *f_getvar = sys_table_arg->runtime->get_variable; @@ -164,7 +164,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, * for both archictectures, with the arch-specific code provided in the * handle_kernel_image() function. */ -unsigned long __init efi_entry(void *handle, efi_system_table_t *sys_table, +unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, unsigned long *image_addr) { efi_loaded_image_t *image; diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index e766df60fbfb..2fe195002021 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -110,7 +110,7 @@ fail: } -unsigned long __init get_dram_base(efi_system_table_t *sys_table_arg) +unsigned long get_dram_base(efi_system_table_t *sys_table_arg) { efi_status_t status; unsigned long map_size;