]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
powerpc/32s: Fix segments setup when TASK_SIZE is not a multiple of 256M
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Wed, 24 Dec 2025 11:20:53 +0000 (12:20 +0100)
committerMadhavan Srinivasan <maddy@linux.ibm.com>
Wed, 7 Jan 2026 04:01:04 +0000 (09:31 +0530)
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
arch/powerpc/include/asm/book3s/32/mmu-hash.h
arch/powerpc/include/asm/task_size_32.h
arch/powerpc/kernel/asm-offsets.c
arch/powerpc/kernel/head_book3s_32.S
arch/powerpc/mm/book3s32/mmu.c
arch/powerpc/mm/ptdump/segment_regs.c

index 8435bf3cdabfaa142bee0df8d6a597d5106beae2..387d370c8a3586f95534cc43fe8677d4ee727cb6 100644 (file)
@@ -192,12 +192,15 @@ extern s32 patch__hash_page_B, patch__hash_page_C;
 extern s32 patch__flush_hash_A0, patch__flush_hash_A1, patch__flush_hash_A2;
 extern s32 patch__flush_hash_B;
 
+#include <linux/sizes.h>
+#include <linux/align.h>
+
 #include <asm/reg.h>
 #include <asm/task_size_32.h>
 
 static __always_inline void update_user_segment(u32 n, u32 val)
 {
-       if (n << 28 < TASK_SIZE)
+       if (n << 28 < ALIGN(TASK_SIZE, SZ_256M))
                mtsr(val + n * 0x111, n << 28);
 }
 
index de7290ee770fb47a7414124df19f230f9e4c5ede..30edc21f71fbd931ebfd0b703bd6fd4a99facc98 100644 (file)
@@ -6,7 +6,7 @@
 #error User TASK_SIZE overlaps with KERNEL_START address
 #endif
 
-#define TASK_SIZE (CONFIG_TASK_SIZE)
+#define TASK_SIZE ASM_CONST(CONFIG_TASK_SIZE)
 
 /*
  * This decides where the kernel will search for a free chunk of vm space during
index a4bc80b30410ae6d2a468613e779e4af7677179f..46149f326fd427d4d174485964553de0e7909af5 100644 (file)
@@ -331,7 +331,7 @@ int main(void)
 
 #ifndef CONFIG_PPC64
        DEFINE(TASK_SIZE, TASK_SIZE);
-       DEFINE(NUM_USER_SEGMENTS, TASK_SIZE>>28);
+       DEFINE(NUM_USER_SEGMENTS, ALIGN(TASK_SIZE, SZ_256M) >> 28);
 #endif /* ! CONFIG_PPC64 */
 
        /* datapage offsets for use by vdso */
index cb2bca76be5350752e6b843adb753835f3717659..c1779455ea32ff0b9409726e066c6a40b434511d 100644 (file)
@@ -420,7 +420,7 @@ InstructionTLBMiss:
        lwz     r2,0(r2)                /* get pmd entry */
 #ifdef CONFIG_EXECMEM
        rlwinm  r3, r0, 4, 0xf
-       subi    r3, r3, (TASK_SIZE >> 28) & 0xf
+       subi    r3, r3, NUM_USER_SEGMENTS
 #endif
        rlwinm. r2,r2,0,0,19            /* extract address of pte page */
        beq-    InstructionAddressInvalid       /* return if no mapping */
@@ -475,7 +475,7 @@ DataLoadTLBMiss:
        lwz     r2,0(r1)                /* get pmd entry */
        rlwinm  r3, r0, 4, 0xf
        rlwinm. r2,r2,0,0,19            /* extract address of pte page */
-       subi    r3, r3, (TASK_SIZE >> 28) & 0xf
+       subi    r3, r3, NUM_USER_SEGMENTS
        beq-    2f                      /* bail if no mapping */
 1:     rlwimi  r2,r0,22,20,29          /* insert next 10 bits of address */
        lwz     r2,0(r2)                /* get linux-style pte */
@@ -554,7 +554,7 @@ DataStoreTLBMiss:
        lwz     r2,0(r1)                /* get pmd entry */
        rlwinm  r3, r0, 4, 0xf
        rlwinm. r2,r2,0,0,19            /* extract address of pte page */
-       subi    r3, r3, (TASK_SIZE >> 28) & 0xf
+       subi    r3, r3, NUM_USER_SEGMENTS
        beq-    2f                      /* bail if no mapping */
 1:
        rlwimi  r2,r0,22,20,29          /* insert next 10 bits of address */
index c42ecdf94e48cdae6b50f0a385b455ee3a8ec8e4..37eefc6786a72f2c08946658db6cb41784a0e5ee 100644 (file)
@@ -225,7 +225,7 @@ int mmu_mark_initmem_nx(void)
 
        BUILD_BUG_ON(ALIGN_DOWN(MODULES_VADDR, SZ_256M) < TASK_SIZE);
 
-       for (i = TASK_SIZE >> 28; i < 16; i++) {
+       for (i = ALIGN(TASK_SIZE, SZ_256M) >> 28; i < 16; i++) {
                /* Do not set NX on VM space for modules */
                if (is_module_segment(i << 28))
                        continue;
index 9df3af8d481f18cea5bd4d6f9ee2fbbbd4e7b272..c06704b18a2c89c3c8a59665900c9ef9b6892f8c 100644 (file)
@@ -31,7 +31,7 @@ static int sr_show(struct seq_file *m, void *v)
        int i;
 
        seq_puts(m, "---[ User Segments ]---\n");
-       for (i = 0; i < TASK_SIZE >> 28; i++)
+       for (i = 0; i < ALIGN(TASK_SIZE, SZ_256M) >> 28; i++)
                seg_show(m, i);
 
        seq_puts(m, "\n---[ Kernel Segments ]---\n");