diff options
author | Ard Biesheuvel <ard.biesheuvel@linaro.org> | 2016-11-24 13:02:23 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-11-25 01:15:23 -0500 |
commit | 018edcfac4c3b140366ad51b0907f3becb5bb624 (patch) | |
tree | cbde451448c6a304321a969401f853ea2239333c | |
parent | b2c74191f4672c4b3265d0335910792b4f72026b (diff) |
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>
-rw-r--r-- | drivers/firmware/efi/libstub/random.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/firmware/efi/libstub/random.c b/drivers/firmware/efi/libstub/random.c index 3a3feacc329f..7e72954d5860 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, | |||
45 | unsigned long align_shift) | 45 | unsigned long align_shift) |
46 | { | 46 | { |
47 | unsigned long align = 1UL << align_shift; | 47 | unsigned long align = 1UL << align_shift; |
48 | u64 start, end; | 48 | u64 first_slot, last_slot, region_end; |
49 | 49 | ||
50 | if (md->type != EFI_CONVENTIONAL_MEMORY) | 50 | if (md->type != EFI_CONVENTIONAL_MEMORY) |
51 | return 0; | 51 | return 0; |
52 | 52 | ||
53 | start = round_up(md->phys_addr, align); | 53 | region_end = min((u64)ULONG_MAX, md->phys_addr + md->num_pages*EFI_PAGE_SIZE - 1); |
54 | end = round_down(md->phys_addr + md->num_pages * EFI_PAGE_SIZE - size, | ||
55 | align); | ||
56 | 54 | ||
57 | if (start > end) | 55 | first_slot = round_up(md->phys_addr, align); |
56 | last_slot = round_down(region_end - size + 1, align); | ||
57 | |||
58 | if (first_slot > last_slot) | ||
58 | return 0; | 59 | return 0; |
59 | 60 | ||
60 | return (end - start + 1) >> align_shift; | 61 | return ((unsigned long)(last_slot - first_slot) >> align_shift) + 1; |
61 | } | 62 | } |
62 | 63 | ||
63 | /* | 64 | /* |