Skip to content

Commit 8a5b403

Browse files
Ard BiesheuvelIngo Molnar
authored andcommitted
arm64, mm, efi: Account for GICv3 LPI tables in static memblock reserve table
In the irqchip and EFI code, we have what basically amounts to a quirk to work around a peculiarity in the GICv3 architecture, which permits the system memory address of LPI tables to be programmable only once after a CPU reset. This means kexec kernels must use the same memory as the first kernel, and thus ensure that this memory has not been given out for other purposes by the time the ITS init code runs, which is not very early for secondary CPUs. On systems with many CPUs, these reservations could overflow the memblock reservation table, and this was addressed in commit: eff8962 ("efi/arm: Defer persistent reservations until after paging_init()") However, this turns out to have made things worse, since the allocation of page tables and heap space for the resized memblock reservation table itself may overwrite the regions we are attempting to reserve, which may cause all kinds of corruption, also considering that the ITS will still be poking bits into that memory in response to incoming MSIs. So instead, let's grow the static memblock reservation table on such systems so it can accommodate these reservations at an earlier time. This will permit us to revert the above commit in a subsequent patch. [ mingo: Minor cleanups. ] Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Mike Rapoport <rppt@linux.ibm.com> Acked-by: Will Deacon <will.deacon@arm.com> Acked-by: Marc Zyngier <marc.zyngier@arm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20190215123333.21209-2-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 5ded587 commit 8a5b403

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

arch/arm64/include/asm/memory.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ static inline void *phys_to_virt(phys_addr_t x)
332332
#define virt_addr_valid(kaddr) \
333333
(_virt_addr_is_linear(kaddr) && _virt_addr_valid(kaddr))
334334

335+
/*
336+
* Given that the GIC architecture permits ITS implementations that can only be
337+
* configured with a LPI table address once, GICv3 systems with many CPUs may
338+
* end up reserving a lot of different regions after a kexec for their LPI
339+
* tables (one per CPU), as we are forced to reuse the same memory after kexec
340+
* (and thus reserve it persistently with EFI beforehand)
341+
*/
342+
#if defined(CONFIG_EFI) && defined(CONFIG_ARM_GIC_V3_ITS)
343+
# define INIT_MEMBLOCK_RESERVED_REGIONS (INIT_MEMBLOCK_REGIONS + NR_CPUS + 1)
344+
#endif
345+
335346
#include <asm-generic/memory_model.h>
336347

337348
#endif

include/linux/memblock.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ extern unsigned long max_pfn;
2929
*/
3030
extern unsigned long long max_possible_pfn;
3131

32-
#define INIT_MEMBLOCK_REGIONS 128
33-
#define INIT_PHYSMEM_REGIONS 4
34-
3532
/**
3633
* enum memblock_flags - definition of memory region attributes
3734
* @MEMBLOCK_NONE: no special request

mm/memblock.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626

2727
#include "internal.h"
2828

29+
#define INIT_MEMBLOCK_REGIONS 128
30+
#define INIT_PHYSMEM_REGIONS 4
31+
32+
#ifndef INIT_MEMBLOCK_RESERVED_REGIONS
33+
# define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
34+
#endif
35+
2936
/**
3037
* DOC: memblock overview
3138
*
@@ -92,7 +99,7 @@ unsigned long max_pfn;
9299
unsigned long long max_possible_pfn;
93100

94101
static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
95-
static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
102+
static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS] __initdata_memblock;
96103
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
97104
static struct memblock_region memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS] __initdata_memblock;
98105
#endif
@@ -105,7 +112,7 @@ struct memblock memblock __initdata_memblock = {
105112

106113
.reserved.regions = memblock_reserved_init_regions,
107114
.reserved.cnt = 1, /* empty dummy entry */
108-
.reserved.max = INIT_MEMBLOCK_REGIONS,
115+
.reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS,
109116
.reserved.name = "reserved",
110117

111118
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP

0 commit comments

Comments
 (0)