MIPS: SMP: Constify smp ops
authorMatt Redfearn <matt.redfearn@imgtec.com>
Wed, 19 Jul 2017 08:21:03 +0000 (09:21 +0100)
committerRalf Baechle <ralf@linux-mips.org>
Tue, 29 Aug 2017 13:21:50 +0000 (15:21 +0200)
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>
21 files changed:
arch/mips/cavium-octeon/smp.c
arch/mips/fw/arc/init.c
arch/mips/include/asm/bmips.h
arch/mips/include/asm/mach-loongson64/loongson.h
arch/mips/include/asm/netlogic/common.h
arch/mips/include/asm/smp-ops.h
arch/mips/include/asm/smp.h
arch/mips/kernel/smp-bmips.c
arch/mips/kernel/smp-cmp.c
arch/mips/kernel/smp-cps.c
arch/mips/kernel/smp-mt.c
arch/mips/kernel/smp-up.c
arch/mips/kernel/smp.c
arch/mips/loongson64/loongson-3/smp.c
arch/mips/netlogic/common/smp.c
arch/mips/paravirt/paravirt-smp.c
arch/mips/paravirt/setup.c
arch/mips/sgi-ip27/ip27-smp.c
arch/mips/sibyte/bcm1480/smp.c
arch/mips/sibyte/common/cfe.c
arch/mips/sibyte/sb1250/smp.c

index 3de7865..163663a 100644 (file)
@@ -408,7 +408,7 @@ late_initcall(register_cavium_notifier);
 
 #endif /* CONFIG_HOTPLUG_CPU */
 
