linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Roy Franz <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: roy.franz@hpe.com, ard.biesheuvel@linaro.org, mingo@kernel.org,
	torvalds@linux-foundation.org, hpa@zytor.com,
	peterz@infradead.org, matt@codeblueprint.co.uk,
	linux-kernel@vger.kernel.org, tglx@linutronix.de
Subject: [tip:efi/core] efi/libstub: Fix allocation size calculations
Date: Sun, 13 Nov 2016 01:04:19 -0800	[thread overview]
Message-ID: <tip-5b88a31c222c47cb8997021cc8a576927ba0e77f@git.kernel.org> (raw)
In-Reply-To: <20161112213237.8804-2-matt@codeblueprint.co.uk>

Commit-ID:  5b88a31c222c47cb8997021cc8a576927ba0e77f
Gitweb:     http://git.kernel.org/tip/5b88a31c222c47cb8997021cc8a576927ba0e77f
Author:     Roy Franz <roy.franz@hpe.com>
AuthorDate: Sat, 12 Nov 2016 21:32:29 +0000
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sun, 13 Nov 2016 08:23:14 +0100

efi/libstub: Fix allocation size calculations

Adjust the size used in calculations to match the actual size of allocation
that will be performed based on EFI size/alignment constraints.
efi_high_alloc() and efi_low_alloc() use the passed size in bytes directly
to find space in the memory map for the allocation, rather than the actual
allocation size that has been adjusted for size and alignment constraints.
This results in failed allocations and retries in efi_high_alloc().  The
same error is present in efi_low_alloc(), although failure will only happen
if the lowest memory block is small.
Also use EFI_PAGE_SIZE consistently and remove use of EFI_PAGE_SHIFT to
calculate page size.

Signed-off-by: Roy Franz <roy.franz@hpe.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20161112213237.8804-2-matt@codeblueprint.co.uk
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 drivers/firmware/efi/libstub/efi-stub-helper.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index aded106..4b74bf8 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -186,14 +186,16 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
 		goto fail;
 
 	/*
-	 * Enforce minimum alignment that EFI requires when requesting
-	 * a specific address.  We are doing page-based allocations,
-	 * so we must be aligned to a page.
+	 * Enforce minimum alignment that EFI or Linux requires when
+	 * requesting a specific address.  We are doing page-based (or
+	 * larger) allocations, and both the address and size must meet
+	 * alignment constraints.
 	 */
 	if (align < EFI_ALLOC_ALIGN)
 		align = EFI_ALLOC_ALIGN;
 
-	nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE;
+	size = round_up(size, EFI_ALLOC_ALIGN);
+	nr_pages = size / EFI_PAGE_SIZE;
 again:
 	for (i = 0; i < map_size / desc_size; i++) {
 		efi_memory_desc_t *desc;
@@ -208,7 +210,7 @@ again:
 			continue;
 
 		start = desc->phys_addr;
-		end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT);
+		end = start + desc->num_pages * EFI_PAGE_SIZE;
 
 		if (end > max)
 			end = max;
@@ -278,14 +280,16 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
 		goto fail;
 
 	/*
-	 * Enforce minimum alignment that EFI requires when requesting
-	 * a specific address.  We are doing page-based allocations,
-	 * so we must be aligned to a page.
+	 * Enforce minimum alignment that EFI or Linux requires when
+	 * requesting a specific address.  We are doing page-based (or
+	 * larger) allocations, and both the address and size must meet
+	 * alignment constraints.
 	 */
 	if (align < EFI_ALLOC_ALIGN)
 		align = EFI_ALLOC_ALIGN;
 
-	nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE;
+	size = round_up(size, EFI_ALLOC_ALIGN);
+	nr_pages = size / EFI_PAGE_SIZE;
 	for (i = 0; i < map_size / desc_size; i++) {
 		efi_memory_desc_t *desc;
 		unsigned long m = (unsigned long)map;
@@ -300,7 +304,7 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
 			continue;
 
 		start = desc->phys_addr;
-		end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT);
+		end = start + desc->num_pages * EFI_PAGE_SIZE;
 
 		/*
 		 * Don't allocate at 0x0. It will confuse code that

  reply	other threads:[~2016-11-13  9:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-12 21:32 [GIT PULL 0/9] EFI changes for v4.10 Matt Fleming
2016-11-12 21:32 ` [PATCH 1/9] efi/libstub: Fix allocation size calculations Matt Fleming
2016-11-13  9:04   ` tip-bot for Roy Franz [this message]
2016-11-12 21:32 ` [PATCH 2/9] MAINTAINERS: Add ARM and arm64 EFI specific files to EFI subsystem Matt Fleming
2016-11-13  9:04   ` [tip:efi/core] " tip-bot for Ard Biesheuvel
2016-11-12 21:32 ` [PATCH 3/9] efi: Add support for seeding the RNG from a UEFI config table Matt Fleming
2016-11-13  9:05   ` [tip:efi/core] " tip-bot for Ard Biesheuvel
2016-11-12 21:32 ` [PATCH 4/9] efi/libstub: Add random.c to ARM build Matt Fleming
2016-11-13  9:05   ` [tip:efi/core] " tip-bot for Ard Biesheuvel
2016-11-12 21:32 ` [PATCH 5/9] efi/arm*: libstub: Invoke EFI_RNG_PROTOCOL to seed the UEFI RNG table Matt Fleming
2016-11-13  7:19   ` Ingo Molnar
2016-11-13  8:59     ` Ingo Molnar
2016-11-14 13:27       ` Matt Fleming
2016-11-14 15:10         ` Lukas Wunner
2016-11-15 10:50           ` [tip:efi/core] thunderbolt, efi: Fix Kconfig dependencies tip-bot for Lukas Wunner
2016-11-14 13:23     ` [PATCH 5/9] efi/arm*: libstub: Invoke EFI_RNG_PROTOCOL to seed the UEFI RNG table Matt Fleming
2016-11-14 13:55       ` Ingo Molnar
2016-11-14 14:01         ` Matt Fleming
2016-11-13  9:06   ` [tip:efi/core] efi/arm*/libstub: " tip-bot for Ard Biesheuvel
2016-11-12 21:32 ` [PATCH 6/9] efi: Add device path parser Matt Fleming
2016-11-13  9:07   ` [tip:efi/core] " tip-bot for Lukas Wunner
2016-11-12 21:32 ` [PATCH 7/9] efi: Allow bitness-agnostic protocol calls Matt Fleming
2016-11-13  9:07   ` [tip:efi/core] " tip-bot for Lukas Wunner
2016-11-12 21:32 ` [PATCH 8/9] x86/efi: Retrieve and assign Apple device properties Matt Fleming
2016-11-13  9:08   ` [tip:efi/core] " tip-bot for Lukas Wunner
2016-11-12 21:32 ` [PATCH 9/9] thunderbolt: Use Device ROM retrieved from EFI Matt Fleming
2016-11-13  9:08   ` [tip:efi/core] " tip-bot for Lukas Wunner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-5b88a31c222c47cb8997021cc8a576927ba0e77f@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=roy.franz@hpe.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).