Skip to content

Commit 8ddccc8

Browse files
Alexander Gordeevhcahca
authored andcommitted
s390/boot: cleanup number of page table levels setup
The separate vmalloc area size check against _REGION2_SIZE is needed in case user provided insanely large value using vmalloc= kernel command line parameter. That could lead to overflow and selecting 3 page table levels instead of 4. Use size_add() for the overflow check and get rid of the extra vmalloc area check. With the current values of CONFIG_MAX_PHYSMEM_BITS and PAGES_PER_SECTION the sum of maximal possible size of identity mapping and vmemmap area (derived from these macros) plus modules area size MODULES_LEN can not overflow. Thus, that sum is used as first addend while vmalloc area size is second addend for size_add(). Suggested-by: Heiko Carstens <hca@linux.ibm.com> Acked-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent ee4ac52 commit 8ddccc8

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

arch/s390/boot/startup.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,17 @@ static unsigned long setup_kernel_memory_layout(void)
177177
unsigned long asce_limit;
178178
unsigned long rte_size;
179179
unsigned long pages;
180+
unsigned long vsize;
180181
unsigned long vmax;
181182

182183
pages = ident_map_size / PAGE_SIZE;
183184
/* vmemmap contains a multiple of PAGES_PER_SECTION struct pages */
184185
vmemmap_size = SECTION_ALIGN_UP(pages) * sizeof(struct page);
185186

186187
/* choose kernel address space layout: 4 or 3 levels. */
187-
vmemmap_start = round_up(ident_map_size, _REGION3_SIZE);
188-
if (IS_ENABLED(CONFIG_KASAN) ||
189-
vmalloc_size > _REGION2_SIZE ||
190-
vmemmap_start + vmemmap_size + vmalloc_size + MODULES_LEN >
191-
_REGION2_SIZE) {
188+
vsize = round_up(ident_map_size, _REGION3_SIZE) + vmemmap_size + MODULES_LEN;
189+
vsize = size_add(vsize, vmalloc_size);
190+
if (IS_ENABLED(CONFIG_KASAN) || (vsize > _REGION2_SIZE)) {
192191
asce_limit = _REGION1_SIZE;
193192
rte_size = _REGION2_SIZE;
194193
} else {

0 commit comments

Comments
 (0)