-struct plat_smp_ops octeon_smp_ops = {
+const struct plat_smp_ops octeon_smp_ops = {
        .send_ipi_single        = octeon_send_ipi_single,
        .send_ipi_mask          = octeon_send_ipi_mask,
        .init_secondary         = octeon_init_secondary,
@@ -485,7 +485,7 @@ static void octeon_78xx_send_ipi_mask(const struct cpumask *mask,
                octeon_78xx_send_ipi_single(cpu, action);
 }
 
-static struct plat_smp_ops octeon_78xx_smp_ops = {
+static const struct plat_smp_ops octeon_78xx_smp_ops = {
        .send_ipi_single        = octeon_78xx_send_ipi_single,
        .send_ipi_mask          = octeon_78xx_send_ipi_mask,
        .init_secondary         = octeon_init_secondary,
@@ -501,7 +501,7 @@ static struct plat_smp_ops octeon_78xx_smp_ops = {
 
 void __init octeon_setup_smp(void)
 {
-       struct plat_smp_ops *ops;
+       const struct plat_smp_ops *ops;
 
        if (octeon_has_feature(OCTEON_FEATURE_CIU3))
                ops = &octeon_78xx_smp_ops;
index 629b24d..0085559 100644 (file)
@@ -51,7 +51,7 @@ void __init prom_init(void)
 #endif
 #ifdef CONFIG_SGI_IP27
        {
-               extern struct plat_smp_ops ip27_smp_ops;
+               extern const struct plat_smp_ops ip27_smp_ops;
 
                register_smp_ops(&ip27_smp_ops);
        }
index a92aee7..b3e2975 100644 (file)
@@ -48,8 +48,8 @@
 #include <asm/r4kcache.h>
 #include <asm/smp-ops.h>
 
-extern struct plat_smp_ops bmips43xx_smp_ops;
-extern struct plat_smp_ops bmips5000_smp_ops;
+extern const struct plat_smp_ops bmips43xx_smp_ops;
+extern const struct plat_smp_ops bmips5000_smp_ops;
 
 static inline int register_bmips_smp_ops(void)
 {
index c68c0cc..d0ae5d5 100644 (file)
@@ -26,7 +26,7 @@ extern void mach_prepare_shutdown(void);
 /* environment arguments from bootloader */
 extern u32 cpu_clock_freq;
 extern u32 memsize, highmemsize;
-extern struct plat_smp_ops loongson3_smp_ops;
+extern const struct plat_smp_ops loongson3_smp_ops;
 
 /* loongson-specific command line, env and memory initialization */
 extern void __init prom_init_memory(void);
index e0717d1..a6e6cbe 100644 (file)
@@ -84,7 +84,7 @@ nlm_set_nmi_handler(void *handler)
  */
 void nlm_init_boot_cpu(void);
 unsigned int nlm_get_cpu_frequency(void);
-extern struct plat_smp_ops nlm_smp_ops;
+extern const struct plat_smp_ops nlm_smp_ops;
 extern char nlm_reset_entry[], nlm_reset_entry_end[];
 
 /* SWIOTLB */
index db7c322..38859e7 100644 (file)
@@ -35,11 +35,11 @@ struct plat_smp_ops {
 #endif
 };
 
-extern void register_smp_ops(struct plat_smp_ops *ops);
+extern void register_smp_ops(const struct plat_smp_ops *ops);
 
 static inline void plat_smp_setup(void)
 {
-       extern struct plat_smp_ops *mp_ops;     /* private */
+       extern const struct plat_smp_ops *mp_ops;       /* private */
 
        mp_ops->smp_setup();
 }
@@ -57,7 +57,7 @@ static inline void plat_smp_setup(void)
        /* UP, nothing to do ...  */
 }
 
-static inline void register_smp_ops(struct plat_smp_ops *ops)
+static inline void register_smp_ops(const struct plat_smp_ops *ops)
 {
 }
 
@@ -66,7 +66,7 @@ static inline void register_smp_ops(struct plat_smp_ops *ops)
 static inline int register_up_smp_ops(void)
 {
 #ifdef CONFIG_SMP_UP
-       extern struct plat_smp_ops up_smp_ops;
+       extern const struct plat_smp_ops up_smp_ops;
 
        register_smp_ops(&up_smp_ops);
 
@@ -79,7 +79,7 @@ static inline int register_up_smp_ops(void)
 static inline int register_cmp_smp_ops(void)
 {
 #ifdef CONFIG_MIPS_CMP
-       extern struct plat_smp_ops cmp_smp_ops;
+       extern const struct plat_smp_ops cmp_smp_ops;
 
        if (!mips_cm_present())
                return -ENODEV;
@@ -95,7 +95,7 @@ static inline int register_cmp_smp_ops(void)
 static inline int register_vsmp_smp_ops(void)
 {
 #ifdef CONFIG_MIPS_MT_SMP
-       extern struct plat_smp_ops vsmp_smp_ops;
+       extern const struct plat_smp_ops vsmp_smp_ops;
 
        register_smp_ops(&vsmp_smp_ops);
 
index bab3d41..9e494f8 100644 (file)
@@ -58,7 +58,7 @@ extern void calculate_cpu_foreign_map(void);
  */
 static inline void smp_send_reschedule(int cpu)
 {
-       extern struct plat_smp_ops *mp_ops;     /* private */
+       extern const struct plat_smp_ops *mp_ops;       /* private */
 
        mp_ops->send_ipi_single(cpu, SMP_RESCHEDULE_YOURSELF);
 }
@@ -66,14 +66,14 @@ static inline void smp_send_reschedule(int cpu)
 #ifdef CONFIG_HOTPLUG_CPU
 static inline int __cpu_disable(void)
 {
-       extern struct plat_smp_ops *mp_ops;     /* private */
+       extern const struct plat_smp_ops *mp_ops;       /* private */
 
        return mp_ops->cpu_disable();
 }
 
 static inline void __cpu_die(unsigned int cpu)
 {
-       extern struct plat_smp_ops *mp_ops;     /* private */
+       extern const struct plat_smp_ops *mp_ops;       /* private */
 
        mp_ops->cpu_die(cpu);
 }
@@ -97,14 +97,14 @@ int mips_smp_ipi_free(const struct cpumask *mask);
 
 static inline void arch_send_call_function_single_ipi(int cpu)
 {
-       extern struct plat_smp_ops *mp_ops;     /* private */
+       extern const struct plat_smp_ops *mp_ops;       /* private */
 
        mp_ops->send_ipi_mask(cpumask_of(cpu), SMP_CALL_FUNCTION);
 }
 
 static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
 {
-       extern struct plat_smp_ops *mp_ops;     /* private */
+       extern const struct plat_smp_ops *mp_ops;       /* private */
 
        mp_ops->send_ipi_mask(mask, SMP_CALL_FUNCTION);
 }
index 1b070a7..f86d755 100644 (file)
@@ -409,7 +409,7 @@ void __ref play_dead(void)
 
 #endif /* CONFIG_HOTPLUG_CPU */
 
-struct plat_smp_ops bmips43xx_smp_ops = {
+const struct plat_smp_ops bmips43xx_smp_ops = {
        .smp_setup              = bmips_smp_setup,
        .prepare_cpus           = bmips_prepare_cpus,
        .boot_secondary         = bmips_boot_secondary,
@@ -423,7 +423,7 @@ struct plat_smp_ops bmips43xx_smp_ops = {
 #endif
 };
 
-struct plat_smp_ops bmips5000_smp_ops = {
+const struct plat_smp_ops bmips5000_smp_ops = {
        .smp_setup              = bmips_smp_setup,
        .prepare_cpus           = bmips_prepare_cpus,
        .boot_secondary         = bmips_boot_secondary,
index 7692334..1acffde 100644 (file)
@@ -148,7 +148,7 @@ void __init cmp_prepare_cpus(unsigned int max_cpus)
 
 }
 
-struct plat_smp_ops cmp_smp_ops = {
+const struct plat_smp_ops cmp_smp_ops = {
        .send_ipi_single        = mips_smp_send_ipi_single,
        .send_ipi_mask          = mips_smp_send_ipi_mask,
        .init_secondary         = cmp_init_secondary,
index f832e99..a6b8700 100644 (file)
@@ -571,7 +571,7 @@ static void cps_cpu_die(unsigned int cpu)
 
 #endif /* CONFIG_HOTPLUG_CPU */
 
-static struct plat_smp_ops cps_smp_ops = {
+static const struct plat_smp_ops cps_smp_ops = {
        .smp_setup              = cps_smp_setup,
        .prepare_cpus           = cps_prepare_cpus,
        .boot_secondary         = cps_boot_secondary,
@@ -587,7 +587,7 @@ static struct plat_smp_ops cps_smp_ops = {
 
 bool mips_cps_smp_in_use(void)
 {
-       extern struct plat_smp_ops *mp_ops;
+       extern const struct plat_smp_ops *mp_ops;
        return mp_ops == &cps_smp_ops;
 }
 
index ed6b4df..004ff5e 100644 (file)
@@ -239,7 +239,7 @@ static void __init vsmp_prepare_cpus(unsigned int max_cpus)
        mips_mt_set_cpuoptions();
 }
 
-struct plat_smp_ops vsmp_smp_ops = {
+const struct plat_smp_ops vsmp_smp_ops = {
        .send_ipi_single        = mips_smp_send_ipi_single,
        .send_ipi_mask          = mips_smp_send_ipi_mask,
        .init_secondary         = vsmp_init_secondary,
index 17878d7..4cf015a 100644 (file)
@@ -63,7 +63,7 @@ static void up_cpu_die(unsigned int cpu)
 }
 #endif
 
-struct plat_smp_ops up_smp_ops = {
+const struct plat_smp_ops up_smp_ops = {
        .send_ipi_single        = up_send_ipi_single,
        .send_ipi_mask          = up_send_ipi_mask,
        .init_secondary         = up_init_secondary,
index 6bace76..20c1f9a 100644 (file)
@@ -146,10 +146,10 @@ void calculate_cpu_foreign_map(void)
                               &temp_foreign_map, &cpu_sibling_map[i]);
 }
 
-struct plat_smp_ops *mp_ops;
+const struct plat_smp_ops *mp_ops;
 EXPORT_SYMBOL(mp_ops);
 
-void register_smp_ops(struct plat_smp_ops *ops)
+void register_smp_ops(const struct plat_smp_ops *ops)
 {
        if (mp_ops)
                printk(KERN_WARNING "Overriding previously set SMP ops\n");
index b7a355c..5b5a44f 100644 (file)
@@ -734,7 +734,7 @@ early_initcall(register_loongson3_notifier);
 
 #endif
 
-struct plat_smp_ops loongson3_smp_ops = {
+const struct plat_smp_ops loongson3_smp_ops = {
        .send_ipi_single = loongson3_send_ipi_single,
        .send_ipi_mask = loongson3_send_ipi_mask,
        .init_secondary = loongson3_init_secondary,
index bddf1ef..eac3f29 100644 (file)
@@ -272,7 +272,7 @@ int nlm_wakeup_secondary_cpus(void)
        return 0;
 }
 
-struct plat_smp_ops nlm_smp_ops = {
+const struct plat_smp_ops nlm_smp_ops = {
        .send_ipi_single        = nlm_send_ipi_single,
        .send_ipi_mask          = nlm_send_ipi_mask,
        .init_secondary         = nlm_init_secondary,
index 72eb1a5..b61b26c 100644 (file)
@@ -133,7 +133,7 @@ static void paravirt_prepare_cpus(unsigned int max_cpus)
        }
 }
 
-struct plat_smp_ops paravirt_smp_ops = {
+const struct plat_smp_ops paravirt_smp_ops = {
        .send_ipi_single        = paravirt_send_ipi_single,
        .send_ipi_mask          = paravirt_send_ipi_mask,
        .init_secondary         = paravirt_init_secondary,
index cb8448b..d2ffec1 100644 (file)
@@ -14,7 +14,7 @@
 #include <asm/smp-ops.h>
 #include <asm/time.h>
 
-extern struct plat_smp_ops paravirt_smp_ops;
+extern const struct plat_smp_ops paravirt_smp_ops;
 
 const char *get_system_type(void)
 {
index 4cd47d2..85ee974 100644 (file)
@@ -231,7 +231,7 @@ static void __init ip27_prepare_cpus(unsigned int max_cpus)
        /* We already did everything necessary earlier */
 }
 
-struct plat_smp_ops ip27_smp_ops = {
+const struct plat_smp_ops ip27_smp_ops = {
        .send_ipi_single        = ip27_send_ipi_single,
        .send_ipi_mask          = ip27_send_ipi_mask,
        .init_secondary         = ip27_init_secondary,
index d0e94ff..20091d5 100644 (file)
@@ -157,7 +157,7 @@ static void __init bcm1480_prepare_cpus(unsigned int max_cpus)
 {
 }
 
-struct plat_smp_ops bcm1480_smp_ops = {
+const struct plat_smp_ops bcm1480_smp_ops = {
        .send_ipi_single        = bcm1480_send_ipi_single,
        .send_ipi_mask          = bcm1480_send_ipi_mask,
        .init_secondary         = bcm1480_init_secondary,
index c1a11a1..1153992 100644 (file)
@@ -229,8 +229,8 @@ static int __init initrd_setup(char *str)
 
 #endif
 
-extern struct plat_smp_ops sb_smp_ops;
-extern struct plat_smp_ops bcm1480_smp_ops;
+extern const struct plat_smp_ops sb_smp_ops;
+extern const struct plat_smp_ops bcm1480_smp_ops;
 
 /*
  * prom_init is called just after the cpu type is determined, from setup_arch()
index 0a4a2c3..46ce129 100644 (file)
@@ -146,7 +146,7 @@ static void __init sb1250_prepare_cpus(unsigned int max_cpus)
 {
 }
 
-struct plat_smp_ops sb_smp_ops = {
+const struct plat_smp_ops sb_smp_ops = {
        .send_ipi_single        = sb1250_send_ipi_single,
        .send_ipi_mask          = sb1250_send_ipi_mask,
        .init_secondary         = sb1250_init_secondary,