-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s390/pai: add support for cryptography counters
PMU device driver perf_pai_crypto supports Processor Activity Instrumentation (PAI), available with IBM z16: - maps a full page to lowcore address 0x1500. - uses CR0 bit 13 to turn PAI crypto counting on and off. - creates a sample with raw data on each context switch out when at context switch some mapped counters have a value of nonzero. This device driver only supports CPU wide context, no task context is allowed. Support for counting: - one or more counters can be specified using perf stat -e pai_crypto/xxx/ where xxx stands for the counter event name. Multiple invocation of this command is possible. The counter names are listed in /sys/devices/pai_crypto/events directory. - one special counters can be specified using perf stat -e pai_crypto/CRYPTO_ALL/ which returns the sum of all incremented crypto counters. - one event pai_crypto/CRYPTO_ALL/ is reserved for sampling. No multiple invocations are possible. The event collects data at context switch out and saves them in the ring buffer. Add qpaci assembly instruction to query supported memory mapped crypto counters. It returns the number of counters (no holes allowed in that range). The PAI crypto counter events are system wide and can not be executed in parallel. Therefore some restrictions documented in function paicrypt_busy apply. In particular event CRYPTO_ALL for sampling must run exclusive. Only counting events can run in parallel. PAI crypto counter events can not be created when a CPU hot plug add is processed. This means a CPU hot plug add does not get the necessary PAI event to record PAI cryptography counter increments on the newly added CPU. CPU hot plug remove removes the event and terminates the counting of PAI counters immediately. Co-developed-by: Sven Schnelle <svens@linux.ibm.com> Signed-off-by: Sven Schnelle <svens@linux.ibm.com> Reviewed-by: Juergen Christ <jchrist@linux.ibm.com> Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Link: https://lore.kernel.org/r/20220504062351.2954280-3-tmricht@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
- Loading branch information
Thomas Richter
authored and
Heiko Carstens
committed
May 9, 2022
1 parent
6d97af4
commit 39d6233
Showing
9 changed files
with
784 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* Processor Activity Instrumentation support for cryptography counters | ||
* | ||
* Copyright IBM Corp. 2022 | ||
* Author(s): Thomas Richter <tmricht@linux.ibm.com> | ||
*/ | ||
#ifndef _ASM_S390_PAI_H | ||
#define _ASM_S390_PAI_H | ||
|
||
#include <linux/jump_label.h> | ||
#include <asm/lowcore.h> | ||
#include <asm/ptrace.h> | ||
|
||
struct qpaci_info_block { | ||
u64 header; | ||
struct { | ||
u64 : 8; | ||
u64 num_cc : 8; /* # of supported crypto counters */ | ||
u64 : 48; | ||
}; | ||
}; | ||
|
||
static inline int qpaci(struct qpaci_info_block *info) | ||
{ | ||
/* Size of info (in double words minus one) */ | ||
size_t size = sizeof(*info) / sizeof(u64) - 1; | ||
int cc; | ||
|
||
asm volatile( | ||
" lgr 0,%[size]\n" | ||
" .insn s,0xb28f0000,%[info]\n" | ||
" lgr %[size],0\n" | ||
" ipm %[cc]\n" | ||
" srl %[cc],28\n" | ||
: [cc] "=d" (cc), [info] "=Q" (*info), [size] "+&d" (size) | ||
: | ||
: "0", "cc", "memory"); | ||
return cc ? (size + 1) * sizeof(u64) : 0; | ||
} | ||
|
||
#define PAI_CRYPTO_BASE 0x1000 /* First event number */ | ||
#define PAI_CRYPTO_MAXCTR 256 /* Max # of event counters */ | ||
#define PAI_CRYPTO_KERNEL_OFFSET 2048 | ||
|
||
DECLARE_STATIC_KEY_FALSE(pai_key); | ||
|
||
static __always_inline void pai_kernel_enter(struct pt_regs *regs) | ||
{ | ||
if (!IS_ENABLED(CONFIG_PERF_EVENTS)) | ||
return; | ||
if (!static_branch_unlikely(&pai_key)) | ||
return; | ||
if (!S390_lowcore.ccd) | ||
return; | ||
if (!user_mode(regs)) | ||
return; | ||
WRITE_ONCE(S390_lowcore.ccd, S390_lowcore.ccd | PAI_CRYPTO_KERNEL_OFFSET); | ||
} | ||
|
||
static __always_inline void pai_kernel_exit(struct pt_regs *regs) | ||
{ | ||
if (!IS_ENABLED(CONFIG_PERF_EVENTS)) | ||
return; | ||
if (!static_branch_unlikely(&pai_key)) | ||
return; | ||
if (!S390_lowcore.ccd) | ||
return; | ||
if (!user_mode(regs)) | ||
return; | ||
WRITE_ONCE(S390_lowcore.ccd, S390_lowcore.ccd & ~PAI_CRYPTO_KERNEL_OFFSET); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.