Received: from [140.186.70.92] (port=60583 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PHxKF-0002I8-9C for qemu-devel@nongnu.org; Mon, 15 Nov 2010 06:34:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PHxKA-0001Y7-IA for qemu-devel@nongnu.org; Mon, 15 Nov 2010 06:34:19 -0500 Received: from demumfd001.nsn-inter.net ([93.183.12.32]:12363) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PHxKA-0001Y1-5a for qemu-devel@nongnu.org; Mon, 15 Nov 2010 06:34:14 -0500 From: Bernhard Kohl Date: Mon, 15 Nov 2010 12:33:57 +0100 Message-Id: <1289820837-24254-1-git-send-email-bernhard.kohl@nsn.com> In-Reply-To: <1284740181.14301.15.camel@x201> References: <1284740181.14301.15.camel@x201> Subject: [Qemu-devel] [PATCH] device-assignment: register a reset function List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Bernhard Kohl , alex.williamson@redhat.com, Thomas Ostler This is necessary because during reboot of a VM the assigned devices continue DMA transfers which causes memory corruption. Signed-off-by: Thomas Ostler Signed-off-by: Bernhard Kohl --- Sorry for for the long delay. Finally we added Alex' suggestions and rebased the patch. Thanks Bernhard --- hw/device-assignment.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 5f5bde1..3f8de66 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -1434,6 +1434,17 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev) dev->msix_table_page = NULL; } +static void reset_assigned_device(DeviceState *dev) +{ + PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev); + uint32_t conf; + + /* reset the bus master bit to avoid further DMA transfers */ + conf = assigned_dev_pci_read_config(d, PCI_COMMAND, 2); + conf &= ~PCI_COMMAND_MASTER; + assigned_dev_pci_write_config(d, PCI_COMMAND, conf, 2); +} + static int assigned_initfn(struct PCIDevice *pci_dev) { AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev); @@ -1544,6 +1555,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, -- 1.7.2.3