Skip to content

Commit 1ba41c8

Browse files
author
Marc Zyngier
committed
KVM: arm64: Add context-switch for FEAT_FGT2 registers
Just like the rest of the FGT registers, perform a switch of the FGT2 equivalent. This avoids the host configuration leaking into the guest... Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent fc631df commit 1ba41c8

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu)
8787
case HAFGRTR_EL2: \
8888
m = &hafgrtr_masks; \
8989
break; \
90+
case HFGRTR2_EL2: \
91+
m = &hfgrtr2_masks; \
92+
break; \
93+
case HFGWTR2_EL2: \
94+
m = &hfgwtr2_masks; \
95+
break; \
96+
case HFGITR2_EL2: \
97+
m = &hfgitr2_masks; \
98+
break; \
99+
case HDFGRTR2_EL2: \
100+
m = &hdfgrtr2_masks; \
101+
break; \
102+
case HDFGWTR2_EL2: \
103+
m = &hdfgwtr2_masks; \
104+
break; \
90105
default: \
91106
BUILD_BUG_ON(1); \
92107
} \
@@ -120,6 +135,17 @@ static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu)
120135
case HAFGRTR_EL2: \
121136
id = HAFGRTR_GROUP; \
122137
break; \
138+
case HFGRTR2_EL2: \
139+
case HFGWTR2_EL2: \
140+
id = HFGRTR2_GROUP; \
141+
break; \
142+
case HFGITR2_EL2: \
143+
id = HFGITR2_GROUP; \
144+
break; \
145+
case HDFGRTR2_EL2: \
146+
case HDFGWTR2_EL2: \
147+
id = HDFGRTR2_GROUP; \
148+
break; \
123149
default: \
124150
BUILD_BUG_ON(1); \
125151
} \
@@ -182,6 +208,15 @@ static inline void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu)
182208

183209
if (cpu_has_amu())
184210
update_fgt_traps(hctxt, vcpu, kvm, HAFGRTR_EL2);
211+
212+
if (!cpus_have_final_cap(ARM64_HAS_FGT2))
213+
return;
214+
215+
update_fgt_traps(hctxt, vcpu, kvm, HFGRTR2_EL2);
216+
update_fgt_traps(hctxt, vcpu, kvm, HFGWTR2_EL2);
217+
update_fgt_traps(hctxt, vcpu, kvm, HFGITR2_EL2);
218+
update_fgt_traps(hctxt, vcpu, kvm, HDFGRTR2_EL2);
219+
update_fgt_traps(hctxt, vcpu, kvm, HDFGWTR2_EL2);
185220
}
186221

187222
#define __deactivate_fgt(htcxt, vcpu, reg) \
@@ -205,6 +240,15 @@ static inline void __deactivate_traps_hfgxtr(struct kvm_vcpu *vcpu)
205240

206241
if (cpu_has_amu())
207242
__deactivate_fgt(hctxt, vcpu, HAFGRTR_EL2);
243+
244+
if (!cpus_have_final_cap(ARM64_HAS_FGT2))
245+
return;
246+
247+
__deactivate_fgt(hctxt, vcpu, HFGRTR2_EL2);
248+
__deactivate_fgt(hctxt, vcpu, HFGWTR2_EL2);
249+
__deactivate_fgt(hctxt, vcpu, HFGITR2_EL2);
250+
__deactivate_fgt(hctxt, vcpu, HDFGRTR2_EL2);
251+
__deactivate_fgt(hctxt, vcpu, HDFGWTR2_EL2);
208252
}
209253

210254
static inline void __activate_traps_mpam(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)