[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 26/29] xen/pt: Make xen_pt_unregister_device idempote
From: |
Stefano Stabellini |
Subject: |
[Qemu-devel] [PULL 26/29] xen/pt: Make xen_pt_unregister_device idempotent |
Date: |
Thu, 10 Sep 2015 18:15:58 +0100 |
From: Konrad Rzeszutek Wilk <address@hidden>
To deal with xen_host_pci_[set|get]_ functions returning error values
and clearing ourselves in the init function we should make the
.exit (xen_pt_unregister_device) function be idempotent in case
the generic code starts calling .exit (or for fun does it before
calling .init!).
Reviewed-by: Stefano Stabellini <address@hidden>
Signed-off-by: Konrad Rzeszutek Wilk <address@hidden>
Signed-off-by: Stefano Stabellini <address@hidden>
---
hw/xen/xen-host-pci-device.c | 5 +++++
hw/xen/xen-host-pci-device.h | 1 +
hw/xen/xen_pt.c | 20 ++++++++++++++------
hw/xen/xen_pt.h | 2 ++
4 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c
index a54b7de..be28ca2 100644
--- a/hw/xen/xen-host-pci-device.c
+++ b/hw/xen/xen-host-pci-device.c
@@ -392,6 +392,11 @@ error:
return rc;
}
+bool xen_host_pci_device_closed(XenHostPCIDevice *d)
+{
+ return d->config_fd == -1;
+}
+
void xen_host_pci_device_put(XenHostPCIDevice *d)
{
if (d->config_fd >= 0) {
diff --git a/hw/xen/xen-host-pci-device.h b/hw/xen/xen-host-pci-device.h
index f1e1c30..3d44e04 100644
--- a/hw/xen/xen-host-pci-device.h
+++ b/hw/xen/xen-host-pci-device.h
@@ -39,6 +39,7 @@ typedef struct XenHostPCIDevice {
int xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
uint8_t bus, uint8_t dev, uint8_t func);
void xen_host_pci_device_put(XenHostPCIDevice *pci_dev);
+bool xen_host_pci_device_closed(XenHostPCIDevice *d);
int xen_host_pci_get_byte(XenHostPCIDevice *d, int pos, uint8_t *p);
int xen_host_pci_get_word(XenHostPCIDevice *d, int pos, uint16_t *p);
diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c
index 1c84d3d..d019968 100644
--- a/hw/xen/xen_pt.c
+++ b/hw/xen/xen_pt.c
@@ -840,6 +840,7 @@ out:
memory_listener_register(&s->memory_listener, &s->dev.bus_master_as);
memory_listener_register(&s->io_listener, &address_space_io);
+ s->listener_set = true;
XEN_PT_LOG(d,
"Real physical device %02x:%02x.%d registered successfully!\n",
s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function);
@@ -852,10 +853,11 @@ static void xen_pt_unregister_device(PCIDevice *d)
XenPCIPassthroughState *s = XEN_PT_DEVICE(d);
XenHostPCIDevice *host_dev = &s->real_device;
uint8_t machine_irq = s->machine_irq;
- uint8_t intx = xen_pt_pci_intx(s);
+ uint8_t intx;
int rc;
- if (machine_irq) {
+ if (machine_irq && !xen_host_pci_device_closed(&s->real_device)) {
+ intx = xen_pt_pci_intx(s);
rc = xc_domain_unbind_pt_irq(xen_xc, xen_domid, machine_irq,
PT_IRQ_TYPE_PCI,
pci_bus_num(d->bus),
@@ -870,6 +872,7 @@ static void xen_pt_unregister_device(PCIDevice *d)
}
}
+ /* N.B. xen_pt_config_delete takes care of freeing them. */
if (s->msi) {
xen_pt_msi_disable(s);
}
@@ -889,6 +892,7 @@ static void xen_pt_unregister_device(PCIDevice *d)
machine_irq, errno);
}
}
+ s->machine_irq = 0;
}
/* delete all emulated config registers */
@@ -896,10 +900,14 @@ static void xen_pt_unregister_device(PCIDevice *d)
xen_pt_unregister_vga_regions(host_dev);
- memory_listener_unregister(&s->memory_listener);
- memory_listener_unregister(&s->io_listener);
-
- xen_host_pci_device_put(&s->real_device);
+ if (s->listener_set) {
+ memory_listener_unregister(&s->memory_listener);
+ memory_listener_unregister(&s->io_listener);
+ s->listener_set = false;
+ }
+ if (!xen_host_pci_device_closed(&s->real_device)) {
+ xen_host_pci_device_put(&s->real_device);
+ }
}
static Property xen_pci_passthrough_properties[] = {
diff --git a/hw/xen/xen_pt.h b/hw/xen/xen_pt.h
index 76551ef..3bc22eb 100644
--- a/hw/xen/xen_pt.h
+++ b/hw/xen/xen_pt.h
@@ -225,6 +225,7 @@ struct XenPCIPassthroughState {
MemoryListener memory_listener;
MemoryListener io_listener;
+ bool listener_set;
};
int xen_pt_config_init(XenPCIPassthroughState *s);
@@ -290,6 +291,7 @@ static inline uint8_t
xen_pt_pci_intx(XenPCIPassthroughState *s)
" value=%i, acceptable range is 1 - 4\n", r_val);
r_val = 0;
} else {
+ /* Note that if s.real_device.config_fd is closed we make 0xff. */
r_val -= 1;
}
--
1.7.10.4
- [Qemu-devel] [PULL 04/29] piix: create host bridge to passthrough, (continued)
- [Qemu-devel] [PULL 04/29] piix: create host bridge to passthrough, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 01/29] xen-hvm: Add trace to ioreq, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 10/29] xen, gfx passthrough: register host bridge specific to passthrough, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 02/29] i440fx: make types configurable at run-time, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 03/29] pc_init1: pass parameters just with types, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 07/29] xen, gfx passthrough: retrieve VGA BIOS to work, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 05/29] hw/pci-assign: split pci-assign.c, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 09/29] xen, gfx passthrough: register a isa bridge, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 06/29] xen, gfx passthrough: basic graphics passthrough support, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 08/29] igd gfx passthrough: create a isa bridge, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 26/29] xen/pt: Make xen_pt_unregister_device idempotent,
Stefano Stabellini <=
- [Qemu-devel] [PULL 13/29] xen/HVM: atomically access pointers in bufioreq handling, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 12/29] xen-hvm: When using xc_domain_add_to_physmap also include errno when reporting, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 22/29] xen/pt: Check if reg->init function sets the 'data' past the reg->size, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 28/29] xen/pt: Check for return values for xen_host_pci_[get|set] in init, Stefano Stabellini, 2015/09/10
- [Qemu-devel] [PULL 21/29] xen/pt: Sync up the dev.config and data values., Stefano Stabellini, 2015/09/10