KVM: arm64: Mandate VGIC v3 for pKVM VMs and Realms

pKVM does not trust the host. Realm VMs follow a similar trust model, with
the Realm Management Monitor owning the protected state instead of the
host. Add a helper to identify VMs that run under a host-distrusting
hypervisor.

Use this for blocking ioremap of vgic-v2 into stage2 and prevent creation
of VGIC other than v3.

Reviewed-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Gavin Shan <gshan@redhat.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://patch.msgid.link/20261007073537.2454351-14-suzuki.poulose@arm.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
This commit is contained in:
Suzuki K Poulose 2026-10-07 08:35:36 +01:00 committed by Marc Zyngier
parent b44a8c32f0
commit 37d7ea3f81
3 changed files with 7 additions and 1 deletions

View File

@ -328,6 +328,8 @@ enum fgt_group_id {
enum kvm_arm_vm_flavor {
VM_NVHE,
VM_VHE,
/* VMs running on a hyp that doesn't trust */
MARKER(__VM_DISTRUSTING_HYP),
VM_PKVM, /* Normal guests on pKVM */
MARKER(__VM_PROTECTED),
VM_PROTECTED_PKVM, /* Protected VM */
@ -1556,6 +1558,8 @@ struct kvm *kvm_arch_alloc_vm(void);
#define kvm_vm_is_protected(kvm) ((kvm)->arch.vm_flavor >= __VM_PROTECTED)
#define vcpu_is_protected(vcpu) kvm_vm_is_protected((vcpu)->kvm)
#define kvm_vm_hyp_is_distrusting(kvm) ((kvm)->arch.vm_flavor >= __VM_DISTRUSTING_HYP)
#endif /* __KVM_NVHE_HYPERVISOR__ */
int kvm_arm_vcpu_finalize(struct kvm_vcpu *vcpu, int feature);

View File

@ -1249,7 +1249,7 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
KVM_PGTABLE_PROT_R |
(writable ? KVM_PGTABLE_PROT_W : 0);
if (is_protected_kvm_enabled())
if (kvm_vm_hyp_is_distrusting(kvm))
return -EPERM;
size += offset_in_page(guest_ipa);

View File

@ -84,6 +84,8 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
!kvm_vgic_global_state.can_emulate_gicv2)
return -ENODEV;
if (kvm_vm_hyp_is_distrusting(kvm) && type != KVM_DEV_TYPE_ARM_VGIC_V3)
return -ENODEV;
/*
* Ensure mutual exclusion with vCPU creation and any vCPU ioctls by:
*