OSDN Git Service

KVM: arm64: Force ID_AA64PFR0_EL1.GIC=1 when exposing a virtual GICv3
authorMarc Zyngier <maz@kernel.org>
Sun, 10 Oct 2021 15:09:06 +0000 (16:09 +0100)
committerMarc Zyngier <maz@kernel.org>
Sun, 17 Oct 2021 10:06:36 +0000 (11:06 +0100)
Until now, we always let ID_AA64PFR0_EL1.GIC reflect the value
visible on the host, even if we were running a GICv2-enabled VM
on a GICv3+compat host.

That's fine, but we also now have the case of a host that does not
expose ID_AA64PFR0_EL1.GIC==1 despite having a vGIC. Yes, this is
confusing. Thank you M1.

Let's go back to first principles and expose ID_AA64PFR0_EL1.GIC=1
when a GICv3 is exposed to the guest. This also hides a GICv4.1
CPU interface from the guest which has no business knowing about
the v4.1 extension.

Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20211010150910.2911495-2-maz@kernel.org
arch/arm64/kvm/sys_regs.c

index 1d46e18..0e8fc29 100644 (file)
@@ -1075,6 +1075,11 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
                val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_CSV2), (u64)vcpu->kvm->arch.pfr0_csv2);
                val &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_CSV3);
                val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_CSV3), (u64)vcpu->kvm->arch.pfr0_csv3);
+               if (irqchip_in_kernel(vcpu->kvm) &&
+                   vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
+                       val &= ~ARM64_FEATURE_MASK(ID_AA64PFR0_GIC);
+                       val |= FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64PFR0_GIC), 1);
+               }
                break;
        case SYS_ID_AA64PFR1_EL1:
                val &= ~ARM64_FEATURE_MASK(ID_AA64PFR1_MTE);