MMIO of assigned device is registered as memory slot. Size of memory slot in 
KVM must be page size multiple. But MMIO of some devices (e.g. EHCI controller) 
is not page size mutiple, so it fails to register these MMIOs, thus device 
assignment fails. In order to solve it, need to register target page alignment 
memory for these MMIOs.

Signed-off-by: Weidong Han <[EMAIL PROTECTED]>
---
 qemu/hw/device-assignment.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c
index eaff09e..4a38a22 100644
--- a/qemu/hw/device-assignment.c
+++ b/qemu/hw/device-assignment.c
@@ -157,12 +157,18 @@ static void assigned_dev_iomem_map(PCIDevice *pci_dev, 
int region_num,
     region->e_physbase = e_phys;
     region->e_size = e_size;
 
-    if (!first_map)
-       kvm_destroy_phys_mem(kvm_context, old_ephys, old_esize);
+    if (!first_map) {
+        int slot = get_slot(old_ephys);
+        if (slot != -1)
+           kvm_destroy_phys_mem(kvm_context, old_ephys,
+                                 TARGET_PAGE_ALIGN(old_esize));
+    }
 
     if (e_size > 0)
        ret = kvm_register_phys_mem(kvm_context, e_phys,
-                                        region->u.r_virtbase, e_size, 0);
+                                    region->u.r_virtbase,
+                                    TARGET_PAGE_ALIGN(e_size), 0);
+
     if (ret != 0) {
        fprintf(stderr, "%s: Error: create new mapping failed\n", __func__);
        exit(1);
-- 
1.5.1

Attachment: 0001-register-page-alignment-memory-for-MMIO-of-assigned.patch
Description: 0001-register-page-alignment-memory-for-MMIO-of-assigned.patch

Reply via email to