Skip to content

Commit

Permalink
s390/perf: fix bug when creating per-thread event
Browse files Browse the repository at this point in the history
A per-thread event could not be created correctly like below:

    perf record --per-thread -e rB0000 -- sleep 1
    Error:
    The sys_perf_event_open() syscall returned with 19 (No such device) for event (rB0000).
    /bin/dmesg may provide additional information.
    No CONFIG_PERF_EVENTS=y kernel support configured?

This bug was introduced by:

    commit c311c79
    Author: Alexey Dobriyan <adobriyan@gmail.com>
    Date:   Mon May 8 15:56:15 2017 -0700

    cpumask: make "nr_cpumask_bits" unsigned

If a per-thread event is not attached to any CPU, the cpu field
in struct perf_event is -1. The above commit converts the CPU number
to unsigned int, which result in an illegal CPU number.

Fixes: c311c79 ("cpumask: make "nr_cpumask_bits" unsigned")
Cc: <stable@vger.kernel.org> # v4.12+
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Pu Hou <bjhoupu@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
Pu Hou authored and Martin Schwidefsky committed Sep 13, 2017
1 parent 6d8ef53 commit fc3100d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions arch/s390/kernel/perf_cpum_sf.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,12 @@ static int cpumsf_pmu_event_init(struct perf_event *event)
}

/* Check online status of the CPU to which the event is pinned */
if ((unsigned int)event->cpu >= nr_cpumask_bits ||
(event->cpu >= 0 && !cpu_online(event->cpu)))
return -ENODEV;
if (event->cpu >= 0) {
if ((unsigned int)event->cpu >= nr_cpumask_bits)
return -ENODEV;
if (!cpu_online(event->cpu))
return -ENODEV;
}

/* Force reset of idle/hv excludes regardless of what the
* user requested.
Expand Down

0 comments on commit fc3100d

Please sign in to comment.