From patchwork Tue Oct 13 08:41:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cao jin X-Patchwork-Id: 529633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3E7B9140D7C for ; Tue, 13 Oct 2015 19:37:09 +1100 (AEDT) Received: from localhost ([::1]:33066 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zlv51-0004fa-2B for incoming@patchwork.ozlabs.org; Tue, 13 Oct 2015 04:37:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zlv4H-0003oM-0P for qemu-devel@nongnu.org; Tue, 13 Oct 2015 04:36:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zlv4F-0005kL-Tw for qemu-devel@nongnu.org; Tue, 13 Oct 2015 04:36:20 -0400 Received: from [59.151.112.132] (port=25161 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zlv4F-0005dX-7x for qemu-devel@nongnu.org; Tue, 13 Oct 2015 04:36:19 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101776164" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 13 Oct 2015 16:38:30 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t9D8ZaG8008526; Tue, 13 Oct 2015 16:35:36 +0800 Received: from G08FNSTD140223.g08.fujitsu.local (10.167.226.38) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 13 Oct 2015 16:36:03 +0800 From: Cao jin To: Date: Tue, 13 Oct 2015 16:41:35 +0800 Message-ID: <1444725695-27517-3-git-send-email-caoj.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1444725695-27517-1-git-send-email-caoj.fnst@cn.fujitsu.com> References: <1444725695-27517-1-git-send-email-caoj.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.38] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: pbonzini@redhat.com, alex.williamson@redhat.com, izumi.taku@jp.fujitsu.com, mst@redhat.com Subject: [Qemu-devel] [PATCH v3 2/2] remove function during multi-function hot-add X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In case user regret when hot-adding multi-function, should roll back, device_del the function added but not exposed to the guest. Signed-off-by: Cao jin --- hw/pci/pci_host.c | 6 +++++- hw/pci/pcie.c | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/hw/pci/pci_host.c b/hw/pci/pci_host.c index 3e26f92..35e5cf3 100644 --- a/hw/pci/pci_host.c +++ b/hw/pci/pci_host.c @@ -20,6 +20,7 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_host.h" +#include "hw/pci/pci_bus.h" #include "trace.h" /* debug PCI */ @@ -88,10 +89,13 @@ void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len) uint32_t pci_data_read(PCIBus *s, uint32_t addr, int len) { PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr); + PCIDevice *f0 = NULL; uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1); uint32_t val; + uint8_t slot = (addr >> 11) & 0x1F; - if (!pci_dev) { + f0 = s->devices[PCI_DEVFN(slot, 0)]; + if (!pci_dev || (!f0 && pci_dev)) { return ~0x0; } diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 89bf61b..58d2153 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -261,13 +261,30 @@ 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; pcie_cap_slot_hotplug_common(PCI_DEVICE(hotplug_dev), dev, &exp_cap, errp); + /* In case user regret when hot-adding multi function, remove the function + * that is unexposed to guest individually, without interaction with guest. + */ + if (PCI_FUNC(pci_dev->devfn) > 0 && + bus->devices[PCI_DEVFN(PCI_SLOT(pci_dev->devfn), 0)] == NULL) { + pcie_unplug_device(bus, pci_dev, NULL); + + return; + } + pcie_cap_slot_push_attention_button(PCI_DEVICE(hotplug_dev)); } @@ -378,11 +395,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) {