Skip to content

Commit 6c4abbe

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Add build validation for FGT trap mask values
These checks help ensure that all the bits are accounted for, that there hasn't been a transcribing error from the spec nor from the generated mask values, which will be used in subsequent patches. Signed-off-by: Fuad Tabba <tabba@google.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20231214100158.2305400-12-tabba@google.com
1 parent fc04838 commit 6c4abbe

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu)
7979
clr |= ~hfg & __ ## reg ## _nMASK; \
8080
} while(0)
8181

82+
/*
83+
* Validate the fine grain trap masks.
84+
* Check that the masks do not overlap and that all bits are accounted for.
85+
*/
86+
#define CHECK_FGT_MASKS(reg) \
87+
do { \
88+
BUILD_BUG_ON((__ ## reg ## _MASK) & (__ ## reg ## _nMASK)); \
89+
BUILD_BUG_ON(~((__ ## reg ## _RES0) ^ (__ ## reg ## _MASK) ^ \
90+
(__ ## reg ## _nMASK))); \
91+
} while(0)
8292

8393
static inline bool cpu_has_amu(void)
8494
{
@@ -94,6 +104,14 @@ static inline void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu)
94104
u64 r_clr = 0, w_clr = 0, r_set = 0, w_set = 0, tmp;
95105
u64 r_val, w_val;
96106

107+
CHECK_FGT_MASKS(HFGRTR_EL2);
108+
CHECK_FGT_MASKS(HFGWTR_EL2);
109+
CHECK_FGT_MASKS(HFGITR_EL2);
110+
CHECK_FGT_MASKS(HDFGRTR_EL2);
111+
CHECK_FGT_MASKS(HDFGWTR_EL2);
112+
CHECK_FGT_MASKS(HAFGRTR_EL2);
113+
CHECK_FGT_MASKS(HCRX_EL2);
114+
97115
if (!cpus_have_final_cap(ARM64_HAS_FGT))
98116
return;
99117

0 commit comments

Comments
 (0)