Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Processor Activity Instrumentation support for cryptography counters
0004  *
0005  *  Copyright IBM Corp. 2022
0006  *  Author(s): Thomas Richter <tmricht@linux.ibm.com>
0007  */
0008 #ifndef _ASM_S390_PAI_H
0009 #define _ASM_S390_PAI_H
0010 
0011 #include <linux/jump_label.h>
0012 #include <asm/lowcore.h>
0013 #include <asm/ptrace.h>
0014 
0015 struct qpaci_info_block {
0016     u64 header;
0017     struct {
0018         u64 : 8;
0019         u64 num_cc : 8; /* # of supported crypto counters */
0020         u64 : 48;
0021     };
0022 };
0023 
0024 static inline int qpaci(struct qpaci_info_block *info)
0025 {
0026     /* Size of info (in double words minus one) */
0027     size_t size = sizeof(*info) / sizeof(u64) - 1;
0028     int cc;
0029 
0030     asm volatile(
0031         "   lgr 0,%[size]\n"
0032         "   .insn   s,0xb28f0000,%[info]\n"
0033         "   lgr %[size],0\n"
0034         "   ipm %[cc]\n"
0035         "   srl %[cc],28\n"
0036         : [cc] "=d" (cc), [info] "=Q" (*info), [size] "+&d" (size)
0037         :
0038         : "0", "cc", "memory");
0039     return cc ? (size + 1) * sizeof(u64) : 0;
0040 }
0041 
0042 #define PAI_CRYPTO_BASE         0x1000  /* First event number */
0043 #define PAI_CRYPTO_MAXCTR       256 /* Max # of event counters */
0044 #define PAI_CRYPTO_KERNEL_OFFSET    2048
0045 
0046 DECLARE_STATIC_KEY_FALSE(pai_key);
0047 
0048 static __always_inline void pai_kernel_enter(struct pt_regs *regs)
0049 {
0050     if (!IS_ENABLED(CONFIG_PERF_EVENTS))
0051         return;
0052     if (!static_branch_unlikely(&pai_key))
0053         return;
0054     if (!S390_lowcore.ccd)
0055         return;
0056     if (!user_mode(regs))
0057         return;
0058     WRITE_ONCE(S390_lowcore.ccd, S390_lowcore.ccd | PAI_CRYPTO_KERNEL_OFFSET);
0059 }
0060 
0061 static __always_inline void pai_kernel_exit(struct pt_regs *regs)
0062 {
0063     if (!IS_ENABLED(CONFIG_PERF_EVENTS))
0064         return;
0065     if (!static_branch_unlikely(&pai_key))
0066         return;
0067     if (!S390_lowcore.ccd)
0068         return;
0069     if (!user_mode(regs))
0070         return;
0071     WRITE_ONCE(S390_lowcore.ccd, S390_lowcore.ccd & ~PAI_CRYPTO_KERNEL_OFFSET);
0072 }
0073 
0074 #endif