sparc64: Fix pcr_ops initialization and usage bugs.
authorDavid S. Miller <davem@davemloft.net>
Mon, 11 Aug 2014 22:38:46 +0000 (15:38 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 12 Aug 2014 03:45:12 +0000 (20:45 -0700)
Christopher reports that perf_event_print_debug() can crash in uniprocessor
builds.  The crash is due to pcr_ops being NULL.

This happens because pcr_arch_init() is only invoked by smp_cpus_done() which
only executes in SMP builds.

init_hw_perf_events() is closely intertwined with pcr_ops being setup properly,
therefore:

1) Call pcr_arch_init() early on from init_hw_perf_events(), instead of
   from smp_cpus_done().

2) Do not hook up a PMU type if pcr_ops is NULL after pcr_arch_init().

3) Move init_hw_perf_events to a later initcall so that it we will be
   sure to invoke pcr_arch_init() after all cpus are brought up.

Finally, guard the one naked sequence of pcr_ops dereferences in
__global_pmu_self() with an appropriate NULL check.

Reported-by: Christopher Alexander Tobias Schulze <cat.schulze@alice-dsl.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/sparc/kernel/perf_event.c
arch/sparc/kernel/process_64.c
arch/sparc/kernel/smp_64.c

index 8efd33753ad33a6fcc7cee5cbe80c1f5080b38bd..d35c490a91cb2952e6fa047591a5760087c966fe 100644 (file)
@@ -1671,9 +1671,12 @@ static bool __init supported_pmu(void)
 
 static int __init init_hw_perf_events(void)
 {
+       int err;
+
        pr_info("Performance events: ");
 
-       if (!supported_pmu()) {
+       err = pcr_arch_init();
+       if (err || !supported_pmu()) {
                pr_cont("No support for PMU type '%s'\n", sparc_pmu_type);
                return 0;
        }
@@ -1685,7 +1688,7 @@ static int __init init_hw_perf_events(void)
 
        return 0;
 }
-early_initcall(init_hw_perf_events);
+pure_initcall(init_hw_perf_events);
 
 void perf_callchain_kernel(struct perf_callchain_entry *entry,
                           struct pt_regs *regs)
index 027e099861947655bc59583b0f2a715ac1fb10f2..0be7bf978cb1da03b8d657958ec6d0ec3c4e7d8b 100644 (file)
@@ -312,6 +312,9 @@ static void __global_pmu_self(int this_cpu)
        struct global_pmu_snapshot *pp;
        int i, num;
 
+       if (!pcr_ops)
+               return;
+
        pp = &global_cpu_snapshot[this_cpu].pmu;
 
        num = 1;
index 41aa2478f3ca7951c1448393ffd9ef26929f19e1..f7ba87543e5ff092e723a14cf6df8403e343ac4c 100644 (file)
@@ -1383,7 +1383,6 @@ void __cpu_die(unsigned int cpu)
 
 void __init smp_cpus_done(unsigned int max_cpus)
 {
-       pcr_arch_init();
 }
 
 void smp_send_reschedule(int cpu)