From patchwork Wed May 9 15:25:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 157997 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AD965B6FA5 for ; Thu, 10 May 2012 01:25:58 +1000 (EST) Received: from localhost ([::1]:44388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS8m4-0003Az-Jh for incoming@patchwork.ozlabs.org; Wed, 09 May 2012 11:25:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS8lo-0003Au-QR for qemu-devel@nongnu.org; Wed, 09 May 2012 11:25:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SS8lj-0002Rl-MG for qemu-devel@nongnu.org; Wed, 09 May 2012 11:25:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14068) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS8lj-0002Rb-DV for qemu-devel@nongnu.org; Wed, 09 May 2012 11:25:35 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q49FPW26024440 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 9 May 2012 11:25:32 -0400 Received: from [10.66.8.167] (dhcp-8-167.nay.redhat.com [10.66.8.167]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q49FPTG3004939; Wed, 9 May 2012 11:25:29 -0400 To: mst@redhat.com, linux-pci@vger.kernel.org, seabios@seabios.org, qemu-devel@nongnu.org, jbarnes@virtuousgeek.org, alex.williamson@redhat.com, kevin@koconnor.net From: Amos Kong Date: Wed, 09 May 2012 23:25:43 +0800 Message-ID: <20120509152543.11307.20072.stgit@t> In-Reply-To: <1315976141-6684-1-git-send-email-akong@redhat.com> References: <1315976141-6684-1-git-send-email-akong@redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] pci: clean all funcs when hot-removing multifunc device 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 RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=737720#c8 (dmesg and DSDT were attached in bz) Boot up a Linux VM with 8 pci block devices which are the 8 functions in one pci slot. | # qemu-kvm ... | -drive file=images/u0,if=none,id=drv0,format=qcow2,cache=none \ | -device virtio-blk-pci,drive=drv0,id=v0,multifunction=on,addr=0x03.0 \ | .... | -drive file=images/u7,if=none,id=drv7,format=qcow2,cache=none \ | -device virtio-blk-pci,drive=drv7,id=v7,multifunction=on,addr=0x03.7 \ Check devices in guest. | vm)# ls /dev/vd* | vda vdb vdc vde vdf vdg vdh | vm)# lspci |grep block | 00:03.0 SCSI storage controller: Red Hat, Inc Virtio block device | ... | 00:03.7 SCSI storage controller: Red Hat, Inc Virtio block device | Func1~7 still exist in guest after hot-removing the whole slot by qemu monitor cmd. | vm)# lspci |grep block (00:03.0 disappeared) | 00:03.1 SCSI storage controller: Red Hat, Inc Virtio block device (rev ff) | ... | 00:03.7 SCSI storage controller: Red Hat, Inc Virtio block device (rev ff) | vm)# ls /dev/vd* (vda disappeared) | vdb vdc vde vdf vdg vdh | vm)# mkfs /dev/vdb | INFO: task mkfs.ext2:1784 blocked for more than 120 seconds. We process pci slot as a whole device, in seabios only defines one device for a slot in ACPI DSDT table, then there is only one entry (for func#0) would be added into 'slot->funcs' list. When we release the whole slot, only the entry in 'slot->funcs' will be cleaned, so func#1~7 could not be cleaned from system. | drivers/pci/hotplug/acpiphp_glue.c: | static int disable_device(struct acpiphp_slot *slot) { | list_for_each_entry(func, &slot->funcs, sibling) { | pdev = pci_get_slot(slot->bridge->pci_bus, | PCI_DEVFN(slot->device, func->function)); | ..clean code.. // those code is only executed 1 time(for func#0) | __pci_remove_bus_device(pdev); | pci_dev_put(pdev); I try to add entries for all hotpluged device in enable_device(), but it doesn't work, because 'slot->funcs' is used in many place which we only need to process func#0. This patch just try to clean all funcs in disable_device(). Hotpluging multifunc of guests(WinXp/Win7) is fine. --- v1 thread: http://marc.info/?t=131597601700003&r=1&w=2 Changes from v1: - rebase patch to latest linux.git - remove unnecessary multiplefunction check - rename 'i' to meaningful 'fn' - fix coding style Signed-off-by: Amos Kong --- drivers/pci/hotplug/acpiphp_glue.c | 20 +++++++++++--------- 1 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 806c44f..42f9bb9 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c @@ -887,6 +887,7 @@ static int disable_device(struct acpiphp_slot *slot) struct acpiphp_func *func; struct pci_dev *pdev; struct pci_bus *bus = slot->bridge->pci_bus; + int fn; /* The slot will be enabled when func 0 is added, so check func 0 before disable the slot. */ @@ -902,16 +903,17 @@ static int disable_device(struct acpiphp_slot *slot) func->bridge = NULL; } - pdev = pci_get_slot(slot->bridge->pci_bus, - PCI_DEVFN(slot->device, func->function)); - if (pdev) { - pci_stop_bus_device(pdev); - if (pdev->subordinate) { - disable_bridges(pdev->subordinate); - pci_disable_device(pdev); + for (fn = 0; fn < 8; fn++) { + pdev = pci_get_slot(bus, PCI_DEVFN(slot->device, fn)); + if (pdev) { + pci_stop_bus_device(pdev); + if (pdev->subordinate) { + disable_bridges(pdev->subordinate); + pci_disable_device(pdev); + } + __pci_remove_bus_device(pdev); + pci_dev_put(pdev); } - __pci_remove_bus_device(pdev); - pci_dev_put(pdev); } }