KVM: pci passthrough un-page-aligned mmio device on machines w/o VT-d
PATCH 2/3 KVM: pci passthrough un-page-aligned mmio device on machines w/o VT-d
KVM doesn't permit the device's iomem size smaller than 1 page. In fact, this is not necessary. For my via-rhine nic, the size of iomem is only 0x200, but we can still use pci passthrough.
And, because un-page-aligned iomem is permitted, sanity check should be adjusted too.
---
kernel/x86/kvm_main.c 2008-12-12 15:56:19.000000000 +0800 renamed from kernel/x86/kvm_main.c 2008-11-12 20:24:04.000000000 +0800 +0 -0
@@ -751,13 +750,16 @@
struct kvm_memory_slot old, new;
r = -EINVAL;
- /* General sanity checks */
+#if 0
+ /* For some device, their iomem is not page aligned */ if (mem->memory_size & (PAGE_SIZE - 1))
goto out;
if (mem->guest_phys_addr & (PAGE_SIZE - 1))
goto out;
if (user_alloc && (mem->userspace_addr & (PAGE_SIZE - 1))) goto out;
+#endif
+ /* General sanity checks */
if (mem->slot >= KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS) goto out;
if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)
@@ -765,7 +767,8 @@
memslot = &kvm->memslots[mem->slot];
base_gfn = mem->guest_phys_addr >> PAGE_SHIFT;
- npages = mem->memory_size >> PAGE_SHIFT;
+ npages = ((mem->guest_phys_addr + mem->memory_size + PAGE_SIZE - 1) >> PAGE_SHIFT)
+ - (mem->guest_phys_addr >> PAGE_SHIFT);
if (!npages)
mem->flags &= ~KVM_MEM_LOG_DIRTY_PAGES;
Xiaojian Liu