@@ -2474,6 +2474,9 @@ static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm,
/* invalidate any gfn reference in case of deletion/shrinking */
memcpy(aliases, kvm->arch.aliases, sizeof(struct kvm_mem_aliases));
+ if (!aliases->aliases[alias->slot].npages)
+ goto set_new_alias;
+
aliases->aliases[alias->slot].flags |= KVM_ALIAS_INVALID;
old_aliases = kvm->arch.aliases;
rcu_assign_pointer(kvm->arch.aliases, aliases);
@@ -2481,6 +2484,8 @@ static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm,
kvm_mmu_zap_all(kvm);
aliases = old_aliases;
+
+set_new_alias:
p = &aliases->aliases[alias->slot];
p->base_gfn = alias->guest_phys_addr >> PAGE_SHIFT;
p->npages = alias->memory_size >> PAGE_SHIFT;