Skip to content

Commit 21e8764

Browse files
Thomas RichterAlexander Gordeev
authored andcommitted
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: 39d6233 ("s390/pai: add support for cryptography counters") Reported-by: Sumanth Korikkar <[email protected]> Signed-off-by: Thomas Richter <[email protected]> Acked-by: Sumanth Korikkar <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent 541a496 commit 21e8764

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

arch/s390/kernel/perf_pai_crypto.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ static int paicrypt_event_init(struct perf_event *event)
209209
if (rc)
210210
return rc;
211211

212+
/* Event initialization sets last_tag to 0. When later on the events
213+
* are deleted and re-added, do not reset the event count value to zero.
214+
* Events are added, deleted and re-added when 2 or more events
215+
* are active at the same time.
216+
*/
217+
event->hw.last_tag = 0;
212218
cpump->event = event;
213219
event->destroy = paicrypt_event_destroy;
214220

@@ -243,9 +249,12 @@ static void paicrypt_start(struct perf_event *event, int flags)
243249
{
244250
u64 sum;
245251

246-
sum = paicrypt_getall(event); /* Get current value */
247-
local64_set(&event->hw.prev_count, sum);
248-
local64_set(&event->count, 0);
252+
if (!event->hw.last_tag) {
253+
event->hw.last_tag = 1;
254+
sum = paicrypt_getall(event); /* Get current value */
255+
local64_set(&event->count, 0);
256+
local64_set(&event->hw.prev_count, sum);
257+
}
249258
}
250259

251260
static int paicrypt_add(struct perf_event *event, int flags)

0 commit comments

Comments
 (0)