Skip to content

Commit 4cab5c8

Browse files
author
Marc Zyngier
committed
KVM: arm64: Hide CNTHV_*_EL2 from userspace for nVHE guests
Although we correctly UNDEF any CNTHV_*_EL2 access from the guest when E2H==0, we still expose these registers to userspace, which is a bad idea. Drop the ad-hoc UNDEF injection and switch to a .visibility() callback which will also hide the register from userspace. Fixes: 0e45981 ("KVM: arm64: timer: Don't adjust the EL2 virtual timer offset") Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 164ecbf commit 4cab5c8

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,16 +1594,6 @@ static bool access_arch_timer(struct kvm_vcpu *vcpu,
15941594
return true;
15951595
}
15961596

1597-
static bool access_hv_timer(struct kvm_vcpu *vcpu,
1598-
struct sys_reg_params *p,
1599-
const struct sys_reg_desc *r)
1600-
{
1601-
if (!vcpu_el2_e2h_is_set(vcpu))
1602-
return undef_access(vcpu, p, r);
1603-
1604-
return access_arch_timer(vcpu, p, r);
1605-
}
1606-
16071597
static s64 kvm_arm64_ftr_safe_value(u32 id, const struct arm64_ftr_bits *ftrp,
16081598
s64 new, s64 cur)
16091599
{
@@ -2831,6 +2821,16 @@ static unsigned int s1pie_el2_visibility(const struct kvm_vcpu *vcpu,
28312821
return __el2_visibility(vcpu, rd, s1pie_visibility);
28322822
}
28332823

2824+
static unsigned int cnthv_visibility(const struct kvm_vcpu *vcpu,
2825+
const struct sys_reg_desc *rd)
2826+
{
2827+
if (vcpu_has_nv(vcpu) &&
2828+
!vcpu_has_feature(vcpu, KVM_ARM_VCPU_HAS_EL2_E2H0))
2829+
return 0;
2830+
2831+
return REG_HIDDEN;
2832+
}
2833+
28342834
static bool access_mdcr(struct kvm_vcpu *vcpu,
28352835
struct sys_reg_params *p,
28362836
const struct sys_reg_desc *r)
@@ -3691,9 +3691,9 @@ static const struct sys_reg_desc sys_reg_descs[] = {
36913691
EL2_REG(CNTHP_CTL_EL2, access_arch_timer, reset_val, 0),
36923692
EL2_REG(CNTHP_CVAL_EL2, access_arch_timer, reset_val, 0),
36933693

3694-
{ SYS_DESC(SYS_CNTHV_TVAL_EL2), access_hv_timer },
3695-
EL2_REG(CNTHV_CTL_EL2, access_hv_timer, reset_val, 0),
3696-
EL2_REG(CNTHV_CVAL_EL2, access_hv_timer, reset_val, 0),
3694+
{ SYS_DESC(SYS_CNTHV_TVAL_EL2), access_arch_timer, .visibility = cnthv_visibility },
3695+
EL2_REG_FILTERED(CNTHV_CTL_EL2, access_arch_timer, reset_val, 0, cnthv_visibility),
3696+
EL2_REG_FILTERED(CNTHV_CVAL_EL2, access_arch_timer, reset_val, 0, cnthv_visibility),
36973697

36983698
{ SYS_DESC(SYS_CNTKCTL_EL12), access_cntkctl_el12 },
36993699

0 commit comments

Comments
 (0)