Skip to content

Commit 5cb57a1

Browse files
author
Marc Zyngier
committed
KVM: arm64: Zero ID_AA64PFR0_EL1.GIC when no GICv3 is presented to the guest
In order to be consistent, we shouldn't advertise a GICv3 when none is actually usable by the guest. Wipe the feature when these conditions apply, and allow the field to be written from userspace. This now allows us to rewrite the kvm_has_gicv3 helper() in terms of kvm_has_feat(), given that it is always evaluated at runtime. Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20240827152517.3909653-6-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 795a0bb commit 5cb57a1

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

arch/arm64/kvm/sys_regs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,6 @@ static const struct sys_reg_desc sys_reg_descs[] = {
23652365
ID_AA64PFR0_EL1_MPAM |
23662366
ID_AA64PFR0_EL1_SVE |
23672367
ID_AA64PFR0_EL1_RAS |
2368-
ID_AA64PFR0_EL1_GIC |
23692368
ID_AA64PFR0_EL1_AdvSIMD |
23702369
ID_AA64PFR0_EL1_FP), },
23712370
ID_SANITISED(ID_AA64PFR1_EL1),
@@ -4634,6 +4633,13 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu)
46344633

46354634
guard(mutex)(&kvm->arch.config_lock);
46364635

4636+
if (!(static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif) &&
4637+
irqchip_in_kernel(kvm) &&
4638+
kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3)) {
4639+
kvm->arch.id_regs[IDREG_IDX(SYS_ID_AA64PFR0_EL1)] &= ~ID_AA64PFR0_EL1_GIC_MASK;
4640+
kvm->arch.id_regs[IDREG_IDX(SYS_ID_PFR1_EL1)] &= ~ID_PFR1_EL1_GIC_MASK;
4641+
}
4642+
46374643
if (vcpu_has_nv(vcpu)) {
46384644
int ret = kvm_init_nv_sysregs(kvm);
46394645
if (ret)

arch/arm64/kvm/vgic/vgic.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,7 @@ void vcpu_set_ich_hcr(struct kvm_vcpu *vcpu);
350350

351351
static inline bool kvm_has_gicv3(struct kvm *kvm)
352352
{
353-
return (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif) &&
354-
irqchip_in_kernel(kvm) &&
355-
kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3);
353+
return kvm_has_feat(kvm, ID_AA64PFR0_EL1, GIC, IMP);
356354
}
357355

358356
#endif

0 commit comments

Comments
 (0)