linux-stable/arch/s390
Thomas Richter 21e8764487 s390/pai: Fix multiple concurrent event installation
Two different events such as pai_crypto/KM_AES_128/ and
pai_crypto/KM_AES_192/ can be installed multiple times on the same CPU
and the events are executed concurrently:

  # perf stat -e pai_crypto/KM_AES_128/  -C0 -a -- sleep 5 &
  # sleep 2
  # perf stat -e pai_crypto/KM_AES_192/ -C0 -a -- true

This results in the first event being installed two times with two seconds
delay. The kernel does install the second event after the first
event has been deleted and re-added, as can be seen in the traces:

 13:48:47.600350  paicrypt_start event 0x1007 (event KM_AES_128)
 13:48:49.599359  paicrypt_stop event 0x1007  (event KM_AES_128)
 13:48:49.599198  paicrypt_start event 0x1007
 13:48:49.599199  paicrypt_start event 0x1008
 13:48:49.599921  paicrypt_event_destroy event 0x1008
 13:48:52.601507  paicrypt_event_destroy event 0x1007

This is caused by functions event_sched_in() and event_sched_out() which
call the PMU's add() and start() functions on schedule_in and the PMU's
stop() and del() functions on schedule_out. This is correct for events
attached to processes.  The pai_crypto events are system-wide events
and not attached to processes.

Since the kernel common code can not be changed easily, fix this issue
and do not reset the event count value to zero each time the event is
added and started. Instead use a flag and zero the event count value
only when called immediately after the event has been initialized.
Therefore only the first invocation of the the event's add() function
initializes the event count value to zero. The following invocations
of the event's add() function leave the current event count value
untouched.

Fixes: 39d62336f5 ("s390/pai: add support for cryptography counters")

Reported-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
2022-06-23 17:24:00 +02:00
..
appldata
boot Kbuild updates for v5.19 2022-05-26 12:09:50 -07:00
configs s390: enable CONFIG_HARDENED_USERCOPY in debug_defconfig 2022-04-12 11:56:08 +02:00
crypto more s390 updates for 5.19 merge window 2022-06-03 13:57:50 -07:00
hypfs s390/hypfs: fix typos in comments 2022-05-06 20:45:13 +02:00
include more s390 updates for 5.19 merge window 2022-06-03 13:57:50 -07:00
kernel s390/pai: Fix multiple concurrent event installation 2022-06-23 17:24:00 +02:00
kvm Bitmap patches for 5.19-rc1 2022-06-04 14:04:27 -07:00
lib s390/alternatives: provide identical sized orginal/alternative sequences 2022-05-17 15:16:28 +02:00
mm virtio: replace arch_has_restricted_virtio_memory_access() 2022-06-06 08:22:01 +02:00
net s390/bpf: Fix typo in comment 2022-05-23 11:25:53 -07:00
pci s390/pci: add error record for CC 2 retries 2022-04-25 13:54:15 +02:00
purgatory s390/purgatory: workaround llvm's IAS limitations 2022-05-17 15:16:28 +02:00
tools s390: raise minimum supported machine generation to z10 2022-03-10 15:58:17 +01:00
Kbuild kbuild: use more subdir- for visiting subdirectories while cleaning 2021-10-24 13:49:46 +09:00
Kconfig xen: branch for v5.19-rc2 2022-06-10 09:57:11 -07:00
Kconfig.debug s390/Kconfig.debug: fix indentation 2022-06-01 12:03:15 +02:00
Makefile gcc-12: disable '-Warray-bounds' universally for now 2022-06-09 10:11:12 -07:00