From: tip-bot for Ard Biesheuvel <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, peterz@infradead.org, mingo@kernel.org,
arnd@arndb.de, torvalds@linux-foundation.org,
linux-kernel@vger.kernel.org, matt@codeblueprint.co.uk,
ard.biesheuvel@linaro.org, hpa@zytor.com
Subject: [tip:efi/core] efi/libstub: Make efi_random_alloc() allocate below 4 GB on 32-bit
Date: Thu, 24 Nov 2016 22:47:15 -0800 [thread overview]
Message-ID: <tip-018edcfac4c3b140366ad51b0907f3becb5bb624@git.kernel.org> (raw)
In-Reply-To: <1480010543-25709-2-git-send-email-ard.biesheuvel@linaro.org>
Commit-ID: 018edcfac4c3b140366ad51b0907f3becb5bb624
Gitweb: http://git.kernel.org/tip/018edcfac4c3b140366ad51b0907f3becb5bb624
Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
AuthorDate: Thu, 24 Nov 2016 18:02:23 +0000
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 25 Nov 2016 07:15:23 +0100
efi/libstub: Make efi_random_alloc() allocate below 4 GB on 32-bit
The UEFI stub executes in the context of the firmware, which identity
maps the available system RAM, which implies that only memory below
4 GB can be used for allocations on 32-bit architectures, even on [L]PAE
capable hardware.
So ignore any reported memory above 4 GB in efi_random_alloc(). This
also fixes a reported build problem on ARM under -Os, where the 64-bit
logical shift relies on a software routine that the ARM decompressor does
not provide.
A second [minor] issue is also fixed, where the '+ 1' is moved out of
the shift, where it belongs: the reason for its presence is that a
memory region where start == end should count as a single slot, given
that 'end' takes the desired size and alignment of the allocation into
account.
To clarify the code in this regard, rename start/end to 'first_slot' and
'last_slot', respectively, and introduce 'region_end' to describe the
last usable address of the current region.
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/1480010543-25709-2-git-send-email-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
drivers/firmware/efi/libstub/random.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/firmware/efi/libstub/random.c b/drivers/firmware/efi/libstub/random.c
index 3a3feac..7e72954 100644
--- a/drivers/firmware/efi/libstub/random.c
+++ b/drivers/firmware/efi/libstub/random.c
@@ -45,19 +45,20 @@ static unsigned long get_entry_num_slots(efi_memory_desc_t *md,
unsigned long align_shift)
{
unsigned long align = 1UL << align_shift;
- u64 start, end;
+ u64 first_slot, last_slot, region_end;
if (md->type != EFI_CONVENTIONAL_MEMORY)
return 0;
- start = round_up(md->phys_addr, align);
- end = round_down(md->phys_addr + md->num_pages * EFI_PAGE_SIZE - size,
- align);
+ region_end = min((u64)ULONG_MAX, md->phys_addr + md->num_pages*EFI_PAGE_SIZE - 1);
- if (start > end)
+ first_slot = round_up(md->phys_addr, align);
+ last_slot = round_down(region_end - size + 1, align);
+
+ if (first_slot > last_slot)
return 0;
- return (end - start + 1) >> align_shift;
+ return ((unsigned long)(last_slot - first_slot) >> align_shift) + 1;
}
/*
next prev parent reply other threads:[~2016-11-25 6:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-24 18:02 [GIT PULL] one more EFI patch for v4.10 Ard Biesheuvel
2016-11-24 18:02 ` Ard Biesheuvel
2016-11-24 18:02 ` [PATCH] efi/libstub: Make efi_random_alloc() allocate below 4 GB on 32-bit Ard Biesheuvel
2016-11-25 6:47 ` tip-bot for Ard Biesheuvel [this message]
2016-12-04 14:17 ` [tip:efi/core] " Matt Fleming
2016-12-04 14:31 ` Ard Biesheuvel
2016-12-04 21:38 ` Matt Fleming
2016-12-05 9:01 ` Ard Biesheuvel
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-018edcfac4c3b140366ad51b0907f3becb5bb624@git.kernel.org \
--to=tipbot@zytor.com \
--cc=ard.biesheuvel@linaro.org \
--cc=arnd@arndb.de \
--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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.