From: Bernhard Kohl <bernhard.kohl@xxxxxxx> This is necessary because during reboot of a VM the assigned devices continue DMA transfers which causes memory corruption. Acked-by: Alex Williamson <alex.williamson@xxxxxxxxxx> Acked-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx> Signed-off-by: Thomas Ostler <thomas.ostler@xxxxxxx> Signed-off-by: Bernhard Kohl <bernhard.kohl@xxxxxxx> Signed-off-by: Marcelo Tosatti <mtosatti@xxxxxxxxxx> diff --git a/hw/device-assignment.c b/hw/device-assignment.c index c2a7b27..369bff9 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -1438,6 +1438,17 @@ static const VMStateDescription vmstate_assigned_device = { .name = "pci-assign" }; +static void reset_assigned_device(DeviceState *dev) +{ + PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev); + + /* + * When a 0 is written to the command register, the device is logically + * disconnected from the PCI bus. This avoids further DMA transfers. + */ + assigned_dev_pci_write_config(d, PCI_COMMAND, 0, 2); +} + static int assigned_initfn(struct PCIDevice *pci_dev) { AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev); @@ -1555,6 +1566,7 @@ static PCIDeviceInfo assign_info = { .qdev.name = "pci-assign", .qdev.desc = "pass through host pci devices to the guest", .qdev.size = sizeof(AssignedDevice), + .qdev.reset = reset_assigned_device, .init = assigned_initfn, .exit = assigned_exitfn, .config_read = assigned_dev_pci_read_config, -- To unsubscribe from this list: send the line "unsubscribe kvm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html