]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
MIPS: Fix perf event init
authorPaul Burton <paul.burton@imgtec.com>
Wed, 20 Sep 2017 05:07:18 +0000 (22:07 -0700)
committerRalf Baechle <ralf@linux-mips.org>
Wed, 20 Sep 2017 08:47:12 +0000 (10:47 +0200)
Commit c311c797998c ("cpumask: make "nr_cpumask_bits" unsigned")
modified mipspmu_event_init() to cast the struct perf_event cpu field to
an unsigned integer before it is compared with nr_cpumask_bits (and
*ahem* did so without copying the linux-mips mailing list or any MIPS
developers...). This is broken because the cpu field may be -1 for
events which follow a process rather than being affine to a particular
CPU. When this is the case the cast to an unsigned int results in a
value equal to ULONG_MAX, which is always greater than nr_cpumask_bits
so we always fail mipspmu_event_init() and return -ENODEV.

The check against nr_cpumask_bits seems nonsensical anyway, so this
patch simply removes it. The cpu field is going to either be -1 or a
valid CPU number. Comparing it with nr_cpumask_bits is effectively
checking that it's a valid cpu number, but it seems safe to rely on the
core perf events code to ensure that's the case.

The end result is that this fixes use of perf on MIPS when not
constraining events to a particular CPU, and fixes the "perf list hw"
command which fails to list any events without this.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Fixes: c311c797998c ("cpumask: make "nr_cpumask_bits" unsigned")
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mips@linux-mips.org
Cc: stable <stable@vger.kernel.org> # v4.12+
Patchwork: https://patchwork.linux-mips.org/patch/17323/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/kernel/perf_event_mipsxx.c

index 9e6c74bf66c485cc3c1a23ee1d298c1b6f81dad5..6668f67a61c3a2bb09fc23d9e2172d7a738020e1 100644 (file)
@@ -618,8 +618,7 @@ static int mipspmu_event_init(struct perf_event *event)
                return -ENOENT;
        }
 
-       if ((unsigned int)event->cpu >= nr_cpumask_bits ||
-           (event->cpu >= 0 && !cpu_online(event->cpu)))
+       if (event->cpu >= 0 && !cpu_online(event->cpu))
                return -ENODEV;
 
        if (!atomic_inc_not_zero(&active_events)) {