From patchwork Sat Nov 12 21:32:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Fleming X-Patchwork-Id: 81937 Delivered-To: patch@linaro.org Received: by 10.182.1.168 with SMTP id 8csp456377obn; Sat, 12 Nov 2016 13:34:01 -0800 (PST) X-Received: by 10.98.67.138 with SMTP id l10mr21007311pfi.101.1478986440925; Sat, 12 Nov 2016 13:34:00 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 197si16412198pfy.74.2016.11.12.13.34.00; Sat, 12 Nov 2016 13:34:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeblueprint-co-uk.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938934AbcKLVd4 (ORCPT + 27 others); Sat, 12 Nov 2016 16:33:56 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:36930 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753522AbcKLVcp (ORCPT ); Sat, 12 Nov 2016 16:32:45 -0500 Received: by mail-wm0-f48.google.com with SMTP id t79so36506804wmt.0 for ; Sat, 12 Nov 2016 13:32:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeblueprint-co-uk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sXJx6Wj0OB8qzElGC7rhT2xP6S779gp9HO/RP/4APVg=; b=WEcfXDULy5dE2cnz1bO3HU4c/TZWDCuEX6aNxuVxfrGX7C/+bPnxU9GHOkPzQLNwIv WlY2ZnVqA0aabMXDl6WgPFaa5635ZCHDwWeni26j2dPZ7Ir4DsxhviQVa+T0Xj7b+sYJ lQ+7SOaL7yz0VajDBtGjxfwcQl/HxzGgU2OtceXo7o95PBvJVfzuorSBx6PpAr+zAfqz Z0L0IG/qja9bEQ/YUgC/AG6t/5/LP53X2QXJFLe0CdAyOs77pWfeal9NM1jimTh3D4om qQYgy3FDZwRSnU/32mZ3+ITUpnsJJagEgwBPKOSgGRL8BWtDDrsIkjTY1FffHDW5796L Z39w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sXJx6Wj0OB8qzElGC7rhT2xP6S779gp9HO/RP/4APVg=; b=EEVP+jiDQuj0zhui7XLwXqeQ2K6UkmzIy5A/y7PJH5Q+ftpUCqGrfSHpr3bMg6zJ3A mFxBGBapvRFGuJnQEpWc2QSN232jteV/YIKvtAMdZ0xc/kD9xfgwMoO/VQH2YYUiKl8H cAvMfnJhBjIMN/IoID1LlAnu7NysreSxYuKZL9MvDcP9GacvsuawERiSMXCsdm3V0Wrf xR3nnox8G8HkU5nNWLEK5rh29TDivYrFQESaf1tw9Icb788MUaaj1TjJYDZ3tkSGJr0y MI7rPiaq7Kd4yPporD9DBqJkym5qpZHuYZ3J8U3EEl7RJvd6muE0g3pmgYszT0jYwdjf pD5A== X-Gm-Message-State: ABUngvd+wDsiwJy6uA0wVSQeBT+5eN1y8EDdq2cOaESML/SKubYuEt120vacKxmiLZv0dg== X-Received: by 10.28.44.6 with SMTP id s6mr3820373wms.44.1478986364209; Sat, 12 Nov 2016 13:32:44 -0800 (PST) Received: from localhost ([2a02:c7f:9225:4100:de53:60ff:fe39:5599]) by smtp.gmail.com with ESMTPSA id z6sm19015185wjt.24.2016.11.12.13.32.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Nov 2016 13:32:43 -0800 (PST) From: Matt Fleming To: Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, Matt Fleming , Kees Cook Subject: [PATCH 4/9] efi/libstub: Add random.c to ARM build Date: Sat, 12 Nov 2016 21:32:32 +0000 Message-Id: <20161112213237.8804-5-matt@codeblueprint.co.uk> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161112213237.8804-1-matt@codeblueprint.co.uk> References: <20161112213237.8804-1-matt@codeblueprint.co.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel Make random.c build for ARM by moving the fallback definition of EFI_ALLOC_ALIGN to efistub.h, and replacing a division by a value we know to be a power of 2 with a right shift (this is required since ARM does not have any integer division helper routines in its decompressor) Cc: Matt Fleming Reviewed-by: Kees Cook Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/Makefile | 4 ++-- drivers/firmware/efi/libstub/efi-stub-helper.c | 9 --------- drivers/firmware/efi/libstub/efistub.h | 9 +++++++++ drivers/firmware/efi/libstub/random.c | 8 +++++--- 4 files changed, 16 insertions(+), 14 deletions(-) -- 2.10.0 diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index c06945160a41..40ddf8f763a8 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -36,11 +36,11 @@ arm-deps := fdt_rw.c fdt_ro.c fdt_wip.c fdt.c fdt_empty_tree.c fdt_sw.c sort.c $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE $(call if_changed_rule,cc_o_c) -lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o \ +lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o random.o \ $(patsubst %.c,lib-%.o,$(arm-deps)) lib-$(CONFIG_ARM) += arm32-stub.o -lib-$(CONFIG_ARM64) += arm64-stub.o random.o +lib-$(CONFIG_ARM64) += arm64-stub.o CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index 4b74bf86c74d..757badc1debb 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -32,15 +32,6 @@ static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE; -/* - * Allow the platform to override the allocation granularity: this allows - * systems that have the capability to run with a larger page size to deal - * with the allocations for initrd and fdt more efficiently. - */ -#ifndef EFI_ALLOC_ALIGN -#define EFI_ALLOC_ALIGN EFI_PAGE_SIZE -#endif - #define EFI_MMAP_NR_SLACK_SLOTS 8 struct file_info { diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index ee49cd23ee63..fe1f22584c69 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -15,6 +15,15 @@ */ #undef __init +/* + * Allow the platform to override the allocation granularity: this allows + * systems that have the capability to run with a larger page size to deal + * with the allocations for initrd and fdt more efficiently. + */ +#ifndef EFI_ALLOC_ALIGN +#define EFI_ALLOC_ALIGN EFI_PAGE_SIZE +#endif + void efi_char16_printk(efi_system_table_t *, efi_char16_t *); efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image, diff --git a/drivers/firmware/efi/libstub/random.c b/drivers/firmware/efi/libstub/random.c index 0c9f58c5ba50..f8e2e5ae6872 100644 --- a/drivers/firmware/efi/libstub/random.c +++ b/drivers/firmware/efi/libstub/random.c @@ -8,6 +8,7 @@ */ #include +#include #include #include "efistub.h" @@ -41,8 +42,9 @@ efi_status_t efi_get_random_bytes(efi_system_table_t *sys_table_arg, */ static unsigned long get_entry_num_slots(efi_memory_desc_t *md, unsigned long size, - unsigned long align) + unsigned long align_shift) { + unsigned long align = 1UL << align_shift; u64 start, end; if (md->type != EFI_CONVENTIONAL_MEMORY) @@ -55,7 +57,7 @@ static unsigned long get_entry_num_slots(efi_memory_desc_t *md, if (start > end) return 0; - return (end - start + 1) / align; + return (end - start + 1) >> align_shift; } /* @@ -98,7 +100,7 @@ efi_status_t efi_random_alloc(efi_system_table_t *sys_table_arg, efi_memory_desc_t *md = (void *)memory_map + map_offset; unsigned long slots; - slots = get_entry_num_slots(md, size, align); + slots = get_entry_num_slots(md, size, ilog2(align)); MD_NUM_SLOTS(md) = slots; total_slots += slots; }