pai.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Processor Activity Instrumentation support for cryptography counters
  4. *
  5. * Copyright IBM Corp. 2022
  6. * Author(s): Thomas Richter <tmricht@linux.ibm.com>
  7. */
  8. #ifndef _ASM_S390_PAI_H
  9. #define _ASM_S390_PAI_H
  10. #include <linux/jump_label.h>
  11. #include <asm/lowcore.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/asm.h>
  14. struct qpaci_info_block {
  15. u64 header;
  16. struct {
  17. u64 : 8;
  18. u64 num_cc : 8; /* # of supported crypto counters */
  19. u64 : 9;
  20. u64 num_nnpa : 7; /* # of supported NNPA counters */
  21. u64 : 32;
  22. };
  23. };
  24. static inline int qpaci(struct qpaci_info_block *info)
  25. {
  26. /* Size of info (in double words minus one) */
  27. size_t size = sizeof(*info) / sizeof(u64) - 1;
  28. int cc;
  29. asm volatile(
  30. " lgr 0,%[size]\n"
  31. " .insn s,0xb28f0000,%[info]\n"
  32. " lgr %[size],0\n"
  33. CC_IPM(cc)
  34. : CC_OUT(cc, cc), [info] "=Q" (*info), [size] "+&d" (size)
  35. :
  36. : CC_CLOBBER_LIST("0", "memory"));
  37. return CC_TRANSFORM(cc) ? (size + 1) * sizeof(u64) : 0;
  38. }
  39. #define PAI_CRYPTO_BASE 0x1000 /* First event number */
  40. #define PAI_CRYPTO_MAXCTR 256 /* Max # of event counters */
  41. #define PAI_CRYPTO_KERNEL_OFFSET 2048
  42. #define PAI_NNPA_BASE 0x1800 /* First event number */
  43. #define PAI_NNPA_MAXCTR 128 /* Max # of event counters */
  44. DECLARE_STATIC_KEY_FALSE(pai_key);
  45. static __always_inline void pai_kernel_enter(struct pt_regs *regs)
  46. {
  47. if (!IS_ENABLED(CONFIG_PERF_EVENTS))
  48. return;
  49. if (!static_branch_unlikely(&pai_key))
  50. return;
  51. if (!get_lowcore()->ccd)
  52. return;
  53. if (!user_mode(regs))
  54. return;
  55. WRITE_ONCE(get_lowcore()->ccd, get_lowcore()->ccd | PAI_CRYPTO_KERNEL_OFFSET);
  56. }
  57. static __always_inline void pai_kernel_exit(struct pt_regs *regs)
  58. {
  59. if (!IS_ENABLED(CONFIG_PERF_EVENTS))
  60. return;
  61. if (!static_branch_unlikely(&pai_key))
  62. return;
  63. if (!get_lowcore()->ccd)
  64. return;
  65. if (!user_mode(regs))
  66. return;
  67. WRITE_ONCE(get_lowcore()->ccd, get_lowcore()->ccd & ~PAI_CRYPTO_KERNEL_OFFSET);
  68. }
  69. #define PAI_SAVE_AREA(x) ((x)->hw.event_base)
  70. #define PAI_CPU_MASK(x) ((x)->hw.addr_filters)
  71. #define PAI_PMU_IDX(x) ((x)->hw.last_tag)
  72. #define PAI_SWLIST(x) (&(x)->hw.tp_list)
  73. #endif