From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bernhard Kohl Subject: [PATCH] device-assignment: register a reset function Date: Tue, 14 Sep 2010 17:04:31 +0200 Message-ID: <1284476671-21012-1-git-send-email-bernhard.kohl@nsn.com> Cc: Bernhard Kohl , Thomas Ostler To: kvm@vger.kernel.org Return-path: Received: from demumfd001.nsn-inter.net ([93.183.12.32]:12982 "EHLO demumfd001.nsn-inter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754751Ab0INPEp (ORCPT ); Tue, 14 Sep 2010 11:04:45 -0400 Received: from demuprx016.emea.nsn-intra.net ([10.150.129.55]) by demumfd001.nsn-inter.net (8.12.11.20060308/8.12.11) with ESMTP id o8EF4hAU004612 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 14 Sep 2010 17:04:43 +0200 Sender: kvm-owner@vger.kernel.org List-ID: 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 --- hw/device-assignment.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 87f7418..001aee8 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -1450,6 +1450,17 @@ static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev) dev->msix_table_page = NULL; } +static void reset_assigned_device(void *opaque) +{ + PCIDevice *d = (PCIDevice *)opaque; + uint32_t conf; + + /* reset the bus master bit to avoid further DMA transfers */ + conf = assigned_dev_pci_read_config(d, 0x04, 0x02); + conf &= ~0x04; + assigned_dev_pci_write_config(d, 0x04, conf, 0x02); +} + static int assigned_initfn(struct PCIDevice *pci_dev) { AssignedDevice *dev = DO_UPCAST(AssignedDevice, dev, pci_dev); @@ -1499,6 +1510,9 @@ static int assigned_initfn(struct PCIDevice *pci_dev) if (r < 0) goto assigned_out; + /* register reset function for the device */ + qemu_register_reset(reset_assigned_device, pci_dev); + /* intercept MSI-X entry page in the MMIO */ if (dev->cap.available & ASSIGNED_DEVICE_CAP_MSIX) if (assigned_dev_register_msix_mmio(dev)) -- 1.7.2.2