Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: SMP: Constify smp ops

smp_ops providers do not modify their ops structures, so they should be
made const for robustness. Since currently the MIPS kernel is not mapped
with memory protection, this does not in itself provide any security
benefit, but it still makes sense to make this change.

There are also slight code size efficincies from the structure being
made read-only, saving 128 bytes of kernel text on a
pistachio_defconfig.
Before:
text data bss dec hex filename
7187239 1772752 470224 9430215 8fe4c7 vmlinux
After:
text data bss dec hex filename
7187111 1772752 470224 9430087 8fe447 vmlinux

Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
Cc: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Huacai Chen <chenhc@lemote.com>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Kevin Cernekee <cernekee@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Doug Ledford <dledford@redhat.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: Joe Perches <joe@perches.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Steven J. Hill <steven.hill@cavium.com>
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/16784/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Matt Redfearn and committed by
Ralf Baechle
ff2c8252 b879c801

+37 -37
+3 -3
arch/mips/cavium-octeon/smp.c
··· 408 408 409 409 #endif /* CONFIG_HOTPLUG_CPU */ 410 410 411 - struct plat_smp_ops octeon_smp_ops = { 411 + const struct plat_smp_ops octeon_smp_ops = { 412 412 .send_ipi_single = octeon_send_ipi_single, 413 413 .send_ipi_mask = octeon_send_ipi_mask, 414 414 .init_secondary = octeon_init_secondary, ··· 485 485 octeon_78xx_send_ipi_single(cpu, action); 486 486 } 487 487 488 - static struct plat_smp_ops octeon_78xx_smp_ops = { 488 + static const struct plat_smp_ops octeon_78xx_smp_ops = { 489 489 .send_ipi_single = octeon_78xx_send_ipi_single, 490 490 .send_ipi_mask = octeon_78xx_send_ipi_mask, 491 491 .init_secondary = octeon_init_secondary, ··· 501 501 502 502 void __init octeon_setup_smp(void) 503 503 { 504 - struct plat_smp_ops *ops; 504 + const struct plat_smp_ops *ops; 505 505 506 506 if (octeon_has_feature(OCTEON_FEATURE_CIU3)) 507 507 ops = &octeon_78xx_smp_ops;
+1 -1
arch/mips/fw/arc/init.c
··· 51 51 #endif 52 52 #ifdef CONFIG_SGI_IP27 53 53 { 54 - extern struct plat_smp_ops ip27_smp_ops; 54 + extern const struct plat_smp_ops ip27_smp_ops; 55 55 56 56 register_smp_ops(&ip27_smp_ops); 57 57 }
+2 -2
arch/mips/include/asm/bmips.h
··· 48 48 #include <asm/r4kcache.h> 49 49 #include <asm/smp-ops.h> 50 50 51 - extern struct plat_smp_ops bmips43xx_smp_ops; 52 - extern struct plat_smp_ops bmips5000_smp_ops; 51 + extern const struct plat_smp_ops bmips43xx_smp_ops; 52 + extern const struct plat_smp_ops bmips5000_smp_ops; 53 53 54 54 static inline int register_bmips_smp_ops(void) 55 55 {
+1 -1
arch/mips/include/asm/mach-loongson64/loongson.h
··· 26 26 /* environment arguments from bootloader */ 27 27 extern u32 cpu_clock_freq; 28 28 extern u32 memsize, highmemsize; 29 - extern struct plat_smp_ops loongson3_smp_ops; 29 + extern const struct plat_smp_ops loongson3_smp_ops; 30 30 31 31 /* loongson-specific command line, env and memory initialization */ 32 32 extern void __init prom_init_memory(void);
+1 -1
arch/mips/include/asm/netlogic/common.h
··· 84 84 */ 85 85 void nlm_init_boot_cpu(void); 86 86 unsigned int nlm_get_cpu_frequency(void); 87 - extern struct plat_smp_ops nlm_smp_ops; 87 + extern const struct plat_smp_ops nlm_smp_ops; 88 88 extern char nlm_reset_entry[], nlm_reset_entry_end[]; 89 89 90 90 /* SWIOTLB */
+6 -6
arch/mips/include/asm/smp-ops.h
··· 35 35 #endif 36 36 }; 37 37 38 - extern void register_smp_ops(struct plat_smp_ops *ops); 38 + extern void register_smp_ops(const struct plat_smp_ops *ops); 39 39 40 40 static inline void plat_smp_setup(void) 41 41 { 42 - extern struct plat_smp_ops *mp_ops; /* private */ 42 + extern const struct plat_smp_ops *mp_ops; /* private */ 43 43 44 44 mp_ops->smp_setup(); 45 45 } ··· 57 57 /* UP, nothing to do ... */ 58 58 } 59 59 60 - static inline void register_smp_ops(struct plat_smp_ops *ops) 60 + static inline void register_smp_ops(const struct plat_smp_ops *ops) 61 61 { 62 62 } 63 63 ··· 66 66 static inline int register_up_smp_ops(void) 67 67 { 68 68 #ifdef CONFIG_SMP_UP 69 - extern struct plat_smp_ops up_smp_ops; 69 + extern const struct plat_smp_ops up_smp_ops; 70 70 71 71 register_smp_ops(&up_smp_ops); 72 72 ··· 79 79 static inline int register_cmp_smp_ops(void) 80 80 { 81 81 #ifdef CONFIG_MIPS_CMP 82 - extern struct plat_smp_ops cmp_smp_ops; 82 + extern const struct plat_smp_ops cmp_smp_ops; 83 83 84 84 if (!mips_cm_present()) 85 85 return -ENODEV; ··· 95 95 static inline int register_vsmp_smp_ops(void) 96 96 { 97 97 #ifdef CONFIG_MIPS_MT_SMP 98 - extern struct plat_smp_ops vsmp_smp_ops; 98 + extern const struct plat_smp_ops vsmp_smp_ops; 99 99 100 100 register_smp_ops(&vsmp_smp_ops); 101 101
+5 -5
arch/mips/include/asm/smp.h
··· 58 58 */ 59 59 static inline void smp_send_reschedule(int cpu) 60 60 { 61 - extern struct plat_smp_ops *mp_ops; /* private */ 61 + extern const struct plat_smp_ops *mp_ops; /* private */ 62 62 63 63 mp_ops->send_ipi_single(cpu, SMP_RESCHEDULE_YOURSELF); 64 64 } ··· 66 66 #ifdef CONFIG_HOTPLUG_CPU 67 67 static inline int __cpu_disable(void) 68 68 { 69 - extern struct plat_smp_ops *mp_ops; /* private */ 69 + extern const struct plat_smp_ops *mp_ops; /* private */ 70 70 71 71 return mp_ops->cpu_disable(); 72 72 } 73 73 74 74 static inline void __cpu_die(unsigned int cpu) 75 75 { 76 - extern struct plat_smp_ops *mp_ops; /* private */ 76 + extern const struct plat_smp_ops *mp_ops; /* private */ 77 77 78 78 mp_ops->cpu_die(cpu); 79 79 } ··· 97 97 98 98 static inline void arch_send_call_function_single_ipi(int cpu) 99 99 { 100 - extern struct plat_smp_ops *mp_ops; /* private */ 100 + extern const struct plat_smp_ops *mp_ops; /* private */ 101 101 102 102 mp_ops->send_ipi_mask(cpumask_of(cpu), SMP_CALL_FUNCTION); 103 103 } 104 104 105 105 static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask) 106 106 { 107 - extern struct plat_smp_ops *mp_ops; /* private */ 107 + extern const struct plat_smp_ops *mp_ops; /* private */ 108 108 109 109 mp_ops->send_ipi_mask(mask, SMP_CALL_FUNCTION); 110 110 }
+2 -2
arch/mips/kernel/smp-bmips.c
··· 409 409 410 410 #endif /* CONFIG_HOTPLUG_CPU */ 411 411 412 - struct plat_smp_ops bmips43xx_smp_ops = { 412 + const struct plat_smp_ops bmips43xx_smp_ops = { 413 413 .smp_setup = bmips_smp_setup, 414 414 .prepare_cpus = bmips_prepare_cpus, 415 415 .boot_secondary = bmips_boot_secondary, ··· 423 423 #endif 424 424 }; 425 425 426 - struct plat_smp_ops bmips5000_smp_ops = { 426 + const struct plat_smp_ops bmips5000_smp_ops = { 427 427 .smp_setup = bmips_smp_setup, 428 428 .prepare_cpus = bmips_prepare_cpus, 429 429 .boot_secondary = bmips_boot_secondary,
+1 -1
arch/mips/kernel/smp-cmp.c
··· 148 148 149 149 } 150 150 151 - struct plat_smp_ops cmp_smp_ops = { 151 + const struct plat_smp_ops cmp_smp_ops = { 152 152 .send_ipi_single = mips_smp_send_ipi_single, 153 153 .send_ipi_mask = mips_smp_send_ipi_mask, 154 154 .init_secondary = cmp_init_secondary,
+2 -2
arch/mips/kernel/smp-cps.c
··· 571 571 572 572 #endif /* CONFIG_HOTPLUG_CPU */ 573 573 574 - static struct plat_smp_ops cps_smp_ops = { 574 + static const struct plat_smp_ops cps_smp_ops = { 575 575 .smp_setup = cps_smp_setup, 576 576 .prepare_cpus = cps_prepare_cpus, 577 577 .boot_secondary = cps_boot_secondary, ··· 587 587 588 588 bool mips_cps_smp_in_use(void) 589 589 { 590 - extern struct plat_smp_ops *mp_ops; 590 + extern const struct plat_smp_ops *mp_ops; 591 591 return mp_ops == &cps_smp_ops; 592 592 } 593 593
+1 -1
arch/mips/kernel/smp-mt.c
··· 239 239 mips_mt_set_cpuoptions(); 240 240 } 241 241 242 - struct plat_smp_ops vsmp_smp_ops = { 242 + const struct plat_smp_ops vsmp_smp_ops = { 243 243 .send_ipi_single = mips_smp_send_ipi_single, 244 244 .send_ipi_mask = mips_smp_send_ipi_mask, 245 245 .init_secondary = vsmp_init_secondary,
+1 -1
arch/mips/kernel/smp-up.c
··· 63 63 } 64 64 #endif 65 65 66 - struct plat_smp_ops up_smp_ops = { 66 + const struct plat_smp_ops up_smp_ops = { 67 67 .send_ipi_single = up_send_ipi_single, 68 68 .send_ipi_mask = up_send_ipi_mask, 69 69 .init_secondary = up_init_secondary,
+2 -2
arch/mips/kernel/smp.c
··· 146 146 &temp_foreign_map, &cpu_sibling_map[i]); 147 147 } 148 148 149 - struct plat_smp_ops *mp_ops; 149 + const struct plat_smp_ops *mp_ops; 150 150 EXPORT_SYMBOL(mp_ops); 151 151 152 - void register_smp_ops(struct plat_smp_ops *ops) 152 + void register_smp_ops(const struct plat_smp_ops *ops) 153 153 { 154 154 if (mp_ops) 155 155 printk(KERN_WARNING "Overriding previously set SMP ops\n");
+1 -1
arch/mips/loongson64/loongson-3/smp.c
··· 734 734 735 735 #endif 736 736 737 - struct plat_smp_ops loongson3_smp_ops = { 737 + const struct plat_smp_ops loongson3_smp_ops = { 738 738 .send_ipi_single = loongson3_send_ipi_single, 739 739 .send_ipi_mask = loongson3_send_ipi_mask, 740 740 .init_secondary = loongson3_init_secondary,
+1 -1
arch/mips/netlogic/common/smp.c
··· 272 272 return 0; 273 273 } 274 274 275 - struct plat_smp_ops nlm_smp_ops = { 275 + const struct plat_smp_ops nlm_smp_ops = { 276 276 .send_ipi_single = nlm_send_ipi_single, 277 277 .send_ipi_mask = nlm_send_ipi_mask, 278 278 .init_secondary = nlm_init_secondary,
+1 -1
arch/mips/paravirt/paravirt-smp.c
··· 133 133 } 134 134 } 135 135 136 - struct plat_smp_ops paravirt_smp_ops = { 136 + const struct plat_smp_ops paravirt_smp_ops = { 137 137 .send_ipi_single = paravirt_send_ipi_single, 138 138 .send_ipi_mask = paravirt_send_ipi_mask, 139 139 .init_secondary = paravirt_init_secondary,
+1 -1
arch/mips/paravirt/setup.c
··· 14 14 #include <asm/smp-ops.h> 15 15 #include <asm/time.h> 16 16 17 - extern struct plat_smp_ops paravirt_smp_ops; 17 + extern const struct plat_smp_ops paravirt_smp_ops; 18 18 19 19 const char *get_system_type(void) 20 20 {
+1 -1
arch/mips/sgi-ip27/ip27-smp.c
··· 231 231 /* We already did everything necessary earlier */ 232 232 } 233 233 234 - struct plat_smp_ops ip27_smp_ops = { 234 + const struct plat_smp_ops ip27_smp_ops = { 235 235 .send_ipi_single = ip27_send_ipi_single, 236 236 .send_ipi_mask = ip27_send_ipi_mask, 237 237 .init_secondary = ip27_init_secondary,
+1 -1
arch/mips/sibyte/bcm1480/smp.c
··· 157 157 { 158 158 } 159 159 160 - struct plat_smp_ops bcm1480_smp_ops = { 160 + const struct plat_smp_ops bcm1480_smp_ops = { 161 161 .send_ipi_single = bcm1480_send_ipi_single, 162 162 .send_ipi_mask = bcm1480_send_ipi_mask, 163 163 .init_secondary = bcm1480_init_secondary,
+2 -2
arch/mips/sibyte/common/cfe.c
··· 229 229 230 230 #endif 231 231 232 - extern struct plat_smp_ops sb_smp_ops; 233 - extern struct plat_smp_ops bcm1480_smp_ops; 232 + extern const struct plat_smp_ops sb_smp_ops; 233 + extern const struct plat_smp_ops bcm1480_smp_ops; 234 234 235 235 /* 236 236 * prom_init is called just after the cpu type is determined, from setup_arch()
+1 -1
arch/mips/sibyte/sb1250/smp.c
··· 146 146 { 147 147 } 148 148 149 - struct plat_smp_ops sb_smp_ops = { 149 + const struct plat_smp_ops sb_smp_ops = { 150 150 .send_ipi_single = sb1250_send_ipi_single, 151 151 .send_ipi_mask = sb1250_send_ipi_mask, 152 152 .init_secondary = sb1250_init_secondary,