linux-stable/arch/s390
Thomas Richter 696c3ede89 s390/cpum_cf: Reject request for sampling in event initialization
[ Upstream commit 613a41b0d1 ]

On s390 command perf top fails
[root@s35lp76 perf] # ./perf top -F100000  --stdio
   Error:
   cycles: PMU Hardware doesn't support sampling/overflow-interrupts.
   	Try 'perf stat'
[root@s35lp76 perf] #

Using event -e rb0000 works as designed.  Event rb0000 is the event
number of the sampling facility for basic sampling.

During system start up the following PMUs are installed in the kernel's
PMU list (from head to tail):
   cpum_cf --> s390 PMU counter facility device driver
   cpum_sf --> s390 PMU sampling facility device driver
   uprobe
   kprobe
   tracepoint
   task_clock
   cpu_clock

Perf top executes following functions and calls perf_event_open(2) system
call with different parameters many times:

cmd_top
--> __cmd_top
    --> perf_evlist__add_default
        --> __perf_evlist__add_default
            --> perf_evlist__new_cycles (creates event type:0 (HW)
			    		config 0 (CPU_CYCLES)
	        --> perf_event_attr__set_max_precise_ip
		    Uses perf_event_open(2) to detect correct
		    precise_ip level. Fails 3 times on s390 which is ok.

Then functions cmd_top
--> __cmd_top
    --> perf_top__start_counters
        -->perf_evlist__config
	   --> perf_can_comm_exec
               --> perf_probe_api
	           This functions test support for the following events:
		   "cycles:u", "instructions:u", "cpu-clock:u" using
		   --> perf_do_probe_api
		       --> perf_event_open_cloexec
		           Test the close on exec flag support with
			   perf_event_open(2).
	               perf_do_probe_api returns true if the event is
		       supported.
		       The function returns true because event cpu-clock is
		       supported by the PMU cpu_clock.
	               This is achieved by many calls to perf_event_open(2).

Function perf_top__start_counters now calls perf_evsel__open() for every
event, which is the default event cpu_cycles (config:0) and type HARDWARE
(type:0) which a predfined frequence of 4000.

Given the above order of the PMU list, the PMU cpum_cf gets called first
and returns 0, which indicates support for this sampling. The event is
fully allocated in the function perf_event_open (file kernel/event/core.c
near line 10521 and the following check fails:

        event = perf_event_alloc(&attr, cpu, task, group_leader, NULL,
		                 NULL, NULL, cgroup_fd);
	if (IS_ERR(event)) {
		err = PTR_ERR(event);
		goto err_cred;
	}

        if (is_sampling_event(event)) {
		if (event->pmu->capabilities & PERF_PMU_CAP_NO_INTERRUPT) {
			err = -EOPNOTSUPP;
			goto err_alloc;
		}
	}

The check for the interrupt capabilities fails and the system call
perf_event_open() returns -EOPNOTSUPP (-95).

Add a check to return -ENODEV when sampling is requested in PMU cpum_cf.
This allows common kernel code in the perf_event_open() system call to
test the next PMU in above list.

Fixes: 97b1198fec (" "s390, perf: Use common PMU interrupt disabled code")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2018-12-17 09:38:32 +01:00
..
appldata sched/cputime: Convert kcpustat to nsecs 2018-10-20 09:51:32 +02:00
boot s390/decompressor: fix initrd corruption caused by bss clear 2017-04-12 12:41:14 +02:00
configs Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux 2016-10-04 14:05:52 -07:00
crypto s390/crc32-vx: use expoline for indirect branches 2018-05-25 16:12:57 +02:00
hypfs hypfs_kill_super(): deal with failed allocations 2018-04-24 09:34:17 +02:00
include s390/qdio: reset old sbal_state flags 2018-09-05 09:20:10 +02:00
kernel s390/cpum_cf: Reject request for sampling in event initialization 2018-12-17 09:38:32 +01:00
kvm s390/sthyi: Fix machine name validity indication 2018-11-13 11:16:49 -08:00
lib s390/lib: use expoline for all bcr instructions 2018-09-15 09:43:06 +02:00
mm s390/mm: Check for valid vma before zapping in gmap_discard 2018-12-01 09:44:25 +01:00
net s390: fix br_r1_trampoline for machines without exrl 2018-09-05 09:20:10 +02:00
numa s390/mm: Fix ERROR: "__node_distance" undefined! 2018-11-27 16:09:39 +01:00
oprofile s390/dumpstack: restore reliable indicator for call traces 2016-10-17 14:44:30 +02:00
pci s390/pci: fix out of bounds access during irq setup 2018-09-05 09:20:10 +02:00
tools s390/facilities: do not generate DWORDS define anymore 2016-07-31 05:27:59 -04:00
defconfig mm/usercopy: get rid of CONFIG_DEBUG_STRICT_USER_COPY_CHECKS 2016-08-30 10:10:21 -07:00
Kbuild
Kconfig s390: add sysfs attributes for spectre 2018-04-29 11:32:00 +02:00
Kconfig.debug arch: consolidate CONFIG_STRICT_DEVM in lib/Kconfig.debug 2016-01-09 06:30:49 -08:00
Makefile s390: add automatic detection of the spectre defense 2018-04-29 11:31:59 +02:00