Browse Source

KVM: ensure that memslot userspace addresses are page-aligned

Bad page translation and silent guest failure ensue if the userspace address is
not page-aligned.  I hit this problem using large (host) pages with qemu,
because qemu currently has a hardcoded 4096-byte alignment for guest memory
allocations.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Hollis Blanchard 16 years ago
parent
commit
7874980922
1 changed files with 2 additions and 0 deletions
  1. 2 0
      virt/kvm/kvm_main.c

+ 2 - 0
virt/kvm/kvm_main.c

@@ -715,6 +715,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
 		goto out;
 		goto out;
 	if (mem->guest_phys_addr & (PAGE_SIZE - 1))
 	if (mem->guest_phys_addr & (PAGE_SIZE - 1))
 		goto out;
 		goto out;
+	if (mem->userspace_addr & (PAGE_SIZE - 1))
+		goto out;
 	if (mem->slot >= KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS)
 	if (mem->slot >= KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS)
 		goto out;
 		goto out;
 	if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)
 	if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)