KVM: arm64: Make build-time check of RES0/RES1 bits optional
authorMarc Zyngier <maz@kernel.org>
Thu, 22 Feb 2024 14:12:09 +0000 (14:12 +0000)
committerOliver Upton <oliver.upton@linux.dev>
Thu, 22 Feb 2024 18:13:53 +0000 (18:13 +0000)
In order to ease the transition towards a state of absolute
paranoia where all RES0/RES1 bits gets checked against what
KVM know of them, make the checks optional and guarded by a
config symbol (CONFIG_KVM_ARM64_RES_BITS_PARANOIA) default to n.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/kvm/87frxka7ud.wl-maz@kernel.org/
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kvm/Kconfig
arch/arm64/kvm/check-res-bits.h

index 5c2a672c06a85b93b816b380f3ee27de1a8366f2..fa9389270cfe11a1901a23025d4eb0f57a74ff48 100644 (file)
@@ -67,4 +67,15 @@ config PROTECTED_NVHE_STACKTRACE
 
          If unsure, or not using protected nVHE (pKVM), say N.
 
+config KVM_ARM64_RES_BITS_PARANOIA
+       bool "Build-time check of RES0/RES1 bits"
+       depends on KVM
+       default n
+       help
+         Say Y here to validate that KVM's knowledge of most system
+         registers' RES0/RES1 bits matches when the rest of the kernel
+         defines. Expect the build to fail badly if you enable this.
+
+         Just say N.
+
 endif # VIRTUALIZATION
index 967b5d171d531de4ae1e4e93543b8926cfeb6d22..2d98e60efc3cdbb989348b9872ca1552e5fced6b 100644 (file)
@@ -21,6 +21,8 @@
  */
 static inline void check_res_bits(void)
 {
+#ifdef CONFIG_KVM_ARM64_RES_BITS_PARANOIA
+
        BUILD_BUG_ON(OSDTRRX_EL1_RES0           != (GENMASK_ULL(63, 32)));
        BUILD_BUG_ON(MDCCINT_EL1_RES0           != (GENMASK_ULL(63, 31) | GENMASK_ULL(28, 0)));
        BUILD_BUG_ON(MDSCR_EL1_RES0             != (GENMASK_ULL(63, 36) | GENMASK_ULL(28, 28) | GENMASK_ULL(25, 24) | GENMASK_ULL(20, 20) | GENMASK_ULL(18, 16) | GENMASK_ULL(11, 7) | GENMASK_ULL(5, 1)));
@@ -118,4 +120,6 @@ static inline void check_res_bits(void)
        BUILD_BUG_ON(TRBMAR_EL1_RES0            != (GENMASK_ULL(63, 12)));
        BUILD_BUG_ON(TRBTRG_EL1_RES0            != (GENMASK_ULL(63, 32)));
        BUILD_BUG_ON(TRBIDR_EL1_RES0            != (GENMASK_ULL(63, 12) | GENMASK_ULL(7, 6)));
+
+#endif
 }