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>
68 lines
1.6 KiB
C
68 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef ARCH_S390_ENTRY_COMMON_H
|
|
#define ARCH_S390_ENTRY_COMMON_H
|
|
|
|
#include <linux/sched.h>
|
|
#include <linux/audit.h>
|
|
#include <linux/randomize_kstack.h>
|
|
#include <linux/processor.h>
|
|
#include <linux/uaccess.h>
|
|
#include <asm/timex.h>
|
|
#include <asm/fpu/api.h>
|
|
#include <asm/pai.h>
|
|
|
|
#define ARCH_EXIT_TO_USER_MODE_WORK (_TIF_GUARDED_STORAGE | _TIF_PER_TRAP)
|
|
|
|
void do_per_trap(struct pt_regs *regs);
|
|
|
|
static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs)
|
|
{
|
|
if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
|
|
debug_user_asce(0);
|
|
|
|
pai_kernel_enter(regs);
|
|
}
|
|
|
|
#define arch_enter_from_user_mode arch_enter_from_user_mode
|
|
|
|
static __always_inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
|
|
unsigned long ti_work)
|
|
{
|
|
if (ti_work & _TIF_PER_TRAP) {
|
|
clear_thread_flag(TIF_PER_TRAP);
|
|
do_per_trap(regs);
|
|
}
|
|
|
|
if (ti_work & _TIF_GUARDED_STORAGE)
|
|
gs_load_bc_cb(regs);
|
|
}
|
|
|
|
#define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
|
|
|
|
static __always_inline void arch_exit_to_user_mode(void)
|
|
{
|
|
if (test_cpu_flag(CIF_FPU))
|
|
__load_fpu_regs();
|
|
|
|
if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
|
|
debug_user_asce(1);
|
|
|
|
pai_kernel_exit(current_pt_regs());
|
|
}
|
|
|
|
#define arch_exit_to_user_mode arch_exit_to_user_mode
|
|
|
|
static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
|
|
unsigned long ti_work)
|
|
{
|
|
choose_random_kstack_offset(get_tod_clock_fast() & 0xff);
|
|
}
|
|
|
|
#define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
|
|
|
|
static inline bool on_thread_stack(void)
|
|
{
|
|
return !(((unsigned long)(current->stack) ^ current_stack_pointer) & ~(THREAD_SIZE - 1));
|
|
}
|
|
|
|
#endif
|