From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Williamson Subject: Re: [PATCH] device-assignment: register a reset function Date: Fri, 17 Sep 2010 10:16:21 -0600 Message-ID: <1284740181.14301.15.camel@x201> References: <4C9377DA.9050904@nsn.com> <1284737271-21457-1-git-send-email-bernhard.kohl@nsn.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, kwolf@redhat.com, Thomas Ostler To: Bernhard Kohl Return-path: Received: from mx1.redhat.com ([209.132.183.28]:31547 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752350Ab0IQQQZ (ORCPT ); Fri, 17 Sep 2010 12:16:25 -0400 In-Reply-To: <1284737271-21457-1-git-send-email-bernhard.kohl@nsn.com> Sender: kvm-owner@vger.kernel.org List-ID: On Fri, 2010-09-17 at 17:27 +0200, Bernhard Kohl wrote: > 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..fb47813 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, 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); > @@ -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)) Hmm, at a minimum, we need a qemu_unregister_reset() in the exitfn, but upon further inspection, we should probably just do it the qdev way. That would mean simply setting qdev.reset to reset_assigned_device() in assign_info, then we can leave the registration/de-registration to qdev. Does that work? Sorry I missed that the first time. Thanks, Alex