Skip to content

Commit fb79037

Browse files
chleroymaddy-kerneldev
authored andcommitted
powerpc/32s: Fix segments setup when TASK_SIZE is not a multiple of 256M
For book3s/32 it is assumed that TASK_SIZE is a multiple of 256 Mbytes, but Kconfig allows any value for TASK_SIZE. In all relevant calculations, align TASK_SIZE to the upper 256 Mbytes boundary. Also use ASM_CONST() in the definition of TASK_SIZE to ensure it is seen as an unsigned constant. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/8928d906079e156c59794c41e826a684eaaaebb4.1766574657.git.chleroy@kernel.org
1 parent 704f430 commit fb79037

6 files changed

Lines changed: 11 additions & 8 deletions

File tree

arch/powerpc/include/asm/book3s/32/mmu-hash.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,15 @@ extern s32 patch__hash_page_B, patch__hash_page_C;
192192
extern s32 patch__flush_hash_A0, patch__flush_hash_A1, patch__flush_hash_A2;
193193
extern s32 patch__flush_hash_B;
194194

195+
#include <linux/sizes.h>
196+
#include <linux/align.h>
197+
195198
#include <asm/reg.h>
196199
#include <asm/task_size_32.h>
197200

198201
static __always_inline void update_user_segment(u32 n, u32 val)
199202
{
200-
if (n << 28 < TASK_SIZE)
203+
if (n << 28 < ALIGN(TASK_SIZE, SZ_256M))
201204
mtsr(val + n * 0x111, n << 28);
202205
}
203206

arch/powerpc/include/asm/task_size_32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#error User TASK_SIZE overlaps with KERNEL_START address
77
#endif
88

9-
#define TASK_SIZE (CONFIG_TASK_SIZE)
9+
#define TASK_SIZE ASM_CONST(CONFIG_TASK_SIZE)
1010

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

arch/powerpc/kernel/asm-offsets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ int main(void)
331331

332332
#ifndef CONFIG_PPC64
333333
DEFINE(TASK_SIZE, TASK_SIZE);
334-
DEFINE(NUM_USER_SEGMENTS, TASK_SIZE>>28);
334+
DEFINE(NUM_USER_SEGMENTS, ALIGN(TASK_SIZE, SZ_256M) >> 28);
335335
#endif /* ! CONFIG_PPC64 */
336336

337337
/* datapage offsets for use by vdso */

arch/powerpc/kernel/head_book3s_32.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ InstructionTLBMiss:
420420
lwz r2,0(r2) /* get pmd entry */
421421
#ifdef CONFIG_EXECMEM
422422
rlwinm r3, r0, 4, 0xf
423-
subi r3, r3, (TASK_SIZE >> 28) & 0xf
423+
subi r3, r3, NUM_USER_SEGMENTS
424424
#endif
425425
rlwinm. r2,r2,0,0,19 /* extract address of pte page */
426426
beq- InstructionAddressInvalid /* return if no mapping */
@@ -475,7 +475,7 @@ DataLoadTLBMiss:
475475
lwz r2,0(r1) /* get pmd entry */
476476
rlwinm r3, r0, 4, 0xf
477477
rlwinm. r2,r2,0,0,19 /* extract address of pte page */
478-
subi r3, r3, (TASK_SIZE >> 28) & 0xf
478+
subi r3, r3, NUM_USER_SEGMENTS
479479
beq- 2f /* bail if no mapping */
480480
1: rlwimi r2,r0,22,20,29 /* insert next 10 bits of address */
481481
lwz r2,0(r2) /* get linux-style pte */
@@ -554,7 +554,7 @@ DataStoreTLBMiss:
554554
lwz r2,0(r1) /* get pmd entry */
555555
rlwinm r3, r0, 4, 0xf
556556
rlwinm. r2,r2,0,0,19 /* extract address of pte page */
557-
subi r3, r3, (TASK_SIZE >> 28) & 0xf
557+
subi r3, r3, NUM_USER_SEGMENTS
558558
beq- 2f /* bail if no mapping */
559559
1:
560560
rlwimi r2,r0,22,20,29 /* insert next 10 bits of address */

arch/powerpc/mm/book3s32/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ int mmu_mark_initmem_nx(void)
225225

226226
BUILD_BUG_ON(ALIGN_DOWN(MODULES_VADDR, SZ_256M) < TASK_SIZE);
227227

228-
for (i = TASK_SIZE >> 28; i < 16; i++) {
228+
for (i = ALIGN(TASK_SIZE, SZ_256M) >> 28; i < 16; i++) {
229229
/* Do not set NX on VM space for modules */
230230
if (is_module_segment(i << 28))
231231
continue;

arch/powerpc/mm/ptdump/segment_regs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int sr_show(struct seq_file *m, void *v)
3131
int i;
3232

3333
seq_puts(m, "---[ User Segments ]---\n");
34-
for (i = 0; i < TASK_SIZE >> 28; i++)
34+
for (i = 0; i < ALIGN(TASK_SIZE, SZ_256M) >> 28; i++)
3535
seg_show(m, i);
3636

3737
seq_puts(m, "\n---[ Kernel Segments ]---\n");

0 commit comments

Comments
 (0)