Skip to content

Commit 370d841

Browse files
chleroymaddy-kerneldev
authored andcommitted
powerpc/32: Automatically adapt TASK_SIZE based on constraints
At the time being, TASK_SIZE can be customized by the user via Kconfig but it is not possible to check all constraints in Kconfig. Impossible setups are detected at compile time with BUILD_BUG() but that leads to build failure when setting crazy values. It is not a problem on its own because the user will usually either use the default value or set a well thought value. However build robots generate crazy random configs that lead to build failures, and build robots see it as a regression every time a patch adds such a constraint. So instead of failing the build when the custom TASK_SIZE is too big, just adjust it to the maximum possible value matching the setup. Several architectures already calculate TASK_SIZE based on other parameters and options. In order to do so, move MODULES_VADDR calculation into task_size_32.h and ensure that: - On book3s/32, userspace and module area have their own segments (256M) - On 8xx, userspace has its own full PGDIR entries (4M) Then TASK_SIZE is guaranteed to be correct so remove related BUILD_BUG()s. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/6a2575420770d075cd090b5a316730a2ffafdee4.1766574657.git.chleroy@kernel.org
1 parent fb79037 commit 370d841

7 files changed

Lines changed: 27 additions & 16 deletions

File tree

arch/powerpc/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,9 +1293,8 @@ config TASK_SIZE_BOOL
12931293
Say N here unless you know what you are doing.
12941294

12951295
config TASK_SIZE
1296-
hex "Size of user task space" if TASK_SIZE_BOOL
1296+
hex "Size of maximum user task space" if TASK_SIZE_BOOL
12971297
default "0x80000000" if PPC_8xx
1298-
default "0xb0000000" if PPC_BOOK3S_32 && EXECMEM
12991298
default "0xc0000000"
13001299

13011300
config MODULES_SIZE_BOOL

arch/powerpc/include/asm/book3s/32/pgtable.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ void unmap_kernel_page(unsigned long va);
195195
#define VMALLOC_END ioremap_bot
196196
#endif
197197

198-
#define MODULES_END ALIGN_DOWN(PAGE_OFFSET, SZ_256M)
199-
#define MODULES_SIZE (CONFIG_MODULES_SIZE * SZ_1M)
200-
#define MODULES_VADDR (MODULES_END - MODULES_SIZE)
201-
202198
#ifndef __ASSEMBLER__
203199
#include <linux/sched.h>
204200
#include <linux/threads.h>

arch/powerpc/include/asm/nohash/32/mmu-8xx.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@
170170

171171
#define mmu_linear_psize MMU_PAGE_8M
172172

173-
#define MODULES_END PAGE_OFFSET
174-
#define MODULES_SIZE (CONFIG_MODULES_SIZE * SZ_1M)
175-
#define MODULES_VADDR (MODULES_END - MODULES_SIZE)
176-
177173
#ifndef __ASSEMBLER__
178174

179175
#include <linux/mmdebug.h>

arch/powerpc/include/asm/task_size_32.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@
22
#ifndef _ASM_POWERPC_TASK_SIZE_32_H
33
#define _ASM_POWERPC_TASK_SIZE_32_H
44

5+
#include <linux/sizes.h>
6+
57
#if CONFIG_TASK_SIZE > CONFIG_KERNEL_START
68
#error User TASK_SIZE overlaps with KERNEL_START address
79
#endif
810

11+
#ifdef CONFIG_PPC_8xx
12+
#define MODULES_END ASM_CONST(CONFIG_PAGE_OFFSET)
13+
#define MODULES_SIZE (CONFIG_MODULES_SIZE * SZ_1M)
14+
#define MODULES_VADDR (MODULES_END - MODULES_SIZE)
15+
#define MODULES_BASE (MODULES_VADDR & ~(UL(SZ_4M) - 1))
16+
#define USER_TOP MODULES_BASE
17+
#endif
18+
19+
#ifdef CONFIG_PPC_BOOK3S_32
20+
#define MODULES_END (ASM_CONST(CONFIG_PAGE_OFFSET) & ~(UL(SZ_256M) - 1))
21+
#define MODULES_SIZE (CONFIG_MODULES_SIZE * SZ_1M)
22+
#define MODULES_VADDR (MODULES_END - MODULES_SIZE)
23+
#define MODULES_BASE (MODULES_VADDR & ~(UL(SZ_256M) - 1))
24+
#define USER_TOP MODULES_BASE
25+
#endif
26+
27+
#ifndef USER_TOP
28+
#define USER_TOP ASM_CONST(CONFIG_PAGE_OFFSET)
29+
#endif
30+
31+
#if CONFIG_TASK_SIZE < USER_TOP
932
#define TASK_SIZE ASM_CONST(CONFIG_TASK_SIZE)
33+
#else
34+
#define TASK_SIZE USER_TOP
35+
#endif
1036

1137
/*
1238
* This decides where the kernel will search for a free chunk of vm space during

arch/powerpc/mm/book3s32/mmu.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ int mmu_mark_initmem_nx(void)
223223

224224
update_bats();
225225

226-
BUILD_BUG_ON(ALIGN_DOWN(MODULES_VADDR, SZ_256M) < TASK_SIZE);
227-
228226
for (i = ALIGN(TASK_SIZE, SZ_256M) >> 28; i < 16; i++) {
229227
/* Do not set NX on VM space for modules */
230228
if (is_module_segment(i << 28))

arch/powerpc/mm/mem.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,6 @@ struct execmem_info __init *execmem_arch_setup(void)
401401
#ifdef MODULES_VADDR
402402
unsigned long limit = (unsigned long)_etext - SZ_32M;
403403

404-
BUILD_BUG_ON(TASK_SIZE > MODULES_VADDR);
405-
406404
/* First try within 32M limit from _etext to avoid branch trampolines */
407405
if (MODULES_VADDR < PAGE_OFFSET && MODULES_END > limit) {
408406
start = limit;

arch/powerpc/mm/nohash/8xx.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ void __init setup_initial_memory_limit(phys_addr_t first_memblock_base,
209209

210210
/* 8xx can only access 32MB at the moment */
211211
memblock_set_current_limit(min_t(u64, first_memblock_size, SZ_32M));
212-
213-
BUILD_BUG_ON(ALIGN_DOWN(MODULES_VADDR, PGDIR_SIZE) < TASK_SIZE);
214212
}
215213

216214
int pud_clear_huge(pud_t *pud)

0 commit comments

Comments
 (0)