From patchwork Mon Jan 12 20:28:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 42970 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C714420DE8 for ; Mon, 12 Jan 2015 20:30:59 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id w7sf11255689lbi.0 for ; Mon, 12 Jan 2015 12:30:58 -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=cFr+bUNLpq4q4OcYHUHAwZ2/R8oBo8V8IAv4MB9uwaU=; b=ZhLoUQApy3r1t+H3Ty1pFBIJ5Xa9c7tJSodG/BN6KBMwlDzGn2iVoOh9QXgedTYr5H Rfy+Xghmo5tX3YOZ07ySSpO9aL1T+o/R/g4o/Q7XN/6TZcv5eFe2DJ2cNvVXULsrD3ZJ oDyP0sB7y9iTVW3niMpIJH1d7QEKfL19BMYagWa9+F+nxCLbwTxguxYoTQzdVgUHDLlF dI2fK3Koi3F9Lhtd7Nnf9QpmN4iGeyI9z3dxe5EbY3adL4yFs19k2u43VK2BoEcgTkVC NBULwMXZ2bj9P7lN9xDS+cX35KngFMf11aLfM+GX4IV3o9WLeJvp75IAPpWpzKagwMyx sSOg== X-Gm-Message-State: ALoCoQnc1za96k+Xr/BN5kK6imkksHUuawvZ30kbCRXYZs+UJPaVxKHqk2fjo47SJ0edRwc81Bmt X-Received: by 10.113.5.170 with SMTP id cn10mr10966lbd.21.1421094658590; Mon, 12 Jan 2015 12:30:58 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.4.8 with SMTP id ca8ls714061lad.0.gmail; Mon, 12 Jan 2015 12:30:58 -0800 (PST) X-Received: by 10.152.8.11 with SMTP id n11mr36963817laa.38.1421094658241; Mon, 12 Jan 2015 12:30:58 -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 g2si22312856lbs.85.2015.01.12.12.30.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 Jan 2015 12:30:58 -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 pn19so26471207lab.9 for ; Mon, 12 Jan 2015 12:30:58 -0800 (PST) X-Received: by 10.152.87.12 with SMTP id t12mr38690019laz.31.1421094658033; Mon, 12 Jan 2015 12:30:58 -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 c8csp1185509lbb; Mon, 12 Jan 2015 12:30:56 -0800 (PST) X-Received: by 10.68.116.5 with SMTP id js5mr47474897pbb.39.1421094655777; Mon, 12 Jan 2015 12:30:55 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ol12si24706905pab.53.2015.01.12.12.30.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jan 2015 12:30:55 -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 1YAlba-0005aC-Er; Mon, 12 Jan 2015 20:28:54 +0000 Received: from mail-we0-f178.google.com ([74.125.82.178]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YAlbW-0005ZE-4R for linux-arm-kernel@lists.infradead.org; Mon, 12 Jan 2015 20:28:50 +0000 Received: by mail-we0-f178.google.com with SMTP id p10so21203034wes.9 for ; Mon, 12 Jan 2015 12:28:27 -0800 (PST) X-Received: by 10.180.207.211 with SMTP id ly19mr33885664wic.73.1421094507530; Mon, 12 Jan 2015 12:28:27 -0800 (PST) Received: from ards-macbook-pro.local ([197.131.20.57]) by mx.google.com with ESMTPSA id bj3sm11574528wib.3.2015.01.12.12.28.25 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 Jan 2015 12:28:26 -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 v2] arm64/efi: efistub: apply __init annotation Date: Mon, 12 Jan 2015 20:28:20 +0000 Message-Id: <1421094500-15659-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_122850_330010_0F7F1546 X-CRM114-Status: GOOD ( 12.37 ) 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.0 SPF_PASS SPF: sender matches SPF record -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.178 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.178 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel , msalter@redhat.com 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 now trigger a section mismatch warning without it. Signed-off-by: Ard Biesheuvel --- v2: fixed an issue with spurious rebuilding of object files, now setting $(extra-y) correctly, which also allows the .PRECIOUS: to be dropped. arch/arm64/kernel/efi-stub.c | 14 +++++++------- drivers/firmware/efi/libstub/Makefile | 14 ++++++++++++++ drivers/firmware/efi/libstub/arm-stub.c | 8 ++++---- drivers/firmware/efi/libstub/efi-stub-helper.c | 2 +- 4 files changed, 26 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..8902f52e0998 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -24,3 +24,17 @@ 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. +# +extra-$(CONFIG_ARM64) := $(lib-y) +lib-$(CONFIG_ARM64) := $(patsubst %.o,%.init.o,$(lib-y)) + +OBJCOPYFLAGS := --prefix-alloc-sections=.init +$(obj)/%.init.o: $(obj)/%.o FORCE + $(call if_changed,objcopy) 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;