fixed_config.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2021 Google LLC
  4. * Author: Fuad Tabba <tabba@google.com>
  5. */
  6. #ifndef __ARM64_KVM_FIXED_CONFIG_H__
  7. #define __ARM64_KVM_FIXED_CONFIG_H__
  8. #include <asm/sysreg.h>
  9. /*
  10. * This file contains definitions for features to be allowed or restricted for
  11. * guest virtual machines, depending on the mode KVM is running in and on the
  12. * type of guest that is running.
  13. *
  14. * The ALLOW masks represent a bitmask of feature fields that are allowed
  15. * without any restrictions as long as they are supported by the system.
  16. *
  17. * The RESTRICT_UNSIGNED masks, if present, represent unsigned fields for
  18. * features that are restricted to support at most the specified feature.
  19. *
  20. * If a feature field is not present in either, than it is not supported.
  21. *
  22. * The approach taken for protected VMs is to allow features that are:
  23. * - Needed by common Linux distributions (e.g., floating point)
  24. * - Trivial to support, e.g., supporting the feature does not introduce or
  25. * require tracking of additional state in KVM
  26. * - Cannot be trapped or prevent the guest from using anyway
  27. */
  28. /*
  29. * Allow for protected VMs:
  30. * - Floating-point and Advanced SIMD
  31. * - Data Independent Timing
  32. * - Spectre/Meltdown Mitigation
  33. */
  34. #define PVM_ID_AA64PFR0_ALLOW (\
  35. ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_FP) | \
  36. ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_AdvSIMD) | \
  37. ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_DIT) | \
  38. ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV2) | \
  39. ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_CSV3) \
  40. )
  41. /*
  42. * Restrict to the following *unsigned* features for protected VMs:
  43. * - AArch64 guests only (no support for AArch32 guests):
  44. * AArch32 adds complexity in trap handling, emulation, condition codes,
  45. * etc...
  46. * - RAS (v1)
  47. * Supported by KVM
  48. */
  49. #define PVM_ID_AA64PFR0_RESTRICT_UNSIGNED (\
  50. SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, EL0, IMP) | \
  51. SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, EL1, IMP) | \
  52. SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, EL2, IMP) | \
  53. SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, EL3, IMP) | \
  54. SYS_FIELD_PREP_ENUM(ID_AA64PFR0_EL1, RAS, IMP) \
  55. )
  56. /*
  57. * Allow for protected VMs:
  58. * - Branch Target Identification
  59. * - Speculative Store Bypassing
  60. */
  61. #define PVM_ID_AA64PFR1_ALLOW (\
  62. ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_BT) | \
  63. ARM64_FEATURE_MASK(ID_AA64PFR1_EL1_SSBS) \
  64. )
  65. #define PVM_ID_AA64PFR2_ALLOW 0ULL
  66. /*
  67. * Allow for protected VMs:
  68. * - Mixed-endian
  69. * - Distinction between Secure and Non-secure Memory
  70. * - Mixed-endian at EL0 only
  71. * - Non-context synchronizing exception entry and exit
  72. */
  73. #define PVM_ID_AA64MMFR0_ALLOW (\
  74. ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_BIGEND) | \
  75. ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_SNSMEM) | \
  76. ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_BIGENDEL0) | \
  77. ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_EXS) \
  78. )
  79. /*
  80. * Restrict to the following *unsigned* features for protected VMs:
  81. * - 40-bit IPA
  82. * - 16-bit ASID
  83. */
  84. #define PVM_ID_AA64MMFR0_RESTRICT_UNSIGNED (\
  85. FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_PARANGE), ID_AA64MMFR0_EL1_PARANGE_40) | \
  86. FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64MMFR0_EL1_ASIDBITS), ID_AA64MMFR0_EL1_ASIDBITS_16) \
  87. )
  88. /*
  89. * Allow for protected VMs:
  90. * - Hardware translation table updates to Access flag and Dirty state
  91. * - Number of VMID bits from CPU
  92. * - Hierarchical Permission Disables
  93. * - Privileged Access Never
  94. * - SError interrupt exceptions from speculative reads
  95. * - Enhanced Translation Synchronization
  96. * - Control for cache maintenance permission
  97. */
  98. #define PVM_ID_AA64MMFR1_ALLOW (\
  99. ARM64_FEATURE_MASK(ID_AA64MMFR1_EL1_HAFDBS) | \
  100. ARM64_FEATURE_MASK(ID_AA64MMFR1_EL1_VMIDBits) | \
  101. ARM64_FEATURE_MASK(ID_AA64MMFR1_EL1_HPDS) | \
  102. ARM64_FEATURE_MASK(ID_AA64MMFR1_EL1_PAN) | \
  103. ARM64_FEATURE_MASK(ID_AA64MMFR1_EL1_SpecSEI) | \
  104. ARM64_FEATURE_MASK(ID_AA64MMFR1_EL1_ETS) | \
  105. ARM64_FEATURE_MASK(ID_AA64MMFR1_EL1_CMOW) \
  106. )
  107. /*
  108. * Allow for protected VMs:
  109. * - Common not Private translations
  110. * - User Access Override
  111. * - IESB bit in the SCTLR_ELx registers
  112. * - Unaligned single-copy atomicity and atomic functions
  113. * - ESR_ELx.EC value on an exception by read access to feature ID space
  114. * - TTL field in address operations.
  115. * - Break-before-make sequences when changing translation block size
  116. * - E0PDx mechanism
  117. */
  118. #define PVM_ID_AA64MMFR2_ALLOW (\
  119. ARM64_FEATURE_MASK(ID_AA64MMFR2_EL1_CnP) | \
  120. ARM64_FEATURE_MASK(ID_AA64MMFR2_EL1_UAO) | \
  121. ARM64_FEATURE_MASK(ID_AA64MMFR2_EL1_IESB) | \
  122. ARM64_FEATURE_MASK(ID_AA64MMFR2_EL1_AT) | \
  123. ARM64_FEATURE_MASK(ID_AA64MMFR2_EL1_IDS) | \
  124. ARM64_FEATURE_MASK(ID_AA64MMFR2_EL1_TTL) | \
  125. ARM64_FEATURE_MASK(ID_AA64MMFR2_EL1_BBM) | \
  126. ARM64_FEATURE_MASK(ID_AA64MMFR2_EL1_E0PD) \
  127. )
  128. #define PVM_ID_AA64MMFR3_ALLOW (0ULL)
  129. /*
  130. * No support for Scalable Vectors for protected VMs:
  131. * Requires additional support from KVM, e.g., context-switching and
  132. * trapping at EL2
  133. */
  134. #define PVM_ID_AA64ZFR0_ALLOW (0ULL)
  135. /*
  136. * No support for debug, including breakpoints, and watchpoints for protected
  137. * VMs:
  138. * The Arm architecture mandates support for at least the Armv8 debug
  139. * architecture, which would include at least 2 hardware breakpoints and
  140. * watchpoints. Providing that support to protected guests adds
  141. * considerable state and complexity. Therefore, the reserved value of 0 is
  142. * used for debug-related fields.
  143. */
  144. #define PVM_ID_AA64DFR0_ALLOW (0ULL)
  145. #define PVM_ID_AA64DFR1_ALLOW (0ULL)
  146. /*
  147. * No support for implementation defined features.
  148. */
  149. #define PVM_ID_AA64AFR0_ALLOW (0ULL)
  150. #define PVM_ID_AA64AFR1_ALLOW (0ULL)
  151. /*
  152. * No restrictions on instructions implemented in AArch64.
  153. */
  154. #define PVM_ID_AA64ISAR0_ALLOW (\
  155. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_AES) | \
  156. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SHA1) | \
  157. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SHA2) | \
  158. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_CRC32) | \
  159. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_ATOMIC) | \
  160. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_RDM) | \
  161. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SHA3) | \
  162. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SM3) | \
  163. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_SM4) | \
  164. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_DP) | \
  165. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_FHM) | \
  166. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_TS) | \
  167. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_TLB) | \
  168. ARM64_FEATURE_MASK(ID_AA64ISAR0_EL1_RNDR) \
  169. )
  170. /* Restrict pointer authentication to the basic version. */
  171. #define PVM_ID_AA64ISAR1_RESTRICT_UNSIGNED (\
  172. FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_APA), ID_AA64ISAR1_EL1_APA_PAuth) | \
  173. FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_API), ID_AA64ISAR1_EL1_API_PAuth) \
  174. )
  175. #define PVM_ID_AA64ISAR2_RESTRICT_UNSIGNED (\
  176. FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64ISAR2_EL1_APA3), ID_AA64ISAR2_EL1_APA3_PAuth) \
  177. )
  178. #define PVM_ID_AA64ISAR1_ALLOW (\
  179. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_DPB) | \
  180. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_JSCVT) | \
  181. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_FCMA) | \
  182. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_LRCPC) | \
  183. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_GPA) | \
  184. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_GPI) | \
  185. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_FRINTTS) | \
  186. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_SB) | \
  187. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_SPECRES) | \
  188. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_BF16) | \
  189. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_DGH) | \
  190. ARM64_FEATURE_MASK(ID_AA64ISAR1_EL1_I8MM) \
  191. )
  192. #define PVM_ID_AA64ISAR2_ALLOW (\
  193. ARM64_FEATURE_MASK(ID_AA64ISAR2_EL1_ATS1A)| \
  194. ARM64_FEATURE_MASK(ID_AA64ISAR2_EL1_GPA3) | \
  195. ARM64_FEATURE_MASK(ID_AA64ISAR2_EL1_MOPS) \
  196. )
  197. u64 pvm_read_id_reg(const struct kvm_vcpu *vcpu, u32 id);
  198. bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code);
  199. bool kvm_handle_pvm_restricted(struct kvm_vcpu *vcpu, u64 *exit_code);
  200. int kvm_check_pvm_sysreg_table(void);
  201. #endif /* __ARM64_KVM_FIXED_CONFIG_H__ */