mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 02:50:49 +09:00
ANDROID: KVM: arm64: Do not allow memslot changes after first VM run under pKVM
As the guest stage-2 page-tables will soon be managed entirely by EL2 when pKVM is enabled, guest memory will be pinned and the MMU notifiers in the host will be unable to reconfigure mappings at EL2 other than destrroying the guest and reclaiming all of the memory. Forbid memslot move/delete operations for VMs that have run under pKVM, returning -EPERM to userspace if such an operation is requested. Signed-off-by: Fuad Tabba <tabba@google.com> Signed-off-by: Will Deacon <willdeacon@google.com> Bug: 233587962 Change-Id: I73650c1ac79d8c116a3f31d17ef2a4ef1b30a844
This commit is contained in:
@@ -1734,6 +1734,13 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
|
||||
hva_t reg_end = hva + mem->memory_size;
|
||||
int ret = 0;
|
||||
|
||||
/* In protected mode, cannot modify memslots once a VM has run. */
|
||||
if (is_protected_kvm_enabled() &&
|
||||
(change == KVM_MR_DELETE || change == KVM_MR_MOVE) &&
|
||||
kvm->arch.pkvm.handle) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if (change != KVM_MR_CREATE && change != KVM_MR_MOVE &&
|
||||
change != KVM_MR_FLAGS_ONLY)
|
||||
return 0;
|
||||
@@ -1807,6 +1814,10 @@ void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
|
||||
gpa_t gpa = slot->base_gfn << PAGE_SHIFT;
|
||||
phys_addr_t size = slot->npages << PAGE_SHIFT;
|
||||
|
||||
/* Stage-2 is managed by hyp in protected mode. */
|
||||
if (is_protected_kvm_enabled())
|
||||
return;
|
||||
|
||||
write_lock(&kvm->mmu_lock);
|
||||
unmap_stage2_range(&kvm->arch.mmu, gpa, size);
|
||||
write_unlock(&kvm->mmu_lock);
|
||||
|
||||
Reference in New Issue
Block a user