From patchwork Fri Apr 10 08:53:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 6193341 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5876DBF4A6 for ; Fri, 10 Apr 2015 08:54:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 86C9C203EB for ; Fri, 10 Apr 2015 08:54:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9DCB4203DB for ; Fri, 10 Apr 2015 08:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932480AbbDJIyc (ORCPT ); Fri, 10 Apr 2015 04:54:32 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:39621 "EHLO e23smtp09.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932305AbbDJIy2 (ORCPT ); Fri, 10 Apr 2015 04:54:28 -0400 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Apr 2015 18:54:25 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Apr 2015 18:54:22 +1000 Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 328362CE8052 for ; Fri, 10 Apr 2015 18:54:22 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3A8sDi925690218 for ; Fri, 10 Apr 2015 18:54:21 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3A8rmgQ030435 for ; Fri, 10 Apr 2015 18:53:48 +1000 Received: from localhost ([9.123.251.49]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t3A8rlqi029912; Fri, 10 Apr 2015 18:53:48 +1000 From: Wei Yang To: bhelgaas@google.com, gwshan@linux.vnet.ibm.com Cc: linux-pci@vger.kernel.org, Wei Yang Subject: [PATCH] pci/iov: return a reference to PF on destroying VF Date: Fri, 10 Apr 2015 16:53:04 +0800 Message-Id: <1428655984-26903-1-git-send-email-weiyang@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15041008-0033-0000-0000-0000014E91CB Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Each VF will get a reference to its PF, while it is not returned back in all cases and leave a removed PF's pci_dev un-released. As commit ac205b7b ("PCI: make sriov work with hotplug remove") indicates, when removing devices on a bus, we do it in the reverse order. This means we would remove VFs first, then PFs. After doing so, VF's removal is done with pci_stop_and_remove_bus_device() instead of virtfn_remove(). virtfn_remove() returns the reference of its PF, while pci_stop_and_remove_bus_device() doesn't. This patches moves the return of PF's reference to pci_destroy_dev() to make sure the PF's pci_dev is released in any case. Signed-off-by: Wei Yang --- drivers/pci/iov.c | 1 - drivers/pci/remove.c | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 4b3a4ea..9b04bde 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -167,7 +167,6 @@ static void virtfn_remove(struct pci_dev *dev, int id, int reset) /* balance pci_get_domain_bus_and_slot() */ pci_dev_put(virtfn); - pci_dev_put(dev); } static int sriov_enable(struct pci_dev *dev, int nr_virtfn) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 8bd76c9..836ddf6 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -41,6 +41,11 @@ static void pci_destroy_dev(struct pci_dev *dev) list_del(&dev->bus_list); up_write(&pci_bus_sem); +#ifdef CONFIG_PCI_IOV + if (dev->is_virtfn) + pci_dev_put(dev->physfn); +#endif + pci_free_resources(dev); put_device(&dev->dev); }