diff options
author | Cédric Le Goater <clg@kaod.org> | 2019-06-14 18:59:19 +0200 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2019-07-02 09:43:58 +1000 |
commit | 981b1c6266c60f4eb86e09ef00f1b5dd046525c7 (patch) | |
tree | 410561671d623bdb552af8ed8fd2c5c2a48bca86 /hw/intc/spapr_xive_kvm.c | |
parent | a2166410ad7434a6830288beb5858b22d5e35ec5 (diff) |
spapr/xive: rework the mapping the KVM memory regions
Today, the interrupt device is fully initialized at reset when the CAS
negotiation process has completed. Depending on the KVM capabilities,
the SpaprXive memory regions (ESB, TIMA) are initialized with a host
MMIO backend or a QEMU emulated backend. This results in a complex
initialization sequence partially done at realize and later at reset,
and some memory region leaks.
To simplify this sequence and to remove of the late initialization of
the emulated device which is required to be done only once, we
introduce new memory regions specific for KVM. These regions are
mapped as overlaps on top of the emulated device to make use of the
host MMIOs. Also provide proper cleanups of these regions when the
XIVE KVM device is destroyed to fix the leaks.
Signed-off-by: Cédric Le Goater <clg@kaod.org>
Message-Id: <20190614165920.12670-2-clg@kaod.org>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'hw/intc/spapr_xive_kvm.c')
-rw-r--r-- | hw/intc/spapr_xive_kvm.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c index b48f135838..5559f8bce5 100644 --- a/hw/intc/spapr_xive_kvm.c +++ b/hw/intc/spapr_xive_kvm.c @@ -728,8 +728,10 @@ void kvmppc_xive_connect(SpaprXive *xive, Error **errp) return; } - memory_region_init_ram_device_ptr(&xsrc->esb_mmio, OBJECT(xsrc), + memory_region_init_ram_device_ptr(&xsrc->esb_mmio_kvm, OBJECT(xsrc), "xive.esb", esb_len, xsrc->esb_mmap); + memory_region_add_subregion_overlap(&xsrc->esb_mmio, 0, + &xsrc->esb_mmio_kvm, 1); /* * 2. END ESB pages (No KVM support yet) @@ -744,8 +746,10 @@ void kvmppc_xive_connect(SpaprXive *xive, Error **errp) error_propagate(errp, local_err); return; } - memory_region_init_ram_device_ptr(&xive->tm_mmio, OBJECT(xive), + memory_region_init_ram_device_ptr(&xive->tm_mmio_kvm, OBJECT(xive), "xive.tima", tima_len, xive->tm_mmap); + memory_region_add_subregion_overlap(&xive->tm_mmio, 0, + &xive->tm_mmio_kvm, 1); xive->change = qemu_add_vm_change_state_handler( kvmppc_xive_change_state_handler, xive); @@ -771,9 +775,6 @@ void kvmppc_xive_connect(SpaprXive *xive, Error **errp) kvm_kernel_irqchip = true; kvm_msi_via_irqfd_allowed = true; kvm_gsi_direct_mapping = true; - - /* Map all regions */ - spapr_xive_map_mmio(xive); } void kvmppc_xive_disconnect(SpaprXive *xive, Error **errp) @@ -795,13 +796,15 @@ void kvmppc_xive_disconnect(SpaprXive *xive, Error **errp) xsrc = &xive->source; esb_len = (1ull << xsrc->esb_shift) * xsrc->nr_irqs; - sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 0); + memory_region_del_subregion(&xsrc->esb_mmio, &xsrc->esb_mmio_kvm); + object_unparent(OBJECT(&xsrc->esb_mmio_kvm)); munmap(xsrc->esb_mmap, esb_len); + xsrc->esb_mmap = NULL; - sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 1); - - sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 2); + memory_region_del_subregion(&xive->tm_mmio, &xive->tm_mmio_kvm); + object_unparent(OBJECT(&xive->tm_mmio_kvm)); munmap(xive->tm_mmap, 4ull << TM_SHIFT); + xive->tm_mmap = NULL; /* * When the KVM device fd is closed, the KVM device is destroyed |