@@ -1679,6 +1679,13 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
hva_t hva, reg_end;
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.shadow_handle) {
+ return -EPERM;
+ }
+
if (change != KVM_MR_CREATE && change != KVM_MR_MOVE &&
change != KVM_MR_FLAGS_ONLY)
return 0;
@@ -1755,6 +1762,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);