From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Za3nE-00083t-Mr for qemu-devel@nongnu.org; Thu, 10 Sep 2015 11:29:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Za3nA-0000X4-Mp for qemu-devel@nongnu.org; Thu, 10 Sep 2015 11:29:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55114) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Za3nA-0000X0-IX for qemu-devel@nongnu.org; Thu, 10 Sep 2015 11:29:40 -0400 Message-ID: <1441898979.20355.579.camel@redhat.com> From: Alex Williamson Date: Thu, 10 Sep 2015 09:29:39 -0600 In-Reply-To: <1441887143-26756-3-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1441887143-26756-1-git-send-email-caoj.fnst@cn.fujitsu.com> <1441887143-26756-3-git-send-email-caoj.fnst@cn.fujitsu.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] PCI-e device multi-function hot-add support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cao jin Cc: pbonzini@redhat.com, qemu-devel@nongnu.org On Thu, 2015-09-10 at 20:12 +0800, Cao jin wrote: > In case user regret when hot-add multi-function, we should roll back, > device_del the function added but still not worked. > > Signed-off-by: Cao jin > --- > hw/pci/pcie.c | 28 +++++++++++++++++++++++----- > 1 file changed, 23 insertions(+), 5 deletions(-) > > diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c > index 61ebefd..b83a244 100644 > --- a/hw/pci/pcie.c > +++ b/hw/pci/pcie.c > @@ -265,10 +265,33 @@ void pcie_cap_slot_hotplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, > } > } > > +static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque) > +{ > + object_unparent(OBJECT(dev)); > +} > + > void pcie_cap_slot_hot_unplug_request_cb(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > uint8_t *exp_cap; > + PCIDevice *pci_dev = PCI_DEVICE(dev); > + PCIBus *bus = pci_dev->bus; > + > + /* handle the condition: user want to hot-add multi function, but regret > + * before finish it, and want to delete the added but not worked function. > + */ > + if (PCI_FUNC(pci_dev->devfn) > 0 && > + bus->devices[PCI_DEVFN(0,0)] == NULL) { > + pci_for_each_device(bus, pci_bus_num(bus), > + pcie_unplug_device, NULL); > + > + pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA, > + PCI_EXP_SLTSTA_PDS); > + pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA, > + PCI_EXP_SLTSTA_PDC); > + > + return; > + } How can we know that the guest hasn't discovered the device and made use of it? The device is fully accessible to the guest even is the notification and standard discovery mechanism are not in place. A gratuitous full PCI bus scan in the guest could find the device. Thanks, Alex > > pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp); > > @@ -382,11 +405,6 @@ void pcie_cap_slot_reset(PCIDevice *dev) > hotplug_event_update_event_status(dev); > } > > -static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque) > -{ > - object_unparent(OBJECT(dev)); > -} > - > void pcie_cap_slot_write_config(PCIDevice *dev, > uint32_t addr, uint32_t val, int len) > {