PKVM and RMM, both do not trust the host. Add a helper to detect the VMs
that have "distrusting" hyp. Use this for blocking ioremap of vgic-v2 into
stage2.
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
arch/arm64/include/asm/kvm_host.h | 3 +++
arch/arm64/kvm/mmu.c | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 1bb43c57fb0f0..09910b2c61bfb 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -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 */@@ -1540,6 +1542,7 @@ struct kvm *kvm_arch_alloc_vm(void);
#define kvm_vm_is_protected_pkvm(kvm) ((kvm)->arch.vm_flavor == VM_PROTECTED_PKVM)
#define kvm_vm_is_unprotected_pkvm(kvm) ((kvm)->arch.vm_flavor == VM_PKVM)
+#define kvm_vm_hyp_is_distrusting(kvm) ((kvm)->arch.vm_flavor > __VM_DISTRUSTING_HYP)
#define kvm_vm_hyp_is_pkvm(kvm) (is_protected_kvm_enabled())
#define vcpu_is_protected(vcpu) kvm_vm_is_protected((vcpu)->kvm)
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 38f3bf772278f..559a8286807cd 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1251,7 +1251,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);
--
2.43.0