From ddfd4dba9522d16832886a81aea264cf96f3fed7 Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Mon, 24 May 2010 13:33:27 -0400 Subject: [PATCH] qemu: avoid corrupting guest info struct on host device PCI hot add The device path doesn't make use of guestAddr, so the memcpy corrupts the guest info struct. Signed-off-by: Alex Williamson --- src/qemu/qemu_driver.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6da538964d..d12955b2a2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7653,7 +7653,6 @@ static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver, qemuDomainObjPrivatePtr priv = vm->privateData; pciDevice *pci; int ret; - virDomainDevicePCIAddress guestAddr; char *devstr = NULL; if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { @@ -7688,20 +7687,24 @@ static int qemudDomainAttachHostPciDevice(struct qemud_driver *driver, if (!(devstr = qemuBuildPCIHostdevDevStr(hostdev))) goto error; - } - qemuDomainObjEnterMonitorWithDriver(driver, vm); - if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) + qemuDomainObjEnterMonitorWithDriver(driver, vm); ret = qemuMonitorAddDevice(priv->mon, devstr); - else + qemuDomainObjExitMonitorWithDriver(driver, vm); + } else { + virDomainDevicePCIAddress guestAddr; + + qemuDomainObjEnterMonitorWithDriver(driver, vm); ret = qemuMonitorAddPCIHostDevice(priv->mon, &hostdev->source.subsys.u.pci, &guestAddr); - qemuDomainObjExitMonitorWithDriver(driver, vm); + qemuDomainObjExitMonitorWithDriver(driver, vm); + + hostdev->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; + memcpy(&hostdev->info.addr.pci, &guestAddr, sizeof(guestAddr)); + } if (ret < 0) goto error; - hostdev->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; - memcpy(&hostdev->info.addr.pci, &guestAddr, sizeof(guestAddr)); vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;